From 21d9eeb5e6177544b32a5e25c355373573a3ccee Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Thu, 1 Aug 2024 14:38:05 +0200 Subject: [PATCH] networkd: Replace existing objects instead of doing nothing if they exist Currently, if for example a traffic control object already exist, networkd will silently do nothing, even if the settings in the network file for the traffic control object have changed. Let's instead replace the object if it already exists so that new settings from the network file are applied as expected. Fixes #31226 --- src/libsystemd/sd-netlink/netlink-message-rtnl.c | 6 +++--- test/test-network/systemd-networkd-tests.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/libsystemd/sd-netlink/netlink-message-rtnl.c b/src/libsystemd/sd-netlink/netlink-message-rtnl.c index fb11c7e02bb..9184c43fecc 100644 --- a/src/libsystemd/sd-netlink/netlink-message-rtnl.c +++ b/src/libsystemd/sd-netlink/netlink-message-rtnl.c @@ -892,7 +892,7 @@ int sd_rtnl_message_new_addrlabel( return r; if (nlmsg_type == RTM_NEWADDRLABEL) - (*ret)->hdr->nlmsg_flags |= NLM_F_CREATE | NLM_F_EXCL; + (*ret)->hdr->nlmsg_flags |= NLM_F_CREATE | NLM_F_REPLACE; addrlabel = NLMSG_DATA((*ret)->hdr); @@ -1143,7 +1143,7 @@ int sd_rtnl_message_new_traffic_control( return r; if (IN_SET(nlmsg_type, RTM_NEWQDISC, RTM_NEWTCLASS)) - (*ret)->hdr->nlmsg_flags |= NLM_F_CREATE | NLM_F_EXCL; + (*ret)->hdr->nlmsg_flags |= NLM_F_CREATE | NLM_F_REPLACE; tcm = NLMSG_DATA((*ret)->hdr); tcm->tcm_ifindex = ifindex; @@ -1212,7 +1212,7 @@ int sd_rtnl_message_new_mdb( return r; if (nlmsg_type == RTM_NEWMDB) - (*ret)->hdr->nlmsg_flags |= NLM_F_CREATE | NLM_F_EXCL; + (*ret)->hdr->nlmsg_flags |= NLM_F_CREATE | NLM_F_REPLACE; bpm = NLMSG_DATA((*ret)->hdr); bpm->family = AF_BRIDGE; diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 8a2c5af3989..1b61038d09e 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -4489,6 +4489,17 @@ class NetworkdTCTests(unittest.TestCase, Utilities): self.assertIn('rtt 1s', output) self.assertIn('ack-filter-aggressive', output) + # Test for replacing existing qdisc. See #31226. + with open(os.path.join(network_unit_dir, '25-qdisc-cake.network'), mode='a', encoding='utf-8') as f: + f.write('Bandwidth=250M\n') + + networkctl_reload() + self.wait_online('dummy98:routable') + + output = check_output('tc qdisc show dev dummy98') + print(output) + self.assertIn('bandwidth 250Mbit', output) + @expectedFailureIfModuleIsNotAvailable('sch_codel') def test_qdisc_codel(self): copy_network_unit('25-qdisc-codel.network', '12-dummy.netdev')