dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *))
{
struct dhcp6_state *state;
- struct ipv6_ctx *ctx;
+ struct dhcpcd_ctx *ctx;
struct sockaddr_in6 dst;
struct cmsghdr *cm;
struct in6_pktinfo pi;
}
#endif
- ctx = ifp->ctx->ipv6;
+ ctx = ifp->ctx;
dst.sin6_scope_id = ifp->index;
ctx->sndhdr.msg_name = (void *)&dst;
ctx->sndhdr.msg_iov[0].iov_base = state->send;
pi.ipi6_ifindex = ifp->index;
memcpy(CMSG_DATA(cm), &pi, sizeof(pi));
- if (sendmsg(ctx->dhcp_fd, &ctx->sndhdr, 0) == -1) {
+ if (sendmsg(ctx->dhcp6_fd, &ctx->sndhdr, 0) == -1) {
logger(ifp->ctx, LOG_ERR,
"%s: %s: sendmsg: %m", ifp->name, __func__);
ifp->options->options &= ~DHCPCD_IPV6;
static void
dhcp6_handledata(void *arg)
{
- struct dhcpcd_ctx *dctx;
- struct ipv6_ctx *ctx;
+ struct dhcpcd_ctx *ctx;
size_t i, len;
ssize_t bytes;
struct cmsghdr *cm;
uint16_t auth_len;
#endif
- dctx = arg;
- ctx = dctx->ipv6;
+ ctx = arg;
ctx->rcvhdr.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo));
- bytes = recvmsg_realloc(ctx->dhcp_fd, &ctx->rcvhdr, 0);
+ bytes = recvmsg_realloc(ctx->dhcp6_fd, &ctx->rcvhdr, 0);
if (bytes == -1) {
- logger(dctx, LOG_ERR, "%s: recvmsg: %m", __func__);
- close(ctx->dhcp_fd);
- eloop_event_delete(dctx->eloop, ctx->dhcp_fd);
- ctx->dhcp_fd = -1;
+ logger(ctx, LOG_ERR, "%s: recvmsg: %m", __func__);
+ close(ctx->dhcp6_fd);
+ eloop_event_delete(ctx->eloop, ctx->dhcp6_fd);
+ ctx->dhcp6_fd = -1;
return;
}
len = (size_t)bytes;
ctx->sfrom = inet_ntop(AF_INET6, &ctx->from.sin6_addr,
ctx->ntopbuf, sizeof(ctx->ntopbuf));
if (len < sizeof(struct dhcp6_message)) {
- logger(dctx, LOG_ERR,
+ logger(ctx, LOG_ERR,
"DHCPv6 packet too short from %s", ctx->sfrom);
return;
}
}
}
if (pkt.ipi6_ifindex == 0) {
- logger(dctx, LOG_ERR,
+ logger(ctx, LOG_ERR,
"DHCPv6 reply did not contain index from %s", ctx->sfrom);
return;
}
- TAILQ_FOREACH(ifp, dctx->ifaces, next) {
+ TAILQ_FOREACH(ifp, ctx->ifaces, next) {
if (ifp->active &&
ifp->index == (unsigned int)pkt.ipi6_ifindex &&
ifp->options->options & DHCPCD_DHCP6)
break;
}
if (ifp == NULL) {
- logger(dctx, LOG_DEBUG,
+ logger(ctx, LOG_DEBUG,
"DHCPv6 reply for unexpected interface from %s",
ctx->sfrom);
return;
r->xid[1] != state->send->xid[1] ||
r->xid[2] != state->send->xid[2]))
{
- logger(dctx, LOG_DEBUG,
+ logger(ctx, LOG_DEBUG,
"%s: wrong xid 0x%02x%02x%02x"
" (expecting 0x%02x%02x%02x) from %s",
ifp->name,
}
o = dhcp6_findmoption(r, len, D6_OPTION_CLIENTID, &ol);
- if (o == NULL || ol != dctx->duid_len ||
- memcmp(o, dctx->duid, ol) != 0)
+ if (o == NULL || ol != ctx->duid_len ||
+ memcmp(o, ctx->duid, ol) != 0)
{
logger(ifp->ctx, LOG_DEBUG, "%s: incorrect client ID from %s",
ifp->name, ctx->sfrom);
}
ifo = ifp->options;
- for (i = 0, opt = dctx->dhcp6_opts;
- i < dctx->dhcp6_opts_len;
+ for (i = 0, opt = ctx->dhcp6_opts;
+ i < ctx->dhcp6_opts_len;
i++, opt++)
{
if (has_option_mask(ifo->requiremask6, opt->option) &&
}
static int
-dhcp6_open(struct dhcpcd_ctx *dctx)
+dhcp6_open(struct dhcpcd_ctx *ctx)
{
- struct ipv6_ctx *ctx;
struct sockaddr_in6 sa;
int n;
sa.sin6_len = sizeof(sa);
#endif
- ctx = dctx->ipv6;
#define SOCK_FLAGS SOCK_CLOEXEC | SOCK_NONBLOCK
- ctx->dhcp_fd = xsocket(PF_INET6, SOCK_DGRAM | SOCK_FLAGS, IPPROTO_UDP);
+ ctx->dhcp6_fd = xsocket(PF_INET6, SOCK_DGRAM | SOCK_FLAGS, IPPROTO_UDP);
#undef SOCK_FLAGS
- if (ctx->dhcp_fd == -1)
+ if (ctx->dhcp6_fd == -1)
return -1;
n = 1;
- if (setsockopt(ctx->dhcp_fd, SOL_SOCKET, SO_REUSEADDR,
+ if (setsockopt(ctx->dhcp6_fd, SOL_SOCKET, SO_REUSEADDR,
&n, sizeof(n)) == -1)
goto errexit;
n = 1;
- if (setsockopt(ctx->dhcp_fd, SOL_SOCKET, SO_BROADCAST,
+ if (setsockopt(ctx->dhcp6_fd, SOL_SOCKET, SO_BROADCAST,
&n, sizeof(n)) == -1)
goto errexit;
#ifdef SO_REUSEPORT
n = 1;
- if (setsockopt(ctx->dhcp_fd, SOL_SOCKET, SO_REUSEPORT,
+ if (setsockopt(ctx->dhcp6_fd, SOL_SOCKET, SO_REUSEPORT,
&n, sizeof(n)) == -1)
- logger(dctx, LOG_WARNING, "setsockopt: SO_REUSEPORT: %m");
+ logger(ctx, LOG_WARNING, "setsockopt: SO_REUSEPORT: %m");
#endif
- if (!(dctx->options & DHCPCD_MASTER)) {
+ if (!(ctx->options & DHCPCD_MASTER)) {
/* Bind to the link-local address to allow more than one
* DHCPv6 client to work. */
struct interface *ifp;
struct ipv6_addr *ia;
- TAILQ_FOREACH(ifp, dctx->ifaces, next) {
+ TAILQ_FOREACH(ifp, ctx->ifaces, next) {
if (ifp->active)
break;
}
}
}
- if (bind(ctx->dhcp_fd, (struct sockaddr *)&sa, sizeof(sa)) == -1)
+ if (bind(ctx->dhcp6_fd, (struct sockaddr *)&sa, sizeof(sa)) == -1)
goto errexit;
n = 1;
- if (setsockopt(ctx->dhcp_fd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
+ if (setsockopt(ctx->dhcp6_fd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
&n, sizeof(n)) == -1)
goto errexit;
- eloop_event_add(dctx->eloop, ctx->dhcp_fd, dhcp6_handledata, dctx);
+ eloop_event_add(ctx->eloop, ctx->dhcp6_fd, dhcp6_handledata, ctx);
return 0;
errexit:
- close(ctx->dhcp_fd);
- ctx->dhcp_fd = -1;
+ close(ctx->dhcp6_fd);
+ ctx->dhcp6_fd = -1;
return -1;
}
size_t i;
const struct dhcp_compat *dhc;
- if (ifp->ctx->ipv6->dhcp_fd == -1 && dhcp6_open(ifp->ctx) == -1)
+ if (ifp->ctx->dhcp6_fd == -1 && dhcp6_open(ifp->ctx) == -1)
return;
state = D6_STATE(ifp);
break;
}
}
- if (ifp == NULL && ctx->ipv6) {
- if (ctx->ipv6->dhcp_fd != -1) {
- eloop_event_delete(ctx->eloop, ctx->ipv6->dhcp_fd);
- close(ctx->ipv6->dhcp_fd);
- ctx->ipv6->dhcp_fd = -1;
- }
+ if (ifp == NULL && ctx->dhcp6_fd != -1) {
+ eloop_event_delete(ctx->eloop, ctx->dhcp6_fd);
+ close(ctx->dhcp6_fd);
+ ctx->dhcp6_fd = -1;
}
}
}
static int
-ipv6nd_open(struct dhcpcd_ctx *dctx)
+ipv6nd_open(struct dhcpcd_ctx *ctx)
{
- struct ipv6_ctx *ctx;
int on;
struct icmp6_filter filt;
- ctx = dctx->ipv6;
if (ctx->nd_fd != -1)
return ctx->nd_fd;
#define SOCK_FLAGS SOCK_CLOEXEC | SOCK_NONBLOCK
&filt, sizeof(filt)) == -1)
goto eexit;
- eloop_event_add(dctx->eloop, ctx->nd_fd, ipv6nd_handledata, dctx);
+ eloop_event_add(ctx->eloop, ctx->nd_fd, ipv6nd_handledata, ctx);
return ctx->nd_fd;
eexit:
if (ctx->nd_fd != -1) {
- eloop_event_delete(dctx->eloop, ctx->nd_fd);
+ eloop_event_delete(ctx->eloop, ctx->nd_fd);
close(ctx->nd_fd);
ctx->nd_fd = -1;
}
ipv6nd_sendrsprobe(void *arg)
{
struct interface *ifp = arg;
- struct ipv6_ctx *ctx;
+ struct dhcpcd_ctx *ctx;
struct rs_state *state;
struct sockaddr_in6 dst;
struct cmsghdr *cm;
}
state = RS_STATE(ifp);
- ctx = ifp->ctx->ipv6;
+ ctx = ifp->ctx;
ctx->sndhdr.msg_name = (void *)&dst;
ctx->sndhdr.msg_iov[0].iov_base = state->rs;
ctx->sndhdr.msg_iov[0].iov_len = state->rslen;
struct ra *rap;
struct timespec now;
- if (ifp->ctx->ipv6 == NULL)
+ if (ifp->ctx->ra_routers == NULL)
return;
clock_gettime(CLOCK_MONOTONIC, &now);
- TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next) {
+ TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
if (rap->iface == ifp) {
rap->acquired = now;
rap->expired = seconds ? 0 : 1;
{
struct ra *rap;
- if (ctx->ipv6) {
- TAILQ_FOREACH(rap, ctx->ipv6->ra_routers, next) {
+ if (ctx->ra_routers) {
+ TAILQ_FOREACH(rap, ctx->ra_routers, next) {
if (IN6_ARE_ADDR_EQUAL(&rap->from, addr)) {
ipv6nd_reachable(rap, flags);
break;
struct ra *rap;
struct ipv6_addr *ap;
- if (ifp->ctx->ipv6 == NULL)
+ if (ifp->ctx->ra_routers == NULL)
return NULL;
- TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next) {
+ TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
if (rap->iface != ifp)
continue;
TAILQ_FOREACH(ap, &rap->addrs, next) {
struct ra *rap;
struct ipv6_addr *ap;
- if (ctx->ipv6 == NULL)
+ if (ctx->ra_routers == NULL)
return NULL;
- TAILQ_FOREACH(rap, ctx->ipv6->ra_routers, next) {
+ TAILQ_FOREACH(rap, ctx->ra_routers, next) {
TAILQ_FOREACH(ap, &rap->addrs, next) {
if (ipv6_findaddrmatch(ap, addr, flags))
return ap;
eloop_timeout_delete(rap->iface->ctx->eloop, NULL, rap->iface);
eloop_timeout_delete(rap->iface->ctx->eloop, NULL, rap);
if (remove_ra && !drop_ra)
- TAILQ_REMOVE(rap->iface->ctx->ipv6->ra_routers, rap, next);
+ TAILQ_REMOVE(rap->iface->ctx->ra_routers, rap, next);
ipv6_freedrop_addrs(&rap->addrs, drop_ra, NULL);
free(rap->data);
free(rap);
free(state);
ifp->if_data[IF_DATA_IPV6ND] = NULL;
n = 0;
- TAILQ_FOREACH_SAFE(rap, ifp->ctx->ipv6->ra_routers, next, ran) {
+ TAILQ_FOREACH_SAFE(rap, ifp->ctx->ra_routers, next, ran) {
if (rap->iface == ifp) {
ipv6nd_free_ra(rap);
n++;
break;
}
if (ifp == NULL) {
- if (ctx->ipv6->nd_fd != -1) {
- eloop_event_delete(ctx->eloop, ctx->ipv6->nd_fd);
- close(ctx->ipv6->nd_fd);
- ctx->ipv6->nd_fd = -1;
+ if (ctx->nd_fd != -1) {
+ eloop_event_delete(ctx->eloop, ctx->nd_fd);
+ close(ctx->nd_fd);
+ ctx->nd_fd = -1;
}
}
}
static void
-add_router(struct ipv6_ctx *ctx, struct ra *router)
+add_router(struct dhcpcd_ctx *ctx, struct ra *router)
{
struct ra *rap;
const struct ra *rap;
const struct ipv6_addr *ap;
- TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next) {
+ TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
if (rap->iface != ifp)
continue;
TAILQ_FOREACH(ap, &rap->addrs, next) {
try_script:
if (!wascompleted) {
- TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next) {
+ TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
if (rap->iface != ifp)
continue;
wascompleted = 1;
#endif
static void
-ipv6nd_handlera(struct dhcpcd_ctx *dctx, struct interface *ifp,
+ipv6nd_handlera(struct dhcpcd_ctx *ctx, struct interface *ifp,
struct icmp6_hdr *icp, size_t len, int hoplimit)
{
- struct ipv6_ctx *ctx = dctx->ipv6;
size_t i, olen;
struct nd_router_advert *nd_ra;
struct nd_opt_hdr ndo;
if (ifp == NULL) {
#ifdef DEBUG_RS
- logger(dctx, LOG_DEBUG,
+ logger(ctx, LOG_DEBUG,
"RA for unexpected interface from %s", ctx->sfrom);
#endif
return;
}
if (len < sizeof(struct nd_router_advert)) {
- logger(dctx, LOG_ERR,
+ logger(ctx, LOG_ERR,
"IPv6 RA packet too short from %s", ctx->sfrom);
return;
}
/* RFC 4861 7.1.2 */
if (hoplimit != 255) {
- logger(dctx, LOG_ERR,
+ logger(ctx, LOG_ERR,
"invalid hoplimit(%d) in RA from %s", hoplimit, ctx->sfrom);
return;
}
if (!IN6_IS_ADDR_LINKLOCAL(&ctx->from.sin6_addr)) {
- logger(dctx, LOG_ERR,
+ logger(ctx, LOG_ERR,
"RA from non local address %s", ctx->sfrom);
return;
}
if (has_option_mask(ifp->options->rejectmasknd,
ndo.nd_opt_type))
{
- for (i = 0, dho = dctx->nd_opts;
- i < dctx->nd_opts_len;
+ for (i = 0, dho = ctx->nd_opts;
+ i < ctx->nd_opts_len;
i++, dho++)
{
if (dho->option == ndo.nd_opt_type)
}
}
- for (i = 0, dho = dctx->nd_opts;
- i < dctx->nd_opts_len;
+ for (i = 0, dho = ctx->nd_opts;
+ i < ctx->nd_opts_len;
i++, dho++)
{
if (has_option_mask(ifp->options->requiremasknd,
}
if (new_rap)
- add_router(ifp->ctx->ipv6, rap);
+ add_router(ifp->ctx, rap);
if (ifp->ctx->options & DHCPCD_TEST) {
script_runreason(ifp, "TEST");
{
const struct ra *rap;
- if (ifp->ctx->ipv6) {
- TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next)
+ if (ifp->ctx->ra_routers) {
+ TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next)
if (rap->iface == ifp && !rap->expired)
return 1;
}
{
const struct ra *rap;
- if (ifp->ctx->ipv6) {
- TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next) {
+ if (ifp->ctx->ra_routers) {
+ TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
if (rap->iface == ifp &&
!rap->expired &&
(rap->flags & (ND_RA_FLAG_MANAGED | ND_RA_FLAG_OTHER)))
clock_gettime(CLOCK_MONOTONIC, &now);
i = n = 0;
- TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next) {
+ TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
if (rap->iface != ifp)
continue;
i++;
/* IPv6 init may not have happened yet if we are learning
* existing addresses when dhcpcd starts. */
- if (addr->iface->ctx->ipv6 == NULL)
+ if (addr->iface->ctx->ra_routers == NULL)
return;
- TAILQ_FOREACH(rap, addr->iface->ctx->ipv6->ra_routers, next) {
+ TAILQ_FOREACH(rap, addr->iface->ctx->ra_routers, next) {
if (rap->iface != addr->iface)
continue;
ipv6_handleifa_addrs(cmd, &rap->addrs, addr);
timespecclear(&next);
validone = 0;
- TAILQ_FOREACH_SAFE(rap, ifp->ctx->ipv6->ra_routers, next, ran) {
+ TAILQ_FOREACH_SAFE(rap, ifp->ctx->ra_routers, next, ran) {
if (rap->iface != ifp)
continue;
valid = 0;
uint8_t expired = 0;
TAILQ_HEAD(rahead, ra) rtrs;
- if (ifp->ctx->ipv6 == NULL)
+ if (ifp->ctx->ra_routers == NULL)
return;
eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
TAILQ_INIT(&rtrs);
- TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next) {
+ TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
if (rap->iface == ifp) {
rap->expired = expired = 1;
- TAILQ_REMOVE(ifp->ctx->ipv6->ra_routers, rap, next);
+ TAILQ_REMOVE(ifp->ctx->ra_routers, rap, next);
TAILQ_INSERT_TAIL(&rtrs, rap, next);
}
}
}
static void
-ipv6nd_handlena(struct dhcpcd_ctx *dctx, struct interface *ifp,
+ipv6nd_handlena(struct dhcpcd_ctx *ctx, struct interface *ifp,
struct icmp6_hdr *icp, size_t len, int hoplimit)
{
- struct ipv6_ctx *ctx = dctx->ipv6;
struct nd_neighbor_advert *nd_na;
struct ra *rap;
uint32_t is_router, is_solicited;
if (ifp == NULL) {
#ifdef DEBUG_NS
logger(ctx, LOG_DEBUG, "NA for unexpected interface from %s",
- dctx->sfrom);
+ ctx->sfrom);
#endif
return;
}
/* RFC 4861 7.1.2 */
if (hoplimit != 255) {
- logger(dctx, LOG_ERR,
+ logger(ctx, LOG_ERR,
"invalid hoplimit(%d) in NA from %s", hoplimit, ctx->sfrom);
return;
}
static void
ipv6nd_handledata(void *arg)
{
- struct dhcpcd_ctx *dctx;
- struct ipv6_ctx *ctx;
+ struct dhcpcd_ctx *ctx;
ssize_t len;
struct cmsghdr *cm;
int hoplimit;
struct icmp6_hdr *icp;
struct interface *ifp;
- dctx = arg;
- ctx = dctx->ipv6;
+ ctx = arg;
ctx->rcvhdr.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_SPACE(sizeof(int));
len = recvmsg_realloc(ctx->nd_fd, &ctx->rcvhdr, 0);
if (len == -1) {
- logger(dctx, LOG_ERR, "recvmsg: %m");
- eloop_event_delete(dctx->eloop, ctx->nd_fd);
+ logger(ctx, LOG_ERR, "recvmsg: %m");
+ eloop_event_delete(ctx->eloop, ctx->nd_fd);
close(ctx->nd_fd);
ctx->nd_fd = -1;
return;
ctx->sfrom = inet_ntop(AF_INET6, &ctx->from.sin6_addr,
ctx->ntopbuf, INET6_ADDRSTRLEN);
if ((size_t)len < sizeof(struct icmp6_hdr)) {
- logger(dctx, LOG_ERR, "IPv6 ICMP packet too short from %s",
+ logger(ctx, LOG_ERR, "IPv6 ICMP packet too short from %s",
ctx->sfrom);
return;
}
}
if (pkt.ipi6_ifindex == 0) {
- logger(dctx, LOG_ERR,
+ logger(ctx, LOG_ERR,
"IPv6 RA/NA did not contain index from %s",
ctx->sfrom);
return;
}
- TAILQ_FOREACH(ifp, dctx->ifaces, next) {
+ TAILQ_FOREACH(ifp, ctx->ifaces, next) {
if (ifp->active &&
ifp->index == (unsigned int)pkt.ipi6_ifindex) {
if (!(ifp->options->options & DHCPCD_IPV6))
if (icp->icmp6_code == 0) {
switch(icp->icmp6_type) {
case ND_NEIGHBOR_ADVERT:
- ipv6nd_handlena(dctx, ifp, icp, (size_t)len,
+ ipv6nd_handlena(ctx, ifp, icp, (size_t)len,
hoplimit);
return;
case ND_ROUTER_ADVERT:
- ipv6nd_handlera(dctx, ifp, icp, (size_t)len,
+ ipv6nd_handlera(ctx, ifp, icp, (size_t)len,
hoplimit);
return;
}
}
- logger(dctx, LOG_ERR, "invalid IPv6 type %d or code %d from %s",
+ logger(ctx, LOG_ERR, "invalid IPv6 type %d or code %d from %s",
icp->icmp6_type, icp->icmp6_code, ctx->sfrom);
}