1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

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.
This commit is contained in:
Tom Gundersen 2014-03-21 18:36:32 +01:00
parent 9765ce69e1
commit 4644fee04f
2 changed files with 34 additions and 13 deletions

View 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, int sd_dhcp_client_set_mac(sd_dhcp_client *client,
const struct ether_addr *addr) { const struct ether_addr *addr) {
assert_return(client, -EINVAL); bool need_restart = false;
assert_return(client->state == DHCP_STATE_INIT, -EBUSY);
log_dhcp_client(client, "set MAC address to " assert_return(client, -EINVAL);
"%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", assert_return(addr, -EINVAL);
addr->ether_addr_octet[0],
addr->ether_addr_octet[1], if (memcmp(&client->client_id.mac_addr, addr, ETH_ALEN) == 0)
addr->ether_addr_octet[2], return 0;
addr->ether_addr_octet[3],
addr->ether_addr_octet[4], if (client->state != DHCP_STATE_INIT) {
addr->ether_addr_octet[5]); 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); memcpy(&client->client_id.mac_addr, addr, ETH_ALEN);
client->client_id.type = 0x01; client->client_id.type = 0x01;
if (need_restart)
sd_dhcp_client_start(client);
return 0; return 0;
} }

View File

@ -375,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) { int sd_ipv4ll_set_mac(sd_ipv4ll *ll, const struct ether_addr *addr) {
assert_return(ll, -EINVAL); bool need_restart = false;
assert_return(ll->state == IPV4LL_STATE_INIT, -EBUSY);
memcpy(&ll->mac_addr.ether_addr_octet, addr, ETH_ALEN); assert_return(ll, -EINVAL);
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);
if (need_restart)
sd_ipv4ll_start(ll);
return 0; return 0;
} }