]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
IP6ND: Remove #defines for functions when INET6 is disabled
authorRoy Marples <roy@marples.name>
Wed, 23 Jan 2019 13:50:34 +0000 (13:50 +0000)
committerRoy Marples <roy@marples.name>
Wed, 23 Jan 2019 13:50:34 +0000 (13:50 +0000)
This allows us to optimise the code better and hopefully
become less error prone.

src/dhcpcd.c
src/if.c
src/ipv6.h
src/ipv6nd.h

index 32c5317201f12272c749b214b89d26fdfd650e82..72bfe5e702d11faa897f1273ac9c2665f721a811 100644 (file)
@@ -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);
index f6d7ab097c473c643bbf9c3589decac62957e858..8590e6e0d98748f1508f59f300893b15b59e3b9a 100644 (file)
--- 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;
index b6ed17b7a6f2b82a5b834a3234244e8ab2edfbcb..bc48d42e280a6e5c3f78e4234c50b74b480bab95 100644 (file)
 #  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 */
index 449a4dc9cc511c024afc2c83bdd9a0af65644448..07f2d02e19ebd0c9fb800cede30fbe408b0b278d 100644 (file)
@@ -28,6 +28,8 @@
 #ifndef IPV6ND_H
 #define IPV6ND_H
 
+#ifdef INET6
+
 #include <time.h>
 
 #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 */