Commit Graph

21088 Commits

Author SHA1 Message Date
Thomas Haller
35f189f1eb platform: ignore RTM_*LINK messages for unknown ifi_family (AF_BRIDGE)
When unenslaving an interface from a bridge, kernel sends a RTM_DELLINK
message with ifi_family AF_BRIDGE. We only care about regular
RTM_DELLINK/RTM_NEWLINK messages, ignore all but ifi_family AF_UNSPEC.

There is also test_nl_bugs_spuroius_dellink(), added in commit
8a87a91813 for related bug rh#1302037.
The workaround was masking a bug in NetworkManager (to not ignore AF_BRIDGE
messages) and can now be removed as well.
2017-08-31 20:01:45 +02:00
Ikey Doherty
5c5a553ca6 settings: ensure the keyfile storage directory actually exists
When first trying to write out the connections we need to ensure that the
keyfile directory exists, as the /etc/ tree may be either stateless or
reset initially.

Creating the directory on demand ensures that we have a chance for our
writes to actually work.

[lkundrak@v3.sk: dropped a comment for what seems obvious, minor style
fixes]
2017-08-31 18:29:48 +02:00
Thomas Haller
4adda2b79a core: fix clearing dirty flag in _nm_ip_config_add_obj()
We rely on clearing the dirty flag. For example in nm_ip4_config_replace(),
we first mark all entries dirty, then force-append the ones we keep,
and finally remove the ones that are still dirty.

Since _nm_ip_config_add_obj() short-cuts nm_dedup_multi_index_add_full(),
it must clear the dirty flag on its own.
2017-08-31 13:13:24 +02:00
Thomas Haller
d36f847e51 core: workaround compiler waring in for-each macros for NMIP4Config/NMIP6Config (again)
Compiler wouldn't recognize that the @route/@address argument is always
initialized. The right workaround seems to let the next() functions always
set the value.
2017-08-31 09:40:41 +02:00
Beniamino Galvani
167118a2cf libnm-core: fix memory leak in NMSettingPppoe
Fixes: f83e56ec6d
2017-08-30 22:03:59 +02:00
Thomas Haller
d686636bf0 core: avoid compiler warning in nm_ip_config_iter_ip4_address_for_each() macro
In file included from src/nm-ip6-config.c:24:0:
  src/nm-ip6-config.c: In function ‘nm_ip6_config_create_setting’:
  src/nm-ip6-config.c:734:62: error: the address of ‘address’ will always evaluate as ‘true’ [-Werror=address]
    nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, self, &address) {
                                                                ^
  src/nm-ip6-config.h:60:17: note: in definition of macro ‘nm_ip_config_iter_ip6_address_for_each’
       for (({ if (address) { *(((const NMPlatformIP6Address **) address)) = NULL; } }), nm_ip_config_iter_ip6_address_init ((iter), (self)); \
                   ^

Fixes: 6e9aa9402a
2017-08-30 20:09:15 +02:00
Thomas Haller
44917a910a core: use _nm_ip_config_add_obj() in NMIP4Config/NMIP6Config 2017-08-30 18:59:36 +02:00
Thomas Haller
6e9aa9402a core: allow NULL argument to nm-ip-config's for-each macros
Allow omitting the platform output argument. One can use the iterator to
access the current entry.
2017-08-30 18:59:36 +02:00
Beniamino Galvani
abcc74e0b5 man: nmcli: grammar fix
s/It's equivalent of/It's equivalent to/
2017-08-30 14:44:26 +02:00
Thomas Haller
eba646ec42 core: fix emitting changed notification during nm_ip4_config_intersect() 2017-08-30 11:47:34 +02:00
Thomas Haller
d95df1cef0 core/trivial: rename local variable
For consistency with other places.
2017-08-30 11:47:34 +02:00
Beniamino Galvani
bea6d05c1d default-route: skip addition when the route already exists
Re-adding the default route has side-effects, as it also prunes the
cloned routes from the kernel FIB.

https://bugzilla.redhat.com/show_bug.cgi?id=1470930
2017-08-29 10:20:07 +02:00
Beniamino Galvani
f42c7ba2b3 platform: tests: silence compilation warning
src/platform/tests/test-common.c: In function ‘_ip4_route_get’:
./src/platform/nmp-object.h:336:18: error: ‘o’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  return obj ? obj->_class->obj_type : NMP_OBJECT_TYPE_UNKNOWN;
               ~~~^~~~~~~~
src/platform/tests/test-common.c:308:19: note: ‘o’ was declared here
  const NMPObject *o;
                   ^

Fixes: cdd8c65799
2017-08-28 10:41:13 +02:00
Beniamino Galvani
67bfdbfc91 checkpoint: better restore device managed state on rollback
Manage a device again if it was managed before the checkpoint.

https://bugzilla.redhat.com/show_bug.cgi?id=1464904
2017-08-28 10:00:50 +02:00
Thomas Haller
1fbd8c079c contrib/scripts: add NM-log helper
To pretty print and colorize NetworkManager logfiles.
2017-08-24 18:40:49 +02:00
Thomas Haller
f4d88630b0 platform: merge branch 'th/platform-route-pt3'
Continue with the routing rework. Get rid of NMRouteManager
and configure non-exclusive routes.

https://github.com/NetworkManager/NetworkManager/pull/25
2017-08-24 11:55:58 +02:00
Thomas Haller
e470e13922 core: don't suppress host route to gateway in ip-config caputure
Why would we do this? The route is there, so, add it.
This revises commit 4fba2260f3
which added this check for matching generated connections.
I don't think this is still necessary, and if it is, then
the matching should be relaxed instead. It's bad to hide
routes from NMIP4Config/NMIP6Config, because those routes are
also exported via D-Bus.
2017-08-24 11:03:45 +02:00
Thomas Haller
10ac675299 platform: add support for routing tables to platform cache
The upper layers still ignore all routes outside the main table.
For now, just add support to NMPlatform.
2017-08-24 10:55:51 +02:00
Thomas Haller
538a0dd2dc platform: report error when configuring manual route
Rework to use nm_platform_ip_route_sync() broke to fail
activation when we were unable to configure a route.

Fix it. As before, we only do this for routes that
are configured manually by the user. Invalid routes from
DHCP do not break activation.

Also, improve logging to give a hint what's wrong.
2017-08-24 10:55:51 +02:00
Thomas Haller
8f65f96a43 platform: add option to suppress error message from nm_platform_ip_route_add()
When an error happens, we want to print a better message.
Avoid duplicate error messages by adding a flag to suppress
logging in the lower layer.
2017-08-24 10:55:51 +02:00
Thomas Haller
b524d879f0 platform: pass string buffer to nm_platform_error_to_string() and print numeric errno
Change the output of nm_platform_error_to_string() to print the numeric value.
Also, accept a string buffer instead of using an alloca() allocated buffer.

There is still a macro to provide the previous functionality, but it
was ill-suited to call from inside a loop.
2017-08-24 10:55:45 +02:00
Thomas Haller
8746dddda2 platform: assert for namespace in nm_platform_cache_update_emit_signal() 2017-08-24 10:48:04 +02:00
Thomas Haller
5a69b27a64 platform: let platform operations only consider kernel response
Also downgrade <error> logging messages to <warn>. An external
condition should never be able to trigger an <error>, and clearly
there is always a external race that can cause a netlink command
to fail.
2017-08-24 10:48:04 +02:00
Thomas Haller
774c8a811e platform: return failure reason from route-add and return only netlink response
Let nm_platform_ip_route_add() and friends return an NMPlatformError
failure reason.

Also, do_add_addrroute() did not return the response from kernel.
Instead, it determined success/failure based on the presence of the
object in the cache. That is racy and does not allow to give a failure
reason from kernel.

Instead, determine success solely based on the netlink reply from
kernel. The received errno shall be authorative, there is no need
to second guess the response.

There is a problem that netlink is not a reliable protocol. In case
of receive buffer overflow, the response is lost and we don't know
whether the command succeeded (it likely did). It's unclear how to fix
that, but for now just return "unspecified" error. We probably avoid
that already by having a huge buffer size.

Also, downgrade the error message to <warn> level. <error> is really
for bugs only.
2017-08-24 10:48:04 +02:00
Thomas Haller
fa7fafe8fd vpn: resolve route to external VPN gateway from kernel
When activating a route, we commonly need to add a route to the
external VPN gateway, so that the (encrypted) data is not sent over
the VPN itself.

Currently, our VPN connections are rather strongly tied to their
parent device. Maybe the shouldn't be, as VPN may happily support
changing the route from one device/IP address to another.

Anyway, our previous way to determine the gateway for the route
was not great. Instead, ask kernel how to reach the gateway via
(something like) `ip route get`. If kernel would route the packets
to the gateway via our parent device, we take that gateway.

If not, we keep our previous heuristic (which is probably wrong
in this case).
2017-08-24 10:48:03 +02:00
Thomas Haller
33a2a7c3e3 platform: add nm_platform_ip_route_get() for route-lookup
Inspired from iproute2. As such, don't use libnl3's "struct nl_msg", but
add _nl_addattr_l() and use a stack-allocated "struct nlmsghdr". With
this, we are closer to the raw netlink API. It really is simple enough.

The complicated part of the patch is that we re-use the existing netlink
socket for events. Hence, we must process the socket via our common
event_handler_recvmsgs(). That also means, that we get the netlink
response a few layers down the stack and have to return the result
via DelayedActionWaitForNlResponseData.
2017-08-24 10:48:03 +02:00
Thomas Haller
fec80e7473 platform: use IFA_F_NOPREFIXROUTE flag for IPv4 addresses
For IPv6 addresses we use IFA_F_NOPREFIXROUTE for a long time.
If we detect that kernel does not support the flag (for IPv6), we
add addresses as /128 to prevent kernel from adding an onlink route.
We add IPv6 device routes explicitly, whenever needed according
to the onlink RA flag.

For IPv4, we also don't want the route added by kernel. The reason is
that is has an undesired metric of zero. However, usually we want the route
to have a different metric. The complicated part is that kernel does
not add the route immediately but sometimes later. For that we have
nm_platform_ip4_dev_route_blacklist_set() (previously that was
nm_route_manager_ip4_route_register_device_route_purge_list()). It
watches the interface and when a registered device route shows up,
it deletes it.

The better solution is to use the IFA_F_NOPREFIXROUTE flag to prevent
the creation of the route in the first place. It was added for IPv4 to
kernel in commit 7b1311807f3d3eb8bef3ccc53127838b3bea3771, October 2015.

Contrary to IPv6, we cannot (easily) detect whether kernel supports IFA_F_NOPREFIXROUTE
for IPv4 routes. Hence keep nm_platform_ip4_dev_route_blacklist_set() for older
kernels.
2017-08-24 10:48:03 +02:00
Thomas Haller
2f83894498 core: cleanup setting ifa_flags in ndisc_config_changed()
Some refactoring and one change:

If we don't have system-support, don't set IFA_F_MANAGETEMPADDR.
2017-08-24 10:48:03 +02:00
Thomas Haller
057b63979e core: move setting NDisc addresses/routes to NMIP6Config
Add an utility function for resetting addresses/routes of NMIP6Config
from NMNDisc data. For one, this de-duplicates code in device and
nm-iface-helper.

Also, we no longer first reset (delete) all addresses and add them anew.
Instead, we first mark all entries as dirty for deletion, merge (append)
the new entires, and delete the remaining dirty entires. This saves a
extra work, in the expected case where NMIP6Config already contains
several of the new entries.
2017-08-24 10:48:03 +02:00
Lubomir Rintel
1b3a0208d9 all,trivial: include kernel versions and release dates in comments
This will make us stop worry how relevant are chunks of compat code with
older kernels when deciding whether it's worth supporting/testing them.
As if we actually were testing old kernels.
2017-08-24 10:48:03 +02:00
Thomas Haller
8670aacc7c platform: cleanup detecting kernel support for IFA_FLAGS and IPv6LL
- cache the result in NMPlatformPrivate. No need to call the virtual
  function every time. The result is not ever going to change.

- if we are unable to detect support, assume support. Those features
  were added quite a while ago to kernel, we should default to "support".
  Note, that we detect support based on the presence of the absence of
  certain netlink flags. That means, we will still detect no support.
  The only moment when we actually use the fallback value, is when we
  didn't encounter an RTM_NEWADDR or AF_INET6-IFLA_AF_SPEC message yet,
  which would be very unusual, because we fill the cache initially and
  usually will have some addresses there.

- for no strong reason, track "undetected" as numerical value zero,
  and "support"/"no-support" as 1/-1. We already did that previously for
  _support_user_ipv6ll, so this just unifies the implementations.
  The minor reason is that this puts @_support_user_ipv6ll to the BSS
  section and allows us to omit initializing priv->check_support_user_ipv6ll_cached
  in platforms constructor.

- detect _support_kernel_extended_ifa_flags also based on IPv4
  RTM_NEWADDR messages. Originally, extended flags were added for IPv6,
  and later to IPv4 as well. Once we see an IPv4 message with IFA_FLAGS,
  we know we have support.
2017-08-24 10:48:03 +02:00
Thomas Haller
48bc116c20 platform/trivial: move code 2017-08-24 10:48:03 +02:00
Thomas Haller
f0de7d347f platform: add non-exclusive routes and drop route-manager
Previously, we would add exclusive routes via netlink message flags
NLM_F_CREATE | NLM_F_REPLACE for RTM_NEWROUTE. Similar to `ip route replace`.
Using that form of RTM_NEWROUTE message, we could only add a certain
route with a certain network/plen,metric triple once. That was already
hugely inconvenient, because

 - when configuring routes, multiple (managed) interfaces may get
   conflicting routes (multihoming). Only one of the routes can be actually
   configured using `ip route replace`, so we need to track routes that are
   currently shadowed.

 - when configuring routes, we might replace externally configured
   routes on unmanaged interfaces. We should not interfere with such
   routes.

That was worked around by having NMRouteManager (and NMDefaultRouteManager).
NMRouteManager would keep a list of the routes which NetworkManager would like
to configure, even if momentarily being unable to do so due to conflicting routes.
This worked mostly well but was complicated. It involved bumping metrics to
avoid conflicts for device routes, as we might require them for gateway routes.

Drop that now. Instead, use the corresponding of `ip route append` to configure
routes. This allows NetworkManager to confiure (almost) all routes that we care.
Especially, it can configure all routes on a managed interface, without
replacing/interfering with routes on other interfaces. Hence, NMRouteManager
becomes obsolete.

It practice it is a bit more complicated because:

 - when adding an IPv4 address, kernel will automatically create a device route
   for the subnet. We should avoid that by using the IFA_F_NOPREFIXROUTE flag for
   IPv4 addresses (still to-do). But as kernel may not support that flag for IPv4
   addresses yet (and we don't require such a kernel yet), we still need functionality
   similar to nm_route_manager_ip4_route_register_device_route_purge_list().
   This functionality is now handled via nm_platform_ip4_dev_route_blacklist_set().

 - trying to configure an IPv6 route with a source address will be rejected
   by kernel as long as the address is tentative (see related bug rh#1457196).
   Preferably, NMDevice would keep the list of routes which should be configured,
   while kernel would have the list of what actually is configured. There is a
   feed-back loop where both affect each other (for example, when externally deleting
   a route, NMDevice must forget about it too). Previously, NMRouteManager would have
   the task of remembering all routes which we currently want to configure, but cannot
   due to conflicting routes.
   We get rid of that, because now we configure non-exclusive routes. We however still
   will need to remember IPv6 routes with a source address, that currently cannot be
   configured yet. Hence, we will need to keep track of routes that
   currently cannot be configured, but later may be.
   That is still not done yet, as NMRouteManager didn't handle this
   correctly either.
2017-08-24 10:48:03 +02:00
Thomas Haller
974ff62996 platform: fix handling rt_scope of IPv4 route
Kernel does not allow to add an IPv4 route with rt_scope RT_SCOPE_NOWHERE
(255). It would fail with EINVAL.

While adding a route, we coerce/normalize the scope in
nm_platform_ip_route_normalize(). However, that should only be
done, if the scope is not explicitly set already. Otherwise,
leave it unchanged.

nm_platform_ip_route_normalize() is related to the compare functions.
Several compare modes do a fuzzy comparison, and they should compare
equal as if they would be normalized. Hence, we must do the same
normalization there.

One pecularity in NetworkManager is that we track scope as it's
inverse. The reason is to have a default value of zero meaning
RT_SCOPE_NOWHERE. Hence "scope_inv".
2017-08-24 10:47:23 +02:00
Thomas Haller
69a50a5053 platform: add and use nm_platform_ip_route_normalize()
Adding a route to kernel may coerce/mangle some properties. Add a function
nm_platform_ip_route_normalize() to simulate these changes.
2017-08-23 18:37:22 +02:00
Thomas Haller
990a050aff platform: cleanup and renaming of nm_platform_address_flush() function
Rename to nm_platform_ip_address_flush(), it's more consistent with naming
for other platform functions.

Also, pass an address family argument. Sometimes I feel an option makes it clearer
what the function does. Otherwise, from the name it's not clear which address
families are affected. As an API, it feels more correct to me.

We soon also get a nm_platform_ip_route_flush() function, which will
look similar.
2017-08-23 18:37:22 +02:00
Thomas Haller
a738a3446b platform: add typedef for NMPObjectPredicateFunc function pointer
Otherwise, casting a function pointer is cumbersome.
2017-08-23 18:37:22 +02:00
Thomas Haller
936ebdc724 core: consistently use _nm_ip_config_add_obj() when adding route/address to ip-config
_nm_ip_config_add_obj() does some additional checking, like setting the ifindex.
We shall not bypass this also during bulk-update (replace).

Add options @merge and @append_force to make _nm_ip_config_add_obj() suitable
in those cases too, and use it.
2017-08-23 18:37:22 +02:00
Thomas Haller
29bfe7c1fd core: merge code block in nm_ip4_config_commit() by un-indenting 2017-08-23 18:37:22 +02:00
Thomas Haller
35ed678cc6 platform: add nm_platform_ip_route_add() function 2017-08-23 18:37:22 +02:00
Thomas Haller
abaaf3a693 platform/trivial: move code
Trivial code (like this which only depends on an enum defined in a header
file) should go first, so that the complex stuff is close together.
2017-08-23 18:37:22 +02:00
Thomas Haller
2cd25d7a37 platform: fix constness of argument for nm_platform_lookup_all()
... and nm_platform_lookup_entry().
2017-08-23 18:37:22 +02:00
Thomas Haller
b0f52d41bc platform: fix handling rt_source/rtprot when comparing routes
In several cases, does the route compare function a fuzzy match, to get
the result as what would happen if you add that route to kernel.

The rt_source enum contains some NetworkManager specific values which
are mapped to a certain rtm_protocol value. Especially, when adding
a route to kernel, the resulting value will be coerced (and end up being
different).

We must take this coercion into account.
2017-08-23 18:37:22 +02:00
Thomas Haller
d85c239101 platform: fix loose comparison for metric of IPv6 routes
For IPv6 routes, a metric of zero is identical to a metric of 1024.
Unless we do NM_PLATFORM_IP_ROUTE_CMP_TYPE_FULL, compare them as
equal.
2017-08-23 18:37:22 +02:00
Thomas Haller
ffd47da5dc platform: use _Generic() for NM_PLATFORM_IP_ROUTE_IS_DEFAULT() macro
Avoid the plain cast and use _Generic() to check the type of @route argument.
2017-08-23 18:37:21 +02:00
Thomas Haller
2f693fb68c shared: return deleted object from nm_dedup_multi_index_remove_obj()
For completeness of the API. remove_obj() is basically a shortcut
of nm_dedup_multi_index_lookup_obj() combined with
nm_dedup_multi_index_remove_entry(). As such, it is useful to return
the actually deleted object. Note that the lookup needle @obj is not
necessarily the same instance as the one that will be removed, it's
only an instance that compares equal according to the index's equality
operator.
2017-08-23 18:37:21 +02:00
Thomas Haller
3fc501e833 shared: indicate changes when only reordering happens during nm_dedup_multi_index_add()
The return value shall indicate whether the add-call changed anything.
Reordering shall count as a change too.

On the other hand, clearing the dirty flag of the entry does not count
as a change.
2017-08-23 18:37:21 +02:00
Thomas Haller
d100ce28e0 shared: add nm_g_slice_free_fcn() util
Useful, when you need a GDestroyNotify function for g_slice_free() of
a certain type.
2017-08-23 18:37:21 +02:00
Thomas Haller
3faff5b457 core/trivial: indentation in src/devices/nm-device-ip-tunnel.c 2017-08-23 18:37:21 +02:00
Thomas Haller
20235453a9 core: fix crash in nm_ip4_config_address_exists()
Fixes: 22edeb5b69
2017-08-23 18:37:21 +02:00