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 Sync



details:   https://anonhg.NetBSD.org/src/rev/c4d288ce3c61
branches:  trunk
changeset: 967741:c4d288ce3c61
user:      roy <roy%NetBSD.org@localhost>
date:      Fri Dec 20 12:01:35 2019 +0000

description:
Sync

diffstat:

 external/bsd/dhcpcd/dist/hooks/dhcpcd-run-hooks.in |    2 +-
 external/bsd/dhcpcd/dist/src/dhcp.c                |   47 +++---
 external/bsd/dhcpcd/dist/src/dhcp6.c               |  147 ++++++++++++++------
 external/bsd/dhcpcd/dist/src/dhcpcd.c              |    2 +-
 external/bsd/dhcpcd/dist/src/ipv6.c                |   75 ++++++----
 external/bsd/dhcpcd/dist/src/ipv6.h                |    1 +
 external/bsd/dhcpcd/dist/src/ipv6nd.c              |    2 +-
 7 files changed, 174 insertions(+), 102 deletions(-)

diffs (truncated from 540 to 300 lines):

diff -r b0be46347f16 -r c4d288ce3c61 external/bsd/dhcpcd/dist/hooks/dhcpcd-run-hooks.in
--- a/external/bsd/dhcpcd/dist/hooks/dhcpcd-run-hooks.in        Fri Dec 20 12:00:18 2019 +0000
+++ b/external/bsd/dhcpcd/dist/hooks/dhcpcd-run-hooks.in        Fri Dec 20 12:01:35 2019 +0000
@@ -212,7 +212,7 @@
 
 # With the advent of alternative init systems, it's possible to have
 # more than one installed. So we need to try and guess what one we're
-# using unless overriden by configure.
+# using unless overridden by configure.
 detect_init()
 {
        _service_exists="@SERVICEEXISTS@"
diff -r b0be46347f16 -r c4d288ce3c61 external/bsd/dhcpcd/dist/src/dhcp.c
--- a/external/bsd/dhcpcd/dist/src/dhcp.c       Fri Dec 20 12:00:18 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp.c       Fri Dec 20 12:01:35 2019 +0000
@@ -176,6 +176,11 @@
        const uint8_t *op;
        size_t bl;
 
+       if (bootp == NULL || bootp_len < DHCP_MIN_LEN) {
+               errno = EINVAL;
+               return NULL;
+       }
+
        /* Check we have the magic cookie */
        if (!IS_DHCP(bootp)) {
                errno = ENOTSUP;
@@ -484,7 +489,7 @@
                        return -1;
                break;
        case 1:
-               if (dl == 0 || dl % 4 != 0) {
+               if (dl % 4 != 0) {
                        errno = EINVAL;
                        break;
                }
@@ -1179,7 +1184,7 @@
         * (it should be more, and our read packet enforces this so this
         * code should not be needed, but of course people could
         * scribble whatever in the stored lease file. */
-       if (bytes < offsetof(struct bootp, vend) + 4) {
+       if (bytes < DHCP_MIN_LEN) {
                free(lease);
                logerrx("%s: %s: truncated lease", ifp->name, __func__);
                return 0;
@@ -1540,7 +1545,7 @@
 }
 
 static int
-dhcp_openudp(struct interface *ifp)
+dhcp_openudp(struct in_addr *ia)
 {
        int s;
        struct sockaddr_in sin;
@@ -1551,29 +1556,25 @@
 
        n = 1;
        if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n)) == -1)
-               goto eexit;
+               goto errexit;
 #ifdef IP_RECVIF
        if (setsockopt(s, IPPROTO_IP, IP_RECVIF, &n, sizeof(n)) == -1)
-               goto eexit;
+               goto errexit;
 #else
        if (setsockopt(s, IPPROTO_IP, IP_RECVPKTINFO, &n, sizeof(n)) == -1)
-               goto eexit;
+               goto errexit;
 #endif
        memset(&sin, 0, sizeof(sin));
        sin.sin_family = AF_INET;
        sin.sin_port = htons(BOOTPC);
-       if (ifp) {
-               const struct dhcp_state *state = D_CSTATE(ifp);
-
-               if (state->addr)
-                       sin.sin_addr.s_addr = state->addr->addr.s_addr;
-       }
+       if (ia != NULL)
+               sin.sin_addr = *ia;
        if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) == -1)
-               goto eexit;
+               goto errexit;
 
        return s;
 
-eexit:
+errexit:
        close(s);
        return -1;
 }
@@ -1675,7 +1676,7 @@
 
        fd = state->udp_fd;
        if (fd == -1) {
-               fd = dhcp_openudp(ifp);
+               fd = dhcp_openudp(state->addr != NULL ?&state->addr->addr:NULL);
                if (fd == -1)
                        return -1;
        }
@@ -1734,7 +1735,9 @@
                goto fail;
        len = (size_t)r;
 
-       if (ipv4_iffindaddr(ifp, &state->lease.addr, NULL) != NULL)
+       if (!(state->added & STATE_FAKE) &&
+           state->addr != NULL &&
+           ipv4_iffindaddr(ifp, &state->lease.addr, NULL) != NULL)
                from.s_addr = state->lease.addr.s_addr;
        else
                from.s_addr = INADDR_ANY;
@@ -1751,7 +1754,7 @@
         * even if they are setup to send them.
         * Broadcasting from UDP is only an optimisation for rebinding
         * and on BSD, at least, is reliant on the subnet route being
-        * correctly configured to recieve the unicast reply.
+        * correctly configured to receive the unicast reply.
         * As such, we always broadcast and receive the reply to it via BPF.
         * This also guarantees we have a DHCP server attached to the
         * interface we want to configure because we can't dictate the
@@ -2266,10 +2269,11 @@
                return;
        dhcp_close(ifp);
 
+
        /* If not in master mode, open an address specific socket. */
        if (ctx->udp_fd != -1)
                return;
-       state->udp_fd = dhcp_openudp(ifp);
+       state->udp_fd = dhcp_openudp(&state->addr->addr);
        if (state->udp_fd == -1) {
                logerr(__func__);
                /* Address sharing without master mode is not supported.
@@ -2352,6 +2356,7 @@
 #ifdef KERNEL_RFC5227
        astate->announced_cb = dhcp_arp_announced;
 #else
+       astate->announced_cb = NULL;
        astate->defend_failed_cb = dhcp_arp_defend_failed;
 #endif
        return astate;
@@ -2501,7 +2506,7 @@
                        state->offer_len = dhcp_message_new(&state->offer,
                            &ifo->req_addr, &ifo->req_mask);
 #ifdef ARP
-                       if (dhcp_arp_address(ifp) == 0)
+                       if (dhcp_arp_address(ifp) != 1)
                                return;
 #endif
                        ia = ipv4_iffindaddr(ifp,
@@ -3390,7 +3395,7 @@
 }
 
 static void
-dhcp_handlebpf(struct interface *ifp, uint8_t *data, size_t len)
+dhcp_packet(struct interface *ifp, uint8_t *data, size_t len)
 {
        struct bootp *bootp;
        struct in_addr from;
@@ -3445,7 +3450,7 @@
                        }
                        break;
                }
-               dhcp_handlebpf(ifp, buf, (size_t)bytes);
+               dhcp_packet(ifp, buf, (size_t)bytes);
                /* Check we still have a state after processing. */
                if ((state = D_STATE(ifp)) == NULL)
                        break;
diff -r b0be46347f16 -r c4d288ce3c61 external/bsd/dhcpcd/dist/src/dhcp6.c
--- a/external/bsd/dhcpcd/dist/src/dhcp6.c      Fri Dec 20 12:00:18 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp6.c      Fri Dec 20 12:01:35 2019 +0000
@@ -171,7 +171,7 @@
 
 static void dhcp6_bind(struct interface *, const char *, const char *);
 static void dhcp6_failinform(void *);
-static int dhcp6_listen(struct dhcpcd_ctx *, struct ipv6_addr *);
+static int dhcp6_openudp(unsigned int, struct in6_addr *);
 static void dhcp6_recvaddr(void *);
 
 void
@@ -2132,13 +2132,10 @@
                        a->dadcallback = dhcp6_dadcallback;
                        a->ia_type = D6_OPTION_IA_PD;
                        memcpy(a->iaid, iaid, sizeof(a->iaid));
-                       TAILQ_INIT(&a->pd_pfxs);
                        TAILQ_INSERT_TAIL(&state->addrs, a, next);
                } else {
-                       if (!(a->flags & IPV6_AF_DELEGATEDPFX)) {
+                       if (!(a->flags & IPV6_AF_DELEGATEDPFX))
                                a->flags |= IPV6_AF_NEW | IPV6_AF_DELEGATEDPFX;
-                               TAILQ_INIT(&a->pd_pfxs);
-                       }
                        a->flags &= ~(IPV6_AF_STALE |
                                      IPV6_AF_EXTENDED |
                                      IPV6_AF_REQUEST);
@@ -2341,6 +2338,46 @@
        return i;
 }
 
+#ifndef SMALL
+static void
+dhcp6_deprecatedele(struct ipv6_addr *ia)
+{
+       struct ipv6_addr *da, *dan, *dda;
+       struct timespec now;
+       struct dhcp6_state *state;
+
+       timespecclear(&now);
+       TAILQ_FOREACH_SAFE(da, &ia->pd_pfxs, pd_next, dan) {
+               if (ia->prefix_vltime == 0) {
+                       if (da->prefix_vltime != 0)
+                               da->prefix_vltime = 0;
+                       else
+                               continue;
+               } else if (da->prefix_pltime != 0)
+                       da->prefix_pltime = 0;
+               else
+                       continue;
+
+               if (ipv6_doaddr(da, &now) != -1)
+                       continue;
+
+               /* Delegation deleted, forget it. */
+               TAILQ_REMOVE(&ia->pd_pfxs, da, pd_next);
+
+               /* Delete it from the interface. */
+               state = D6_STATE(da->iface);
+               TAILQ_FOREACH(dda, &state->addrs, next) {
+                       if (IN6_ARE_ADDR_EQUAL(&dda->addr, &da->addr))
+                               break;
+               }
+               if (dda != NULL) {
+                       TAILQ_REMOVE(&state->addrs, dda, next);
+                       ipv6_freeaddr(dda);
+               }
+       }
+}
+#endif
+
 static void
 dhcp6_deprecateaddrs(struct ipv6_addrhead *addrs)
 {
@@ -2363,24 +2400,8 @@
 #ifndef SMALL
                /* If we delegated from this prefix, deprecate or remove
                 * the delegations. */
-               if (ia->flags & IPV6_AF_DELEGATEDPFX) {
-                       struct ipv6_addr *da;
-                       bool touched = false;
-
-                       TAILQ_FOREACH(da, &ia->pd_pfxs, pd_next) {
-                               if (ia->prefix_vltime == 0) {
-                                       if (da->prefix_vltime != 0) {
-                                               da->prefix_vltime = 0;
-                                               touched = true;
-                                       }
-                               } else if (da->prefix_pltime != 0) {
-                                       da->prefix_pltime = 0;
-                                       touched = true;
-                               }
-                       }
-                       if (touched)
-                               ipv6_addaddrs(&ia->pd_pfxs);
-               }
+               if (ia->flags & IPV6_AF_DELEGATEDPFX)
+                       dhcp6_deprecatedele(ia);
 #endif
 
                if (ia->flags & IPV6_AF_REQUEST) {
@@ -2988,8 +3009,9 @@
                        TAILQ_FOREACH(ia, &state->addrs, next) {
                                if (ia->flags & IPV6_AF_STALE)
                                        continue;
-                               if (!(state->renew == ND6_INFINITE_LIFETIME &&
-                                   ia->prefix_vltime == ND6_INFINITE_LIFETIME)
+                               if (!(state->renew == ND6_INFINITE_LIFETIME
+                                   && ia->prefix_vltime == ND6_INFINITE_LIFETIME)
+                                   && ia->prefix_vltime != 0
                                    && ia->prefix_vltime <= state->renew)
                                        logwarnx(
                                            "%s: %s will expire before renewal",
@@ -3557,6 +3579,42 @@
                ifp = ifp1;
        }
 
+#if 0
+       /*
+        * Handy code to inject raw DHCPv6 packets over responses
+        * from our server.
+        * This allows me to take a 3rd party wireshark trace and
+        * replay it in my code.
+        */
+       static int replyn = 0;
+       char fname[PATH_MAX], tbuf[64 * 1024];
+       int fd;
+       ssize_t tlen;
+       uint8_t *si1, *si2;
+       uint16_t si_len1, si_len2;
+
+       snprintf(fname, sizeof(fname),



Home | Main Index | Thread Index | Old Index