From: Roy Marples Date: Wed, 29 Jan 2014 14:05:58 +0000 (+0000) Subject: Add nodhcp and nodhcp6 directives. X-Git-Tag: v6.3.0~84 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d4154ba7a8bea0764014fcb89643baa39bcdcda5;p=thirdparty%2Fdhcpcd.git Add nodhcp and nodhcp6 directives. Thanks to Sebastian Huber for the initial patch and testing. --- diff --git a/arp.c b/arp.c index ea8a73c7..13779a48 100644 --- a/arp.c +++ b/arp.c @@ -245,6 +245,9 @@ arp_announce(void *arg) return; } if (state->new->cookie != htonl(MAGIC_COOKIE)) { + /* Check if doing DHCP */ + if (!(ifp->options->options & DHCPCD_DHCP)) + return; /* We should pretend to be at the end * of the DHCP negotation cycle unless we rebooted */ if (state->interval != 0) diff --git a/dhcp.c b/dhcp.c index e0edf86d..1641f44c 100644 --- a/dhcp.c +++ b/dhcp.c @@ -2660,7 +2660,7 @@ dhcp_start(struct interface *ifp) return; } - if (dhcp_open(ifp) == -1) + if (ifo->options & DHCPCD_DHCP && dhcp_open(ifp) == -1) return; if (ifo->options & DHCPCD_INFORM) { @@ -2709,10 +2709,21 @@ dhcp_start(struct interface *ifp) } } } + + if (!(ifo->options & DHCPCD_DHCP)) { + if (ifo->options & DHCPCD_IPV4LL) { + if (state->offer && state->offer->cookie != 0) { + free(state->offer); + state->offer = NULL; + } + ipv4ll_start(ifp); + } + return; + } + if (state->offer == NULL) dhcp_discover(ifp); - else if (state->offer->cookie == 0 && - ifp->options->options & DHCPCD_IPV4LL) + else if (state->offer->cookie == 0 && ifo->options & DHCPCD_IPV4LL) ipv4ll_start(ifp); else dhcp_reboot(ifp); diff --git a/dhcp6.c b/dhcp6.c index ebd4cabd..d3c6f07f 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -2491,6 +2491,9 @@ dhcp6_start(struct interface *ifp, enum DH6S init_state) return 0; } + if (!(ifp->options->options & DHCPCD_DHCP6)) + return 0; + if (sock == -1 && dhcp6_open() == -1) return -1; diff --git a/dhcpcd.conf.5.in b/dhcpcd.conf.5.in index a901aa0d..888b3c14 100644 --- a/dhcpcd.conf.5.in +++ b/dhcpcd.conf.5.in @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd January 24, 2014 +.Dd January 29, 2014 .Dt DHCPCD.CONF 5 .Os .Sh NAME @@ -323,6 +323,12 @@ Don't require authentication even though we requested it. Don't load .Pa /dev management modules. +.It Ic nodhcp +Don't start DHCP or listen to DHCP messages. +This is only useful when allowing IPv4LL. +.It Ic nodhcp6 +Don't start DHCPv6 or listen to DHCPv6 messages. +Normally DHCPv6 is started by a RA instruction or configuration. .It Ic nogateway Don't install any default routes. .It Ic nohook Ar script diff --git a/if-options.c b/if-options.c index d30220e7..c7930096 100644 --- a/if-options.c +++ b/if-options.c @@ -84,6 +84,8 @@ unsigned long long options = 0; #define O_AUTHPROTOCOL O_BASE + 25 #define O_AUTHTOKEN O_BASE + 26 #define O_AUTHNOTREQUIRED O_BASE + 27 +#define O_NODHCP O_BASE + 28 +#define O_NODHCP6 O_BASE + 29 char *dev_load; @@ -162,6 +164,8 @@ const struct option cf_options[] = { {"authprotocol", required_argument, NULL, O_AUTHPROTOCOL}, {"authtoken", required_argument, NULL, O_AUTHTOKEN}, {"noauthrequired", no_argument, NULL, O_AUTHNOTREQUIRED}, + {"nodhcp", no_argument, NULL, O_NODHCP}, + {"nodhcp6", no_argument, NULL, O_NODHCP6}, {NULL, 0, NULL, '\0'} }; @@ -1697,6 +1701,12 @@ parse_option(const char *ifname, struct if_options *ifo, case O_AUTHNOTREQUIRED: ifo->auth.options &= ~DHCPCD_AUTH_REQUIRE; break; + case O_NODHCP: + ifo->options &= ~DHCPCD_DHCP; + break; + case O_NODHCP6: + ifo->options &= ~DHCPCD_DHCP6; + break; default: return 0; } @@ -1773,11 +1783,12 @@ read_config(const char *file, ifo->options |= DHCPCD_DEV; #endif #ifdef INET - ifo->options |= DHCPCD_IPV4 | DHCPCD_IPV4LL; + ifo->options |= DHCPCD_IPV4 | DHCPCD_DHCP | DHCPCD_IPV4LL; ifo->options |= DHCPCD_GATEWAY | DHCPCD_ARP; #endif #ifdef INET6 ifo->options |= DHCPCD_IPV6 | DHCPCD_IPV6RS | DHCPCD_IPV6RA_REQRDNSS; + ifo->options |= DHCPCD_DHCP6; ifo->dadtransmits = ipv6_dadtransmits(ifname); #endif ifo->timeout = DEFAULT_TIMEOUT; diff --git a/if-options.h b/if-options.h index c0a3e80c..77c0c3e5 100644 --- a/if-options.h +++ b/if-options.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2013 Roy Marples + * Copyright (c) 2006-2014 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -100,6 +100,8 @@ #define DHCPCD_WAITIP6 (1ULL << 46) #define DHCPCD_DEV (1ULL << 47) #define DHCPCD_IAID (1ULL << 48) +#define DHCPCD_DHCP (1ULL << 49) +#define DHCPCD_DHCP6 (1ULL << 50) extern const struct option cf_options[]; diff --git a/ipv4ll.c b/ipv4ll.c index 4aab862a..cab565d1 100644 --- a/ipv4ll.c +++ b/ipv4ll.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2013 Roy Marples + * Copyright (c) 2006-2014 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -158,8 +158,12 @@ ipv4ll_handle_failure(void *arg) if (++state->conflicts > MAX_CONFLICTS) { syslog(LOG_ERR, "%s: failed to acquire an IPv4LL address", ifp->name); - state->interval = RATE_LIMIT_INTERVAL / 2; - dhcp_discover(ifp); + if (ifp->options->options & DHCPCD_DHCP) { + state->interval = RATE_LIMIT_INTERVAL / 2; + dhcp_discover(ifp); + } else + eloop_add_timeout_sec(RATE_LIMIT_INTERVAL, + ipv4ll_start, ifp); } else { eloop_timeout_add_sec(PROBE_WAIT, ipv4ll_start, ifp); }