]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
BOOTP fixes. Also, we don't write a BOOTP lease file.
authorRoy Marples <roy@marples.name>
Thu, 20 Nov 2008 09:57:46 +0000 (09:57 +0000)
committerRoy Marples <roy@marples.name>
Thu, 20 Nov 2008 09:57:46 +0000 (09:57 +0000)
dhcp.c
dhcpcd.c
dhcpf.h

diff --git a/dhcp.c b/dhcp.c
index cd6d7195280b76ab75d4ac8e94b450bf8e66b3de..ae93235a12cd6c499f6d3033c1c770b15e86a3b3 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -374,7 +374,8 @@ get_option_uint8(uint8_t *i, const struct dhcp_message *dhcp, uint8_t option)
 
        if (!p)
                return -1;
-       *i = *(p);
+       if (i)
+               *i = *(p);
        return 0;
 }
 
@@ -774,7 +775,7 @@ make_message(struct dhcp_message **message,
        if ((type == DHCP_INFORM ||
             type == DHCP_RELEASE ||
             type == DHCP_REQUEST) &&
-            !IN_LINKLOCAL(ntohl(iface->addr.s_addr)))
+           !IN_LINKLOCAL(ntohl(iface->addr.s_addr)))
        {
                dhcp->ciaddr = iface->addr.s_addr;
                /* Just incase we haven't actually configured the address yet */
@@ -961,6 +962,12 @@ write_lease(const struct interface *iface, const struct dhcp_message *dhcp)
        uint8_t l;
        uint8_t o = 0;
 
+       /* We don't write BOOTP leases */
+       if (is_bootp(dhcp)) {
+               unlink(iface->leasefile);
+               return 0;
+       }
+
        fd = open(iface->leasefile, O_WRONLY | O_CREAT | O_TRUNC, 0400);
        if (fd == -1)
                return -1;
index 05ee45e17d66f417072dc8916cffee536f0766fe..a263e9b1cf21c9fb9439c2f6715dfc5b58de715f 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -264,19 +264,20 @@ send_message(struct interface *iface, int type,
                tv.tv_sec = state->interval + DHCP_RAND_MIN;
                tv.tv_usec = arc4random() % (DHCP_RAND_MAX_U - DHCP_RAND_MIN_U);
                syslog(LOG_DEBUG,
-                      "%s: sending %s with xid 0x%x, next in %0.2f seconds",
+                      "%s: sending %s (xid 0x%x), next in %0.2f seconds",
                       iface->name, get_dhcp_op(type), state->xid,
                       timeval_to_double(&tv));
        }
        /* 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. */
-       if (iface->udp_fd == -1) {
+        * This could happen if our IP was pulled out from underneath us.
+        * Also, we should not unicast from a BOOTP lease. */
+       if (iface->udp_fd == -1 || is_bootp(iface->state->new)) {
                a = iface->addr.s_addr;
                iface->addr.s_addr = 0;
        }
        len = make_message(&dhcp, iface, type);
-       if (iface->udp_fd == -1)
+       if (a)
                iface->addr.s_addr = a;
        from.s_addr = dhcp->ciaddr;
        if (from.s_addr)
@@ -363,12 +364,8 @@ start_expire(void *arg)
        drop_config(iface, "EXPIRE");
        unlink(iface->leasefile);
        iface->state->interval = 0;
-       if (iface->carrier != LINK_DOWN) {
-               if (IN_LINKLOCAL(htonl(iface->state->lease.addr.s_addr)))
-                       start_interface(iface);
-               else
-                       start_ipv4ll(iface);
-       }
+       if (iface->carrier != LINK_DOWN)
+               start_interface(iface);
 }
 
 void
@@ -534,9 +531,13 @@ handle_dhcp(struct interface *iface, struct dhcp_message **dhcpp)
        }
 
        close_sockets(iface);
-       free(state->offer);
-       state->offer = dhcp;
-       *dhcpp = NULL;
+       /* BOOTP could have already assigned this above, so check we still
+        * have a pointer. */
+       if (*dhcpp) {
+               free(state->offer);
+               state->offer = dhcp;
+               *dhcpp = NULL;
+       }
        /* Delete all timeouts for this interface. */
        delete_timeout(NULL, iface);
        lease->frominfo = 0;
@@ -783,6 +784,9 @@ start_interface(void *arg)
        }
 
        iface->start_uptime = uptime();
+       free(iface->state->offer);
+       iface->state->offer = NULL;
+
        if (options & DHCPCD_TEST) {
                start_discover(iface);
                return;
diff --git a/dhcpf.h b/dhcpf.h
index eb09633a8bd6a9b45a3904ceaa525a031329caf0..727590e08c42808d4187f7a1866e8aa7619581d7 100644 (file)
--- a/dhcpf.h
+++ b/dhcpf.h
@@ -42,6 +42,7 @@ int get_option_addr(uint32_t *, const struct dhcp_message *, uint8_t);
 int get_option_uint32(uint32_t *, const struct dhcp_message *, uint8_t);
 int get_option_uint16(uint16_t *, const struct dhcp_message *, uint8_t);
 int get_option_uint8(uint8_t *, const struct dhcp_message *, uint8_t);
+#define is_bootp(m) (m && get_option_uint8(NULL, m, DHO_MESSAGETYPE) == -1)
 struct rt *get_option_routes(const struct dhcp_message *);
 ssize_t configure_env(char **, const char *, const struct dhcp_message *,
                      const struct if_options *);