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/dfced12a7a90
branches:  trunk
changeset: 339266:dfced12a7a90
user:      roy <roy%NetBSD.org@localhost>
date:      Thu Jul 09 10:15:34 2015 +0000

description:
Sync

diffstat:

 external/bsd/dhcpcd/dist/arp.c                   |  105 +++--
 external/bsd/dhcpcd/dist/arp.h                   |   13 +-
 external/bsd/dhcpcd/dist/auth.c                  |    6 +-
 external/bsd/dhcpcd/dist/common.c                |   13 +-
 external/bsd/dhcpcd/dist/common.h                |    5 +-
 external/bsd/dhcpcd/dist/defs.h                  |    6 +-
 external/bsd/dhcpcd/dist/dhcp-common.c           |  109 ++++-
 external/bsd/dhcpcd/dist/dhcp-common.h           |    9 +-
 external/bsd/dhcpcd/dist/dhcp.c                  |  387 ++++++++++------------
 external/bsd/dhcpcd/dist/dhcp.h                  |   25 +-
 external/bsd/dhcpcd/dist/dhcp6.c                 |  270 ++++++---------
 external/bsd/dhcpcd/dist/dhcp6.h                 |   10 +-
 external/bsd/dhcpcd/dist/dhcpcd-definitions.conf |   14 +-
 external/bsd/dhcpcd/dist/dhcpcd-embedded.c       |    5 +-
 external/bsd/dhcpcd/dist/dhcpcd-embedded.h       |    4 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/01-test    |    6 +-
 external/bsd/dhcpcd/dist/dhcpcd-run-hooks.8.in   |   12 +-
 external/bsd/dhcpcd/dist/dhcpcd-run-hooks.in     |    6 +-
 external/bsd/dhcpcd/dist/dhcpcd.8.in             |   24 +-
 external/bsd/dhcpcd/dist/dhcpcd.c                |  164 +++++----
 external/bsd/dhcpcd/dist/dhcpcd.conf.5.in        |   39 +-
 external/bsd/dhcpcd/dist/dhcpcd.h                |   17 +-
 external/bsd/dhcpcd/dist/duid.c                  |    5 +-
 external/bsd/dhcpcd/dist/if-bsd.c                |   24 +-
 external/bsd/dhcpcd/dist/if-options.c            |   52 ++-
 external/bsd/dhcpcd/dist/if-options.h            |   16 +-
 external/bsd/dhcpcd/dist/if.c                    |   20 +-
 external/bsd/dhcpcd/dist/if.h                    |   10 +-
 external/bsd/dhcpcd/dist/ipv4.c                  |  273 ++++++++--------
 external/bsd/dhcpcd/dist/ipv4.h                  |   43 ++-
 external/bsd/dhcpcd/dist/ipv4ll.c                |  328 +++++++++++++------
 external/bsd/dhcpcd/dist/ipv4ll.h                |   36 ++-
 external/bsd/dhcpcd/dist/ipv6.c                  |  217 +++++++-----
 external/bsd/dhcpcd/dist/ipv6.h                  |    7 +-
 external/bsd/dhcpcd/dist/ipv6nd.c                |   95 +++-
 external/bsd/dhcpcd/dist/ipv6nd.h                |    5 +-
 external/bsd/dhcpcd/dist/script.c                |  106 ++++--
 37 files changed, 1370 insertions(+), 1116 deletions(-)

diffs (truncated from 5090 to 300 lines):

diff -r 7e474092f10f -r dfced12a7a90 external/bsd/dhcpcd/dist/arp.c
--- a/external/bsd/dhcpcd/dist/arp.c    Thu Jul 09 07:20:57 2015 +0000
+++ b/external/bsd/dhcpcd/dist/arp.c    Thu Jul 09 10:15:34 2015 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: arp.c,v 1.13 2015/05/16 23:31:32 roy Exp $");
+ __RCSID("$NetBSD: arp.c,v 1.14 2015/07/09 10:15:34 roy Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -31,6 +31,8 @@
 #include <sys/socket.h>
 #include <sys/types.h>
 
+#include <arpa/inet.h>
+
 #include <net/if.h>
 #include <netinet/in.h>
 #include <netinet/if_ether.h>
@@ -47,7 +49,6 @@
 #include "if.h"
 #include "ipv4.h"
 #include "common.h"
-#include "dhcp.h"
 #include "dhcpcd.h"
 #include "eloop.h"
 #include "if.h"
@@ -101,7 +102,7 @@
 arp_report_conflicted(const struct arp_state *astate, const struct arp_msg *amsg)
 {
 
-       if (amsg) {
+       if (amsg != NULL) {
                char buf[HWADDR_LEN * 3];
 
                logger(astate->iface->ctx, LOG_ERR,
@@ -125,12 +126,12 @@
        struct arphdr ar;
        struct arp_msg arm;
        ssize_t bytes;
-       struct dhcp_state *state;
+       struct iarp_state *state;
        struct arp_state *astate, *astaten;
        unsigned char *hw_s, *hw_t;
        int flags;
 
-       state = D_STATE(ifp);
+       state = ARP_STATE(ifp);
        flags = 0;
        while (!(flags & RAW_EOF)) {
                bytes = if_readrawpacket(ifp, ETHERTYPE_ARP,
@@ -138,7 +139,7 @@
                if (bytes == -1) {
                        logger(ifp->ctx, LOG_ERR,
                            "%s: arp if_readrawpacket: %m", ifp->name);
-                       dhcp_close(ifp);
+                       arp_close(ifp);
                        return;
                }
                /* We must have a full ARP header */
@@ -189,17 +190,17 @@
 static void
 arp_open(struct interface *ifp)
 {
-       struct dhcp_state *state;
+       struct iarp_state *state;
 
-       state = D_STATE(ifp);
-       if (state->arp_fd == -1) {
-               state->arp_fd = if_openrawsocket(ifp, ETHERTYPE_ARP);
-               if (state->arp_fd == -1) {
+       state = ARP_STATE(ifp);
+       if (state->fd == -1) {
+               state->fd = if_openrawsocket(ifp, ETHERTYPE_ARP);
+               if (state->fd == -1) {
                        logger(ifp->ctx, LOG_ERR, "%s: %s: %m",
                            __func__, ifp->name);
                        return;
                }
-               eloop_event_add(ifp->ctx->eloop, state->arp_fd,
+               eloop_event_add(ifp->ctx->eloop, state->fd,
                    arp_packet, ifp, NULL, NULL);
        }
 }
@@ -300,10 +301,10 @@
 struct arp_state *
 arp_find(struct interface *ifp, const struct in_addr *addr)
 {
+       struct iarp_state *state;
        struct arp_state *astate;
-       struct dhcp_state *state;
 
-       if ((state = D_STATE(ifp)) == NULL)
+       if ((state = ARP_STATE(ifp)) == NULL)
                goto out;
        TAILQ_FOREACH(astate, &state->arp_states, next) {
                if (astate->addr.s_addr == addr->s_addr && astate->iface == ifp)
@@ -317,20 +318,31 @@
 struct arp_state *
 arp_new(struct interface *ifp, const struct in_addr *addr)
 {
+       struct iarp_state *state;
        struct arp_state *astate;
-       struct dhcp_state *state;
 
-       if (addr && (astate = arp_find(ifp, addr)))
-               return astate;
+       if ((state = ARP_STATE(ifp)) == NULL) {
+               ifp->if_data[IF_DATA_ARP] = malloc(sizeof(*state));
+               state = ARP_STATE(ifp);
+               if (state == NULL) {
+                       logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
+                       return NULL;
+               }
+               state->fd = -1;
+               TAILQ_INIT(&state->arp_states);
+       } else {
+               if (addr && (astate = arp_find(ifp, addr)))
+                       return astate;
+       }
 
        if ((astate = calloc(1, sizeof(*astate))) == NULL) {
                logger(ifp->ctx, LOG_ERR, "%s: %s: %m", ifp->name, __func__);
                return NULL;
        }
-       state = D_STATE(ifp);
        astate->iface = ifp;
        if (addr)
                astate->addr = *addr;
+       state = ARP_STATE(ifp);
        TAILQ_INSERT_TAIL(&state->arp_states, astate, next);
        return astate;
 }
@@ -345,27 +357,38 @@
 void
 arp_free(struct arp_state *astate)
 {
-       struct dhcp_state *state;
 
-       if (astate) {
-               eloop_timeout_delete(astate->iface->ctx->eloop, NULL, astate);
-               state = D_STATE(astate->iface);
+       if (astate != NULL) {
+               struct interface *ifp;
+               struct iarp_state *state;
+
+               ifp = astate->iface;
+               eloop_timeout_delete(ifp->ctx->eloop, NULL, astate);
+               state = ARP_STATE(ifp);
                TAILQ_REMOVE(&state->arp_states, astate, next);
-               if (state->arp_ipv4ll == astate) {
-                       ipv4ll_stop(astate->iface);
-                       state->arp_ipv4ll = NULL;
+               if (astate->free_cb)
+                       astate->free_cb(astate);
+               free(astate);
+
+               /* If there are no more ARP states, close the socket. */
+               if (state->fd != -1 &&
+                   TAILQ_FIRST(&state->arp_states) == NULL)
+               {
+                       eloop_event_delete(ifp->ctx->eloop, state->fd);
+                       close(state->fd);
+                       free(state);
+                       ifp->if_data[IF_DATA_ARP] = NULL;
                }
-               free(astate);
        }
 }
 
 void
 arp_free_but(struct arp_state *astate)
 {
+       struct iarp_state *state;
        struct arp_state *p, *n;
-       struct dhcp_state *state;
 
-       state = D_STATE(astate->iface);
+       state = ARP_STATE(astate->iface);
        TAILQ_FOREACH_SAFE(p, &state->arp_states, next, n) {
                if (p != astate)
                        arp_free(p);
@@ -375,24 +398,16 @@
 void
 arp_close(struct interface *ifp)
 {
-       struct dhcp_state *state = D_STATE(ifp);
+       struct iarp_state *state;
        struct arp_state *astate;
 
-       if (state == NULL)
-               return;
-
-       if (state->arp_fd != -1) {
-               eloop_event_delete(ifp->ctx->eloop, state->arp_fd);
-               close(state->arp_fd);
-               state->arp_fd = -1;
-       }
-
-       while ((astate = TAILQ_FIRST(&state->arp_states))) {
-#ifndef __clang_analyzer__
-               /* clang guard needed for a more compex variant on this bug:
-                * http://llvm.org/bugs/show_bug.cgi?id=18222 */
+       /* Freeing the last state will also free the main state,
+        * so test for both. */
+       for (;;) {
+               if ((state = ARP_STATE(ifp)) == NULL ||
+                   (astate = TAILQ_FIRST(&state->arp_states)) == NULL)
+                       break;
                arp_free(astate);
-#endif
        }
 }
 
@@ -401,10 +416,10 @@
     int flags)
 {
 #ifdef IN_IFF_DUPLICATED
-       struct dhcp_state *state = D_STATE(ifp);
+       struct iarp_state *state;
        struct arp_state *astate, *asn;
 
-       if (cmd != RTM_NEWADDR || (state = D_STATE(ifp)) == NULL)
+       if (cmd != RTM_NEWADDR || (state = ARP_STATE(ifp)) == NULL)
                return;
 
        TAILQ_FOREACH_SAFE(astate, &state->arp_states, next, asn) {
diff -r 7e474092f10f -r dfced12a7a90 external/bsd/dhcpcd/dist/arp.h
--- a/external/bsd/dhcpcd/dist/arp.h    Thu Jul 09 07:20:57 2015 +0000
+++ b/external/bsd/dhcpcd/dist/arp.h    Thu Jul 09 10:15:34 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: arp.h,v 1.10 2015/05/16 23:31:32 roy Exp $ */
+/* $NetBSD: arp.h,v 1.11 2015/07/09 10:15:34 roy Exp $ */
 
 /*
  * dhcpcd - DHCP client daemon
@@ -59,6 +59,7 @@
        void (*probed_cb)(struct arp_state *);
        void (*announced_cb)(struct arp_state *);
        void (*conflicted_cb)(struct arp_state *, const struct arp_msg *);
+       void (*free_cb)(struct arp_state *);
 
        struct in_addr addr;
        int probes;
@@ -67,6 +68,16 @@
 };
 TAILQ_HEAD(arp_statehead, arp_state);
 
+struct iarp_state {
+       int fd;
+       struct arp_statehead arp_states;
+};
+
+#define ARP_STATE(ifp)                                                        \
+       ((struct iarp_state *)(ifp)->if_data[IF_DATA_ARP])
+#define ARP_CSTATE(ifp)                                                               \
+       ((const struct iarp_state *)(ifp)->if_data[IF_DATA_ARP])
+
 #ifdef INET
 void arp_report_conflicted(const struct arp_state *, const struct arp_msg *);
 void arp_announce(struct arp_state *);
diff -r 7e474092f10f -r dfced12a7a90 external/bsd/dhcpcd/dist/auth.c
--- a/external/bsd/dhcpcd/dist/auth.c   Thu Jul 09 07:20:57 2015 +0000
+++ b/external/bsd/dhcpcd/dist/auth.c   Thu Jul 09 10:15:34 2015 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: auth.c,v 1.9 2015/03/26 10:26:37 roy Exp $");
+ __RCSID("$NetBSD: auth.c,v 1.10 2015/07/09 10:15:34 roy Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -418,7 +418,8 @@
        rdm++;
        if (fseek(fp, 0, SEEK_SET) == -1 ||
            ftruncate(fileno(fp), 0) == -1 ||
-           fprintf(fp, "0x%016" PRIu64 "\n", rdm) != 19)
+           fprintf(fp, "0x%016" PRIu64 "\n", rdm) != 19 ||
+           fflush(fp) == EOF)
        {
                if (!auth->last_replay_set) {
                        auth->last_replay = rdm;
@@ -427,7 +428,6 @@
                        rdm = ++auth->last_replay;
                /* report error? */
        }
-       fflush(fp);
 #ifdef LOCK_EX
        if (flocked == 0)
                flock(fileno(fp), LOCK_UN);
diff -r 7e474092f10f -r dfced12a7a90 external/bsd/dhcpcd/dist/common.c
--- a/external/bsd/dhcpcd/dist/common.c Thu Jul 09 07:20:57 2015 +0000
+++ b/external/bsd/dhcpcd/dist/common.c Thu Jul 09 10:15:34 2015 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: common.c,v 1.13 2015/05/16 23:31:32 roy Exp $");
+ __RCSID("$NetBSD: common.c,v 1.14 2015/07/09 10:15:34 roy Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -257,17 +257,6 @@



Home | Main Index | Thread Index | Old Index