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 Import dhcpcd-6.0.0 with the follow...



details:   https://anonhg.NetBSD.org/src/rev/70aea25b8770
branches:  trunk
changeset: 787514:70aea25b8770
user:      roy <roy%NetBSD.org@localhost>
date:      Fri Jun 21 19:33:06 2013 +0000

description:
Import dhcpcd-6.0.0 with the following changes:
 * DHCPv6 support
 * wpa_supplicant hook script
 * route IPv4 addresses to 127.0.0.1 for machine centric traffic
 * DHCPv6 Prefix Delegation support
 * DHCPv6 FQDN support
 * Control existing IPv4 routes
 * less spamy to syslog by default
 * IPv6 protocols now wait for a valid LL address before starting
 * IPv6 DAD support now listens to kernel for more accurate timings
 * IPv4 code split out more cleanly so dhcpcd can be compiled for
   IPv4, IPv6 or IPv4 AND IPv6
 * MTU is no longer requested by default
 * a DUID is now generated in /etc/dhcpcd.duid and this is used as a
   client ID for DHCPv4 and DHCPv6
   This does mean that you may get new DHCPv4 addresses

Many bugs have also been fixed along the way and this release addresses
the following PR's

PR bin/47364
PR bin/47502
PR bin/47666
PR bin/47699
PR bin/47775
PR bin/47776

diffstat:

 external/bsd/dhcpcd/dist/arp.c                           |   208 +-
 external/bsd/dhcpcd/dist/arp.h                           |    15 +-
 external/bsd/dhcpcd/dist/bpf.c                           |    76 +-
 external/bsd/dhcpcd/dist/common.c                        |    81 +-
 external/bsd/dhcpcd/dist/common.h                        |    72 +-
 external/bsd/dhcpcd/dist/config.h                        |     2 +
 external/bsd/dhcpcd/dist/control.c                       |    87 +-
 external/bsd/dhcpcd/dist/control.h                       |    16 +-
 external/bsd/dhcpcd/dist/defs.h                          |     9 +-
 external/bsd/dhcpcd/dist/dhcp-common.c                   |   459 ++
 external/bsd/dhcpcd/dist/dhcp-common.h                   |    79 +
 external/bsd/dhcpcd/dist/dhcp.h                          |   131 +-
 external/bsd/dhcpcd/dist/dhcp6.c                         |  2588 ++++++++++++++
 external/bsd/dhcpcd/dist/dhcp6.h                         |   240 +
 external/bsd/dhcpcd/dist/dhcpcd-hooks/01-test            |     2 +
 external/bsd/dhcpcd/dist/dhcpcd-hooks/02-dump            |     2 +
 external/bsd/dhcpcd/dist/dhcpcd-hooks/10-mtu             |     6 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/10-wpa_supplicant  |    68 +
 external/bsd/dhcpcd/dist/dhcpcd-hooks/15-timezone        |    53 +
 external/bsd/dhcpcd/dist/dhcpcd-hooks/20-resolv.conf     |    10 +
 external/bsd/dhcpcd/dist/dhcpcd-hooks/29-lookup-hostname |     2 +
 external/bsd/dhcpcd/dist/dhcpcd-hooks/30-hostname        |    43 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ntp.conf        |     9 +
 external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ypbind          |     2 +
 external/bsd/dhcpcd/dist/dhcpcd-run-hooks.in             |    16 +-
 external/bsd/dhcpcd/dist/dhcpcd.c                        |  1836 ++-------
 external/bsd/dhcpcd/dist/dhcpcd.conf.5.in                |    90 +-
 external/bsd/dhcpcd/dist/dhcpcd.h                        |   107 +-
 external/bsd/dhcpcd/dist/duid.c                          |    47 +-
 external/bsd/dhcpcd/dist/duid.h                          |     4 +-
 external/bsd/dhcpcd/dist/eloop.c                         |   363 +-
 external/bsd/dhcpcd/dist/eloop.h                         |    35 +-
 external/bsd/dhcpcd/dist/if-bsd.c                        |   239 +-
 external/bsd/dhcpcd/dist/if-options.c                    |   543 ++-
 external/bsd/dhcpcd/dist/if-options.h                    |    45 +-
 external/bsd/dhcpcd/dist/if-pref.c                       |    70 +-
 external/bsd/dhcpcd/dist/if-pref.h                       |     4 +-
 external/bsd/dhcpcd/dist/ipv4.c                          |   728 +++
 external/bsd/dhcpcd/dist/ipv4.h                          |    92 +
 external/bsd/dhcpcd/dist/ipv4ll.c                        |    95 +-
 external/bsd/dhcpcd/dist/ipv4ll.h                        |    11 +-
 external/bsd/dhcpcd/dist/ipv6.c                          |   788 +++-
 external/bsd/dhcpcd/dist/ipv6.h                          |   134 +-
 external/bsd/dhcpcd/dist/ipv6ns.c                        |   458 ++-
 external/bsd/dhcpcd/dist/ipv6ns.h                        |    23 +-
 external/bsd/dhcpcd/dist/ipv6rs.c                        |   618 ++-
 external/bsd/dhcpcd/dist/ipv6rs.h                        |    23 +-
 external/bsd/dhcpcd/dist/net.c                           |   458 +--
 external/bsd/dhcpcd/dist/net.h                           |    74 +-
 external/bsd/dhcpcd/dist/platform-bsd.c                  |    76 +-
 external/bsd/dhcpcd/dist/platform.h                      |    11 +-
 external/bsd/dhcpcd/dist/script.c                        |   610 +++
 external/bsd/dhcpcd/dist/script.h                        |    39 +
 53 files changed, 8844 insertions(+), 3053 deletions(-)

diffs (truncated from 15479 to 300 lines):

diff -r e565a35da819 -r 70aea25b8770 external/bsd/dhcpcd/dist/arp.c
--- a/external/bsd/dhcpcd/dist/arp.c    Fri Jun 21 19:16:00 2013 +0000
+++ b/external/bsd/dhcpcd/dist/arp.c    Fri Jun 21 19:33:06 2013 +0000
@@ -1,6 +1,9 @@
-/* 
+#include <sys/cdefs.h>
+ __RCSID("$NetBSD: arp.c,v 1.1.1.9 2013/06/21 19:33:07 roy Exp $");
+
+/*
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2011 Roy Marples <roy%marples.name@localhost>
+ * Copyright (c) 2006-2013 Roy Marples <roy%marples.name@localhost>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -33,8 +36,9 @@
 #include <unistd.h>
 
 #include "arp.h"
-#include "bind.h"
+#include "ipv4.h"
 #include "common.h"
+#include "dhcp.h"
 #include "dhcpcd.h"
 #include "eloop.h"
 #include "if-options.h"
@@ -45,80 +49,92 @@
        (sizeof(struct arphdr) + (2 * sizeof(uint32_t)) + (2 * HWADDR_LEN))
 
 static int
-send_arp(const struct interface *iface, int op, in_addr_t sip, in_addr_t tip)
+arp_send(const struct interface *ifp, int op, in_addr_t sip, in_addr_t tip)
 {
        uint8_t arp_buffer[ARP_LEN];
        struct arphdr ar;
        size_t len;
        uint8_t *p;
-       int retval;
 
-       ar.ar_hrd = htons(iface->family);
+       ar.ar_hrd = htons(ifp->family);
        ar.ar_pro = htons(ETHERTYPE_IP);
-       ar.ar_hln = iface->hwlen;
+       ar.ar_hln = ifp->hwlen;
        ar.ar_pln = sizeof(sip);
        ar.ar_op = htons(op);
-       memcpy(arp_buffer, &ar, sizeof(ar));
-       p = arp_buffer + sizeof(ar);
-       memcpy(p, iface->hwaddr, iface->hwlen);
-       p += iface->hwlen;
-       memcpy(p, &sip, sizeof(sip));
-       p += sizeof(sip);
-       /* ARP requests should ignore this */
-       retval = iface->hwlen;
-       while (retval--)
-               *p++ = '\0';
-       memcpy(p, &tip, sizeof(tip));
-       p += sizeof(tip);
+
+       p = arp_buffer;
+       len = sizeof(arp_buffer);
+
+#define CHECK(fun, b, l)                                               \
+       do {                                                            \
+               if (len < (l))                                          \
+                       goto eexit;                                     \
+               fun(p, (b), (l));                                       \
+               p += (l);                                               \
+               len -= (l);                                             \
+       } while (/* CONSTCOND */ 0)
+#define APPEND(b, l)   CHECK(memcpy, b, l)
+#define ZERO(l)                CHECK(memset, 0, l)
+
+       APPEND(&ar, sizeof(ar));
+       APPEND(ifp->hwaddr, ifp->hwlen);
+       APPEND(&sip, sizeof(sip));
+       ZERO(ifp->hwlen);
+       APPEND(&tip, sizeof(tip));
        len = p - arp_buffer;
-       retval = send_raw_packet(iface, ETHERTYPE_ARP, arp_buffer, len);
-       return retval;
+       return ipv4_sendrawpacket(ifp, ETHERTYPE_ARP, arp_buffer, len);
+
+eexit:
+       errno = ENOBUFS;
+       return -1;
 }
 
 static void
-handle_arp_failure(struct interface *iface)
+arp_failure(struct interface *ifp)
 {
+       const struct dhcp_state *state = D_CSTATE(ifp);
 
        /* If we failed without a magic cookie then we need to try
         * and defend our IPv4LL address. */
-       if ((iface->state->offer != NULL &&
-               iface->state->offer->cookie != htonl(MAGIC_COOKIE)) ||
-           (iface->state->new != NULL &&
-               iface->state->new->cookie != htonl(MAGIC_COOKIE)))
+       if ((state->offer != NULL &&
+               state->offer->cookie != htonl(MAGIC_COOKIE)) ||
+           (state->new != NULL &&
+               state->new->cookie != htonl(MAGIC_COOKIE)))
        {
-               handle_ipv4ll_failure(iface);
+               ipv4ll_handle_failure(ifp);
                return;
        }
 
-       unlink(iface->leasefile);
-       if (!iface->state->lease.frominfo)
-               send_decline(iface);
-       close_sockets(iface);
-       delete_timeout(NULL, iface);
-       if (iface->state->lease.frominfo)
-               start_interface(iface);
+       unlink(state->leasefile);
+       if (!state->lease.frominfo)
+               dhcp_decline(ifp);
+       dhcp_close(ifp);
+       eloop_timeout_delete(NULL, ifp);
+       if (state->lease.frominfo)
+               start_interface(ifp);
        else
-               add_timeout_sec(DHCP_ARP_FAIL, start_interface, iface);
+               eloop_timeout_add_sec(DHCP_ARP_FAIL, start_interface, ifp);
 }
 
 static void
-handle_arp_packet(void *arg)
+arp_packet(void *arg)
 {
-       struct interface *iface = arg;
+       struct interface *ifp = arg;
        uint8_t arp_buffer[ARP_LEN];
        struct arphdr ar;
        uint32_t reply_s;
        uint32_t reply_t;
        uint8_t *hw_s, *hw_t;
        ssize_t bytes;
-       struct if_state *state = iface->state;
-       struct if_options *opts = state->options;
+       struct dhcp_state *state;
+       struct if_options *opts = ifp->options;
        const char *hwaddr;
        struct in_addr ina;
 
+       state = D_STATE(ifp);
        state->fail.s_addr = 0;
        for(;;) {
-               bytes = get_raw_packet(iface, ETHERTYPE_ARP,
+               bytes = ipv4_getrawpacket(ifp, ETHERTYPE_ARP,
                    arp_buffer, sizeof(arp_buffer), NULL);
                if (bytes == 0 || bytes == -1)
                        return;
@@ -143,8 +159,8 @@
                if ((hw_t + ar.ar_hln + ar.ar_pln) - arp_buffer > bytes)
                        continue;
                /* Ignore messages from ourself */
-               if (ar.ar_hln == iface->hwlen &&
-                   memcmp(hw_s, iface->hwaddr, iface->hwlen) == 0)
+               if (ar.ar_hln == ifp->hwlen &&
+                   memcmp(hw_s, ifp->hwaddr, ifp->hwlen) == 0)
                        continue;
                /* Copy out the IP addresses */
                memcpy(&reply_s, hw_s + ar.ar_hln, ar.ar_pln);
@@ -162,13 +178,13 @@
                            (size_t)ar.ar_hln);
                        syslog(LOG_INFO,
                            "%s: found %s on hardware address %s",
-                           iface->name, inet_ntoa(ina), hwaddr);
-                       if (select_profile(iface, hwaddr) == -1 &&
+                           ifp->name, inet_ntoa(ina), hwaddr);
+                       if (select_profile(ifp, hwaddr) == -1 &&
                            errno == ENOENT)
-                               select_profile(iface, inet_ntoa(ina));
-                       close_sockets(iface);
-                       delete_timeout(NULL, iface);
-                       start_interface(iface);
+                               select_profile(ifp, inet_ntoa(ina));
+                       dhcp_close(ifp);
+                       eloop_timeout_delete(NULL, ifp);
+                       start_interface(ifp);
                        return;
                }
 
@@ -179,51 +195,51 @@
                        state->fail.s_addr = state->offer->yiaddr;
 
                /* Handle IPv4LL conflicts */
-               if (IN_LINKLOCAL(htonl(iface->addr.s_addr)) &&
-                   (reply_s == iface->addr.s_addr ||
-                       (reply_s == 0 && reply_t == iface->addr.s_addr)))
-                       state->fail.s_addr = iface->addr.s_addr;
+               if (IN_LINKLOCAL(htonl(state->addr.s_addr)) &&
+                   (reply_s == state->addr.s_addr ||
+                       (reply_s == 0 && reply_t == 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",
-                           iface->name,
+                           ifp->name,
                            hwaddr_ntoa((unsigned char *)hw_s,
                                (size_t)ar.ar_hln),
                            inet_ntoa(state->fail));
                        errno = EEXIST;
-                       handle_arp_failure(iface);
+                       arp_failure(ifp);
                        return;
                }
        }
 }
 
 void
-send_arp_announce(void *arg)
+arp_announce(void *arg)
 {
-       struct interface *iface = arg;
-       struct if_state *state = iface->state;
+       struct interface *ifp = arg;
+       struct dhcp_state *state = D_STATE(ifp);
        struct timeval tv;
 
        if (state->new == NULL)
                return;
-       if (iface->arp_fd == -1) {
-               open_socket(iface, ETHERTYPE_ARP);
-               add_event(iface->arp_fd, handle_arp_packet, iface);
+       if (state->arp_fd == -1) {
+               ipv4_opensocket(ifp, ETHERTYPE_ARP);
+               eloop_event_add(state->arp_fd, arp_packet, ifp);
        }
-       if (++state->claims < ANNOUNCE_NUM)     
+       if (++state->claims < ANNOUNCE_NUM)
                syslog(LOG_DEBUG,
                    "%s: sending ARP announce (%d of %d), "
                    "next in %d.00 seconds",
-                   iface->name, state->claims, ANNOUNCE_NUM, ANNOUNCE_WAIT);
+                   ifp->name, state->claims, ANNOUNCE_NUM, ANNOUNCE_WAIT);
        else
                syslog(LOG_DEBUG,
                    "%s: sending ARP announce (%d of %d)",
-                   iface->name, state->claims, ANNOUNCE_NUM);
-       if (send_arp(iface, ARPOP_REQUEST,
+                   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) {
-               add_timeout_sec(ANNOUNCE_WAIT, send_arp_announce, iface);
+               eloop_timeout_add_sec(ANNOUNCE_WAIT, arp_announce, ifp);
                return;
        }
        if (state->new->cookie != htonl(MAGIC_COOKIE)) {
@@ -236,25 +252,31 @@
                tv.tv_sec = state->interval - DHCP_RAND_MIN;
                tv.tv_usec = arc4random() % (DHCP_RAND_MAX_U - DHCP_RAND_MIN_U);
                timernorm(&tv);
-               add_timeout_tv(&tv, start_discover, iface);
+               eloop_timeout_add_tv(&tv, dhcp_discover, ifp);
        } else {
-               delete_event(iface->arp_fd);
-               close(iface->arp_fd);
-               iface->arp_fd = -1;
+               eloop_event_delete(state->arp_fd);
+               close(state->arp_fd);
+               state->arp_fd = -1;
        }
 }
 
 void
-send_arp_probe(void *arg)
+arp_probe(void *arg)
 {
-       struct interface *iface = arg;
-       struct if_state *state = iface->state;
+       struct interface *ifp = arg;
+       struct dhcp_state *state = D_STATE(ifp);
        struct in_addr addr;
        struct timeval tv;
        int arping = 0;
 
-       if (state->arping_index < state->options->arping_len) {
-               addr.s_addr = state->options->arping[state->arping_index];
+       if (state->arp_fd == -1) {
+               if (ipv4_opensocket(ifp, ETHERTYPE_ARP) == -1)
+                       return;
+               eloop_event_add(state->arp_fd, arp_packet, ifp);
+       }
+
+       if (state->arping_index < ifp->options->arping_len) {
+               addr.s_addr = ifp->options->arping[state->arping_index];
                arping = 1;
        } else if (state->offer) {
                if (state->offer->yiaddr)
@@ -262,49 +284,47 @@
                else
                        addr.s_addr = state->offer->ciaddr;



Home | Main Index | Thread Index | Old Index