]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Make finding interfaces take an interface list rather than a dhcpcd_ctx.
authorRoy Marples <roy@marples.name>
Thu, 30 Apr 2015 10:16:06 +0000 (10:16 +0000)
committerRoy Marples <roy@marples.name>
Thu, 30 Apr 2015 10:16:06 +0000 (10:16 +0000)
dhcp6.c
dhcpcd.c
if-bsd.c
if-linux.c
if.c
if.h

diff --git a/dhcp6.c b/dhcp6.c
index 5b98180c6b0182ec0f41eacb523f42e1899c8fbf..9d06fd41c04f02bc7c993c4f10e216e151bce541 100644 (file)
--- 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);
index 3185a620a3ef813e988b1d4432f0b75e0cba2cca..c91fce84a024878276fd1cbba5d89b2e20d35c6d 100644 (file)
--- 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]);
index 69af7b6d34b6374b70de76ec73a7a78fee200d04..775c857da1c8b2515a82333dca0892daf3890162 100644 (file)
--- 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);
index d2669f1a316efdb2731e41fbfafb9e4e949b5450..ca89bae1530f4b7dab5eda8f41b75aa9f417b229 100644 (file)
@@ -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 240f7fd23c7635211385d8d1cca9b543740f3c7a..b89a5cd9ef4b188906c9679c33aa3acd3a5a841e 100644 (file)
--- 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 084b3abb6fffa7557743065bbb06dbedae92942f..4efc63641d5c1c35d49d12c5e99a744a4ffb74e2 100644 (file)
--- 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);