Commit graph

344 commits

Author SHA1 Message Date
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
Beniamino Galvani
36d9e252d2 platform: support preferred source option for IPv6 routes
Extend the support for the preferred source route option (RTA_PREFSRC)
to IPv6.
2017-03-06 15:20:25 +01:00
Thomas Haller
ed07de8667 platform: avoid printing "(null)" interface name during logging
Avoids:

    platform: link: setting up '(null)' (11)

Use nm_strquote_a() to quote the string if it is not NULL.
2017-02-10 17:31:16 +01:00
Beniamino Galvani
a347962831 platform: fix detection of primary/secondary addresses
ip4_addr_subnets_is_secondary() should fill the list of addresses in
the same subnet also when returning FALSE, because
nm_platform_ip4_address_sync() uses it.

Fixes: 2f68a50041
2017-02-08 14:47:14 +01:00
Lubomir Rintel
5b51a5f260 platform/tun: don't passing around the ifname guess
nm_platform_sysctl_open_netdir() doesn't take it anyways, gets it from
the cache.

CID 160209 (#1 of 1): Unused value (UNUSED_VALUE)
2017-01-16 22:14:47 +01:00
Beniamino Galvani
85103656e9 platform: add support for macsec links
Add support for a new macsec link type and its netlink attributes to
the platform code.
2017-01-16 17:37:14 +01:00
Beniamino Galvani
1dbd9d7948 platform: don't update IPv6 temporary addresses
The kernel already takes care of adding and updating temporary
addresses when an address with IFA_F_MANAGETEMPADDR flag is added or
updated; doing it also in nm_platform_ip6_address_sync() can overwrite
the changes done by kernel, especially because since commit
0a0bca9c7f ("ip6-config: sort addresses only when reading the
property value") there is no guarantee that temporary addresses are
before the public ones in the IPv6 configuration.

Still delete temporary addresses, but don't add or update them.
2017-01-10 15:39:15 +01:00
Thomas Haller
e8d5a8356c platform: add wrappers for if_nametoindex() and if_indextoname() 2017-01-04 14:18:01 +01:00
Thomas Haller
3641178508 platform: lookup ifname for ethtool/mii ioctl immediately before use
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 ab41c13b06 .
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.
2016-12-13 11:26:59 +01:00
Thomas Haller
22be2ae865 core: use nmp_utils_sysctl_open_netdir() for platform master/slave options 2016-12-13 11:26:59 +01:00
Thomas Haller
d3af925b91 core: use nmp_utils_sysctl_open_netdir() to read tun/tap sysctl 2016-12-13 11:26:59 +01:00
Thomas Haller
e933a2ff87 core: use nmp_utils_sysctl_open_netdir() to read infiniband sysctl 2016-12-13 11:26:58 +01:00
Thomas Haller
c85418746c platform: implement sysctl access via relative path to sysctl_open_netdir() 2016-12-13 11:26:58 +01:00
Thomas Haller
d8cefd57fb platform: add optional dirfd argument to sysctl functions
Still unused.
2016-12-13 11:26:58 +01:00
Beniamino Galvani
2f68a50041 platform: fix the order of addition of primary and secondary IPv4 addresses
nm_platform_ip4_address_sync() tries to apply the new configuration
with the minimum effort and doesn't delete addresses if they are
already present on the interface. This can break the ordering, as an
existing address would be promoted by kernel to primary, even if it
was last in our configuration.

Add some logic to ensure the correct order of addresses is always
enforced. This fixes situations like:

 # nmcli connection add type ethernet ifname eth0 con-name t \
                        ipv4.method manual \
                        ipv4.addresses "1.1.1.1/24,1.1.1.2/24,1.1.1.5/24"
 # nmcli connection up t

  => addresses are applied in the right order:
     inet 1.1.1.1/24 brd 1.1.1.255 scope global eth0
     inet 1.1.1.2/24 brd 1.1.1.255 scope global secondary eth0
     inet 1.1.1.5/24 brd 1.1.1.255 scope global secondary eth0

 # nmcli connection mod t ipv4.addresses "1.1.1.5/24,1.1.1.2/24,1.1.1.1/24"
 # nmcli device reapply eth0

  => order is wrong:
     inet 1.1.1.2/24 brd 1.1.1.255 scope global eth0
     inet 1.1.1.5/24 brd 1.1.1.255 scope global secondary eth0
     inet 1.1.1.1/24 brd 1.1.1.255 scope global secondary eth0

Co-Authored-By: Thomas Haller <thaller@redhat.com>
2016-12-05 10:56:51 +01:00
Francesco Giudici
ab0954b0e5 platform: add APIs to allow link negotiation management
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
2016-11-22 15:24:47 +01:00
Thomas Haller
002f17c25d src: drop generated nm-src-enum-types.h
We only needed proper glib enum types for having properties
and signal arguments. These got all converted to plain int,
so no longer generate such an enum type.
2016-10-22 17:16:17 +02:00
Thomas Haller
3bbc55fd9c core: don't use generated glib enum for platform types 2016-10-22 17:16:17 +02:00
Thomas Haller
b219eb19f1 build: merge "src/Makefile.am" into toplevel Makefile
Had to rename "nm-enum-types.h" because it works badly with
"libnm/nm-enum-types.h". Maybe I could fix that differently,
but duplicate names is anyway error prone.

Note that "nm-core-enum-types.h" is already taken too, so
"nm-src-enum-types.h" it is.
2016-10-19 17:16:08 +02:00
Thomas Haller
3ceaef90fe core: remove unnecessary includes to netlink/route library
We no longer use libnl-route-3 library in NetworkManager. Remove the
unnecessary includes.
2016-10-07 21:37:17 +02:00
Thomas Haller
0aa3a6dbfb core: refactor private data for NMExportedObject and others 2016-10-03 12:04:14 +02:00
Thomas Haller
a83eb773ce all: modify line separator comments to be 80 chars wide
sed 's#^/\*\{5\}\*\+/$#/*****************************************************************************/#' $(git grep -l '\*\{5\}' | grep '\.[hc]$') -i
2016-10-03 12:01:15 +02:00
Thomas Haller
3d9d91b2be platform: print rx/tx counters in nm_platform_link_to_string() 2016-08-17 16:08:21 +02:00
Thomas Haller
9c5405eba4 platform: drop nm_platform_link_get_stats()
No need to add accessors for fields of NMPlatformLink. Just access
them directly.
2016-08-17 16:08:21 +02:00
Thomas Haller
b3c376cd29 platform: fix sorting order for nm_platform_link_cmp()
nm_platform_link_cmp() shall first compare the ifindex, otherwise
the sort-order first considers rather unimportant fields instead
of the primary key: the ifindex.

Fixes: a3185f22e55484b819859cb4cef8f54385dac1a9
2016-08-17 16:08:21 +02:00
Alfonso Sanchez-Beato
6ed939e841 platform: add network statistics
Make network traffic statistics data available through the platform.
2016-08-17 15:50:20 +02:00
Thomas Haller
e8518b2a37 device: tune down warning about failure to set userspace IPv6LL on non-existing device
When a device gets removed externally, we still try to clear userspace IPv6LL address handling.
That fails, due to non-existing device. Such a failure should not be logged as warning.

    <debug> [1467723214.2078] device[0x558c59335ca0] (enp0s25): disposing
    <debug> [1467723214.2079] device[0x558c59335ca0] (enp0s25): remove_pending_action (0): 'dhcp6' not pending (expected)
    <debug> [1467723214.2079] device[0x558c59335ca0] (enp0s25): remove_pending_action (0): 'autoconf6' not pending (expected)
    <debug> [1467723214.2079] device[0x558c59335ca0] (enp0s25): will disable userland IPv6LL
    <debug> [1467723214.2079] platform-linux: link: change 20: user-ipv6ll: set IPv6 address generation mode to eui64
    <trace> [1467723214.2080] platform-linux: delayed-action: schedule wait-for-nl-response (seq 92, timeout in 0.199998611)
    <trace> [1467723214.2080] platform-linux: delayed-action: schedule refresh-link (ifindex 20)
    <trace> [1467723214.2080] platform-linux: delayed-action: handle refresh-link (ifindex 20)
    <debug> [1467723214.2080] platform-linux: do-request-link: 20
    <trace> [1467723214.2080] platform-linux: netlink: recvmsg: new message type 2, seq 92
    <debug> [1467723214.2080] platform-linux: netlink: recvmsg: error message from kernel: No such device (19) for request 92
    <trace> [1467723214.2081] platform-linux: delayed-action: complete wait-for-nl-response (seq 92, timeout in 0.199895684, failure 19 (No such device))
    <trace> [1467723214.2081] platform-linux: delayed-action: schedule wait-for-nl-response (seq 93, timeout in 0.199999306)
    <trace> [1467723214.2081] platform-linux: delayed-action: handle wait-for-nl-response (any)
    <trace> [1467723214.2081] platform-linux: netlink: recvmsg: new message type 2, seq 93
    <debug> [1467723214.2081] platform-linux: netlink: recvmsg: error message from kernel: No such device (19) for request 93
    <trace> [1467723214.2082] platform-linux: delayed-action: complete wait-for-nl-response (seq 93, timeout in 0.199921142, failure 19 (No such device))
    <debug> [1467723214.2082] platform-linux: do-change-link[20]: failure changing link: failure 19 (No such device)
    <warn>  [1467723214.2082] device (enp0s25): failed to disable userspace IPv6LL address handling

https://bugzilla.redhat.com/show_bug.cgi?id=1323571
2016-07-05 23:11:57 +02:00
Thomas Haller
f9852821e3 core: don't warn when setting address of non-existing link
Trying to set a property on a device that does not exist is not something
necessarily wrong. Don't print error/warning messages.

    <trace> [1467707267.2887] device[0x55a74adbdaf0] (enp0s25): set-hw-addr: setting MAC address to 'AA:BB:CC:DD:EE:FF' (reset, unmanage)...
    <debug> [1467707267.2887] platform: link: setting '(null)' (2) hardware address
    <debug> [1467707267.2887] platform-linux: link: change 2: address: 68:F7:28:61:68:F7 (6 bytes)
    <debug> [1467707267.2887] platform-linux: do-request-link: 2
    <debug> [1467707267.2888] platform-linux: netlink: recvmsg: error message from kernel: No such device (19) for request 226
    <debug> [1467707267.2888] platform-linux: netlink: recvmsg: error message from kernel: No such device (19) for request 227
    <error> [1467707267.2888] platform-linux: do-change-link[2]: failure changing link: failure 19 (No such device)
    <warn>  [1467707267.2888] device (enp0s25): set-hw-addr: failed to reset MAC address to 68:F7:28:61:68:F7 (unmanage)
2016-07-05 23:08:22 +02:00
Lubomir Rintel
60e2a3ea76 platform: add capability to set the tokenized interface identifier
We don't need the token set in platform for our address mode generation,
but having it set makes it possible to correctly generate and assume
connections that use tokens.
2016-05-30 16:32:07 +02:00
Lubomir Rintel
24f428f768 platform: use utility functionality to stringify link 2016-05-30 16:32:06 +02:00
Thomas Haller
e88f5a6c23 platform: remove nm_platform_link_get_ipv6_token()
No need for the extra cache lookup.
2016-05-30 16:32:06 +02:00
Thomas Haller
e5f63f2a50 platform: remove unnecessary NMPlatformLink.inet6_token.is_valid field
The only user of platform who accesses this field is NMDevice,
when calling nm_platform_link_get_ipv6_token(). It cares more
about whether the token is all-zero or set to something.

Another use of inet6_token.is_valid was so that when we receive a
netlink message without IFLA_INET6_TOKEN attribute, that we don't
treat the value as zero, although it is just unknown. Fix that
instead in a better way by setting the value from the cache, if
IFLA_AF_SPEC doesn't provide it.

Also, when printing the token in nm_platform_link_to_string()
treat it as an IPv6 address (inet_ntop).
2016-05-30 16:19:20 +02:00
Thomas Haller
d933164087 platform: change order in which fields are compared in nm_platform_ip4_route_cmp()
..., nm_platform_ip6_route_cmp(), nm_platform_ip4_address_cmp() and
nm_platform_ip6_address_cmp().

Compare those fields first, for which we expect that their properties
differ. E.g. usually, each route destination in a set is unique, thus by
comparing those fields first we shortcut some comparisons.
2016-04-28 12:53:21 +02:00
Thomas Haller
e26fcce0f8 platform: refactor marking cloned routes in platform
We handle cloned routes (that have rtm_flags RTM_F_CLONED) differently.
We used to mark such routes by hacking NMIPConfigSource to have a special
value. No longer do this, because it mixes different concepts.

Note that the rt_cloned filed fits into a hole in the aligment
of NMPlatformIPRoute. Thus there is almost no overhead to this
change.
2016-04-28 12:53:21 +02:00
Thomas Haller
9e83383223 platform: add nmp_utils_ip_config_source_to_string()
Expose nmp_utils_ip_config_source_to_string() in the header file and
implement it via NM_UTILS_ENUM2STR_DEFINE().
2016-04-28 12:53:21 +02:00
Thomas Haller
6bf022359f core/trivial: rename "source" field of addresses and routes
The "source" field of NMPlatformIPRoute (now "rt_source") maps to the
protocol field of the route. The source of NMPlatformIPAddress (now
"addr_source") has no direct equivalent in the kernel.

As their use is different, they should have different names. Also,
the name "source" is used all over the place. Hence give the fields
a more distinct name.
2016-04-28 12:53:21 +02:00
Thomas Haller
44753a590e platform: sort links by ifindex in nm_platform_link_get_all()
This way, we get a defined order at startup.

Also, get rid of the logging statements. It was used for
debugging, but a "getter" really should not log the stuff it
is returning.
2016-04-28 12:53:21 +02:00
Thomas Haller
9c323261ea platform: use nm_utils_new_infiniband_name() 2016-04-20 12:09:40 +02:00
Thomas Haller
eab817d34a platform: restrict valid p_key for infiniband partitions 2016-04-20 12:09:40 +02:00
Lubomir Rintel
745d22f08e platform: avoid using the nm_platform_link_*() getters excessively
Thomas thinks it's a sin.
2016-04-20 10:49:01 +02:00
Lubomir Rintel
940a423de4 platform: add functionality to remove infiniband partitions 2016-04-20 10:49:00 +02:00
Thomas Haller
d6b3081f7b platform: add NM_PLATFORM_NETNS_SUPPORT_DEFAULT 2016-04-11 11:26:37 +02:00
Thomas Haller
44768f0311 platform: change @plen field of NMPlatformIPxAddress to type guint8
On netlink layer, this field is uint8_t/uchar.

A larger (signed) plen makes no sense. Adjust the signatures
to have only guint8.
2016-04-11 11:26:36 +02:00