From: Roy Marples Date: Mon, 26 May 2008 09:58:36 +0000 (+0000) Subject: Pull ARP replies correctly. X-Git-Tag: v4.0.2~333 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2d3069decc2e6530c3db0212cf73ea9cab30f6d;p=thirdparty%2Fdhcpcd.git Pull ARP replies correctly. --- diff --git a/client.c b/client.c index 85a7ba00..07bed64c 100644 --- a/client.c +++ b/client.c @@ -1266,7 +1266,6 @@ dhcp_run(const struct options *options, int *pidfd) goto eexit; fds[POLLFD_SIGNAL].fd = signal_fd(); - for (;;) { retval = wait_for_packet(fds, state, options); diff --git a/lpf.c b/lpf.c index 4491e0be..87e6460a 100644 --- a/lpf.c +++ b/lpf.c @@ -163,13 +163,13 @@ get_packet(struct interface *iface, void *data, ssize_t len) return errno == EAGAIN ? 0 : -1; /* If it's an ARP reply, then just send it back */ - if (iface->socket_protocol == ETHERTYPE_ARP) - return bytes; - - if (valid_udp_packet(iface->buffer) != 0) - return -1; - - bytes = get_udp_data(&p, iface->buffer); + if (iface->socket_protocol == ETHERTYPE_ARP) { + p = iface->buffer; + } else { + if (valid_udp_packet(iface->buffer) != 0) + return -1; + bytes = get_udp_data(&p, iface->buffer); + } if (bytes > len) bytes = len; memcpy(data, p, bytes); diff --git a/net.c b/net.c index 87feebef..34e1889c 100644 --- a/net.c +++ b/net.c @@ -732,7 +732,6 @@ arp_claim(struct interface *iface, struct in_addr address) if (get_time(&stopat) != 0) break; stopat.tv_usec += timeout; - continue; } @@ -746,29 +745,32 @@ arp_claim(struct interface *iface, struct in_addr address) if (!(fds[1].revents & POLLIN)) continue; - for(;;) { memset(&arp_reply, 0, sizeof(arp_reply)); - bytes = get_packet(iface, &arp_reply, sizeof(arp_reply)); + bytes = get_packet(iface, + &arp_reply, sizeof(arp_reply)); if (bytes == -1 || bytes == 0) break; - memcpy(&reply, arp_reply, sizeof(reply)); + memcpy(&reply, &arp_reply, sizeof(reply)); /* Only these types are recognised */ if (reply.ar_op != htons(ARPOP_REPLY)) continue; - /* Protocol must be IP. */ if (reply.ar_pro != htons(ETHERTYPE_IP)) continue; if (reply.ar_pln != sizeof(reply_ipv4)) continue; - if ((size_t)bytes < sizeof(reply) + 2 * (4 + reply.ar_hln) || + if ((size_t)bytes < sizeof(reply) + 2 * + (4 + reply.ar_hln) || reply.ar_hln > 8) continue; - memcpy(&reply_mac, arp_reply + sizeof(reply), reply.ar_hln); - memcpy(&reply_ipv4, arp_reply + sizeof(reply) + reply.ar_hln, reply.ar_hln); + memcpy(&reply_mac, + arp_reply + sizeof(reply), reply.ar_hln); + memcpy(&reply_ipv4, + arp_reply + sizeof(reply) + reply.ar_hln, + reply.ar_hln); /* Ensure the ARP reply is for the our address */ if (reply_ipv4.s_addr != address.s_addr) @@ -777,12 +779,14 @@ arp_claim(struct interface *iface, struct in_addr address) /* Some systems send a reply back from our hwaddress, * which is wierd */ if (reply.ar_hln == iface->hwlen && - memcmp(&reply_mac, iface->hwaddr, iface->hwlen) == 0) + memcmp(&reply_mac, iface->hwaddr, + iface->hwlen) == 0) continue; logger(LOG_ERR, "ARPOP_REPLY received from %s (%s)", inet_ntoa(reply_ipv4), - hwaddr_ntoa((unsigned char *)&reply_mac, (size_t)reply.ar_hln)); + hwaddr_ntoa((unsigned char *)&reply_mac, + (size_t)reply.ar_hln)); retval = -1; goto eexit; }