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/b561319ede06
branches:  trunk
changeset: 457896:b561319ede06
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Jul 24 09:57:43 2019 +0000

description:
Sync

diffstat:

 external/bsd/dhcpcd/dist/hooks/20-resolv.conf |   39 +-
 external/bsd/dhcpcd/dist/hooks/50-ntp.conf    |    1 +
 external/bsd/dhcpcd/dist/src/bpf.c            |   28 +-
 external/bsd/dhcpcd/dist/src/dhcp.c           |  534 ++++++++++---------------
 external/bsd/dhcpcd/dist/src/dhcp6.c          |  123 ++---
 external/bsd/dhcpcd/dist/src/dhcpcd.c         |   58 ++-
 external/bsd/dhcpcd/dist/src/if-bsd.c         |   30 +-
 external/bsd/dhcpcd/dist/src/if-options.c     |   39 +-
 external/bsd/dhcpcd/dist/src/ipv6nd.c         |  242 +++++++----
 9 files changed, 558 insertions(+), 536 deletions(-)

diffs (truncated from 2031 to 300 lines):

diff -r 04a8d8978374 -r b561319ede06 external/bsd/dhcpcd/dist/hooks/20-resolv.conf
--- a/external/bsd/dhcpcd/dist/hooks/20-resolv.conf     Wed Jul 24 09:54:48 2019 +0000
+++ b/external/bsd/dhcpcd/dist/hooks/20-resolv.conf     Wed Jul 24 09:57:43 2019 +0000
@@ -19,6 +19,7 @@
        interfaces=$(list_interfaces "$resolv_conf_dir")
 
        # Build the resolv.conf
+       header=
        if [ -n "$interfaces" ]; then
                # Build the header
                for x in ${interfaces}; do
@@ -69,30 +70,26 @@
 }
 
 # Extract any ND DNS options from the RA
-# For now, we ignore the lifetime of the DNS options unless they
-# are absent or zero.
-# In this case they are removed from consideration.
-# See draft-gont-6man-slaac-dns-config-issues-01 for issues
-# regarding DNS option lifetime in ND messages.
+# Obey the lifetimes
 eval_nd_dns()
 {
-       eval ltime=\$nd${i}_rdnss${j}_lifetime
-       if [ -z "$ltime" ] || [ "$ltime" = 0 ]; then
-               rdnss=
-       else
+
+       eval rdnsstime=\$nd${i}_rdnss${j}_lifetime
+       [ -z "$rdnsstime" ] && return 1
+       ltime=$(($rdnsstime - $offset))
+       if [ "$ltime" -gt 0 ]; then
                eval rdnss=\$nd${i}_rdnss${j}_servers
-       fi
-       eval ltime=\$nd${i}_dnssl${j}_lifetime
-       if [ -z "$ltime" ] || [ "$ltime" = 0 ]; then
-               dnssl=
-       else
-               eval dnssl=\$nd${i}_dnssl${j}_search
+               [ -n "$rdnss" ] && new_rdnss="$new_rdnss${new_rdnss:+ }$rdnss"
        fi
 
-       [ -z "${rdnss}${dnssl}" ] && return 1
+       eval dnssltime=\$nd${i}_dnssl${j}_lifetime
+       [ -z "$dnssltime" ] && return 1
+       ltime=$(($dnssltime - $offset))
+       if [ "$ltime" -gt 0 ]; then
+               eval dnssl=\$nd${i}_dnssl${j}_search
+               [ -n "$dnssl" ] && new_dnssl="$new_dnssl${new_dnssl:+ }$dnssl"
+       fi
 
-       [ -n "$rdnss" ] && new_rdnss="$new_rdnss${new_rdnss:+ }$rdnss"
-       [ -n "$dnssl" ] && new_dnssl="$new_dnssl${new_dnssl:+ }$dnssl"
        j=$(($j + 1))
        return 0
 }
@@ -106,12 +103,16 @@
        i=1
        j=1
        while true; do
+               eval acquired=\$nd${i}_acquired
+               [ -z "$acquired" ] && break
+               eval now=\$nd${i}_now
+               [ -z "$now" ] && break
+               offset=$(($now - $acquired))
                while true; do
                        eval_nd_dns || break
                done
                i=$(($i + 1))
                j=1
-               eval_nd_dns || break
        done
        [ -n "$new_rdnss" ] && \
            new_domain_name_servers="$new_domain_name_servers${new_domain_name_servers:+ }$new_rdnss"
diff -r 04a8d8978374 -r b561319ede06 external/bsd/dhcpcd/dist/hooks/50-ntp.conf
--- a/external/bsd/dhcpcd/dist/hooks/50-ntp.conf        Wed Jul 24 09:54:48 2019 +0000
+++ b/external/bsd/dhcpcd/dist/hooks/50-ntp.conf        Wed Jul 24 09:57:43 2019 +0000
@@ -62,6 +62,7 @@
        # Build a list of interfaces
        interfaces=$(list_interfaces "$ntp_conf_dir")
 
+       header=
        servers=
        if [ -n "$interfaces" ]; then
                # Build the header
diff -r 04a8d8978374 -r b561319ede06 external/bsd/dhcpcd/dist/src/bpf.c
--- a/external/bsd/dhcpcd/dist/src/bpf.c        Wed Jul 24 09:54:48 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/bpf.c        Wed Jul 24 09:57:43 2019 +0000
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
 /*
  * dhcpcd: BPF arp and bootp filtering
  * Copyright (c) 2006-2019 Roy Marples <roy%marples.name@localhost>
@@ -84,7 +85,7 @@
 bpf_frame_header_len(const struct interface *ifp)
 {
 
-       switch(ifp->family) {
+       switch (ifp->family) {
        case ARPHRD_ETHER:
                return sizeof(struct ether_header);
        default:
@@ -92,6 +93,23 @@
        }
 }
 
+static const uint8_t etherbroadcastaddr[] =
+    { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+
+int
+bpf_frame_bcast(const struct interface *ifp, const char *frame)
+{
+
+       switch (ifp->family) {
+       case ARPHRD_ETHER:
+               return memcmp(frame +
+                   offsetof(struct ether_header, ether_dhost),
+                   etherbroadcastaddr, sizeof(etherbroadcastaddr));
+       default:
+               return -1;
+       }
+}
+
 #ifndef __linux__
 /* Linux is a special snowflake for opening, attaching and reading BPF.
  * See if-linux.c for the Linux specific BPF functions. */
@@ -227,8 +245,12 @@
                if (state->buffer_pos + packet.bh_caplen + packet.bh_hdrlen >
                    state->buffer_len)
                        goto next; /* Packet beyond buffer, drop. */
-               payload = state->buffer + state->buffer_pos +
-                   packet.bh_hdrlen + fl;
+               payload = state->buffer + state->buffer_pos + packet.bh_hdrlen;
+               if (bpf_frame_bcast(ifp, payload) == 0)
+                       *flags |= BPF_BCAST;
+               else
+                       *flags &= ~BPF_BCAST;
+               payload += fl;
                bytes = (ssize_t)packet.bh_caplen - fl;
                if ((size_t)bytes > len)
                        bytes = (ssize_t)len;
diff -r 04a8d8978374 -r b561319ede06 external/bsd/dhcpcd/dist/src/dhcp.c
--- a/external/bsd/dhcpcd/dist/src/dhcp.c       Wed Jul 24 09:54:48 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp.c       Wed Jul 24 09:57:43 2019 +0000
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
 /*
  * dhcpcd - DHCP client daemon
  * Copyright (c) 2006-2019 Roy Marples <roy%marples.name@localhost>
@@ -47,6 +48,7 @@
 #include <inttypes.h>
 #include <stdbool.h>
 #include <stddef.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -124,8 +126,9 @@
 };
 
 static int dhcp_openbpf(struct interface *);
+static void dhcp_start1(void *);
 #ifdef ARP
-static void dhcp_arp_conflicted(struct arp_state *, const struct arp_msg *);
+static void dhcp_arp_found(struct arp_state *, const struct arp_msg *);
 #endif
 static void dhcp_handledhcp(struct interface *, struct bootp *, size_t,
     const struct in_addr *);
@@ -339,23 +342,25 @@
 }
 
 ssize_t
-decode_rfc3442(char *out, size_t len, const uint8_t *p, size_t pl)
+print_rfc3442(FILE *fp, const uint8_t *data, size_t data_len)
 {
-       const uint8_t *e;
-       size_t bytes = 0, ocets;
-       int b;
+       const uint8_t *p = data, *e;
+       size_t ocets;
        uint8_t cidr;
        struct in_addr addr;
-       char *o = out;
 
        /* Minimum is 5 -first is CIDR and a router length of 4 */
-       if (pl < 5) {
+       if (data_len < 5) {
                errno = EINVAL;
                return -1;
        }
 
-       e = p + pl;
+       e = p + data_len;
        while (p < e) {
+               if (p != data) {
+                       if (fputc(' ', fp) == EOF)
+                               return -1;
+               }
                cidr = *p++;
                if (cidr > 32) {
                        errno = EINVAL;
@@ -366,45 +371,29 @@
                        errno = ERANGE;
                        return -1;
                }
-               if (!out) {
-                       p += 4 + ocets;
-                       bytes += ((4 * 4) * 2) + 4;
-                       continue;
-               }
-               if ((((4 * 4) * 2) + 4) > len) {
-                       errno = ENOBUFS;
-                       return -1;
+               /* If we have ocets then we have a destination and netmask */
+               addr.s_addr = 0;
+               if (ocets > 0) {
+                       memcpy(&addr.s_addr, p, ocets);
+                       p += ocets;
                }
-               if (o != out) {
-                       *o++ = ' ';
-                       len--;
-               }
-               /* If we have ocets then we have a destination and netmask */
-               if (ocets > 0) {
-                       addr.s_addr = 0;
-                       memcpy(&addr.s_addr, p, ocets);
-                       b = snprintf(o, len, "%s/%d", inet_ntoa(addr), cidr);
-                       p += ocets;
-               } else
-                       b = snprintf(o, len, "0.0.0.0/0");
-               o += b;
-               len -= (size_t)b;
+               if (fprintf(fp, "%s/%d", inet_ntoa(addr), cidr) == -1)
+                       return -1;
 
                /* Finally, snag the router */
                memcpy(&addr.s_addr, p, 4);
                p += 4;
-               b = snprintf(o, len, " %s", inet_ntoa(addr));
-               o += b;
-               len -= (size_t)b;
+               if (fprintf(fp, " %s", inet_ntoa(addr)) == -1)
+                       return -1;
        }
 
-       if (out)
-               return o - out;
-       return (ssize_t)bytes;
+       if (fputc('\0', fp) == EOF)
+               return -1;
+       return 1;
 }
 
 static int
-decode_rfc3442_rt(struct rt_head *routes, struct interface *ifp,
+decode_rfc3442_rt(rb_tree_t *routes, struct interface *ifp,
     const uint8_t *data, size_t dl, const struct bootp *bootp)
 {
        const uint8_t *p = data;
@@ -467,22 +456,18 @@
                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++;
+               if (rt_proto_add(routes, rt))
+                       n = 1;
        }
        return n;
 }
 
-char *
-decode_rfc3361(const uint8_t *data, size_t dl)
+ssize_t
+print_rfc3361(FILE *fp, const uint8_t *data, size_t dl)
 {
        uint8_t enc;
-       size_t l;
-       ssize_t r;
-       char *sip = NULL;
+       char sip[NS_MAXDNAME];
        struct in_addr addr;
-       char *p;
 
        if (dl < 2) {
                errno = EINVAL;
@@ -493,13 +478,10 @@
        dl--;
        switch (enc) {
        case 0:
-               if ((r = decode_rfc1035(NULL, 0, data, dl)) > 0) {
-                       l = (size_t)r + 1;
-                       sip = malloc(l);
-                       if (sip == NULL)
-                               return 0;
-                       decode_rfc1035(sip, l, data, dl);
-               }
+               if (decode_rfc1035(sip, sizeof(sip), data, dl) == -1)



Home | Main Index | Thread Index | Old Index