From: Roy Marples Date: Thu, 20 Nov 2008 09:57:46 +0000 (+0000) Subject: BOOTP fixes. Also, we don't write a BOOTP lease file. X-Git-Tag: v5.0.0~172 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2328d2dddd1513622f04d1953269dac6f1fd051;p=thirdparty%2Fdhcpcd.git BOOTP fixes. Also, we don't write a BOOTP lease file. --- diff --git a/dhcp.c b/dhcp.c index cd6d7195..ae93235a 100644 --- 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; diff --git a/dhcpcd.c b/dhcpcd.c index 05ee45e1..a263e9b1 100644 --- 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 eb09633a..727590e0 100644 --- 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 *);