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/fa8fa73186d3
branches:  trunk
changeset: 933924:fa8fa73186d3
user:      roy <roy%NetBSD.org@localhost>
date:      Sun May 31 12:52:11 2020 +0000

description:
Sync

diffstat:

 external/bsd/dhcpcd/dist/hooks/dhcpcd-run-hooks.in |    2 +-
 external/bsd/dhcpcd/dist/src/bpf.c                 |  383 +++++++-------
 external/bsd/dhcpcd/dist/src/dhcp.c                |  448 ++++++++---------
 external/bsd/dhcpcd/dist/src/dhcp6.c               |  529 ++++++++++++--------
 external/bsd/dhcpcd/dist/src/dhcpcd.8.in           |    8 +-
 external/bsd/dhcpcd/dist/src/dhcpcd.c              |  285 ++++++----
 external/bsd/dhcpcd/dist/src/if-bsd.c              |  150 ++---
 external/bsd/dhcpcd/dist/src/if-options.c          |  235 ++------
 external/bsd/dhcpcd/dist/src/ipv6.c                |  146 ++++-
 external/bsd/dhcpcd/dist/src/ipv6.h                |   26 +-
 external/bsd/dhcpcd/dist/src/ipv6nd.c              |  167 ++++--
 external/bsd/dhcpcd/dist/src/logerr.c              |    5 +-
 external/bsd/dhcpcd/dist/src/privsep.c             |  164 +++--
 external/bsd/dhcpcd/dist/src/script.c              |   38 +-
 14 files changed, 1341 insertions(+), 1245 deletions(-)

diffs (truncated from 4957 to 300 lines):

diff -r 1afb820f7929 -r fa8fa73186d3 external/bsd/dhcpcd/dist/hooks/dhcpcd-run-hooks.in
--- a/external/bsd/dhcpcd/dist/hooks/dhcpcd-run-hooks.in        Sun May 31 12:50:46 2020 +0000
+++ b/external/bsd/dhcpcd/dist/hooks/dhcpcd-run-hooks.in        Sun May 31 12:52:11 2020 +0000
@@ -211,7 +211,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
+# more than one installed. So we need to try to guess what one we're
 # using unless overridden by configure.
 detect_init()
 {
diff -r 1afb820f7929 -r fa8fa73186d3 external/bsd/dhcpcd/dist/src/bpf.c
--- a/external/bsd/dhcpcd/dist/src/bpf.c        Sun May 31 12:50:46 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/bpf.c        Sun May 31 12:52:11 2020 +0000
@@ -57,8 +57,6 @@
 #include "if.h"
 #include "logerr.h"
 
-#define        ARP_ADDRS_MAX   3
-
 /* BPF helper macros */
 #ifdef __linux__
 #define        BPF_WHOLEPACKET         0x7fffffff /* work around buggy LPF filters */
@@ -85,7 +83,7 @@
 bpf_frame_header_len(const struct interface *ifp)
 {
 
-       switch (ifp->family) {
+       switch (ifp->hwtype) {
        case ARPHRD_ETHER:
                return sizeof(struct ether_header);
        default:
@@ -98,7 +96,7 @@
 {
        uint8_t *f = fh;
 
-       switch (ifp->family) {
+       switch (ifp->hwtype) {
        case ARPHRD_ETHER:
                *len = sizeof(((struct ether_header *)0)->ether_shost);
                return f + offsetof(struct ether_header, ether_shost);
@@ -114,7 +112,7 @@
 {
        uint8_t *f = fh;
 
-       switch (ifp->family) {
+       switch (ifp->hwtype) {
        case ARPHRD_ETHER:
                *len = sizeof(((struct ether_header *)0)->ether_dhost);
                return f + offsetof(struct ether_header, ether_dhost);
@@ -129,12 +127,12 @@
     { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 
 int
-bpf_frame_bcast(const struct interface *ifp, const char *frame)
+bpf_frame_bcast(const struct interface *ifp, const void *frame)
 {
 
-       switch (ifp->family) {
+       switch (ifp->hwtype) {
        case ARPHRD_ETHER:
-               return memcmp(frame +
+               return memcmp((const char *)frame +
                    offsetof(struct ether_header, ether_dhost),
                    etherbcastaddr, sizeof(etherbcastaddr));
        default:
@@ -148,15 +146,15 @@
 
 const char *bpf_name = "Berkley Packet Filter";
 
-int
-bpf_open(struct interface *ifp, int (*filter)(struct interface *, int))
+struct bpf *
+bpf_open(const struct interface *ifp,
+    int (*filter)(const struct bpf *, const struct in_addr *),
+    const struct in_addr *ia)
 {
-       struct ipv4_state *state;
-       int fd = -1;
-       struct ifreq ifr;
+       struct bpf *bpf;
+       struct bpf_version pv = { .bv_major = 0, .bv_minor = 0 };
+       struct ifreq ifr = { .ifr_flags = 0 };
        int ibuf_len = 0;
-       size_t buf_len;
-       struct bpf_version pv;
 #ifdef BIOCIMMEDIATE
        unsigned int flags;
 #endif
@@ -164,8 +162,13 @@
        int fd_opts;
 #endif
 
+       bpf = calloc(1, sizeof(*bpf));
+       if (bpf == NULL)
+               return NULL;
+       bpf->bpf_ifp = ifp;
+
 #ifdef _PATH_BPF
-       fd = open(_PATH_BPF, O_RDWR | O_NONBLOCK
+       bpf->bpf_fd = open(_PATH_BPF, O_RDWR | O_NONBLOCK
 #ifdef O_CLOEXEC
                | O_CLOEXEC
 #endif
@@ -176,27 +179,24 @@
 
        do {
                snprintf(device, sizeof(device), "/dev/bpf%d", n++);
-               fd = open(device, O_RDWR | O_NONBLOCK
+               bpf->bpf_fd = open(device, O_RDWR | O_NONBLOCK
 #ifdef O_CLOEXEC
                                | O_CLOEXEC
 #endif
                );
-       } while (fd == -1 && errno == EBUSY);
+       } while (bpf->bpf_fd == -1 && errno == EBUSY);
 #endif
 
-       if (fd == -1)
-               return -1;
+       if (bpf->bpf_fd == -1)
+               goto eexit;
 
 #ifndef O_CLOEXEC
-       if ((fd_opts = fcntl(fd, F_GETFD)) == -1 ||
-           fcntl(fd, F_SETFD, fd_opts | FD_CLOEXEC) == -1) {
-               close(fd);
-               return -1;
-       }
+       if ((fd_opts = fcntl(bpf->bpf_fd, F_GETFD)) == -1 ||
+           fcntl(bpf->bpf_fd, F_SETFD, fd_opts | FD_CLOEXEC) == -1)
+               goto eexit;
 #endif
 
-       memset(&pv, 0, sizeof(pv));
-       if (ioctl(fd, BIOCVERSION, &pv) == -1)
+       if (ioctl(bpf->bpf_fd, BIOCVERSION, &pv) == -1)
                goto eexit;
        if (pv.bv_major != BPF_MAJOR_VERSION ||
            pv.bv_minor < BPF_MINOR_VERSION) {
@@ -204,94 +204,84 @@
                goto eexit;
        }
 
-       if (filter(ifp, fd) != 0)
+       strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
+       if (ioctl(bpf->bpf_fd, BIOCSETIF, &ifr) == -1)
                goto eexit;
 
-       memset(&ifr, 0, sizeof(ifr));
-       strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
-       if (ioctl(fd, BIOCSETIF, &ifr) == -1)
+#ifdef BIOCIMMEDIATE
+       flags = 1;
+       if (ioctl(bpf->bpf_fd, BIOCIMMEDIATE, &flags) == -1)
+               goto eexit;
+#endif
+
+       if (filter(bpf, ia) != 0)
                goto eexit;
 
        /* Get the required BPF buffer length from the kernel. */
-       if (ioctl(fd, BIOCGBLEN, &ibuf_len) == -1)
-               goto eexit;
-       buf_len = (size_t)ibuf_len;
-       state = ipv4_getstate(ifp);
-       if (state == NULL)
+       if (ioctl(bpf->bpf_fd, BIOCGBLEN, &ibuf_len) == -1)
                goto eexit;
-       if (state->buffer_size != buf_len) {
-               void *nb;
-
-               if ((nb = realloc(state->buffer, buf_len)) == NULL)
-                       goto eexit;
-               state->buffer = nb;
-               state->buffer_size = buf_len;
-       }
-
-#ifdef BIOCIMMEDIATE
-       flags = 1;
-       if (ioctl(fd, BIOCIMMEDIATE, &flags) == -1)
+       bpf->bpf_size = (size_t)ibuf_len;
+       bpf->bpf_buffer = malloc(bpf->bpf_size);
+       if (bpf->bpf_buffer == NULL)
                goto eexit;
-#endif
-
-       return fd;
+       return bpf;
 
 eexit:
-       close(fd);
-       return -1;
+       if (bpf->bpf_fd != -1)
+               close(bpf->bpf_fd);
+       free(bpf);
+       return NULL;
 }
 
 /* BPF requires that we read the entire buffer.
  * So we pass the buffer in the API so we can loop on >1 packet. */
 ssize_t
-bpf_read(struct interface *ifp, int fd, void *data, size_t len,
-    unsigned int *flags)
+bpf_read(struct bpf *bpf, void *data, size_t len)
 {
        ssize_t bytes;
-       struct ipv4_state *state = IPV4_STATE(ifp);
-
        struct bpf_hdr packet;
        const char *payload;
 
-       *flags &= ~BPF_EOF;
+       bpf->bpf_flags &= ~BPF_EOF;
        for (;;) {
-               if (state->buffer_len == 0) {
-                       bytes = read(fd, state->buffer, state->buffer_size);
+               if (bpf->bpf_len == 0) {
+                       bytes = read(bpf->bpf_fd, bpf->bpf_buffer,
+                           bpf->bpf_size);
 #if defined(__sun)
                        /* After 2^31 bytes, the kernel offset overflows.
                         * To work around this bug, lseek 0. */
                        if (bytes == -1 && errno == EINVAL) {
-                               lseek(fd, 0, SEEK_SET);
+                               lseek(bpf->bpf_fd, 0, SEEK_SET);
                                continue;
                        }
 #endif
                        if (bytes == -1 || bytes == 0)
                                return bytes;
-                       state->buffer_len = (size_t)bytes;
-                       state->buffer_pos = 0;
+                       bpf->bpf_len = (size_t)bytes;
+                       bpf->bpf_pos = 0;
                }
                bytes = -1;
-               memcpy(&packet, state->buffer + state->buffer_pos,
-                   sizeof(packet));
-               if (state->buffer_pos + packet.bh_caplen + packet.bh_hdrlen >
-                   state->buffer_len)
+               payload = (const char *)bpf->bpf_buffer + bpf->bpf_pos;
+               memcpy(&packet, payload, sizeof(packet));
+               if (bpf->bpf_pos + packet.bh_caplen + packet.bh_hdrlen >
+                   bpf->bpf_len)
                        goto next; /* Packet beyond buffer, drop. */
-               payload = state->buffer + state->buffer_pos + packet.bh_hdrlen;
-               if (bpf_frame_bcast(ifp, payload) == 0)
-                       *flags |= BPF_BCAST;
-               else
-                       *flags &= ~BPF_BCAST;
+               payload += packet.bh_hdrlen;
                if (packet.bh_caplen > len)
                        bytes = (ssize_t)len;
                else
                        bytes = (ssize_t)packet.bh_caplen;
+               if (bpf_frame_bcast(bpf->bpf_ifp, payload) == 0)
+                       bpf->bpf_flags |= BPF_BCAST;
+               else
+                       bpf->bpf_flags &= ~BPF_BCAST;
                memcpy(data, payload, (size_t)bytes);
 next:
-               state->buffer_pos += BPF_WORDALIGN(packet.bh_hdrlen +
+               bpf->bpf_pos += BPF_WORDALIGN(packet.bh_hdrlen +
                    packet.bh_caplen);
-               if (state->buffer_pos >= state->buffer_len) {
-                       state->buffer_len = state->buffer_pos = 0;
-                       *flags |= BPF_EOF;
+               if (bpf->bpf_pos >= bpf->bpf_len) {
+                       bpf->bpf_len = bpf->bpf_pos = 0;
+                       bpf->bpf_flags |= BPF_EOF;
                }
                if (bytes != -1)
                        return bytes;
@@ -303,29 +293,38 @@
 int
 bpf_attach(int fd, void *filter, unsigned int filter_len)
 {
-       struct bpf_program pf;
+       struct bpf_program pf = { .bf_insns = filter, .bf_len = filter_len };
 
        /* Install the filter. */
-       memset(&pf, 0, sizeof(pf));
-       pf.bf_insns = filter;
-       pf.bf_len = filter_len;
        return ioctl(fd, BIOCSETF, &pf);
 }
+
+#ifdef BIOCSETWF
+static int
+bpf_wattach(int fd, void *filter, unsigned int filter_len)
+{
+       struct bpf_program pf = { .bf_insns = filter, .bf_len = filter_len };
+
+       /* Install the filter. */
+       return ioctl(fd, BIOCSETWF, &pf);
+}
+#endif
 #endif



Home | Main Index | Thread Index | Old Index