]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix some more copyrights
authorRoy Marples <roy@marples.name>
Thu, 2 Feb 2012 16:22:40 +0000 (16:22 +0000)
committerRoy Marples <roy@marples.name>
Thu, 2 Feb 2012 16:22:40 +0000 (16:22 +0000)
RA expiry timers now trigger off options as well
Stop prefixing new_ for RA options
if_up and if_down are now set by dhcpcd itself
Correctly prefer a DHCP lease over an IPv4LL entry

common.c
configure.c
configure.h
dhcpcd-hooks/20-resolv.conf
dhcpcd-run-hooks.in
dhcpcd.c
if-pref.c
ipv6rs.c

index 2eae929903898fe747e4c81b061a8e71638fd52c..05b547b7901a43d1a76059588c16ae8710fcda30 100644 (file)
--- a/common.c
+++ b/common.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -203,10 +203,15 @@ get_monotonic(struct timeval *tp)
 ssize_t
 setvar(char ***e, const char *prefix, const char *var, const char *value)
 {
-       size_t len = strlen(prefix) + strlen(var) + strlen(value) + 4;
+       size_t len = strlen(var) + strlen(value) + 3;
 
+       if (prefix)
+               len += strlen(prefix) + 1;
        **e = xmalloc(len);
-       snprintf(**e, len, "%s_%s=%s", prefix, var, value);
+       if (prefix)
+               snprintf(**e, len, "%s_%s=%s", prefix, var, value);
+       else
+               snprintf(**e, len, "%s=%s", var, value);
        (*e)++;
        return len;
 }
index fecece5ed40f0de9e92ba7d157eee6676f63c6de..e12046f94336aafeac9d046a111c689e131b810b 100644 (file)
@@ -163,7 +163,7 @@ arraytostr(const char *const *argv, char **s)
 }
 
 static ssize_t
-make_env(const struct interface *iface, char ***argv)
+make_env(const struct interface *iface, const char *reason, char ***argv)
 {
        char **env, *p;
        ssize_t e, elen, l;
@@ -171,9 +171,8 @@ make_env(const struct interface *iface, char ***argv)
        const struct interface *ifp;
        int dhcp, ra;
 
-       dhcp = 0;
-       ra = 0;
-       if (strcmp(iface->state->reason, "ROUTERADVERT") == 0)
+       dhcp = ra = 0;
+       if (strcmp(reason, "ROUTERADVERT") == 0)
                ra = 1;
        else
                dhcp = 1;
@@ -183,16 +182,16 @@ make_env(const struct interface *iface, char ***argv)
        if (options & DHCPCD_DUMPLEASE)
                elen = 2;
        else
-               elen = 8;
+               elen = 10;
 
        /* Make our env */
        env = xmalloc(sizeof(char *) * (elen + 1));
        e = strlen("interface") + strlen(iface->name) + 2;
        env[0] = xmalloc(e);
        snprintf(env[0], e, "interface=%s", iface->name);
-       e = strlen("reason") + strlen(iface->state->reason) + 2;
+       e = strlen("reason") + strlen(reason) + 2;
        env[1] = xmalloc(e);
-       snprintf(env[1], e, "reason=%s", iface->state->reason);
+       snprintf(env[1], e, "reason=%s", reason);
        if (options & DHCPCD_DUMPLEASE)
                goto dumplease;
 
@@ -222,6 +221,13 @@ make_env(const struct interface *iface, char ***argv)
                e--;
        }
        *--p = '\0';
+       if (iface->state->new || iface->ras) {
+               env[8] = strdup("if_up=true");
+               env[9] = strdup("if_down=false");
+       } else {
+               env[8] = strdup("if_up=false");
+               env[9] = strdup("if_down=true");
+       }
        if (*iface->state->profile) {
                e = strlen("profile=") + strlen(iface->state->profile) + 2;
                env[elen] = xmalloc(e);
@@ -270,7 +276,7 @@ dumplease:
                e = ipv6rs_env(NULL, NULL, iface);
                if (e > 0) {
                        env = xrealloc(env, sizeof(char *) * (elen + e + 1));
-                       elen += ipv6rs_env(env + elen, "new", iface);
+                       elen += ipv6rs_env(env + elen, NULL, iface);
                }
        }
 
@@ -293,8 +299,8 @@ dumplease:
        return elen;
 }
 
-int
-send_interface(int fd, const struct interface *iface)
+static int
+send_interface1(int fd, const struct interface *iface, const char *reason)
 {
        char **env, **ep, *s;
        ssize_t elen;
@@ -302,7 +308,7 @@ send_interface(int fd, const struct interface *iface)
        int retval;
 
        retval = 0;
-       make_env(iface, &env);
+       make_env(iface, reason, &env);
        elen = arraytostr((const char *const *)env, &s);
        iov[0].iov_base = &elen;
        iov[0].iov_len = sizeof(ssize_t);
@@ -318,7 +324,20 @@ send_interface(int fd, const struct interface *iface)
 }
 
 int
-run_script(const struct interface *iface)
+send_interface(int fd, const struct interface *iface)
+{
+       int retval = 0;
+       if (send_interface1(fd, iface, iface->state->reason) == -1)
+               retval = -1;
+       if (iface->ras) {
+               if (send_interface1(fd, iface, "ROUTERADVERT") == -1)
+                       retval = -1;
+       }
+       return retval;
+}
+
+int
+run_script_reason(const struct interface *iface, const char *reason)
 {
        char *const argv[2] = { UNCONST(iface->state->options->script), NULL };
        char **env = NULL, **ep;
@@ -334,11 +353,13 @@ run_script(const struct interface *iface)
            strcmp(iface->state->options->script, "/dev/null") == 0)
                return 0;
 
+       if (reason == NULL)
+               reason = iface->state->reason;
        syslog(LOG_DEBUG, "%s: executing `%s', reason %s",
-           iface->name, argv[0], iface->state->reason);
+           iface->name, argv[0], reason);
 
        /* Make our env */
-       elen = make_env(iface, &env);
+       elen = make_env(iface, reason, &env);
        env = xrealloc(env, sizeof(char *) * (elen + 2));
        /* Add path to it */
        path = getenv("PATH");
index 17c506e5493b392d7327527673a1303e7a69c0bf..e125369bdfe57bd805c0729874d68aa4049726b0 100644 (file)
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2009 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
 #include "net.h"
 
 int send_interface(int, const struct interface *);
-int run_script(const struct interface *);
+int run_script_reason(const struct interface *, const char *);
 void build_routes(void);
 int configure(struct interface *);
 int route_deleted(const struct rt *);
+
+#define run_script(ifp) run_script_reason(ifp, (ifp)->state->reason);
 #endif
index baa18d2de7cb069d6da8145382ce53c45d8a3b4d..b4dd5f385edfc9b71fdd0d50cc7fb5c6443c24e6 100644 (file)
@@ -71,12 +71,12 @@ build_resolv_conf()
 
 add_resolv_conf()
 {
-       local x= conf="$signature$NL" i=${new_ra_count:-0} ra=
+       local x= conf="$signature$NL" i=${ra_count:-0} ra=
 
        while [ $i -ne 0 ]; do
-               eval ra=\$new_ra${i}_rdnss
+               eval ra=\$ra${i}_rdnss
                new_domain_name_servers="$new_domain_name_servers${new_domain_name_servers:+ }$ra"
-               eval ra=\$new_ra${i}_dnssl
+               eval ra=\$ra${i}_dnssl
                new_domain_search="$new_domain_search${new_domain_search:+ }$ra"
                i=$(($i - 1))
        done
index c97657937ed3c24b95014d6026bfc606eca43e6f..dc7dfeb9e13b6e6b034fe094d09d957b333adf97 100644 (file)
@@ -9,16 +9,8 @@ signature_base_end="# End of dhcpcd"
 signature_end="$signature_base_end $from $interface"
 state_dir=/var/run/dhcpcd
 
-if_up=false
-if_down=false
-case "$reason" in
-BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC)       if_up=true;;
-PREINIT|EXPIRE|FAIL|IPV4LL|NAK|NOCARRIER|RELEASE|STOP) if_down=true;;
-esac
-
 if [ "$reason" = ROUTERADVERT ]; then
        if_suffix=":ra"
-       [ "$new_ra_count" != 0 ] && if_up=true
 else
        if_suffix=
 fi
index d41c30a23161e95a4795044d10e0b5e476e29aa4..621b83ac8b024f6e9a0590cb20611631754a5933 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -247,8 +247,7 @@ stop_interface(struct interface *iface)
        if (iface->ras) {
                ipv6rs_free(iface);
                iface->ras = NULL;
-               iface->state->reason = "ROUTERADVERT";
-               run_script(iface);
+               run_script_reason(iface, "ROUTERADVERT");
        }
        if (strcmp(iface->state->reason, "RELEASE") != 0)
                drop_dhcp(iface, "STOP");
@@ -915,8 +914,7 @@ handle_carrier(int action, int flags, const char *ifname)
                        if (iface->ras) {
                                ipv6rs_free(iface);
                                iface->ras = NULL;
-                               iface->state->reason = "ROUTERADVERT";
-                               run_script(iface);
+                               run_script_reason(iface, "ROUTERADVERT");
                        }
                        drop_dhcp(iface, "NOCARRIER");
                }
@@ -1603,8 +1601,11 @@ handle_args(struct fd_list *fd, int argc, char **argv)
                } else if (strcmp(*argv, "--getinterfaces") == 0) {
                        len = 0;
                        if (argc == 1) {
-                               for (ifp = ifaces; ifp; ifp = ifp->next)
+                               for (ifp = ifaces; ifp; ifp = ifp->next) {
                                        len++;
+                                       if (ifp->ras)
+                                               len++;
+                               }
                                len = write(fd->fd, &len, sizeof(len));
                                if (len != sizeof(len))
                                        return -1;
@@ -1615,8 +1616,11 @@ handle_args(struct fd_list *fd, int argc, char **argv)
                        opt = 0;
                        while (argv[++opt] != NULL) {
                                for (ifp = ifaces; ifp; ifp = ifp->next)
-                                       if (strcmp(argv[opt], ifp->name) == 0)
+                                       if (strcmp(argv[opt], ifp->name) == 0) {
                                                len++;
+                                               if (ifp->ras)
+                                                       len++;
+                                       }
                        }
                        len = write(fd->fd, &len, sizeof(len));
                        if (len != sizeof(len))
index 83b1b0fbe56ef7207fbeaa054709316644ec0437..6169dbe968c00a9016c8bb59056ea9977ea61bf2 100644 (file)
--- a/if-pref.c
+++ b/if-pref.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -55,9 +55,9 @@ ifcmp(struct interface *si, struct interface *ti)
                sill = (si->state->new->cookie == htonl(MAGIC_COOKIE));
                till = (ti->state->new->cookie == htonl(MAGIC_COOKIE));
                if (!sill && till)
-                       return -1;
-               if (sill && !till)
                        return 1;
+               if (sill && !till)
+                       return -1;
        }
        /* Then carrier status. */
        if (si->carrier > ti->carrier)
index 1caf91229d95c39e856f20a169b62f0aba35902b..1cd586b6453f3ad6d787b096f24e7ffa26104be0 100644 (file)
--- a/ipv6rs.c
+++ b/ipv6rs.c
@@ -499,10 +499,9 @@ ipv6rs_handledata(_unused void *arg)
                        rao->type = ndo->nd_opt_type;
                        rao->option = opt;
                }
-               if (lifetime == ~0U) {
-                       rao->expire.tv_sec = 0;
-                       rao->expire.tv_usec = 0;
-               } else {
+               if (lifetime == ~0U)
+                       timerclear(&rao->expire);
+               else {
                        expire.tv_sec = lifetime;
                        expire.tv_usec = 0;
                        timeradd(&rap->received, &expire, &rao->expire);
@@ -510,12 +509,7 @@ ipv6rs_handledata(_unused void *arg)
        }
 
        ipv6rs_sort(ifp);
-
-       if (options & DHCPCD_TEST)
-               ifp->state->reason = "TEST";
-       else
-               ifp->state->reason = "ROUTERADVERT";
-       run_script(ifp);
+       run_script_reason(ifp, options & DHCPCD_TEST ? "TEST" : "ROUTERADVERT");
        if (options & DHCPCD_TEST)
                exit(EXIT_SUCCESS);
 
@@ -545,15 +539,8 @@ ipv6rs_env(char **env, const char *prefix, const struct interface *ifp)
                        setvar(&env, prefix, buffer, rap->sfrom);
                }
                l++;
+
                for (rao = rap->options; rao; rao = rao->next) {
-                       if (rao->expire.tv_sec != 0 &&
-                           rao->expire.tv_usec != 0 &&
-                           timercmp(&now, &rao->expire, >))
-                       {
-                               syslog(LOG_INFO, "%s: %s: expired option %d",
-                                   ifp->name, rap->sfrom, rao->type);
-                               continue;
-                       }
                        if (rao->option == NULL)
                                continue;
                        if (env == NULL) {
@@ -644,6 +631,7 @@ ipv6rs_expire(void *arg)
 {
        struct interface *ifp;
        struct ra *rap, *ran, *ral;
+       struct ra_opt *rao, *raol, *raon;
        struct timeval now, lt, expire, next;
        int expired;
        uint32_t expire_secs;
@@ -662,6 +650,8 @@ ipv6rs_expire(void *arg)
                lt.tv_usec = 0;
                timeradd(&rap->received, &lt, &expire);
                if (timercmp(&now, &expire, >)) {
+                       syslog(LOG_INFO, "%s: %s: expired Router Advertisement",
+                           ifp->name, rap->sfrom);
                        expired = 1;
                        if (ral)
                                ral->next = ran;
@@ -669,8 +659,29 @@ ipv6rs_expire(void *arg)
                                ifp->ras = ran;
                        ipv6rs_free_opts(rap);
                        free(rap);
-               } else {
-                       timersub(&now, &expire, &lt);
+                       continue;
+               }
+               timersub(&expire, &now, &lt);
+               if (!timerisset(&next) || timercmp(&next, &lt, >))
+                       next = lt;
+               
+               for (rao = rap->options;
+                   rao && (raon = rao->next);
+                   raol = rao, rao = raon)
+               {
+                       if (!timerisset(&rao->expire))
+                               continue;
+                       if (timercmp(&now, &rao->expire, >)) {
+                               syslog(LOG_INFO,
+                                   "%s: %s: expired option %d",
+                                   ifp->name, rap->sfrom, rao->type);
+                               if (raol)
+                                       raol = raon;
+                               else
+                                       rap->options = raon;
+                               continue;
+                       }
+                       timersub(&rao->expire, &now, &lt);
                        if (!timerisset(&next) || timercmp(&next, &lt, >))
                                next = lt;
                }
@@ -678,12 +689,8 @@ ipv6rs_expire(void *arg)
 
        if (timerisset(&next))
                add_timeout_tv(&next, ipv6rs_expire, ifp);
-
-       if (expired) {
-               ifp->state->reason = "ROUTERADVERT";
-               run_script(ifp);
-       }
-
+       if (expired)
+               run_script_reason(ifp, "ROUTERADVERT");
 }
 
 int