#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
(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,
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 */
#include "common.h"
#include "control.h"
#include "dev.h"
+#include "dhcp-common.h"
#include "dhcpcd.h"
#include "dhcp6.h"
#include "duid.h"
free(ctx->nd_opts);
ctx->nd_opts = NULL;
}
+#ifdef DHCP6
if (ctx->dhcp6_opts) {
for (opt = ctx->dhcp6_opts;
ctx->dhcp6_opts_len > 0;
free(ctx->dhcp6_opts);
ctx->dhcp6_opts = NULL;
}
+#endif
#endif
if (ctx->vivso) {
for (opt = ctx->vivso;
ifo->options |= DHCPCD_IAID;
}
-#ifdef INET6
+#ifdef DHCP6
if (ifo->ia_len == 0 && ifo->options & DHCPCD_IPV6 &&
ifp->name[0] != '\0')
{
dhcp_abort(ifp);
#endif
ipv6nd_expire(ifp, 0);
+#ifdef DHCP6
dhcp6_abort(ifp);
+#endif
#else
dhcpcd_drop(ifp, 0);
#endif
ipv6nd_startrs(ifp);
}
-
+#ifdef DHCP6
if (ifo->options & DHCPCD_DHCP6) {
dhcp6_find_delegates(ifp);
logerr("%s: dhcp6_start", ifp->name);
}
}
+#endif
}
#ifdef INET
#ifdef INET
dhcp_reboot_newopts(ifp, oldopts);
#endif
+#ifdef DHCP6
dhcp6_reboot(ifp);
+#endif
dhcpcd_prestartinterface(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
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;
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;
#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;
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;
return arg + strlen("nd_");
}
+#ifdef DHCP6
if (strncmp(arg, "dhcp6_", strlen("dhcp6_")) == 0) {
*d = ctx->dhcp6_opts;
*dl = ctx->dhcp6_opts_len;
return arg + strlen("dhcp6_");
}
#endif
+#endif
#ifdef INET
*d = ctx->dhcp_opts;
#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;
dhcp_free(ifp);
ipv4_free(ifp);
#endif
+#ifdef DHCP6
dhcp6_free(ifp);
+#endif
ipv6nd_free(ifp);
ipv6_free(ifp);
rt_freeif(ifp);
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. */
#include <sys/socket.h>
#include <sys/stat.h>
+#include <arpa/inet.h>
#include <net/if.h>
#include <net/route.h>
#include <netinet/in.h>
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)
if (nap->iface->metric < dap->iface->metric)
return nap;
return dap;
+#else
+ return nap;
+#endif
}
ssize_t
if (ipv6nd_iffindaddr(ifp, NULL, 0) != NULL)
return 1;
+#ifdef DHCP6
if (dhcp6_iffindaddr(ifp, NULL, 0) != NULL)
return 1;
+#endif
return 0;
}
return 0;
}
+#ifdef DHCP6
static int
inet6_dhcproutes(struct rt_head *routes, struct dhcpcd_ctx *ctx,
enum DH6S dstate)
}
return 0;
}
+#endif
bool
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 */
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
#define ELOOP_QUEUE 3
#include "common.h"
#include "dhcpcd.h"
+#include "dhcp-common.h"
#include "dhcp6.h"
#include "eloop.h"
#include "if.h"
else {
logwarnx("%s: no IPv6 Routers available", ifp->name);
ipv6nd_drop(ifp);
+#ifdef DHCP6
dhcp6_dropnondelegates(ifp);
+#endif
}
}
#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)
{
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);
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;
rap->lifetime = 0;
}
} else {
- valid = 1;
+ valid = true;
timespecsub(&expire, &now, <);
if (!timespecisset(&next) ||
timespeccmp(&next, <, >))
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;
ia->prefix_vltime = ia->prefix_pltime = 0;
ia->flags &=
~(IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED);
- expired = 1;
+ expired = true;
} else {
timespecsub(&expire, &now, <);
if (!timespecisset(&next) ||
timespeccmp(&next, <, >))
next = lt;
- validone = 1;
+ validone = true;
}
}
* as well punt it. */
if (!valid && !validone)
ipv6nd_free_ra(rap);
+#ifdef DHCP6
else
- anyvalid = 1;
+ anyvalid = true;
+#endif
}
if (timespecisset(&next))
script_runreason(ifp, "ROUTERADVERT");
}
+#ifdef DHCP6
/* No valid routers? Kill any DHCPv6. */
if (!anyvalid)
dhcp6_dropnondelegates(ifp);
+#endif
}
void
const struct ipv4ll_state *istate;
#endif
#endif
-#ifdef INET6
+#ifdef DHCP6
const struct dhcp6_state *d6_state;
#endif
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
#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
#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
)
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);
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);
elen += (size_t)n;
}
}
+#endif
if (protocol == PROTO_RA) {
n = ipv6nd_env(NULL, NULL, ifp);
if (n > 0) {
#ifdef INET
const struct dhcp_state *d;
#endif
-#ifdef INET6
+#ifdef DHCP6
const struct dhcp6_state *d6;
#endif
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;