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



details:   https://anonhg.NetBSD.org/src/rev/744f2224c762
branches:  trunk
changeset: 755399:744f2224c762
user:      roy <roy%NetBSD.org@localhost>
date:      Fri Jun 04 09:07:59 2010 +0000

description:
Import dhcpcd-5.2.4 with the following changes:
* Fix crash when using clientid and the interface re-configures
* log the pid of dhcpcd
* Indicate server IP received message from even if server ID not
  present
* Fix crashes on IPv4LL failure and add more logging

diffstat:

 external/bsd/dhcpcd/dist/arp.c        |   10 +-
 external/bsd/dhcpcd/dist/bind.c       |    5 +-
 external/bsd/dhcpcd/dist/configure.c  |   55 ++++++++++-
 external/bsd/dhcpcd/dist/defs.h       |    2 +-
 external/bsd/dhcpcd/dist/dhcpcd.c     |  181 +++++++++++++++++----------------
 external/bsd/dhcpcd/dist/dhcpcd.h     |    4 +-
 external/bsd/dhcpcd/dist/if-bsd.c     |    2 +-
 external/bsd/dhcpcd/dist/if-options.c |   23 ++--
 external/bsd/dhcpcd/dist/if-options.h |    2 +-
 external/bsd/dhcpcd/dist/if-pref.c    |    2 +-
 external/bsd/dhcpcd/dist/ipv4ll.c     |    8 +-
 external/bsd/dhcpcd/dist/net.c        |    2 +-
 external/bsd/dhcpcd/dist/net.h        |    2 +-
 13 files changed, 185 insertions(+), 113 deletions(-)

diffs (truncated from 720 to 300 lines):

diff -r 21f39cac89a0 -r 744f2224c762 external/bsd/dhcpcd/dist/arp.c
--- a/external/bsd/dhcpcd/dist/arp.c    Fri Jun 04 08:40:24 2010 +0000
+++ b/external/bsd/dhcpcd/dist/arp.c    Fri Jun 04 09:07:59 2010 +0000
@@ -78,10 +78,18 @@
 static void
 handle_arp_failure(struct interface *iface)
 {
-       if (iface->state->offer->cookie != htonl(MAGIC_COOKIE)) {
+
+       /* 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)))
+       {
                handle_ipv4ll_failure(iface);
                return;
        }
+
        unlink(iface->leasefile);
        if (!iface->state->lease.frominfo)
                send_decline(iface);
diff -r 21f39cac89a0 -r 744f2224c762 external/bsd/dhcpcd/dist/bind.c
--- a/external/bsd/dhcpcd/dist/bind.c   Fri Jun 04 08:40:24 2010 +0000
+++ b/external/bsd/dhcpcd/dist/bind.c   Fri Jun 04 09:07:59 2010 +0000
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2009 Roy Marples <roy%marples.name@localhost>
+ * Copyright (c) 2006-2010 Roy Marples <roy%marples.name@localhost>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -73,7 +73,7 @@
                syslog(LOG_ERR, "pipe: %m");
                return -1;
        }
-       syslog(LOG_INFO, "forking to background");
+       syslog(LOG_DEBUG, "forking to background");
        switch (pid = fork()) {
        case -1:
                syslog(LOG_ERR, "fork: %m");
@@ -105,6 +105,7 @@
        }
        /* Done with the fd now */
        if (pid != 0) {
+               syslog(LOG_INFO, "forked to background, child pid %d",pid);
                writepid(pidfd, pid);
                close(pidfd);
                pidfd = -1;
diff -r 21f39cac89a0 -r 744f2224c762 external/bsd/dhcpcd/dist/configure.c
--- a/external/bsd/dhcpcd/dist/configure.c      Fri Jun 04 08:40:24 2010 +0000
+++ b/external/bsd/dhcpcd/dist/configure.c      Fri Jun 04 09:07:59 2010 +0000
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2009 Roy Marples <roy%marples.name@localhost>
+ * Copyright (c) 2006-2010 Roy Marples <roy%marples.name@localhost>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -567,6 +567,58 @@
        return r;
 }
 
+/* We should check to ensure the routers are on the same subnet
+ * OR supply a host route. If not, warn and add a host route. */
+static struct rt *
+add_router_host_route(struct rt *rt, const struct interface *ifp)
+{
+       struct rt *rtp, *rtl, *rtn;
+       const char *cp, *cp2, *cp3, *cplim;
+
+       for (rtp = rt, rtl = NULL; rtp; rtl = rtp, rtp = rtp->next) {
+               if (rtp->dest.s_addr != INADDR_ANY)
+                       continue;
+               /* Scan for a route to match */
+               for (rtn = rt; rtn != rtp; rtn = rtn->next) {
+                       /* match host */
+                       if (rtn->dest.s_addr == rtp->gate.s_addr)
+                               break;
+                       /* match subnet */
+                       cp = (const char *)&rtp->gate.s_addr;
+                       cp2 = (const char *)&rtn->dest.s_addr;
+                       cp3 = (const char *)&rtn->net.s_addr;
+                       cplim = cp3 + sizeof(rtn->net.s_addr);
+                       while (cp3 < cplim) {
+                               if ((*cp++ ^ *cp2++) & *cp3++)
+                                       break;
+                       }
+                       if (cp3 == cplim)
+                               break;
+               }
+               if (rtn != rtp)
+                       continue;
+               if (ifp->flags & IFF_NOARP) {
+                       syslog(LOG_WARNING,
+                           "%s: forcing router %s through interface",
+                           ifp->name, inet_ntoa(rtp->gate));
+                       rtp->gate.s_addr = 0;
+                       continue;
+               }
+               syslog(LOG_WARNING, "%s: router %s requires a host route",
+                   ifp->name, inet_ntoa(rtp->gate));
+               rtn = xmalloc(sizeof(*rtn));
+               rtn->dest.s_addr = rtp->gate.s_addr;
+               rtn->net.s_addr = INADDR_BROADCAST;
+               rtn->gate.s_addr = rtp->gate.s_addr;
+               rtn->next = rtp;
+               if (rtl == NULL)
+                       rt = rtn;
+               else
+                       rtl->next = rtn;
+       }
+       return rt;
+}
+
 void
 build_routes(void)
 {
@@ -578,6 +630,7 @@
                        continue;
                dnr = get_routes(ifp);
                dnr = add_subnet_route(dnr, ifp);
+               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;
diff -r 21f39cac89a0 -r 744f2224c762 external/bsd/dhcpcd/dist/defs.h
--- a/external/bsd/dhcpcd/dist/defs.h   Fri Jun 04 08:40:24 2010 +0000
+++ b/external/bsd/dhcpcd/dist/defs.h   Fri Jun 04 09:07:59 2010 +0000
@@ -28,7 +28,7 @@
 #define CONFIG_H
 
 #define PACKAGE                        "dhcpcd"
-#define VERSION                        "5.2.2"
+#define VERSION                        "5.2.4"
 
 #ifndef CONFIG
 # define CONFIG                        SYSCONFDIR "/" PACKAGE ".conf"
diff -r 21f39cac89a0 -r 744f2224c762 external/bsd/dhcpcd/dist/dhcpcd.c
--- a/external/bsd/dhcpcd/dist/dhcpcd.c Fri Jun 04 08:40:24 2010 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd.c Fri Jun 04 09:07:59 2010 +0000
@@ -100,14 +100,14 @@
 };
 
 static const struct dhcp_op dhcp_ops[] = {
-       { DHCP_DISCOVER, "DHCP_DISCOVER" },
-       { DHCP_OFFER,    "DHCP_OFFER" },
-       { DHCP_REQUEST,  "DHCP_REQUEST" },
-       { DHCP_DECLINE,  "DHCP_DECLINE" },
-       { DHCP_ACK,      "DHCP_ACK" },
-       { DHCP_NAK,      "DHCP_NAK" },
-       { DHCP_RELEASE,  "DHCP_RELEASE" },
-       { DHCP_INFORM,   "DHCP_INFORM" },
+       { DHCP_DISCOVER, "DISCOVER" },
+       { DHCP_OFFER,    "OFFER" },
+       { DHCP_REQUEST,  "REQUEST" },
+       { DHCP_DECLINE,  "DECLINE" },
+       { DHCP_ACK,      "ACK" },
+       { DHCP_NAK,      "NAK" },
+       { DHCP_RELEASE,  "RELEASE" },
+       { DHCP_INFORM,   "INFORM" },
        { 0, NULL }
 };
 
@@ -218,26 +218,6 @@
        iface->state->lease.addr.s_addr = 0;
 }
 
-void
-close_sockets(struct interface *iface)
-{
-       if (iface->arp_fd != -1) {
-               delete_event(iface->arp_fd);
-               close(iface->arp_fd);
-               iface->arp_fd = -1;
-       }
-       if (iface->raw_fd != -1) {
-               delete_event(iface->raw_fd);
-               close(iface->raw_fd);
-               iface->raw_fd = -1;
-       }
-       if (iface->udp_fd != -1) {
-               /* we don't listen to events on the udp */
-               close(iface->udp_fd);
-               iface->udp_fd = -1;
-       }
-}
-
 struct interface *
 find_interface(const char *ifname)
 {
@@ -320,6 +300,10 @@
                    iface->name, get_dhcp_op(type), state->xid,
                    timeval_to_double(&tv));
        }
+
+       /* Ensure sockets are open. */
+       open_sockets(iface);
+
        /* If we couldn't open a UDP port for our IP address
         * then we cannot renew.
         * This could happen if our IP was pulled out from underneath us.
@@ -340,8 +324,10 @@
                to.s_addr = 0;
        if (to.s_addr && to.s_addr != INADDR_BROADCAST) {
                r = send_packet(iface, to, (uint8_t *)dhcp, len);
-               if (r == -1)
+               if (r == -1) {
                        syslog(LOG_ERR, "%s: send_packet: %m", iface->name);
+                       close_sockets(iface);
+               }
        } else {
                len = make_udp_packet(&udp, (uint8_t *)dhcp, len, from, to);
                r = send_raw_packet(iface, ETHERTYPE_IP, udp, len);
@@ -361,6 +347,7 @@
                }
        }
        free(dhcp);
+
        /* Even if we fail to send a packet we should continue as we are
         * as our failure timeouts will change out codepath when needed. */
        if (callback)
@@ -420,8 +407,10 @@
 
 static void
 log_dhcp(int lvl, const char *msg,
-    const struct interface *iface, const struct dhcp_message *dhcp)
+    const struct interface *iface, const struct dhcp_message *dhcp,
+    const struct in_addr *from)
 {
+       const char *tfrom;
        char *a;
        struct in_addr addr;
        int r;
@@ -433,21 +422,24 @@
                a = xstrdup(inet_ntoa(addr));
        } else
                a = NULL;
+
+       tfrom = "from";
        r = get_option_addr(&addr, dhcp, DHO_SERVERID);
        if (dhcp->servername[0] && r == 0)
-               syslog(lvl, "%s: %s %s from %s `%s'", iface->name, msg, a,
-                   inet_ntoa(addr), dhcp->servername);
-       else if (r == 0) {
+               syslog(lvl, "%s: %s %s %s %s `%s'", iface->name, msg, a,
+                   tfrom, inet_ntoa(addr), dhcp->servername);
+       else {
+               if (r != 0) {
+                       tfrom = "via";
+                       addr = *from;
+               }
                if (a == NULL)
-                       syslog(lvl, "%s: %s from %s",
-                           iface->name, msg, inet_ntoa(addr));
+                       syslog(lvl, "%s: %s %s %s",
+                           iface->name, msg, tfrom, inet_ntoa(addr));
                else
-                       syslog(lvl, "%s: %s %s from %s",
-                           iface->name, msg, a, inet_ntoa(addr));
-       } else if (a != NULL)
-               syslog(lvl, "%s: %s %s", iface->name, msg, a);
-       else
-               syslog(lvl, "%s: %s", iface->name, msg);
+                       syslog(lvl, "%s: %s %s %s %s",
+                           iface->name, msg, a, tfrom, inet_ntoa(addr));
+       }
        free(a);
 }
 
@@ -476,7 +468,7 @@
 }
 
 static void
-handle_dhcp(struct interface *iface, struct dhcp_message **dhcpp)
+handle_dhcp(struct interface *iface, struct dhcp_message **dhcpp, const struct in_addr *from)
 {
        struct if_state *state = iface->state;
        struct if_options *ifo = state->options;
@@ -498,20 +490,16 @@
                if (has_option_mask(ifo->requiremask, DHO_SERVERID) &&
                    get_option_addr(&addr, dhcp, DHO_SERVERID) == -1)
                {
-                       log_dhcp(LOG_WARNING, "reject NAK", iface, dhcp);
+                       log_dhcp(LOG_WARNING, "reject NAK", iface, dhcp, from);
                        return;
                }
                /* We should restart on a NAK */
-               log_dhcp(LOG_WARNING, "NAK:", iface, dhcp);
+               log_dhcp(LOG_WARNING, "NAK:", iface, dhcp, from);
                if (!(options & DHCPCD_TEST)) {
                        drop_config(iface, "NAK");
                        unlink(iface->leasefile);
                }
-               delete_event(iface->raw_fd);
-               close(iface->raw_fd);
-               iface->raw_fd = -1;



Home | Main Index | Thread Index | Old Index