From 5e25a13a05b2a3844295ca4a2a7e0f12de203ccb Mon Sep 17 00:00:00 2001 From: Jason Reeder Date: Fri, 31 Mar 2017 14:23:10 -0500 Subject: [PATCH 1/2] libsystemd-network: sd-ipv4ll: Wrapper to restart address aquisition after conflict After an ipv4ll claimed address conflict occurs a new address needs to be chosen and then the acquisition state machine needs to be restarted. This commit adds a function (sd_ipv4ll_restart) that clears the previously acquired address (ll->address) and then calls the existing sd_ipv4ll_start function to choose the new address and start the acquisition. Signed-off-by: Jason Reeder --- src/libsystemd-network/sd-ipv4ll.c | 6 ++++++ src/systemd/sd-ipv4ll.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/libsystemd-network/sd-ipv4ll.c b/src/libsystemd-network/sd-ipv4ll.c index 13209261f9..88a90e593b 100644 --- a/src/libsystemd-network/sd-ipv4ll.c +++ b/src/libsystemd-network/sd-ipv4ll.c @@ -248,6 +248,12 @@ static int ipv4ll_pick_address(sd_ipv4ll *ll) { return sd_ipv4ll_set_address(ll, &(struct in_addr) { addr }); } +int sd_ipv4ll_restart(sd_ipv4ll *ll) { + ll->address = 0; + + return sd_ipv4ll_start(ll); +} + #define MAC_HASH_KEY SD_ID128_MAKE(df,04,22,98,3f,ad,14,52,f9,87,2e,d1,9c,70,e2,f2) int sd_ipv4ll_start(sd_ipv4ll *ll) { diff --git a/src/systemd/sd-ipv4ll.h b/src/systemd/sd-ipv4ll.h index 1109ec52e0..5ba92083f4 100644 --- a/src/systemd/sd-ipv4ll.h +++ b/src/systemd/sd-ipv4ll.h @@ -47,6 +47,7 @@ int sd_ipv4ll_set_ifindex(sd_ipv4ll *ll, int interface_index); int sd_ipv4ll_set_address(sd_ipv4ll *ll, const struct in_addr *address); int sd_ipv4ll_set_address_seed(sd_ipv4ll *ll, uint64_t seed); int sd_ipv4ll_is_running(sd_ipv4ll *ll); +int sd_ipv4ll_restart(sd_ipv4ll *ll); int sd_ipv4ll_start(sd_ipv4ll *ll); int sd_ipv4ll_stop(sd_ipv4ll *ll); sd_ipv4ll *sd_ipv4ll_ref(sd_ipv4ll *ll); From 0698ff4184c3652d97c04e15ffac90d0b3aa3529 Mon Sep 17 00:00:00 2001 From: Jason Reeder Date: Fri, 31 Mar 2017 15:40:18 -0500 Subject: [PATCH 2/2] libsystemd-network: sd-ipv4ll: acquire new address after claimed address conflict If a conflict occurs on a claimed ipv4ll address, the device releases the address and then does not attempt to acquire a new ipv4ll address. According to RFC3927, releasing the address in this situation is correct. However, this should be followed by an attempt to configure a new ipv4ll address. This commit restarts the ipv4ll address acquisition state machine after releasing the conflicting address. From RFC3927 Section 2.5 conflict defense method (b): ... However, if this is not the first conflicting ARP packet the host has seen, and the time recorded for the previous conflicting ARP packet is recent, within DEFEND_INTERVAL seconds, then the host MUST immediately cease using this address and configure a new IPv4 Link-Local address as described above. ... Signed-off-by: Jason Reeder --- src/network/networkd-ipv4ll.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/network/networkd-ipv4ll.c b/src/network/networkd-ipv4ll.c index 7ba05dbec3..e2578a298b 100644 --- a/src/network/networkd-ipv4ll.c +++ b/src/network/networkd-ipv4ll.c @@ -179,12 +179,22 @@ static void ipv4ll_handler(sd_ipv4ll *ll, int event, void *userdata) { switch(event) { case SD_IPV4LL_EVENT_STOP: + r = ipv4ll_address_lost(link); + if (r < 0) { + link_enter_failed(link); + return; + } + break; case SD_IPV4LL_EVENT_CONFLICT: r = ipv4ll_address_lost(link); if (r < 0) { link_enter_failed(link); return; } + + r = sd_ipv4ll_restart(ll); + if (r < 0) + log_link_warning(link, "Could not acquire IPv4 link-local address"); break; case SD_IPV4LL_EVENT_BIND: r = ipv4ll_address_claimed(ll, link);