]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Don't send DHCP messages when we don't have a carrier.
authorRoy Marples <roy@marples.name>
Fri, 15 May 2015 22:05:17 +0000 (22:05 +0000)
committerRoy Marples <roy@marples.name>
Fri, 15 May 2015 22:05:17 +0000 (22:05 +0000)
dhcp.c
dhcp6.c

diff --git a/dhcp.c b/dhcp.c
index 3fb9ddd3a38af96d8c3970f8e6c97b4de91c04f3..a8edf3eb75b6c5081795d44711f13a0c1b3020b8 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -1593,12 +1593,16 @@ send_message(struct interface *ifp, uint8_t type,
        struct ipv4_addr *ia;
 #endif
 
-       if (!callback)
+       s = -1;
+       if (!callback) {
+               /* No carrier? Don't bother sending the packet. */
+               if (ifp->carrier == LINK_DOWN)
+                       return;
                logger(ifp->ctx, LOG_DEBUG, "%s: sending %s with xid 0x%x",
                    ifp->name,
                    ifo->options & DHCPCD_BOOTP ? "BOOTP" : get_dhcp_op(type),
                    state->xid);
-       else {
+       else {
                if (state->interval == 0)
                        state->interval = 4;
                else {
@@ -1610,6 +1614,10 @@ send_message(struct interface *ifp, uint8_t type,
                tv.tv_nsec = (suseconds_t)arc4random_uniform(
                    (DHCP_RAND_MAX - DHCP_RAND_MIN) * NSEC_PER_SEC);
                timespecnorm(&tv);
+               /* No carrier? Don't bother sending the packet.
+                * However, we do need to advance the timeout. */
+               if (ifp->carrier == LINK_DOWN)
+                       goto fail;
                logger(ifp->ctx, LOG_DEBUG,
                    "%s: sending %s (xid 0x%x), next in %0.1f seconds",
                    ifp->name,
@@ -1635,8 +1643,7 @@ send_message(struct interface *ifp, uint8_t type,
                if (s == -1 && errno != EADDRINUSE)
                        logger(ifp->ctx, LOG_ERR,
                            "%s: dhcp_openudp: %m", ifp->name);
-       } else
-               s = -1;
+       }
 
        /* If we couldn't open a UDP port for our IP address
         * then we cannot renew.
diff --git a/dhcp6.c b/dhcp6.c
index b35b02b7cbeec7994634f57fb34ea990a262d228..c1b7bfdb36883cc5cce2c441421dedb7fdfd5fa9 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -1019,6 +1019,9 @@ dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *))
        const char *broad_uni;
        const struct in6_addr alldhcp = IN6ADDR_LINKLOCAL_ALLDHCP_INIT;
 
+       if (!callback && ifp->carrier == LINK_DOWN)
+               return 0;
+
        memset(&dst, 0, sizeof(dst));
        dst.sin6_family = AF_INET6;
        dst.sin6_port = htons(DHCP6_SERVER_PORT);
@@ -1106,16 +1109,17 @@ dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *))
                }
 
 logsend:
-               logger(ifp->ctx, LOG_DEBUG,
-                   "%s: %s %s (xid 0x%02x%02x%02x),"
-                   " next in %0.1f seconds",
-                   ifp->name,
-                   broad_uni,
-                   dhcp6_get_op(state->send->type),
-                   state->send->xid[0],
-                   state->send->xid[1],
-                   state->send->xid[2],
-                   timespec_to_double(&state->RT));
+               if (ifp->carrier != LINK_DOWN)
+                       logger(ifp->ctx, LOG_DEBUG,
+                           "%s: %s %s (xid 0x%02x%02x%02x),"
+                           " next in %0.1f seconds",
+                           ifp->name,
+                           broad_uni,
+                           dhcp6_get_op(state->send->type),
+                           state->send->xid[0],
+                           state->send->xid[1],
+                           state->send->xid[2],
+                           timespec_to_double(&state->RT));
 
                /* Wait the initial delay */
                if (state->IMD) {
@@ -1126,6 +1130,9 @@ logsend:
                }
        }
 
+       if (ifp->carrier == LINK_DOWN)
+               return 0;
+
        /* Update the elapsed time */
        dhcp6_updateelapsed(ifp, state->send, state->send_len);
        if (ifp->options->auth.options & DHCPCD_AUTH_SEND &&