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/c3eabe3d6dc1
branches:  trunk
changeset: 456182:c3eabe3d6dc1
user:      roy <roy%NetBSD.org@localhost>
date:      Fri Apr 26 14:34:10 2019 +0000

description:
Sync

diffstat:

 external/bsd/dhcpcd/dist/src/dhcp.c   |   14 +-
 external/bsd/dhcpcd/dist/src/dhcp6.c  |    6 +-
 external/bsd/dhcpcd/dist/src/if-bsd.c |    8 +-
 external/bsd/dhcpcd/dist/src/ipv6nd.c |  181 +++++++++++++++++++++++++--------
 4 files changed, 154 insertions(+), 55 deletions(-)

diffs (truncated from 443 to 300 lines):

diff -r f4154934e6ed -r c3eabe3d6dc1 external/bsd/dhcpcd/dist/src/dhcp.c
--- a/external/bsd/dhcpcd/dist/src/dhcp.c       Fri Apr 26 14:32:27 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp.c       Fri Apr 26 14:34:10 2019 +0000
@@ -215,6 +215,12 @@
                }
                l = *p++;
 
+               /* Check we can read the option data, if present */
+               if (p + l > e) {
+                       errno = EINVAL;
+                       return NULL;
+               }
+
                if (o == DHO_OPTSOVERLOADED) {
                        /* Ensure we only get this option once by setting
                         * the last bit as well as the value.
@@ -249,10 +255,6 @@
                                bp += ol;
                        }
                        ol = l;
-                       if (p + ol >= e) {
-                               errno = EINVAL;
-                               return NULL;
-                       }
                        op = p;
                        bl += ol;
                }
@@ -2075,7 +2077,7 @@
            ifp->name, inet_ntoa(astate->addr));
        if (!(ifo->options & DHCPCD_INFORM))
                dhcp_bind(ifp);
-#ifndef IN_IFF_TENTATIVE
+#ifndef IN_IFF_DUPLICATED
        else {
                struct bootp *bootp;
                size_t len;
@@ -2429,7 +2431,7 @@
        if (astate == NULL)
                return -1;
 
-#ifdef IN_IFF_TENTATIVE
+#ifdef IN_IFF_NOTUSEABLE
        if (ia == NULL || ia->addr_flags & IN_IFF_NOTUSEABLE) {
                state->state = DHS_PROBE;
                if (ia == NULL) {
diff -r f4154934e6ed -r c3eabe3d6dc1 external/bsd/dhcpcd/dist/src/dhcp6.c
--- a/external/bsd/dhcpcd/dist/src/dhcp6.c      Fri Apr 26 14:32:27 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp6.c      Fri Apr 26 14:34:10 2019 +0000
@@ -2029,12 +2029,12 @@
                nd = o + ol;
                l -= (size_t)(nd - d);
                d = nd;
-               if (ol < 24) {
+               if (ol < sizeof(ia)) {
                        errno = EINVAL;
                        logerrx("%s: IA Address option truncated", ifp->name);
                        continue;
                }
-               memcpy(&ia, o, ol);
+               memcpy(&ia, o, sizeof(ia));
                ia.pltime = ntohl(ia.pltime);
                ia.vltime = ntohl(ia.vltime);
                /* RFC 3315 22.6 */
@@ -3035,7 +3035,7 @@
                                 * unless those values in those fields are 0.
                                 */
                                logwarnx("%s: ignoring T1 %"PRIu32
-                                   " to due address expiry",
+                                   " due to address expiry",
                                    ifp->name, state->renew);
                                state->renew = state->rebind = 0;
                        }
diff -r f4154934e6ed -r c3eabe3d6dc1 external/bsd/dhcpcd/dist/src/if-bsd.c
--- a/external/bsd/dhcpcd/dist/src/if-bsd.c     Fri Apr 26 14:32:27 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/if-bsd.c     Fri Apr 26 14:34:10 2019 +0000
@@ -943,10 +943,15 @@
        priv = (struct priv *)ia->iface->ctx->priv;
        if (ioctl(priv->pf_inet6_fd, SIOCGIFALIFETIME_IN6, &ifr6) == -1)
                return -1;
+       clock_gettime(CLOCK_MONOTONIC, &ia->created);
 
+#if defined(__FreeBSD__) || defined(__DragonFly__)
+       t = ia->created.tv_sec;
+#else
        t = time(NULL);
+#endif
+
        lifetime = &ifr6.ifr_ifru.ifru_lifetime;
-
        if (lifetime->ia6t_preferred)
                ia->prefix_pltime = (uint32_t)(lifetime->ia6t_preferred -
                    MIN(t, lifetime->ia6t_preferred));
@@ -956,7 +961,6 @@
                ia->prefix_vltime = (uint32_t)(lifetime->ia6t_expire -
                    MIN(t, lifetime->ia6t_expire));
                /* Calculate the created time */
-               clock_gettime(CLOCK_MONOTONIC, &ia->created);
                ia->created.tv_sec -= lifetime->ia6t_vltime - ia->prefix_vltime;
        } else
                ia->prefix_vltime = ND6_INFINITE_LIFETIME;
diff -r f4154934e6ed -r c3eabe3d6dc1 external/bsd/dhcpcd/dist/src/ipv6nd.c
--- a/external/bsd/dhcpcd/dist/src/ipv6nd.c     Fri Apr 26 14:32:27 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/ipv6nd.c     Fri Apr 26 14:34:10 2019 +0000
@@ -190,54 +190,106 @@
 }
 
 static int
-ipv6nd_open(struct dhcpcd_ctx *ctx)
+ipv6nd_open0(void)
 {
-       int on;
+       int s, on;
        struct icmp6_filter filt;
 
-       if (ctx->nd_fd != -1)
-               return ctx->nd_fd;
 #define SOCK_FLAGS     SOCK_CLOEXEC | SOCK_NONBLOCK
-       ctx->nd_fd = xsocket(PF_INET6, SOCK_RAW | SOCK_FLAGS, IPPROTO_ICMPV6);
+       s = xsocket(PF_INET6, SOCK_RAW | SOCK_FLAGS, IPPROTO_ICMPV6);
 #undef SOCK_FLAGS
-       if (ctx->nd_fd == -1)
+       if (s == -1)
                return -1;
 
        /* RFC4861 4.1 */
        on = 255;
-       if (setsockopt(ctx->nd_fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
+       if (setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
            &on, sizeof(on)) == -1)
                goto eexit;
 
        on = 1;
-       if (setsockopt(ctx->nd_fd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
-           &on, sizeof(on)) == -1)
-               goto eexit;
-
-       on = 1;
-       if (setsockopt(ctx->nd_fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT,
+       if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVHOPLIMIT,
            &on, sizeof(on)) == -1)
                goto eexit;
 
        ICMP6_FILTER_SETBLOCKALL(&filt);
        ICMP6_FILTER_SETPASS(ND_NEIGHBOR_ADVERT, &filt);
        ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filt);
-       if (setsockopt(ctx->nd_fd, IPPROTO_ICMPV6, ICMP6_FILTER,
+       if (setsockopt(s, IPPROTO_ICMPV6, ICMP6_FILTER,
            &filt, sizeof(filt)) == -1)
                goto eexit;
 
-       eloop_event_add(ctx->eloop, ctx->nd_fd,  ipv6nd_handledata, ctx);
-       return ctx->nd_fd;
+       return s;
 
 eexit:
-       if (ctx->nd_fd != -1) {
-               eloop_event_delete(ctx->eloop, ctx->nd_fd);
-               close(ctx->nd_fd);
-               ctx->nd_fd = -1;
-       }
+       close(s);
        return -1;
 }
 
+#ifdef __sun
+static int
+ipv6nd_open(struct interface *ifp)
+{
+       int s;
+       struct ipv6_mreq mreq = {
+           .ipv6mr_multiaddr = IN6ADDR_LINKLOCAL_ALLNODES_INIT,
+           .ipv6mr_interface = ifp->index
+       };
+       struct rs_state *state = RS_STATE(ifp);
+       uint_t ifindex = ifp->index;
+
+       if (state->nd_fd != -1)
+               return state->nd_fd;
+
+       s = ipv6nd_open0();
+       if (s == -1)
+               return -1;
+
+       if (setsockopt(s, IPPROTO_IPV6, IPV6_BOUND_IF,
+           &ifindex, sizeof(ifindex)) == -1)
+       {
+               close(s);
+               return -1;
+       }
+
+       if (setsockopt(s, IPPROTO_IPV6, IPV6_JOIN_GROUP,
+           &mreq, sizeof(mreq)) == -1)
+       {
+               close(s);
+               return -1;
+       }
+
+       state->nd_fd = s;
+       eloop_event_add(ifp->ctx->eloop, s, ipv6nd_handledata, ifp);
+       return s;
+}
+#else
+static int
+ipv6nd_open(struct dhcpcd_ctx *ctx)
+{
+       int s, on;
+
+       if (ctx->nd_fd != -1)
+               return ctx->nd_fd;
+
+       s = ipv6nd_open0();
+       if (s == -1)
+               return -1;
+
+       on = 1;
+       if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO,
+           &on, sizeof(on)) == -1)
+       {
+               close(s);
+               return -1;
+       }
+
+       ctx->nd_fd = s;
+       eloop_event_add(ctx->eloop, s, ipv6nd_handledata, ctx);
+       return s;
+}
+#endif
+
 static int
 ipv6nd_makersprobe(struct interface *ifp)
 {
@@ -273,9 +325,12 @@
 ipv6nd_sendrsprobe(void *arg)
 {
        struct interface *ifp = arg;
-       struct dhcpcd_ctx *ctx;
        struct rs_state *state = RS_STATE(ifp);
-       struct sockaddr_in6 dst = { .sin6_family = AF_INET6 };
+       struct sockaddr_in6 dst = {
+               .sin6_family = AF_INET6,
+               .sin6_addr = IN6ADDR_LINKLOCAL_ALLROUTERS_INIT,
+               .sin6_scope_id = ifp->index,
+       };
        struct iovec iov = { .iov_base = state->rs, .iov_len = state->rslen };
        unsigned char ctl[CMSG_SPACE(sizeof(struct in6_pktinfo))] = { 0 };
        struct msghdr msg = {
@@ -285,6 +340,7 @@
        };
        struct cmsghdr *cm;
        struct in6_pktinfo pi = { .ipi6_ifindex = ifp->index };
+       int s;
 
        if (ipv6_linklocal(ifp) == NULL) {
                logdebugx("%s: delaying Router Solicitation for LL address",
@@ -296,13 +352,6 @@
 #ifdef HAVE_SA_LEN
        dst.sin6_len = sizeof(dst);
 #endif
-       dst.sin6_scope_id = ifp->index;
-       if (inet_pton(AF_INET6, ALLROUTERS, &dst.sin6_addr) != 1) {
-               logerr(__func__);
-               return;
-       }
-
-       ctx = ifp->ctx;
 
        /* Set the outbound interface */
        cm = CMSG_FIRSTHDR(&msg);
@@ -314,7 +363,12 @@
        memcpy(CMSG_DATA(cm), &pi, sizeof(pi));
 
        logdebugx("%s: sending Router Solicitation", ifp->name);
-       if (sendmsg(ctx->nd_fd, &msg, 0) == -1) {
+#ifdef __sun
+       s = state->nd_fd;
+#else
+       s = ifp->ctx->nd_fd;
+#endif
+       if (sendmsg(s, &msg, 0) == -1) {
                logerr(__func__);
                /* Allow IPv6ND to continue .... at most a few errors
                 * would be logged.
@@ -342,6 +396,7 @@
        struct dhcpcd_ctx *ctx = ifp->ctx;
        struct sockaddr_in6 dst = {
            .sin6_family = AF_INET6,
+           .sin6_addr = IN6ADDR_LINKLOCAL_ALLNODES_INIT,
            .sin6_scope_id = ifp->index,
        };
        struct iovec iov = { .iov_base = ia->na, .iov_len = ia->na_len };
@@ -354,6 +409,7 @@
        struct cmsghdr *cm;
        struct in6_pktinfo pi = { .ipi6_ifindex = ifp->index };
        const struct rs_state *state = RS_CSTATE(ifp);
+       int s;
 
        if (state == NULL || ifp->carrier <= LINK_DOWN)
                goto freeit;
@@ -361,10 +417,6 @@
 #ifdef SIN6_LEN



Home | Main Index | Thread Index | Old Index