Commit graph

436 commits

Author SHA1 Message Date
Thomas Haller
7141a3b87a platform: cleanup handling metric paramters for non-exclusive routes 2017-08-03 18:33:00 +02:00
Thomas Haller
93fd03277f platform: cleanup handling locks for non-exclusive routes 2017-08-03 18:33:00 +02:00
Thomas Haller
19a709069a platform: print lock paramters of route
It is valid to set "lock" for a property with numeric value 0.

    # ip route append 192.168.7.0/24 dev bond0 window lock 0
    # ip route append 192.168.7.0/24 dev bond0 window 0
    # ip route append 192.168.7.0/24 dev bond0 window lock 10
    # ip route append 192.168.7.0/24 dev bond0 window 10
    # ip -4 -d route show dev bond0
    unicast 192.168.7.0/24 proto boot scope link linkdown
    unicast 192.168.7.0/24 proto boot scope link linkdown
    unicast 192.168.7.0/24 proto boot scope link linkdown window lock 10
    unicast 192.168.7.0/24 proto boot scope link linkdown window 10

Our to-string methods should accurately print the content of
the routes. Note that iproute2 fails to do so too.
2017-08-03 18:33:00 +02:00
Thomas Haller
bf348cde69 platform: cleanup handling "window" for non-exclusive routes 2017-08-03 18:33:00 +02:00
Thomas Haller
8fc669c02a platform: use route src/src_plen when deleting IPv6 route 2017-08-03 18:33:00 +02:00
Thomas Haller
415e00d086 platform: use route pref_src when deleting IP route 2017-08-03 18:32:59 +02:00
Thomas Haller
8e4c5b173f platform: use route mss when deleting IP route
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).
2017-08-03 18:32:59 +02:00
Thomas Haller
88da13f0b2 platform: use correct gateway for deleting route
Routes may only differ by their gateway. When deleting
a route, we must specify the exact gateway to delete.
2017-08-03 18:32:59 +02:00
Thomas Haller
a041e431da platform: use correct scope for deleting IPv4 route
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.
2017-08-03 18:32:59 +02:00
Thomas Haller
5a422af0d1 platform: use proper rt_source of route for add and delete
_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.
2017-08-03 18:32:59 +02:00
Thomas Haller
372f14a6ef platform: add compare functions for routes with different compare semantics
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.
2017-08-03 18:32:59 +02:00
Thomas Haller
8d03caf599 shared: cleanup NM_CMP_*() macros 2017-07-31 15:13:31 +02:00
Thomas Haller
b9fd352eca shared: move NM_CMP_*() helper macros to shared header 2017-07-31 15:13:31 +02:00
Thomas Haller
c8f3cd51ac platform/trivial: rename cmp helper macros 2017-07-31 15:13:31 +02:00
Beniamino Galvani
1dd4fec550 platform: fix IPv4 secondary address detection
If the subnet index was built without the @full_index flag, secondary
addresses are not present in the hash table.

Fixes: 5fcca9ba3e
2017-07-27 16:44:27 +02:00
Beniamino Galvani
5414239988 platform: fix IPv4 address lookup in nm_platform_ip4_address_sync()
Fixes: 5fcca9ba3e
2017-07-26 17:27:05 +02:00
Thomas Haller
459e76bdfe platform: consolidate debug logging during link-add
Don't log both in NMPlatform and NMLinuxPlatform.
Also, log all provided arguments.
2017-07-25 15:20:30 +02:00
Thomas Haller
2861c59116 platform: pass full route object to platform delete function
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.
2017-07-25 06:44:12 +02:00
Thomas Haller
5fcca9ba3e platform: refactor nm_platform_ip4_address_sync()
To reuse array of NMPObject instances instead of creating
a GArray clone.

Also get rid of the nm_platform_ipx_address_get_all() functions.
2017-07-25 06:44:12 +02:00
Thomas Haller
b2112ff471 platform: refactor NMPObject cast macros using _Generic()
This way, we also accept void pointers, while preserving constness.
2017-07-05 22:17:42 +02:00
Thomas Haller
06598700fe platform: refactor nm_platform_link_get_all() to return GPtrArray
Instead of doing a full clone, return a pointer array (with references
owned). The NMPlatformLink instances are now immutable.
2017-07-05 19:03:46 +02:00
Thomas Haller
ac60b0ce60 platform: move link accessors to NMPlatform base class
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().
2017-07-05 18:37:39 +02:00
Thomas Haller
71cf60e852 platform: refactor fake platform to use NMPCache for addresses
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.
2017-07-05 18:37:39 +02:00
Thomas Haller
35f52aafc1 platform: drop nm_platform_ip6_route_get_all()
We no longer need a full clone of routes. The only remaining uses
are in test code. Rework it.
2017-07-05 18:37:39 +02:00
Thomas Haller
aeaa1b3b98 platform: refactor nm_dedup_multi_objs_to_ptr_array_head()
by moving the core functionality to "nm-dedup-multi.c".

As the ref-counting mechanism now is part of "nm-dedup-multi.c",
this works better and is reusable outside of platform.
2017-07-05 18:37:39 +02:00
Thomas Haller
667c50f5d9 core: avoid cloning platform routes but iterate the cache directly 2017-07-05 18:37:39 +02:00
Thomas Haller
c9cd6d9954 platform: track routes in NMFakePlatform via NMPCache
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.
2017-07-05 18:37:39 +02:00
Thomas Haller
16aefdd865 platform: expose index lookup for objects in public API 2017-07-05 18:37:39 +02:00
Thomas Haller
c5af191dbf platform: expose emit-signal function from platform
It will be used by NMFakePlatform too.
2017-07-05 18:37:39 +02:00
Thomas Haller
e160928b9e platform: move the NMPCache from linux platform to NMPlatform
We want to expose the NMPLookup and NMDedupMultiHeadEntry to the users
of NMPlatform, so that they can iterate the cache directly.

That means, NMPCache becames an integral part of NMPlatform's API
and must also be implemented by NMFakePlatform.
2017-07-05 18:37:39 +02:00
Thomas Haller
485551286c platform: add use-udev property for NMPlatform
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.
2017-07-05 18:37:39 +02:00
Thomas Haller
55e66cc7e6 platform: implement hash function for NMPlatformLnk types 2017-07-05 18:37:39 +02:00
Thomas Haller
9440eefb6d platform: use NMDedupMultiIndex for routes in NMPCache
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).
2017-07-05 18:37:38 +02:00
Thomas Haller
89385bd968 core: pass NMDedupMultiIndex instance to NMIP4Config and other
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.
2017-07-05 14:22:10 +02:00
Thomas Haller
6d9c3eab38 platform: let NMPObject implement NMDedupIndexObj 2017-07-05 14:22:10 +02:00
Thomas Haller
b002357f5f platform: fix nm_platform_lnk_macvlan_cmp() to consider "tap" field 2017-07-05 14:22:10 +02:00
Thomas Haller
6ab2288c28 platform: add nm_platform_link_veth_add() to create VETH links 2017-05-27 23:16:56 +02:00
Thomas Haller
d1b951a7e5 platform: remove plen argument for IPv6 address ID
The prefix length is not part of the ID for IPv6 address. Remove
it from nmp_object_stackinit_id_ip6_address().
2017-05-27 11:38:38 +02:00
Beniamino Galvani
31656a066b core: add configuration flag to choose slaves activation order
Commits 39d0559d9a ("platform: sort links by name instead of
ifindex") and 529a0a1a7f ("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
2017-05-24 15:56:15 +02:00
Francesco Giudici
23bc781063 all/trivial: fix few comment typos 2017-05-15 15:52:21 +02:00
Thomas Haller
8ac1bf76bd core: move NMIPAddr to nm-core-utils.h
(cherry picked from commit 67da0a28db)
2017-04-27 17:21:33 +02:00
Beniamino Galvani
2511e27e76 platform: detect SR-IOV support and allow changing the number of VFs
(cherry picked from commit 0a7694cf81)
2017-04-18 23:28:59 +02:00
Thomas Haller
c2297fb66c core: enable "log-with-ptr" by default for platform and route-manager
Arguably, we currently only have one instance of NMPlatform,
NMRouteManager, NMDefaultRouteManager -- the one owned by the
NMNetns singleton.

Hence, all these instances we create with "log-with-ptr" set explicitly
to false.

In the future we want to support namespaces, and it will be be common to
have multiple instances. For that we have "log-with-ptr" so we are able
to disambiguiate the logging.

Change the default to TRUE because it makes more sense. It has currently
no effect as the default is never used.

(cherry picked from commit 41148caba8)
2017-04-18 15:53:11 +02:00
Thomas Haller
d37b9d79bc core: add NMNetns to bundle platform and route managers
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 0af2f5c28b)
2017-04-18 15:53:11 +02:00
Thomas Haller
be19ec0739 core: ignore host part when comparing routes for route-manager
(cherry picked from commit b78562570a)
2017-04-15 00:37:22 +02:00
Beniamino Galvani
39d0559d9a platform: sort links by name instead of ifindex
We should try to guarantee a stable activation order of connections
across reboots; this is required, for example, for bonds because they
get assigned the MAC address of the first device enslaved, and thus
changing the activation order of slaves means also changing the MAC
address of the bond. Since we activate connections in the order links
are discovered, having a stable sorting of links returned by platform
is enough.

The ifindex of interfaces can change between reboots as it depends on
the order in which kernel discover interfaces. Provided that the
system uses a mechanism to enforce persistent interface naming (as
udev rules or systemd-udevd predictable names), and that NM starts
after all interfaces have been announced by udev, using the interface
name instead of ifindex will guarantee a consistent order.
2017-03-27 21:51:55 +02:00
Lubomir Rintel
ed552c732c logging: log device and connection along with the message 2017-03-24 12:42:09 +01:00
Thomas Haller
e32839838e udev: drop libgudev in favor of libudev
libgudev is just a wrapper around libudev. We can
use libudev directly and drop the dependency for
libgudev.
2017-03-22 12:41:06 +01:00
Beniamino Galvani
45dc2feded platform: add support for some route options
Add support for new route options: window, cwnd, initcwnd, initrwnd,
mtu (and their related *-lock flag), tos and src (RTA_SRC).
2017-03-06 15:20:25 +01:00
Beniamino Galvani
63951cad7f platform: change signature of nm_platform_ip{4,6}_route_add()
Change the functions to accept a platform route as argument. This will
make it easier to add new route options.
2017-03-06 15:20:25 +01:00