From 6a765a4ffd2229ccca9d5b9972c618a72ead9eaf Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Tue, 27 Sep 2016 10:17:39 +0000 Subject: [PATCH] Allow DHCPv6 support to be compiled out. --- README | 3 ++- configure | 25 +++++++++++++++++-------- dhcp6.c | 2 ++ dhcp6.h | 9 +++++++-- ipv6nd.c | 23 +++++++++++++++++++++-- 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/README b/README index 7db28cbf..e2389015 100644 --- a/README +++ b/README @@ -22,9 +22,10 @@ Other features maybe dropped as and when required. dhcpcd can also be made smaller by removing the IPv4 or IPv6 stack: * --disable-inet * --disable-inet6 -Or by removing the following features +Or by removing the following features: * --disable-auth * --disable-ipv4ll + * --disable-dhcp6 You can also move the embedded extended configuration from the dhcpcd binary to an external file (LIBEXECDIR/dhcpcd-definitions.conf) diff --git a/configure b/configure index fac3cbb8..59cce565 100755 --- a/configure +++ b/configure @@ -50,6 +50,8 @@ for x do --enable-ipv4ll) IPV4LL=yes; INET=yes;; --disable-ipv6) INET6=no;; --enable-ipv6) INET6=yes;; + --disable-dhcp6) DHCP6=no;; + --enable-dhcp6) DHCP6=yes;; --disable-embedded) EMBEDDED=no;; --enable-embedded) EMBEDDED=yes;; --disable-auth) AUTH=no;; @@ -440,16 +442,30 @@ sunos*) esac if [ -z "$INET" -o "$INET" = yes ]; then + echo "Enabling INET support" echo "CPPFLAGS+= -DINET" >>$CONFIG_MK echo "DHCPCD_SRCS+= arp.c dhcp.c ipv4.c" >>$CONFIG_MK fi if [ -z "$IPV4LL" -o "$IPV4LL" = yes ]; then + echo "Enabling IPv4LL support" echo "CPPFLAGS+= -DIPV4LL" >>$CONFIG_MK echo "DHCPCD_SRCS+= ipv4ll.c" >>$CONFIG_MK fi if [ -z "$INET6" -o "$INET6" = yes ]; then + echo "Enabling INET6 support" echo "CPPFLAGS+= -DINET6" >>$CONFIG_MK - echo "DHCPCD_SRCS+= ipv6.c ipv6nd.c dhcp6.c" >>$CONFIG_MK + echo "DHCPCD_SRCS+= ipv6.c ipv6nd.c" >>$CONFIG_MK +fi +if [ -z "$DHCP6" -o "$DHCP6" = yes ]; then + echo "Enabling DHCPv6 support" + echo "CPPFLAGS+= -DDHCP6" >>$CONFIG_MK + echo "DHCPCD_SRCS+= dhcp6.c" >>$CONFIG_MK +fi +if [ -z "$AUTH" -o "$AUTH" = yes ]; then + echo "Enabling Authentiaction" + echo "CPPFLAGS+= -DAUTH" >>$CONFIG_MK + echo "AUTH_SRCS= auth.c crypt/hmac_md5.c" >>$CONFIG_MK + echo "AUTH_SRCS+= \${MD5_SRC} \${SHA256_SRC}" >>$CONFIG_MK fi echo "Using compiler .. $CC" @@ -490,13 +506,6 @@ else echo "EMBEDDEDINSTALL= _embeddedinstall" >>$CONFIG_MK fi -if [ -z "$AUTH" -o "$AUTH" = yes ]; then - echo "Enabling Authentiaction" - echo "CPPFLAGS+= -DAUTH" >>$CONFIG_MK - echo "AUTH_SRCS= auth.c crypt/hmac_md5.c" >>$CONFIG_MK - echo "AUTH_SRCS+= \${MD5_SRC} \${SHA256_SRC}" >>$CONFIG_MK -fi - if [ "$OS" = linux ]; then printf "Testing for nl80211 ... " cat <_nl80211.c diff --git a/dhcp6.c b/dhcp6.c index 3423f767..6846f414 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -72,6 +72,7 @@ #define IPV6_RECVPKTINFO IPV6_PKTINFO #endif +#ifdef DHCP6 struct dhcp6_op { uint16_t type; const char *name; @@ -3747,3 +3748,4 @@ dhcp6_dump(struct interface *ifp) state->reason = "DUMP6"; return script_runreason(ifp, state->reason); } +#endif diff --git a/dhcp6.h b/dhcp6.h index d967caa2..2fb30f27 100644 --- a/dhcp6.h +++ b/dhcp6.h @@ -230,7 +230,7 @@ struct dhcp6_state { #define D6_COPTION_DATA(o) \ ((const uint8_t *)(o) + sizeof(struct dhcp6_option)) -#ifdef INET6 +#ifdef DHCP6 void dhcp6_printoptions(const struct dhcpcd_ctx *, const struct dhcp_opt *, size_t); const struct ipv6_addr *dhcp6_iffindaddr(const struct interface *ifp, @@ -250,14 +250,19 @@ void dhcp6_drop(struct interface *, const char *); void dhcp6_dropnondelegates(struct interface *ifp); int dhcp6_dump(struct interface *); #else +#define dhcp6_printoptions(a, b, c) {} +#define dhcp6_iffindaddr(a, b, c) (NULL) +#define dhcp6_findaddr(a, b, c) (NULL) #define dhcp6_find_delegates(a) {} #define dhcp6_start(a, b) (0) #define dhcp6_reboot(a) {} #define dhcp6_renew(a) {} -#define dhcp6_env(a, b, c, d, e) {} +#define dhcp6_env(a, b, c, d, e) (0) #define dhcp6_free(a) {} +#define dhcp6_handleifa(a, b) {} #define dhcp6_dadcompleted(a) (0) #define dhcp6_drop(a, b) {} +#define dhcp6_dropnondelegates(a) {} #define dhcp6_dump(a) (-1) #endif diff --git a/ipv6nd.c b/ipv6nd.c index 11415c1f..103b332f 100644 --- a/ipv6nd.c +++ b/ipv6nd.c @@ -712,6 +712,19 @@ try_script: } } +#ifndef DHCP6 +/* If DHCPv6 is compiled out, supply a shim to provide an error message + * if IPv6RA requests DHCPv6. */ +#undef dhcp6_start +static int +dhcp6_start(__unused struct interface *ifp, __unused enum DH6S init_state) +{ + + errno = ENOTSUP; + return -1; +} +#endif + static void ipv6nd_handlera(struct dhcpcd_ctx *dctx, struct interface *ifp, struct icmp6_hdr *icp, size_t len, int hoplimit) @@ -1102,13 +1115,19 @@ ipv6nd_handlera(struct dhcpcd_ctx *dctx, struct interface *ifp, handle_flag: if (!(ifp->options->options & DHCPCD_DHCP6)) goto nodhcp6; +/* Only log a DHCPv6 start error if compiled in or debugging is enabled. */ +#ifdef DHCP6 +#define LOG_DHCP6 LOG_ERR +#else +#define LOG_DHCP6 LOG_DEBUG +#endif if (rap->flags & ND_RA_FLAG_MANAGED) { if (new_data && dhcp6_start(ifp, DH6S_INIT) == -1) - logger(ifp->ctx, LOG_ERR, + logger(ifp->ctx, LOG_DHCP6, "dhcp6_start: %s: %m", ifp->name); } else if (rap->flags & ND_RA_FLAG_OTHER) { if (new_data && dhcp6_start(ifp, DH6S_INFORM) == -1) - logger(ifp->ctx, LOG_ERR, + logger(ifp->ctx, LOG_DHCP6, "dhcp6_start: %s: %m", ifp->name); } else { if (new_data) -- 2.47.2