| 1 |
NetworkManager daemon |
| 2 |
===================== |
| 3 |
|
| 4 |
The following diagram describes the main components of the |
| 5 |
NetworkManager daemon. Note that each component is in most cases a |
| 6 |
GObject and the names always start with the "NM" prefix, which has |
| 7 |
been omitted for clarity. |
| 8 |
|
| 9 |
 |
| 10 |
|
| 11 |
## Manager |
| 12 |
|
| 13 |
The main responsibilities of the manager are: |
| 14 |
|
| 15 |
- initialize all known device factories. A device factory contains the |
| 16 |
logic detect new devices of a certain type and create the |
| 17 |
corresponding object; |
| 18 |
|
| 19 |
- maintain a list of devices created by the factories; |
| 20 |
|
| 21 |
- maintain a list of active connections; |
| 22 |
|
| 23 |
- expose on D-Bus properties, methods and signal on the |
| 24 |
`/org/freedesktop/NetworkManager` |
| 25 |
[object](../../introspection/org.freedesktop.NetworkManager.xml). |
| 26 |
|
| 27 |
## Policy |
| 28 |
|
| 29 |
This object implements some policy decisions that involve multiple |
| 30 |
connection profiles, such as: |
| 31 |
|
| 32 |
- it determines what is the best (with lowest metric) active |
| 33 |
connection with default route for IPv4 and IPv6; |
| 34 |
|
| 35 |
- it updates the DNS configuration in the DNS manager, also according |
| 36 |
to what connection has the best default route; |
| 37 |
|
| 38 |
- it handles the activation of secondary connections when a |
| 39 |
connection goes up (see property `connection.secondaries` in |
| 40 |
`man nm-settings`); |
| 41 |
|
| 42 |
- it collects IPv6 prefix delegations from active connections, to |
| 43 |
distribute them on connections using IPv6 shared mode; |
| 44 |
|
| 45 |
## Settings |
| 46 |
|
| 47 |
This object handles connection profiles; each profile is represented |
| 48 |
as a *SettingsConnection* object and is persisted to disk using one of |
| 49 |
the existing *SettingsPlugin*s such as keyfile, ifcfg-rh or |
| 50 |
ifupdown. |
| 51 |
|
| 52 |
It also controls *SecretAgent*s; an agent is an external service that |
| 53 |
registers to NetworkManager as capable of handling requests for new |
| 54 |
secrets. For example, when a Wi-Fi connection is activated and the |
| 55 |
password is missing or wrong, NetworkManager asks all registered |
| 56 |
agents for the missing secrets and then continues with |
| 57 |
activation. Examples of tools that register as agents are: nmcli, |
| 58 |
nmtui, GNOME shell, the GTK nm-applet and the KDE network applet. |
| 59 |
|
| 60 |
## Devices and device factories |
| 61 |
|
| 62 |
As mentioned before, NetworkManager instantiates device factories to |
| 63 |
discover and create new devices. Those factories are internal to the |
| 64 |
daemon or provided by a device plugin; a plugin is a dynamic library |
| 65 |
(shared object) that is loaded at runtime. NetworkManager uses plugins |
| 66 |
for optional functionality that depend on external software. In this |
| 67 |
way, it is possible to install a minimal version of NetworkManager |
| 68 |
with a limited set of dependencies. As there is no stable API/ABI for |
| 69 |
those plugins, they must be built together with the daemonq and |
| 70 |
maintained as part of NetworkManager. |
| 71 |
|
| 72 |
Currently the following device types are provided by plugins: |
| 73 |
|
| 74 |
- Wi-Fi (depends on wpa_supplicant) |
| 75 |
- OVS (depends on openswitch) |
| 76 |
- PPP (depends on pppd) |
| 77 |
- Bluetooth (depends on bluez) |
| 78 |
- team (depends on teamd) |
| 79 |
|
| 80 |
When a device is activated, it relies on other objects: |
| 81 |
|
| 82 |
- *L3cfg*: controls the IP configuration (address, routes, etc) on a |
| 83 |
given ifindex, and also does IPv4 ACD (address conflict detection, |
| 84 |
also know as DAD - duplicate address detection); |
| 85 |
- *DhcpClient*: performs DHCPv4 and DHCPv6 on the interface; the |
| 86 |
object has different implementations; |
| 87 |
- *NDisc*: implements IPv6 SLAAC (stateless address |
| 88 |
autoconfiguration, RFC 4861 and 4862); it supports acting both as |
| 89 |
a host or a router for shared IPv6 mode; |
| 90 |
- *LldpListener*: when the profile enables |
| 91 |
[LLDP](https://en.wikipedia.org/wiki/Link_Layer_Discovery_Protocol) |
| 92 |
via the `connection.lldp` property, this object sets up a socket |
| 93 |
to listen for neighbors; |
| 94 |
- *FirewalldManager*: talks with [firewalld](https://firewalld.org/) |
| 95 |
to set the interface in the zone specified by the |
| 96 |
`connection.zone` property; |
| 97 |
- *BondManager*: used to configure bond devices in a special mode |
| 98 |
(balance-slb) that requires the creation of nftables rules; |
| 99 |
|
| 100 |
For more information about the implementation of devices, see [this |
| 101 |
document](./device.md). |
| 102 |
|
| 103 |
## Platform |
| 104 |
|
| 105 |
*Platform* communicates with kernel to query and update the |
| 106 |
configuration of network interfaces; it uses netlink and implements |
| 107 |
the crafting and parsing of netlink message by itself without relying |
| 108 |
on external libraries such as libnl. |
| 109 |
|
| 110 |
Platform has two subclasses, *PlatformLinux* and a *PlatformFake*. The |
| 111 |
former is the one that contain the actual implementation while the |
| 112 |
latter is only used for unit testing. |
| 113 |
|
| 114 |
Note how the platform object has an incoming dotted arrow in the |
| 115 |
diagram, to represent that the object is used by several other |
| 116 |
objects. |
| 117 |
|
| 118 |
As mentioned, the purposes of platform are: |
| 119 |
|
| 120 |
- perform operations such as adding or removing links, addresses, |
| 121 |
routes, routing rules and other kernel entities |
| 122 |
|
| 123 |
- allow querying the current state of the kernel configuration. To do |
| 124 |
so, platform listens to kernel notifications and parses them to |
| 125 |
build a cache of `NMPObject`s that is always up to date. |
| 126 |
|
| 127 |
NMPObject and its subtypes are also used through the core to represent |
| 128 |
information about addresses, routes, etc. Thus the cache of NMPlatform |
| 129 |
contains the currently configured objects in the netlink API, while |
| 130 |
other NMPObject instances are used for other tracking purposes. |
| 131 |
|
| 132 |
For these purposes platform uses two sockets, one with protocol |
| 133 |
NETLINK_ROUTE for regular operations about links, addresses, routes, |
| 134 |
etc. and a NETLINK_GENERIC socket to configure Wireguard and MPTCP. |
| 135 |
|
| 136 |
## Other objects |
| 137 |
|
| 138 |
The diagram shows other objects on the right side: |
| 139 |
|
| 140 |
- *DnsManager*: merges all the DNS data received by multiple |
| 141 |
interfaces and updates the system configuration. Besides directly |
| 142 |
writing `/etc/resolv.conf`, it supports updating |
| 143 |
`systemd-resolved` and `dnsmasq` via plugins. |
| 144 |
|
| 145 |
- *HostnameManager*: implements reading and updating the system |
| 146 |
hostname; by default it tries to do that by talking to |
| 147 |
[systemd-hostnamed](https://www.freedesktop.org/wiki/Software/systemd/hostnamed/) |
| 148 |
via D-Bus; in case it's not available, the hostname manager falls |
| 149 |
back to reading and writing `/etc/hostname` directly. |
| 150 |
|
| 151 |
- *RfkillManager*: enumerates RFKill devices and controls their status. See also |
| 152 |
the [related page](https://networkmanager.dev/docs/rfkill/) on the website. |
| 153 |
|
| 154 |
- *AuthManager*: is used to authenticate the API requests received by |
| 155 |
the daemon. The authentication is done via |
| 156 |
[Polkit](https://www.freedesktop.org/software/polkit/docs/latest/polkit.8.html) |
| 157 |
|
| 158 |
- *DbusManager*: creates a connection to the system D-Bus instance |
| 159 |
and allows exporting objects |
| 160 |
|
| 161 |
- *SleepMonitor*: gets notifications for sleep and wake events by |
| 162 |
registering to the available subsystem provided by the distro such |
| 163 |
as systemd-logind or ConsoleKit. |
| 164 |
|
| 165 |
- *SessionMonitor*: tracks which users have an active session by |
| 166 |
using systemd-logind, elogind or ConsoleKit. |
| 167 |
|
| 168 |
- *Dispatcher*: takes care of spawning dispatcher scripts by talking |
| 169 |
to the `nm-dispatcher` service via D-Bus. |