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/13e1fc2204ee
branches:  trunk
changeset: 803453:13e1fc2204ee
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Oct 29 01:08:31 2014 +0000

description:
Sync

diffstat:

 external/bsd/dhcpcd/dist/arp.c                   |  359 ++++++++++------------
 external/bsd/dhcpcd/dist/arp.h                   |   35 +-
 external/bsd/dhcpcd/dist/auth.c                  |    2 +-
 external/bsd/dhcpcd/dist/auth.h                  |    2 +-
 external/bsd/dhcpcd/dist/bpf-filter.h            |    2 +-
 external/bsd/dhcpcd/dist/common.c                |    2 +-
 external/bsd/dhcpcd/dist/common.h                |    2 +-
 external/bsd/dhcpcd/dist/config.h                |    2 +-
 external/bsd/dhcpcd/dist/control.c               |    2 +-
 external/bsd/dhcpcd/dist/control.h               |    2 +-
 external/bsd/dhcpcd/dist/defs.h                  |    4 +-
 external/bsd/dhcpcd/dist/dev.h                   |    2 +-
 external/bsd/dhcpcd/dist/dhcp-common.c           |    2 +-
 external/bsd/dhcpcd/dist/dhcp-common.h           |    2 +-
 external/bsd/dhcpcd/dist/dhcp.c                  |  253 ++++++++++++----
 external/bsd/dhcpcd/dist/dhcp.h                  |   23 +-
 external/bsd/dhcpcd/dist/dhcp6.c                 |    2 +-
 external/bsd/dhcpcd/dist/dhcp6.h                 |    2 +-
 external/bsd/dhcpcd/dist/dhcpcd-definitions.conf |    2 +-
 external/bsd/dhcpcd/dist/dhcpcd-embedded.c       |    2 +-
 external/bsd/dhcpcd/dist/dhcpcd-embedded.h       |    2 +-
 external/bsd/dhcpcd/dist/dhcpcd-run-hooks.8.in   |    2 +-
 external/bsd/dhcpcd/dist/dhcpcd-run-hooks.in     |    2 +-
 external/bsd/dhcpcd/dist/dhcpcd.8.in             |    2 +-
 external/bsd/dhcpcd/dist/dhcpcd.c                |   37 +-
 external/bsd/dhcpcd/dist/dhcpcd.conf             |    2 +-
 external/bsd/dhcpcd/dist/dhcpcd.conf.5.in        |    5 +-
 external/bsd/dhcpcd/dist/dhcpcd.h                |    2 +-
 external/bsd/dhcpcd/dist/duid.c                  |    2 +-
 external/bsd/dhcpcd/dist/duid.h                  |    2 +-
 external/bsd/dhcpcd/dist/eloop.c                 |    2 +-
 external/bsd/dhcpcd/dist/eloop.h                 |    2 +-
 external/bsd/dhcpcd/dist/if-bsd.c                |    2 +-
 external/bsd/dhcpcd/dist/if-options.c            |    2 +-
 external/bsd/dhcpcd/dist/if-options.h            |    5 +-
 external/bsd/dhcpcd/dist/if.c                    |    2 +-
 external/bsd/dhcpcd/dist/if.h                    |    2 +-
 external/bsd/dhcpcd/dist/ipv4.c                  |   24 +-
 external/bsd/dhcpcd/dist/ipv4.h                  |    3 +-
 external/bsd/dhcpcd/dist/ipv4ll.c                |  238 ++++++++++----
 external/bsd/dhcpcd/dist/ipv4ll.h                |    3 +-
 external/bsd/dhcpcd/dist/ipv6.c                  |    2 +-
 external/bsd/dhcpcd/dist/ipv6.h                  |    2 +-
 external/bsd/dhcpcd/dist/ipv6nd.c                |    4 +-
 external/bsd/dhcpcd/dist/ipv6nd.h                |    2 +-
 external/bsd/dhcpcd/dist/script.c                |    8 +-
 external/bsd/dhcpcd/dist/script.h                |    2 +-
 47 files changed, 642 insertions(+), 425 deletions(-)

diffs (truncated from 1939 to 300 lines):

diff -r 506f92078fc7 -r 13e1fc2204ee external/bsd/dhcpcd/dist/arp.c
--- a/external/bsd/dhcpcd/dist/arp.c    Wed Oct 29 00:48:12 2014 +0000
+++ b/external/bsd/dhcpcd/dist/arp.c    Wed Oct 29 01:08:31 2014 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: arp.c,v 1.3 2014/10/17 23:42:24 roy Exp $");
+ __RCSID("$NetBSD: arp.c,v 1.4 2014/10/29 01:08:31 roy Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -42,7 +42,7 @@
 #include <syslog.h>
 #include <unistd.h>
 
-#define ELOOP_QUEUE 2
+#define ELOOP_QUEUE 5
 #include "config.h"
 #include "arp.h"
 #include "ipv4.h"
@@ -97,31 +97,15 @@
        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
@@ -131,19 +115,14 @@
        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,
@@ -158,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) &&
@@ -182,77 +164,26 @@
                }
                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) {
@@ -262,126 +193,157 @@
                eloop_event_add(ifp->ctx->eloop, state->arp_fd,
                    arp_packet, ifp, NULL, NULL);
        }
-       if (++state->claims < ANNOUNCE_NUM)
+}
+
+static void
+arp_announced(void *arg)
+{
+       struct arp_state *astate = arg;
+
+       if (astate->announced_cb) {
+               astate->announced_cb(astate);
+               return;
+       }
+
+       /* 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: sending ARP announce (%d of %d), "
                    "next in %d.0 seconds",
-                   ifp->name, state->claims, ANNOUNCE_NUM, ANNOUNCE_WAIT);
+                   ifp->name, astate->claims, ANNOUNCE_NUM, ANNOUNCE_WAIT);
        else
                syslog(LOG_DEBUG,
                    "%s: sending ARP announce (%d of %d)",
-                   ifp->name, state->claims, ANNOUNCE_NUM);
+                   ifp->name, astate->claims, ANNOUNCE_NUM);
        if (arp_send(ifp, ARPOP_REQUEST,
-               state->new->yiaddr, state->new->yiaddr) == -1)
+               astate->addr.s_addr, astate->addr.s_addr) == -1)
                syslog(LOG_ERR, "send_arp: %m");
-       if (state->claims < ANNOUNCE_NUM) {
-               eloop_timeout_add_sec(ifp->ctx->eloop,
-                   ANNOUNCE_WAIT, arp_announce, ifp);
-               return;
+       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;
+       struct timeval tv;
+
+       if (++astate->probes < PROBE_NUM) {
+               tv.tv_sec = PROBE_MIN;
+               tv.tv_usec = (suseconds_t)arc4random_uniform(
+                   (PROBE_MAX - PROBE_MIN) * 1000000);
+               timernorm(&tv);
+               eloop_timeout_add_tv(ifp->ctx->eloop, &tv, arp_probe1, astate);
+       } else {
+               tv.tv_sec = ANNOUNCE_WAIT;
+               tv.tv_usec = 0;
+               eloop_timeout_add_tv(ifp->ctx->eloop, &tv, arp_probed, astate);
        }
-       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;
-               tv.tv_usec = (suseconds_t)arc4random_uniform(
-                   (DHCP_RAND_MAX - DHCP_RAND_MIN) * 1000000);
-               timernorm(&tv);
-               eloop_timeout_add_tv(ifp->ctx->eloop, &tv, dhcp_discover, ifp);
-       } else {
-               eloop_event_delete(ifp->ctx->eloop, state->arp_fd, 0);
-               close(state->arp_fd);
-               state->arp_fd = -1;
+       syslog(LOG_DEBUG,
+           "%s: sending ARP probe (%d of %d), next in %0.1f seconds",
+           ifp->name, astate->probes ? astate->probes : PROBE_NUM, PROBE_NUM,
+           timeval_to_double(&tv));
+       if (arp_send(ifp, ARPOP_REQUEST, 0, astate->addr.s_addr) == -1)
+               syslog(LOG_ERR, "send_arp: %m");
+}
+



Home | Main Index | Thread Index | Old Index