From: Roy Marples Date: Sun, 17 Feb 2013 18:17:29 +0000 (+0000) Subject: Work on FreeBSD9 where we fail on some interfaces X-Git-Tag: v5.99.6~65 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=83e82504e5fbcb4dad08714ecd77db58642af82e;p=thirdparty%2Fdhcpcd.git Work on FreeBSD9 where we fail on some interfaces --- diff --git a/arp.c b/arp.c index d61053a4..82b2a641 100644 --- a/arp.c +++ b/arp.c @@ -256,6 +256,12 @@ arp_probe(void *arg) struct timeval tv; int arping = 0; + if (state->arp_fd == -1) { + if (ipv4_opensocket(ifp, ETHERTYPE_ARP) == -1) + return; + eloop_event_add(state->arp_fd, arp_packet, ifp); + } + if (state->arping_index < ifp->options->arping_len) { addr.s_addr = ifp->options->arping[state->arping_index]; arping = 1; @@ -267,10 +273,6 @@ arp_probe(void *arg) } else addr.s_addr = state->addr.s_addr; - if (state->arp_fd == -1) { - ipv4_opensocket(ifp, ETHERTYPE_ARP); - eloop_event_add(state->arp_fd, arp_packet, ifp); - } if (state->probes == 0) { if (arping) syslog(LOG_INFO, "%s: searching for %s", diff --git a/dhcp.c b/dhcp.c index 8ec51400..6ae46b91 100644 --- a/dhcp.c +++ b/dhcp.c @@ -1342,11 +1342,11 @@ dhcp_openudp(struct interface *iface) #endif if ((s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) - return -1; + return -1; n = 1; if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n)) == -1) - goto eexit; + goto eexit; #ifdef SO_BINDTODEVICE memset(&ifr, 0, sizeof(ifr)); strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name)); @@ -1356,20 +1356,20 @@ dhcp_openudp(struct interface *iface) *p = '\0'; if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) == -1) - goto eexit; + goto eexit; #endif /* As we don't use this socket for receiving, set the * * receive buffer to 1 */ n = 1; if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) == -1) - goto eexit; + goto eexit; state = D_STATE(iface); memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_port = htons(DHCP_CLIENT_PORT); sin.sin_addr.s_addr = state->addr.s_addr; if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) == -1) - goto eexit; + goto eexit; state->udp_fd = s; set_cloexec(s); @@ -1445,9 +1445,9 @@ dhcp_makeudppacket(uint8_t **p, const uint8_t *data, size_t length, ip->ip_p = IPPROTO_UDP; ip->ip_src.s_addr = source.s_addr; if (dest.s_addr == 0) - ip->ip_dst.s_addr = INADDR_BROADCAST; + ip->ip_dst.s_addr = INADDR_BROADCAST; else - ip->ip_dst.s_addr = dest.s_addr; + ip->ip_dst.s_addr = dest.s_addr; udp->uh_sport = htons(DHCP_CLIENT_PORT); udp->uh_dport = htons(DHCP_SERVER_PORT); @@ -2413,10 +2413,11 @@ dhcp_open(struct interface *ifp) state = D_STATE(ifp); if (state->raw_fd == -1) { - if ((r = ipv4_opensocket(ifp, ETHERTYPE_IP)) == -1) + if ((r = ipv4_opensocket(ifp, ETHERTYPE_IP)) == -1) { syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name); - else - eloop_event_add(state->raw_fd, dhcp_handlepacket, ifp); + return -1; + } + eloop_event_add(state->raw_fd, dhcp_handlepacket, ifp); } if (state->udp_fd == -1 && state->addr.s_addr != 0 && @@ -2426,10 +2427,10 @@ dhcp_open(struct interface *ifp) { if (dhcp_openudp(ifp) == -1 && errno != EADDRINUSE) { syslog(LOG_ERR, "%s: dhcp_openudp: %m", ifp->name); - r = -1; + return -1; } } - return r; + return 0; } int @@ -2609,7 +2610,7 @@ dhcp_start(struct interface *ifp) return; } - if (!dhcp_open(ifp)) + if (dhcp_open(ifp) == -1) return; if (ifo->options & DHCPCD_INFORM) { diff --git a/dhcp6.c b/dhcp6.c index 4a187da9..81c46829 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -562,7 +562,7 @@ dhcp6_freedrop_addrs(struct interface *ifp, int drop) ipv6_buildroutes(); } -static void +static int dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *)) { struct dhcp6_state *state; @@ -647,8 +647,12 @@ dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *)) pi.ipi6_ifindex = ifp->index; memcpy(CMSG_DATA(cm), &pi, sizeof(pi)); - if (sendmsg(sock, &sndhdr, 0) == -1) + if (sendmsg(sock, &sndhdr, 0) == -1) { syslog(LOG_ERR, "%s: sendmsg: %m", ifp->name); + ifp->options->options &= ~DHCPCD_IPV6; + dhcp6_drop(ifp, "EXPIRE6"); + return -1; + } state->RTC++; if (callback) { @@ -661,6 +665,7 @@ dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *)) syslog(LOG_WARNING, "%s: sent %d times with no reply", ifp->name, state->RTC); } + return 0; } static void @@ -754,6 +759,7 @@ dhcp6_startdiscover(void *arg) struct dhcp6_state *state; ifp = arg; + printf ("%s: HERE!!!!\n", ifp->name); state = D6_STATE(ifp); state->state = DH6S_DISCOVER; state->start_uptime = uptime(); @@ -786,7 +792,8 @@ dhcp6_failconfirm(void *arg) /* Section 18.1.2 says that we SHOULD use the last known * IP address(s) and lifetimes if we didn't get a reply. * I disagree with this. */ - dhcp6_startdiscover(ifp); + if (ifp->options->options & DHCPCD_IPV6) + dhcp6_startdiscover(ifp); } static void diff --git a/ipv6rs.c b/ipv6rs.c index 3e09ee38..f71db5bb 100644 --- a/ipv6rs.c +++ b/ipv6rs.c @@ -257,8 +257,12 @@ ipv6rs_sendprobe(void *arg) memcpy(CMSG_DATA(cm), &hoplimit, sizeof(hoplimit)); syslog(LOG_INFO, "%s: sending IPv6 Router Solicitation", ifp->name); - if (sendmsg(sock, &sndhdr, 0) == -1) + if (sendmsg(sock, &sndhdr, 0) == -1) { syslog(LOG_ERR, "%s: sendmsg: %m", ifp->name); + ipv6rs_drop(ifp); + ifp->options->options &= ~DHCPCD_IPV6RS; + return; + } if (state->rsprobes++ < MAX_RTR_SOLICITATIONS) eloop_timeout_add_sec(RTR_SOLICITATION_INTERVAL,