Commit graph

436 commits

Author SHA1 Message Date
Thomas Haller
3e9ba55c3a platform: move asserts for sysctl_get/set functions to nm-linux-platform
Also assert inside of sysctl_get() that we read the expected file
locations. Especially because now we might log the content of these
files.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-03-04 21:21:35 +01:00
Dan Winship
5fe94852ef platform: change sysctl_get/set error logging
Remove the "silent_on_error" flag from nm_platform_sysctl_get(), and
make both get() and set() log at debug level on ENOENT and error level
on all other errors, always.

Also ensure that we don't sometimes write "failed to set 'x' to 'y':
Success" when a partial write occurs.
2014-02-27 15:28:11 -05:00
Thomas Haller
8b294541d8 platform: share the static buffer for platform to_string functions
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-02-24 21:58:51 +01:00
Thomas Haller
6c0db3107e platform: align debugging output in platform signals
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-02-24 18:29:25 +01:00
Thomas Haller
66f5256b94 core: add nm_platform_link_refresh() function to refresh the libnl cache for links
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-02-23 22:31:42 +01:00
Thomas Haller
a6767f215e platform: refactor address_to_string() to return device as numeric if ifname is unknown
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-02-18 13:21:47 +01:00
Thomas Haller
2bc90a5f2d platform: do not check for _exists() before deleting addresses and routes
Before, nm_platform_ip4_address_exists(), et al. look into the cache to see
whether the address/route already exists and returned an error if it
did.

Change the semantic of the delete functions, to return success in case of
"nothing to delete". Also always try to delete the object in the
kernel. The reason is, that the cache might be out of date and the
caller really wants to delete it. So, to be sure, we always delete.

In most cases the object is actually in the cache (because that is
how the caller came to know that such an object might exist).
In those cases, the lookup was not useful either, because the object
was actually cached.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-02-14 21:41:25 +01:00
Thomas Haller
e54a3ccaf8 platform: add debug logging when adding/deleting routes
Also, change the logging of nm_platform_ip._address_delete()
to log what we are about to do, *before* checking for existing
addresses.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-02-14 18:35:07 +01:00
Thomas Haller
5d6a5f8572 core/platform: add debug logging when adding/deleting addresses
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-30 20:31:29 +01:00
Thomas Haller
0535aa44db core: use nm_utils_get_monotonic_timestamp_s for timestamp of NMPlatformIP[46]Address
https://bugzilla.gnome.org/show_bug.cgi?id=720833

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-30 19:51:45 +01:00
Thomas Haller
7841f9ea0a core/platform: add check_support_kernel_extended_ifa_flags function
The kernel adds a new capability to allow user space to manage
temporary IPv6 addresses. We need to detect this capability
to act differently, depending on whether NM has an older kernel
at hand.

This capability got introduced together when extending the
ifa_flags to 32 bit. So, we can check the netlink message,
whether we have such an nl attribute at hand.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-30 17:04:36 +01:00
Thomas Haller
2bc61d1ad3 core/platform: workaround new address flag in address_to_string
The kernel and libnl adds two new flags IFA_F_MANAGETEMPADDR
and IFA_F_NOPREFIXROUTE. Older versions of libnl do not recognize
this flag, so add a workaround to nm_platform_ip6_address_to_string()
to show "mngtmpaddr" and "noprefixroute", respectively.

Also, add function nm_platform_check_support_libnl_extended_ifa_flags()
that checks whether libnl supports extended ifa_flags that were
added recently.

Extended flags and the two ifa-flags above were added to libnl in close
succession.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-30 17:04:36 +01:00
Thomas Haller
634e4c99c3 platform: add parameter to nm_platform_sysctl_get() to suppress logging error
In some cases, an error when reading the sysctl value can be expected.
In this case, we want to suppress the error message

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-30 11:53:32 +01:00
Thomas Haller
8959b6dbcb core/platform: sort routes before adding them in nm_platform_ipX_route_sync()
A gateway route can only be added, if there exists a device route
for that gateway. Therefore, nm_platform_ip4_route_sync() and
nm_platform_ip6_route_sync() has to add the device routes first,
before adding gateway routes.

Note: usually for all configured addresses, there is also a device
route for the subnet added by the kernel. This means, NM must first
configure the addresses before route_sync, so that these implicit device
routes already exist -- this is however already done correctly.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-24 09:42:52 -06:00
Thomas Haller
c8d7a06d64 core/platform: revise failure to activate connection on error of setting route
This revises the commit fbde824584 which
causes the activation of a connection to fail generally when a route
cannot be added. Instead, we only want to fail for user configured
routes.

Related: https://bugzilla.gnome.org/show_bug.cgi?id=722843
Related: https://bugzilla.redhat.com/show_bug.cgi?id=999544
Related: https://bugzilla.redhat.com/show_bug.cgi?id=1005416
Related: https://bugzilla.gnome.org/show_bug.cgi?id=721771

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-24 09:42:52 -06:00
Thomas Haller
29501c9955 core/platform: compare IPv4 addresses in nm_platform_ip4_*_cmp() as integers, without memcmp()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-24 09:42:52 -06:00
Dan Williams
8d9bfcdd5a platform: don't replace routes that already exist
If a route already exists that matches the network, prefix, gateway,
and metric of a route NM would like to add, don't try to overwrite
the route.

Unlike IP addresses, the kernel doesn't update the details, it
appears to completely replace that route, which might screw up
external tools that added the route originally.

One example of this is IPSec via openswan/libreswan.  They add the
routes to the kernel upon connection, and if NM replaces those routes,
IPSec no longer works.  While this may be due to kernel bugs or
bad handling of route replacement, there's no reason for NM to touch
routes that it wouldn't materially change anyway.

(yes, we could perhaps use NLM_F_REPLACE in add_kernel_object() only
when we really wanted to replace something, but why ask the kernel
to do the work when it's not required anyway?)
2014-01-24 09:42:52 -06:00
Dan Williams
4c16f3c7e2 core/platform: preserve external and static route metrics
Two issues:

1) routes added by external programs or by users with /sbin/ip should not
be modified, but NetworkManager was always changing those routes' metrics
to match the device priority.  This caused the nm_platform_ipX_route_sync()
functions to remove the original, external route (due to mismatched metric)
and re-add the route with the NetworkManager specified metric.  Fix that
by not touching routes which came from the kernel.

2) Static routes (from persistent connections) that specified a metric were
getting their metric overwritten with the NetworkManager device priority.
Stop doing that.

Since the platform no longer defaults the metric to 1024, callers of
nm_platform_ip4_route_add() (like NMPolicy's default route handling)
must do that themselves, if they desire this behavior.
2014-01-24 09:42:52 -06:00
Dan Williams
067db6f8d7 core/platform: add address/route sources (rh#1005416, bgo#722843)
Tag addresses and routes with their source.  We'll use this later to do
(or not do) operations based on where the item came from.

One thing to note is that when synchronizing items with the kernel, all
items are read as source=KERNEL even when they originally came from
NetworkManager, since the kernel has no way of providing this source
information.  This requires the source 'priority', which
nm_ip*_config_add_address() and nm_ip*_config_add_route() must respect
to ensure that NM-owned routes don't have their source overwritten
when merging various IP configs in ip*_config_merge_and_apply().

Also of note is that memcmp() can no longer be used to compare
addresses/routes in nm-platform.c, but this had problems before
anyway with ifindex, so that workaround from nm_platform_ip4_route_sync()
can be removed.

https://bugzilla.gnome.org/show_bug.cgi?id=722843
https://bugzilla.redhat.com/show_bug.cgi?id=1005416
2014-01-24 09:42:52 -06:00
Thomas Haller
2b87dbb2a9 core: cleanup data types for nm_platform_sysctl_get_int32()
The sysctl values in the kernel (for those values for which
nm_platform_sysctl_get_uint() is currently used) are defined as s32.
Change nm_platform_sysctl_get_uint() to nm_platform_sysctl_get_int32()
and ensure, that a matching integer type is used thoroughly.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-22 12:23:58 +01:00
Thomas Haller
1b0f832c7f core: print peer_address in NMPlatform address_to_string
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-02 21:13:11 +01:00
Dan Winship
f099a04132 platform/core: add back support for PtP/peer addresses (rh #1018317)
In the migration to NMPlatform, support for ptp/peer addresses was
accidentally dropped. This broke OpenVPN configurations using 'p2p'
topology, which send a different peer address than the local address
for tunX, plus the server may also push routes that use the peer
address as the next hop. NetworkManager was unable to add these
routes, because the kernel had no idea how to talk to the peer,
because the peer's address was not assigned to any interface or
reachable over any routes.

Partly based on a patch from Dan Williams.
2013-12-02 15:00:28 -05:00
Dan Winship
7bc7da83ec core: remove redundant sysctl utilities
NMDevice was still using the old sysctl functions from
NetworkManagerUtils rather than the new NMPlatform ones. Fix it, and
remove the old functions.
2013-11-15 10:49:43 -05:00
Thomas Haller
97935382f4 coverity: fix various warnings detected with Coverity
These are (most likely) only warnings and not severe bugs.
Some of these changes are mostly made to get a clean run of
Coverity without any warnings.

Error found by running Coverity scan

https://bugzilla.redhat.com/show_bug.cgi?id=1025894

Co-Authored-By: Jiří Klimeš <jklimes@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-11-13 15:29:24 +01:00
Thomas Haller
5023af9b84 platform: sort slaves after their master devices
Slaves should get sorted after their masters so that when generating
connections, the NMManager knows about the masters already.

The convoluted logic here is to ensure that:

1) the kernel doesn't pass bad information that causes NM to crash
or infinite loop

2) that with complicated parent/child relationships (like a VLAN interface
with a parent that is also a slave), children always get sorted after
*all* of their ancestors.  The previous code was only sorting children
after their immediate parent/master's ifindex, but not actually after
the parent in the returned list.
2013-11-08 16:46:44 -06:00
Thomas Haller
ac94d83f04 core: add ifa_flags to NMPlatformIP6Address structure
Add a field 'flags' to NMPlatformIP6Address that holds the
IFA_F_* flags as reported over netlink.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-11-08 00:46:33 +01:00
Thomas Haller
69d154012d core: omit "dev -" for *_to_string of NMPlatformIP* addresses and routes
The NMPlatformIP[46]Address and NMPlatformIP[46]Route structs have a
field 'dev'. Before this field was always printed in the *_to_string
functions and a missing device was signaled as ' dev -'.
This had the advantage, that the output contained the same fields
regardless whether there was a device set or not.

Change it, not to print the device if it is not set. This has the
advantage, that it looks better in the logfiles.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-11-08 00:45:44 +01:00
Dan Winship
b7300bbe5a core: improve handling of NPAR/SR-IOV devices (rh #804527)
Use the new kernel physical_port_id interface property to recognize
when two devices are just virtual devices sharing the same physical
port, and refuse to bond/team multiple slaves on the same port.
2013-11-06 10:26:16 -05:00
Thomas Haller
b1113a0a59 core: add nm_platform_ip[46]_*_cmp functions
New functions to compare two instances of NMPlatformIP4Address, NMPlatformIP6Address,
NMPlatformIP4Route, NMPlatformIP6Route, respectively.

These functions return -1, 0 or 1 as result of the comparison. This is similar to
strcmp with the additional restriction, that only one of these 3 values will be
returned.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-09-25 23:12:37 +02:00
Pavel Šimerda
e96b5d82bd platform: fix and simplify address lifetime compensation
Acked-by: Dan Williams <dcbw@redhat.com>
2013-08-31 00:47:11 +02:00
Thomas Haller
38213b0524 platform: add nm_platform_*_to_string functions
Add *_to_string functions for address (ip4 and ip6) and
route (ip4 and ip6). Also refactor the previously existing
nm_platform_ip4_route_to_string function.

The to_string function returns a pointer to an internal
buffer. Also update log_* functions to make use of the new
to_string functions.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-08-29 22:16:45 +02:00
Thomas Haller
c822b12cf1 core: add nm_platform_ip4_route_to_string for debugging
Add convenience function to convert an IPv4 route to string.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-08-26 23:37:36 +02:00
Dan Winship
1d3ae22905 platform: fix initial link-added emission
nm_platform_query_devices() wasn't including the new "reason" argument
in its link-added emissions. (This didn't cause any problems since
NMManager doesn't look at that argument anyway, but it's still
obviously wrong.)
2013-08-06 16:36:51 -05:00
Dan Williams
7570832b20 platform: simplify getting routes and ignoring the default route
Most places except the tests don't want the default route when asking
the platform for all routes, so make that simpler by just adding a
parameter for including the default route or not.
2013-08-03 00:14:19 -05:00
Pavel Šimerda
356cad68fa platform: add reason attribute to all signals 2013-08-02 23:12:21 +02:00
Pavel Šimerda
2167e4376b Revert "platform: work around missing kernel netlink notifications of default route changes"
This reverts commit 42b4323902.
2013-08-02 22:17:06 +02:00
Pavel Šimerda
5dd15bd459 platform: don't check for route existence
This is the same we already did for nm-platform addresses in commit
68c3e1153c. It will help to avoid various
issues and is also a step towards support for route lifetimes.
2013-08-01 18:09:03 +02:00
Dan Williams
42b4323902 platform: work around missing kernel netlink notifications of default route changes
It appears the kernel does not send notifications via netlink if the
default route is removed in some cases.  This causes the platform
route cache to become stale, and thus when the default route is
reset by NM the platform thinks the route already exists, and does
not add it.  But the route doesn't exist, becuase the kernel silently
removed it without telling anyone.

Fix that with a big hammer by flushing/refilling the route cache when
devices are deactivated (deletion of their addresses causes the default
route to be removed by the kernel) and when the default route is
updated by NM itself.

Pavel: if we find a more granular method, we should probably revert
this as the cache refill can be expensive.
2013-07-31 12:14:52 -05:00
Pavel Šimerda
e59949c7cf platform: show address lifetimes in debug 2013-07-30 16:36:47 +02:00
Pavel Šimerda
68c3e1153c platform: update all address lifetimes
The nm_platform_ip[46]_address_sync() functions no longer use
nm_platform_ip[46]_address_exists() to avoid adding already
existing addresses. That means nm_platform_ip[46]_address_add()
is now called for *all* commited addresses and the lifetimes
are thus always updated.

Because of that, nm_platform_ip[46]_address_add() had to be modified to
accept existing addresses and update their lifetimes when appropriate.

https://bugzilla.gnome.org/show_bug.cgi?id=705102
2013-07-30 11:40:19 +02:00
Pavel Šimerda
3cf1b71de2 platform: simplify address comparisons 2013-07-30 11:40:19 +02:00
Pavel Šimerda
22c4f5f5af platform: handle empty arrays in array_contains_ip[46]_*() 2013-07-30 11:40:19 +02:00
Dan Williams
9fea2430bd platform: temporarily work around mismatching lifetime/timestamp/preferred (bgo #705102)
Addresses in the platform cache will have timestamp/lifetime/preferred set,
but addresses to be added or removed (like new IP config from DHCP renewal
or new RAs) won't have these set, since they only get set when the address
is actually added to the kernel.  So when syncing addresses, we can't look
at any of these items or nothing matches, and all existing addresses get
removed.

https://bugzilla.gnome.org/show_bug.cgi?id=705102
2013-07-29 14:54:25 -05:00
Pavel Šimerda
f121995fad platform: add support for address lifetimes 2013-07-26 22:45:15 +02:00
Pavel Šimerda
1c88de0488 platform: remove nm_platform_delete_device_by_name() 2013-07-26 21:10:27 +02:00
Pavel Šimerda
801434ce45 platform: don't remove default route in *_route_sync() 2013-07-22 13:03:46 +02:00
Pavel Šimerda
b0ae0be291 platform: use the term 'software devices' consistently 2013-06-26 22:38:55 +02:00
Pavel Šimerda
9d92275ac9 platform: add link type classification 2013-06-26 22:29:11 +02:00
Pavel Šimerda
1c078e9bd5 platform: log route metric 2013-06-26 19:58:18 +02:00
Pavel Šimerda
a19e1d6f61 platform: make log_* consistent 2013-06-26 19:58:18 +02:00