Module Name: src Committed By: roy Date: Fri Sep 20 10:56:32 UTC 2013
Modified Files: src/external/bsd/dhcpcd/dist: dhcp.c dhcpcd.8.in dhcpcd.conf dhcpcd.conf.5.in net.c Removed Files: src/external/bsd/dhcpcd/dist: ipv6ns.c ipv6ns.h ipv6rs.c ipv6rs.h Log Message: Sync To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/external/bsd/dhcpcd/dist/dhcp.c cvs rdiff -u -r1.21 -r1.22 src/external/bsd/dhcpcd/dist/dhcpcd.8.in cvs rdiff -u -r1.7 -r1.8 src/external/bsd/dhcpcd/dist/dhcpcd.conf cvs rdiff -u -r1.3 -r1.4 src/external/bsd/dhcpcd/dist/dhcpcd.conf.5.in cvs rdiff -u -r1.1.1.3 -r0 src/external/bsd/dhcpcd/dist/ipv6ns.c \ src/external/bsd/dhcpcd/dist/ipv6ns.h cvs rdiff -u -r1.1.1.13 -r0 src/external/bsd/dhcpcd/dist/ipv6rs.c cvs rdiff -u -r1.1.1.5 -r0 src/external/bsd/dhcpcd/dist/ipv6rs.h cvs rdiff -u -r1.2 -r1.3 src/external/bsd/dhcpcd/dist/net.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/bsd/dhcpcd/dist/dhcp.c diff -u src/external/bsd/dhcpcd/dist/dhcp.c:1.6 src/external/bsd/dhcpcd/dist/dhcp.c:1.7 --- src/external/bsd/dhcpcd/dist/dhcp.c:1.6 Mon Jul 29 20:39:28 2013 +++ src/external/bsd/dhcpcd/dist/dhcp.c Fri Sep 20 10:56:32 2013 @@ -1,5 +1,5 @@ #include <sys/cdefs.h> - __RCSID("$NetBSD: dhcp.c,v 1.6 2013/07/29 20:39:28 roy Exp $"); + __RCSID("$NetBSD: dhcp.c,v 1.7 2013/09/20 10:56:32 roy Exp $"); /* * dhcpcd - DHCP client daemon @@ -1702,7 +1702,6 @@ dhcp_rebind(void *arg) send_rebind(ifp); } - void dhcp_bind(void *arg) { @@ -1724,10 +1723,10 @@ dhcp_bind(void *arg) state->offer = NULL; get_lease(lease, state->new); if (ifo->options & DHCPCD_STATIC) { - syslog(LOG_INFO, "%s: using static address %s", - iface->name, inet_ntoa(lease->addr)); + syslog(LOG_INFO, "%s: using static address %s/%d", + iface->name, inet_ntoa(lease->addr), + inet_ntocidr(lease->net)); lease->leasetime = ~0U; - lease->net.s_addr = ifo->req_mask.s_addr; state->reason = "STATIC"; } else if (state->new->cookie != htonl(MAGIC_COOKIE)) { syslog(LOG_INFO, "%s: using IPv4LL address %s", @@ -1834,7 +1833,7 @@ dhcp_timeout(void *arg) } struct dhcp_message * -dhcp_message_new(struct in_addr *addr, struct in_addr *mask) +dhcp_message_new(const struct in_addr *addr, const struct in_addr *mask) { struct dhcp_message *dhcp; uint8_t *p; @@ -1854,60 +1853,65 @@ dhcp_message_new(struct in_addr *addr, s return dhcp; } -static int -handle_3rdparty(struct interface *ifp) +static void +dhcp_static(struct interface *ifp) { struct if_options *ifo; struct dhcp_state *state; - struct in_addr addr, net, dst; + state = D_STATE(ifp); ifo = ifp->options; - if (ifo->req_addr.s_addr != INADDR_ANY) - return 0; - - if (ipv4_getaddress(ifp->name, &addr, &net, &dst) == 1) - ipv4_handleifa(RTM_NEWADDR, ifp->name, &addr, &net, &dst); - else { + if (ifo->req_addr.s_addr == INADDR_ANY) { syslog(LOG_INFO, - "%s: waiting for 3rd party to configure IP address", + "%s: waiting for 3rd party to " + "configure IP address", ifp->name); - state = D_STATE(ifp); state->reason = "3RDPARTY"; script_runreason(ifp, state->reason); - } - return 1; -} - -static void -dhcp_static(struct interface *ifp) -{ - struct if_options *ifo; - struct dhcp_state *state; - - if (handle_3rdparty(ifp)) return; - ifo = ifp->options; - state = D_STATE(ifp); + } state->offer = dhcp_message_new(&ifo->req_addr, &ifo->req_mask); - eloop_timeout_delete(NULL, ifp); - dhcp_bind(ifp); + if (state->offer) { + eloop_timeout_delete(NULL, ifp); + dhcp_bind(ifp); + } } void dhcp_inform(struct interface *ifp) { struct dhcp_state *state; - - if (handle_3rdparty(ifp)) - return; + struct if_options *ifo; + struct ipv4_addr *ap; state = D_STATE(ifp); + ifo = ifp->options; if (options & DHCPCD_TEST) { - state->addr.s_addr = ifp->options->req_addr.s_addr; - state->net.s_addr = ifp->options->req_mask.s_addr; + state->addr.s_addr = ifo->req_addr.s_addr; + state->net.s_addr = ifo->req_mask.s_addr; } else { - ifp->options->options |= DHCPCD_STATIC; - dhcp_static(ifp); + if (ifo->req_addr.s_addr == INADDR_ANY) { + state = D_STATE(ifp); + ap = ipv4_findaddr(ifp, NULL, NULL); + if (ap == NULL) { + syslog(LOG_INFO, + "%s: waiting for 3rd party to " + "configure IP address", + ifp->name); + state->reason = "3RDPARTY"; + script_runreason(ifp, state->reason); + return; + } + state->offer = + dhcp_message_new(&ap->addr, &ap->net); + } else + state->offer = + dhcp_message_new(&ifo->req_addr, &ifo->req_mask); + if (state->offer) { + ifo->options |= DHCPCD_STATIC; + dhcp_bind(ifp); + ifo->options &= ~DHCPCD_STATIC; + } } state->state = DHS_INFORM; @@ -2220,6 +2224,8 @@ dhcp_handle(struct interface *iface, str if (!(ifo->options & DHCPCD_INFORM)) log_dhcp(LOG_DEBUG, "acknowledged", iface, dhcp, from); + else + ifo->options &= ~DHCPCD_STATIC; } /* BOOTP could have already assigned this above, so check we still @@ -2244,7 +2250,7 @@ dhcp_handle(struct interface *iface, str /* If the interface already has the address configured * then we can't ARP for duplicate detection. */ addr.s_addr = state->offer->yiaddr; - if (ipv4_hasaddress(iface->name, &addr, NULL) != 1) { + if (!ipv4_findaddr(iface, &addr, NULL)) { state->claims = 0; state->probes = 0; state->conflicts = 0; @@ -2687,3 +2693,70 @@ dhcp_start(struct interface *ifp) else dhcp_reboot(ifp); } + +void +dhcp_handleifa(int type, struct interface *ifp, + const struct in_addr *addr, + const struct in_addr *net, + const struct in_addr *dst) +{ + struct dhcp_state *state; + struct if_options *ifo; + int i; + + state = D_STATE(ifp); + if (state == NULL) + return; + + if (type == RTM_DELADDR) { + if (state->new && + (state->new->yiaddr == addr->s_addr || + (state->new->yiaddr == INADDR_ANY && + state->new->ciaddr == addr->s_addr))) + { + syslog(LOG_INFO, "%s: removing IP address %s/%d", + ifp->name, inet_ntoa(state->lease.addr), + inet_ntocidr(state->lease.net)); + dhcp_drop(ifp, "EXPIRE"); + } + return; + } + + if (type != RTM_NEWADDR) + return; + + ifo = ifp->options; + if (ifo->options & DHCPCD_INFORM) { + if (state->state != DHS_INFORM) + dhcp_inform(ifp); + return; + } + + if (!(ifo->options & DHCPCD_STATIC)) + return; + if (ifo->req_addr.s_addr != INADDR_ANY) + return; + + free(state->old); + state->old = state->new; + state->new = dhcp_message_new(addr, net); + if (state->new == NULL) + return; + state->dst.s_addr = dst ? dst->s_addr : INADDR_ANY; + if (dst) { + for (i = 1; i < 255; i++) + if (i != DHO_ROUTER && has_option_mask(ifo->dstmask,i)) + dhcp_message_add_addr(state->new, i, *dst); + } + state->reason = "STATIC"; + ipv4_buildroutes(); + script_runreason(ifp, state->reason); + if (ifo->options & DHCPCD_INFORM) { + state->state = DHS_INFORM; + state->xid = dhcp_xid(ifp); + state->lease.server.s_addr = dst ? dst->s_addr : INADDR_ANY; + state->addr = *addr; + state->net = *net; + dhcp_inform(ifp); + } +} Index: src/external/bsd/dhcpcd/dist/dhcpcd.8.in diff -u src/external/bsd/dhcpcd/dist/dhcpcd.8.in:1.21 src/external/bsd/dhcpcd/dist/dhcpcd.8.in:1.22 --- src/external/bsd/dhcpcd/dist/dhcpcd.8.in:1.21 Mon Jul 29 20:39:28 2013 +++ src/external/bsd/dhcpcd/dist/dhcpcd.8.in Fri Sep 20 10:56:32 2013 @@ -1,4 +1,4 @@ -.\" $NetBSD: dhcpcd.8.in,v 1.21 2013/07/29 20:39:28 roy Exp $ +.\" $NetBSD: dhcpcd.8.in,v 1.22 2013/09/20 10:56:32 roy Exp $ .\" Copyright (c) 2006-2013 Roy Marples .\" All rights reserved .\" @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd June 6, 2013 +.Dd September 12, 2013 .Dt DHCPCD 8 .Os .Sh NAME @@ -31,7 +31,7 @@ .Nd a DHCP client .Sh SYNOPSIS .Nm -.Op Fl 46ABbDdEGgHJKkLnpqTVw +.Op Fl 46ABbDdEGgHJKLpqTV .Op Fl C , Fl Fl nohook Ar hook .Op Fl c , Fl Fl script Ar script .Op Fl e , Fl Fl env Ar value @@ -52,6 +52,7 @@ .Op Fl u , Fl Fl userclass Ar class .Op Fl v , Fl Fl vendor Ar code , Ar value .Op Fl W , Fl Fl whitelist Ar address Ns Op Ar /cidr +.Op Fl w , Fl Fl waitip Op 4 | 6 .Op Fl y , Fl Fl reboot Ar seconds .Op Fl X , Fl Fl blacklist Ar address Ns Op Ar /cidr .Op Fl Z , Fl Fl denyinterfaces Ar pattern @@ -59,6 +60,9 @@ .Op interface .Op ... .Nm +.Fl n , Fl Fl rebind +.Op interface +.Nm .Fl k , Fl Fl release .Op interface .Nm @@ -300,16 +304,19 @@ For example If not set then none is sent. Some badly configured DHCP servers reject unknown vendorclassids. To work around it, try and impersonate Windows by using the MSFT vendorclassid. -.It Fl k , Fl Fl release +.It Fl k , Fl Fl release Op Ar interface This causes an existing .Nm process running on the .Ar interface -to release its lease, de-configure the +to release its lease and de-configure the +.Ar interface . +If no .Ar interface -and then exit. +is specified then this applies to all interfaces. +If no interfaces are left running, .Nm -then waits until this process has exited. +will exit. .It Fl l , Fl Fl leasetime Ar seconds Request a specific lease time in .Ar seconds . @@ -323,10 +330,12 @@ Metrics are used to prefer an interface will supply a default metic of 200 + .Xr if_nametoindex 3 . An extra 100 will be added for wireless interfaces. -.It Fl n , Fl Fl rebind +.It Fl n , Fl Fl rebind Op Ar interface Notifies .Nm -to reload its configuration and rebind its interfaces. +to reload its configuration and rebind the specified +.Ar interface . +If no interface is specified then this applies to all interfaces. If .Nm is not running, then it starts up as normal. @@ -344,7 +353,8 @@ normally de-configures the .Ar interface and configuration when it exits. Sometimes, this isn't desirable if, for example, you have root mounted over -NFS. +NFS or SSH clients connect to this host and they need to be notified of +the host shutting down. You can use this option to stop this from happening. .It Fl r , Fl Fl request Op Ar address Request the @@ -374,6 +384,21 @@ If .Nm fails to contact a DHCP server then it returns a failure instead of falling back on IPv4LL. +.It Fl S, Fl Fl static Ar value +Configures a static +.Ar value . +If you set +.Ic ip_address +then +.Nm +will not attempt to obtain a lease and just use the value for the address with +an infinite lease time. +.Pp +Here is an example which configures a static address, routes and dns. +.D1 dhcpcd -S ip_address=192.168.0.10/24 \e +.D1 -S routers=192.168.0.1 \e +.D1 -S domain_name_servers=192.168.0.1 \e +.D1 eth0 .It Fl t , Fl Fl timeout Ar seconds Timeout after .Ar seconds , @@ -409,9 +434,17 @@ Set un-encapsulated vendor option to hel Display both program version and copyright information. .Nm then exits before doing any configuration. -.It Fl w , Fl Fl waitip +.It Fl w , Fl Fl waitip Op 4 | 6 Wait for an address to be assigned before forking to the background. -.It Fl x , Fl Fl exit +4 means wait for an IPv4 address to be assigned. +6 means wait for an IPv6 address to be assigned. +If no argument is given, +.Nm +will wait for any address protocol to be assigned. +It is possible to wait for more than one address protocol and +.Nm +will only fork to the background when all waiting conditions are satisfied. +.It Fl x , Fl Fl exit Op Ar interface This will signal an existing .Nm process running on the @@ -419,6 +452,7 @@ process running on the to de-configure the .Ar interface and exit. +If no interface is specified, then the above is applied to all interfaces. .Nm then waits until this process has exited. .It Fl y , Fl Fl reboot Ar seconds @@ -494,21 +528,6 @@ Quiet .Nm on the command line, only warnings and errors will be displayed. The messages are still logged though. -.It Fl S, Fl Fl static Ar value -Configures a static -.Ar value . -If you set -.Ic ip_address -then -.Nm -will not attempt to obtain a lease and just use the value for the address with -an infinite lease time. -.Pp -Here is an example which configures a static address, routes and dns. -.D1 dhcpcd -S ip_address=192.168.0.10/24 \e -.D1 -S routers=192.168.0.1 \e -.D1 -S domain_name_servers=192.168.0.1 \e -.D1 eth0 .It Fl T, Fl Fl test On receipt of DHCP messages just call .Pa @SCRIPT@ @@ -554,6 +573,10 @@ which is a space or comma separated list If the same interface is matched in .Fl Z , Fl Fl denyinterfaces then it is still denied. +.It Fl Fl nodev +Don't load any +.Pa /dev +management modules. .El .Sh 3RDPARTY LINK MANAGEMENT Some interfaces require configuration by 3rd parties, such as PPP or VPN. @@ -582,6 +605,9 @@ If you always use the same options, put Text file that holds the DUID used to identify the host. .It Pa @SCRIPT@ Bourne shell script that is run to configure or de-configure an interface. +.It Pa @LIBDIR@/dhcpcd/dev +.Pa /dev +management modules. .It Pa @HOOKDIR@ A directory containing bourne shell scripts that are run by the above script. Each script can be disabled by using the @@ -612,7 +638,7 @@ running on the RFC\ 951 RFC\ 1534 RFC\ 2131, RFC\ 2132, RFC\ 2855, RFC\ 3004, RFC\ 3315, RFC\ 3361, RFC\ 3633, RFC\ 3396, RFC\ 3397, RFC\ 3442, RFC\ 3927, RFC\ 4039 RFC\ 4075, RFC\ 4361, RFC\ 4390, RFC\ 4702, RFC\ 4704, RFC\ 4861, RFC\ 4833, -RFC\ 5227, RFC\ 5969, RFC\ 6106. +RFC\ 5227, RFC\ 5942, RFC\ 5969, RFC\ 6106. .Sh AUTHORS .An Roy Marples Aq Mt r...@marples.name .Sh BUGS Index: src/external/bsd/dhcpcd/dist/dhcpcd.conf diff -u src/external/bsd/dhcpcd/dist/dhcpcd.conf:1.7 src/external/bsd/dhcpcd/dist/dhcpcd.conf:1.8 --- src/external/bsd/dhcpcd/dist/dhcpcd.conf:1.7 Mon Jul 29 20:39:28 2013 +++ src/external/bsd/dhcpcd/dist/dhcpcd.conf Fri Sep 20 10:56:32 2013 @@ -1,4 +1,4 @@ -# $NetBSD: dhcpcd.conf,v 1.7 2013/07/29 20:39:28 roy Exp $ +# $NetBSD: dhcpcd.conf,v 1.8 2013/09/20 10:56:32 roy Exp $ # A sample configuration for dhcpcd. # See dhcpcd.conf(5) for details. @@ -12,6 +12,9 @@ hostname # Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361. duid +# Persist interface configuration when dhcpcd exits. +persistent + # Rapid commit support. # Safe to enable by default because it requires the equivalent option set # on the server to actually work. Index: src/external/bsd/dhcpcd/dist/dhcpcd.conf.5.in diff -u src/external/bsd/dhcpcd/dist/dhcpcd.conf.5.in:1.3 src/external/bsd/dhcpcd/dist/dhcpcd.conf.5.in:1.4 --- src/external/bsd/dhcpcd/dist/dhcpcd.conf.5.in:1.3 Mon Jul 29 20:39:28 2013 +++ src/external/bsd/dhcpcd/dist/dhcpcd.conf.5.in Fri Sep 20 10:56:32 2013 @@ -1,4 +1,4 @@ -.\" $NetBSD: dhcpcd.conf.5.in,v 1.3 2013/07/29 20:39:28 roy Exp $ +.\" $NetBSD: dhcpcd.conf.5.in,v 1.4 2013/09/20 10:56:32 roy Exp $ .\" Copyright (c) 2006-2013 Roy Marples .\" All rights reserved .\" @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd July 25, 2013 +.Dd September 12, 2013 .Dt DHCPCD.CONF 5 SMM .Os .Sh NAME @@ -91,6 +91,13 @@ such as FireWire and InfiniBand. In most cases, .Nm dhcpcd will set this automatically. +.It Ic dev Ar value +Load the +.Ar value +.Pa /dev +management module. +.Nm dhcpcd +will load the first one found to work, if any. .It Ic env Ar value Push .Ar value @@ -135,6 +142,13 @@ is generated, otherwise DUID-LL is gener The DUID-LLT generated will be held in .Pa @SYSCONFDIR@/dhcpcd.duid and should not be copied to other hosts. +.It Ic persistent +.Nm dhcpcd +normally de-configures the interface and configuration when it exits. +Sometimes, this isn't desirable if, for example, you have root mounted over +NFS or SSH clients connect to this host and they need to be notified of +the host shutting down. +You can use this option to stop this from happening. .It Ic fallback Ar profile Fallback to using this profile if DHCP fails. This allows you to configure a static profile instead of using ZeroConf. @@ -164,9 +178,11 @@ If none is specified, a default is used. If the interface name is 4 characters or less then that is used, otherwise the interface index is used. +You can request more than one ia_na by specifying a unique iaid for each one. .It Ic ia_ta Op Ar iaid Request a DHCPv6 Temporary Address for .Ar iaid . +You can request more than one ia_ta by specifying a unique iaid for each one. .It Ic ia_pd Op Ar iaid Op Ar interface Op / Ar sla_id Op / Ar prefix_len Request a DHCPv6 Delegated Prefix for .Ar iaid . @@ -255,6 +271,10 @@ alongside. .It Ic noarp Don't send any ARP requests. This also disables IPv4LL. +.It Ic nodev +Don't load +.Pa /dev +management modules. .It Ic nogateway Don't install any default routes. .It Ic nohook Ar script @@ -404,8 +424,16 @@ For example If not set then none is sent. Some badly configured DHCP servers reject unknown vendorclassids. To work around it, try and impersonate Windows by using the MSFT vendorclassid. -.It Ic waitip +.It Ic waitip Op 4 | 6 Wait for an address to be assigned before forking to the background. +4 means wait for an IPv4 address to be assigned. +6 means wait for an IPv6 address to be assigned. +If no argument is given, +.Nm +will wait for any address protocol to be assigned. +It is possible to wait for more than one address protocol and +.Nm +will only fork to the background when all waiting conditions are satisfied. .It Ic xidhwaddr Use the last four bytes of the hardware address as the DHCP xid instead of a randomly generated number. Index: src/external/bsd/dhcpcd/dist/net.c diff -u src/external/bsd/dhcpcd/dist/net.c:1.2 src/external/bsd/dhcpcd/dist/net.c:1.3 --- src/external/bsd/dhcpcd/dist/net.c:1.2 Wed Sep 11 18:50:00 2013 +++ src/external/bsd/dhcpcd/dist/net.c Fri Sep 20 10:56:32 2013 @@ -1,5 +1,5 @@ #include <sys/cdefs.h> - __RCSID("$NetBSD: net.c,v 1.2 2013/09/11 18:50:00 drochner Exp $"); + __RCSID("$NetBSD: net.c,v 1.3 2013/09/20 10:56:32 roy Exp $"); /* * dhcpcd - DHCP client daemon @@ -70,10 +70,12 @@ #include "config.h" #include "common.h" +#include "dev.h" #include "dhcp.h" #include "dhcp6.h" #include "if-options.h" -#include "ipv6rs.h" +#include "ipv4.h" +#include "ipv6nd.h" #include "net.h" int socket_afnet = -1; @@ -141,10 +143,11 @@ free_interface(struct interface *ifp) if (ifp == NULL) return; + ipv4_free(ifp); dhcp_free(ifp); ipv6_free(ifp); dhcp6_free(ifp); - ipv6rs_free(ifp); + ipv6nd_free(ifp); free_options(ifp->options); free(ifp); } @@ -226,6 +229,10 @@ discover_interfaces(int argc, char * con #ifdef __linux__ char ifn[IF_NAMESIZE]; #endif +#ifdef INET + const struct sockaddr_in *addr; + const struct sockaddr_in *net; + const struct sockaddr_in *dst; #ifdef INET6 const struct sockaddr_in6 *sin6; int ifa_flags; @@ -264,6 +271,10 @@ discover_interfaces(int argc, char * con #endif } + /* Ensure that the interface name has settled */ + if (!dev_initialized(ifa->ifa_name)) + continue; + /* It's possible for an interface to have >1 AF_LINK. * For our purposes, we use the first one. */ TAILQ_FOREACH(ifp, ifs, next) { @@ -444,11 +455,29 @@ discover_interfaces(int argc, char * con TAILQ_INSERT_TAIL(ifs, ifp, next); } -#ifdef INET6 for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) { - if (ifa->ifa_addr != NULL && - ifa->ifa_addr->sa_family == AF_INET6) - { + if (ifa->ifa_addr == NULL) + continue; + switch(ifa->ifa_addr->sa_family) { +#ifdef INET + case AF_INET: + addr = (const struct sockaddr_in *) + (void *)ifa->ifa_addr; + net = (const struct sockaddr_in *) + (void *)ifa->ifa_netmask; + if (ifa->ifa_flags & IFF_POINTOPOINT) + dst = (const struct sockaddr_in *) + (void *)ifa->ifa_dstaddr; + else + dst = NULL; + ipv4_handleifa(RTM_NEWADDR, ifs, ifa->ifa_name, + &addr->sin_addr, + &net->sin_addr, + dst ? &dst->sin_addr : NULL); + break; +#endif +#ifdef INET6 + case AF_INET6: sin6 = (const struct sockaddr_in6 *) (void *)ifa->ifa_addr; ifa_flags = in6_addr_flags(ifa->ifa_name, @@ -457,6 +486,8 @@ discover_interfaces(int argc, char * con ipv6_handleifa(RTM_NEWADDR, ifs, ifa->ifa_name, &sin6->sin6_addr, ifa_flags); + break; +#endif } } #endif