]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Change arping_index from 1 based to 0 based, defaulting not started to -1.
authorRoy Marples <roy@marples.name>
Tue, 6 Dec 2016 19:28:05 +0000 (19:28 +0000)
committerRoy Marples <roy@marples.name>
Tue, 6 Dec 2016 19:28:05 +0000 (19:28 +0000)
Fixes pinging the last set address.

dhcp.c
dhcp.h
if-options.c
if-options.h

diff --git a/dhcp.c b/dhcp.c
index d19a7c08f131746bf907cea985832c18aef0bf67..d222342c2295c7e9d7e1cef23dbd022c865741ee 100644 (file)
--- 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 931fa377d834d5c152c5af4725c1cfa0b2736db1..64ca34b49de3a645c1d50d4c560142e4bcf9db74 100644 (file)
--- 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
 };
 
index eba1a086ab6daeb9f5e980f5a475a149ad696867..c832c21497210a1acd283526bb1c70d1a08675d2 100644 (file)
@@ -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;
index bbd26eab9adeab628578212849441dbf3c10476b..6d35d044bae8caf091d8bbb428a68efa4c0a67c8 100644 (file)
@@ -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;