From: Roy Marples Date: Sat, 19 Nov 2016 16:15:45 +0000 (+0000) Subject: Move ipv6_ctx into dhcpcd_ctx. X-Git-Tag: v7.0.0-beta1~105 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc9d9bf8014e58c5702016a7a10dd0adb38c60d1;p=thirdparty%2Fdhcpcd.git Move ipv6_ctx into dhcpcd_ctx. --- diff --git a/dhcp6.c b/dhcp6.c index 13280154..dfccde07 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -1038,7 +1038,7 @@ static int 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; @@ -1183,7 +1183,7 @@ logsend: } #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; @@ -1200,7 +1200,7 @@ logsend: 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; @@ -2729,8 +2729,7 @@ dhcp6_find_delegates(struct interface *ifp) 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; @@ -2751,22 +2750,21 @@ dhcp6_handledata(void *arg) 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; } @@ -2786,19 +2784,19 @@ dhcp6_handledata(void *arg) } } 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; @@ -2827,7 +2825,7 @@ dhcp6_handledata(void *arg) 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, @@ -2845,8 +2843,8 @@ dhcp6_handledata(void *arg) } 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); @@ -2854,8 +2852,8 @@ dhcp6_handledata(void *arg) } 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) && @@ -3251,9 +3249,8 @@ dhcp6_handledata(void *arg) } static int -dhcp6_open(struct dhcpcd_ctx *dctx) +dhcp6_open(struct dhcpcd_ctx *ctx) { - struct ipv6_ctx *ctx; struct sockaddr_in6 sa; int n; @@ -3264,37 +3261,36 @@ dhcp6_open(struct dhcpcd_ctx *dctx) 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; } @@ -3304,20 +3300,20 @@ dhcp6_open(struct dhcpcd_ctx *dctx) } } - 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; } @@ -3362,7 +3358,7 @@ dhcp6_start1(void *arg) 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); @@ -3573,12 +3569,10 @@ dhcp6_freedrop(struct interface *ifp, int drop, const char *reason) 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; } } diff --git a/dhcpcd.c b/dhcpcd.c index e5facde4..58abaf45 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -649,7 +649,7 @@ dhcpcd_initstate2(struct interface *ifp, unsigned long long options) } else ifo = ifp->options; - if (ifo->options & DHCPCD_IPV6 && ipv6_init(ifp->ctx) == NULL) { + if (ifo->options & DHCPCD_IPV6 && ipv6_init(ifp->ctx) == -1) { logger(ifp->ctx, LOG_ERR, "ipv6_init: %m"); ifo->options &= ~DHCPCD_IPV6; } diff --git a/dhcpcd.h b/dhcpcd.h index aa1ede6a..8be79661 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -93,6 +93,28 @@ struct interface { }; TAILQ_HEAD(if_head, interface); + +#ifdef INET6 +/* dhcpcd requires CMSG_SPACE to evaluate to a compile time constant. */ +#if defined(__QNX) || \ + (defined(__NetBSD_Version__) && __NetBSD_Version__ < 600000000) +#undef CMSG_SPACE +#endif + +#ifndef ALIGNBYTES +#define ALIGNBYTES (sizeof(int) - 1) +#endif +#ifndef ALIGN +#define ALIGN(p) (((unsigned int)(p) + ALIGNBYTES) & ~ALIGNBYTES) +#endif +#ifndef CMSG_SPACE +#define CMSG_SPACE(len) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(len)) +#endif + +#define IP6BUFLEN (CMSG_SPACE(sizeof(struct in6_pktinfo)) + \ + CMSG_SPACE(sizeof(int))) +#endif + struct dhcpcd_ctx { char pidfile[sizeof(PIDFILE) + IF_NAMESIZE + 1]; const char *cffile; @@ -167,11 +189,25 @@ struct dhcpcd_ctx { uint8_t *secret; size_t secret_len; + unsigned char ctlbuf[IP6BUFLEN]; + struct sockaddr_in6 from; + struct msghdr sndhdr; + struct iovec sndiov[1]; + unsigned char sndbuf[CMSG_SPACE(sizeof(struct in6_pktinfo))]; + struct msghdr rcvhdr; + char ntopbuf[INET6_ADDRSTRLEN]; + const char *sfrom; + + int nd_fd; + struct ra_head *ra_routers; + + int dhcp6_fd; + struct dhcp_opt *nd_opts; size_t nd_opts_len; struct dhcp_opt *dhcp6_opts; size_t dhcp6_opts_len; - struct ipv6_ctx *ipv6; + #ifndef __linux__ int ra_global; #endif diff --git a/ipv6.c b/ipv6.c index 80bb5f1e..c51a1efb 100644 --- a/ipv6.c +++ b/ipv6.c @@ -127,22 +127,17 @@ static void ipv6_regentempaddr(void *); #define ipv6_regentempifid(a) {} #endif -struct ipv6_ctx * -ipv6_init(struct dhcpcd_ctx *dhcpcd_ctx) +int +ipv6_init(struct dhcpcd_ctx *ctx) { - struct ipv6_ctx *ctx; - - if (dhcpcd_ctx->ipv6) - return dhcpcd_ctx->ipv6; - ctx = calloc(1, sizeof(*ctx)); - if (ctx == NULL) - return NULL; + if (ctx->sndhdr.msg_iovlen == 1) + return 0; - ctx->ra_routers = malloc(sizeof(*ctx->ra_routers)); if (ctx->ra_routers == NULL) { - free(ctx); - return NULL; + ctx->ra_routers = malloc(sizeof(*ctx->ra_routers)); + if (ctx->ra_routers == NULL) + return -1; } TAILQ_INIT(ctx->ra_routers); @@ -153,18 +148,15 @@ ipv6_init(struct dhcpcd_ctx *dhcpcd_ctx) ctx->sndhdr.msg_controllen = sizeof(ctx->sndbuf); ctx->rcvhdr.msg_name = &ctx->from; ctx->rcvhdr.msg_namelen = sizeof(ctx->from); - ctx->rcvhdr.msg_iov = dhcpcd_ctx->iov; + ctx->rcvhdr.msg_iov = ctx->iov; ctx->rcvhdr.msg_iovlen = 1; ctx->rcvhdr.msg_control = ctx->ctlbuf; // controllen is set at recieve //ctx->rcvhdr.msg_controllen = sizeof(ctx->rcvbuf); ctx->nd_fd = -1; - ctx->dhcp_fd = -1; - - dhcpcd_ctx->ipv6 = ctx; - - return ctx; + ctx->dhcp6_fd = -1; + return 0; } static ssize_t @@ -1657,7 +1649,7 @@ ipv6_freedrop(struct interface *ifp, int drop) ipv6_freedrop_addrs(&state->addrs, drop ? 2 : 0, NULL); if (drop) { - if (ifp->ctx->ipv6 != NULL) { + if (ifp->ctx->ra_routers != NULL) { if_initrt(ifp->ctx, AF_INET6); rt_build(ifp->ctx, AF_INET6); } @@ -1674,12 +1666,8 @@ void ipv6_ctxfree(struct dhcpcd_ctx *ctx) { - if (ctx->ipv6 == NULL) - return; - + free(ctx->ra_routers); free(ctx->secret); - free(ctx->ipv6->ra_routers); - free(ctx->ipv6); } int @@ -2226,7 +2214,7 @@ inet6_raroutes(struct rt_head *routes, struct dhcpcd_ctx *ctx, int expired, int n; n = 0; - TAILQ_FOREACH(rap, ctx->ipv6->ra_routers, next) { + TAILQ_FOREACH(rap, ctx->ra_routers, next) { if (rap->expired != expired) continue; if (rap->iface->options->options & DHCPCD_IPV6RA_OWN) { diff --git a/ipv6.h b/ipv6.h index 602258f7..11a38968 100644 --- a/ipv6.h +++ b/ipv6.h @@ -226,43 +226,9 @@ struct ipv6_state { ((const struct ipv6_state *)(ifp)->if_data[IF_DATA_IPV6]) #define IPV6_STATE_RUNNING(ifp) ipv6_staticdadcompleted((ifp)) -/* dhcpcd requires CMSG_SPACE to evaluate to a compile time constant. */ -#if defined(__QNX) || \ - (defined(__NetBSD_Version__) && __NetBSD_Version__ < 600000000) -#undef CMSG_SPACE -#endif - -#ifndef ALIGNBYTES -#define ALIGNBYTES (sizeof(int) - 1) -#endif -#ifndef ALIGN -#define ALIGN(p) (((unsigned int)(p) + ALIGNBYTES) & ~ALIGNBYTES) -#endif -#ifndef CMSG_SPACE -#define CMSG_SPACE(len) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(len)) -#endif - -#define IP6BUFLEN (CMSG_SPACE(sizeof(struct in6_pktinfo)) + \ - CMSG_SPACE(sizeof(int))) - #ifdef INET6 -struct ipv6_ctx { - unsigned char ctlbuf[IP6BUFLEN]; - struct sockaddr_in6 from; - struct msghdr sndhdr; - struct iovec sndiov[1]; - unsigned char sndbuf[CMSG_SPACE(sizeof(struct in6_pktinfo))]; - struct msghdr rcvhdr; - char ntopbuf[INET6_ADDRSTRLEN]; - const char *sfrom; - - int nd_fd; - struct ra_head *ra_routers; - - int dhcp_fd; -}; -struct ipv6_ctx *ipv6_init(struct dhcpcd_ctx *); +int ipv6_init(struct dhcpcd_ctx *); int ipv6_makestableprivate(struct in6_addr *addr, const struct in6_addr *prefix, int prefix_len, const struct interface *ifp, int *dad_counter); diff --git a/ipv6nd.c b/ipv6nd.c index 1a80a910..aed0bcd0 100644 --- a/ipv6nd.c +++ b/ipv6nd.c @@ -183,13 +183,11 @@ ipv6nd_printoptions(const struct dhcpcd_ctx *ctx, } 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 @@ -221,12 +219,12 @@ ipv6nd_open(struct dhcpcd_ctx *dctx) &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; } @@ -262,7 +260,7 @@ static void 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; @@ -288,7 +286,7 @@ ipv6nd_sendrsprobe(void *arg) } 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; @@ -331,12 +329,12 @@ ipv6nd_expire(struct interface *ifp, uint32_t seconds) 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; @@ -392,8 +390,8 @@ ipv6nd_neighbour(struct dhcpcd_ctx *ctx, struct in6_addr *addr, int flags) { 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; @@ -409,10 +407,10 @@ ipv6nd_iffindaddr(const struct interface *ifp, const struct in6_addr *addr, 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) { @@ -430,10 +428,10 @@ ipv6nd_findaddr(struct dhcpcd_ctx *ctx, const struct in6_addr *addr, 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; @@ -449,7 +447,7 @@ ipv6nd_removefreedrop_ra(struct ra *rap, int remove_ra, int drop_ra) 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); @@ -478,7 +476,7 @@ ipv6nd_free(struct interface *ifp) 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++; @@ -493,10 +491,10 @@ ipv6nd_free(struct interface *ifp) 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; } } @@ -524,7 +522,7 @@ rtpref(struct ra *rap) } static void -add_router(struct ipv6_ctx *ctx, struct ra *router) +add_router(struct dhcpcd_ctx *ctx, struct ra *router) { struct ra *rap; @@ -604,7 +602,7 @@ ipv6nd_dadcompleted(const struct interface *ifp) 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) { @@ -687,7 +685,7 @@ ipv6nd_dadcallback(void *arg) 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; @@ -729,10 +727,9 @@ dhcp6_start(__unused struct interface *ifp, __unused enum DH6S init_state) #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; @@ -752,27 +749,27 @@ ipv6nd_handlera(struct dhcpcd_ctx *dctx, struct interface *ifp, 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; } @@ -897,8 +894,8 @@ ipv6nd_handlera(struct dhcpcd_ctx *dctx, struct interface *ifp, 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) @@ -1072,8 +1069,8 @@ ipv6nd_handlera(struct dhcpcd_ctx *dctx, struct interface *ifp, } } - 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, @@ -1091,7 +1088,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *dctx, struct interface *ifp, } if (new_rap) - add_router(ifp->ctx->ipv6, rap); + add_router(ifp->ctx, rap); if (ifp->ctx->options & DHCPCD_TEST) { script_runreason(ifp, "TEST"); @@ -1151,8 +1148,8 @@ ipv6nd_hasra(const struct interface *ifp) { 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; } @@ -1164,8 +1161,8 @@ ipv6nd_hasradhcp(const struct interface *ifp) { 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))) @@ -1228,7 +1225,7 @@ ipv6nd_env(char **env, const char *prefix, const struct interface *ifp) 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++; @@ -1332,10 +1329,10 @@ ipv6nd_handleifa(int cmd, struct ipv6_addr *addr) /* 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); @@ -1357,7 +1354,7 @@ ipv6nd_expirera(void *arg) 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; @@ -1449,15 +1446,15 @@ ipv6nd_drop(struct interface *ifp) 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); } } @@ -1473,10 +1470,9 @@ ipv6nd_drop(struct interface *ifp) } 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; @@ -1486,7 +1482,7 @@ ipv6nd_handlena(struct dhcpcd_ctx *dctx, struct interface *ifp, if (ifp == NULL) { #ifdef DEBUG_NS logger(ctx, LOG_DEBUG, "NA for unexpected interface from %s", - dctx->sfrom); + ctx->sfrom); #endif return; } @@ -1499,7 +1495,7 @@ ipv6nd_handlena(struct dhcpcd_ctx *dctx, struct interface *ifp, /* 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; } @@ -1558,8 +1554,7 @@ ipv6nd_handlena(struct dhcpcd_ctx *dctx, struct interface *ifp, 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; @@ -1567,14 +1562,13 @@ ipv6nd_handledata(void *arg) 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; @@ -1582,7 +1576,7 @@ ipv6nd_handledata(void *arg) 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; } @@ -1608,13 +1602,13 @@ ipv6nd_handledata(void *arg) } 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)) @@ -1627,17 +1621,17 @@ ipv6nd_handledata(void *arg) 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); }