summaryrefslogtreecommitdiff
path: root/src/platform/nm-platform.h
Commit message (Collapse)AuthorAgeFilesLines
* platform: add nm_platform_link_set_name()Beniamino Galvani2017-08-051-0/+2
| | | | We'll need it to rename the new PPP interface to a given name.
* platform: extend API for adding routesThomas Haller2017-08-031-5/+32
| | | | | | | | | | | | | | | | | | | | Via the flags of the RTM_NEWROUTE netlink message, kernel and iproute2 support various variants to add a route. - ip route add - ip route change - ip route replace - ip route prepend - ip route append - ip route test Previously, our nm_platform_ip4_route_add() function was basically `ip route replace`. In the future, we should rather user `ip route append` instead. Anyway, expose the netlink message flags in the API. This allows to use the various forms, and makes it also more apparent to the user that they even exist.
* platform,libnm: cleanup handling of TOS for routesThomas Haller2017-08-031-1/+8
| | | | | | | | | | - kernel ignores rtm_tos for IPv6 routes. While iproute2 accepts it, let libnm reject TOS attribute for routes as well. - move the tos field from NMPlatformIPRoute to NMPlatformIP4Route. - the tos field is part of the weak-id of an IPv4 route. Meaning, `ip route add` can add routes that only differ by their TOS.
* core: implement NMIP4Config's and NMIP6Config's route equality based on ↵Thomas Haller2017-08-031-0/+5
| | | | | | | | | | | nm_platform_ipx_route_cmp() There are various notions of how to compare routes. Collect them all in nm_platform_ip4_route_cmp(), nm_platform_ip4_route_hash(), nm_platform_ip6_route_cmp(), and nm_platform_ip6_route_hash(). This way, we have them side-by-side, which makes the differences more discoverable.
* platform: cleanup handling metric paramters for non-exclusive routesThomas Haller2017-08-031-0/+9
|
* platform: cleanup handling locks for non-exclusive routesThomas Haller2017-08-031-10/+12
|
* platform: cleanup handling "window" for non-exclusive routesThomas Haller2017-08-031-7/+16
|
* platform: use route src/src_plen when deleting IPv6 routeThomas Haller2017-08-031-0/+8
|
* platform: use route pref_src when deleting IP routeThomas Haller2017-08-031-2/+11
|
* platform: use route mss when deleting IP routeThomas Haller2017-08-031-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The mss (advmss, RTA_METRICS.RTAX_ADVMSS) is in a way part of the ID for IPv4 routes. That is, you can add multiple IPv4 routes, that only differ by mss. On the other hand, that is not the case for IPv6. Two IPv6 routes that only differ by mss are considered the same. Another issue is, that you cannot selectively delete an IPv4 route based on the mss: ip netns del x ip netns add x IP() { ip netns exec x ip "$@" } IP link add type veth IP link set veth0 name v IP link set veth1 up IP link set v up IP route append 192.168.7.0/24 dev v advmss 6 IP route append 192.168.7.0/24 dev v advmss 7 IP -d route show dev v IP route delete 192.168.7.0/24 dev v advmss 7 IP -d route show dev v It seems for deleting routes, kernel ignores mss (which doesn't really matter for IPv6, but does so for IPv4).
* platform: use correct gateway for deleting routeThomas Haller2017-08-031-0/+5
| | | | | Routes may only differ by their gateway. When deleting a route, we must specify the exact gateway to delete.
* platform: use correct scope for deleting IPv4 routeThomas Haller2017-08-031-4/+13
| | | | | | | | | | | | | | | | | | | | Refactor _nl_msg_new_route() to obtain the route scope (rtm_scope) from the NMPObject, instead of a separate argument. That way, when deleting an IPv4 route, we don't pick the first route that matches (RT_SCOPE_NOWHERE), but use the actual scope of the route that we want to delete. That matters, if there are more then one otherwise identical routes that only differ by their scope. For kernel, the scope of IPv6 routes is always global (RT_SCOPE_UNIVERSE). Also, during ip4_route_add() initialize the intermediate @obj to have the values as we expect them after adding the route. That is necessary to use it in _nl_msg_new_route(). But also nicer for consistency. Also, move the scope_inv field in NMPlatformIP4Route to let the other in_addr_t fields life side by side.
* platform: use proper rt_source of route for add and deleteThomas Haller2017-08-031-1/+9
| | | | | | | | | | | | | _nl_msg_new_route() should not get extra arguments, but instead use all parameters from the NMPObject argument. This will allow during nm_platform_ip_route_delete() to pick the exact route that should be deleted. Also, in ip4_route_add()/ip6_route_add(), keep the stack-allocated @obj object consistent with what we expect to add. That is, set the rt_source argument to the value of what the route will have after kernel adds it. That might be necessary, because do_add_addrroute() searches the cache for @obj.
* platform: add compare functions for routes with different compare semanticsThomas Haller2017-08-031-9/+64
| | | | | | | | | | Routes are complicated. `ip route add` and `ip route append` behaves differently with respect to determine whether an existing route is idential or not. Extend the cmp() and hash() functions to have a compare type, that covers the different semantics.
* platform: pass full route object to platform delete functionThomas Haller2017-07-251-6/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Contrary to addresses, routes have no ID. When deleting a route, you cannot just specify certain properties like network/plen,metric. Well, actually you can specify only certain properties, but then kernel will treat unspecified properties as wildcard and delete the first matching route. That is not something we want, because we need to be in control which exact route shall be deleted. Also, rtm_tos *must* match. Even if we like the wildcard behavior, we would need to pass TOS to nm_platform_ip4_route_delete() to be able to delete routes with non-zero TOS. So, while certain properties may be omitted, some must not. See how test_ip4_route_options() was broken. For NetworkManager it only makes ever sense to call delete on a route, if the route is already fully known. Which means, we only delete routes that we have already in the platform cache (otherwise, how would we know that there is something to delete). Because of that, no longer have separate IPv4 and IPv6 functions. Instead, have nm_platform_ip_route_delete() which accepts a full NMPObject from the platform cache. The code in core doesn't jet make use of this new functionality. It will in the future. At least, it fixes deleting routes with differing TOS.
* platform: refactor nm_platform_ip4_address_sync()Thomas Haller2017-07-251-4/+2
| | | | | | | To reuse array of NMPObject instances instead of creating a GArray clone. Also get rid of the nm_platform_ipx_address_get_all() functions.
* core: track addresses for NMIP4Config/NMIP6Config via NMDedupMultiIndexThomas Haller2017-07-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | Reasons: - it adds an O(1) lookup index for accessing NMIPxConfig's addresses. Hence, operations like merge/intersect have now runtime O(n) instead of O(n^2). Arguably, we expect low numbers of addresses in general. For low numbers, the O(n^2) doesn't matter and quite likely in those cases the previous implementation was just fine -- maybe even faster. But the simple case works fine either way. It's important to scale well in the exceptional case. - the tracked objects can be shared between the various NMPI4Config, NMIP6Config instances with NMPlatform and everybody else. - the NMPObject can be treated generically, meaning it enables code to handle both IPv4 and IPv6, or addresses and routes. See for example _nm_ip_config_add_obj(). - I want core to evolve to somewhere where we don't keep copies of NMPlatformIP4Address, et al. instances. Instead they shall all be shared. I hope this will reduce memory consumption (although tracking a reference consumes some memory too). Also, it shortcuts nmp_object_equal() when comparing the same object. Calling nmp_object_equal() on the identical objects would be a common case after the hash function pre-evaluates equality.
* platform: refactor nm_platform_link_get_all() to return GPtrArrayThomas Haller2017-07-051-1/+1
| | | | | Instead of doing a full clone, return a pointer array (with references owned). The NMPlatformLink instances are now immutable.
* platform: move link accessors to NMPlatform base classThomas Haller2017-07-051-9/+3
| | | | | | | | | | | | and refactor NMFakePlatform to also track links via NMPCache. For one, now NMFakePlatform also tests NMPCache, increasing the coverage of what we care about. Also, all our NMPlatform implementations now use NMPObject and NMPCache. That means, we can expose those as part of the public API. Which is great, because callers can keep a reference to the NMPObject object and make use of generic functions like nmp_object_to_string().
* platform: refactor fake platform to use NMPCache for addressesThomas Haller2017-07-051-4/+0
| | | | | | | | | | | | | | | | | And move some code from NMLinuxPlatform to NMPlatform, where it belongs. The advantage is that we reuse (and test!) the NMPCache implementation for tracking addresses. Also, we now always expose proper NMPObjects from both linux and fake platform. For example, obj = NMP_OBJECT_UP_CAST (nm_platform_ip4_address_get (...)); will work as expected. Also, the caller is now by NMPlatform API allowed to take and keep a reference to the returned objects.
* platform: drop nm_platform_ip6_route_get_all()Thomas Haller2017-07-051-13/+0
| | | | | We no longer need a full clone of routes. The only remaining uses are in test code. Rework it.
* core: avoid cloning platform routes but iterate the cache directlyThomas Haller2017-07-051-2/+9
|
* platform: track routes in NMFakePlatform via NMPCacheThomas Haller2017-07-051-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | NMPlatform's cache should be directly accessible to the users, at least the NMPLookup part and the fact that the cache contains ref-counted, immutable NMPObjects. This allows users to inspect the cache with zero overhead. Meaning, they can obtain an NMDedupMultiHeadEntry and iterate the objects themself. It also means, the are free to take and keep references of the NMPObject instances (of course, without modifying them!). NMFakePlatform will use the very same cache. The fake platform should only differ when modifying the objects. Another reason why this makes sense is because NMFakePlatform is for one a test-stup but also tests behavior of platform itself. Using a separate internal implementation for the caching is a pointless excecise, because only the real NMPCache's implementation really matters for production. So, either NMFakePlatform behaves idential, or it is buggy. Reuse it. Port fake platform's tracking of routes to NMPCache and move duplicate code from NMLinuxPlatform to the base class. This commit only ports IP routes, eventually also addresses and links should be tracked via the NMPCache instance.
* platform: expose index lookup for objects in public APIThomas Haller2017-07-051-0/+5
|
* platform: add use-udev property for NMPlatformThomas Haller2017-07-051-0/+2
| | | | | | | We want to move the multi_idx from NMLinuxPlatform to NMPlatform, so that it can be used by NMFakePlatform as well. For that, we need to know whether NMPlatform will use udev or not. Add a constrctor property.
* platform: implement hash function for NMPlatformLnk typesThomas Haller2017-07-051-1/+10
|
* platform: use NMDedupMultiIndex for routes in NMPCacheThomas Haller2017-07-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rework platform object cache to use NMDedupMultiIndex. Already previously, NMPCache used NMMultiIndex and had thus O(1) for most operations. What is new is: - Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of the cached items. That is crucial to handle routes properly as kernel will replace the first matching route based on network/plen/metric properties. See related bug rh#1337855. Without tracking the order of routes as they are exposed by kernel, we cannot properly maintain the route cache. - All NMPObject instances are now treated immutable, refcounted and get de-duplicated via NMDedupMultiIndex. This allows to have a global NMDedupMultiIndex that can be shared with NMIP4Config and NMRouteManager. It also allows to share the objects themselves. Immutable objects are so much nicer. We can get rid of the update pre-hook callback, which was required previously because we would mutate the object inplace. Now, we can just update the cache, and compare obj_old and obj_new after the fact. - NMMultiIndex was treated as an internal of NMPCache. On the other hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is basically an object that allows to iterate over all related objects. That means, we can now lookup objects in the cache and give the NMDedupMultiHeadEntry instance to the caller, which then can iterate the list on it's own -- without need for copying anything. Currently, at various places we still create copies of lookup results. That can be improved later. The ability to share NMPObject instances should enable us to significantly improve performance and scale with large number of routes. Of course there is a memory overhead of having an index for each list entry. Each NMPObject may also require an NMDedupMultiEntry, NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head for multiple objects, and NMDedupMultiBox is able to deduplicate several NMPObjects, so that there is a net saving. Also, each object type has several indexes of type NMPCacheIdType. So, worst case an NMPlatformIP4Route in the platform cache is tracked by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry, plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance is shared between the 8 indexes (and possibly other).
* core: pass NMDedupMultiIndex instance to NMIP4Config and otherThomas Haller2017-07-051-0/+2
| | | | | | | | | | | | | | NMIP4Config, NMIP6Config, and NMPlatform shall share one NMDedupMultiIndex instance. For that, pass an NMDedupMultiIndex instance to NMPlatform and NMNetns. NMNetns than passes it on to NMDevice, NMDhcpClient, NMIP4Config and NMIP6Config. So currently NMNetns is the access point to the shared NMDedupMultiIndex instance, and it gets it from it's NMPlatform instance. The NMDedupMultiIndex instance is really a singleton, we don't want multiple instances of it. However, for testing, instead of adding a singleton instance, pass the instance explicitly around.
* platform: let NMPObject implement NMDedupIndexObjThomas Haller2017-07-051-0/+5
|
* platform: add nm_platform_link_veth_add() to create VETH linksThomas Haller2017-05-271-0/+3
|
* platform: remove plen argument for IPv6 address IDThomas Haller2017-05-271-2/+2
| | | | | The prefix length is not part of the ID for IPv6 address. Remove it from nmp_object_stackinit_id_ip6_address().
* core: add configuration flag to choose slaves activation orderBeniamino Galvani2017-05-241-1/+1
| | | | | | | | | Commits 39d0559d9a7a ("platform: sort links by name instead of ifindex") and 529a0a1a7f19 ("manager: sort slaves to be autoconnected by device name") changed the order of activation of slaves. Introduce a system-wide configuration property to preserve the old behavior. https://bugzilla.redhat.com/show_bug.cgi?id=1452585
* core: move NMIPAddr to nm-core-utils.hThomas Haller2017-04-271-18/+0
| | | | (cherry picked from commit 67da0a28db834192d207fb315a3ba1983fe4a79e)
* platform: detect SR-IOV support and allow changing the number of VFsBeniamino Galvani2017-04-181-0/+4
| | | | (cherry picked from commit 0a7694cf81d27cd3e73295372065f46a4765f3a1)
* core: add NMNetns to bundle platform and route managersThomas Haller2017-04-181-2/+3
| | | | | | | | | | | | | | | | | | | | | | | NMPlatform, NMRouteManager and NMDefaultRouteManager are singletons instances. Users of those are for example NMDevice, which registers to GObject signals of both NMPlatform and NMRouteManager. Hence, as NMDevice:dispose() disconnects the signal handlers, it must ensure that those singleton instances live longer then the NMDevice instance. That is usually accomplished by having users of singleton instances own a reference to those instances. For NMDevice that effectively means that it shall own a reference to several singletons. NMPlatform, NMRouteManager, and NMDefaultRouteManager are all per-namespace. In general it doesn't make sense to have more then one instances of these per name space. Nnote that currently we don't support multiple namespaces yet. If we will ever support multiple namespaces, then a NMDevice would have a reference to all of these manager instances. Hence, introduce a new class NMNetns which bundles them together. (cherry picked from commit 0af2f5c28b7646c687b5180a45a9124d62c0dfac)
* platform: fix a typoLubomir Rintel2017-04-181-1/+1
| | | | (cherry picked from commit c76ee5883d6684213fb2fe7bf06c9e4ce016f97a)
* core: ignore host part when comparing routes for route-managerThomas Haller2017-04-151-3/+15
| | | | (cherry picked from commit b78562570ac49ddd31e20336206399613d5604ef)
* udev: drop libgudev in favor of libudevThomas Haller2017-03-221-2/+4
| | | | | | libgudev is just a wrapper around libudev. We can use libudev directly and drop the dependency for libgudev.
* platform: add support for some route optionsBeniamino Galvani2017-03-061-0/+13
| | | | | Add support for new route options: window, cwnd, initcwnd, initrwnd, mtu (and their related *-lock flag), tos and src (RTA_SRC).
* platform: change signature of nm_platform_ip{4,6}_route_add()Beniamino Galvani2017-03-061-12/+4
| | | | | Change the functions to accept a platform route as argument. This will make it easier to add new route options.
* platform: support preferred source option for IPv6 routesBeniamino Galvani2017-03-061-2/+3
| | | | | Extend the support for the preferred source route option (RTA_PREFSRC) to IPv6.
* platform/tun: don't passing around the ifname guessLubomir Rintel2017-01-161-1/+1
| | | | | | | nm_platform_sysctl_open_netdir() doesn't take it anyways, gets it from the cache. CID 160209 (#1 of 1): Unused value (UNUSED_VALUE)
* platform: add support for macsec linksBeniamino Galvani2017-01-161-0/+29
| | | | | Add support for a new macsec link type and its netlink attributes to the platform code.
* platform: add wrappers for if_nametoindex() and if_indextoname()Thomas Haller2017-01-041-0/+3
|
* platform: lookup ifname for ethtool/mii ioctl immediately before useThomas Haller2016-12-131-3/+3
| | | | | | | | | | | | | | | | | The ioctl APIs ethtool/mii require an interface ifname. That is inherrently racy as interfaces can be renamed. This cannot be fixed, we can only minimize the time between verifying the ifname and calling ioctl. We already had problems with that when ethtool would access an interface by name that didn't exists. See commit ab41c13b0611c6cc967b055d328637a143b5c59b . Checking for an existing interface only helps avoiding races when an interface gets deleted. It does not help against renaming. Go one step further, and instead of checking whether such an ifname exists, try to get the ifname based on the ifindex immediately before we need it. This brings an additional overhead for each ethtool access.
* core: use nmp_utils_sysctl_open_netdir() to read tun/tap sysctlThomas Haller2016-12-131-3/+1
|
* platform: implement sysctl access via relative path to sysctl_open_netdir()Thomas Haller2016-12-131-0/+11
|
* platform: add optional dirfd argument to sysctl functionsThomas Haller2016-12-131-6/+9
| | | | Still unused.
* core: merge NM_PLATFORM_LINK_DUPLEX_UNSET and UNKNOWNfg/802-3-prop_rh1353612_IIThomas Haller2016-11-221-2/+1
| | | | | They have basically the same use, except that certain places handled one but not the other.
* platform: add APIs to allow link negotiation managementFrancesco Giudici2016-11-221-1/+9
| | | | | | | Added platform functions to retrieve device link mode status and to switch from auto to manual link negotiation: nm_platform_ethtool_get_link_settings nm_platform_ethtool_set_link_settings