From: Roy Marples Date: Tue, 6 Dec 2016 19:28:05 +0000 (+0000) Subject: Change arping_index from 1 based to 0 based, defaulting not started to -1. X-Git-Tag: v7.0.0-beta1~92 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9239add403e3f2909e3ef556826bb1f8820756ef;p=thirdparty%2Fdhcpcd.git Change arping_index from 1 based to 0 based, defaulting not started to -1. Fixes pinging the last set address. --- diff --git a/dhcp.c b/dhcp.c index d19a7c08..d222342c 100644 --- a/dhcp.c +++ b/dhcp.c @@ -2023,7 +2023,7 @@ dhcp_arp_probed(struct arp_state *astate) * arping profile */ if (++state->arping_index < ifo->arping_len) { astate->addr.s_addr = - ifo->arping[state->arping_index - 1]; + ifo->arping[state->arping_index]; arp_probe(astate); return; } @@ -2087,16 +2087,16 @@ dhcp_arp_conflicted(struct arp_state *astate, const struct arp_msg *amsg) #ifdef ARPING ifo = ifp->options; - if (state->arping_index && - state->arping_index <= ifo->arping_len && + if (state->arping_index != -1 && + state->arping_index < ifo->arping_len && amsg && - (amsg->sip.s_addr == ifo->arping[state->arping_index - 1] || + (amsg->sip.s_addr == ifo->arping[state->arping_index] || (amsg->sip.s_addr == 0 && - amsg->tip.s_addr == ifo->arping[state->arping_index - 1]))) + amsg->tip.s_addr == ifo->arping[state->arping_index]))) { char buf[HWADDR_LEN * 3]; - astate->failed.s_addr = ifo->arping[state->arping_index - 1]; + astate->failed.s_addr = ifo->arping[state->arping_index]; arp_report_conflicted(astate, amsg); hwaddr_ntoa(amsg->sha, ifp->hwlen, buf, sizeof(buf)); if (dhcpcd_selectprofile(ifp, buf) == -1 && @@ -2596,6 +2596,9 @@ dhcp_drop(struct interface *ifp, const char *reason) return; } +#ifdef ARPING + state->arping_index = -1; +#endif if (ifp->options->options & DHCPCD_RELEASE && !(ifp->options->options & DHCPCD_INFORM)) { @@ -3410,6 +3413,9 @@ dhcp_init(struct interface *ifp) /* 0 is a valid fd, so init to -1 */ state->raw_fd = -1; +#ifdef ARPING + state->arping_index = -1; +#endif /* Now is a good time to find IPv4 routes */ if_initrt(ifp->ctx, AF_INET); } @@ -3663,6 +3669,9 @@ void dhcp_start(struct interface *ifp) { struct timespec tv; +#ifdef ARPING + const struct dhcp_state *state; +#endif if (!(ifp->options->options & DHCPCD_IPV4)) return; @@ -3706,6 +3715,15 @@ dhcp_start(struct interface *ifp) return; } +#ifdef ARPING + /* If we have arpinged then we have already delayed. */ + state = D_CSTATE(ifp); + if (state != NULL && state->arping_index != -1) { + dhcp_start1(ifp); + return; + } +#endif + tv.tv_sec = DHCP_MIN_DELAY; tv.tv_nsec = (suseconds_t)arc4random_uniform( (DHCP_MAX_DELAY - DHCP_MIN_DELAY) * NSEC_PER_SEC); @@ -3720,6 +3738,13 @@ dhcp_start(struct interface *ifp) void dhcp_abort(struct interface *ifp) { +#ifdef ARPING + struct dhcp_state *state; + + state = D_STATE(ifp); + if (state != NULL) + state->arping_index = -1; +#endif eloop_timeout_delete(ifp->ctx->eloop, dhcp_start1, ifp); } diff --git a/dhcp.h b/dhcp.h index 931fa377..64ca34b4 100644 --- a/dhcp.h +++ b/dhcp.h @@ -209,7 +209,7 @@ struct dhcp_state { unsigned char *clientid; struct authstate auth; #ifdef ARPING - size_t arping_index; + ssize_t arping_index; #endif }; diff --git a/if-options.c b/if-options.c index eba1a086..c832c214 100644 --- a/if-options.c +++ b/if-options.c @@ -1238,7 +1238,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, if (parse_addr(ctx, &addr, NULL, arg) != 0) return -1; naddr = realloc(ifo->arping, - sizeof(in_addr_t) * (ifo->arping_len + 1)); + sizeof(in_addr_t) * ((size_t)ifo->arping_len + 1)); if (naddr == NULL) { logger(ctx, LOG_ERR, "%s: %m", __func__); return -1; diff --git a/if-options.h b/if-options.h index bbd26eab..6d35d044 100644 --- a/if-options.h +++ b/if-options.h @@ -197,7 +197,7 @@ struct if_options { in_addr_t *blacklist; size_t whitelist_len; in_addr_t *whitelist; - size_t arping_len; + ssize_t arping_len; in_addr_t *arping; char *fallback;