networkd: NetLabel integration
authorTopi Miettinen <toiwoton@gmail.com>
Tue, 3 May 2022 20:43:00 +0000 (23:43 +0300)
committerTopi Miettinen <topimiettinen@users.noreply.github.com>
Mon, 6 Jun 2022 18:24:10 +0000 (18:24 +0000)
commit3cf63830acdef9d8afdc9ef1cf25aa7e85a5e4d5
treeda068c2af170caaba91e6163fdf18a5e21e1fc60
parentcc9e3a55d3d3558c309b1ebbde0f2cc26d69ee54
networkd: NetLabel integration

New directive `NetLabel=` provides a method for integrating dynamic network
configuration into Linux NetLabel subsystem rules, used by Linux security
modules (LSMs) for network access control. The option expects a whitespace
separated list of NetLabel labels. The labels must conform to lexical
restrictions of LSM labels. When an interface is configured with IP addresses,
the addresses and subnetwork masks will be appended to the NetLabel Fallback
Peer Labeling rules. They will be removed when the interface is
deconfigured. Failures to manage the labels will be ignored.

Example:
```
[DHCP]
NetLabel=system_u:object_r:localnet_peer_t:s0
```

With the above rules for interface `eth0`, when the interface is configured with
an IPv4 address of 10.0.0.0/8, `systemd-networkd` performs the equivalent of
`netlabelctl` operation

```
$ sudo netlabelctl unlbl add interface eth0 address:10.0.0.0/8 label:system_u:object_r:localnet_peer_t:s0
```

Result:
```
$ sudo netlabelctl -p unlbl list
...
 interface: eth0
   address: 10.0.0.0/8
    label: "system_u:object_r:localnet_peer_t:s0"
...
```
16 files changed:
man/systemd.network.xml
src/basic/in-addr-util.c
src/basic/in-addr-util.h
src/basic/missing_network.h
src/libsystemd/sd-netlink/netlink-types-genl.c
src/libsystemd/sd-netlink/test-netlink.c
src/network/meson.build
src/network/networkd-address.c
src/network/networkd-address.h
src/network/networkd-netlabel.c [new file with mode: 0644]
src/network/networkd-netlabel.h [new file with mode: 0644]
src/network/networkd-network-gperf.gperf
src/network/networkd-network.c
src/network/networkd-network.h
src/test/test-in-addr-util.c
test/fuzz/fuzz-network-parser/directives