From 4644fee04fb515787bcfbba53b3cabe58c81d317 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Fri, 21 Mar 2014 18:36:32 +0100 Subject: 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. --- src/libsystemd-network/sd-ipv4ll.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/libsystemd-network/sd-ipv4ll.c') diff --git a/src/libsystemd-network/sd-ipv4ll.c b/src/libsystemd-network/sd-ipv4ll.c index 689dce9adf..ad8b4e3b43 100644 --- a/src/libsystemd-network/sd-ipv4ll.c +++ b/src/libsystemd-network/sd-ipv4ll.c @@ -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) { + 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; } -- cgit v1.2.3-54-g00ecf