diff options
author | Tom Gundersen <teg@jklm.no> | 2014-03-21 18:36:32 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-03-21 18:36:32 +0100 |
commit | 4644fee04fb515787bcfbba53b3cabe58c81d317 (patch) | |
tree | 281ec9f90238811bf30460db1ae54b734041718f /src/libsystemd-network/sd-dhcp-client.c | |
parent | 9765ce69e15fd294db9553777b621515fa57f2c6 (diff) |
sd-dhcp-client/sd-ipv4ll: allow mac address to be updated at any time
If necessary, restart the clients to deal with a changing mac address
at runtime. This will solve the problem of starting clients on bridges
before they have received their final MAC address.
Diffstat (limited to 'src/libsystemd-network/sd-dhcp-client.c')
-rw-r--r-- | src/libsystemd-network/sd-dhcp-client.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c index 59cd30c606..0728a15550 100644 --- a/src/libsystemd-network/sd-dhcp-client.c +++ b/src/libsystemd-network/sd-dhcp-client.c @@ -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; } |