Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/dhcpcd/dist/src Sync



details:   https://anonhg.NetBSD.org/src/rev/0f1c96297d01
branches:  trunk
changeset: 450562:0f1c96297d01
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Apr 17 23:35:34 2019 +0000

description:
Sync

diffstat:

 external/bsd/dhcpcd/dist/src/dhcp.c       |  283 +++++++++++++++++++----------
 external/bsd/dhcpcd/dist/src/dhcp6.c      |  230 +++++++++++------------
 external/bsd/dhcpcd/dist/src/dhcpcd.c     |   12 +-
 external/bsd/dhcpcd/dist/src/if-bsd.c     |   81 +++++--
 external/bsd/dhcpcd/dist/src/if-options.c |  141 ++++++-------
 external/bsd/dhcpcd/dist/src/ipv6nd.c     |  194 +++++++++-----------
 6 files changed, 508 insertions(+), 433 deletions(-)

diffs (truncated from 2052 to 300 lines):

diff -r 5c930ea839d3 -r 0f1c96297d01 external/bsd/dhcpcd/dist/src/dhcp.c
--- a/external/bsd/dhcpcd/dist/src/dhcp.c       Wed Apr 17 23:33:08 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp.c       Wed Apr 17 23:35:34 2019 +0000
@@ -86,9 +86,9 @@
 #define IPDEFTTL 64 /* RFC1340 */
 #endif
 
-/* NetBSD-7 has an incomplete IP_PKTINFO implementation. */
-#if defined(__NetBSD_Version__) && __NetBSD_Version__ < 800000000
-#undef IP_PKTINFO
+/* Support older systems with different defines */
+#if !defined(IP_RECVPKTINFO) && defined(IP_PKTINFO)
+#define IP_RECVPKTINFO IP_PKTINFO
 #endif
 
 /* Assert the correct structure size for on wire */
@@ -129,6 +129,9 @@
 #endif
 static void dhcp_handledhcp(struct interface *, struct bootp *, size_t,
     const struct in_addr *);
+#ifdef IP_PKTINFO
+static void dhcp_handleifudp(void *);
+#endif
 static int dhcp_initstate(struct interface *);
 
 void
@@ -447,7 +450,7 @@
                memcpy(&gateway.s_addr, p, 4);
                p += 4;
 
-               /* A host route is normally set by having the
+               /* An on-link host route is normally set by having the
                 * gateway match the destination or assigned address */
                if (gateway.s_addr == dest.s_addr ||
                    (gateway.s_addr == bootp->yiaddr ||
@@ -455,17 +458,14 @@
                {
                        gateway.s_addr = INADDR_ANY;
                        netmask.s_addr = INADDR_BROADCAST;
+               }
+               if (netmask.s_addr == INADDR_BROADCAST)
                        rt->rt_flags = RTF_HOST;
-               }
 
                sa_in_init(&rt->rt_dest, &dest);
                sa_in_init(&rt->rt_netmask, &netmask);
                sa_in_init(&rt->rt_gateway, &gateway);
 
-               /* If CIDR is 32 then it's a host route. */
-               if (cidr == 32)
-                       rt->rt_flags = RTF_HOST;
-
                TAILQ_INSERT_TAIL(routes, rt, rt_next);
                n++;
        }
@@ -638,7 +638,7 @@
                        if ((rt = rt_new(ifp)) == NULL)
                                return -1;
 
-                       /* A host route is normally set by having the
+                       /* A on-link host route is normally set by having the
                         * gateway match the destination or assigned address */
                        if (gateway.s_addr == dest.s_addr ||
                             (gateway.s_addr == bootp->yiaddr ||
@@ -646,12 +646,15 @@
                        {
                                gateway.s_addr = INADDR_ANY;
                                netmask.s_addr = INADDR_BROADCAST;
-                               rt->rt_flags = RTF_HOST;
                        } else
                                netmask.s_addr = route_netmask(dest.s_addr);
+                       if (netmask.s_addr == INADDR_BROADCAST)
+                               rt->rt_flags = RTF_HOST;
+
                        sa_in_init(&rt->rt_dest, &dest);
                        sa_in_init(&rt->rt_netmask, &netmask);
                        sa_in_init(&rt->rt_gateway, &gateway);
+
                        TAILQ_INSERT_TAIL(routes, rt, rt_next);
                        n++;
                }
@@ -1587,6 +1590,11 @@
                state->bpf_fd = -1;
                state->bpf_flags |= BPF_EOF;
        }
+       if (state->udp_fd != -1) {
+               eloop_event_delete(ifp->ctx->eloop, state->udp_fd);
+               close(state->udp_fd);
+               state->udp_fd = -1;
+       }
 
        state->interval = 0;
 }
@@ -1604,11 +1612,15 @@
        n = 1;
        if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n)) == -1)
                goto eexit;
+#ifdef IP_RECVPKTINFO
+       if (setsockopt(s, IPPROTO_IP, IP_RECVPKTINFO, &n, sizeof(n)) == -1)
+               goto eexit;
+#endif
        memset(&sin, 0, sizeof(sin));
        sin.sin_family = AF_INET;
        sin.sin_port = htons(BOOTPC);
        if (ifp) {
-               struct dhcp_state *state = D_STATE(ifp);
+               const struct dhcp_state *state = D_CSTATE(ifp);
 
                if (state->addr)
                        sin.sin_addr.s_addr = state->addr->addr.s_addr;
@@ -1699,12 +1711,8 @@
        struct msghdr msg;
        struct sockaddr_in sin;
        struct iovec iov[1];
+       struct dhcp_state *state = D_STATE(ifp);
        ssize_t r;
-#ifdef IP_PKTINFO
-       uint8_t cmsg[CMSG_SPACE(sizeof(struct in_pktinfo))];
-       struct cmsghdr *cm;
-       struct in_pktinfo ipi;
-#endif
 
        iov[0].iov_base = data;
        iov[0].iov_len = len;
@@ -1723,29 +1731,15 @@
        msg.msg_iov = iov;
        msg.msg_iovlen = 1;
 
-#ifdef IP_PKTINFO
-       /* Set the outbound interface */
-       msg.msg_control = cmsg;
-       msg.msg_controllen = sizeof(cmsg);
-
-       memset(&ipi, 0, sizeof(ipi));
-       ipi.ipi_ifindex = ifp->index;
-       cm = CMSG_FIRSTHDR(&msg);
-       if (cm == NULL) {
-               errno = ESRCH;
-               return -1;
+       s = state->udp_fd;
+       if (s == -1) {
+               s = dhcp_openudp(ifp);
+               if (s == -1)
+                       return -1;
        }
-       cm->cmsg_level = IPPROTO_IP;
-       cm->cmsg_type = IP_PKTINFO;
-       cm->cmsg_len = CMSG_LEN(sizeof(ipi));
-       memcpy(CMSG_DATA(cm), &ipi, sizeof(ipi));
-#endif
-
-       s = dhcp_openudp(ifp);
-       if (s == -1)
-               return -1;
        r = sendmsg(s, &msg, 0);
-       close(s);
+       if (state->udp_fd == -1)
+               close(s);
        return r;
 }
 
@@ -1803,7 +1797,7 @@
        else
                to.s_addr = INADDR_ANY;
 
-       /* If unicasting, try and void sending by BPF so we don't
+       /* If unicasting, try and avoid sending by BPF so we don't
         * use a L2 broadcast. */
        if (to.s_addr != INADDR_ANY && to.s_addr != INADDR_BROADCAST) {
                if (dhcp_sendudp(ifp, &to, bootp, len) != -1)
@@ -2068,11 +2062,6 @@
                        return;
                }
                arp_free(astate);
-#ifdef KERNEL_RFC5227
-               /* As arping is finished, close the ARP socket.
-                * The kernel will handle ACD from here. */
-               arp_close(ifp);
-#endif
                dhcpcd_startinterface(ifp);
                return;
        }
@@ -2150,11 +2139,6 @@
                        return;
                }
                arp_free(astate);
-#ifdef KERNEL_RFC5227
-               /* As arping is finished, close the ARP socket.
-                * The kernel will handle ACD from here. */
-               arp_close(ifp);
-#endif
                eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
                dhcpcd_startinterface(ifp);
                return;
@@ -2209,11 +2193,22 @@
                return;
        }
 }
+
+static void
+dhcp_arp_announced(struct arp_state *state)
+{
+
+// TODO: DHCP addresses handle ACD?
+//#ifdef KERNEL_RFC5227
+       arp_free(state);
+//#endif
+}
 #endif
 
 void
 dhcp_bind(struct interface *ifp)
 {
+       struct dhcpcd_ctx *ctx = ifp->ctx;
        struct dhcp_state *state = D_STATE(ifp);
        struct if_options *ifo = ifp->options;
        struct dhcp_lease *lease = &state->lease;
@@ -2289,10 +2284,10 @@
                                    lease->leasetime);
                }
        }
-       if (ifp->ctx->options & DHCPCD_TEST) {
+       if (ctx->options & DHCPCD_TEST) {
                state->reason = "TEST";
                script_runreason(ifp, state->reason);
-               eloop_exit(ifp->ctx->eloop, EXIT_SUCCESS);
+               eloop_exit(ctx->eloop, EXIT_SUCCESS);
                return;
        }
        if (state->reason == NULL) {
@@ -2311,26 +2306,42 @@
        if (lease->leasetime == ~0U)
                lease->renewaltime = lease->rebindtime = lease->leasetime;
        else {
-               eloop_timeout_add_sec(ifp->ctx->eloop,
+               eloop_timeout_add_sec(ctx->eloop,
                    (time_t)lease->renewaltime, dhcp_startrenew, ifp);
-               eloop_timeout_add_sec(ifp->ctx->eloop,
+               eloop_timeout_add_sec(ctx->eloop,
                    (time_t)lease->rebindtime, dhcp_rebind, ifp);
-               eloop_timeout_add_sec(ifp->ctx->eloop,
+               eloop_timeout_add_sec(ctx->eloop,
                    (time_t)lease->leasetime, dhcp_expire, ifp);
                logdebugx("%s: renew in %"PRIu32" seconds, rebind in %"PRIu32
                    " seconds",
                    ifp->name, lease->renewaltime, lease->rebindtime);
        }
        state->state = DHS_BOUND;
-       /* Re-apply the filter because we need to accept any XID anymore. */
-       if (bpf_bootp(ifp, state->bpf_fd) == -1)
-               logerr(__func__); /* try to continue */
        if (!state->lease.frominfo &&
            !(ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC)))
                if (write_lease(ifp, state->new, state->new_len) == -1)
                        logerr(__func__);
 
        ipv4_applyaddr(ifp);
+
+#ifdef IP_PKTINFO
+       /* Close the BPF filter as we can now receive the DHCP renew messages
+        * on a UDP socket. */
+       if (state->udp_fd == -1 ||
+           (state->old != NULL && state->old->yiaddr != state->new->yiaddr))
+       {
+               dhcp_close(ifp);
+               /* If not in master mode, open an address specific socket. */
+               if (ctx->udp_fd == -1) {
+                       state->udp_fd = dhcp_openudp(ifp);
+                       if (state->udp_fd == -1)
+                               logerr(__func__);
+                       else
+                               eloop_event_add(ctx->eloop,
+                                   state->udp_fd, dhcp_handleifudp, ifp);
+               }
+       }
+#endif
 }
 
 static void
@@ -2384,6 +2395,20 @@
 }
 
 #ifdef ARP
+static struct arp_state *
+dhcp_arp_new(struct interface *ifp, struct in_addr *addr)
+{
+       struct arp_state *astate;
+       astate = arp_new(ifp, addr);
+       if (astate == NULL)
+               return NULL;
+
+       astate->probed_cb = dhcp_arp_probed;
+       astate->conflicted_cb = dhcp_arp_conflicted;
+       astate->announced_cb = dhcp_arp_announced;
+       return astate;
+}
+
 static int
 dhcp_arp_address(struct interface *ifp)
 {



Home | Main Index | Thread Index | Old Index