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 * Fixed a potential segfault with I...



details:   https://anonhg.NetBSD.org/src/rev/45b27201fa5f
branches:  trunk
changeset: 778465:45b27201fa5f
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Mar 28 10:19:31 2012 +0000

description:
* Fixed a potential segfault with IPv6 option handling
* Add a suffix to all our config files so that RA never stamps on IPv4
* All valgrind errors fixed on FreeBSD (with ./configure --debug=YES)
* When started with an interface list, respect that with signal handling
* Fix a potential route table corruption if we failed to add a route

diffstat:

 external/bsd/dhcpcd/dist/configure.c                 |  50 ++++++++++---------
 external/bsd/dhcpcd/dist/defs.h                      |   2 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/20-resolv.conf |  16 +++---
 external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ntp.conf    |   8 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ypbind      |   8 +-
 external/bsd/dhcpcd/dist/dhcpcd-run-hooks.in         |  17 +++---
 external/bsd/dhcpcd/dist/dhcpcd.c                    |  29 +++++++----
 external/bsd/dhcpcd/dist/if-bsd.c                    |  38 ++++++++++----
 external/bsd/dhcpcd/dist/ipv6rs.c                    |   4 +-
 external/bsd/dhcpcd/dist/net.c                       |  16 ++++++
 external/bsd/dhcpcd/dist/net.h                       |  15 ++----
 11 files changed, 121 insertions(+), 82 deletions(-)

diffs (truncated from 527 to 300 lines):

diff -r ded615fee4bd -r 45b27201fa5f external/bsd/dhcpcd/dist/configure.c
--- a/external/bsd/dhcpcd/dist/configure.c      Tue Mar 27 21:56:04 2012 +0000
+++ b/external/bsd/dhcpcd/dist/configure.c      Wed Mar 28 10:19:31 2012 +0000
@@ -435,9 +435,10 @@
 }
 
 static void
-desc_route(const char *cmd, const struct rt *rt, const char *ifname)
+desc_route(const char *cmd, const struct rt *rt)
 {
        char addr[sizeof("000.000.000.000") + 1];
+       const char *ifname = rt->iface->name;
 
        strlcpy(addr, inet_ntoa(rt->dest), sizeof(addr));
        if (rt->gate.s_addr == INADDR_ANY)
@@ -465,7 +466,7 @@
        f = find_route(routes, rt, &l, NULL);
        if (f == NULL)
                return 0;
-       desc_route("removing", f, f->iface->name);
+       desc_route("removing", f);
        if (l)
                l->next = f->next;
        else
@@ -475,59 +476,60 @@
 }
 
 static int
-n_route(struct rt *rt, const struct interface *iface)
+n_route(struct rt *rt)
 {
        /* Don't set default routes if not asked to */
        if (rt->dest.s_addr == 0 &&
            rt->net.s_addr == 0 &&
-           !(iface->state->options->options & DHCPCD_GATEWAY))
+           !(rt->iface->state->options->options & DHCPCD_GATEWAY))
                return -1;
 
-       desc_route("adding", rt, iface->name);
-       if (!add_route(iface, &rt->dest, &rt->net, &rt->gate, iface->metric))
+       desc_route("adding", rt);
+       if (!add_route(rt))
                return 0;
        if (errno == EEXIST) {
                /* Pretend we added the subnet route */
-               if (rt->dest.s_addr == (iface->addr.s_addr & iface->net.s_addr) &&
-                   rt->net.s_addr == iface->net.s_addr &&
+               if (rt->dest.s_addr ==
+                   (rt->iface->addr.s_addr & rt->iface->net.s_addr) &&
+                   rt->net.s_addr == rt->iface->net.s_addr &&
                    rt->gate.s_addr == 0)
                        return 0;
                else
                        return -1;
        }
-       syslog(LOG_ERR, "%s: add_route: %m", iface->name);
+       syslog(LOG_ERR, "%s: add_route: %m", rt->iface->name);
        return -1;
 }
 
 static int
-c_route(struct rt *ort, struct rt *nrt, const struct interface *iface)
+c_route(struct rt *ort, struct rt *nrt)
 {
        /* Don't set default routes if not asked to */
        if (nrt->dest.s_addr == 0 &&
            nrt->net.s_addr == 0 &&
-           !(iface->state->options->options & DHCPCD_GATEWAY))
+           !(nrt->iface->state->options->options & DHCPCD_GATEWAY))
                return -1;
 
-       desc_route("changing", nrt, iface->name);
+       desc_route("changing", nrt);
        /* We delete and add the route so that we can change metric.
         * This also has the nice side effect of flushing ARP entries so
         * we don't have to do that manually. */
-       del_route(ort->iface, &ort->dest, &ort->net, &ort->gate, ort->metric);
-       if (!add_route(iface, &nrt->dest, &nrt->net, &nrt->gate, nrt->metric))
+       del_route(ort);
+       if (!add_route(nrt))
                return 0;
-       syslog(LOG_ERR, "%s: add_route: %m", iface->name);
+       syslog(LOG_ERR, "%s: add_route: %m", nrt->iface->name);
        return -1;
 }
 
 static int
-d_route(struct rt *rt, const struct interface *iface, int metric)
+d_route(struct rt *rt)
 {
        int retval;
 
-       desc_route("deleting", rt, iface->name);
-       retval = del_route(iface, &rt->dest, &rt->net, &rt->gate, metric);
+       desc_route("deleting", rt);
+       retval = del_route(rt);
        if (retval != 0 && errno != ENOENT && errno != ESRCH)
-               syslog(LOG_ERR,"%s: del_route: %m", iface->name);
+               syslog(LOG_ERR,"%s: del_route: %m", rt->iface->name);
        return retval;
 }
 
@@ -712,7 +714,7 @@
                                    rt->gate.s_addr != or->gate.s_addr ||
                                    rt->metric != or->metric)
                                {
-                                       if (c_route(or, rt, ifp) != 0)
+                                       if (c_route(or, rt) != 0)
                                                continue;
                                }
                                if (rtl != NULL)
@@ -721,7 +723,7 @@
                                        routes = or->next;
                                free(or);
                        } else {
-                               if (n_route(rt, ifp) != 0)
+                               if (n_route(rt) != 0)
                                        continue;
                        }
                        if (dnr == rt)
@@ -730,6 +732,7 @@
                                lrt->next = rtn;
                        rt->next = nrs;
                        nrs = rt;
+                       rt = lrt; /* When we loop this makes lrt correct */
                }
                free_routes(dnr);
        }
@@ -737,7 +740,7 @@
        /* Remove old routes we used to manage */
        for (rt = routes; rt; rt = rt->next) {
                if (find_route(nrs, rt, NULL, NULL) == NULL)
-                       d_route(rt, rt->iface, rt->iface->metric);
+                       d_route(rt);
        }
 
        free_routes(routes);
@@ -817,8 +820,9 @@
        rt = get_subnet_route(dhcp);
        if (rt != NULL) {
                rt->iface = iface;
+               rt->metric = 0;
                if (!find_route(routes, rt, NULL, NULL))
-                       del_route(iface, &rt->dest, &rt->net, &rt->gate, 0);
+                       del_route(rt);
                free(rt);
        }
 
diff -r ded615fee4bd -r 45b27201fa5f external/bsd/dhcpcd/dist/defs.h
--- a/external/bsd/dhcpcd/dist/defs.h   Tue Mar 27 21:56:04 2012 +0000
+++ b/external/bsd/dhcpcd/dist/defs.h   Wed Mar 28 10:19:31 2012 +0000
@@ -28,7 +28,7 @@
 #define CONFIG_H
 
 #define PACKAGE                        "dhcpcd"
-#define VERSION                        "5.5.5"
+#define VERSION                        "5.5.6"
 
 #ifndef CONFIG
 # define CONFIG                        SYSCONFDIR "/" PACKAGE ".conf"
diff -r ded615fee4bd -r 45b27201fa5f external/bsd/dhcpcd/dist/dhcpcd-hooks/20-resolv.conf
--- a/external/bsd/dhcpcd/dist/dhcpcd-hooks/20-resolv.conf      Tue Mar 27 21:56:04 2012 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd-hooks/20-resolv.conf      Wed Mar 28 10:19:31 2012 +0000
@@ -12,7 +12,7 @@
 
 build_resolv_conf()
 {
-       local cf="$state_dir/resolv.conf.$interface$if_suffix"
+       local cf="$state_dir/resolv.conf.$ifname"
        local interfaces= header= search= srvs= servers= x=
 
        # Build a list of interfaces
@@ -114,25 +114,25 @@
        done
        if type resolvconf >/dev/null 2>&1; then
                [ -n "$ifmetric" ] && export IF_METRIC="$ifmetric"
-               printf %s "$conf" | resolvconf -a "$interface$if_suffix"
+               printf %s "$conf" | resolvconf -a "$ifname"
                return $?
        fi
 
-       if [ -e "$resolv_conf_dir/$interface$if_suffix" ]; then
-               rm -f "$resolv_conf_dir/$interface$if_suffix"
+       if [ -e "$resolv_conf_dir/$ifname" ]; then
+               rm -f "$resolv_conf_dir/$ifname"
        fi
        [ -d "$resolv_conf_dir" ] || mkdir -p "$resolv_conf_dir"
-       printf %s "$conf" > "$resolv_conf_dir/$interface$if_suffix"
+       printf %s "$conf" > "$resolv_conf_dir/$ifname"
        build_resolv_conf
 }
 
 remove_resolv_conf()
 {
        if type resolvconf >/dev/null 2>&1; then
-               resolvconf -d "$interface$if_suffix" -f
+               resolvconf -d "$ifname" -f
        else
-               if [ -e "$resolv_conf_dir/$interface$if_suffix" ]; then
-                       rm -f "$resolv_conf_dir/$interface$if_suffix"
+               if [ -e "$resolv_conf_dir/$ifname" ]; then
+                       rm -f "$resolv_conf_dir/$ifname"
                fi
                build_resolv_conf
        fi
diff -r ded615fee4bd -r 45b27201fa5f external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ntp.conf
--- a/external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ntp.conf Tue Mar 27 21:56:04 2012 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ntp.conf Wed Mar 28 10:19:31 2012 +0000
@@ -25,7 +25,7 @@
 
 build_ntp_conf()
 {
-       local cf="$state_dir/ntp.conf.$interface"
+       local cf="$state_dir/ntp.conf.$ifname"
        local interfaces= header= srvs= servers= x=
 
        # Build a list of interfaces
@@ -75,7 +75,7 @@
 
 add_ntp_conf()
 {
-       local cf="$ntp_conf_dir/$interface" x=
+       local cf="$ntp_conf_dir/$ifname" x=
 
        [ -e "$cf" ] && rm "$cf"
        [ -d "$ntp_conf_dir" ] || mkdir -p "$ntp_conf_dir"
@@ -89,8 +89,8 @@
 
 remove_ntp_conf()
 {
-       if [ -e "$ntp_conf_dir/$interface" ]; then
-               rm "$ntp_conf_dir/$interface"
+       if [ -e "$ntp_conf_dir/$ifname" ]; then
+               rm "$ntp_conf_dir/$ifname"
        fi
        build_ntp_conf
 }
diff -r ded615fee4bd -r 45b27201fa5f external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ypbind
--- a/external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ypbind   Tue Mar 27 21:56:04 2012 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ypbind   Wed Mar 28 10:19:31 2012 +0000
@@ -20,12 +20,12 @@
 make_yp_binding()
 {
        [ -d "$ypbind_dir" ] || mkdir -p "$ypbind_dir"
-       echo "$new_nis_domain" >"$ypbind_dir/$interface"
+       echo "$new_nis_domain" >"$ypbind_dir/$ifname"
        local nd="$(best_domain)"
 
        local cf=/var/yp/binding/"$new_nis_domain".ypservers
        if [ -n "$new_nis_servers" ]; then
-               local ncf="$cf.$interface" x=
+               local ncf="$cf.$ifname" x=
                rm -f "$ncf"
                for x in $new_nis_servers; do
                        echo "$x" >>"$ncf"
@@ -46,7 +46,7 @@
 
 restore_yp_binding()
 {
-       rm -f "$ypbind_dir/$interface"
+       rm -f "$ypbind_dir/$ifname"
        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
@@ -64,7 +64,7 @@
 }
 
 if [ "$reason" = PREINIT ]; then
-       rm -f "$ypbind_dir/$interface"
+       rm -f "$ypbind_dir/$ifname"
 elif $if_up || $if_down; then
        if [ -n "$new_nis_domain" ]; then
                if valid_domainname "$new_nis_domain"; then
diff -r ded615fee4bd -r 45b27201fa5f external/bsd/dhcpcd/dist/dhcpcd-run-hooks.in
--- a/external/bsd/dhcpcd/dist/dhcpcd-run-hooks.in      Tue Mar 27 21:56:04 2012 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd-run-hooks.in      Wed Mar 28 10:19:31 2012 +0000
@@ -2,19 +2,20 @@
 # dhcpcd client configuration script 
 
 # Handy variables and functions for our hooks to use
+if [ "$reason" = ROUTERADVERT ]; then
+       ifsuffix=":ra"
+else
+       ifsuffix=
+fi
+ifname="$interface$ifsuffix"
+
 from=from
 signature_base="# Generated by dhcpcd"
-signature="$signature_base $from $interface"
+signature="$signature_base $from $ifname"
 signature_base_end="# End of dhcpcd"
-signature_end="$signature_base_end $from $interface"
+signature_end="$signature_base_end $from $ifname"
 state_dir=/var/run/dhcpcd
 
-if [ "$reason" = ROUTERADVERT ]; then
-       if_suffix=":ra"
-else
-       if_suffix=



Home | Main Index | Thread Index | Old Index