From: Roy Marples Date: Thu, 2 Feb 2012 16:22:40 +0000 (+0000) Subject: Fix some more copyrights X-Git-Tag: v5.5.2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=449df9c85965b2a6415a608ecb61d9f5c0256bed;p=thirdparty%2Fdhcpcd.git Fix some more copyrights 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 --- diff --git a/common.c b/common.c index 2eae9299..05b547b7 100644 --- a/common.c +++ b/common.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2011 Roy Marples + * Copyright (c) 2006-2012 Roy Marples * 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; } diff --git a/configure.c b/configure.c index fecece5e..e12046f9 100644 --- a/configure.c +++ b/configure.c @@ -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"); diff --git a/configure.h b/configure.h index 17c506e5..e125369b 100644 --- a/configure.h +++ b/configure.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2009 Roy Marples + * Copyright (c) 2006-2012 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -31,8 +31,10 @@ #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 diff --git a/dhcpcd-hooks/20-resolv.conf b/dhcpcd-hooks/20-resolv.conf index baa18d2d..b4dd5f38 100644 --- a/dhcpcd-hooks/20-resolv.conf +++ b/dhcpcd-hooks/20-resolv.conf @@ -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 diff --git a/dhcpcd-run-hooks.in b/dhcpcd-run-hooks.in index c9765793..dc7dfeb9 100644 --- a/dhcpcd-run-hooks.in +++ b/dhcpcd-run-hooks.in @@ -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 diff --git a/dhcpcd.c b/dhcpcd.c index d41c30a2..621b83ac 100644 --- 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)) diff --git a/if-pref.c b/if-pref.c index 83b1b0fb..6169dbe9 100644 --- a/if-pref.c +++ b/if-pref.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2010 Roy Marples + * Copyright (c) 2006-2012 Roy Marples * 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) diff --git a/ipv6rs.c b/ipv6rs.c index 1caf9122..1cd586b6 100644 --- 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, <, &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, <); + continue; + } + timersub(&expire, &now, <); + if (!timerisset(&next) || timercmp(&next, <, >)) + 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, <); if (!timerisset(&next) || timercmp(&next, <, >)) 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