Lines Matching defs:route

24 #include "networkd-route.h"
32 _cleanup_route_free_ Route *route = NULL;
34 route = new0(Route, 1);
35 if (!route)
38 route->family = AF_UNSPEC;
39 route->scope = RT_SCOPE_UNIVERSE;
40 route->protocol = RTPROT_UNSPEC;
41 route->table = RT_TABLE_DEFAULT;
42 route->lifetime = USEC_INFINITY;
44 *ret = route;
45 route = NULL;
51 _cleanup_route_free_ Route *route = NULL;
55 route = hashmap_get(network->routes_by_section,
57 if (route) {
58 *ret = route;
59 route = NULL;
65 r = route_new(&route);
69 route->protocol = RTPROT_STATIC;
70 route->network = network;
72 LIST_PREPEND(routes, network->static_routes, route);
75 route->section = section;
77 UINT_TO_PTR(route->section), route);
80 *ret = route;
81 route = NULL;
86 void route_free(Route *route) {
87 if (!route)
90 if (route->network) {
91 LIST_REMOVE(routes, route->network->static_routes, route);
93 if (route->section)
94 hashmap_remove(route->network->routes_by_section,
95 UINT_TO_PTR(route->section));
98 if (route->link) {
99 set_remove(route->link->routes, route);
100 set_remove(route->link->routes_foreign, route);
103 sd_event_source_unref(route->expire);
105 free(route);
109 const Route *route = b;
111 assert(route);
113 siphash24_compress(&route->family, sizeof(route->family), state);
115 switch (route->family) {
120 siphash24_compress(&route->dst, FAMILY_ADDRESS_SIZE(route->family), state);
121 siphash24_compress(&route->dst_prefixlen, sizeof(route->dst_prefixlen), state);
122 siphash24_compress(&route->tos, sizeof(route->tos), state);
123 siphash24_compress(&route->priority, sizeof(route->priority), state);
124 siphash24_compress(&route->table, sizeof(route->table), state);
184 Route route = {
196 route.dst = *dst;
198 existing = set_get(link->routes, &route);
203 existing = set_get(link->routes_foreign, &route);
220 _cleanup_route_free_ Route *route = NULL;
227 r = route_new(&route);
231 route->family = family;
232 route->dst = *dst;
233 route->dst_prefixlen = dst_prefixlen;
234 route->tos = tos;
235 route->priority = priority;
236 route->table = table;
242 r = set_put(*routes, route);
246 route->link = link;
249 *ret = route;
251 route = NULL;
273 Route *route;
276 r = route_get(link, family, dst, dst_prefixlen, tos, priority, table, &route);
279 r = route_add_internal(link, &link->routes, family, dst, dst_prefixlen, tos, priority, table, &route);
283 /* Take over a foreign route */
288 r = set_put(link->routes, route);
292 set_remove(link->routes_foreign, route);
299 *ret = route;
304 int route_update(Route *route,
311 assert(route);
316 route->src = *src;
317 route->src_prefixlen = src_prefixlen;
318 route->gw = *gw;
319 route->prefsrc = *prefsrc;
320 route->scope = scope;
321 route->protocol = protocol;
326 void route_drop(Route *route) {
327 assert(route);
329 route_free(route);
332 int route_remove(Route *route, Link *link,
341 assert(route->family == AF_INET || route->family == AF_INET6);
344 RTM_DELROUTE, route->family,
345 route->protocol);
349 if (!in_addr_is_null(route->family, &route->gw)) {
350 if (route->family == AF_INET)
351 r = sd_netlink_message_append_in_addr(req, RTA_GATEWAY, &route->gw.in);
352 else if (route->family == AF_INET6)
353 r = sd_netlink_message_append_in6_addr(req, RTA_GATEWAY, &route->gw.in6);
358 if (route->dst_prefixlen) {
359 if (route->family == AF_INET)
360 r = sd_netlink_message_append_in_addr(req, RTA_DST, &route->dst.in);
361 else if (route->family == AF_INET6)
362 r = sd_netlink_message_append_in6_addr(req, RTA_DST, &route->dst.in6);
366 r = sd_rtnl_message_route_set_dst_prefixlen(req, route->dst_prefixlen);
371 if (route->src_prefixlen) {
372 if (route->family == AF_INET)
373 r = sd_netlink_message_append_in_addr(req, RTA_SRC, &route->src.in);
374 else if (route->family == AF_INET6)
375 r = sd_netlink_message_append_in6_addr(req, RTA_SRC, &route->src.in6);
379 r = sd_rtnl_message_route_set_src_prefixlen(req, route->src_prefixlen);
384 if (!in_addr_is_null(route->family, &route->prefsrc)) {
385 if (route->family == AF_INET)
386 r = sd_netlink_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc.in);
387 else if (route->family == AF_INET6)
388 r = sd_netlink_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc.in6);
393 r = sd_rtnl_message_route_set_scope(req, route->scope);
397 r = sd_netlink_message_append_u32(req, RTA_PRIORITY, route->priority);
415 Route *route = userdata;
418 assert(route);
420 r = route_remove(route, route->link, NULL);
422 log_warning_errno(r, "Could not remove route: %m");
427 int route_configure(Route *route, Link *link,
438 assert(route->family == AF_INET || route->family == AF_INET6);
441 RTM_NEWROUTE, route->family,
442 route->protocol);
446 if (!in_addr_is_null(route->family, &route->gw)) {
447 if (route->family == AF_INET)
448 r = sd_netlink_message_append_in_addr(req, RTA_GATEWAY, &route->gw.in);
449 else if (route->family == AF_INET6)
450 r = sd_netlink_message_append_in6_addr(req, RTA_GATEWAY, &route->gw.in6);
455 if (route->dst_prefixlen) {
456 if (route->family == AF_INET)
457 r = sd_netlink_message_append_in_addr(req, RTA_DST, &route->dst.in);
458 else if (route->family == AF_INET6)
459 r = sd_netlink_message_append_in6_addr(req, RTA_DST, &route->dst.in6);
463 r = sd_rtnl_message_route_set_dst_prefixlen(req, route->dst_prefixlen);
468 if (route->src_prefixlen) {
469 if (route->family == AF_INET)
470 r = sd_netlink_message_append_in_addr(req, RTA_SRC, &route->src.in);
471 else if (route->family == AF_INET6)
472 r = sd_netlink_message_append_in6_addr(req, RTA_SRC, &route->src.in6);
476 r = sd_rtnl_message_route_set_src_prefixlen(req, route->src_prefixlen);
481 if (!in_addr_is_null(route->family, &route->prefsrc)) {
482 if (route->family == AF_INET)
483 r = sd_netlink_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc.in);
484 else if (route->family == AF_INET6)
485 r = sd_netlink_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc.in6);
490 r = sd_rtnl_message_route_set_scope(req, route->scope);
494 r = sd_rtnl_message_route_set_flags(req, route->flags);
498 r = sd_netlink_message_append_u32(req, RTA_PRIORITY, route->priority);
502 r = sd_netlink_message_append_u8(req, RTA_PREF, route->pref);
516 lifetime = route->lifetime;
518 r = route_add(link, route->family, &route->dst, route->dst_prefixlen, route->tos, route->priority, route->table, &route);
520 return log_error_errno(r, "Could not add route: %m");
523 route->lifetime = lifetime;
525 if (route->lifetime != USEC_INFINITY) {
527 route->lifetime, 0, route_expire_handler, route);
532 sd_event_source_unref(route->expire);
533 route->expire = expire;
771 log_syntax(unit, LOG_ERR, filename, line, 0, "Unknown route scope: %s", rvalue);