From: Roy Marples Date: Thu, 30 Apr 2015 10:16:06 +0000 (+0000) Subject: Make finding interfaces take an interface list rather than a dhcpcd_ctx. X-Git-Tag: v6.8.2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=68729f15d95543e1e8bb2ee5fc6b432b4a94bb87;p=thirdparty%2Fdhcpcd.git Make finding interfaces take an interface list rather than a dhcpcd_ctx. --- diff --git a/dhcp6.c b/dhcp6.c index 5b98180c..9d06fd41 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -2428,7 +2428,7 @@ dhcp6_delegate_prefix(struct interface *ifp) if (strcmp(sla->ifname, ia->sla[j].ifname) == 0) break; if (j >= i && - if_find(ifp->ctx, sla->ifname) == NULL) + if_find(ifp->ctx->ifaces, sla->ifname) == NULL) { logger(ifp->ctx, LOG_INFO, "%s: loading for delegation", sla->ifname); diff --git a/dhcpcd.c b/dhcpcd.c index 3185a620..c91fce84 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -591,7 +591,7 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags, { struct interface *ifp; - ifp = if_find(ctx, ifname); + ifp = if_find(ctx->ifaces, ifname); if (ifp == NULL || !(ifp->options->options & DHCPCD_LINK)) return; @@ -903,7 +903,7 @@ dhcpcd_handleinterface(void *arg, int action, const char *ifname) ctx = arg; if (action == -1) { - ifp = if_find(ctx, ifname); + ifp = if_find(ctx->ifaces, ifname); if (ifp == NULL) { errno = ESRCH; return -1; @@ -934,7 +934,7 @@ dhcpcd_handleinterface(void *arg, int action, const char *ifname) continue; i = 0; /* Check if we already have the interface */ - iff = if_find(ctx, ifp->name); + iff = if_find(ctx->ifaces, ifp->name); if (iff) { logger(ctx, LOG_DEBUG, "%s: interface updated", iff->name); /* The flags and hwaddr could have changed */ @@ -973,7 +973,7 @@ dhcpcd_handlehwaddr(struct dhcpcd_ctx *ctx, const char *ifname, struct interface *ifp; char buf[sizeof(ifp->hwaddr) * 3]; - ifp = if_find(ctx, ifname); + ifp = if_find(ctx->ifaces, ifname); if (ifp == NULL) return; @@ -1036,7 +1036,7 @@ reconf_reboot(struct dhcpcd_ctx *ctx, int action, int argc, char **argv, int oi) while ((ifp = TAILQ_FIRST(ifs))) { TAILQ_REMOVE(ifs, ifp, next); - ifn = if_find(ctx, ifp->name); + ifn = if_find(ctx->ifaces, ifp->name); if (ifn) { if (action) if_reboot(ifn, argc, argv); @@ -1289,7 +1289,7 @@ dhcpcd_handleargs(struct dhcpcd_ctx *ctx, struct fd_list *fd, return 0; } for (oi = optind; oi < argc; oi++) { - if ((ifp = if_find(ctx, argv[oi])) == NULL) + if ((ifp = if_find(ctx->ifaces, argv[oi])) == NULL) continue; if (do_release) { ifp->options->options |= DHCPCD_RELEASE; @@ -1743,7 +1743,7 @@ main(int argc, char **argv) goto exit_failure; } for (i = 0; i < ctx.ifc; i++) { - if (if_find(&ctx, ctx.ifv[i]) == NULL) + if (if_find(ctx.ifaces, ctx.ifv[i]) == NULL) logger(&ctx, LOG_ERR, "%s: interface not found or invalid", ctx.ifv[i]); diff --git a/if-bsd.c b/if-bsd.c index 69af7b6d..775c857d 100644 --- a/if-bsd.c +++ b/if-bsd.c @@ -281,7 +281,7 @@ if_findsdl(struct dhcpcd_ctx *ctx, struct sockaddr_dl *sdl) char ifname[IF_NAMESIZE]; memcpy(ifname, sdl->sdl_data, sdl->sdl_nlen); ifname[sdl->sdl_nlen] = '\0'; - return if_find(ctx, ifname); + return if_find(ctx->ifaces, ifname); } return NULL; } @@ -517,7 +517,7 @@ if_copyrt(struct dhcpcd_ctx *ctx, struct rt *rt, struct rt_msghdr *rtm) COPYOUT(rt->gate, rti_info[RTAX_GATEWAY]); if (rtm->rtm_index) - rt->iface = if_findindex(ctx, rtm->rtm_index); + rt->iface = if_findindex(ctx->ifaces, rtm->rtm_index); else if (rtm->rtm_addrs & RTA_IFP) { struct sockaddr_dl *sdl; @@ -873,7 +873,7 @@ if_copyrt6(struct dhcpcd_ctx *ctx, struct rt6 *rt, struct rt_msghdr *rtm) COPYOUT6(rt->gate, rti_info[RTAX_GATEWAY]); if (rtm->rtm_index) - rt->iface = if_findindex(ctx, rtm->rtm_index); + rt->iface = if_findindex(ctx->ifaces, rtm->rtm_index); else if (rtm->rtm_addrs & RTA_IFP) { struct sockaddr_dl *sdl; @@ -1156,7 +1156,8 @@ if_managelink(struct dhcpcd_ctx *ctx) #endif case RTM_IFINFO: ifm = (struct if_msghdr *)(void *)p; - if ((ifp = if_findindex(ctx, ifm->ifm_index)) == NULL) + ifp = if_findindex(ctx->ifaces, ifm->ifm_index); + if (ifp == NULL) break; switch (ifm->ifm_data.ifi_link_state) { case LINK_STATE_DOWN: @@ -1232,7 +1233,8 @@ if_managelink(struct dhcpcd_ctx *ctx) case RTM_DELADDR: /* FALLTHROUGH */ case RTM_NEWADDR: ifam = (struct ifa_msghdr *)(void *)p; - if ((ifp = if_findindex(ctx, ifam->ifam_index)) == NULL) + ifp = if_findindex(ctx->ifaces, ifam->ifam_index); + if (ifp == NULL) break; cp = (char *)(void *)(ifam + 1); get_addrs(ifam->ifam_addrs, cp, rti_info); diff --git a/if-linux.c b/if-linux.c index d2669f1a..ca89bae1 100644 --- a/if-linux.c +++ b/if-linux.c @@ -431,7 +431,7 @@ if_copyrt(struct dhcpcd_ctx *ctx, struct rt *rt, struct nlmsghdr *nlm) sizeof(prefsrc.s_addr)); break; case RTA_OIF: - rt->iface = if_findindex(ctx, + rt->iface = if_findindex(ctx->ifaces, *(unsigned int *)RTA_DATA(rta)); break; case RTA_PRIORITY: @@ -492,7 +492,7 @@ if_copyrt6(struct dhcpcd_ctx *ctx, struct rt6 *rt, struct nlmsghdr *nlm) sizeof(rt->gate.s6_addr)); break; case RTA_OIF: - rt->iface = if_findindex(ctx, + rt->iface = if_findindex(ctx->ifaces, *(unsigned int *)RTA_DATA(rta)); break; case RTA_PRIORITY: @@ -596,7 +596,7 @@ link_addr(struct dhcpcd_ctx *ctx, struct interface *ifp, struct nlmsghdr *nlm) return -1; } ifa = NLMSG_DATA(nlm); - if ((ifp = if_findindex(ctx, ifa->ifa_index)) == NULL) { + if ((ifp = if_findindex(ctx->ifaces, ifa->ifa_index)) == NULL) { /* We don't know about the interface the address is for * so it's not really an error */ return 1; @@ -803,8 +803,7 @@ link_netlink(struct dhcpcd_ctx *ctx, struct interface *ifp, return 0; /* Check for a new interface */ - ifp = if_find(ctx, ifn); - if (ifp == NULL) { + if ((ifp = if_find(ctx->ifaces, ifn)) == NULL) { /* If are listening to a dev manager, let that announce * the interface rather than the kernel. */ if (dev_listening(ctx) < 1) diff --git a/if.c b/if.c index 240f7fd2..b89a5cd9 100644 --- a/if.c +++ b/if.c @@ -537,12 +537,12 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) } static struct interface * -if_findindexname(struct dhcpcd_ctx *ctx, unsigned int idx, const char *name) +if_findindexname(struct if_head *ifaces, unsigned int idx, const char *name) { struct interface *ifp; - if (ctx != NULL && ctx->ifaces != NULL) { - TAILQ_FOREACH(ifp, ctx->ifaces, next) { + if (ifaces != NULL) { + TAILQ_FOREACH(ifp, ifaces, next) { if ((ifp->options == NULL || !(ifp->options->options & DHCPCD_PFXDLGONLY)) && ((name && strcmp(ifp->name, name) == 0) || @@ -557,17 +557,17 @@ if_findindexname(struct dhcpcd_ctx *ctx, unsigned int idx, const char *name) } struct interface * -if_find(struct dhcpcd_ctx *ctx, const char *name) +if_find(struct if_head *ifaces, const char *name) { - return if_findindexname(ctx, 0, name); + return if_findindexname(ifaces, 0, name); } struct interface * -if_findindex(struct dhcpcd_ctx *ctx, unsigned int idx) +if_findindex(struct if_head *ifaces, unsigned int idx) { - return if_findindexname(ctx, idx, NULL); + return if_findindexname(ifaces, idx, NULL); } int diff --git a/if.h b/if.h index 084b3abb..4efc6364 100644 --- a/if.h +++ b/if.h @@ -83,8 +83,8 @@ int if_setflag(struct interface *ifp, short flag); #define if_up(ifp) if_setflag((ifp), (IFF_UP | IFF_RUNNING)) struct if_head *if_discover(struct dhcpcd_ctx *, int, char * const *); -struct interface *if_find(struct dhcpcd_ctx *, const char *); -struct interface *if_findindex(struct dhcpcd_ctx *, unsigned int); +struct interface *if_find(struct if_head *, const char *); +struct interface *if_findindex(struct if_head *, unsigned int); void if_sortinterfaces(struct dhcpcd_ctx *); void if_free(struct interface *); int if_domtu(const char *, short int);