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 Merge changes



details:   https://anonhg.NetBSD.org/src/rev/d2d585369c7e
branches:  trunk
changeset: 374366:d2d585369c7e
user:      roy <roy%NetBSD.org@localhost>
date:      Fri Apr 21 16:54:26 2023 +0000

description:
Merge changes

diffstat:

 external/bsd/dhcpcd/dist/hooks/20-resolv.conf     |    2 +-
 external/bsd/dhcpcd/dist/hooks/29-lookup-hostname |    6 +-
 external/bsd/dhcpcd/dist/hooks/30-hostname        |    4 +-
 external/bsd/dhcpcd/dist/hooks/50-ntp.conf        |    6 +-
 external/bsd/dhcpcd/dist/src/bpf.c                |   38 +-
 external/bsd/dhcpcd/dist/src/dhcp.c               |   81 +--
 external/bsd/dhcpcd/dist/src/dhcp6.c              |  102 +++--
 external/bsd/dhcpcd/dist/src/dhcpcd.c             |  184 ++++++---
 external/bsd/dhcpcd/dist/src/if-bsd.c             |   82 ++-
 external/bsd/dhcpcd/dist/src/if-options.c         |   74 +++-
 external/bsd/dhcpcd/dist/src/ipv6.c               |  109 +++--
 external/bsd/dhcpcd/dist/src/ipv6.h               |    2 +-
 external/bsd/dhcpcd/dist/src/ipv6nd.c             |   98 ++++-
 external/bsd/dhcpcd/dist/src/logerr.c             |    2 +-
 external/bsd/dhcpcd/dist/src/privsep.c            |  413 ++++++++++++++++-----
 external/bsd/dhcpcd/dist/src/script.c             |    2 +-
 16 files changed, 801 insertions(+), 404 deletions(-)

diffs (truncated from 2519 to 300 lines):

diff -r 34009324c0bb -r d2d585369c7e external/bsd/dhcpcd/dist/hooks/20-resolv.conf
--- a/external/bsd/dhcpcd/dist/hooks/20-resolv.conf     Fri Apr 21 16:52:28 2023 +0000
+++ b/external/bsd/dhcpcd/dist/hooks/20-resolv.conf     Fri Apr 21 16:54:26 2023 +0000
@@ -11,7 +11,7 @@ nocarrier_roaming_dir="$state_dir/roamin
 NL="
 "
 : ${resolvconf:=resolvconf}
-if type "$resolvconf" >/dev/null 2>&1; then
+if command -v "$resolvconf" >/dev/null 2>&1; then
        have_resolvconf=true
 else
        have_resolvconf=false
diff -r 34009324c0bb -r d2d585369c7e external/bsd/dhcpcd/dist/hooks/29-lookup-hostname
--- a/external/bsd/dhcpcd/dist/hooks/29-lookup-hostname Fri Apr 21 16:52:28 2023 +0000
+++ b/external/bsd/dhcpcd/dist/hooks/29-lookup-hostname Fri Apr 21 16:54:26 2023 +0000
@@ -4,20 +4,20 @@ lookup_hostname()
 {
        [ -z "$new_ip_address" ] && return 1
        # Silly ISC programs love to send error text to stdout
-       if type dig >/dev/null 2>&1; then
+       if command -v dig >/dev/null 2>&1; then
                h=$(dig +short -x $new_ip_address)
                if [ $? = 0 ]; then
                        echo "$h" | sed 's/\.$//'
                        return 0
                fi
-       elif type host >/dev/null 2>&1; then
+       elif command -v host >/dev/null 2>&1; then
                h=$(host $new_ip_address)
                if [ $? = 0 ]; then 
                        echo "$h" \
                        | sed 's/.* domain name pointer \(.*\)./\1/'
                        return 0
                fi
-       elif type getent >/dev/null 2>&1; then
+       elif command -v getent >/dev/null 2>&1; then
                h=$(getent hosts $new_ip_address)
                if [ $? = 0 ]; then
                        echo "$h" | sed 's/[^ ]* *\([^ ]*\).*/\1/'
diff -r 34009324c0bb -r d2d585369c7e external/bsd/dhcpcd/dist/hooks/30-hostname
--- a/external/bsd/dhcpcd/dist/hooks/30-hostname        Fri Apr 21 16:52:28 2023 +0000
+++ b/external/bsd/dhcpcd/dist/hooks/30-hostname        Fri Apr 21 16:54:26 2023 +0000
@@ -25,7 +25,7 @@
        if [ -z "${1+x}" ]; then
                if [ -r /proc/sys/kernel/hostname ]; then
                        read name </proc/sys/kernel/hostname && echo "$name"
-               elif type hostname >/dev/null 2>/dev/null; then
+               elif command -v hostname >/dev/null 2>/dev/null; then
                        hostname
                elif sysctl kern.hostname >/dev/null 2>&1; then
                        sysctl -n kern.hostname
@@ -39,7 +39,7 @@
 
        if [ -w /proc/sys/kernel/hostname ]; then
                echo "$1" >/proc/sys/kernel/hostname
-       elif [ -n "$1" ] && type hostname >/dev/null 2>&1; then
+       elif [ -n "$1" ] && command -v hostname >/dev/null 2>&1; then
                hostname "$1"
        elif sysctl kern.hostname >/dev/null 2>&1; then
                sysctl -w "kern.hostname=$1" >/dev/null
diff -r 34009324c0bb -r d2d585369c7e external/bsd/dhcpcd/dist/hooks/50-ntp.conf
--- a/external/bsd/dhcpcd/dist/hooks/50-ntp.conf        Fri Apr 21 16:52:28 2023 +0000
+++ b/external/bsd/dhcpcd/dist/hooks/50-ntp.conf        Fri Apr 21 16:54:26 2023 +0000
@@ -43,7 +43,7 @@ fi
 
 # Debian has a separate file for DHCP config to avoid stamping on
 # the master.
-if [ "$ntp_service" = ntpd ] && type invoke-rc.d >/dev/null 2>&1; then
+if [ "$ntp_service" = ntpd ] && command -v invoke-rc.d >/dev/null 2>&1; then
        [ -e /var/lib/ntp ] || mkdir /var/lib/ntp
        : ${ntp_service:=ntp}
        : ${NTP_DHCP_CONF:=/var/lib/ntp/ntp.conf.dhcp}
@@ -113,7 +113,7 @@ add_ntp_conf()
        [ -e "$cf" ] && rm "$cf"
        [ -d "$ntp_conf_dir" ] || mkdir -p "$ntp_conf_dir"
        if [ -n "$new_ntp_servers" ]; then
-               for x in $new_ntp_servers; do
+               for x in $(uniqify $new_ntp_servers); do
                        echo "server $x" >> "$cf"
                done
        fi
@@ -131,7 +131,7 @@ remove_ntp_conf()
 # For ease of use, map DHCP6 names onto our DHCP4 names
 case "$reason" in
 BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
-       new_ntp_servers="$new_dhcp6_sntp_servers"
+       new_ntp_servers="$new_dhcp6_sntp_servers $new_dhcp6_ntp_server_addr $new_dhcp6_ntp_server_fqdn"
 ;;
 esac
 
diff -r 34009324c0bb -r d2d585369c7e external/bsd/dhcpcd/dist/src/bpf.c
--- a/external/bsd/dhcpcd/dist/src/bpf.c        Fri Apr 21 16:52:28 2023 +0000
+++ b/external/bsd/dhcpcd/dist/src/bpf.c        Fri Apr 21 16:54:26 2023 +0000
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: BSD-2-Clause */
 /*
  * dhcpcd: BPF arp and bootp filtering
- * Copyright (c) 2006-2021 Roy Marples <roy%marples.name@localhost>
+ * Copyright (c) 2006-2023 Roy Marples <roy%marples.name@localhost>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -45,7 +45,6 @@
 
 #include <errno.h>
 #include <fcntl.h>
-#include <paths.h>
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
@@ -155,6 +154,11 @@ bpf_open(const struct interface *ifp,
        struct bpf_version pv = { .bv_major = 0, .bv_minor = 0 };
        struct ifreq ifr = { .ifr_flags = 0 };
        int ibuf_len = 0;
+#ifdef O_CLOEXEC
+#define BPF_OPEN_FLAGS O_RDWR | O_NONBLOCK | O_CLOEXEC
+#else
+#define BPF_OPEN_FLAGS O_RDWR | O_NONBLOCK
+#endif
 #ifdef BIOCIMMEDIATE
        unsigned int flags;
 #endif
@@ -167,25 +171,19 @@ bpf_open(const struct interface *ifp,
                return NULL;
        bpf->bpf_ifp = ifp;
 
-#ifdef _PATH_BPF
-       bpf->bpf_fd = open(_PATH_BPF, O_RDWR | O_NONBLOCK
-#ifdef O_CLOEXEC
-               | O_CLOEXEC
-#endif
-       );
-#else
-       char device[32];
-       int n = 0;
+       /* /dev/bpf is a cloner on modern kernels */
+       bpf->bpf_fd = open("/dev/bpf", BPF_OPEN_FLAGS);
 
-       do {
-               snprintf(device, sizeof(device), "/dev/bpf%d", n++);
-               bpf->bpf_fd = open(device, O_RDWR | O_NONBLOCK
-#ifdef O_CLOEXEC
-                               | O_CLOEXEC
-#endif
-               );
-       } while (bpf->bpf_fd == -1 && errno == EBUSY);
-#endif
+       /* Support older kernels where /dev/bpf is not a cloner */
+       if (bpf->bpf_fd == -1) {
+               char device[32];
+               int n = 0;
+
+               do {
+                       snprintf(device, sizeof(device), "/dev/bpf%d", n++);
+                       bpf->bpf_fd = open(device, BPF_OPEN_FLAGS);
+               } while (bpf->bpf_fd == -1 && errno == EBUSY);
+       }
 
        if (bpf->bpf_fd == -1)
                goto eexit;
diff -r 34009324c0bb -r d2d585369c7e external/bsd/dhcpcd/dist/src/dhcp.c
--- a/external/bsd/dhcpcd/dist/src/dhcp.c       Fri Apr 21 16:52:28 2023 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp.c       Fri Apr 21 16:54:26 2023 +0000
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: BSD-2-Clause */
 /*
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2021 Roy Marples <roy%marples.name@localhost>
+ * Copyright (c) 2006-2023 Roy Marples <roy%marples.name@localhost>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -84,11 +84,6 @@
 /* We should define a maximum for the NAK exponential backoff */
 #define NAKOFF_MAX              60
 
-/* Wait N nanoseconds between sending a RELEASE and dropping the address.
- * This gives the kernel enough time to actually send it. */
-#define RELEASE_DELAY_S                0
-#define RELEASE_DELAY_NS       10000000
-
 #ifndef IPDEFTTL
 #define IPDEFTTL 64 /* RFC1340 */
 #endif
@@ -137,7 +132,7 @@ static void dhcp_arp_found(struct arp_st
 #endif
 static void dhcp_handledhcp(struct interface *, struct bootp *, size_t,
     const struct in_addr *);
-static void dhcp_handleifudp(void *);
+static void dhcp_handleifudp(void *, unsigned short);
 static int dhcp_initstate(struct interface *);
 
 void
@@ -400,7 +395,7 @@ print_rfc3442(FILE *fp, const uint8_t *d
 
 static int
 decode_rfc3442_rt(rb_tree_t *routes, struct interface *ifp,
-    const uint8_t *data, size_t dl, const struct bootp *bootp)
+    const uint8_t *data, size_t dl)
 {
        const uint8_t *p = data;
        const uint8_t *e;
@@ -447,15 +442,6 @@ decode_rfc3442_rt(rb_tree_t *routes, str
                memcpy(&gateway.s_addr, p, 4);
                p += 4;
 
-               /* 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 ||
-                   gateway.s_addr == bootp->ciaddr))
-               {
-                       gateway.s_addr = INADDR_ANY;
-                       netmask.s_addr = INADDR_BROADCAST;
-               }
                if (netmask.s_addr == INADDR_BROADCAST)
                        rt->rt_flags = RTF_HOST;
 
@@ -594,7 +580,7 @@ get_option_routes(rb_tree_t *routes, str
                if (p)
                        csr = "MS ";
        }
-       if (p && (n = decode_rfc3442_rt(routes, ifp, p, len, bootp)) != -1) {
+       if (p && (n = decode_rfc3442_rt(routes, ifp, p, len)) != -1) {
                const struct dhcp_state *state;
 
                state = D_CSTATE(ifp);
@@ -782,7 +768,7 @@ make_message(struct bootp **bootpm, cons
 
        bootp->op = BOOTREQUEST;
        bootp->htype = (uint8_t)ifp->hwtype;
-       if (ifp->hwlen != 0 && ifp->hwlen < sizeof(bootp->chaddr)) {
+       if (ifp->hwlen != 0 && ifp->hwlen <= sizeof(bootp->chaddr)) {
                bootp->hlen = (uint8_t)ifp->hwlen;
                memcpy(&bootp->chaddr, &ifp->hwaddr, ifp->hwlen);
        }
@@ -2005,7 +1991,7 @@ dhcp_finish_dad(struct interface *ifp, s
 {
        struct dhcp_state *state = D_STATE(ifp);
 
-       if (state->state != DHS_PROBE)
+       if (state->state == DHS_BOUND)
                return;
        if (state->offer == NULL || state->offer->yiaddr != ia->s_addr)
                return;
@@ -2407,7 +2393,9 @@ openudp:
                dhcp_openbpf(ifp);
                return;
        }
-       eloop_event_add(ctx->eloop, state->udp_rfd, dhcp_handleifudp, ifp);
+       if (eloop_event_add(ctx->eloop, state->udp_rfd, ELE_READ,
+           dhcp_handleifudp, ifp) == -1)
+               logerr("%s: eloop_event_add", __func__);
 }
 
 static size_t
@@ -2753,12 +2741,8 @@ dhcp_reboot(struct interface *ifp)
 void
 dhcp_drop(struct interface *ifp, const char *reason)
 {
-       struct dhcp_state *state;
-#ifdef RELEASE_SLOW
-       struct timespec ts;
-#endif
-
-       state = D_STATE(ifp);
+       struct dhcp_state *state = D_STATE(ifp);
+
        /* dhcp_start may just have been called and we don't yet have a state
         * but we do have a timeout, so punt it. */
        if (state == NULL || state->state == DHS_NONE) {
@@ -2792,12 +2776,6 @@ dhcp_drop(struct interface *ifp, const c
                            ifp->name, inet_ntoa(state->lease.addr));
                        dhcp_new_xid(ifp);
                        send_message(ifp, DHCP_RELEASE, NULL);
-#ifdef RELEASE_SLOW
-                       /* Give the packet a chance to go */
-                       ts.tv_sec = RELEASE_DELAY_S;
-                       ts.tv_nsec = RELEASE_DELAY_NS;
-                       nanosleep(&ts, NULL);
-#endif
                }
        }
 #ifdef AUTH
@@ -2818,10 +2796,6 @@ dhcp_drop(struct interface *ifp, const c
        dhcp_auth_reset(&state->auth);
 #endif
 
-       /* Close DHCP ports so a changed interface family is picked
-        * up by a new BPF state. */
-       dhcp_close(ifp);
-
        state->state = DHS_NONE;
        free(state->offer);
        state->offer = NULL;
@@ -2845,6 +2819,10 @@ dhcp_drop(struct interface *ifp, const c
        state->lease.addr.s_addr = 0;
        ifp->options->options &= ~(DHCPCD_CSR_WARNED |
            DHCPCD_ROUTER_HOST_ROUTE_WARNED);
+



Home | Main Index | Thread Index | Old Index