]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Work on FreeBSD9 where we fail on some interfaces
authorRoy Marples <roy@marples.name>
Sun, 17 Feb 2013 18:17:29 +0000 (18:17 +0000)
committerRoy Marples <roy@marples.name>
Sun, 17 Feb 2013 18:17:29 +0000 (18:17 +0000)
arp.c
dhcp.c
dhcp6.c
ipv6rs.c

diff --git a/arp.c b/arp.c
index d61053a49c25db4f99455bbfd4723d07ae5b5dbd..82b2a641704ea25a655f1a335f3c9796493ffb73 100644 (file)
--- 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 8ec514002b9d10fc9fd0cd2716aba99fd10c18ee..6ae46b912624d8b2e96b2110091d960b4185181b 100644 (file)
--- 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 4a187da9f1e8b14db2b505b9a128ba50082e75bd..81c468299d447d6f6f6dd981c5ffdcc6f3892791 100644 (file)
--- 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
index 3e09ee38f5ce049502978c437d7e19e74dc17fc4..f71db5bb197052422693abea2fd57c707e70b18c 100644 (file)
--- 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,