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