Commit Graph

748 Commits

Author SHA1 Message Date
Lubomir Rintel
2af11440f9 platform/linux: add support for 6LoWPAN links 2018-06-26 16:21:55 +02:00
Lubomir Rintel
a7d2cad67e platform/linux: add support for WPAN links 2018-06-26 16:21:54 +02:00
Lubomir Rintel
c630a6a2c9 platform/linux: recognize 6LoWPAN links 2018-06-26 16:21:54 +02:00
Lubomir Rintel
4e3d2f5a85 platform/linux: recognize WPAN links 2018-06-26 16:21:54 +02:00
Lubomir Rintel
6371f399ae platform: move the management of the genl socket to linux-platform
We're fine with a single genl socket instead of opening a new one for each
WifiData instance.
2018-06-26 16:21:54 +02:00
Lubomir Rintel
123b79518c platform: attach WifiData to NMPObject
This fixes leakage of the WifiData structures.
2018-06-26 16:21:54 +02:00
Lubomir Rintel
0b4010d740 platform: don't initialize pllink when not needed 2018-06-26 16:21:54 +02:00
Lubomir Rintel
787dc484b3 platform/wifi: turn NMWifiUtils into a GObject 2018-06-26 16:21:54 +02:00
Lubomir Rintel
91c82cc465 platform/wifi: rename wifi-utils to nm-wifi-utils 2018-06-26 16:21:54 +02:00
Lubomir Rintel
2c3a14fed3 platform/wifi: drop *_get_wowlan()
It's redundant and was probably just left in a an oversight.
*_get_wake_on_wlan() now does the same thing.
2018-06-26 16:21:54 +02:00
Alfonso Sánchez-Beato
ac13027934 platform: add methods to retrieve current WoWLAN state 2018-06-22 13:54:37 +02:00
Simon Fels
1621c79e7b platform: add support for wake-on-wlan
Co-authored-by: Alfonso Sanchez-Beato <alfonso.sanchez-beato@canonical.com>
2018-06-15 09:46:26 +02:00
Lubomir Rintel
e69d386975 all: use the elvis operator wherever possible
Coccinelle:

  @@
  expression a, b;
  @@
  -a ? a : b
  +a ?: b

Applied with:

  spatch --sp-file ternary.cocci --in-place --smpl-spacing --dir .

With some manual adjustments on spots that Cocci didn't catch for
reasons unknown.

Thanks to the marvelous effort of the GNU compiler developer we can now
spare a couple of bits that could be used for more important things,
like this commit message. Standards commitees yet have to catch up.
2018-05-10 14:36:58 +02:00
Beniamino Galvani
1b5925ce88 all: remove consecutive empty lines
Normalize coding style by removing consecutive empty lines from C
sources and headers.

https://github.com/NetworkManager/NetworkManager/pull/108
2018-04-30 16:24:52 +02:00
Thomas Haller
ef93f6caad platform: support creating non-persistant TUN/TAP devices
For completeness, extend the API to support non-persistant
device. That requires that nm_platform_link_tun_add()
returns the file descriptor.

While NetworkManager doesn't create such devices itself,
it recognizes the IFLA_TUN_PERSIST / IFF_PERSIST flag.
Since ip-tuntap (obviously) cannot create such devices,
we cannot add a test for how non-persistent devices look
in the platform cache. Well, we could instead add them
with ioctl directly, but instead, just extend the platform
API to allow for that.

Also, use the function from test-lldp.c to (optionally) use
nm_platform_link_tun_add() to create the tap device.
2018-04-09 20:16:31 +02:00
Thomas Haller
722f79c9c5 platform: workaround kernel issue for tun device for first RTM_NETLINK event
Due to a bug, the current rc-kernel will emit the first netlink
notification about tun devices before the device is initialized.

Hence, the content of the message is bogus. If the message
looks like to be this case, re-request it right away.
2018-04-09 20:16:30 +02:00
Thomas Haller
f76a94668d platform: refetch TUN link when no type-specific lnk data was received
Now that kernel supports providing information about tun/tap devices
via netlink, make use of it.

Also, enable the hack that:
  - when we first see a link that has no lnk data, we refetch
    it on the assumption, that kernel just didn't send it
    the first time.

For old kernels that do not yet support tun properties on netlink,
this means that we will always refetch the link once, the first
time we see it. I think that is acceptable, and the more correct
behavior for newer kernels that do support it.
2018-04-09 20:16:30 +02:00
Thomas Haller
031e58e1cf platform: enable parsing tun/tap properties from netlink
Now that the kernel patches are merged to mainline (rc), enable accepting
tun/tap link properties from netlink.

https://bugzilla.redhat.com/show_bug.cgi?id=1547213
2018-04-09 20:16:30 +02:00
Thomas Haller
e8a9bffdb0 platform: refactor fetching links in cache_on_change()
Rework the code to if-else-if, to not schedule the same
DELAYED_ACTION_TYPE_REFRESH_LINK instance multiple times.

Note that delayed_action_schedule() already would check that
no duplicates are scheduled, but we can avoid that.
2018-04-09 20:16:30 +02:00
Thomas Haller
28b5118ad2 platform: assert in nm_platform_link_tun_add() for unsupported options
It doesn't make sense that NetworkManager adds non-persist tun
devices, likewise, only the type IFF_TUN or IFF_TAP is supported.

Assert that the values are as expected.
2018-04-09 20:16:30 +02:00
Thomas Haller
39ab38a04d core/platform: add support for TUN/TAP netlink support and various cleanup
Kernel recently got support for exposing TUN/TAP information on netlink
[1], [2], [3]. Add support for it to the platform cache.

The advantage of using netlink is that querying sysctl bypasses the
order of events of the netlink socket. It is out of sync and racy. For
example, platform cache might still think that a tun device exists, but
a subsequent lookup at sysfs might fail because the device was deleted
in the meantime. Another point is, that we don't get change
notifications via sysctl and that it requires various extra syscalls
to read the device information. If the tun information is present on
netlink, put it into the cache. This bypasses checking sysctl while
we keep looking at sysctl for backward compatibility until we require
support from kernel.

Notes:

- we had two link types NM_LINK_TYPE_TAP and NM_LINK_TYPE_TUN. This
  deviates from the model of how kernel treats TUN/TAP devices, which
  makes it more complicated. The link type of a NMPlatformLink instance
  should match what kernel thinks about the device. Point in case,
  when parsing RTM_NETLINK messages, we very early need to determine
  the link type (_linktype_get_type()). However, to determine the
  type of a TUN/TAP at that point, we need to look into nested
  netlink attributes which in turn depend on the type (IFLA_INFO_KIND
  and IFLA_INFO_DATA), or even worse, we would need to look into
  sysctl for older kernel vesions. Now, the TUN/TAP type is a property
  of the link type NM_LINK_TYPE_TUN, instead of determining two
  different link types.

- various parts of the API (both kernel's sysctl vs. netlink) and
  NMDeviceTun vs. NMSettingTun disagree whether the PI is positive
  (NM_SETTING_TUN_PI, IFLA_TUN_PI, NMPlatformLnkTun.pi) or inverted
  (NM_DEVICE_TUN_NO_PI, IFF_NO_PI). There is no consistent way,
  but prefer the positive form for internal API at NMPlatformLnkTun.pi.

- previously NMDeviceTun.mode could not change after initializing
  the object. Allow for that to happen, because forcing some properties
  that are reported by kernel to not change is wrong, in case they
  might change. Of course, in practice kernel doesn't allow the device
  to ever change its type, but the type property of the NMDeviceTun
  should not make that assumption, because, if it actually changes, what
  would it mean?

- note that as of now, new netlink API is not yet merged to mainline Linus
  tree. Shortcut _parse_lnk_tun() to not accidentally use unstable API
  for now.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1277457
[2] https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git/commit/?id=1ec010e705934c8acbe7dbf31afc81e60e3d828b
[3] https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=118eda77d6602616bc523a17ee45171e879d1818

https://bugzilla.redhat.com/show_bug.cgi?id=1547213
https://github.com/NetworkManager/NetworkManager/pull/77
2018-03-20 11:59:52 +01:00
Thomas Haller
e81224824a platform: pre-increment netlink sequence number and add comment
Pre-increment. That allows to not explicitly initialize nlh_seq_next
in nm_linux_platform_init().
2018-03-09 17:52:43 +01:00
Beniamino Galvani
a2f1a93817 platform: remove unused typedef 2018-03-09 17:52:43 +01:00
Beniamino Galvani
773ab140d2 platform: return extack message from WaitForNlResponse delayed action
Return the extended ack message from the WaitForNlResponse delayed
action so that the caller can print a detailed reason with the
appropriate logging level.
2018-03-09 17:52:43 +01:00
Beniamino Galvani
b107e121b0 platform: print error message from netlink extended ack
From v4.12 the kernel appends some attributes to netlink acks
containing a textual description of the error and other fields (see
commit [1]). Parse those attributes and print the error message.

Examples:

platform-linux: netlink: recvmsg: error message from kernel: Network is unreachable (101) "Nexthop has invalid gateway" for request 12

platform-linux: netlink: recvmsg: error message from kernel: Invalid argument (22) "Local address cannot be multicast" for request 21

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2d4bc93368f5a0ddb57c8c885cdad9c9b7a10ed5
2018-03-09 17:52:43 +01:00
Beniamino Galvani
2d1fad641b platform: don't require cloned flag for RTM_GETROUTE IPv6 result
IPv4 routes that are a response to RTM_GETROUTE must have the cloned
flag while IPv6 routes don't have to. Don't check the flag for IPv6
routes and add a test case to verify that RTM_GETROUTE works for IPv6.

https://bugzilla.gnome.org/show_bug.cgi?id=793962
2018-03-05 18:47:25 +01:00
Thomas Haller
d074ffc836 platform: refactor completing netlink responses in event_handler_read_netlink()
- refactor the loop in event_handler_read_netlink() to mark pending
  requests as answered by adding a new helper function
  delayed_action_wait_for_nl_response_complete_check()

- delayed_action_wait_for_nl_response_complete_all() can be implemented
  in terms of delayed_action_wait_for_nl_response_complete_check()

- if nm_platform_netns_push() fails, also complete all pending requests
  with a new error code WAIT_FOR_NL_RESPONSE_RESULT_FAILED_SETNS.
2018-02-21 12:08:46 +01:00
Thomas Haller
b3633a282d platform: cleanup error handling in event_handler_recvmsgs()
Now that we cleaned up nl_recv(), we have full control over which error
variables are returned when. We no longer need to check "errno"
directly, and we no longer need the NLE_USER_* workaround.
2018-02-21 12:08:46 +01:00
Thomas Haller
ff7f8b3a79 netlink: use glib allocator functions for nlmsg_alloc*()
Glib is not out of memory safe, meaning it always aborts the program
when an allocation fails. It is not possible to meaningfully handle
out of memory when using glib.

Replace all allocation functions for netlink message with their glib
counter part and remove the NULL checks.
2018-02-21 12:08:46 +01:00
Thomas Haller
b6f31a2d22 netlink: refactor error numbers from netlink
Originally, these were error numbers from libnl3. These error numbers
are separate from errno, which is unfortunate, because sometimes we
care about the native errno returned from kernel.

Now, refactor them so that the error numbers are in the shared realm
of errno, but failures from kernel or underlying API are still returned
via their native errno.

- NLE_INVAL doesn't exist anymore. Passing invalid arguments to a function
  is commonly a bug. g_return_*(NLE_BUG) is the right answer to that.

- NLE_NOMEM and NLE_AGAIN is replaced by their errno counterparts.

- drop several error numbers. If nobody cares about these numbers,
  there is no reason to have a specific error number for them.
  NLE_UNSPEC is sufficient.
2018-02-21 12:08:46 +01:00
Thomas Haller
f3a0f60e9a netlink: drop workaround for libnl3 bug in nl_recv() 2018-02-21 12:08:46 +01:00
Thomas Haller
3fab322a20 netlink: drop libnl3 dependency
From libnl3, we only used the helper function to parse/generate netlink
messages and the socket functions to send/receive messages. We don't
need an external dependency to do that, it is simple enough.

Drop the libnl3 dependency, and replace all missing code by directly
copying it from libnl3 sources. At this point, I mostly tried to
import the required bits to make it working with few modifications.

Note that this increases the binary size of NetworkManager by 4736 bytes
for contrib/rpm build on x86_64. In the future, we can simplify the code
further.

A few modifications from libnl3 are:

- netlink errors NLE_* are now in the domain or regular errno.
  The distinction of having to bother with two kinds of error
  number domains was annoying.

- parts of the callback handling is copied partially and unused parts
  are dropped. Especially, the verbose/debug handlers are not used.
  In following commits, the callback handling will be significantly
  simplified.

- the complex handling of seleting ports was simplified. We now always
  let kernel choose the right port automatically.
2018-02-21 12:08:46 +01:00
Thomas Haller
ffbad3d0e8 netlink: move nl_nlmsghdr_to_str() to netlink header 2018-02-21 12:08:46 +01:00
Thomas Haller
06b968a820 platform: add nm_platform_refresh_all() API
Add a function that allows to re-request all objects of a certain type.
Usually, the cache is supposed to keep itself in a consistent state and
this function is not useful.

It is however useful during testing and debugging to explicitly reload
an object type.

If you ever think to need this function in non-testing code, then
something else is probably wrong with the cache implementation.
2018-02-09 17:40:01 +01:00
Thomas Haller
d702581812 platform: move netlink functions to nm-netlink.h 2018-01-15 20:29:26 +01:00
Thomas Haller
feb1fc2e73 wifi: rework WifiData to use a separate struct for function pointers
Add a WifiDataClass struct, that is immutable and contains all the
function pointers that were previously embedded in WifiData directly.
They are not ever modified after creation, hence this allows to have
a "static const" allocated instance of the VTable.

Also rename wifi_data_deinit() to wifi_data_unref(). It does not only
deinitialize the instance, instead it also frees it. Hence, rename it
to "unref()".
2018-01-15 20:29:26 +01:00
Thomas Haller
3de3f59ffd platform: fix wrong cleanup function in ip_route_get()
Fixes: 33a2a7c3e3
2018-01-15 20:29:26 +01:00
Lubomir Rintel
f3b4053a91 platform-linux: reload qdiscs and tfilters after removing them
Kernel (as of 4.14) merely ACKs our RTM_DELQDISC and RTM_DELTFILTER, not
bothering to signal the full RTM_DEL* message unless the removal is
external to NetworkManager.

https://bugzilla.redhat.com/show_bug.cgi?id=1527197
2018-01-08 17:49:41 +01:00
Beniamino Galvani
da4c9e51a0 ip-tunnel: add support for tunnel flags
Implement support for IP tunnel flags. Currently only some IPv6 tunnel
flags are supported. Example:

 # nmcli connection add type ip-tunnel mode ip6ip6 \
   ip-tunnel.flags ip6-ign-encap-limit,ip6-use-orig-tclass \
   ifname abc ip-tunnel.parent ens8 ipv4.method disabled \
   ipv6.method manual ipv6.address ::8888 remote ::42

 # ip -d l
  61: abc@ens8: <NOARP,UP,LOWER_UP> mtu 1460 qdisc noqueue ...
    link/tunnel6 :: brd ::42 promiscuity 0
    ip6tnl ip6ip6 remote ::42 local :: dev ens8 encaplimit none
    hoplimit 0 tclass inherit ...

https://bugzilla.gnome.org/show_bug.cgi?id=791846
2018-01-05 18:25:08 +01:00
Thomas Haller
c696a226ea all: don't use NM_FLAGS_HAS() with non-constant argument
NM_FLAGS_HAS() uses a static-assert that the second argument is a
single flag (power of two). With a single flag, NM_FLAGS_HAS(),
NM_FLAGS_ANY() and NM_FLAGS_ALL() are all identical.

The second argument must be a compile time constant, and if that is
not the case, one must not use NM_FLAGS_HAS().

Use NM_FLAGS_ANY() in these cases.
2017-12-15 11:48:38 +01:00
Thomas Haller
fe3d7209e7 platform: fix TC to-string/hash/cmp functions to include the action
Also add a define NM_PLATFORM_ACTION_KIND_SIMPLE. It makes the
uses of "simple" grepable.
2017-12-11 11:08:41 +01:00
Lubomir Rintel
b0fd3ecbaf platform: add support for traffic filters 2017-12-11 11:08:41 +01:00
Lubomir Rintel
ff9f27eb12 platform: add support for queueing disciplines 2017-12-11 10:52:22 +01:00
Thomas Haller
82befe3c40 platform: add <linux/tc_act/tc_defact.h> header
We're going to need that one for TC filter & action support.

<linux/tc_act/tc_defact.h> was moved to user-space API only in 2013
by commit 5bc3db5c9ca8407f52918b6504d3b27230defedc. Our travis CI currently
fails to build due to that.

Re-implement the header.
2017-12-11 10:50:43 +01:00
Thomas Haller
7573594a21 platform: merge nm_platform_*_delete() delete functions
It only makes sense to call delete() with NMPObjects that
we obtained from the platform cache. Otherwise, if we didn't
get it from the cache in the first place, we wouldn't know
what to delete.

Hence, the input argument is (almost) always an NMPObject
in the first place. That is different from add(), where
we might create a new specific NMPlatform* instance on the
stack. For add() it makes slightly more sense to have different
functions depending on the type. For delete(), it doesn't.
2017-12-11 10:30:26 +01:00
Lubomir Rintel
ffe89f86e0 platform/linux: stringify also NLMSG_* in logs 2017-12-11 10:30:26 +01:00
Lubomir Rintel
93ac0e455b platform/trivial: s/ADDRROUTE/OBJECT/ for the cache lookup
It's going to be useful for other objects that have a type (of course)
and an ifindex.
2017-12-11 10:30:26 +01:00
Thomas Haller
93adadbdcb all: use nm_direct_hash() instead of g_direct_hash()
We also do this for libnm, where it causes visible changes
in behavior. But if somebody would rely on the hashing implementation
for hash tables, it would be seriously flawed.
2017-11-16 11:49:52 +01:00
Thomas Haller
79482c9a9e platform: fix double closing netlink socket
The file descriptor is owned by the netlink socket instance,
which we close in finalize. We most not close it when destroying
the IO channel, otherwise the file descriptor gets closed twice.

Closing an invalid file descriptor (or a descriptor that is already closed)
is a serious bug, because the integer values are re-used, so there is a race
that the close might affect an innocent file descriptor instead of just
failing with EBADF.
2017-11-14 15:10:42 +01:00
Thomas Haller
5b29c2e5b9 all: use nm_close() instead of close() 2017-11-14 15:10:42 +01:00