Commit graph

15 commits

Author SHA1 Message Date
Javier Arteaga
56e79a4e07 platform: move genl_ctrl_resolve to nm-netlink.c
Move genl_ctrl_resolve out of the wifi code so it can be reused by other
interfaces based on genetlink.

https://mail.gnome.org/archives/networkmanager-list/2018-March/msg00044.html
2018-03-30 22:09:04 +02: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
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
ba25221236 netlink: various cleanups and use cleanup attribute
- adjust some coding style (space after function name).
- ensure to use g_free(), as we no longer use malloc
  but the g_malloc aliases. Nowadays, glib's malloc
  is identical to malloc from the standard library and
  so this is no issue in practice. Still it's bad
  style to mix g_malloc() with free().
- use cleanup attribute for memory handling.
2018-02-21 12:08:46 +01:00
Thomas Haller
5376aa2db7 netlink: use slice allocator for "struct nl_msg" 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
a7bda2ed12 netlink: simplify netlink callback handling
With libnl3, each socket has it's own callback structure.
One would often take that callback structure, clone it, modify it
and invoke a receive operation with it.

We don't need this complexity. We got rid of all default handlers,
hence, by default all callbacks are unset.

The only callbacks that are set, are those that we specify immediately
before invoking the receive operation. Just pass the callback structure
at that point.

Also, no more ref-counting, and cloning of the callback structure. It is
so simple, just stack allocate one if you need it.
2018-02-21 12:08:46 +01:00
Thomas Haller
4da2a19a87 netlink: drop redundant nl_recvmsgs_report() function
The only difference between nl_recvmsgs_report() and nl_recvmsgs() is
the return value on success. libnl3 couldn't change that for backward
compatibility reasons. We can merge them.
2018-02-21 12:08:46 +01:00
Thomas Haller
03420e6a5c netlink: drop unused callback types 2018-02-21 12:08:46 +01:00
Thomas Haller
356332a840 netlink: remove unused callback hooks 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
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
a21a5558b1 platform: move genl functions to nm-netlink.c
So they can be reused outside of wifi, like for implementing
wireguard support.
2018-01-15 20:29:26 +01:00
Thomas Haller
9562d88633 platform: add nm-netlink.h for netlink related helper functions
Especially useful, because we don't link against libnl-genl-3.so
but re-implement generic netlink support. Such code should go there
so it can be used by various components.
2018-01-15 20:29:26 +01:00