]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-ipv4acd: allow to change MAC address without restarting sd-ipv4acd
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 20 Jun 2021 17:29:46 +0000 (02:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 30 Jun 2021 15:49:02 +0000 (00:49 +0900)
This also makes sd_ipv4acd_set_mac() refuses null MAC address.

src/libsystemd-network/sd-ipv4acd.c

index ee4f215002dcc8732528f6fed2f2f4ecb919abad..d763ba8e62e52def12a8d950f8f6445147a86ef0 100644 (file)
@@ -432,12 +432,24 @@ const char *sd_ipv4acd_get_ifname(sd_ipv4acd *acd) {
 }
 
 int sd_ipv4acd_set_mac(sd_ipv4acd *acd, const struct ether_addr *addr) {
+        int r;
+
         assert_return(acd, -EINVAL);
         assert_return(addr, -EINVAL);
-        assert_return(acd->state == IPV4ACD_STATE_INIT, -EBUSY);
+        assert_return(!ether_addr_is_null(addr), -EINVAL);
 
         acd->mac_addr = *addr;
 
+        if (!sd_ipv4acd_is_running(acd))
+                return 0;
+
+        assert(acd->fd >= 0);
+        r = arp_update_filter(acd->fd, &acd->address, &acd->mac_addr);
+        if (r < 0) {
+                ipv4acd_reset(acd);
+                return r;
+        }
+
         return 0;
 }