From: Roy Marples Date: Wed, 23 Jan 2019 13:50:34 +0000 (+0000) Subject: IP6ND: Remove #defines for functions when INET6 is disabled X-Git-Tag: v7.1.1~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=81917252aca2073c8e7a80f80ea46f9b23e37607;p=thirdparty%2Fdhcpcd.git IP6ND: Remove #defines for functions when INET6 is disabled This allows us to optimise the code better and hopefully become less error prone. --- diff --git a/src/dhcpcd.c b/src/dhcpcd.c index 32c53172..72bfe5e7 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -208,23 +208,39 @@ int dhcpcd_ifafwaiting(const struct interface *ifp) { unsigned long long opts; + bool foundany = false; if (ifp->active != IF_ACTIVE_USER) return AF_MAX; +#define DHCPCD_WAITALL (DHCPCD_WAITIP4 | DHCPCD_WAITIP6) opts = ifp->options->options; #ifdef INET - if (opts & DHCPCD_WAITIP4 && !ipv4_hasaddr(ifp)) - return AF_INET; + if (opts & DHCPCD_WAITIP4 || + (opts & DHCPCD_WAITIP && !(opts & DHCPCD_WAITALL))) + { + bool foundaddr = ipv4_hasaddr(ifp); + + if (opts & DHCPCD_WAITIP4 && !foundaddr) + return AF_INET; + if (foundaddr) + foundany = true; + } #endif - if (opts & DHCPCD_WAITIP6 && !ipv6_hasaddr(ifp)) - return AF_INET6; - if (opts & DHCPCD_WAITIP && - !(opts & (DHCPCD_WAITIP4 | DHCPCD_WAITIP6)) && -#ifdef INET - !ipv4_hasaddr(ifp) && +#ifdef INET6 + if (opts & DHCPCD_WAITIP6 || + (opts & DHCPCD_WAITIP && !(opts & DHCPCD_WAITALL))) + { + bool foundaddr = ipv6_hasaddr(ifp); + + if (opts & DHCPCD_WAITIP6 && !foundaddr) + return AF_INET; + if (foundaddr) + foundany = true; + } #endif - !ipv6_hasaddr(ifp)) + + if (opts & DHCPCD_WAITIP && !(opts & DHCPCD_WAITALL) && !foundany) return AF_UNSPEC; return AF_MAX; } @@ -246,9 +262,11 @@ dhcpcd_afwaiting(const struct dhcpcd_ctx *ctx) ipv4_hasaddr(ifp)) opts &= ~(DHCPCD_WAITIP | DHCPCD_WAITIP4); #endif +#ifdef INET6 if (opts & (DHCPCD_WAITIP | DHCPCD_WAITIP6) && ipv6_hasaddr(ifp)) opts &= ~(DHCPCD_WAITIP | DHCPCD_WAITIP6); +#endif if (!(opts & DHCPCD_WAITOPTS)) break; } @@ -746,7 +764,9 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags, #ifdef INET dhcp_abort(ifp); #endif +#ifdef INET6 ipv6nd_expire(ifp, 0); +#endif #ifdef DHCP6 dhcp6_abort(ifp); #endif @@ -786,6 +806,7 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags, } dhcpcd_initstate(ifp, 0); script_runreason(ifp, "CARRIER"); +#ifdef INET6 #ifdef NOCARRIER_PRESERVE_IP /* Set any IPv6 Routers we remembered to expire * faster than they would normally as we @@ -794,6 +815,7 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags, #endif /* RFC4941 Section 3.5 */ ipv6_gentempifid(ifp); +#endif dhcpcd_startinterface(ifp); } } @@ -899,10 +921,12 @@ dhcpcd_startinterface(void *arg) #endif } +#ifdef INET6 if (ifo->options & DHCPCD_IPV6 && ipv6_start(ifp) == -1) { logerr("%s: ipv6_start", ifp->name); ifo->options &= ~DHCPCD_IPV6; } + if (ifo->options & DHCPCD_IPV6) { if (ifp->active == IF_ACTIVE_USER) { ipv6_startstatic(ifp); @@ -930,6 +954,7 @@ dhcpcd_startinterface(void *arg) } #endif } +#endif #ifdef INET if (ifo->options & DHCPCD_IPV4 && ifp->active == IF_ACTIVE_USER) { @@ -1276,9 +1301,11 @@ dhcpcd_ifrenew(struct interface *ifp) #ifdef INET dhcp_renew(ifp); #endif +#ifdef INET6 #define DHCPCD_RARENEW (DHCPCD_IPV6 | DHCPCD_IPV6RS) if ((ifp->options->options & DHCPCD_RARENEW) == DHCPCD_RARENEW) ipv6nd_startrs(ifp); +#endif #ifdef DHCP6 dhcp6_renew(ifp); #endif @@ -1371,10 +1398,12 @@ dhcpcd_getinterfaces(void *arg) if (IPV4LL_STATE_RUNNING(ifp)) len++; #endif +#ifdef INET6 if (IPV6_STATE_RUNNING(ifp)) len++; if (RS_STATE_RUNNING(ifp)) len++; +#endif #ifdef DHCP6 if (D6_STATE_RUNNING(ifp)) len++; @@ -2102,7 +2131,9 @@ exit1: } if_closesockets(&ctx); free_globals(&ctx); +#ifdef INET6 ipv6_ctxfree(&ctx); +#endif dev_stop(&ctx); eloop_free(ctx.eloop); free(ctx.iov[0].iov_base); diff --git a/src/if.c b/src/if.c index f6d7ab09..8590e6e0 100644 --- a/src/if.c +++ b/src/if.c @@ -88,8 +88,10 @@ if_free(struct interface *ifp) #ifdef DHCP6 dhcp6_free(ifp); #endif +#ifdef INET6 ipv6nd_free(ifp); ipv6_free(ifp); +#endif rt_freeif(ifp); free_options(ifp->ctx, ifp->options); free(ifp); @@ -738,10 +740,12 @@ if_cmp(const struct interface *si, const struct interface *ti) if (!D_STATE_RUNNING(si) && D_STATE_RUNNING(ti)) return 1; #endif +#ifdef INET6 if (RS_STATE_RUNNING(si) && !RS_STATE_RUNNING(ti)) return -1; if (!RS_STATE_RUNNING(si) && RS_STATE_RUNNING(ti)) return 1; +#endif #ifdef DHCP6 if (D6_STATE_RUNNING(si) && !D6_STATE_RUNNING(ti)) return -1; diff --git a/src/ipv6.h b/src/ipv6.h index b6ed17b7..bc48d42e 100644 --- a/src/ipv6.h +++ b/src/ipv6.h @@ -140,6 +140,7 @@ # define IN6_IFF_DETACHED 0 #endif +#ifdef INET6 TAILQ_HEAD(ipv6_addrhead, ipv6_addr); struct ipv6_addr { TAILQ_ENTRY(ipv6_addr) next; @@ -223,7 +224,6 @@ struct ipv6_state { ((const struct ipv6_state *)(ifp)->if_data[IF_DATA_IPV6]) #define IPV6_STATE_RUNNING(ifp) ipv6_staticdadcompleted((ifp)) -#ifdef INET6 int ipv6_init(struct dhcpcd_ctx *); int ipv6_makestableprivate(struct in6_addr *addr, @@ -282,16 +282,6 @@ int ipv6_startstatic(struct interface *); ssize_t ipv6_env(char **, const char *, const struct interface *); void ipv6_ctxfree(struct dhcpcd_ctx *); bool inet6_getroutes(struct dhcpcd_ctx *, struct rt_head *); +#endif /* INET6 */ -#else -#define ipv6_start(a) (-1) -#define ipv6_startstatic(a) -#define ipv6_staticdadcompleted(a) (0) -#define ipv6_hasaddr(a) (0) -#define ipv6_free_ll_callbacks(a) {} -#define ipv6_free(a) {} -#define ipv6_ctxfree(a) {} -#define ipv6_gentempifid(a) {} -#endif - -#endif +#endif /* INET6_H */ diff --git a/src/ipv6nd.h b/src/ipv6nd.h index 449a4dc9..07f2d02e 100644 --- a/src/ipv6nd.h +++ b/src/ipv6nd.h @@ -28,6 +28,8 @@ #ifndef IPV6ND_H #define IPV6ND_H +#ifdef INET6 + #include #include "config.h" @@ -87,7 +89,6 @@ struct rs_state { #define IPV6ND_REACHABLE (1 << 0) #define IPV6ND_ROUTER (1 << 1) -#ifdef INET6 void ipv6nd_printoptions(const struct dhcpcd_ctx *, const struct dhcp_opt *, size_t); void ipv6nd_startrs(struct interface *); @@ -106,12 +107,6 @@ void ipv6nd_advertise(struct ipv6_addr *); void ipv6nd_expire(struct interface *, uint32_t); void ipv6nd_drop(struct interface *); void ipv6nd_neighbour(struct dhcpcd_ctx *, struct in6_addr *, int); -#else -#define ipv6nd_startrs(a) {} -#define ipv6nd_free(a) {} -#define ipv6nd_hasra(a) (0) -#define ipv6nd_dadcompleted(a) (0) -#define ipv6nd_expire(a, b) {} -#endif +#endif /* INET6 */ -#endif +#endif /* IPV6ND_H */