]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
If we load a saved lease we are trying to rebind, set ciaddr correctly.
authorRoy Marples <roy@marples.name>
Wed, 1 Jul 2015 19:36:32 +0000 (19:36 +0000)
committerRoy Marples <roy@marples.name>
Wed, 1 Jul 2015 19:36:32 +0000 (19:36 +0000)
dhcp.c
dhcp.h

diff --git a/dhcp.c b/dhcp.c
index 80ca5962533b1a493670d7027627c1f4a0bd716e..f9fb4643787ccf901227ef8f9a9fb58f39dd5fd9 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -1660,31 +1660,26 @@ send_message(struct interface *ifp, uint8_t type,
            !(ia->addr_flags & IN_IFF_NOTUSEABLE)) &&
 #endif
            (state->lease.server.s_addr ||
-           ifp->options->options & DHCPCD_INFORM))
+           ifp->options->options & DHCPCD_INFORM) &&
+           !IS_BOOTP(ifp, state->new))
        {
                s = dhcp_openudp(ifp);
-               if (s == -1 && errno != EADDRINUSE)
-                       logger(ifp->ctx, LOG_ERR,
-                           "%s: dhcp_openudp: %m", ifp->name);
+               if (s == -1) {
+                       if (errno != EADDRINUSE)
+                               logger(ifp->ctx, LOG_ERR,
+                                   "%s: dhcp_openudp: %m", ifp->name);
+                       /* We cannot renew */
+                       a = state->addr.s_addr;
+                       state->addr.s_addr = INADDR_ANY;
+               }
        }
 
-       /* If we couldn't open a UDP port for our IP address
-        * then we cannot renew.
-        * This could happen if our IP was pulled out from underneath us.
-        * Also, we should not unicast from a BOOTP lease. */
-       if (s == -1 ||
-           (!(ifo->options & DHCPCD_INFORM) &&
-           IS_BOOTP(ifp, state->new)))
-       {
-               a = state->addr.s_addr;
-               state->addr.s_addr = INADDR_ANY;
-       }
        r = make_message(&dhcp, ifp, type);
+       if (a != INADDR_ANY)
+               state->addr.s_addr = a;
        if (r == -1)
                goto fail;
        len = (size_t)r;
-       if (a)
-               state->addr.s_addr = a;
        from.s_addr = dhcp->ciaddr;
        if (from.s_addr)
                to.s_addr = state->lease.server.s_addr;
diff --git a/dhcp.h b/dhcp.h
index 04d1df8ab6f6d8eb579dd7a7d6f73887ea82884b..daa4f56000568b1e14d172e99bf216ea746df626 100644 (file)
--- a/dhcp.h
+++ b/dhcp.h
@@ -243,7 +243,7 @@ void dhcp_printoptions(const struct dhcpcd_ctx *,
     const struct dhcp_opt *, size_t);
 int get_option_addr(struct dhcpcd_ctx *,struct in_addr *,
     const struct dhcp_message *, uint8_t);
-#define IS_BOOTP(i, m) ((m) &&                                             \
+#define IS_BOOTP(i, m) ((m) != NULL &&                                             \
            get_option_uint8((i)->ctx, NULL, (m), DHO_MESSAGETYPE) == -1)
 struct rt_head *get_option_routes(struct interface *,
     const struct dhcp_message *);