chiark / gitweb /
sd-dhcp-client/sd-ipv4ll: allow mac address to be updated at any time
[elogind.git] / src / libsystemd-network / sd-ipv4ll.c
index c6f6e014310a2c7fbafd29717735cabf0c0d8464..ad8b4e3b4334974b66cd344d1a1ea5df0a00b070 100644 (file)
@@ -113,9 +113,7 @@ static int ipv4ll_stop(sd_ipv4ll *ll, int event) {
         assert(ll);
 
         ll->receive_message = sd_event_source_unref(ll->receive_message);
-        if (ll->fd >= 0)
-                close_nointr_nofail(ll->fd);
-        ll->fd = -1;
+        ll->fd = safe_close(ll->fd);
 
         ll->timer = sd_event_source_unref(ll->timer);
 
@@ -377,10 +375,25 @@ int sd_ipv4ll_set_index(sd_ipv4ll *ll, int interface_index) {
 }
 
 int sd_ipv4ll_set_mac(sd_ipv4ll *ll, const struct ether_addr *addr) {
+        bool need_restart = false;
+
         assert_return(ll, -EINVAL);
-        assert_return(ll->state == IPV4LL_STATE_INIT, -EBUSY);
+        assert_return(addr, -EINVAL);
+
+        if (memcmp(&ll->mac_addr, addr, ETH_ALEN) == 0)
+                return 0;
+
+        if (ll->state != IPV4LL_STATE_INIT) {
+                log_ipv4ll(ll, "Changing MAC address on running IPv4LL "
+                           "client, restarting");
+                sd_ipv4ll_stop(ll);
+                need_restart = true;
+        }
+
+        memcpy(&ll->mac_addr, addr, ETH_ALEN);
 
-        memcpy(&ll->mac_addr.ether_addr_octet, addr, ETH_ALEN);
+        if (need_restart)
+                sd_ipv4ll_start(ll);
 
         return 0;
 }