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-5.6.2 with the follow...



details:   https://anonhg.NetBSD.org/src/rev/f3c3ad08b148
branches:  trunk
changeset: 781383:f3c3ad08b148
user:      roy <roy%NetBSD.org@localhost>
date:      Mon Sep 03 09:46:12 2012 +0000

description:
Import dhcpcd-5.6.2 with the following changes:
Disable kernel RA earlier on Linux
* Don't set if_up or if_down as true when testing
* ra%d_prefix is now a space separated array of the finished address/len
* If we fail to open sockets, don't bother sending the request
* Send our NS solicitation directly to the router
* Change the NS times so that we assume reachable until the reachable time
  expires, then send probes at retrans intervals until
  DELAY_FIRST_PROBE_TIME is reached at which point we expire the router
* Remove -v from --version in usage
* Only add our own host or destination routes to the build table when we
  are adding gateways
* Ensure we have correct memory allocation for each prefix in the RA

diffstat:

 external/bsd/dhcpcd/dist/common.h    |   5 ++
 external/bsd/dhcpcd/dist/configure.c |  11 ++++-
 external/bsd/dhcpcd/dist/defs.h      |   2 +-
 external/bsd/dhcpcd/dist/dhcpcd.c    |  33 +++++++++++-----
 external/bsd/dhcpcd/dist/dhcpcd.h    |   2 +-
 external/bsd/dhcpcd/dist/ipv6.c      |  14 ++++++-
 external/bsd/dhcpcd/dist/ipv6ns.c    |  69 ++++++++++++++++++++--------------
 external/bsd/dhcpcd/dist/ipv6ns.h    |   2 +-
 external/bsd/dhcpcd/dist/ipv6rs.c    |  71 ++++++++++++++---------------------
 external/bsd/dhcpcd/dist/ipv6rs.h    |   2 +
 10 files changed, 122 insertions(+), 89 deletions(-)

diffs (truncated from 501 to 300 lines):

diff -r 4cc22a3caff6 -r f3c3ad08b148 external/bsd/dhcpcd/dist/common.h
--- a/external/bsd/dhcpcd/dist/common.h Mon Sep 03 05:01:44 2012 +0000
+++ b/external/bsd/dhcpcd/dist/common.h Mon Sep 03 09:46:12 2012 +0000
@@ -37,6 +37,11 @@
 #define UNCONST(a)             ((void *)(unsigned long)(const void *)(a))
 
 #define timeval_to_double(tv) ((tv)->tv_sec * 1.0 + (tv)->tv_usec * 1.0e-6)
+#define ms_to_tv(tv, ms)                                               \
+       do {                                                            \
+               (tv)->tv_sec = (ms / 1000);                             \
+               (tv)->tv_usec = ((ms % 1000) * 1000);                   \
+       } while (0 /* CONSTCOND */);
 #define timernorm(tvp)                                                 \
        do {                                                            \
                while ((tvp)->tv_usec >= 1000000) {                     \
diff -r 4cc22a3caff6 -r f3c3ad08b148 external/bsd/dhcpcd/dist/configure.c
--- a/external/bsd/dhcpcd/dist/configure.c      Mon Sep 03 05:01:44 2012 +0000
+++ b/external/bsd/dhcpcd/dist/configure.c      Mon Sep 03 09:46:12 2012 +0000
@@ -216,7 +216,10 @@
                e--;
        }
        *--p = '\0';
-       if ((dhcp && iface->state->new) || (ra && ipv6rs_has_ra(iface))) {
+       if (strcmp(reason, "TEST") == 0) {
+               env[8] = strdup("if_up=false");
+               env[9] = strdup("if_down=false");
+       } else if ((dhcp && iface->state->new) || (ra && ipv6rs_has_ra(iface))){
                env[8] = strdup("if_up=true");
                env[9] = strdup("if_down=false");
        } else {
@@ -692,8 +695,10 @@
                dnr = get_routes(ifp);
                dnr = massage_host_routes(dnr, ifp);
                dnr = add_subnet_route(dnr, ifp);
-               dnr = add_router_host_route(dnr, ifp);
-               dnr = add_destination_route(dnr, ifp);
+               if (ifp->state->options->options & DHCPCD_GATEWAY) {
+                       dnr = add_router_host_route(dnr, ifp);
+                       dnr = add_destination_route(dnr, ifp);
+               }
                for (rt = dnr; rt && (rtn = rt->next, 1); lrt = rt, rt = rtn) {
                        rt->iface = ifp;
                        rt->metric = ifp->metric;
diff -r 4cc22a3caff6 -r f3c3ad08b148 external/bsd/dhcpcd/dist/defs.h
--- a/external/bsd/dhcpcd/dist/defs.h   Mon Sep 03 05:01:44 2012 +0000
+++ b/external/bsd/dhcpcd/dist/defs.h   Mon Sep 03 09:46:12 2012 +0000
@@ -28,7 +28,7 @@
 #define CONFIG_H
 
 #define PACKAGE                        "dhcpcd"
-#define VERSION                        "5.6.1"
+#define VERSION                        "5.6.2"
 
 #ifndef CONFIG
 # define CONFIG                        SYSCONFDIR "/" PACKAGE ".conf"
diff -r 4cc22a3caff6 -r f3c3ad08b148 external/bsd/dhcpcd/dist/dhcpcd.c
--- a/external/bsd/dhcpcd/dist/dhcpcd.c Mon Sep 03 05:01:44 2012 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd.c Mon Sep 03 09:46:12 2012 +0000
@@ -163,7 +163,7 @@
        "\t\t[-z, --allowinterfaces pattern] [interface] [...]\n"
        "       "PACKAGE"\t-k, --release [interface]\n"
        "       "PACKAGE"\t-U, --dumplease interface\n"
-       "       "PACKAGE"\t-v, --version\n"
+       "       "PACKAGE"\t--version\n"
        "       "PACKAGE"\t-x, --exit [interface]\n");
 }
 
@@ -326,7 +326,11 @@
        }
 
        /* Ensure sockets are open. */
-       open_sockets(iface);
+       if (open_sockets(iface) == -1) {
+               if (!(options & DHCPCD_TEST))
+                       drop_dhcp(iface, "FAIL");
+               return;
+       }
 
        /* If we couldn't open a UDP port for our IP address
         * then we cannot renew.
@@ -785,6 +789,12 @@
        if (ifo->metric != -1)
                iface->metric = ifo->metric;
 
+       /* We want to disable kernel interface RA as early as possible. */
+       if (options & DHCPCD_IPV6RS && ifo->options & DHCPCD_IPV6RS) {
+               if (check_ipv6(iface->name) != 1)
+                       ifo->options &= ~DHCPCD_IPV6RS;
+       }
+
        /* If we haven't specified a ClientID and our hardware address
         * length is greater than DHCP_CHADDR_LEN then we enforce a ClientID
         * of the hardware address family and the hardware address. */
@@ -1167,12 +1177,8 @@
        free(iface->state->offer);
        iface->state->offer = NULL;
 
-       if (options & DHCPCD_IPV6RS && ifo->options & DHCPCD_IPV6RS) {
-               if (check_ipv6(iface->name) == 1)
-                       ipv6rs_start(iface);
-               else
-                       ifo->options &= ~DHCPCD_IPV6RS;
-       }
+       if (options & DHCPCD_IPV6RS && ifo->options & DHCPCD_IPV6RS)
+               ipv6rs_start(iface);
 
        if (iface->state->arping_index < ifo->arping_len) {
                start_arping(iface);
@@ -1708,11 +1714,13 @@
        return 0;
 }
 
-void
+int
 open_sockets(struct interface *iface)
 {
+       int r = 0;
+
        if (iface->raw_fd == -1) {
-               if (open_socket(iface, ETHERTYPE_IP) == -1)
+               if ((r = open_socket(iface, ETHERTYPE_IP)) == -1)
                        syslog(LOG_ERR, "%s: open_socket: %m", iface->name);
                else
                        add_event(iface->raw_fd, handle_dhcp_packet, iface);
@@ -1723,9 +1731,12 @@
            (iface->state->new->cookie == htonl(MAGIC_COOKIE) ||
            iface->state->options->options & DHCPCD_INFORM))
        {
-               if (open_udp_socket(iface) == -1 && errno != EADDRINUSE)
+               if (open_udp_socket(iface) == -1 && errno != EADDRINUSE) {
                        syslog(LOG_ERR, "%s: open_udp_socket: %m", iface->name);
+                       r = -1;
+               }
        }
+       return r;
 }
 
 void
diff -r 4cc22a3caff6 -r f3c3ad08b148 external/bsd/dhcpcd/dist/dhcpcd.h
--- a/external/bsd/dhcpcd/dist/dhcpcd.h Mon Sep 03 05:01:44 2012 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd.h Mon Sep 03 09:46:12 2012 +0000
@@ -141,7 +141,7 @@
 void start_reboot(struct interface *);
 void start_expire(void *);
 void send_decline(struct interface *);
-void open_sockets(struct interface *);
+int open_sockets(struct interface *);
 void close_sockets(struct interface *);
 void drop_dhcp(struct interface *, const char *);
 void drop_interface(struct interface *, const char *);
diff -r 4cc22a3caff6 -r f3c3ad08b148 external/bsd/dhcpcd/dist/ipv6.c
--- a/external/bsd/dhcpcd/dist/ipv6.c   Mon Sep 03 05:01:44 2012 +0000
+++ b/external/bsd/dhcpcd/dist/ipv6.c   Mon Sep 03 09:46:12 2012 +0000
@@ -327,6 +327,9 @@
 ipv6_remove_subnet(struct ra *rap, struct ipv6_addr *addr)
 {
        struct rt6 *rt;
+#if HAVE_ROUTE_METRIC
+       struct rt6 *ort;
+#endif
        int r;
 
        /* We need to delete the subnet route to have our metric or
@@ -340,7 +343,15 @@
 #else
                rt->metric = 0;
 #endif
+#if HAVE_ROUTE_METRIC
+               /* For some reason, Linux likes to re-add the subnet
+                  route under the original metric.
+                  I would love to find a way of stopping this! */
+               if ((ort = find_route6(routes, rt)) == NULL ||
+                   ort->metric != rt->metric)
+#else
                if (!find_route6(routes, rt))
+#endif
                        r = del_route6(rt);
                free(rt);
        }
@@ -367,12 +378,13 @@
        TAILQ_FOREACH(rap, &ipv6_routers, next) {
                if (rap->expired)
                        continue;
-               if (options & DHCPCD_IPV6RA_OWN)
+               if (options & DHCPCD_IPV6RA_OWN) {
                        TAILQ_FOREACH(addr, &rap->addrs, next) {
                                rt = make_prefix(rap, addr);
                                if (rt)
                                        TAILQ_INSERT_TAIL(&dnr, rt, next);
                        }
+               }
                rt = make_router(rap);
                if (rt)
                        TAILQ_INSERT_TAIL(&dnr, rt, next);
diff -r 4cc22a3caff6 -r f3c3ad08b148 external/bsd/dhcpcd/dist/ipv6ns.c
--- a/external/bsd/dhcpcd/dist/ipv6ns.c Mon Sep 03 05:01:44 2012 +0000
+++ b/external/bsd/dhcpcd/dist/ipv6ns.c Mon Sep 03 09:46:12 2012 +0000
@@ -60,7 +60,7 @@
 //#define DEBUG_NS
 
 static int sock;
-static struct sockaddr_in6 allrouters, from;
+static struct sockaddr_in6 from;
 static struct msghdr sndhdr;
 static struct iovec sndiov[2];
 static unsigned char *sndbuf;
@@ -87,13 +87,6 @@
        int len;
        struct icmp6_filter filt;
 
-       memset(&allrouters, 0, sizeof(allrouters));
-       allrouters.sin6_family = AF_INET6;
-#ifdef SIN6_LEN
-       allrouters.sin6_len = sizeof(allrouters);
-#endif
-       if (inet_pton(AF_INET6, ALLROUTERS, &allrouters.sin6_addr.s6_addr) != 1)
-               return -1;
        sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
        if (sock == -1)
                return -1;
@@ -165,6 +158,20 @@
        return 0;
 }
 
+static void
+ipv6ns_unreachable(void *arg)
+{
+       struct ra *rap = arg;
+
+       /* We could add an unreachable flag and persist the information,
+        * but that is more effort than it's probably worth. */
+       syslog(LOG_WARNING, "%s: %s is unreachable, expiring it",
+           rap->iface->name, rap->sfrom);
+       rap->expired = 1;
+       ipv6_build_routes();
+       run_script_reason(rap->iface, "ROUTERADVERT"); /* XXX not RA */
+}
+
 void
 ipv6ns_sendprobe(void *arg)
 {
@@ -175,13 +182,18 @@
        int hoplimit = HOPLIMIT;
        struct timeval tv, rtv;
 
-       if (!rap->nsprobes) {
+       if (!rap->ns) {
                if (ipv6ns_makeprobe(rap) == -1)
                        return;
        }
 
-       dst = allrouters;
-       //dst.sin6_scope_id = ifp->linkid;
+       memset(&dst, 0, sizeof(dst));
+       dst.sin6_family = AF_INET6;
+#ifdef SIN6_LEN
+       dst.sin6_len = sizeof(dst);
+#endif
+       memcpy(&dst.sin6_addr, &rap->from, sizeof(dst.sin6_addr));
+       //dst.sin6_scope_id = rap->iface->index;
 
        sndhdr.msg_name = (caddr_t)&dst;
        sndhdr.msg_iov[0].iov_base = rap->ns;
@@ -210,26 +222,18 @@
        if (sendmsg(sock, &sndhdr, 0) == -1)
                syslog(LOG_ERR, "%s: sendmsg: %m", rap->iface->name);
 
-       tv.tv_sec = RETRANS_TIMER;
-       tv.tv_usec = MIN_RANDOM_FACTOR;
+
+       ms_to_tv(&tv, rap->retrans ? rap->retrans : RETRANS_TIMER);
+       ms_to_tv(&rtv, MIN_RANDOM_FACTOR);
+       timeradd(&tv, &rtv, &tv);
        rtv.tv_sec = 0;
        rtv.tv_usec = arc4random() % (MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR);
        timeradd(&tv, &rtv, &tv);
        add_timeout_tv(&tv, ipv6ns_sendprobe, rap);
-}
 
-void
-ipv6ns_unreachable(void *arg)
-{
-       struct ra *rap = arg;
-
-       /* We could add an unreachable flag and persist the information,
-        * but that is more effort than it's probably worth. */
-       syslog(LOG_WARNING, "%s: %s is unreachable, expiring it",
-           rap->iface->name, rap->sfrom);
-       rap->expired = 1;
-       ipv6_build_routes();
-       run_script_reason(rap->iface, "ROUTERADVERT"); /* XXX not RA */
+       if (rap->nsprobes++ == 0)
+               add_timeout_sec(DELAY_FIRST_PROBE_TIME,
+                   ipv6ns_unreachable, rap);
 }
 
 /* ARGSUSED */
@@ -246,6 +250,7 @@
        struct nd_neighbor_advert *nd_na;
        struct ra *rap;



Home | Main Index | Thread Index | Old Index