Commit Graph

748 Commits

Author SHA1 Message Date
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
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
Kai-Heng Feng
b95556eb78 platform: wifi: use nmp_utils_open_sysctl() to check if device is wifi
Since function nmp_utils_open_sysctl() can avoid race condition, use it
in wifi_utils_is_wifi() to open sysfs and correctly check if it's a wifi
device.

https://bugzilla.gnome.org/show_bug.cgi?id=775613
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
2016-12-13 11:26:58 +01:00
Thomas Haller
7744fdd00f platform: rename _assert_netns_current() to a ASSERT_NETNS_CURRENT()
This assert, although being a regular function has more the character
of a macro as it only contains asserts itself.
2016-12-13 11:26:58 +01:00
Thomas Haller
ed82b6bcb3 platform: increase initial buffer size of libnl's nl_recvmsg() to 32K
Since commit 9fafb382db, we would
explicitly set libnl's socket buffer size to 4*getpagesize().
That is also the default of libnl itself. Additionally, we would
workaround too small buffers by increasing the buffer size up to 512K.

A too small buffer causes messages to be lost. Usually, that only
results in a cache-resync, which isn't too bad. Lost messages are however
a problem if the lost message was an ACK that we were waiting for.
However, it is rather unlikely to happen, because it's expected that
the buffer size gets adjusted already when the cache is filled initially,
before any other requests are pending.

Still, let's increase the default buffer size to 32K, hoping that this
initial value is already large enough to avoid the problem altogether.

Note that iproute2 also uses a buffer size of 32K [1] [2].

Alternatively, we could use MSG_PEEK like systemd does [3]. However,
that requires two syscalls per message.

[1] https://patchwork.ozlabs.org/patch/592178/
[2] https://git.kernel.org/cgit/linux/kernel/git/shemminger/iproute2.git/tree/lib/libnetlink.c?id=f5f760b81250630da23a4021c30e802695be79d2#n274
[3] cd66af2274/src/libsystemd/sd-netlink/netlink-socket.c (L323)
2016-12-02 15:23:11 +01:00
Thomas Haller
ce2d1f062b platform: don't use static temporary cache_id
This only saves some typing at a few places. In general, avoid
static variables, so drop it in favor of a stack-allocated
cache_id.
2016-12-01 10:57:35 +01:00
Thomas Haller
9fafb382db platform: workaround NLE_MSG_TRUNC failure of nl_recv() with too small buffer size
We don't want to enable MSG_PEEK due to the overhead. But when we detect
that we just lost a message due to MSG_TRUNC, increase the buffer size and
retry.

See-also: 55ea6e6b6c
2016-11-30 17:01:35 +01:00
Lubomir Rintel
b49c194f84 linux: don't assume short write when the kernel ignores the trailing whitespace
Certain sysctls don't appreciate the final newline. That's completely
fine.

  17941 open("/proc/sys/net/ipv6/conf/eth2/forwarding", O_WRONLY|O_TRUNC) = 21
  17941 write(21, "1\n", 2)               = 1
2016-11-09 15:06:20 +01:00
Thomas Haller
3bbc55fd9c core: don't use generated glib enum for platform types 2016-10-22 17:16:17 +02:00
Beniamino Galvani
89bcf50f61 platform: avoid unaligned access to link stats on 64bit architectures
The undefined behavior sanitizer complains with:

platform/nm-linux-platform.c:1482:31: runtime error: member access within misaligned address 0x61a000016fac for type 'struct rtnl_link_stats64', which requires 8 byte alignment
0x61a000016fac: note: pointer points here
  bc 00 17 00 bf 05 00 00  00 00 00 00 bf 05 00 00  00 00 00 00 b5 68 02 00  00 00 00 00 b5 68 02 00
              ^
platform/nm-linux-platform.c:1483:29: runtime error: member access within misaligned address 0x61a000016fac for type 'struct rtnl_link_stats64', which requires 8 byte alignment
0x61a000016fac: note: pointer points here
  bc 00 17 00 bf 05 00 00  00 00 00 00 bf 05 00 00  00 00 00 00 b5 68 02 00  00 00 00 00 b5 68 02 00
              ^
platform/nm-linux-platform.c:1484:31: runtime error: member access within misaligned address 0x61a000016fac for type 'struct rtnl_link_stats64', which requires 8 byte alignment
0x61a000016fac: note: pointer points here
  bc 00 17 00 bf 05 00 00  00 00 00 00 bf 05 00 00  00 00 00 00 b5 68 02 00  00 00 00 00 b5 68 02 00
              ^
platform/nm-linux-platform.c:1485:29: runtime error: member access within misaligned address 0x61a000016fac for type 'struct rtnl_link_stats64', which requires 8 byte alignment
0x61a000016fac: note: pointer points here
  bc 00 17 00 bf 05 00 00  00 00 00 00 bf 05 00 00  00 00 00 00 b5 68 02 00  00 00 00 00 b5 68 02 00
              ^

That's because the pointer returned by nla_data() is only
32bit-aligned and using it to access structure members can cause
issues on some 64bit architectures.

Use the unaligned_read_ne64() macro to access the structure members.

https://bugzilla.gnome.org/show_bug.cgi?id=772605
2016-10-14 11:16:13 +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
4d37f7a1e9 core: refactor private data in "src"
- use _NM_GET_PRIVATE() and _NM_GET_PRIVATE_PTR() everywhere.

- reorder statements, to have GObject related functions (init, dispose,
  constructed) at the bottom of each file and in a consistent order w.r.t.
  each other.

- unify whitespaces in signal and properties declarations.

- use NM_GOBJECT_PROPERTIES_DEFINE() and _notify()

- drop unused signal slots in class structures

- drop unused header files for device factories
2016-10-04 09:50:56 +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
08f5681b0e core: const arguments for _nm_utils_ptrarray_find_*() functions 2016-09-23 15:34:17 +02:00
Thomas Haller
145d199589 platform: fix return value for error case in do_change_link_request()
There is a "goto retry" in do_change_link_request(), at that point,
seq_result has the value -EOPNOTSUPP, instead of
WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN.

Fixes: 02fb3eff48
2016-08-30 16:22:42 +02:00
Lubomir Rintel
02fb3eff48 platform: fix build
Fixes: 471521ca84187cd32afcd20aebe5a369fe7368dc
2016-08-30 15:05:41 +02:00
Thomas Haller
2bef71611b platform: workaround kernel wrongly returning ENFILE when changing MAC address
https://bugzilla.gnome.org/show_bug.cgi?id=770456
2016-08-29 11:36:01 +02:00
Thomas Haller
3dc0944677 platform: split processing result from do_change_link() 2016-08-29 11:30:50 +02:00
Thomas Haller
c930b7b4fe platform: silence error reading sysctl for non existing device
https://bugzilla.gnome.org/show_bug.cgi?id=770378
2016-08-25 15:38:28 +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
178bb25a03 platform: let _new_from_nl_link() lookup missing tb[IFLA_STATS64] data from cache 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
Beniamino Galvani
45484af2af platform: wifi: drop old wifi data when an interface is renamed
Drop the old wifi data when the interface is renamed, otherwise WEXT
methods would use the old name.

https://bugzilla.gnome.org/show_bug.cgi?id=768433
2016-07-08 13:40:10 +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
Thomas Haller
66715515dc platform: avoid crash after calling nl_recv() for old libnl3 version
nl_recv() in libnl3 before version 3.2.15 would return dangling pointers
if nl_recv() fails or has nothing to read [1].

Workaround that by explicitly clearing @buf and @creds.

https://bugzilla.gnome.org/show_bug.cgi?id=767986

[1] 69468517d0
2016-06-24 19:10:03 +02:00
Dan Williams
16c368b8eb platform: recognize rmnet and ccmni interfaces as WWAN network devices
https://mail.gnome.org/archives/networkmanager-list/2016-June/msg00087.html
2016-06-17 11:08:51 +02:00
Dan Williams
f969193db4 platform/trivial: rename NM_LINK_TYPE_WWAN_ETHERNET to NM_LINK_TYPE_WWAN_NET
Some newer WWAN netdev types are "rawip" which don't bother with
ethernet framing.
2016-06-17 11:00:10 +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
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
Lubomir Rintel
76ee40cb58 linux: use the utility functionality to convert the token from platform 2016-05-30 16:14:04 +02:00
Thomas Haller
791cbd0817 platform: handle missing netlink attribute IFLA_ADDRESS by cache-lookup
Sometimes the netlink event lacks the IFLA_ADDRESS attribute with
the MAC address of the link. In this case, take the value from
the cached link instance. A missing netlink attribute should have the
meaning of reusing the previous value, not clearing the address.
2016-05-25 15:11:47 +02:00
Thomas Haller
02e84ba1e8 platform: ensure refetching routes when link goes down
It's not enough to consider IF_LOWER_UP flag. Instead,
the important flag is actually IF_UP.

Actually, I suspect that IF_LOWER_UP is not needed. But for
now leave it, in order not to break something.
2016-05-12 14:50:01 +02:00
Thomas Haller
aaa28d4d40 platform: add nm_linux_platform_lookup()
Give a direct access to the cache to lookup values there. This is only
useful for testing.
2016-04-28 12:53:21 +02:00
Thomas Haller
4c2410bc92 platform: extend NMIPConfigSource to preserve the rtm_protocol field
For addresses (NMPlatformIPAddress) the @addr_source field is ignored
on a platform level. That is, all addresses inside the platform cache
have this value set to NM_IP_CONFIG_SOURCE_KERNEL. Maybe, for that reason,
the source should not be a part of the NMPlatformIPAddress structure, but
it is convenient for users to piggy back the source inside the platform
address structure.

For routes, the source is stored in NMPlatformIPRoute's @rt_source
field. When adding a route to kernel, we set the @rtm_protocol of the
route depending on the source. However, we want to map different source
values to the same protocol value.

On the other hand, when kernel sends us a route that gets put inside
the cache, we must preserve the protocol value and must not map
different protocol values to the same source.
The reason is, that a user can add two routes that only differ by
@rtm_protocol. In that sense, the @rtm_protocol fields is part of the
unique ID of a kernel route, and thus different values must map to
different sources.

Fix this, by extending the range of NMIPConfigSource to contain
a range of protocol fields.
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
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
5fe99a1d1a core: add nm_utils_ipx_address_clear_host_address() util 2016-04-28 12:53:21 +02:00
Lubomir Rintel
dd4d8b24da linux-platform: re-read the link type if the name changed
For some device types, we use the DEVTYPE from sysfs to determine the
link type. However, the way we read from sysfs can race with device
renames and we could miss the chance to read DEVTYPE correctly.

This doesn't completely fix the sysfs race, but cures the boot-time race
with systemd renaming the device while we are initializing the link.

We ideally should use GUDev for all sysfs accesses, but that would need
some more work for this particular case as currently we need the link type
before we have an udev device instance.

https://bugzilla.gnome.org/show_bug.cgi?id=764803

Co-Authored-By: Beniamino Galvani <bgalvani@redhat.com>
2016-04-26 12:20:42 +02:00
Thomas Haller
a6477fca48 platform: stack-allocate anycast_mask path in _linktype_get_type() 2016-04-21 15:05:34 +02:00
Thomas Haller
e714a20bc2 platform: refactor wifi_utils_is_wifi() not to pass sysfs_path
wifi_utils_is_wifi() only has one caller, so it's very clear
what the passed in @sysfs_path contains. Instead of accepting
a redundant argument, compute the sysfs path internally based
on @iface alone.
2016-04-21 15:05:34 +02:00
Thomas Haller
aa509fd8fe platform: stack-allocate temporary string in _linktype_read_devtype()
And while at it, don't pass the sysfs_path but instead the ifname to it.
2016-04-21 15:02:22 +02:00
Thomas Haller
d52a88a3f8 platform: request link after deleting inifiniband partition
After issuing the sysctl "delete_child", we must request the
link to get the platform cache in sync.
2016-04-20 13:21:05 +02:00
Thomas Haller
b103af0f1e platform: stack allocate string buffers in _infiniband_partition_action() 2016-04-20 12:09:40 +02:00
Thomas Haller
9c323261ea platform: use nm_utils_new_infiniband_name() 2016-04-20 12:09:40 +02:00
Thomas Haller
67d45ea1d3 platform: preserve errno in nm_platform_sysctl_set()
We want to preserve the relevant errno during nm_platform_sysctl_set().
Also, if the final close() fails, fail altogether.
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
940a423de4 platform: add functionality to remove infiniband partitions 2016-04-20 10:49:00 +02:00
Thomas Haller
201d91115c linux-platform: fix crash in _new_from_nl_link() when sharing lnk data
We want to reuse an existing (equal) lnk-data from the cache.

  NetworkManager[20977]: <debug> [1460993609.1427] platform: signal: link   added: 11: qib_ib0.8002@4 <UP,LOWER_UP;broadcast,multicast,up,running,lowerup> mtu 65520 arp 32 infiniband? not-init addrgenmode eui64 addr 80:00:00:11:FE:80:00:00:00:00:00:00:00:11:75:00:00:6F:33:DE driver ib_ipoib
  ...
  NetworkManager[20977]: <debug> [1460993609.1467] platform-linux: do-request-link: 11
  NetworkManager[20977]: nmp_object_ref: assertion 'NMP_OBJECT_IS_VALID (obj)' failed

  Program received signal SIGTRAP, Trace/breakpoint trap.
  g_logv (log_domain=0x55555583dcce "NetworkManager", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffffffc8e0) at gmessages.c:1046
  1046              g_private_set (&g_log_depth, GUINT_TO_POINTER (depth));
  (gdb) bt
  #0  0x00002aaaad94b8c3 in g_logv (log_domain=0x55555583dcce "NetworkManager", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffffffc8e0) at gmessages.c:1046
  #1  0x00002aaaad94ba3f in g_log (log_domain=<optimized out>, log_level=<optimized out>, format=<optimized out>) at gmessages.c:1079
  #2  0x00005555557863be in nmp_object_ref (obj=0x0) at platform/nmp-object.c:210
  #3  0x0000555555624c0e in event_handler_recvmsgs (id_only=<optimized out>, nlh=<optimized out>, cache=<optimized out>, platform=<optimized out>) at platform/nm-linux-platform.c:1568
  #4  0x0000555555624c0e in event_handler_recvmsgs (id_only=<optimized out>, msg=0x555555b0ebf0, cache=<optimized out>, platform=<optimized out>) at platform/nm-linux-platform.c:1923
  #5  0x0000555555624c0e in event_handler_recvmsgs (handle_events=<optimized out>, msg=0x555555b0ebf0, platform=<optimized out>) at platform/nm-linux-platform.c:3656
  #6  0x0000555555624c0e in event_handler_recvmsgs (platform=platform@entry=0x555555b00980 [NMLinuxPlatform], handle_events=handle_events@entry=1) at platform/nm-linux-platform.c:5886
  #7  0x0000555555626857 in event_handler_read_netlink (platform=platform@entry=0x555555b00980 [NMLinuxPlatform], wait_for_acks=wait_for_acks@entry=0) at platform/nm-linux-platform.c:5942
  #8  0x0000555555627093 in do_request_link_no_delayed_actions (platform=platform@entry=0x555555b00980 [NMLinuxPlatform], ifindex=ifindex@entry=11, name=name@entry=0x0) at platform/nm-linux-platform.c:3480
  #9  0x00005555556273d6 in delayed_action_handle_all (ifindex=11, platform=0x555555b00980 [NMLinuxPlatform]) at platform/nm-linux-platform.c:2918
  #10 0x00005555556273d6 in delayed_action_handle_all (platform=0x555555b00980 [NMLinuxPlatform]) at platform/nm-linux-platform.c:3003
  #11 0x00005555556273d6 in delayed_action_handle_all (platform=0x555555b00980 [NMLinuxPlatform], read_netlink=<optimized out>) at platform/nm-linux-platform.c:3029
  #12 0x000055555562a33f in constructed (_object=<optimized out>) at platform/nm-linux-platform.c:6241
  #13 0x00002aaaad6c0292 in g_object_new_internal (class=class@entry=0x555555b12ef0, params=params@entry=0x7fffffffd660, n_params=2) at gobject.c:1814
  #14 0x00002aaaad6c21d4 in g_object_new_valist (object_type=object_type@entry=93824998249472, first_property_name=first_property_name@entry=0x55555580629e "register-singleton", var_args=var_args@entry=0x7fffffffd7b0) at gobject.c:2034
  #15 0x00002aaaad6c25d1 in g_object_new (object_type=93824998249472, first_property_name=0x55555580629e "register-singleton") at gobject.c:1617
  #16 0x00005555555d1798 in main (argc=1, argv=0x7fffffffda58) at main.c:446

Fixes: db5d00d396
2016-04-18 17:55:02 +02:00