Source-Changes-HG archive

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

[src/netbsd-7]: src/external/bsd/dhcpcd/dist Pullup the import of dhcpcd-6.6....



details:   https://anonhg.NetBSD.org/src/rev/87858d279987
branches:  netbsd-7
changeset: 798747:87858d279987
user:      martin <martin%NetBSD.org@localhost>
date:      Mon Dec 29 16:18:04 2014 +0000

description:
Pullup the import of dhcpcd-6.6.7, requested by roy in #207

diffstat:

 external/bsd/dhcpcd/dist/arp.c                           |  392 ++++----
 external/bsd/dhcpcd/dist/arp.h                           |   39 +-
 external/bsd/dhcpcd/dist/auth.c                          |    3 +-
 external/bsd/dhcpcd/dist/auth.h                          |    4 +-
 external/bsd/dhcpcd/dist/bpf-filter.h                    |    2 +-
 external/bsd/dhcpcd/dist/common.c                        |    6 +-
 external/bsd/dhcpcd/dist/common.h                        |    2 +-
 external/bsd/dhcpcd/dist/config.h                        |    3 +-
 external/bsd/dhcpcd/dist/control.c                       |  311 +++++-
 external/bsd/dhcpcd/dist/control.h                       |   24 +-
 external/bsd/dhcpcd/dist/crypt/crypt.h                   |    2 +-
 external/bsd/dhcpcd/dist/crypt/hmac_md5.c                |    2 +-
 external/bsd/dhcpcd/dist/defs.h                          |    7 +-
 external/bsd/dhcpcd/dist/dev.h                           |    6 +-
 external/bsd/dhcpcd/dist/dhcp-common.c                   |  315 +++++-
 external/bsd/dhcpcd/dist/dhcp-common.h                   |   13 +-
 external/bsd/dhcpcd/dist/dhcp.c                          |  655 +++++++++-----
 external/bsd/dhcpcd/dist/dhcp.h                          |   30 +-
 external/bsd/dhcpcd/dist/dhcp6.c                         |  488 +++++++---
 external/bsd/dhcpcd/dist/dhcp6.h                         |   16 +-
 external/bsd/dhcpcd/dist/dhcpcd-definitions.conf         |   48 +-
 external/bsd/dhcpcd/dist/dhcpcd-embedded.c               |   46 +-
 external/bsd/dhcpcd/dist/dhcpcd-embedded.h               |    2 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/01-test            |    6 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/02-dump            |    2 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/10-mtu             |    2 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/10-wpa_supplicant  |    6 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/15-timezone        |    2 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/20-resolv.conf     |    2 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/29-lookup-hostname |    8 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/30-hostname        |    2 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ntp.conf        |    4 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ypbind          |    6 +-
 external/bsd/dhcpcd/dist/dhcpcd-run-hooks.8.in           |  112 ++-
 external/bsd/dhcpcd/dist/dhcpcd-run-hooks.in             |   12 +-
 external/bsd/dhcpcd/dist/dhcpcd.8.in                     |   58 +-
 external/bsd/dhcpcd/dist/dhcpcd.c                        |  526 ++++++-----
 external/bsd/dhcpcd/dist/dhcpcd.conf                     |    5 +-
 external/bsd/dhcpcd/dist/dhcpcd.conf.5.in                |   77 +-
 external/bsd/dhcpcd/dist/dhcpcd.h                        |   21 +-
 external/bsd/dhcpcd/dist/duid.c                          |    2 +-
 external/bsd/dhcpcd/dist/duid.h                          |    2 +-
 external/bsd/dhcpcd/dist/eloop.c                         |  100 +-
 external/bsd/dhcpcd/dist/eloop.h                         |   18 +-
 external/bsd/dhcpcd/dist/if-bsd.c                        |  416 +++++---
 external/bsd/dhcpcd/dist/if-options.c                    |   86 +-
 external/bsd/dhcpcd/dist/if-options.h                    |    5 +-
 external/bsd/dhcpcd/dist/if.c                            |  137 ++-
 external/bsd/dhcpcd/dist/if.h                            |   28 +-
 external/bsd/dhcpcd/dist/ipv4.c                          |  191 +++-
 external/bsd/dhcpcd/dist/ipv4.h                          |   10 +-
 external/bsd/dhcpcd/dist/ipv4ll.c                        |  237 +++-
 external/bsd/dhcpcd/dist/ipv4ll.h                        |    4 +-
 external/bsd/dhcpcd/dist/ipv6.c                          |  253 ++++-
 external/bsd/dhcpcd/dist/ipv6.h                          |   19 +-
 external/bsd/dhcpcd/dist/ipv6nd.c                        |  212 ++--
 external/bsd/dhcpcd/dist/ipv6nd.h                        |   18 +-
 external/bsd/dhcpcd/dist/script.c                        |  164 ++-
 external/bsd/dhcpcd/dist/script.h                        |    6 +-
 59 files changed, 3357 insertions(+), 1818 deletions(-)

diffs (truncated from 9784 to 300 lines):

diff -r eab820a9a010 -r 87858d279987 external/bsd/dhcpcd/dist/arp.c
--- a/external/bsd/dhcpcd/dist/arp.c    Wed Dec 24 00:07:46 2014 +0000
+++ b/external/bsd/dhcpcd/dist/arp.c    Mon Dec 29 16:18:04 2014 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: arp.c,v 1.1.1.13 2014/07/30 15:44:09 roy Exp $");
+ __RCSID("$NetBSD: arp.c,v 1.1.1.13.2.1 2014/12/29 16:18:04 martin Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -42,6 +42,7 @@
 #include <syslog.h>
 #include <unistd.h>
 
+#define ELOOP_QUEUE 5
 #include "config.h"
 #include "arp.h"
 #include "ipv4.h"
@@ -96,57 +97,37 @@
        return -1;
 }
 
-static void
-arp_failure(struct interface *ifp)
+void
+arp_report_conflicted(const struct arp_state *astate, const struct arp_msg *amsg)
 {
-       const struct dhcp_state *state = D_CSTATE(ifp);
+       char buf[HWADDR_LEN * 3];
 
-       /* If we failed without a magic cookie then we need to try
-        * and defend our IPv4LL address. */
-       if ((state->offer != NULL &&
-           state->offer->cookie != htonl(MAGIC_COOKIE)) ||
-           (state->new != NULL &&
-           state->new->cookie != htonl(MAGIC_COOKIE)))
-       {
-               ipv4ll_handle_failure(ifp);
-               return;
-       }
-
-       unlink(state->leasefile);
-       if (!state->lease.frominfo)
-               dhcp_decline(ifp);
-       eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
-       if (state->lease.frominfo)
-               dhcpcd_startinterface(ifp);
-       else
-               eloop_timeout_add_sec(ifp->ctx->eloop,
-                   DHCP_ARP_FAIL, dhcpcd_startinterface, ifp);
+       syslog(LOG_ERR, "%s: hardware address %s claims %s",
+           astate->iface->name,
+           hwaddr_ntoa(amsg->sha, astate->iface->hwlen, buf, sizeof(buf)),
+           inet_ntoa(astate->failed));
 }
 
 static void
 arp_packet(void *arg)
 {
        struct interface *ifp = arg;
+       const struct interface *ifn;
        uint8_t arp_buffer[ARP_LEN];
        struct arphdr ar;
-       uint32_t reply_s;
-       uint32_t reply_t;
-       uint8_t *hw_s, *hw_t;
+       struct arp_msg arm;
        ssize_t bytes;
        struct dhcp_state *state;
-       struct if_options *opts = ifp->options;
-       const char *hwaddr;
-       struct in_addr ina;
-       char hwbuf[HWADDR_LEN * 3];
+       struct arp_state *astate, *astaten;
+       unsigned char *hw_s, *hw_t;
        int flags;
 
        state = D_STATE(ifp);
-       state->fail.s_addr = 0;
        flags = 0;
        while (!(flags & RAW_EOF)) {
                bytes = if_readrawpacket(ifp, ETHERTYPE_ARP,
                    arp_buffer, sizeof(arp_buffer), &flags);
-               if (bytes == 0 || bytes == -1) {
+               if (bytes == -1) {
                        syslog(LOG_ERR, "%s: arp if_readrawpacket: %m",
                            ifp->name);
                        dhcp_close(ifp);
@@ -156,10 +137,13 @@
                if ((size_t)bytes < sizeof(ar))
                        continue;
                memcpy(&ar, arp_buffer, sizeof(ar));
+               /* Families must match */
+               if (ar.ar_hrd != htons(ifp->family))
+                       continue;
                /* Protocol must be IP. */
                if (ar.ar_pro != htons(ETHERTYPE_IP))
                        continue;
-               if (ar.ar_pln != sizeof(reply_s))
+               if (ar.ar_pln != sizeof(arm.sip.s_addr))
                        continue;
                /* Only these types are recognised */
                if (ar.ar_op != htons(ARPOP_REPLY) &&
@@ -173,217 +157,213 @@
                if ((hw_t + ar.ar_hln + ar.ar_pln) - arp_buffer > bytes)
                        continue;
                /* Ignore messages from ourself */
-               if (ar.ar_hln == ifp->hwlen &&
-                   memcmp(hw_s, ifp->hwaddr, ifp->hwlen) == 0)
+               TAILQ_FOREACH(ifn, ifp->ctx->ifaces, next) {
+                       if (ar.ar_hln == ifn->hwlen &&
+                           memcmp(hw_s, ifn->hwaddr, ifn->hwlen) == 0)
+                               break;
+               }
+               if (ifn)
                        continue;
-               /* Copy out the IP addresses */
-               memcpy(&reply_s, hw_s + ar.ar_hln, ar.ar_pln);
-               memcpy(&reply_t, hw_t + ar.ar_hln, ar.ar_pln);
+               /* Copy out the HW and IP addresses */
+               memcpy(&arm.sha, hw_s, ar.ar_hln);
+               memcpy(&arm.sip.s_addr, hw_s + ar.ar_hln, ar.ar_pln);
+               memcpy(&arm.tha, hw_t, ar.ar_hln);
+               memcpy(&arm.tip.s_addr, hw_t + ar.ar_hln, ar.ar_pln);
 
-               /* Check for arping */
-               if (state->arping_index &&
-                   state->arping_index <= opts->arping_len &&
-                   (reply_s == opts->arping[state->arping_index - 1] ||
-                   (reply_s == 0 &&
-                   reply_t == opts->arping[state->arping_index - 1])))
-               {
-                       ina.s_addr = reply_s;
-                       hwaddr = hwaddr_ntoa((unsigned char *)hw_s,
-                           (size_t)ar.ar_hln, hwbuf, sizeof(hwbuf));
-                       syslog(LOG_INFO,
-                           "%s: found %s on hardware address %s",
-                           ifp->name, inet_ntoa(ina), hwaddr);
-                       if (dhcpcd_selectprofile(ifp, hwaddr) == -1 &&
-                           dhcpcd_selectprofile(ifp, inet_ntoa(ina)) == -1)
-                       {
-                               state->probes = 0;
-                               /* We didn't find a profile for this
-                                * address or hwaddr, so move to the next
-                                * arping profile */
-                               if (state->arping_index <
-                                   ifp->options->arping_len)
-                               {
-                                       arp_probe(ifp);
-                                       return;
-                               }
-                       }
-                       dhcp_close(ifp);
-                       eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
-                       dhcpcd_startinterface(ifp);
-                       return;
-               }
-
-               /* RFC 2131 3.1.5, Client-server interaction
-                * RFC 3927 2.2.1, Probe Conflict Detection */
-               if (state->offer &&
-                   (reply_s == state->offer->yiaddr ||
-                   (reply_s == 0 && reply_t == state->offer->yiaddr)))
-                       state->fail.s_addr = state->offer->yiaddr;
-
-               /* RFC 3927 2.5, Conflict Defense */
-               if (IN_LINKLOCAL(htonl(state->addr.s_addr)) &&
-                   reply_s == state->addr.s_addr)
-                       state->fail.s_addr = state->addr.s_addr;
-
-               if (state->fail.s_addr) {
-                       syslog(LOG_ERR, "%s: hardware address %s claims %s",
-                           ifp->name,
-                           hwaddr_ntoa((unsigned char *)hw_s,
-                               (size_t)ar.ar_hln, hwbuf, sizeof(hwbuf)),
-                           inet_ntoa(state->fail));
-                       errno = EEXIST;
-                       arp_failure(ifp);
-                       return;
+               /* Run the conflicts */
+               TAILQ_FOREACH_SAFE(astate, &state->arp_states, next, astaten) {
+                       if (astate->conflicted_cb)
+                               astate->conflicted_cb(astate, &arm);
                }
        }
 }
 
-void
-arp_announce(void *arg)
+static void
+arp_open(struct interface *ifp)
 {
-       struct interface *ifp = arg;
-       struct dhcp_state *state = D_STATE(ifp);
-       struct timeval tv;
+       struct dhcp_state *state;
 
-       if (state->new == NULL)
-               return;
+       state = D_STATE(ifp);
        if (state->arp_fd == -1) {
                state->arp_fd = if_openrawsocket(ifp, ETHERTYPE_ARP);
                if (state->arp_fd == -1) {
                        syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
                        return;
                }
-               eloop_event_add(ifp->ctx->eloop,
-                   state->arp_fd, arp_packet, ifp);
+               eloop_event_add(ifp->ctx->eloop, state->arp_fd,
+                   arp_packet, ifp, NULL, NULL);
        }
-       if (++state->claims < ANNOUNCE_NUM)
-               syslog(LOG_DEBUG,
-                   "%s: sending ARP announce (%d of %d), "
-                   "next in %d.0 seconds",
-                   ifp->name, state->claims, ANNOUNCE_NUM, ANNOUNCE_WAIT);
-       else
-               syslog(LOG_DEBUG,
-                   "%s: sending ARP announce (%d of %d)",
-                   ifp->name, state->claims, ANNOUNCE_NUM);
-       if (arp_send(ifp, ARPOP_REQUEST,
-               state->new->yiaddr, state->new->yiaddr) == -1)
-               syslog(LOG_ERR, "send_arp: %m");
-       if (state->claims < ANNOUNCE_NUM) {
-               eloop_timeout_add_sec(ifp->ctx->eloop,
-                   ANNOUNCE_WAIT, arp_announce, ifp);
+}
+
+static void
+arp_announced(void *arg)
+{
+       struct arp_state *astate = arg;
+
+       if (astate->announced_cb) {
+               astate->announced_cb(astate);
                return;
        }
-       if (state->new->cookie != htonl(MAGIC_COOKIE)) {
-               /* Check if doing DHCP */
-               if (!(ifp->options->options & DHCPCD_DHCP))
-                       return;
-               /* We should pretend to be at the end
-                * of the DHCP negotation cycle unless we rebooted */
-               if (state->interval != 0)
-                       state->interval = 64;
-               state->probes = 0;
-               state->claims = 0;
-               tv.tv_sec = state->interval - DHCP_RAND_MIN;
+
+       /* Nothing more to do, so free us */
+       arp_free(astate);
+}
+
+static void
+arp_announce1(void *arg)
+{
+       struct arp_state *astate = arg;
+       struct interface *ifp = astate->iface;
+
+       if (++astate->claims < ANNOUNCE_NUM)
+               syslog(LOG_DEBUG,
+                   "%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)",
+                   ifp->name, inet_ntoa(astate->addr),
+                   astate->claims, ANNOUNCE_NUM);
+       if (arp_send(ifp, ARPOP_REQUEST,
+               astate->addr.s_addr, astate->addr.s_addr) == -1)
+               syslog(LOG_ERR, "send_arp: %m");
+       eloop_timeout_add_sec(ifp->ctx->eloop, ANNOUNCE_WAIT,
+           astate->claims < ANNOUNCE_NUM ? arp_announce1 : arp_announced,
+           astate);
+}
+
+void
+arp_announce(struct arp_state *astate)
+{
+
+       arp_open(astate->iface);
+       astate->claims = 0;
+       arp_announce1(astate);
+}
+
+static void
+arp_probed(void *arg)
+{
+       struct arp_state *astate = arg;
+
+       astate->probed_cb(astate);
+}
+
+static void
+arp_probe1(void *arg)
+{
+       struct arp_state *astate = arg;
+       struct interface *ifp = astate->iface;



Home | Main Index | Thread Index | Old Index