NetworkManager/shared
Beniamino Galvani 1350134947 n-dhcp4: discard NAKs from other servers in SELECTING
I got a report of a scenario where multiple servers reply to a REQUEST
in SELECTING, and all servers send NAKs except the one which sent the
offer, which replies with a ACK. In that scenario, n-dhcp4 is not able
to obtain a lease because it restarts from INIT as soon as the first
NAK is received. For comparison, dhclient can get a lease because it
ignores all NAKs in SELECTING.

Arguably, the network is misconfigured there, but it would be great if
n-dhcp4 could still work in such scenario.

According to RFC 2131, ACK and NAK messages from server must contain a
server-id option. The RFC doesn't explicitly say that the client
should check the option, but I think it's a reasonable thing to do, at
least for NAKs.

This patch stores the server-id of the REQUEST in SELECTING, and
compares it with the server-id from NAKs, to discard other servers'
replies.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1144
(cherry picked from commit 118561e284)
(cherry picked from commit 3abfdbab33)
(cherry picked from commit c499412ec4)
(cherry picked from commit bfca239a27)
2022-03-24 15:55:51 +01:00
..
c-list shared/c-list: reimport 2021-01-20 11:07:23 +01:00
c-rbtree shared/c-rbtree: reimport 2021-01-15 11:16:25 +01:00
c-siphash shared/c-siphash: reimport 2021-01-15 11:17:32 +01:00
c-stdaux shared/c-siphash: reimport 2021-01-15 11:19:04 +01:00
n-acd all: fix minor typos 2020-07-07 11:33:46 +02:00
n-dhcp4 n-dhcp4: discard NAKs from other servers in SELECTING 2022-03-24 15:55:51 +01:00
nm-base shared: copy file instead of symlink "nm-ethtool-utils.h" 2021-02-09 12:38:19 +01:00
nm-glib-aux glib-aux: add _nm_utils_ascii_str_to_int64_bin() helper 2021-10-05 09:35:48 +02:00
nm-log-core all: add "nm-glib-aux/nm-default-glib-i18n-lib.h" as replacement for "nm-default.h" 2021-02-09 12:38:17 +01:00
nm-platform platform: fix releasing thead-local stack of NMPNetns instances 2021-07-16 18:40:00 +02:00
nm-std-aux std-aux/glib-aux: move NM_AUTO_PROTECT_ERRNO() to libnm-std-aux 2021-07-16 18:40:00 +02:00
nm-udev-aux all: add "nm-glib-aux/nm-default-glib-i18n-lib.h" as replacement for "nm-default.h" 2021-02-09 12:38:17 +01:00
nm-utils tests: add "/bin:/sbin" to "$PATH" for unit tests 2021-02-15 14:03:20 +01:00
systemd systemd: add nm_sd_dns_name_normalize() accessor 2021-02-11 09:23:07 +01:00
meson.build libnm: move "nm-version-macros.h" from shared/ to libnm-core/ 2021-02-09 12:38:19 +01:00
nm-test-libnm-utils.h all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
nm-test-utils-impl.c all: add "libnm/nm-default-libnm.h" as replacement for "nm-default.h" 2021-02-09 12:38:18 +01:00
README.md shared: add "shared/README.md" 2021-01-15 12:17:15 +01:00

The "shared/" Directory

For NetworkManager we place helper/utility code under "shared/" in static libraries. The idea is to avoid code duplication but also provide high quality helper functions that simplify the higher layers. In NetworkManager there are complicated parts, for example "src/nm-manager.c" is huge. On the other hand, this helper code should be simple and easy to understand, so that we can build more complex code on top of it.

As we statically link them into our binaries, they are all inherently internal API, that means they cannot be part of libnm's (libnm-core's) public API. It also means that their API/ABI is not stable.

We don't care these libraries to be minimal and contain only symbols that are used by all users. Instead, we expect the linker to throw away unused symbols. We achieve this by having a symbol versioning file to hide internal symbols (which gives the linker a possibility to remove them if they are unused) and compiling with LTO or "-Wl,--gc-sections". Let the tool solve this and not manual organization.

Hence these libraries (and their content) are structured this way to satisfy the following questions:

  1. which dependencies (libraries) do they have? That determines which other libraries can use it. For example:

    • "shared/nm-std-aux" and "shared/nm-glib-aux" both provide general purpose helpers, the difference is that the former has no dependency on glib2 library. Both these libraries are a basic dependency for many other parts of the code.

    • "shared/nm-udev-aux" has a dependency on libudev, it thus cannot be in "shared/nm-glib-aux".

    • client code also has a glib2 dependency. That means it can link with "shared/nm-std-aux" and "shared/nm-glib-aux", but must not link with "shared/nm-udev-aux" (as it has no direct udev dependenct -- although clients get it indirectly because libnm already requires it).

  2. what is their overall purpose? As said, we rely on the linker to prune unused symbols. But in a few cases we avoid to merge different code in the same library. For example:

    • "shared/nm-glib-aux" and "shared/nm-base" both only have a glib2 dependency. Hence, they could be merged. However we don't do that because "shared/nm-base" is more about NetworkManager specific code, while "shared/nm-glib-aux" is about general purpose helpers.
  3. some of these libraries are forked from an upstream. They are kept separate so that we can re-import future upstream versions.

Detail

  • shared/c-list

  • shared/c-rbtree

  • shared/c-siphash

  • shared/c-stdoux

  • shared/n-acd

  • shared/n-dhcp4

    These are forked from upstream and imported with git-subtree. They in general only have a libc dependency (or dependencies between each other).

  • shared/nm-std-aux

    This contains helper code with only a libc dependency. Almost all C code depends on this library.

  • shared/nm-glib-aux

    Like "shared/nm-std-aux" but also has a glib2 dependency. Almost all glib2 code depends on this library.

  • shared/nm-udev/aux

    Like "shared/nm-glib-aux" but also has a libudev dependency. It has code related to libudev.

  • shared/systemd

    These are forked from upstream systemd and imported with a script. Under "shared/systemd/src" we try to keep the sources as close to the original as possible. There is also some adapter code to make it useable for us. It has a dependency on "shared/nm-glib-aux" and will need a logging implementation for "shared/nm-glib-aux/nm-logging-fwd.h".

  • shared/nm-base

    Depends on "shared/nm-glib-aux" and glib2 but it provides helper code that more about NetworkManager specifc things.

  • shared/nm-log-core

    This is the logging implementation as used by NetworkManager core ("src/"). It is also a dependency for "shared/nm-platform".

  • shared/nm-platform

    Platform implementation. It depends on "shared/nm-log-core", "shared/nm-base" and "shared/nm-glib-aux".

  • Other than that, there are still a few unorganized files/directories here. These should be cleaned up.