]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
options: allow static routes to be configured on the command line
authorRoy Marples <roy@marples.name>
Wed, 28 Mar 2018 10:00:18 +0000 (11:00 +0100)
committerRoy Marples <roy@marples.name>
Wed, 28 Mar 2018 10:00:18 +0000 (11:00 +0100)
src/if-options.c
src/ipv4.c
src/route.c
src/route.h

index 40a7e7a5325619419fca3c31449f3cb7585689f1..bd051b3bc76c7c819f0815b32513406a6c4f78e4 100644 (file)
@@ -1086,14 +1086,8 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                    strncmp(arg, "ms_classless_static_routes=",
                        strlen("ms_classless_static_routes=")) == 0)
                {
-                       struct interface *ifp;
                        struct in_addr addr3;
 
-                       ifp = if_find(ctx->ifaces, ifname);
-                       if (ifp == NULL) {
-                               logerrx("static routes require an interface");
-                               return -1;
-                       }
                        fp = np = strwhite(p);
                        if (np == NULL) {
                                logerrx("all routes need a gateway");
@@ -1107,7 +1101,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                                *fp = ' ';
                                return -1;
                        }
-                       if ((rt = rt_new(ifp)) == NULL) {
+                       if ((rt = rt_new0(ctx)) == NULL) {
                                *fp = ' ';
                                return -1;
                        }
@@ -1117,16 +1111,9 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                        TAILQ_INSERT_TAIL(&ifo->routes, rt, rt_next);
                        *fp = ' ';
                } else if (strncmp(arg, "routers=", strlen("routers=")) == 0) {
-                       struct interface *ifp;
-
-                       ifp = if_find(ctx->ifaces, ifname);
-                       if (ifp == NULL) {
-                               logerrx("static routes require an interface");
-                               return -1;
-                       }
                        if (parse_addr(&addr, NULL, p) == -1)
                                return -1;
-                       if ((rt = rt_new(ifp)) == NULL)
+                       if ((rt = rt_new0(ctx)) == NULL)
                                return -1;
                        addr2.s_addr = INADDR_ANY;
                        sa_in_init(&rt->rt_dest, &addr2);
index d40b3f632566f2e72b9cf8a35f08c7d7fec9efc0..955f2020abaffe4194892cb733291d98e4b5efb0 100644 (file)
@@ -289,10 +289,11 @@ inet_dhcproutes(struct rt_head *routes, struct interface *ifp)
                TAILQ_FOREACH(r, &ifp->options->routes, rt_next) {
                        if (sa_is_unspecified(&r->rt_gateway))
                                break;
-                       if ((rt = rt_new(ifp)) == NULL)
+                       if ((rt = rt_new0(ifp->ctx)) == NULL)
                                return -1;
-                       rt->rt_dflags = RTDF_STATIC;
                        memcpy(rt, r, sizeof(*rt));
+                       rt_setif(rt, ifp);
+                       rt->rt_dflags = RTDF_STATIC;
                        TAILQ_INSERT_TAIL(&nroutes, rt, rt_next);
                }
        } else {
index 70d8868bccf4ee8795ba9c808358ba90906750cf..4ce073fca3b819670a28d7a2fe1a9ae33e2b2b1f 100644 (file)
@@ -146,13 +146,11 @@ rt_dispose(struct dhcpcd_ctx *ctx)
 }
 
 struct rt *
-rt_new(struct interface *ifp)
+rt_new0(struct dhcpcd_ctx *ctx)
 {
        struct rt *rt;
-       struct dhcpcd_ctx *ctx;
 
-       assert(ifp != NULL);
-       ctx = ifp->ctx;
+       assert(ctx != NULL);
        if ((rt = TAILQ_FIRST(&ctx->froutes)) != NULL)
                TAILQ_REMOVE(&ctx->froutes, rt, rt_next);
        else if ((rt = malloc(sizeof(*rt))) == NULL) {
@@ -160,10 +158,30 @@ rt_new(struct interface *ifp)
                return NULL;
        }
        memset(rt, 0, sizeof(*rt));
+       return rt;
+}
+
+void
+rt_setif(struct rt *rt, struct interface *ifp)
+{
+
+       assert(rt != NULL);
+       assert(ifp != NULL);
        rt->rt_ifp = ifp;
 #ifdef HAVE_ROUTE_METRIC
        rt->rt_metric = ifp->metric;
 #endif
+}
+
+struct rt *
+rt_new(struct interface *ifp)
+{
+       struct rt *rt;
+
+       assert(ifp != NULL);
+       if ((rt = rt_new0(ifp->ctx)) == NULL)
+               return NULL;
+       rt_setif(rt, ifp);
        return rt;
 }
 
index 160f6ff921b81004377f26510077594fe6680de1..db316e2e5669acf58cd1acb81a32a1e76c654093 100644 (file)
@@ -88,6 +88,8 @@ void rt_free(struct rt *);
 void rt_freeif(struct interface *);
 void rt_headclear(struct rt_head *, int);
 void rt_headfreeif(struct rt_head *);
+struct rt * rt_new0(struct dhcpcd_ctx *);
+void rt_setif(struct rt *, struct interface *);
 struct rt * rt_new(struct interface *);
 void rt_recvrt(int, const struct rt *);
 void rt_build(struct dhcpcd_ctx *, int);