Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/ROY]: src/external/bsd/dhcpcd/dist/src Import dhcpcd-7.0.0-beta3 with th...



details:   https://anonhg.NetBSD.org/src/rev/b9f542e9d9d8
branches:  ROY
changeset: 455200:b9f542e9d9d8
user:      roy <roy%NetBSD.org@localhost>
date:      Fri Apr 14 09:53:06 2017 +0000

description:
Import dhcpcd-7.0.0-beta3 with the following changes:
  *  restored --logfile support as a few people complained it vanished
     The new logging code even makes the overall binary size smaller
     on most platforms.
  *  BPF filter now trims garbage trailing the payload
     OK, it's not garbage, but userland doesn't know some drivers append
     FCS to it.
  *  support NetBSD's RO_MSGFILTER socket option to reduce avoid context
     switching for route(4) messages that don't interest us.
  *  Don't open sockets if just sending signals.
  *  HMAC-MD5 test's now check expectations in code rather than relying
     on visual confirmation.
  *  added eloop-bench to test performance of eloop with available
     polling mechanisms.

diffstat:

 external/bsd/dhcpcd/dist/src/arp.c            |   46 +-
 external/bsd/dhcpcd/dist/src/bpf.c            |   34 +-
 external/bsd/dhcpcd/dist/src/bpf.h            |    2 +-
 external/bsd/dhcpcd/dist/src/common.c         |    7 +-
 external/bsd/dhcpcd/dist/src/control.c        |    6 +-
 external/bsd/dhcpcd/dist/src/defs.h           |    2 +-
 external/bsd/dhcpcd/dist/src/dhcp-common.c    |   17 +-
 external/bsd/dhcpcd/dist/src/dhcp.c           |  290 +++++++++----------
 external/bsd/dhcpcd/dist/src/dhcp6.c          |  290 +++++++++-----------
 external/bsd/dhcpcd/dist/src/dhcpcd.8.in      |   17 +-
 external/bsd/dhcpcd/dist/src/dhcpcd.c         |  244 ++++++++--------
 external/bsd/dhcpcd/dist/src/dhcpcd.conf.5.in |   16 +-
 external/bsd/dhcpcd/dist/src/dhcpcd.h         |    2 +-
 external/bsd/dhcpcd/dist/src/duid.c           |   22 +-
 external/bsd/dhcpcd/dist/src/eloop.c          |   26 +-
 external/bsd/dhcpcd/dist/src/if-bsd.c         |   75 +++-
 external/bsd/dhcpcd/dist/src/if-options.c     |  318 +++++++++++-----------
 external/bsd/dhcpcd/dist/src/if-options.h     |    2 +-
 external/bsd/dhcpcd/dist/src/if.c             |   27 +-
 external/bsd/dhcpcd/dist/src/ipv4.c           |   39 +-
 external/bsd/dhcpcd/dist/src/ipv4ll.c         |   27 +-
 external/bsd/dhcpcd/dist/src/ipv6.c           |   80 ++---
 external/bsd/dhcpcd/dist/src/ipv6nd.c         |  161 +++++------
 external/bsd/dhcpcd/dist/src/logerr.c         |  368 ++++++++++++++++++++++++++
 external/bsd/dhcpcd/dist/src/logerr.h         |   77 +++++
 external/bsd/dhcpcd/dist/src/route.c          |   26 +-
 external/bsd/dhcpcd/dist/src/script.c         |   27 +-
 27 files changed, 1339 insertions(+), 909 deletions(-)

diffs (truncated from 6714 to 300 lines):

diff -r c69fe53babc4 -r b9f542e9d9d8 external/bsd/dhcpcd/dist/src/arp.c
--- a/external/bsd/dhcpcd/dist/src/arp.c        Sun Apr 02 18:54:20 2017 +0000
+++ b/external/bsd/dhcpcd/dist/src/arp.c        Fri Apr 14 09:53:06 2017 +0000
@@ -38,7 +38,6 @@
 #include <signal.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <unistd.h>
 
 #define ELOOP_QUEUE 5
@@ -52,6 +51,7 @@
 #include "if.h"
 #include "if-options.h"
 #include "ipv4ll.h"
+#include "logerr.h"
 
 #if defined(ARP) && (!defined(KERNEL_RFC5227) || defined(ARPING))
 #define ARP_LEN                                                                      \
@@ -152,7 +152,7 @@
        }
        if (ifn) {
 #ifdef ARP_DEBUG
-               syslog(LOG_DEBUG, "%s: ignoring ARP from self", ifp->name);
+               logdebugx("%s: ignoring ARP from self", ifp->name);
 #endif
                return;
        }
@@ -180,7 +180,7 @@
 
        if ((state = ARP_STATE(ifp)) != NULL && state->fd != -1) {
                eloop_event_delete(ifp->ctx->eloop, state->fd);
-               bpf_close(state->fd);
+               bpf_close(ifp, state->fd);
                state->fd = -1;
        }
 }
@@ -202,7 +202,7 @@
        while (!(flags & BPF_EOF)) {
                bytes = bpf_read(ifp, state->fd, buf, sizeof(buf), &flags);
                if (bytes == -1) {
-                       syslog(LOG_ERR, "%s: arp bpf_read: %m", ifp->name);
+                       logerr("%s: %s", __func__, ifp->name);
                        arp_close(ifp);
                        return;
                }
@@ -222,7 +222,7 @@
        if (state->fd == -1) {
                state->fd = bpf_open(ifp, bpf_arp);
                if (state->fd == -1) {
-                       syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
+                       logerr("%s: %s", __func__, ifp->name);
                        return -1;
                }
                eloop_event_add(ifp->ctx->eloop, state->fd, arp_read, ifp);
@@ -256,13 +256,12 @@
                tv.tv_nsec = 0;
                eloop_timeout_add_tv(ifp->ctx->eloop, &tv, arp_probed, astate);
        }
-       syslog(LOG_DEBUG,
-           "%s: ARP probing %s (%d of %d), next in %0.1f seconds",
+       logdebugx("%s: ARP probing %s (%d of %d), next in %0.1f seconds",
            ifp->name, inet_ntoa(astate->addr),
            astate->probes ? astate->probes : PROBE_NUM, PROBE_NUM,
            timespec_to_double(&tv));
        if (arp_request(ifp, 0, astate->addr.s_addr) == -1)
-               syslog(LOG_ERR, "send_arp: %m");
+               logerr(__func__);
 }
 
 void
@@ -270,15 +269,16 @@
 {
 
        if (arp_open(astate->iface) == -1) {
-               syslog(LOG_ERR, "%s: %s: %m", __func__, astate->iface->name);
+               logerr(__func__);
                return;
        } else {
                const struct iarp_state *state = ARP_CSTATE(astate->iface);
 
-               bpf_arp(astate->iface, state->fd);
+               if (bpf_arp(astate->iface, state->fd) == -1)
+                       logerr(__func__);
        }
        astate->probes = 0;
-       syslog(LOG_DEBUG, "%s: probing for %s",
+       logdebugx("%s: probing for %s",
            astate->iface->name, inet_ntoa(astate->addr));
        arp_probe1(astate);
 }
@@ -311,18 +311,16 @@
        astate->claims++;
 #else
        if (++astate->claims < ANNOUNCE_NUM)
-               syslog(LOG_DEBUG,
-                   "%s: ARP announcing %s (%d of %d), "
+               logdebugx("%s: ARP announcing %s (%d of %d), "
                    "next in %d.0 seconds",
                    ifp->name, inet_ntoa(astate->addr),
                    astate->claims, ANNOUNCE_NUM, ANNOUNCE_WAIT);
        else
-               syslog(LOG_DEBUG,
-                   "%s: ARP announcing %s (%d of %d)",
+               logdebugx("%s: ARP announcing %s (%d of %d)",
                    ifp->name, inet_ntoa(astate->addr),
                    astate->claims, ANNOUNCE_NUM);
        if (arp_request(ifp, astate->addr.s_addr, astate->addr.s_addr) == -1)
-               syslog(LOG_ERR, "arp_request: %m");
+               logerr(__func__);
 #endif
        eloop_timeout_add_sec(ifp->ctx->eloop, ANNOUNCE_WAIT,
            astate->claims < ANNOUNCE_NUM ? arp_announce1 : arp_announced,
@@ -335,7 +333,7 @@
 
 #ifndef KERNEL_RFC5227
        if (arp_open(astate->iface) == -1) {
-               syslog(LOG_ERR, "%s: %s: %m", __func__, astate->iface->name);
+               logerr(__func__);
                return;
        }
 #endif
@@ -352,13 +350,13 @@
        if (amsg != NULL) {
                char buf[HWADDR_LEN * 3];
 
-               syslog(LOG_ERR, "%s: hardware address %s claims %s",
+               logerrx("%s: hardware address %s claims %s",
                    astate->iface->name,
                    hwaddr_ntoa(amsg->sha, astate->iface->hwlen,
                    buf, sizeof(buf)),
                    inet_ntoa(astate->failed));
        } else
-               syslog(LOG_ERR, "%s: DAD detected %s",
+               logerrx("%s: DAD detected %s",
                    astate->iface->name, inet_ntoa(astate->failed));
 }
 
@@ -389,7 +387,7 @@
                ifp->if_data[IF_DATA_ARP] = malloc(sizeof(*state));
                state = ARP_STATE(ifp);
                if (state == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        return NULL;
                }
                state->fd = -1;
@@ -400,7 +398,7 @@
        }
 
        if ((astate = calloc(1, sizeof(*astate))) == NULL) {
-               syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__);
+               logerr(__func__);
                return NULL;
        }
        astate->iface = ifp;
@@ -409,7 +407,8 @@
        state = ARP_STATE(ifp);
        TAILQ_INSERT_TAIL(&state->arp_states, astate, next);
 
-       bpf_arp(ifp, state->fd);
+       if (bpf_arp(ifp, state->fd) == -1)
+               logerr(__func__); /* try and continue */
 
        return astate;
 }
@@ -444,7 +443,8 @@
                free(state);
                ifp->if_data[IF_DATA_ARP] = NULL;
        } else
-               bpf_arp(ifp, state->fd);
+               if (bpf_arp(ifp, state->fd) == -1)
+                       logerr(__func__);
 }
 
 static void
diff -r c69fe53babc4 -r b9f542e9d9d8 external/bsd/dhcpcd/dist/src/bpf.c
--- a/external/bsd/dhcpcd/dist/src/bpf.c        Sun Apr 02 18:54:20 2017 +0000
+++ b/external/bsd/dhcpcd/dist/src/bpf.c        Fri Apr 14 09:53:06 2017 +0000
@@ -48,13 +48,13 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 
 #include "common.h"
 #include "arp.h"
 #include "bpf.h"
 #include "dhcp.h"
 #include "if.h"
+#include "logerr.h"
 
 #define        ARP_ADDRS_MAX   3
 
@@ -150,7 +150,7 @@
                goto eexit;
        if (pv.bv_major != BPF_MAJOR_VERSION ||
            pv.bv_minor < BPF_MINOR_VERSION) {
-               syslog(LOG_ERR, "BPF version mismatch - recompile");
+               logerrx("BPF version mismatch - recompile");
                goto eexit;
        }
 
@@ -174,7 +174,6 @@
                        goto eexit;
                state->buffer = nb;
                state->buffer_size = buf_len;
-               state->buffer_len = state->buffer_pos = 0;
        }
 
 #ifdef BIOCIMMEDIATE
@@ -222,8 +221,6 @@
                bytes = -1;
                memcpy(&packet, state->buffer + state->buffer_pos,
                    sizeof(packet));
-               if (packet.bh_caplen != packet.bh_datalen)
-                       goto next; /* Incomplete packet, drop. */
                if (state->buffer_pos + packet.bh_caplen + packet.bh_hdrlen >
                    state->buffer_len)
                        goto next; /* Packet beyond buffer, drop. */
@@ -288,6 +285,16 @@
 }
 #endif
 
+int
+bpf_close(struct interface *ifp, int fd)
+{
+       struct ipv4_state *state = IPV4_STATE(ifp);
+
+       /* Rewind the buffer on closing. */
+       state->buffer_len = state->buffer_pos = 0;
+       return close(fd);
+}
+
 static unsigned int
 bpf_cmp_hwaddr(struct bpf_insn *bpf, size_t bpf_len, size_t off,
     bool equal, uint8_t *hwaddr, size_t hwaddr_len)
@@ -419,15 +426,16 @@
        BPF_STMT(BPF_RET + BPF_K, 0),
 };
 #define bpf_arp_filter_len     __arraycount(bpf_arp_filter)
-#define bpf_arp_extra          (((ARP_ADDRS_MAX + 1) * 2) * 2) + 2
+#define bpf_arp_extra          ((((ARP_ADDRS_MAX + 1) * 2) * 2) + 2)
+#define bpf_arp_hw             ((((HWADDR_LEN / 4) + 2) * 2) + 1)
 
 int
 bpf_arp(struct interface *ifp, int fd)
 {
-       size_t bpf_hw = (((sizeof(ifp->hwaddr) / 4) + 2) * 2) + 1;
-       struct bpf_insn bpf[3 + bpf_arp_filter_len + bpf_hw + bpf_arp_extra];
+       struct bpf_insn bpf[3+ bpf_arp_filter_len + bpf_arp_hw + bpf_arp_extra];
        struct bpf_insn *bp;
        struct iarp_state *state;
+       uint16_t arp_len;
 
        if (fd == -1)
                return 0;
@@ -438,6 +446,7 @@
        case ARPHRD_ETHER:
                memcpy(bp, bpf_arp_ether, sizeof(bpf_arp_ether));
                bp += bpf_arp_ether_len;
+               arp_len = sizeof(struct ether_header)+sizeof(struct ether_arp);
                break;
        default:
                errno = EINVAL;
@@ -449,7 +458,7 @@
        bp += bpf_arp_filter_len;
 
        /* Ensure it's not from us. */
-       bp += bpf_cmp_hwaddr(bp, bpf_hw, sizeof(struct arphdr),
+       bp += bpf_cmp_hwaddr(bp, bpf_arp_hw, sizeof(struct arphdr),
                             false, ifp->hwaddr, ifp->hwlen);
 
        state = ARP_STATE(ifp);
@@ -465,13 +474,13 @@
                TAILQ_FOREACH(astate, &state->arp_states, next) {
                        if (++naddrs > ARP_ADDRS_MAX) {
                                errno = ENOBUFS;
-                               syslog(LOG_ERR, "%s: %m", __func__);
+                               logerr(__func__);
                                break;
                        }
                        BPF_SET_JUMP(bp, BPF_JMP + BPF_JEQ + BPF_K,
                                     htonl(astate->addr.s_addr), 0, 1);
                        bp++;
-                       BPF_SET_STMT(bp, BPF_RET + BPF_K, BPF_WHOLEPACKET);
+                       BPF_SET_STMT(bp, BPF_RET + BPF_K, arp_len);
                        bp++;
                }
 
@@ -496,8 +505,7 @@
                        BPF_SET_JUMP(bp, BPF_JMP + BPF_JEQ + BPF_K,
                                     htonl(astate->addr.s_addr), 0, 1);
                        bp++;
-                       BPF_SET_STMT(bp, BPF_RET + BPF_K,
-                                    BPF_WHOLEPACKET);
+                       BPF_SET_STMT(bp, BPF_RET + BPF_K, arp_len);
                        bp++;
                }
 



Home | Main Index | Thread Index | Old Index