]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: check link state with link_is_ready_to_configure() before configuring DHCP...
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 13 May 2022 11:48:18 +0000 (20:48 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 5 Aug 2022 12:49:27 +0000 (21:49 +0900)
Otherwise, DHCP client or friends may started before link-layer properties,
e.g. MAC address, being configured or the link being activated.

src/network/netdev/l2tp-tunnel.c
src/network/netdev/netdev-util.c
src/network/networkd-dhcp-server.c
src/network/networkd-dhcp4.c
src/network/networkd-dhcp6.c
src/network/networkd-ndisc.c
src/network/networkd-radv.c

index c38b9dc31296b7cd2dc2a08cf218f272e69bde17..7e7d1679282d1cc777af07b6750704821a31a4e8 100644 (file)
@@ -292,7 +292,7 @@ static int l2tp_get_local_address(NetDev *netdev, union in_addr_union *ret) {
                 if (r < 0)
                         return r;
 
-                if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
+                if (!link_is_ready_to_configure(link, /* allow_unmanaged = */ false))
                         return -EBUSY;
         }
 
@@ -346,7 +346,7 @@ static int l2tp_get_local_address(NetDev *netdev, union in_addr_union *ret) {
                 return link_get_l2tp_local_address(link, t, ret);
 
         HASHMAP_FOREACH(link, netdev->manager->links_by_index) {
-                if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
+                if (!link_is_ready_to_configure(link, /* allow_unmanaged = */ false))
                         continue;
 
                 if (link_get_l2tp_local_address(link, t, ret) >= 0)
index 06028855a84ac294fe1aee8b3ee6260335c78ac0..23506246ce2f44d9c9454627bf1d0aa545ce0522 100644 (file)
@@ -51,7 +51,7 @@ int link_get_local_address(
                 assert_not_reached();
         }
 
-        if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
+        if (!link_is_ready_to_configure(link, /* allow_unmanaged = */ false))
                 return -EBUSY;
 
         SET_FOREACH(a, link->addresses) {
index 5861ecb922874fe31926f8295ba183407c81b0c1..076779dc0e5f2c169c8ca9bf2754d3e6a5a430c8 100644 (file)
@@ -539,13 +539,7 @@ static bool dhcp_server_is_ready_to_configure(Link *link) {
 
         assert(link);
 
-        if (!link->network)
-                return false;
-
-        if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
-                return false;
-
-        if (link->set_flags_messages > 0)
+        if (!link_is_ready_to_configure(link, /* allow_unmanaged = */ false))
                 return false;
 
         if (!link_has_carrier(link))
index c6cbadc08baac7786a74ac0f15a3e738886ea69b..3795fb32f3faea0c8506297c0adae8e5f60729f7 100644 (file)
@@ -1557,7 +1557,7 @@ static int dhcp4_process_request(Request *req, Link *link, void *userdata) {
 
         assert(link);
 
-        if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
+        if (!link_is_ready_to_configure(link, /* allow_unmanaged = */ false))
                 return 0;
 
         r = dhcp4_configure_duid(link);
index 7f9f4e12b99cff8494c624a75a92be94ccfdeb4d..4293eb624215de4563de9fc53c31671c6e716522 100644 (file)
@@ -741,7 +741,7 @@ static int dhcp6_process_request(Request *req, Link *link, void *userdata) {
 
         assert(link);
 
-        if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
+        if (!link_is_ready_to_configure(link, /* allow_unmanaged = */ false))
                 return 0;
 
         r = dhcp_configure_duid(link, link_get_dhcp6_duid(link));
index dfbb7043bf14c665cfcd05a3ed5800da958a7d51..579282136f2c8f1e6dee2afaeb9443d559b514ad 100644 (file)
@@ -1099,7 +1099,7 @@ static int ndisc_process_request(Request *req, Link *link, void *userdata) {
 
         assert(link);
 
-        if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
+        if (!link_is_ready_to_configure(link, /* allow_unmanaged = */ false))
                 return 0;
 
         r = ndisc_configure(link);
index c59ae8269401dfdab19761386fc9c09743de86a0..a0ce162532c12702c61e1ce3f74c31cc7552cb3f 100644 (file)
@@ -549,7 +549,7 @@ static int radv_is_ready_to_configure(Link *link) {
         assert(link);
         assert(link->network);
 
-        if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
+        if (!link_is_ready_to_configure(link, /* allow_unmanaged = */ false))
                 return false;
 
         if (in6_addr_is_null(&link->ipv6ll_address))