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");
*fp = ' ';
return -1;
}
- if ((rt = rt_new(ifp)) == NULL) {
+ if ((rt = rt_new0(ctx)) == NULL) {
*fp = ' ';
return -1;
}
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);
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 {
}
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) {
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;
}
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);