X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd-network%2Fsd-ipv4ll.c;h=8626d4afa993a32df288c8ced0ac91e3b582dab4;hb=fe21f16764147d51819a904d57ac36967f9913e3;hp=37cb802b635c8288baf80c5faf4b65bd8d60916e;hpb=56cd007ab83749b85670c9c7f560e083980c2ff4;p=elogind.git diff --git a/src/libsystemd-network/sd-ipv4ll.c b/src/libsystemd-network/sd-ipv4ll.c index 37cb802b6..8626d4afa 100644 --- a/src/libsystemd-network/sd-ipv4ll.c +++ b/src/libsystemd-network/sd-ipv4ll.c @@ -61,6 +61,7 @@ typedef enum IPv4LLState { IPV4LL_STATE_WAITING_ANNOUNCE, IPV4LL_STATE_ANNOUNCING, IPV4LL_STATE_RUNNING, + IPV4LL_STATE_STOPPED, _IPV4LL_STATE_MAX, _IPV4LL_STATE_INVALID = -1 } IPv4LLState; @@ -185,8 +186,8 @@ static void ipv4ll_set_next_wakeup(sd_ipv4ll *ll, int sec, int random_sec) { if (random_sec) next_timeout += random_u32() % (random_sec * USEC_PER_SEC); - if (sd_event_now(ll->event, CLOCK_MONOTONIC, &time_now) < 0) - time_now = now(CLOCK_MONOTONIC); + if (sd_event_now(ll->event, clock_boottime_or_monotonic(), &time_now) < 0) + time_now = now(clock_boottime_or_monotonic()); ll->next_wakeup = time_now + next_timeout; ll->next_wakeup_valid = 1; @@ -264,7 +265,7 @@ static void ipv4ll_run_state_machine(sd_ipv4ll *ll, IPv4LLTrigger trigger, void log_ipv4ll(ll, "ANNOUNCE"); ll->claimed_address = ll->address; ll = ipv4ll_client_notify(ll, IPV4LL_EVENT_BIND); - if (!ll) + if (!ll || ll->state == IPV4LL_STATE_STOPPED) goto out; ll->conflict = 0; @@ -288,7 +289,7 @@ static void ipv4ll_run_state_machine(sd_ipv4ll *ll, IPv4LLTrigger trigger, void if (ipv4ll_arp_conflict(ll, in_packet)) { - r = sd_event_now(ll->event, CLOCK_MONOTONIC, &time_now); + r = sd_event_now(ll->event, clock_boottime_or_monotonic(), &time_now); if (r < 0) goto out; @@ -311,7 +312,7 @@ static void ipv4ll_run_state_machine(sd_ipv4ll *ll, IPv4LLTrigger trigger, void if (conflicted) { log_ipv4ll(ll, "CONFLICT"); ll = ipv4ll_client_notify(ll, IPV4LL_EVENT_CONFLICT); - if (!ll) + if (!ll || ll->state == IPV4LL_STATE_STOPPED) goto out; ll->claimed_address = 0; @@ -343,7 +344,7 @@ static void ipv4ll_run_state_machine(sd_ipv4ll *ll, IPv4LLTrigger trigger, void if (ll->next_wakeup_valid) { ll->timer = sd_event_source_unref(ll->timer); - r = sd_event_add_time(ll->event, &ll->timer, CLOCK_MONOTONIC, + r = sd_event_add_time(ll->event, &ll->timer, clock_boottime_or_monotonic(), ll->next_wakeup, 0, ipv4ll_timer, ll); if (r < 0) goto out; @@ -351,6 +352,10 @@ static void ipv4ll_run_state_machine(sd_ipv4ll *ll, IPv4LLTrigger trigger, void r = sd_event_source_set_priority(ll->timer, ll->event_priority); if (r < 0) goto out; + + r = sd_event_source_set_description(ll->timer, "ipv4ll-timer"); + if (r < 0) + goto out; } out: @@ -381,8 +386,9 @@ static int ipv4ll_receive_message(sd_event_source *s, int fd, int sd_ipv4ll_set_index(sd_ipv4ll *ll, int interface_index) { assert_return(ll, -EINVAL); - assert_return(interface_index >= -1, -EINVAL); - assert_return(ll->state == IPV4LL_STATE_INIT, -EBUSY); + assert_return(interface_index > 0, -EINVAL); + assert_return(IN_SET(ll->state, IPV4LL_STATE_INIT, + IPV4LL_STATE_STOPPED), -EBUSY); ll->index = interface_index; @@ -398,7 +404,7 @@ int sd_ipv4ll_set_mac(sd_ipv4ll *ll, const struct ether_addr *addr) { if (memcmp(&ll->mac_addr, addr, ETH_ALEN) == 0) return 0; - if (ll->state != IPV4LL_STATE_INIT) { + if (!IN_SET(ll->state, IPV4LL_STATE_INIT, IPV4LL_STATE_STOPPED)) { log_ipv4ll(ll, "Changing MAC address on running IPv4LL " "client, restarting"); ll = ipv4ll_stop(ll, IPV4LL_EVENT_STOP); @@ -467,10 +473,13 @@ int sd_ipv4ll_get_address(sd_ipv4ll *ll, struct in_addr *address){ } int sd_ipv4ll_set_address_seed (sd_ipv4ll *ll, uint8_t seed[8]) { - unsigned int entropy = *seed; + unsigned int entropy; int r; assert_return(ll, -EINVAL); + assert_return(seed, -EINVAL); + + entropy = *seed; free(ll->random_data); free(ll->random_data_state); @@ -500,7 +509,7 @@ error: bool sd_ipv4ll_is_running(sd_ipv4ll *ll) { assert_return(ll, -EINVAL); - return ll->state != IPV4LL_STATE_INIT; + return !IN_SET(ll->state, IPV4LL_STATE_INIT, IPV4LL_STATE_STOPPED); } #define HASH_KEY SD_ID128_MAKE(df,04,22,98,3f,ad,14,52,f9,87,2e,d1,9c,70,e2,f2) @@ -511,7 +520,10 @@ int sd_ipv4ll_start (sd_ipv4ll *ll) { assert_return(ll, -EINVAL); assert_return(ll->event, -EINVAL); assert_return(ll->index > 0, -EINVAL); - assert_return(ll->state == IPV4LL_STATE_INIT, -EBUSY); + assert_return(IN_SET(ll->state, IPV4LL_STATE_INIT, + IPV4LL_STATE_STOPPED), -EBUSY); + + ll->state = IPV4LL_STATE_INIT; r = arp_network_bind_raw_socket(ll->index, &ll->link); @@ -552,17 +564,24 @@ int sd_ipv4ll_start (sd_ipv4ll *ll) { if (r < 0) goto out; + r = sd_event_source_set_description(ll->receive_message, "ipv4ll-receive-message"); + if (r < 0) + goto out; + r = sd_event_add_time(ll->event, &ll->timer, - CLOCK_MONOTONIC, - now(CLOCK_MONOTONIC), 0, + clock_boottime_or_monotonic(), + now(clock_boottime_or_monotonic()), 0, ipv4ll_timer, ll); if (r < 0) goto out; r = sd_event_source_set_priority(ll->timer, ll->event_priority); + if (r < 0) + goto out; + r = sd_event_source_set_description(ll->timer, "ipv4ll-timer"); out: if (r < 0) ipv4ll_stop(ll, IPV4LL_EVENT_STOP); @@ -572,6 +591,8 @@ out: int sd_ipv4ll_stop(sd_ipv4ll *ll) { ipv4ll_stop(ll, IPV4LL_EVENT_STOP); + if (ll) + ipv4ll_set_state(ll, IPV4LL_STATE_STOPPED, 1); return 0; }