chiark / gitweb /
sd-dhcp-client/sd-ipv4ll: allow mac address to be updated at any time
[elogind.git] / src / libsystemd-network / sd-dhcp-client.c
index 59cd30c606c6c7b8ac1b3e9f95ea1ae6f277ef02..0728a15550cd7d51f7bb503bb1ee4c8bc19cf064 100644 (file)
@@ -143,21 +143,27 @@ int sd_dhcp_client_set_index(sd_dhcp_client *client, int interface_index) {
 
 int sd_dhcp_client_set_mac(sd_dhcp_client *client,
                            const struct ether_addr *addr) {
+        bool need_restart = false;
+
         assert_return(client, -EINVAL);
-        assert_return(client->state == DHCP_STATE_INIT, -EBUSY);
+        assert_return(addr, -EINVAL);
+
+        if (memcmp(&client->client_id.mac_addr, addr, ETH_ALEN) == 0)
+                return 0;
 
-        log_dhcp_client(client, "set MAC address to "
-                        "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
-                        addr->ether_addr_octet[0],
-                        addr->ether_addr_octet[1],
-                        addr->ether_addr_octet[2],
-                        addr->ether_addr_octet[3],
-                        addr->ether_addr_octet[4],
-                        addr->ether_addr_octet[5]);
+        if (client->state != DHCP_STATE_INIT) {
+                log_dhcp_client(client, "Changing MAC address on running DHCP "
+                                "client, restarting");
+                sd_dhcp_client_stop(client);
+                need_restart = true;
+        }
 
         memcpy(&client->client_id.mac_addr, addr, ETH_ALEN);
         client->client_id.type = 0x01;
 
+        if (need_restart)
+                sd_dhcp_client_start(client);
+
         return 0;
 }