]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Add nodhcp and nodhcp6 directives.
authorRoy Marples <roy@marples.name>
Wed, 29 Jan 2014 14:05:58 +0000 (14:05 +0000)
committerRoy Marples <roy@marples.name>
Wed, 29 Jan 2014 14:05:58 +0000 (14:05 +0000)
Thanks to Sebastian Huber for the initial patch and testing.

arp.c
dhcp.c
dhcp6.c
dhcpcd.conf.5.in
if-options.c
if-options.h
ipv4ll.c

diff --git a/arp.c b/arp.c
index ea8a73c7e06426c6d80a8c4083fb23c93772fd19..13779a480ada14541a6dc40362033c5b683d46ce 100644 (file)
--- 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 e0edf86d4296d7bebeee3c3bd379e2e6409940c2..1641f44cc6d3be9ff77b30607be3ef90c3d60c93 100644 (file)
--- 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 ebd4cabd9258a7e28bec9c791f8f04b93b288510..d3c6f07f4f8ad80c420a3847a32ad9faef5607bf 100644 (file)
--- 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;
 
index a901aa0dab816f102ab440ea69b78703ac50061b..888b3c144875e3cf92be976a2720158235efe61c 100644 (file)
@@ -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
index d30220e74ac43534a00ea0f184f9671f99383e36..c7930096e9c4d89e0c5d6248e552c33aa1a41523 100644 (file)
@@ -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;
index c0a3e80c10c44702be7312941d371f39f7b852fb..77c0c3e59ae1f0a4d85c200adf35dc1db83b108d 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2014 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
 #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[];
 
index 4aab862a2779039ae8c6dcab2009a4557ed2c155..cab565d156a8c6777fb5a517cb7e184a3ace975e 100644 (file)
--- a/ipv4ll.c
+++ b/ipv4ll.c
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2014 Roy Marples <roy@marples.name>
  * 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);
        }