Lines Matching refs:rt

248 static struct rt *
249 find_route(struct rt_head *rts, const struct rt *r, const struct rt *srt) in find_route()
251 struct rt *rt; in find_route() local
255 TAILQ_FOREACH(rt, rts, next) { in find_route()
256 if (rt->dest.s_addr == r->dest.s_addr && in find_route()
258 (srt || (r->iface == NULL || rt->iface == NULL || in find_route()
259 rt->iface->metric == r->iface->metric)) && in find_route()
261 (!srt || srt != rt) && in find_route()
262 rt->net.s_addr == r->net.s_addr) in find_route()
263 return rt; in find_route()
269 desc_route(const char *cmd, const struct rt *rt) in desc_route() argument
272 struct dhcpcd_ctx *ctx = rt->iface ? rt->iface->ctx : NULL; in desc_route()
273 const char *ifname = rt->iface ? rt->iface->name : NULL; in desc_route()
275 strlcpy(addr, inet_ntoa(rt->dest), sizeof(addr)); in desc_route()
276 if (rt->net.s_addr == htonl(INADDR_BROADCAST) && in desc_route()
277 rt->gate.s_addr == htonl(INADDR_ANY)) in desc_route()
280 else if (rt->net.s_addr == htonl(INADDR_BROADCAST)) in desc_route()
282 ifname, cmd, addr, inet_ntoa(rt->gate)); in desc_route()
283 else if (rt->gate.s_addr == htonl(INADDR_ANY)) in desc_route()
285 ifname, cmd, addr, inet_ntocidr(rt->net)); in desc_route()
286 else if (rt->dest.s_addr == htonl(INADDR_ANY) && in desc_route()
287 rt->net.s_addr == htonl(INADDR_ANY)) in desc_route()
289 ifname, cmd, inet_ntoa(rt->gate)); in desc_route()
292 ifname, cmd, addr, inet_ntocidr(rt->net), in desc_route()
293 inet_ntoa(rt->gate)); in desc_route()
296 static struct rt *
297 ipv4_findrt(struct dhcpcd_ctx *ctx, const struct rt *rt, int flags) in ipv4_findrt() argument
299 struct rt *r; in ipv4_findrt()
304 if (rt->dest.s_addr == r->dest.s_addr && in ipv4_findrt()
306 rt->iface == r->iface && in ipv4_findrt()
307 (!flags || rt->metric == r->metric) && in ipv4_findrt()
309 (!flags || rt->iface == r->iface) && in ipv4_findrt()
311 rt->net.s_addr == r->net.s_addr) in ipv4_findrt()
320 struct rt *rt; in ipv4_freerts() local
322 while ((rt = TAILQ_FIRST(routes))) { in ipv4_freerts()
323 TAILQ_REMOVE(routes, rt, next); in ipv4_freerts()
324 free(rt); in ipv4_freerts()
331 ipv4_handlert(struct dhcpcd_ctx *ctx, int cmd, struct rt *rt) in ipv4_handlert() argument
333 struct rt *f; in ipv4_handlert()
338 f = ipv4_findrt(ctx, rt, 1); in ipv4_handlert()
344 *f = *rt; in ipv4_handlert()
355 if ((f = find_route(ctx->ipv4_routes, rt, NULL))) { in ipv4_handlert()
368 nc_route(struct rt *ort, struct rt *nrt) in nc_route()
428 d_route(struct rt *rt) in d_route() argument
432 desc_route("deleting", rt); in d_route()
433 retval = if_route(RTM_DELETE, rt); in d_route()
435 logger(rt->iface->ctx, LOG_ERR, in d_route()
436 "%s: if_delroute: %m", rt->iface->name); in d_route()
441 add_subnet_route(struct rt_head *rt, const struct interface *ifp) in add_subnet_route() argument
444 struct rt *r; in add_subnet_route()
446 if (rt == NULL) /* earlier malloc failed */ in add_subnet_route()
452 return rt; in add_subnet_route()
456 return rt; in add_subnet_route()
461 ipv4_freeroutes(rt); in add_subnet_route()
468 TAILQ_INSERT_HEAD(rt, r, next); in add_subnet_route()
469 return rt; in add_subnet_route()
474 add_loopback_route(struct rt_head *rt, const struct interface *ifp) in add_loopback_route() argument
476 struct rt *r; in add_loopback_route()
479 if (rt == NULL) /* earlier malloc failed */ in add_loopback_route()
484 return rt; in add_loopback_route()
489 ipv4_freeroutes(rt); in add_loopback_route()
495 TAILQ_INSERT_HEAD(rt, r, next); in add_loopback_route()
496 return rt; in add_loopback_route()
504 struct rt *rt, *r = NULL; in get_routes() local
509 TAILQ_FOREACH(rt, ifp->options->routes, next) { in get_routes()
510 if (rt->gate.s_addr == 0) in get_routes()
518 memcpy(r, rt, sizeof(*r)); in get_routes()
531 massage_host_routes(struct rt_head *rt, const struct interface *ifp) in massage_host_routes() argument
533 struct rt *r; in massage_host_routes()
535 if (rt) { in massage_host_routes()
536 TAILQ_FOREACH(r, rt, next) { in massage_host_routes()
545 return rt; in massage_host_routes()
550 add_destination_route(struct rt_head *rt, const struct interface *ifp) in add_destination_route() argument
552 struct rt *r; in add_destination_route()
554 if (rt == NULL || /* failed a malloc earlier probably */ in add_destination_route()
557 return rt; in add_destination_route()
562 ipv4_freeroutes(rt); in add_destination_route()
568 TAILQ_INSERT_HEAD(rt, r, next); in add_destination_route()
569 return rt; in add_destination_route()
575 add_router_host_route(struct rt_head *rt, const struct interface *ifp) in add_router_host_route() argument
577 struct rt *rtp, *rtn; in add_router_host_route()
582 if (rt == NULL) /* earlier malloc failed */ in add_router_host_route()
585 TAILQ_FOREACH(rtp, rt, next) { in add_router_host_route()
589 TAILQ_FOREACH(rtn, rt, next) { in add_router_host_route()
634 ipv4_freeroutes(rt); in add_router_host_route()
642 return rt; in add_router_host_route()
651 struct rt *or, *rt, *rtn; in ipv4_buildroutes() local
682 TAILQ_FOREACH_SAFE(rt, dnr, next, rtn) { in ipv4_buildroutes()
683 rt->iface = ifp; in ipv4_buildroutes()
685 rt->metric = ifp->metric; in ipv4_buildroutes()
687 rt->flags = state->added & STATE_FAKE; in ipv4_buildroutes()
689 if ((find_route(nrs, rt, NULL)) != NULL) in ipv4_buildroutes()
691 rt->src.s_addr = state->addr.s_addr; in ipv4_buildroutes()
693 if ((or = find_route(ctx->ipv4_routes, rt, NULL))) { in ipv4_buildroutes()
699 rt->metric != or->metric || in ipv4_buildroutes()
702 rt->gate.s_addr != or->gate.s_addr) in ipv4_buildroutes()
704 if (c_route(or, rt) != 0) in ipv4_buildroutes()
711 or = ipv4_findrt(ctx, rt, 1); in ipv4_buildroutes()
713 or->gate.s_addr != rt->gate.s_addr) in ipv4_buildroutes()
716 if (n_route(rt) != 0) in ipv4_buildroutes()
720 rt->flags |= STATE_ADDED; in ipv4_buildroutes()
721 TAILQ_REMOVE(dnr, rt, next); in ipv4_buildroutes()
722 TAILQ_INSERT_TAIL(nrs, rt, next); in ipv4_buildroutes()
729 TAILQ_FOREACH(rt, ctx->ipv4_routes, next) { in ipv4_buildroutes()
730 if (find_route(nrs, rt, NULL) == NULL && in ipv4_buildroutes()
731 (rt->iface->options->options & in ipv4_buildroutes()
734 d_route(rt); in ipv4_buildroutes()