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

src/dhcp6.h
src/dhcpcd.c
src/dhcpcd.h
src/if-options.c
src/if.c
src/ipv6.c
src/ipv6nd.c
src/script.c

index 53f4a567e701dd44b5876054d7ce1208875bcebe..e1a0a37406ae00fc48efb47cde2c2e05eebb1d2c 100644 (file)
@@ -55,6 +55,8 @@
 #define DHCP6_RECONFIGURE_REQ  18
 #define DHCP6_RECONFIGURE_REPLY        19
 
+#ifdef DHCP6
+
 #define D6_OPTION_CLIENTID             1
 #define D6_OPTION_SERVERID             2
 #define D6_OPTION_IA_NA                        3
@@ -216,7 +218,6 @@ struct dhcp6_state {
        (D6_CSTATE((ifp)) &&                                                   \
        D6_CSTATE((ifp))->reason && dhcp6_dadcompleted((ifp)))
 
-#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,
@@ -236,20 +237,6 @@ void dhcp6_abort(struct interface *);
 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) (0)
-#define dhcp6_free(a) {}
-#define dhcp6_dadcompleted(a) (0)
-#define dhcp6_drop(a, b) {}
-#define dhcp6_dropnondelegates(a) {}
-#define dhcp6_dump(a) (-1)
-#endif
-
-#endif
+#endif /* DHCP6 */
+
+#endif /* DHCP6_H */
index b20b2d0530d9b90f29ece3dcbe25e123af4261aa..32c5317201f12272c749b214b89d26fdfd650e82 100644 (file)
@@ -52,6 +52,7 @@ const char dhcpcd_copyright[] = "Copyright (c) 2006-2019 Roy Marples";
 #include "common.h"
 #include "control.h"
 #include "dev.h"
+#include "dhcp-common.h"
 #include "dhcpcd.h"
 #include "dhcp6.h"
 #include "duid.h"
@@ -151,6 +152,7 @@ free_globals(struct dhcpcd_ctx *ctx)
                free(ctx->nd_opts);
                ctx->nd_opts = NULL;
        }
+#ifdef DHCP6
        if (ctx->dhcp6_opts) {
                for (opt = ctx->dhcp6_opts;
                    ctx->dhcp6_opts_len > 0;
@@ -159,6 +161,7 @@ free_globals(struct dhcpcd_ctx *ctx)
                free(ctx->dhcp6_opts);
                ctx->dhcp6_opts = NULL;
        }
+#endif
 #endif
        if (ctx->vivso) {
                for (opt = ctx->vivso;
@@ -536,7 +539,7 @@ configure_interface1(struct interface *ifp)
                ifo->options |= DHCPCD_IAID;
        }
 
-#ifdef INET6
+#ifdef DHCP6
        if (ifo->ia_len == 0 && ifo->options & DHCPCD_IPV6 &&
            ifp->name[0] != '\0')
        {
@@ -744,7 +747,9 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
                        dhcp_abort(ifp);
 #endif
                        ipv6nd_expire(ifp, 0);
+#ifdef DHCP6
                        dhcp6_abort(ifp);
+#endif
 #else
                        dhcpcd_drop(ifp, 0);
 #endif
@@ -906,7 +911,7 @@ dhcpcd_startinterface(void *arg)
                                ipv6nd_startrs(ifp);
                }
 
-
+#ifdef DHCP6
                if (ifo->options & DHCPCD_DHCP6) {
                        dhcp6_find_delegates(ifp);
 
@@ -923,6 +928,7 @@ dhcpcd_startinterface(void *arg)
                                        logerr("%s: dhcp6_start", ifp->name);
                        }
                }
+#endif
        }
 
 #ifdef INET
@@ -1185,7 +1191,9 @@ if_reboot(struct interface *ifp, int argc, char **argv)
 #ifdef INET
        dhcp_reboot_newopts(ifp, oldopts);
 #endif
+#ifdef DHCP6
        dhcp6_reboot(ifp);
+#endif
        dhcpcd_prestartinterface(ifp);
 }
 
@@ -1271,7 +1279,9 @@ dhcpcd_ifrenew(struct interface *ifp)
 #define DHCPCD_RARENEW (DHCPCD_IPV6 | DHCPCD_IPV6RS)
        if ((ifp->options->options & DHCPCD_RARENEW) == DHCPCD_RARENEW)
                ipv6nd_startrs(ifp);
+#ifdef DHCP6
        dhcp6_renew(ifp);
+#endif
 }
 
 static void
@@ -1365,8 +1375,10 @@ dhcpcd_getinterfaces(void *arg)
                        len++;
                if (RS_STATE_RUNNING(ifp))
                        len++;
+#ifdef DHCP6
                if (D6_STATE_RUNNING(ifp))
                        len++;
+#endif
        }
        if (write(fd->fd, &len, sizeof(len)) != sizeof(len))
                return;
@@ -1685,9 +1697,11 @@ main(int argc, char **argv)
                        printf("\nND options:\n");
                        ipv6nd_printoptions(&ctx,
                            ifo->nd_override, ifo->nd_override_len);
+#ifdef DHCP6
                        printf("\nDHCPv6 options:\n");
                        dhcp6_printoptions(&ctx,
                            ifo->dhcp6_override, ifo->dhcp6_override_len);
+#endif
                }
 #endif
                goto exit_success;
@@ -1823,8 +1837,13 @@ printpidfile:
 #endif
                }
                if (family == 0 || family == AF_INET6) {
+#ifdef DHCP6
                        if (dhcp6_dump(ifp) == -1)
                                i = -1;
+#else
+                       if (family == AF_INET6)
+                               logerrx("No DHCP6 support");
+#endif
                }
                if (i == -1)
                        goto exit_failure;
index 06602baee740e34684700df708d82fe5094d4c1d..16b9ad2590514a9791a0a9e78bf86e4f0831474c 100644 (file)
@@ -198,8 +198,10 @@ struct dhcpcd_ctx {
 
        struct dhcp_opt *nd_opts;
        size_t nd_opts_len;
+#ifdef DHCP6
        struct dhcp_opt *dhcp6_opts;
        size_t dhcp6_opts_len;
+#endif
 
 #ifndef __linux__
        int ra_global;
index 14a49df27d3f6b2e61febf7b2dc615a2dfdc09ed..dd10cb59bc48c0ed26121c5cc87b6bf7d14536d1 100644 (file)
@@ -541,6 +541,7 @@ set_option_space(struct dhcpcd_ctx *ctx,
                return arg + strlen("nd_");
        }
 
+#ifdef DHCP6
        if (strncmp(arg, "dhcp6_", strlen("dhcp6_")) == 0) {
                *d = ctx->dhcp6_opts;
                *dl = ctx->dhcp6_opts_len;
@@ -553,6 +554,7 @@ set_option_space(struct dhcpcd_ctx *ctx,
                return arg + strlen("dhcp6_");
        }
 #endif
+#endif
 
 #ifdef INET
        *d = ctx->dhcp_opts;
@@ -2430,8 +2432,10 @@ read_config(struct dhcpcd_ctx *ctx,
 #ifdef INET6
                ctx->nd_opts = ifo->nd_override;
                ctx->nd_opts_len = ifo->nd_override_len;
+#ifdef DHCP6
                ctx->dhcp6_opts = ifo->dhcp6_override;
                ctx->dhcp6_opts_len = ifo->dhcp6_override_len;
+#endif
 #else
                for (i = 0, opt = ifo->nd_override;
                    i < ifo->nd_override_len;
index c0d26301d86b314ccbfc48a43aed22fe13ae9144..f6d7ab097c473c643bbf9c3589decac62957e858 100644 (file)
--- a/src/if.c
+++ b/src/if.c
@@ -85,7 +85,9 @@ if_free(struct interface *ifp)
        dhcp_free(ifp);
        ipv4_free(ifp);
 #endif
+#ifdef DHCP6
        dhcp6_free(ifp);
+#endif
        ipv6nd_free(ifp);
        ipv6_free(ifp);
        rt_freeif(ifp);
@@ -740,10 +742,12 @@ if_cmp(const struct interface *si, const struct interface *ti)
                return -1;
        if (!RS_STATE_RUNNING(si) && RS_STATE_RUNNING(ti))
                return 1;
+#ifdef DHCP6
        if (D6_STATE_RUNNING(si) && !D6_STATE_RUNNING(ti))
                return -1;
        if (!D6_STATE_RUNNING(si) && D6_STATE_RUNNING(ti))
                return 1;
+#endif
 
 #ifdef INET
        /* Special attention needed here due to states and IPv4LL. */
index 1f1e36c0cf1246e273569a8ae7bf534785c3cb93..62ce9cc611a438d31f37fe0baf4efc0b6aec8ec6 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/socket.h>
 #include <sys/stat.h>
 
+#include <arpa/inet.h>
 #include <net/if.h>
 #include <net/route.h>
 #include <netinet/in.h>
@@ -882,10 +883,14 @@ ipv6_findaddrmatch(const struct ipv6_addr *addr, const struct in6_addr *match,
 struct ipv6_addr *
 ipv6_findaddr(struct dhcpcd_ctx *ctx, const struct in6_addr *addr, unsigned int flags)
 {
-       struct ipv6_addr *dap, *nap;
+       struct ipv6_addr *nap;
+#ifdef DHCP6
+       struct ipv6_addr *dap;
+#endif
 
-       dap = dhcp6_findaddr(ctx, addr, flags);
        nap = ipv6nd_findaddr(ctx, addr, flags);
+#ifdef DHCP6
+       dap = dhcp6_findaddr(ctx, addr, flags);
        if (!dap && !nap)
                return NULL;
        if (dap && !nap)
@@ -895,6 +900,9 @@ ipv6_findaddr(struct dhcpcd_ctx *ctx, const struct in6_addr *addr, unsigned int
        if (nap->iface->metric < dap->iface->metric)
                return nap;
        return dap;
+#else
+       return nap;
+#endif
 }
 
 ssize_t
@@ -1183,8 +1191,10 @@ ipv6_hasaddr(const struct interface *ifp)
 
        if (ipv6nd_iffindaddr(ifp, NULL, 0) != NULL)
                return 1;
+#ifdef DHCP6
        if (dhcp6_iffindaddr(ifp, NULL, 0) != NULL)
                return 1;
+#endif
        return 0;
 }
 
@@ -2269,6 +2279,7 @@ inet6_raroutes(struct rt_head *routes, struct dhcpcd_ctx *ctx, int expired,
        return 0;
 }
 
+#ifdef DHCP6
 static int
 inet6_dhcproutes(struct rt_head *routes, struct dhcpcd_ctx *ctx,
     enum DH6S dstate)
@@ -2292,6 +2303,7 @@ inet6_dhcproutes(struct rt_head *routes, struct dhcpcd_ctx *ctx,
        }
        return 0;
 }
+#endif
 
 bool
 inet6_getroutes(struct dhcpcd_ctx *ctx, struct rt_head *routes)
@@ -2307,6 +2319,7 @@ inet6_getroutes(struct dhcpcd_ctx *ctx, struct rt_head *routes)
        if (inet6_raroutes(routes, ctx, 0, &have_default) == -1)
                return false;
 
+#ifdef DHCP6
        /* We have no way of knowing if prefixes added by DHCP are reachable
         * or not, so we have to assume they are.
         * Add bound before delegated so we can prefer interfaces better */
@@ -2314,6 +2327,7 @@ inet6_getroutes(struct dhcpcd_ctx *ctx, struct rt_head *routes)
                return false;
        if (inet6_dhcproutes(routes, ctx, DH6S_DELEGATED) == -1)
                return false;
+#endif
 
 #ifdef HAVE_ROUTE_METRIC
        /* If we have an unreachable router, we really do need to remove the
index 9a53fc92f42c10cc52419badf11ba5b6b7752aa8..b524a9e86775060238101d0f5b590aa1ed1b0206 100644 (file)
@@ -45,6 +45,7 @@
 #define ELOOP_QUEUE 3
 #include "common.h"
 #include "dhcpcd.h"
+#include "dhcp-common.h"
 #include "dhcp6.h"
 #include "eloop.h"
 #include "if.h"
@@ -328,7 +329,9 @@ ipv6nd_sendrsprobe(void *arg)
        else {
                logwarnx("%s: no IPv6 Routers available", ifp->name);
                ipv6nd_drop(ifp);
+#ifdef DHCP6
                dhcp6_dropnondelegates(ifp);
+#endif
        }
 }
 
@@ -855,7 +858,10 @@ try_script:
 #ifndef DHCP6
 /* If DHCPv6 is compiled out, supply a shim to provide an error message
  * if IPv6RA requests DHCPv6. */
-#undef dhcp6_start
+enum DH6S {
+       DH6S_REQUEST,
+       DH6S_INFORM,
+};
 static int
 dhcp6_start(__unused struct interface *ifp, __unused enum DH6S init_state)
 {
@@ -1239,8 +1245,10 @@ handle_flag:
                if (new_data && dhcp6_start(ifp, DH6S_INFORM) == -1)
                        LOG_DHCP6("dhcp6_start: %s", ifp->name);
        } else {
+#ifdef DHCP6
                if (new_data)
                        logdebugx("%s: No DHCPv6 instruction in RA", ifp->name);
+#endif
 nodhcp6:
                if (ifp->ctx->options & DHCPCD_TEST) {
                        eloop_exit(ifp->ctx->eloop, EXIT_SUCCESS);
@@ -1451,19 +1459,21 @@ ipv6nd_expirera(void *arg)
        struct interface *ifp;
        struct ra *rap, *ran;
        struct timespec now, lt, expire, next;
-       uint8_t expired, anyvalid, valid, validone;
+       bool expired, valid, validone;
        struct ipv6_addr *ia;
+#ifdef DHCP6
+       bool anyvalid = false;
+#endif
 
        ifp = arg;
        clock_gettime(CLOCK_MONOTONIC, &now);
-       expired = 0;
+       expired = false;
        timespecclear(&next);
 
-       anyvalid = 0;
        TAILQ_FOREACH_SAFE(rap, ifp->ctx->ra_routers, next, ran) {
                if (rap->iface != ifp)
                        continue;
-               valid = validone = 0;
+               valid = validone = false;
                if (rap->lifetime) {
                        lt.tv_sec = (time_t)rap->lifetime;
                        lt.tv_nsec = 0;
@@ -1477,7 +1487,7 @@ ipv6nd_expirera(void *arg)
                                        rap->lifetime = 0;
                                }
                        } else {
-                               valid = 1;
+                               valid = true;
                                timespecsub(&expire, &now, &lt);
                                if (!timespecisset(&next) ||
                                    timespeccmp(&next, &lt, >))
@@ -1492,7 +1502,7 @@ ipv6nd_expirera(void *arg)
                        if (ia->prefix_vltime == 0)
                                continue;
                        if (ia->prefix_vltime == ND6_INFINITE_LIFETIME) {
-                               validone = 1;
+                               validone = true;
                                continue;
                        }
                        lt.tv_sec = (time_t)ia->prefix_vltime;
@@ -1510,13 +1520,13 @@ ipv6nd_expirera(void *arg)
                                ia->prefix_vltime = ia->prefix_pltime = 0;
                                ia->flags &=
                                    ~(IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED);
-                               expired = 1;
+                               expired = true;
                        } else {
                                timespecsub(&expire, &now, &lt);
                                if (!timespecisset(&next) ||
                                    timespeccmp(&next, &lt, >))
                                        next = lt;
-                               validone = 1;
+                               validone = true;
                        }
                }
 
@@ -1529,8 +1539,10 @@ ipv6nd_expirera(void *arg)
                 * as well punt it. */
                if (!valid && !validone)
                        ipv6nd_free_ra(rap);
+#ifdef DHCP6
                else
-                       anyvalid = 1;
+                       anyvalid = true;
+#endif
        }
 
        if (timespecisset(&next))
@@ -1541,9 +1553,11 @@ ipv6nd_expirera(void *arg)
                script_runreason(ifp, "ROUTERADVERT");
        }
 
+#ifdef DHCP6
        /* No valid routers? Kill any DHCPv6. */
        if (!anyvalid)
                dhcp6_dropnondelegates(ifp);
+#endif
 }
 
 void
index 965e8caf74ae218d427f500137f722be0b25c8c3..96104b10eea2a4289ecc65a7686437cffd590131 100644 (file)
@@ -251,7 +251,7 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
        const struct ipv4ll_state *istate;
 #endif
 #endif
-#ifdef INET6
+#ifdef DHCP6
        const struct dhcp6_state *d6_state;
 #endif
 
@@ -261,14 +261,16 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
        istate = IPV4LL_CSTATE(ifp);
 #endif
 #endif
-#ifdef INET6
+#ifdef DHCP6
        d6_state = D6_CSTATE(ifp);
 #endif
        if (strcmp(reason, "TEST") == 0) {
                if (1 == 2) {}
 #ifdef INET6
+#ifdef DHCP6
                else if (d6_state && d6_state->new)
                        protocol = PROTO_DHCP6;
+#endif
                else if (ipv6nd_hasra(ifp))
                        protocol = PROTO_RA;
 #endif
@@ -284,8 +286,10 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
 #ifdef INET6
        else if (strcmp(reason, "STATIC6") == 0)
                protocol = PROTO_STATIC6;
+#ifdef DHCP6
        else if (reason[strlen(reason) - 1] == '6')
                protocol = PROTO_DHCP6;
+#endif
        else if (strcmp(reason, "ROUTERADVERT") == 0)
                protocol = PROTO_RA;
 #endif
@@ -379,7 +383,9 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
 #endif
 #ifdef INET6
            || (protocol == PROTO_STATIC6 && IPV6_STATE_RUNNING(ifp))
+#ifdef DHCP6
            || (protocol == PROTO_DHCP6 && d6_state && d6_state->new)
+#endif
            || (protocol == PROTO_RA && ipv6nd_hasra(ifp))
 #endif
            )
@@ -463,7 +469,7 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
                        goto eexit;
        }
 #endif
-#ifdef INET6
+#ifdef DHCP6
        if (protocol == PROTO_DHCP6 && d6_state && d6_state->old) {
                n = dhcp6_env(NULL, NULL, ifp,
                    d6_state->old, d6_state->old_len);
@@ -534,6 +540,7 @@ dumplease:
                        elen += (size_t)n;
                }
        }
+#ifdef DHCP6
        if (protocol == PROTO_DHCP6 && D6_STATE_RUNNING(ifp)) {
                n = dhcp6_env(NULL, NULL, ifp,
                    d6_state->new, d6_state->new_len);
@@ -550,6 +557,7 @@ dumplease:
                        elen += (size_t)n;
                }
        }
+#endif
        if (protocol == PROTO_RA) {
                n = ipv6nd_env(NULL, NULL, ifp);
                if (n > 0) {
@@ -632,7 +640,7 @@ send_interface(struct fd_list *fd, const struct interface *ifp)
 #ifdef INET
        const struct dhcp_state *d;
 #endif
-#ifdef INET6
+#ifdef DHCP6
        const struct dhcp6_state *d6;
 #endif
 
@@ -672,11 +680,13 @@ send_interface(struct fd_list *fd, const struct interface *ifp)
                if (send_interface1(fd, ifp, "ROUTERADVERT") == -1)
                        retval = -1;
        }
+#ifdef DHCP6
        if (D6_STATE_RUNNING(ifp)) {
                d6 = D6_CSTATE(ifp);
                if (send_interface1(fd, ifp, d6->reason) == -1)
                        retval = -1;
        }
+#endif
 #endif
 
        return retval;