Lines Matching refs:rt

60 static struct rt *routes;
62 static struct rt *
63 find_route(struct rt *rts, const struct rt *r, struct rt **lrt, in find_route()
64 const struct rt *srt) in find_route()
66 struct rt *rt; in find_route() local
70 for (rt = rts; rt; rt = rt->next) { in find_route()
71 if (rt->dest.s_addr == r->dest.s_addr && in find_route()
73 (srt || (!rt->iface || in find_route()
74 rt->iface->metric == r->iface->metric)) && in find_route()
76 (!srt || srt != rt) && in find_route()
77 rt->net.s_addr == r->net.s_addr) in find_route()
78 return rt; in find_route()
80 *lrt = rt; in find_route()
86 desc_route(const char *cmd, const struct rt *rt, const char *ifname) in desc_route() argument
90 strlcpy(addr, inet_ntoa(rt->dest), sizeof(addr)); in desc_route()
91 if (rt->gate.s_addr == INADDR_ANY) in desc_route()
93 addr, inet_ntocidr(rt->net)); in desc_route()
94 else if (rt->gate.s_addr == rt->dest.s_addr && in desc_route()
95 rt->net.s_addr == INADDR_BROADCAST) in desc_route()
98 else if (rt->dest.s_addr == INADDR_ANY && rt->net.s_addr == INADDR_ANY) in desc_route()
100 inet_ntoa(rt->gate)); in desc_route()
103 addr, inet_ntocidr(rt->net), inet_ntoa(rt->gate)); in desc_route()
109 route_deleted(const struct rt *rt) in route_deleted() argument
111 struct rt *f, *l; in route_deleted()
113 f = find_route(routes, rt, &l, NULL); in route_deleted()
126 n_route(struct rt *rt, const struct interface *iface) in n_route() argument
129 if (rt->dest.s_addr == 0 && in n_route()
130 rt->net.s_addr == 0 && in n_route()
134 desc_route("adding", rt, iface->name); in n_route()
135 if (!add_route(iface, &rt->dest, &rt->net, &rt->gate, iface->metric)) in n_route()
139 if (rt->dest.s_addr == (iface->addr.s_addr & iface->net.s_addr) && in n_route()
140 rt->net.s_addr == iface->net.s_addr && in n_route()
141 rt->gate.s_addr == 0) in n_route()
151 c_route(struct rt *ort, struct rt *nrt, const struct interface *iface) in c_route()
173 d_route(struct rt *rt, const struct interface *iface, int metric) in d_route() argument
177 desc_route("deleting", rt, iface->name); in d_route()
178 retval = del_route(iface, &rt->dest, &rt->net, &rt->gate, metric); in d_route()
184 static struct rt *
189 struct rt *rt; in get_subnet_route() local
199 rt = malloc(sizeof(*rt)); in get_subnet_route()
200 rt->dest.s_addr = addr & net.s_addr; in get_subnet_route()
201 rt->net.s_addr = net.s_addr; in get_subnet_route()
202 rt->gate.s_addr = 0; in get_subnet_route()
203 return rt; in get_subnet_route()
206 static struct rt *
207 add_subnet_route(struct rt *rt, const struct interface *iface) in add_subnet_route() argument
209 struct rt *r; in add_subnet_route()
216 return rt; in add_subnet_route()
222 r->next = rt; in add_subnet_route()
226 static struct rt *
229 struct rt *rt, *nrt = NULL, *r = NULL; in get_routes() local
232 for (rt = iface->state->options->routes; in get_routes()
233 rt != NULL; in get_routes()
234 rt = rt->next) in get_routes()
236 if (rt->gate.s_addr == 0) in get_routes()
244 memcpy(r, rt, sizeof(*r)); in get_routes()
257 static struct rt *
258 massage_host_routes(struct rt *rt, const struct interface *iface) in massage_host_routes() argument
260 struct rt *r; in massage_host_routes()
262 for (r = rt; r; r = r->next) in massage_host_routes()
266 return rt; in massage_host_routes()
269 static struct rt *
270 add_destination_route(struct rt *rt, const struct interface *iface) in add_destination_route() argument
272 struct rt *r; in add_destination_route()
276 return rt; in add_destination_route()
281 r->next = rt; in add_destination_route()
287 static struct rt *
288 add_router_host_route(struct rt *rt, const struct interface *ifp) in add_router_host_route() argument
290 struct rt *rtp, *rtl, *rtn; in add_router_host_route()
293 for (rtp = rt, rtl = NULL; rtp; rtl = rtp, rtp = rtp->next) { in add_router_host_route()
297 for (rtn = rt; rtn != rtp; rtn = rtn->next) { in add_router_host_route()
330 rt = rtn; in add_router_host_route()
334 return rt; in add_router_host_route()
340 struct rt *nrs = NULL, *dnr, *or, *rt, *rtn, *rtl, *lrt = NULL; in build_routes() local
351 for (rt = dnr; rt && (rtn = rt->next, 1); lrt = rt, rt = rtn) { in build_routes()
352 rt->iface = ifp; in build_routes()
354 if ((find_route(nrs, rt, NULL, NULL)) != NULL) in build_routes()
357 if ((or = find_route(routes, rt, &rtl, NULL))) { in build_routes()
359 rt->gate.s_addr != or->gate.s_addr) in build_routes()
361 if (c_route(or, rt, ifp) != 0) in build_routes()
370 if (n_route(rt, ifp) != 0) in build_routes()
373 if (dnr == rt) in build_routes()
377 rt->next = nrs; in build_routes()
378 nrs = rt; in build_routes()
384 for (rt = routes; rt; rt = rt->next) { in build_routes()
385 if (find_route(nrs, rt, NULL, NULL) == NULL) in build_routes()
386 d_route(rt, rt->iface, rt->iface->metric); in build_routes()
421 struct rt *rt; in configure() local
449 rt = get_subnet_route(dhcp); in configure()
450 if (rt != NULL) { in configure()
451 rt->iface = iface; in configure()
452 if (!find_route(routes, rt, NULL, NULL)) in configure()
453 del_route(iface, &rt->dest, &rt->net, &rt->gate, 0); in configure()
454 free(rt); in configure()