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.1.4



details:   https://anonhg.NetBSD.org/src/rev/a67f88653253
branches:  trunk
changeset: 750290:a67f88653253
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Dec 23 08:30:06 2009 +0000

description:
Import dhcpcd-5.1.4

Changes from dhcpcd-5.1.3 include:
 * dhcpcd logs even in quiet mode.
 * Sleep for 1/100th of a second to give time for kernel to send RELEASE.
 * -S option now works.
 * Only warn about using CSR on bind.

diffstat:

 external/bsd/dhcpcd/dist/bind.c                 |   1 +
 external/bsd/dhcpcd/dist/configure.c            |   3 +-
 external/bsd/dhcpcd/dist/defs.h                 |   2 +-
 external/bsd/dhcpcd/dist/dhcp.c                 |  29 ++++---
 external/bsd/dhcpcd/dist/dhcp.h                 |   2 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ypbind |  86 +++++++++++++++++++++++++
 external/bsd/dhcpcd/dist/dhcpcd.c               |  66 ++++++++++++++----
 external/bsd/dhcpcd/dist/if-options.h           |   4 +-
 external/bsd/dhcpcd/dist/net.c                  |  14 ++-
 9 files changed, 170 insertions(+), 37 deletions(-)

diffs (truncated from 384 to 300 lines):

diff -r bc43ed63f0b4 -r a67f88653253 external/bsd/dhcpcd/dist/bind.c
--- a/external/bsd/dhcpcd/dist/bind.c   Wed Dec 23 02:29:46 2009 +0000
+++ b/external/bsd/dhcpcd/dist/bind.c   Wed Dec 23 08:30:06 2009 +0000
@@ -222,6 +222,7 @@
                add_timeout_sec(lease->rebindtime, start_rebind, iface);
                add_timeout_sec(lease->leasetime, start_expire, iface);
        }
+       ifo->options &= ~ DHCPCD_CSR_WARNED;
        configure(iface);
        daemonise();
        state->state = DHS_BOUND;
diff -r bc43ed63f0b4 -r a67f88653253 external/bsd/dhcpcd/dist/configure.c
--- a/external/bsd/dhcpcd/dist/configure.c      Wed Dec 23 02:29:46 2009 +0000
+++ b/external/bsd/dhcpcd/dist/configure.c      Wed Dec 23 08:30:06 2009 +0000
@@ -547,7 +547,8 @@
                return nrt;
        }
 
-       return get_option_routes(iface->name, iface->state->new);
+       return get_option_routes(iface->state->new,
+           iface->name, &iface->state->options->options);
 }
 
 static struct rt *
diff -r bc43ed63f0b4 -r a67f88653253 external/bsd/dhcpcd/dist/defs.h
--- a/external/bsd/dhcpcd/dist/defs.h   Wed Dec 23 02:29:46 2009 +0000
+++ b/external/bsd/dhcpcd/dist/defs.h   Wed Dec 23 08:30:06 2009 +0000
@@ -28,7 +28,7 @@
 #define CONFIG_H
 
 #define PACKAGE                        "dhcpcd"
-#define VERSION                        "5.1.3"
+#define VERSION                        "5.1.4"
 
 #ifndef CONFIG
 # define CONFIG                        SYSCONFDIR "/" PACKAGE ".conf"
diff -r bc43ed63f0b4 -r a67f88653253 external/bsd/dhcpcd/dist/dhcp.c
--- a/external/bsd/dhcpcd/dist/dhcp.c   Wed Dec 23 02:29:46 2009 +0000
+++ b/external/bsd/dhcpcd/dist/dhcp.c   Wed Dec 23 08:30:06 2009 +0000
@@ -70,7 +70,7 @@
        { 1,    IPV4 | REQUEST, "subnet_mask" },
                /* RFC 3442 states that the CSR has to come before all other
                 * routes. For completeness, we also specify static routes,
-                * then routers. */
+                * then routers. */
        { 121,  RFC3442,        "classless_static_routes" },
        { 249,  RFC3442,        "ms_classless_static_routes" },
        { 33,   IPV4 | ARRAY | REQUEST, "static_routes" },
@@ -701,7 +701,8 @@
  * If we have a CSR then we only use that.
  * Otherwise we add static routes and then routers. */
 struct rt *
-get_option_routes(const char *ifname, const struct dhcp_message *dhcp)
+get_option_routes(const struct dhcp_message *dhcp,
+    const char *ifname, int *opts)
 {
        const uint8_t *p;
        const uint8_t *e;
@@ -716,9 +717,11 @@
                p = get_option(dhcp, DHO_MSCSR, &len, NULL);
        if (p) {
                routes = decode_rfc3442_rt(len, p);
-               if (routes) {
-                       syslog(LOG_DEBUG, "%s: using Classless Static Routes (RFC3442)",
-                              ifname);
+               if (routes && !(*opts & DHCPCD_CSR_WARNED)) {
+                       syslog(LOG_DEBUG,
+                           "%s: using Classless Static Routes (RFC3442)",
+                           ifname);
+                       *opts |= DHCPCD_CSR_WARNED;
                        return routes;
                }
        }
@@ -787,12 +790,12 @@
        return p - dst;
 }
 
-#define PUTADDR(_type, _val)                                           \
-       {                                                               \
-               *p++ = _type;                                           \
-               *p++ = 4;                                               \
-               memcpy(p, &_val.s_addr, 4);                             \
-               p += 4;                                                 \
+#define PUTADDR(_type, _val)                                                 \
+       {                                                                     \
+               *p++ = _type;                                                 \
+               *p++ = 4;                                                     \
+               memcpy(p, &_val.s_addr, 4);                                   \
+               p += 4;                                                       \
        }
 
 int
@@ -1137,7 +1140,7 @@
                case '\'': /* FALLTHROUGH */
                case '$':  /* FALLTHROUGH */
                case '`':  /* FALLTHROUGH */
-               case '\\': /* FALLTHROUGH */
+               case '\\':
                        if (s) {
                                if (len < 3) {
                                        errno = ENOBUFS;
@@ -1392,4 +1395,6 @@
                lease->renewaltime = 0;
        if (get_option_uint32(&lease->rebindtime, dhcp, DHO_REBINDTIME) != 0)
                lease->rebindtime = 0;
+       if (get_option_addr(&lease->server, dhcp, DHO_SERVERID) != 0)
+               lease->server.s_addr = INADDR_ANY;
 }
diff -r bc43ed63f0b4 -r a67f88653253 external/bsd/dhcpcd/dist/dhcp.h
--- a/external/bsd/dhcpcd/dist/dhcp.h   Wed Dec 23 02:29:46 2009 +0000
+++ b/external/bsd/dhcpcd/dist/dhcp.h   Wed Dec 23 08:30:06 2009 +0000
@@ -184,7 +184,7 @@
 #define is_bootp(m) (m &&                                              \
            !IN_LINKLOCAL(htonl((m)->yiaddr)) &&                        \
            get_option_uint8(NULL, m, DHO_MESSAGETYPE) == -1)
-struct rt *get_option_routes(const char *, const struct dhcp_message *);
+struct rt *get_option_routes(const struct dhcp_message *, const char *, int *);
 ssize_t configure_env(char **, const char *, const struct dhcp_message *,
     const struct if_options *);
 
diff -r bc43ed63f0b4 -r a67f88653253 external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ypbind
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ypbind   Wed Dec 23 08:30:06 2009 +0000
@@ -0,0 +1,86 @@
+# Sample dhcpcd hook for ypbind
+# This script is only suitable for the Linux version.
+
+# Distributions may want to just have their command here instead of this
+if [ -x /etc/rc.d/ypbind ]; then
+       ypbind_restart_cmd="/etc/rc.d/ypbind restart"
+       ypbind_stop_cmd="/etc/rc.d/ypbind stop"
+elif [ -x /usr/local/etc/rc.d/ypbind ]; then
+       ypbind_restart_cmd="/usr/local/etc/rc.d/ypbind restart"
+       ypbind_stop_cmd="/usr/local/etc/rc.d/ypbind stop"
+fi
+
+ypbind_dir="$state_dir/ypbind"
+
+best_domain()
+{
+       local i=
+
+       for i in $interfaces; do
+               if [ -e "$ypbind_dir/$i" ]; then
+                       cat "$ypbind_dir/$i"
+               fi
+       done
+       return 1
+}
+
+make_yp_binding()
+{
+       [ -d "$ypbind_dir" ] || mkdir -p "$ypbind_dir"
+       echo "$new_nis_domain" >"$ypbind_dir/$interface"
+       local nd="$(best_domain)"
+
+       local cf=/var/yp/binding/"$new_nis_domain".ypservers
+       if [ -n "$new_nis_servers" ]; then
+               local ncf="$cf.$interface" x=
+               rm -f "$ncf"
+               for x in $new_nis_servers; do
+                       echo "$x" >>"$ncf"
+               done
+               change_file "$cf" "$ncf"
+       else
+               # Because this is not an if .. fi then we can use $? below
+               [ -e "$cf" ] && rm "$cf"
+       fi
+
+       if [ $? = 0 -o "$nd" != "$(domainname)" ]; then
+               domainname "$nd"
+               if [ -n "$ypbind_restart_cmd" ]; then
+                       eval $ypbind_restart_cmd
+               fi
+       fi
+}
+
+restore_yp_binding()
+{
+       rm -f "$ypbind_dir/$interface"
+       local nd="$(best_domain)"
+       # We need to stop ypbind if there is no best domain
+       # otherwise it will just stall as we cannot set domainname
+       # to blank :/
+       if [ -z "$nd" ]; then
+               if [ -n "$ypbind_stop_cmd" ]; then
+                       eval $ypbind_stop_cmd
+               fi
+       elif [ "$nd" != "$(domainname)" ]; then
+               domainname "$nd"
+               if [ -n "$ypbind_restart_cmd" ]; then
+                       eval $ypbind_restart_cmd
+               fi
+       fi
+}
+
+case "$reason" in
+PREINIT)
+       rm -f "$ypbind_dir/$interface"
+       ;;
+TEST)
+       ;;
+*)
+       if [ -n "$new_nis_domain" ]; then
+               make_yp_binding
+       elif [ -n "$old_nis_domain" ]; then
+               restore_yp_binding
+       fi
+       ;;
+esac
diff -r bc43ed63f0b4 -r a67f88653253 external/bsd/dhcpcd/dist/dhcpcd.c
--- a/external/bsd/dhcpcd/dist/dhcpcd.c Wed Dec 23 02:29:46 2009 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd.c Wed Dec 23 08:30:06 2009 +0000
@@ -72,6 +72,11 @@
 /* We should define a maximum for the NAK exponential backoff */ 
 #define NAKOFF_MAX              60
 
+/* Wait N nanoseconds between sending a RELEASE and dropping the address.
+ * This gives the kernel enough time to actually send it. */
+#define RELEASE_DELAY_S                0
+#define RELEASE_DELAY_NS       10000000
+
 int options = 0;
 int pidfd = -1;
 struct interface *ifaces = NULL;
@@ -518,10 +523,9 @@
        {
                lease->frominfo = 0;
                lease->addr.s_addr = dhcp->yiaddr;
-               lease->server.s_addr = INADDR_ANY;
-               if (type != 0)
-                       get_option_addr(&lease->server,
-                           dhcp, DHO_SERVERID);
+               if (type == 0 ||
+                   get_option_addr(&lease->server, dhcp, DHO_SERVERID) != 0)
+                       lease->server.s_addr = INADDR_ANY;
                log_dhcp(LOG_INFO, "offered", iface, dhcp);
                free(state->offer);
                state->offer = dhcp;
@@ -572,9 +576,10 @@
                state->offer = dhcp;
                *dhcpp = NULL;
        }
-       lease->frominfo = 0;
 
+       lease->frominfo = 0;
        delete_timeout(NULL, iface);
+
        /* We now have an offer, so close the DHCP sockets.
         * This allows us to safely ARP when broken DHCP servers send an ACK
         * follows by an invalid NAK. */
@@ -704,13 +709,20 @@
 static void
 send_release(struct interface *iface)
 {
+       struct timespec ts;
+
        if (iface->state->lease.addr.s_addr &&
            !IN_LINKLOCAL(htonl(iface->state->lease.addr.s_addr)))
        {
                syslog(LOG_INFO, "%s: releasing lease of %s",
                    iface->name, inet_ntoa(iface->state->lease.addr));
                open_sockets(iface);
+               iface->state->xid = arc4random();
                send_message(iface, DHCP_RELEASE, NULL);
+               /* Give the packet a chance to go before dropping the ip */
+               ts.tv_sec = RELEASE_DELAY_S;
+               ts.tv_nsec = RELEASE_DELAY_NS;
+               nanosleep(&ts, NULL);
                drop_config(iface, "RELEASE");
        }
        unlink(iface->leasefile);
@@ -1630,7 +1642,7 @@
        if (options & DHCPCD_DEBUG)
                setlogmask(LOG_UPTO(LOG_DEBUG));
        else if (options & DHCPCD_QUIET)
-               setlogmask(LOG_UPTO(LOG_WARNING));
+               close(STDERR_FILENO);
 
        if (!(options & DHCPCD_TEST)) {
                /* If we have any other args, we should run as a single dhcpcd
@@ -1805,16 +1817,38 @@
                if (iface->carrier != LINK_DOWN)
                        opt = 1;
        }
-       if (opt == 0 &&
-           options & DHCPCD_LINK &&
-           !(options & DHCPCD_WAITIP))
-       {
-               syslog(LOG_WARNING, "no interfaces have a carrier");
-               daemonise();
-       } else if (options & DHCPCD_DAEMONISE && ifo->timeout > 0) {
-               if (options & DHCPCD_IPV4LL)
-                       options |= DHCPCD_TIMEOUT_IPV4LL;
-               add_timeout_sec(ifo->timeout, handle_exit_timeout, NULL);
+
+       if (!(options & DHCPCD_BACKGROUND)) {
+               /* If we don't have a carrier, we may have to wait for a second
+                * before one becomes available if we brought an interface up. */
+               if (opt == 0 &&



Home | Main Index | Thread Index | Old Index