Commit graph

436 commits

Author SHA1 Message Date
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
Thomas Haller
14ee5dd2f8 platform: change @plen field of NMPlatformIPxRoute 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
Thomas Haller
207c0f5f81 platform: add nm_platform_link_can_assume() 2016-04-04 15:33:16 +02:00
Thomas Haller
c7aea6b620 platform: use gint32 for monotonic-timestamp seconds
@now is obtained via nm_utils_get_monotonic_timestamp_s(),
which is gint32 (although it will never be negative).

Use the correct type.
2016-03-15 18:28:43 +01:00
Thomas Haller
6cb7322465 platform: remove padding for IP address lifetimes
We used to pad the lifetime since the beginning (commit
f121995fad).

However, there is not race involved, since our platform cache
is in sync with the messages from kernel (which didn't used to
be the case).

Also, when receiving a RA with a zero preferred time, we must
not extend the address lifetime by 5 seconds, but instead deprecate
the address immediately.

https://bugzilla.gnome.org/show_bug.cgi?id=763513
2016-03-15 18:28:43 +01:00
Stjepan Gros
9995699116 platform: add nm_platform_link_set_netns() function
[thaller@redhat.com: cherry-picked original patch and modified
  slightly]
2016-03-15 12:56:58 +01:00
Thomas Haller
b36d721525 all: drop str_if_set() in favor of the "?:" operator
str_if_set() was added to replace the non-standard gcc extension "?:".
However, "?:" is supported by clang as well and we already use it at
several places.

Also, str_if_set() did not follow our naming scheme and renaming to
nm_str_if_set() would be ugly. So just drop it.
2016-03-08 17:57:20 +01:00
Thomas Haller
d5cc42ff6f core/trivial: rename NM_ASSERT_VALID_PATH_COMPONENT() helper
All defines from header files must have a NM prefix.
2016-03-08 17:45:50 +01:00
Thomas Haller
c7b3862503 platform: add network namespace support to platform
Add a new NMPNetns class. This allows creation, deletion and
switching of network namespaces. The API only offers push/pop
operations to switch the namespace. This way the API enforces
the user to always restore the previous namespace.

A NMPlatform instance not only uses the netlink socket, but also
sysfs, udev, ethtool, mii. Still, a NMPlatform instance lives
entirely inside one namespace and is not spanning multiple namespaces.
To properly support network namespaces, the platform instance must
switch the namespace as necessary, transparent to the caller.
Udev is only supported in the main namespace.

For now, network namespaces are not actually used and are disabled
via the NM_PLATFORM_NETNS_SUPPORT argument.

https://bugzilla.gnome.org/show_bug.cgi?id=762408
2016-03-07 12:28:13 +01:00