Lines Matching refs:rt

65 static struct rt *routes;
414 static struct rt *
415 find_route(struct rt *rts, const struct rt *r, struct rt **lrt, in find_route()
416 const struct rt *srt) in find_route()
418 struct rt *rt; in find_route() local
422 for (rt = rts; rt; rt = rt->next) { in find_route()
423 if (rt->dest.s_addr == r->dest.s_addr && in find_route()
425 (srt || (!rt->iface || in find_route()
426 rt->iface->metric == r->iface->metric)) && in find_route()
428 (!srt || srt != rt) && in find_route()
429 rt->net.s_addr == r->net.s_addr) in find_route()
430 return rt; in find_route()
432 *lrt = rt; in find_route()
438 desc_route(const char *cmd, const struct rt *rt) in desc_route() argument
441 const char *ifname = rt->iface->name; in desc_route()
443 strlcpy(addr, inet_ntoa(rt->dest), sizeof(addr)); in desc_route()
444 if (rt->gate.s_addr == INADDR_ANY) in desc_route()
446 addr, inet_ntocidr(rt->net)); in desc_route()
447 else if (rt->gate.s_addr == rt->dest.s_addr && in desc_route()
448 rt->net.s_addr == INADDR_BROADCAST) in desc_route()
451 else if (rt->dest.s_addr == INADDR_ANY && rt->net.s_addr == INADDR_ANY) in desc_route()
453 inet_ntoa(rt->gate)); in desc_route()
456 addr, inet_ntocidr(rt->net), inet_ntoa(rt->gate)); in desc_route()
462 route_deleted(const struct rt *rt) in route_deleted() argument
464 struct rt *f, *l; in route_deleted()
466 f = find_route(routes, rt, &l, NULL); in route_deleted()
479 n_route(struct rt *rt) in n_route() argument
482 if (rt->dest.s_addr == 0 && in n_route()
483 rt->net.s_addr == 0 && in n_route()
484 !(rt->iface->state->options->options & DHCPCD_GATEWAY)) in n_route()
487 desc_route("adding", rt); in n_route()
488 if (!add_route(rt)) in n_route()
492 if (rt->dest.s_addr == in n_route()
493 (rt->iface->addr.s_addr & rt->iface->net.s_addr) && in n_route()
494 rt->net.s_addr == rt->iface->net.s_addr && in n_route()
495 rt->gate.s_addr == 0) in n_route()
500 syslog(LOG_ERR, "%s: add_route: %m", rt->iface->name); in n_route()
505 c_route(struct rt *ort, struct rt *nrt) in c_route()
525 d_route(struct rt *rt) in d_route() argument
529 desc_route("deleting", rt); in d_route()
530 retval = del_route(rt); in d_route()
532 syslog(LOG_ERR,"%s: del_route: %m", rt->iface->name); in d_route()
536 static struct rt *
541 struct rt *rt; in get_subnet_route() local
551 rt = malloc(sizeof(*rt)); in get_subnet_route()
552 rt->dest.s_addr = addr & net.s_addr; in get_subnet_route()
553 rt->net.s_addr = net.s_addr; in get_subnet_route()
554 rt->gate.s_addr = 0; in get_subnet_route()
555 return rt; in get_subnet_route()
558 static struct rt *
559 add_subnet_route(struct rt *rt, const struct interface *iface) in add_subnet_route() argument
561 struct rt *r; in add_subnet_route()
568 return rt; in add_subnet_route()
574 r->next = rt; in add_subnet_route()
578 static struct rt *
581 struct rt *rt, *nrt = NULL, *r = NULL; in get_routes() local
584 for (rt = iface->state->options->routes; in get_routes()
585 rt != NULL; in get_routes()
586 rt = rt->next) in get_routes()
588 if (rt->gate.s_addr == 0) in get_routes()
596 memcpy(r, rt, sizeof(*r)); in get_routes()
609 static struct rt *
610 massage_host_routes(struct rt *rt, const struct interface *iface) in massage_host_routes() argument
612 struct rt *r; in massage_host_routes()
614 for (r = rt; r; r = r->next) in massage_host_routes()
618 return rt; in massage_host_routes()
621 static struct rt *
622 add_destination_route(struct rt *rt, const struct interface *iface) in add_destination_route() argument
624 struct rt *r; in add_destination_route()
628 return rt; in add_destination_route()
633 r->next = rt; in add_destination_route()
639 static struct rt *
640 add_router_host_route(struct rt *rt, const struct interface *ifp) in add_router_host_route() argument
642 struct rt *rtp, *rtl, *rtn; in add_router_host_route()
645 for (rtp = rt, rtl = NULL; rtp; rtl = rtp, rtp = rtp->next) { in add_router_host_route()
649 for (rtn = rt; rtn != rtp; rtn = rtn->next) { in add_router_host_route()
682 rt = rtn; in add_router_host_route()
686 return rt; in add_router_host_route()
692 struct rt *nrs = NULL, *dnr, *or, *rt, *rtn, *rtl, *lrt = NULL; in build_routes() local
705 for (rt = dnr; rt && (rtn = rt->next, 1); lrt = rt, rt = rtn) { in build_routes()
706 rt->iface = ifp; in build_routes()
707 rt->metric = ifp->metric; in build_routes()
709 if ((find_route(nrs, rt, NULL, NULL)) != NULL) in build_routes()
711 rt->src.s_addr = ifp->addr.s_addr; in build_routes()
713 if ((or = find_route(routes, rt, &rtl, NULL))) { in build_routes()
716 rt->gate.s_addr != or->gate.s_addr || in build_routes()
717 rt->metric != or->metric) in build_routes()
719 if (c_route(or, rt) != 0) in build_routes()
728 if (n_route(rt) != 0) in build_routes()
731 if (dnr == rt) in build_routes()
735 rt->next = nrs; in build_routes()
736 nrs = rt; in build_routes()
737 rt = lrt; /* When we loop this makes lrt correct */ in build_routes()
743 for (rt = routes; rt; rt = rt->next) { in build_routes()
744 if (find_route(nrs, rt, NULL, NULL) == NULL) in build_routes()
745 d_route(rt); in build_routes()
780 struct rt *rt; in configure() local
823 rt = get_subnet_route(dhcp); in configure()
824 if (rt != NULL) { in configure()
825 rt->iface = iface; in configure()
826 rt->metric = 0; in configure()
827 if (!find_route(routes, rt, NULL, NULL)) in configure()
828 del_route(rt); in configure()
829 free(rt); in configure()