871 Commits

Author SHA1 Message Date
Quentin Deslandes
5b0e262f45 network: clear existing routes if Gateway= is empty in [Network]
Add support for an empty Gateway= in [Network] to clear the existing
routes. This change will allow users to remove the default route from a
drop-in file.
2025-11-20 07:16:26 +09:00
Yu Watanabe
d7cf08b735 test-network: drop two overly verbose outputs
Follow-up for 7f9c0c31d2.
2025-11-16 22:15:44 +09:00
Yu Watanabe
3632d7322f test-network: set TimeoutStopFailureMode=abort when running with sanitizers
Hopefully this provides useful data for issue #39631.
2025-11-16 22:15:43 +09:00
Yu Watanabe
c43585bc30 Revert "test-network: disable several more sandbox features when running with sanitizers"
This reverts commit 454ce42305.

Unfortunately, it does not work.
2025-11-16 22:15:43 +09:00
Lennart Poettering
a7fa29b1b5 networkd: add support for resolved hook for DHCP server
Let's synthesize DNS RRs for leases handed out by our DHCP server. This
way local VMs can have resolvable hostnames locally.

This does not implement reverse look ups for now. We can add this
later in similar fashion.
2025-11-15 07:52:42 +01:00
Chris Down
7f9c0c31d2 sd-dhcp-server: Add Hostname= option to static leases
This adds a new `Hostname=` option to the [DHCPServerStaticLease]
section in .network files, allowing an administrator to assign a
specific hostname to a client receiving a static lease.

We automatically select the correct DHCP option to use based on the
format of the provided string:

- Single DNS labels are sent as Option 12.
- Names with multiple DNS labels are sent as Option 81 in wire format.

Fixes: #39634
2025-11-14 07:50:13 +09:00
Yu Watanabe
454ce42305 test-network: disable several more sandbox features when running with sanitizers
These settings also imply seccomp.
Hopefully fixes #39567.
2025-11-06 00:50:11 +09:00
Yu Watanabe
da665b708a test-network: read default values from environment variables
Nowadays, the test script is run as a service, and no argument about
sanitizers are passed. Let's read them from the environment variables.
2025-11-06 00:22:17 +09:00
Yu Watanabe
df75dd34f6 test-network: also save the current state of socket units for resolved and stop them
Silence the following waring:
```
Stopping 'systemd-resolved.service', but its triggering units are still active:
systemd-resolved-varlink.socket, systemd-resolved-monitor.socket
```

Follow-up for 0fa188307b.
2025-08-08 19:38:27 +09:00
haxibami
3a83ea5bf2 test-network: add test cases for SIP servers 2025-07-22 17:06:11 +09:00
Yu Watanabe
c0c8f918bb test-network: stop varlink.socket before stopping networkd.service
To avoid the following warnings:
```
systemd-networkd-tests.py[3139]: Stopping 'systemd-networkd.service', but its triggering units are still active:
systemd-networkd-tests.py[3139]: systemd-networkd-varlink.socket
```

Follow-up for b0ea79c5b5.
2025-07-16 08:28:23 +09:00
Yu Watanabe
3d38732179 test: assume RTA_VIA is supported
RTA_VIA support was added in kernel v5.2:
d15662682d

Our baseline on the kernel is v5.4. Hence, we can assume that the
attribute is supported.
2025-07-03 12:51:22 +09:00
Yu Watanabe
d63c8ce020 test-network: wait for all addresses and routes configured before start monitoring
Otherwise, kernel may announce configuration of an address or route
after 'ip monitor' is started.

This also makes the test check if the whole output of 'ip monitor' is
empty. Otherwise, if the test fails, it is hard to find what is wrong.

Follow-ups for 912a48572d and
bcb9e72b6b.

Fixes #37982.
2025-06-27 11:30:33 +01:00
Yu Watanabe
e08fdfdd7d test-network: compare LLDP sender and receiver information 2025-06-18 01:51:19 +09:00
Lennart Poettering
f2a365b982 network/dhcp-server: improvements for saving/loading leases (#37835) 2025-06-17 14:31:22 +02:00
Yu Watanabe
312e3835ee test-network: add tests for tunnel mode 2025-06-16 17:01:37 +09:00
Yu Watanabe
ce5a54ed9b test-network: add test case for issue #37714
I cannot reproduce the issue with the current git HEAD.
Let's add a test case that is used by the reporter of the issue.
2025-06-15 09:33:23 +09:00
Yu Watanabe
009d64dddd test-network: add test case for PersistLeases=runtime 2025-06-14 03:42:24 +09:00
Avram Dorfman
fb9076b994 test-network: add test case for bootp
Co-authored-by: Yu Watanabe <watanabe.yu+github@gmail.com>
2025-06-13 14:15:04 +09:00
Yu Watanabe
78f8d5ed71 network: also check ID_NET_MANAGED_BY property on reconfigure
Previously, the property was checked only when an uevent is received,
so even if an interface has ID_NET_MANAGED_BY property, the interface
will be configured by networkd when reconfiguration is triggered e.g.
when interface state is changed.

Follow-up for ba87a61d05.
Fixes #36997.
2025-06-12 14:24:50 +09:00
Yu Watanabe
c6aae2cd8a test-network: add test case for issue #32186
The reporter said that the issue is caused by BindCarrier=, but
I cannot reproduce it. Anyway, let's test it.
2025-06-11 17:32:46 +09:00
Yu Watanabe
8882519583 test-network: read the current link flags of bond interface
Follow-up for 2700d2c7dc.
2025-06-11 17:18:43 +09:00
Yu Watanabe
356e9bc018 test-network: extend comments how to run the test 2025-06-04 16:46:41 +01:00
Yu Watanabe
ff6f0a58c5 test-network: replace unnecessary assertRegex() with assertIn()
This fixes the following warning:
```
/tmp/systemd/test/test-network/systemd-networkd-tests.py:5107: SyntaxWarning: invalid escape sequence '\.'
  self.assertRegex(output, 'inet 10\.234\.77\.111/32.*dummy98')
```

Follow-up for 6479204e56.
2025-05-28 04:38:56 +09:00
Yu Watanabe
b1bed07d84 test-network: add test case for issue #37629 2025-05-28 04:38:56 +09:00
Luca Boccassi
f9a85b7490 test: fix test_qdisc_tbf regex with iproute2 v6.15
iproute2 v6.15 fixed some rounding errors in the reported stats:

https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=d947f365602b30657d1b797e7464000d0ab88d5a

so the current regex doesn't work anymore. Fix it to check for both
old and new values.

systemd-networkd-tests.py[523]: FAIL: test_qdisc_tbf (__main__.NetworkdTCTests.test_qdisc_tbf)
systemd-networkd-tests.py[523]: ----------------------------------------------------------------------
systemd-networkd-tests.py[523]: Traceback (most recent call last):
systemd-networkd-tests.py[523]:   File "/usr/lib/systemd/tests/testdata/test-network/systemd-networkd-tests.py", line 5402, in test_qdisc_tbf
systemd-networkd-tests.py[523]:     self.assertRegex(output, 'rate 1Gbit burst 5000b peakrate 100Gbit minburst 987500b lat 70(.0)?ms')
systemd-networkd-tests.py[523]:     ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
systemd-networkd-tests.py[523]: AssertionError: Regex didn't match: 'rate 1Gbit burst 5000b peakrate 100Gbit minburst 987500b lat 70(.0)?ms' not found in 'qdisc tbf 35: root refcnt 2 rate 1Gbit burst 5000b peakrate 100Gbit minburst 999200b lat 70ms \nqdisc pfifo 37: parent 35: limit 100000p'
2025-05-27 17:24:47 +01:00
Matteo Croce
6288739eaf networkd: print a meaningful error on failure
test_keep_configuration_on_restart() works, but the error printed is
misleading because self.assertNotEmpty() doesn't exist.

Add a working assert statement so, when the unmanaged interface is
altered, the test fails with a meaningful error, like:

        ### ip monitor dev unmanaged0 BEGIN
        222:33::/64 proto kernel metric 256 pref medium
        FAIL
        [...]
        Traceback (most recent call last):
          File "/work/src/test/test-network/systemd-networkd-tests.py", line 5085, in test_keep_configuration_on_restart
            self.assertEqual(line, '')
        AssertionError: '222:33::/64 proto kernel metric 256 pref medium' != ''
        - 222:33::/64 proto kernel metric 256 pref medium

While at it, strip the trailing newline so we can print easily the
string (and in future build more a robust regexp which uses the $ token)
2025-05-22 09:33:39 +02:00
Matteo Croce
bcb9e72b6b networkd: ensure that unmanaged interfaces aren't touched
Extend the test_keep_configuration_on_restart in order to check
that the unmanaged interface isn't altered in any way.
2025-05-22 03:04:40 +09:00
Matteo Croce
6479204e56 networkd: add test to ensure that untracked addresses are kept
Users can alter the network configuration manually, but networkd should
not interfere with manually set addresses and routes.
2025-05-20 14:14:53 +02:00
Beniamino Galvani
ec65c29e51 network: fix handling of routing policy rule fwmask
The firewall mask should be applied even if the mark is 0, to allow defining a
value of e.g. 0/255.

Fixes #36973
2025-04-17 09:18:54 +09:00
Beniamino Galvani
f7996e2a33 network: add support for HSR netdev
Add support for creating HSR/PRP interfaces. HSR (High-availability Seamless
Redundancy) and PRP (Parallel Redundancy Protocol) are two protocols that
provide seamless failover against failure of any single network component. They
are both implemented by the "hsr" kernel driver.
2025-04-05 05:23:53 +09:00
Luca Boccassi
da24983526 test: skip networkd tests if networkd/resolved are disabled at build time 2025-03-30 10:18:18 +02:00
Erik Larsson
c88adbc01d networkd: add support for setting vlan_tunnel on bridge ports 2025-03-24 17:15:19 +09:00
Erik Larsson
6e529860ba networkd: add support for externally managed vxlan devices
With this a vxlan interface can be created which is managed by
for example a EVPN control plane.
2025-03-20 20:29:47 +09:00
Matteo Croce
912a48572d test-network: check that network configuration is stable with KeepConfiguration=yes
Check that when networkd restarts, and the network configures
KeepConfiguration=yes, the network configuration is never changed.

Ensure this by dumping the `ip monitor` output when networkd is restarting.

Co-authored-by: Yu Watanabe <watanabe.yu+github@gmail.com>
2025-03-15 10:26:20 +09:00
Yu Watanabe
51e60dac12 test-network: drop deprecated ExecStart= modifier 2025-03-05 18:17:19 +09:00
Yu Watanabe
94dc76c996 test-network: extend test case for static routes
- split out verifications into two functions,
- also check the following scenarios:
  * unmanaging an existing interface,
  * re-managing an unmanaged interface,
  * adding a new unmanaged interface,
  * removing an unmanaged interface.
2025-02-28 08:51:14 +01:00
Yu Watanabe
1cac0676da test-network: add test case for KeepConfiguration=yes with RTPROT_BOOT
For issue #36411.
2025-02-18 23:01:53 +09:00
Luca Boccassi
382e8a03ca network: allow to configure routing policy rule even if requesting interface is not activated yet (#36257)
Fixes a regression caused by 4f8b153d90
(v257).
Fixes #36244.
2025-02-07 22:56:36 +00:00
Luca Boccassi
2ee81b556f network/route: improve Gateway=_dhcp4 handling (#36183)
- Also configures route to the gateway and prefix route in the specified
table, if necessary.
- Also set preferred source address of the route.

Closes #36168.
2025-02-05 12:19:01 +00:00
Yu Watanabe
a10172b035 test-network: add test case for issue #35874 2025-02-05 09:40:31 +09:00
Yu Watanabe
f7ae28fcec test-network: add test case for requesting routing policy rules by multiple interfaces
For issue #36244.
2025-02-04 12:28:59 +09:00
Yu Watanabe
d90c01d02c network: bridge: add support for configuring locked ports (#36150)
"Recently" (as of 5.18) the Linux kernel gained the ability of locking
bridge ports to restrict network access to authenticated hosts only.

This is implemented by disabling automated learning and dropping
incoming traffic from unknown hosts. User space is then expected to add
fdb entries for authenticated hosts. Once a fdb entry exist, traffic for
that host will be forwarded as expected.

This was later extended with "Mac Authentication Bypass", where the
locking was extended to fdb entries. In this mode the kernel adds fdb
entries again automatically, but they are locked by default.

To properly configure this, add two network options and one netdev
option:

* `LinkLocalLearning=` to prevent the kernel from creating unlocked
entries based on link-local traffic, which would bypass any
authentication. Needed when enabling learning on a locked port.
* `Locked=` to allow setting a bridge port to locked.
* `MACAuthenticationBypass=` to allow enabling Mac Authentication
 Bypass on a port. Requires learning to be enabled on the port as well
 (and consequently `LinkLocalLearning` disabled on the bridge).

An authenticator (e.g. hostapd) is still needed to do the actual
authentication, the kernel only provides the access control.
2025-01-29 04:16:20 +09:00
Nick Rosbrook
d6608da1e6 networkd-test: add basic tests for systemd-networkd-wait-online --dns 2025-01-28 08:49:49 -05:00
Jonas Gorski
08a26ecc47 network: bridge: add support for IFLA_BRPORT_MAB
Since linux commit a35ec8e38cdd1766f29924ca391a01de20163931 ("bridge:
Add MAC Authentication Bypass (MAB) support"), included since v6.2, it
is possible to enable MAC Authentication Bypass for bridge ports. In
this mode the locked port learns again, but the learned fdb entries are
locked, allowing user space to unlock hosts based seen MAC addresses.

This requires learning to be enabled on the port, and link-local
learning disabled for the bridge.

Add support to systemd-network for setting the new attribute for bridge
ports.
2025-01-28 12:22:26 +01:00
Jonas Gorski
a434de6056 network: bridge: add support for IFLA_BRPORT_LOCKED
Since linux commit a21d9a670d81103db7f788de1a4a4a6e4b891a0b ("net:
bridge: Add support for bridge port in locked mode"), included since
v5.18,  it is possible to set bridge ports to locked.

Locked ports do not learn automatically, and discard any traffic from
unknown source MACs. To allow traffic, the userspace authenticator is
expected to create fdb entries for authenticated hosts.

Add support to systemd-network for setting the new attribute for bridge
ports.
2025-01-28 10:38:01 +01:00
Jonas Gorski
d7de242ce7 network: bridge: add support for NO_LL_LEARN
When using locked ports on a bridge link-local learning needs to be
disabled to prevent the kernel from learning and automatically unlocking
hosts based on link-local traffic.

So add support for enabling NO_LL_LEARN for bridges.
2025-01-28 10:38:01 +01:00
Yu Watanabe
2ea15435fd test-network: add test case for Gateway=_dhcp4 with Table= 2025-01-27 08:39:09 +09:00
Yu Watanabe
60ce6a3413 test-network: add test case for [IPv6RoutePrefix] Preference= 2025-01-22 20:48:31 +00:00
Yu Watanabe
220f7aac8c test-network: drop workaround for old CentOS release 2025-01-07 02:06:04 +09:00