Lines Matching refs:route
25 _cleanup_(route_freep) Route *route = NULL; in route_new()
27 route = new(Route, 1); in route_new()
28 if (!route) in route_new()
31 *route = (Route) { in route_new()
44 *ret = TAKE_PTR(route); in route_new()
51 _cleanup_(route_freep) Route *route = NULL; in route_new_static()
63 route = hashmap_get(network->routes_by_section, n); in route_new_static()
64 if (route) { in route_new_static()
65 *ret = TAKE_PTR(route); in route_new_static()
72 r = route_new(&route); in route_new_static()
76 route->protocol = RTPROT_STATIC; in route_new_static()
77 route->network = network; in route_new_static()
78 route->section = TAKE_PTR(n); in route_new_static()
79 route->source = NETWORK_CONFIG_SOURCE_STATIC; in route_new_static()
81 …= hashmap_ensure_put(&network->routes_by_section, &config_section_hash_ops, route->section, route); in route_new_static()
85 *ret = TAKE_PTR(route); in route_new_static()
89 Route *route_free(Route *route) { in route_free() argument
90 if (!route) in route_free()
93 if (route->network) { in route_free()
94 assert(route->section); in route_free()
95 hashmap_remove(route->network->routes_by_section, route->section); in route_free()
98 config_section_free(route->section); in route_free()
100 if (route->link) in route_free()
101 set_remove(route->link->routes, route); in route_free()
103 if (route->manager) in route_free()
104 set_remove(route->manager->routes, route); in route_free()
106 ordered_set_free_with_destructor(route->multipath_routes, multipath_route_free); in route_free()
108 sd_event_source_disable_unref(route->expire); in route_free()
110 return mfree(route); in route_free()
113 static void route_hash_func(const Route *route, struct siphash *state) { in route_hash_func() argument
114 assert(route); in route_hash_func()
116 siphash24_compress(&route->family, sizeof(route->family), state); in route_hash_func()
118 switch (route->family) { in route_hash_func()
121 siphash24_compress(&route->dst_prefixlen, sizeof(route->dst_prefixlen), state); in route_hash_func()
122 siphash24_compress(&route->dst, FAMILY_ADDRESS_SIZE(route->family), state); in route_hash_func()
124 siphash24_compress(&route->src_prefixlen, sizeof(route->src_prefixlen), state); in route_hash_func()
125 siphash24_compress(&route->src, FAMILY_ADDRESS_SIZE(route->family), state); in route_hash_func()
127 siphash24_compress(&route->gw_family, sizeof(route->gw_family), state); in route_hash_func()
128 if (IN_SET(route->gw_family, AF_INET, AF_INET6)) { in route_hash_func()
129 … siphash24_compress(&route->gw, FAMILY_ADDRESS_SIZE(route->gw_family), state); in route_hash_func()
130 siphash24_compress(&route->gw_weight, sizeof(route->gw_weight), state); in route_hash_func()
133 siphash24_compress(&route->prefsrc, FAMILY_ADDRESS_SIZE(route->family), state); in route_hash_func()
135 siphash24_compress(&route->tos, sizeof(route->tos), state); in route_hash_func()
136 siphash24_compress(&route->priority, sizeof(route->priority), state); in route_hash_func()
137 siphash24_compress(&route->table, sizeof(route->table), state); in route_hash_func()
138 siphash24_compress(&route->protocol, sizeof(route->protocol), state); in route_hash_func()
139 siphash24_compress(&route->scope, sizeof(route->scope), state); in route_hash_func()
140 siphash24_compress(&route->type, sizeof(route->type), state); in route_hash_func()
142 siphash24_compress(&route->initcwnd, sizeof(route->initcwnd), state); in route_hash_func()
143 siphash24_compress(&route->initrwnd, sizeof(route->initrwnd), state); in route_hash_func()
145 siphash24_compress(&route->advmss, sizeof(route->advmss), state); in route_hash_func()
146 siphash24_compress(&route->nexthop_id, sizeof(route->nexthop_id), state); in route_hash_func()
253 static bool route_type_is_reject(const Route *route) { in route_type_is_reject() argument
254 assert(route); in route_type_is_reject()
256 return IN_SET(route->type, RTN_UNREACHABLE, RTN_PROHIBIT, RTN_BLACKHOLE, RTN_THROW); in route_type_is_reject()
259 static bool route_needs_convert(const Route *route) { in route_needs_convert() argument
260 assert(route); in route_needs_convert()
262 return route->nexthop_id > 0 || !ordered_set_isempty(route->multipath_routes); in route_needs_convert()
265 static int route_add(Manager *manager, Link *link, Route *route) { in route_add() argument
268 assert(route); in route_add()
270 if (route_type_is_reject(route)) { in route_add()
273 r = set_ensure_put(&manager->routes, &route_hash_ops, route); in route_add()
279 route->manager = manager; in route_add()
283 r = set_ensure_put(&link->routes, &route_hash_ops, route); in route_add()
289 route->link = link; in route_add()
296 Route *route; in route_get() local
304 route = set_get(manager->routes, in); in route_get()
309 route = set_get(link->routes, in); in route_get()
311 if (!route) in route_get()
315 *ret = route; in route_get()
344 static void route_apply_nexthop(Route *route, const NextHop *nh, uint8_t nh_weight) { in route_apply_nexthop() argument
345 assert(route); in route_apply_nexthop()
349 route->gw_family = nh->family; in route_apply_nexthop()
350 route->gw = nh->gw; in route_apply_nexthop()
353 route->gw_weight = nh_weight; in route_apply_nexthop()
356 route->type = RTN_BLACKHOLE; in route_apply_nexthop()
359 static void route_apply_multipath_route(Route *route, const MultipathRoute *m) { in route_apply_multipath_route() argument
360 assert(route); in route_apply_multipath_route()
363 route->gw_family = m->gateway.family; in route_apply_multipath_route()
364 route->gw = m->gateway.address; in route_apply_multipath_route()
365 route->gw_weight = m->weight; in route_apply_multipath_route()
439 static int route_convert(Manager *manager, const Route *route, ConvertedRoutes **ret) { in route_convert() argument
444 assert(route); in route_convert()
447 if (!route_needs_convert(route)) { in route_convert()
452 if (route->nexthop_id > 0) { in route_convert()
456 r = manager_get_nexthop_by_id(manager, route->nexthop_id, &nh); in route_convert()
465 r = route_dup(route, &c->routes[0]); in route_convert()
488 r = route_dup(route, &c->routes[i]); in route_convert()
503 assert(!ordered_set_isempty(route->multipath_routes)); in route_convert()
505 r = converted_routes_new(ordered_set_size(route->multipath_routes), &c); in route_convert()
511 ORDERED_SET_FOREACH(m, route->multipath_routes) { in route_convert()
512 r = route_dup(route, &c->routes[i]); in route_convert()
530 Route *route; in link_mark_routes() local
534 SET_FOREACH(route, link->routes) { in link_mark_routes()
535 if (route->source != source) in link_mark_routes()
539 router && !in6_addr_equal(router, &route->provider.in6)) in link_mark_routes()
542 route_mark(route); in link_mark_routes()
546 static void log_route_debug(const Route *route, const char *str, const Link *link, const Manager *m… in log_route_debug() argument
551 assert(route); in log_route_debug()
560 (void) network_config_state_to_string_alloc(route->state, &state); in log_route_debug()
561 if (in_addr_is_set(route->family, &route->dst) || route->dst_prefixlen > 0) in log_route_debug()
562 … (void) in_addr_prefix_to_string(route->family, &route->dst, route->dst_prefixlen, &dst); in log_route_debug()
563 if (in_addr_is_set(route->family, &route->src) || route->src_prefixlen > 0) in log_route_debug()
564 … (void) in_addr_prefix_to_string(route->family, &route->src, route->src_prefixlen, &src); in log_route_debug()
565 if (in_addr_is_set(route->gw_family, &route->gw)) { in log_route_debug()
566 (void) in_addr_to_string(route->gw_family, &route->gw, &gw_alloc); in log_route_debug()
568 } else if (route->gateway_from_dhcp_or_ra) { in log_route_debug()
569 if (route->gw_family == AF_INET) in log_route_debug()
571 else if (route->gw_family == AF_INET6) in log_route_debug()
576 ORDERED_SET_FOREACH(m, route->multipath_routes) { in log_route_debug()
591 if (in_addr_is_set(route->family, &route->prefsrc)) in log_route_debug()
592 (void) in_addr_to_string(route->family, &route->prefsrc, &prefsrc); in log_route_debug()
593 (void) route_scope_to_string_alloc(route->scope, &scope); in log_route_debug()
594 (void) manager_get_route_table_to_string(manager, route->table, &table); in log_route_debug()
595 (void) route_protocol_full_to_string_alloc(route->protocol, &proto); in log_route_debug()
596 (void) route_flags_to_string_alloc(route->flags, &flags); in log_route_debug()
601 str, strna(network_config_source_to_string(route->source)), strna(state), in log_route_debug()
604 strna(route_type_to_string(route->type)), in log_route_debug()
605 route->nexthop_id, route->priority, strna(flags)); in log_route_debug()
608 static int route_set_netlink_message(const Route *route, sd_netlink_message *req, Link *link) { in route_set_netlink_message() argument
611 assert(route); in route_set_netlink_message()
616 if (in_addr_is_set(route->gw_family, &route->gw) && route->nexthop_id == 0) { in route_set_netlink_message()
617 if (route->gw_family == route->family) { in route_set_netlink_message()
618 … r = netlink_message_append_in_addr_union(req, RTA_GATEWAY, route->gw_family, &route->gw); in route_set_netlink_message()
623 .family = route->gw_family, in route_set_netlink_message()
624 .address = route->gw, in route_set_netlink_message()
633 if (route->dst_prefixlen > 0) { in route_set_netlink_message()
634 r = netlink_message_append_in_addr_union(req, RTA_DST, route->family, &route->dst); in route_set_netlink_message()
638 r = sd_rtnl_message_route_set_dst_prefixlen(req, route->dst_prefixlen); in route_set_netlink_message()
643 if (route->src_prefixlen > 0) { in route_set_netlink_message()
644 r = netlink_message_append_in_addr_union(req, RTA_SRC, route->family, &route->src); in route_set_netlink_message()
648 r = sd_rtnl_message_route_set_src_prefixlen(req, route->src_prefixlen); in route_set_netlink_message()
653 if (in_addr_is_set(route->family, &route->prefsrc)) { in route_set_netlink_message()
654 … r = netlink_message_append_in_addr_union(req, RTA_PREFSRC, route->family, &route->prefsrc); in route_set_netlink_message()
659 r = sd_rtnl_message_route_set_scope(req, route->scope); in route_set_netlink_message()
663 r = sd_rtnl_message_route_set_flags(req, route->flags & RTNH_F_ONLINK); in route_set_netlink_message()
667 if (route->table < 256) { in route_set_netlink_message()
668 r = sd_rtnl_message_route_set_table(req, route->table); in route_set_netlink_message()
677 r = sd_netlink_message_append_u32(req, RTA_TABLE, route->table); in route_set_netlink_message()
682 if (!route_type_is_reject(route) && in route_set_netlink_message()
683 route->nexthop_id == 0 && in route_set_netlink_message()
684 ordered_set_isempty(route->multipath_routes)) { in route_set_netlink_message()
692 if (route->nexthop_id > 0) { in route_set_netlink_message()
693 r = sd_netlink_message_append_u32(req, RTA_NH_ID, route->nexthop_id); in route_set_netlink_message()
698 r = sd_netlink_message_append_u8(req, RTA_PREF, route->pref); in route_set_netlink_message()
702 r = sd_netlink_message_append_u32(req, RTA_PRIORITY, route->priority); in route_set_netlink_message()
726 int route_remove(Route *route) { in route_remove() argument
733 assert(route); in route_remove()
734 assert(route->manager || (route->link && route->link->manager)); in route_remove()
735 assert(IN_SET(route->family, AF_INET, AF_INET6)); in route_remove()
737 link = route->link; in route_remove()
738 manager = route->manager ?: link->manager; in route_remove()
740 log_route_debug(route, "Removing", link, manager); in route_remove()
743 RTM_DELROUTE, route->family, in route_remove()
744 route->protocol); in route_remove()
748 if (route->family == AF_INET && route->nexthop_id > 0 && route->type == RTN_BLACKHOLE) in route_remove()
757 type = route->type; in route_remove()
763 r = route_set_netlink_message(route, req, link); in route_remove()
774 route_enter_removing(route); in route_remove()
779 Route *route; in manager_mark_routes() local
786 SET_FOREACH(route, manager->routes) { in manager_mark_routes()
788 if (route->protocol == RTPROT_KERNEL) in manager_mark_routes()
792 if (foreign != (route->source == NETWORK_CONFIG_SOURCE_FOREIGN)) in manager_mark_routes()
796 if (IN_SET(route->source, NETWORK_CONFIG_SOURCE_DHCP4, NETWORK_CONFIG_SOURCE_DHCP6)) in manager_mark_routes()
800 if (!route_exists(route)) in manager_mark_routes()
803 route_mark(route); in manager_mark_routes()
817 HASHMAP_FOREACH(route, link->network->routes_by_section) { in manager_mark_routes()
821 r = route_convert(manager, route, &converted); in manager_mark_routes()
825 if (route_get(manager, NULL, route, &existing) >= 0) in manager_mark_routes()
838 Route *route; in manager_drop_marked_routes() local
843 SET_FOREACH(route, manager->routes) { in manager_drop_marked_routes()
844 if (!route_is_marked(route)) in manager_drop_marked_routes()
847 k = route_remove(route); in manager_drop_marked_routes()
855 static bool route_by_kernel(const Route *route) { in route_by_kernel() argument
856 assert(route); in route_by_kernel()
858 if (route->protocol == RTPROT_KERNEL) in route_by_kernel()
863 if (route->protocol == RTPROT_BOOT && in route_by_kernel()
864 route->family == AF_INET6 && in route_by_kernel()
865 route->dst_prefixlen == 8 && in route_by_kernel()
866 …in6_addr_equal(&route->dst.in6, & (struct in6_addr) {{{ 0xff,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 }}})) in route_by_kernel()
873 Route *route, *existing; in link_unmark_wireguard_routes() local
882 SET_FOREACH(route, w->routes) in link_unmark_wireguard_routes()
883 if (route_get(NULL, link, route, &existing) >= 0) in link_unmark_wireguard_routes()
888 Route *route; in link_drop_foreign_routes() local
895 SET_FOREACH(route, link->routes) { in link_drop_foreign_routes()
897 if (route_by_kernel(route)) in link_drop_foreign_routes()
901 if (route->source != NETWORK_CONFIG_SOURCE_FOREIGN) in link_drop_foreign_routes()
905 if (!route_exists(route)) in link_drop_foreign_routes()
908 if (route->protocol == RTPROT_STATIC && in link_drop_foreign_routes()
912 if (route->protocol == RTPROT_DHCP && in link_drop_foreign_routes()
916 route_mark(route); in link_drop_foreign_routes()
919 HASHMAP_FOREACH(route, link->network->routes_by_section) { in link_drop_foreign_routes()
923 r = route_convert(link->manager, route, &converted); in link_drop_foreign_routes()
927 if (route_get(NULL, link, route, &existing) >= 0) in link_drop_foreign_routes()
940 SET_FOREACH(route, link->routes) { in link_drop_foreign_routes()
941 if (!route_is_marked(route)) in link_drop_foreign_routes()
944 k = route_remove(route); in link_drop_foreign_routes()
959 Route *route; in link_drop_managed_routes() local
964 SET_FOREACH(route, link->routes) { in link_drop_managed_routes()
966 if (route_by_kernel(route)) in link_drop_managed_routes()
970 if (route->source == NETWORK_CONFIG_SOURCE_FOREIGN) in link_drop_managed_routes()
973 if (!route_exists(route)) in link_drop_managed_routes()
976 k = route_remove(route); in link_drop_managed_routes()
991 Route *route; in link_foreignize_routes() local
995 SET_FOREACH(route, link->routes) in link_foreignize_routes()
996 route->source = NETWORK_CONFIG_SOURCE_FOREIGN; in link_foreignize_routes()
1000 SET_FOREACH(route, link->manager->routes) { in link_foreignize_routes()
1001 if (!route_is_marked(route)) in link_foreignize_routes()
1004 route->source = NETWORK_CONFIG_SOURCE_FOREIGN; in link_foreignize_routes()
1009 Route *route = userdata; in route_expire_handler() local
1013 assert(route); in route_expire_handler()
1014 assert(route->manager || (route->link && route->link->manager)); in route_expire_handler()
1016 link = route->link; /* This may be NULL. */ in route_expire_handler()
1018 r = route_remove(route); in route_expire_handler()
1028 static int route_setup_timer(Route *route, const struct rta_cacheinfo *cacheinfo) { in route_setup_timer() argument
1032 assert(route); in route_setup_timer()
1033 assert(route->manager || (route->link && route->link->manager)); in route_setup_timer()
1035 manager = route->manager ?: route->link->manager; in route_setup_timer()
1037 if (route->lifetime_usec == USEC_INFINITY) in route_setup_timer()
1044 r = event_reset_time(manager->event, &route->expire, CLOCK_BOOTTIME, in route_setup_timer()
1045 … route->lifetime_usec, 0, route_expire_handler, route, 0, "route-expiration", true); in route_setup_timer()
1052 static int append_nexthop_one(const Link *link, const Route *route, const MultipathRoute *m, struct… in append_nexthop_one() argument
1057 assert(route); in append_nexthop_one()
1076 if (route->family == m->gateway.family) { in append_nexthop_one()
1097 static int append_nexthops(const Link *link, const Route *route, sd_netlink_message *req) { in append_nexthops() argument
1105 assert(route); in append_nexthops()
1108 if (ordered_set_isempty(route->multipath_routes)) in append_nexthops()
1121 ORDERED_SET_FOREACH(m, route->multipath_routes) { in append_nexthops()
1122 r = append_nexthop_one(link, route, m, &rta, offset); in append_nexthops()
1154 static int route_configure(const Route *route, Link *link, Request *req) { in route_configure() argument
1158 assert(route); in route_configure()
1159 assert(IN_SET(route->family, AF_INET, AF_INET6)); in route_configure()
1166 log_route_debug(route, "Configuring", link, link->manager); in route_configure()
1168 …r = sd_rtnl_message_new_route(link->manager->rtnl, &m, RTM_NEWROUTE, route->family, route->protoco… in route_configure()
1172 r = sd_rtnl_message_route_set_type(m, route->type); in route_configure()
1176 r = route_set_netlink_message(route, m, link); in route_configure()
1180 if (route->lifetime_usec != USEC_INFINITY) { in route_configure()
1182 …MIN(DIV_ROUND_UP(usec_sub_unsigned(route->lifetime_usec, now(CLOCK_BOOTTIME)), USEC_PER_SEC), UINT… in route_configure()
1187 if (route->ttl_propagate >= 0) { in route_configure()
1188 r = sd_netlink_message_append_u8(m, RTA_TTL_PROPAGATE, route->ttl_propagate); in route_configure()
1197 if (route->mtu > 0) { in route_configure()
1198 r = sd_netlink_message_append_u32(m, RTAX_MTU, route->mtu); in route_configure()
1203 if (route->initcwnd > 0) { in route_configure()
1204 r = sd_netlink_message_append_u32(m, RTAX_INITCWND, route->initcwnd); in route_configure()
1209 if (route->initrwnd > 0) { in route_configure()
1210 r = sd_netlink_message_append_u32(m, RTAX_INITRWND, route->initrwnd); in route_configure()
1215 if (route->quickack >= 0) { in route_configure()
1216 r = sd_netlink_message_append_u32(m, RTAX_QUICKACK, route->quickack); in route_configure()
1221 if (route->fast_open_no_cookie >= 0) { in route_configure()
1222 … r = sd_netlink_message_append_u32(m, RTAX_FASTOPEN_NO_COOKIE, route->fast_open_no_cookie); in route_configure()
1227 if (route->advmss > 0) { in route_configure()
1228 r = sd_netlink_message_append_u32(m, RTAX_ADVMSS, route->advmss); in route_configure()
1237 if (!ordered_set_isempty(route->multipath_routes)) { in route_configure()
1238 assert(route->nexthop_id == 0); in route_configure()
1239 assert(!in_addr_is_set(route->gw_family, &route->gw)); in route_configure()
1241 r = append_nexthops(link, route, m); in route_configure()
1249 static int route_is_ready_to_configure(const Route *route, Link *link) { in route_is_ready_to_configure() argument
1252 assert(route); in route_is_ready_to_configure()
1261 if (route->nexthop_id > 0) { in route_is_ready_to_configure()
1265 if (manager_get_nexthop_by_id(link->manager, route->nexthop_id, &nh) < 0) in route_is_ready_to_configure()
1282 if (in_addr_is_set(route->family, &route->prefsrc) > 0) { in route_is_ready_to_configure()
1283 … r = manager_has_address(link->manager, route->family, &route->prefsrc, route->family == AF_INET6); in route_is_ready_to_configure()
1288 … if (!gateway_is_ready(link, FLAGS_SET(route->flags, RTNH_F_ONLINK), route->gw_family, &route->gw)) in route_is_ready_to_configure()
1292 ORDERED_SET_FOREACH(m, route->multipath_routes) { in route_is_ready_to_configure()
1306 … if (!gateway_is_ready(l ?: link, FLAGS_SET(route->flags, RTNH_F_ONLINK), m->gateway.family, &a)) in route_is_ready_to_configure()
1313 static int route_process_request(Request *req, Link *link, Route *route) { in route_process_request() argument
1319 assert(route); in route_process_request()
1321 r = route_is_ready_to_configure(route, link); in route_process_request()
1327 if (route_needs_convert(route)) { in route_process_request()
1328 r = route_convert(link->manager, route, &converted); in route_process_request()
1357 r = route_configure(route, link, req); in route_process_request()
1369 route_enter_configuring(route); in route_process_request()
1376 Route *route, in link_request_route() argument
1387 assert(route); in link_request_route()
1388 assert(route->source != NETWORK_CONFIG_SOURCE_FOREIGN); in link_request_route()
1389 assert(!route_needs_convert(route)); in link_request_route()
1391 if (route_get(link->manager, link, route, &existing) < 0) { in link_request_route()
1395 tmp = route; in link_request_route()
1397 r = route_dup(route, &tmp); in link_request_route()
1408 existing->source = route->source; in link_request_route()
1409 existing->provider = route->provider; in link_request_route()
1410 existing->lifetime_usec = route->lifetime_usec; in link_request_route()
1412 route_free(route); in link_request_route()
1439 …ic_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, Route *route) { in static_route_handler() argument
1457 static int link_request_static_route(Link *link, Route *route) { in link_request_static_route() argument
1460 assert(route); in link_request_static_route()
1462 if (!route_needs_convert(route)) in link_request_static_route()
1463 return link_request_route(link, route, false, &link->static_route_messages, in link_request_static_route()
1466 log_route_debug(route, "Requesting", link, link->manager); in link_request_static_route()
1468 route, NULL, route_hash_func, route_compare_func, in link_request_static_route()
1476 Route *route; in link_request_wireguard_routes() local
1491 SET_FOREACH(route, w->routes) { in link_request_wireguard_routes()
1492 if (only_ipv4 && route->family != AF_INET) in link_request_wireguard_routes()
1495 r = link_request_static_route(link, route); in link_request_wireguard_routes()
1504 Route *route; in link_request_static_routes() local
1512 HASHMAP_FOREACH(route, link->network->routes_by_section) { in link_request_static_routes()
1513 if (route->gateway_from_dhcp_or_ra) in link_request_static_routes()
1516 if (only_ipv4 && route->family != AF_INET) in link_request_static_routes()
1519 r = link_request_static_route(link, route); in link_request_static_routes()
1539 void route_cancel_request(Route *route, Link *link) { in route_cancel_request() argument
1542 assert(route); in route_cancel_request()
1544 link = route->link ?: link; in route_cancel_request()
1548 if (!route_is_requesting(route)) in route_cancel_request()
1554 .userdata = route, in route_cancel_request()
1560 route_cancel_requesting(route); in route_cancel_request()
1571 Route *route = NULL; in process_route_one() local
1580 (void) route_get(manager, link, tmp, &route); in process_route_one()
1584 if (route) { in process_route_one()
1585 route->flags = tmp->flags; in process_route_one()
1586 route_enter_configured(route); in process_route_one()
1587 log_route_debug(route, "Received remembered", link, manager); in process_route_one()
1589 r = route_setup_timer(route, cacheinfo); in process_route_one()
1593 … log_route_debug(route, "Configured expiration timer for", link, manager); in process_route_one()
1614 if (route) { in process_route_one()
1615 route_enter_removed(route); in process_route_one()
1616 if (route->state == 0) { in process_route_one()
1617 log_route_debug(route, "Forgetting", link, manager); in process_route_one()
1618 route_free(route); in process_route_one()
1620 log_route_debug(route, "Removed", link, manager); in process_route_one()
2753 static int route_section_verify(Route *route, Network *network) { in route_section_verify() argument
2754 if (section_is_invalid(route->section)) in route_section_verify()
2758 assert(route->lifetime_usec == USEC_INFINITY); in route_section_verify()
2760 if (route->gateway_from_dhcp_or_ra) { in route_section_verify()
2761 if (route->gw_family == AF_UNSPEC) { in route_section_verify()
2763 switch (route->family) { in route_section_verify()
2767 route->section->filename, route->section->line); in route_section_verify()
2768 route->family = AF_INET; in route_section_verify()
2774 … route->section->filename, route->section->line, route->family == AF_INET ? "_dhcp4" : "_ipv6ra"); in route_section_verify()
2779 … route->section->filename, route->section->line); in route_section_verify()
2781 route->gw_family = route->family; in route_section_verify()
2784 if (route->gw_family == AF_INET && !FLAGS_SET(network->dhcp, ADDRESS_FAMILY_IPV4)) in route_section_verify()
2788 route->section->filename, route->section->line); in route_section_verify()
2790 if (route->gw_family == AF_INET6 && !network->ipv6_accept_ra) in route_section_verify()
2794 route->section->filename, route->section->line); in route_section_verify()
2798 if (route->family == AF_UNSPEC) in route_section_verify()
2799 route->family = route->gw_family; in route_section_verify()
2801 if (route->family == AF_UNSPEC) { in route_section_verify()
2802 assert(route->section); in route_section_verify()
2808 route->section->filename, route->section->line); in route_section_verify()
2811 if (route->family == AF_INET6 && route->gw_family == AF_INET) in route_section_verify()
2815 route->section->filename, route->section->line); in route_section_verify()
2817 if (!route->table_set && network->vrf) { in route_section_verify()
2818 route->table = VRF(network->vrf)->table; in route_section_verify()
2819 route->table_set = true; in route_section_verify()
2822 … if (!route->table_set && IN_SET(route->type, RTN_LOCAL, RTN_BROADCAST, RTN_ANYCAST, RTN_NAT)) in route_section_verify()
2823 route->table = RT_TABLE_LOCAL; in route_section_verify()
2825 if (!route->scope_set && route->family != AF_INET6) { in route_section_verify()
2826 if (IN_SET(route->type, RTN_LOCAL, RTN_NAT)) in route_section_verify()
2827 route->scope = RT_SCOPE_HOST; in route_section_verify()
2828 else if (IN_SET(route->type, RTN_BROADCAST, RTN_ANYCAST, RTN_MULTICAST)) in route_section_verify()
2829 route->scope = RT_SCOPE_LINK; in route_section_verify()
2830 else if (IN_SET(route->type, RTN_UNICAST, RTN_UNSPEC) && in route_section_verify()
2831 !route->gateway_from_dhcp_or_ra && in route_section_verify()
2832 !in_addr_is_set(route->gw_family, &route->gw) && in route_section_verify()
2833 ordered_set_isempty(route->multipath_routes) && in route_section_verify()
2834 route->nexthop_id == 0) in route_section_verify()
2835 route->scope = RT_SCOPE_LINK; in route_section_verify()
2838 if (route->scope != RT_SCOPE_UNIVERSE && route->family == AF_INET6) { in route_section_verify()
2839 …log_warning("%s: Scope= is specified for IPv6 route. It will be ignored.", route->section->filenam… in route_section_verify()
2840 route->scope = RT_SCOPE_UNIVERSE; in route_section_verify()
2843 if (route->family == AF_INET6 && route->priority == 0) in route_section_verify()
2844 route->priority = IP6_RT_PRIO_USER; in route_section_verify()
2846 if (route->gateway_onlink < 0 && in_addr_is_set(route->gw_family, &route->gw) && in route_section_verify()
2853 route->gateway_onlink = true; in route_section_verify()
2856 if (route->gateway_onlink >= 0) in route_section_verify()
2857 SET_FLAG(route->flags, RTNH_F_ONLINK, route->gateway_onlink); in route_section_verify()
2859 if (route->family == AF_INET6) { in route_section_verify()
2862 ORDERED_SET_FOREACH(m, route->multipath_routes) in route_section_verify()
2867 … route->section->filename, route->section->line); in route_section_verify()
2870 if ((route->gateway_from_dhcp_or_ra || in route_section_verify()
2871 in_addr_is_set(route->gw_family, &route->gw)) && in route_section_verify()
2872 !ordered_set_isempty(route->multipath_routes)) in route_section_verify()
2876 route->section->filename, route->section->line); in route_section_verify()
2878 if (route->nexthop_id > 0 && in route_section_verify()
2879 (route->gateway_from_dhcp_or_ra || in route_section_verify()
2880 in_addr_is_set(route->gw_family, &route->gw) || in route_section_verify()
2881 !ordered_set_isempty(route->multipath_routes))) in route_section_verify()
2885 route->section->filename, route->section->line); in route_section_verify()
2891 Route *route; in network_drop_invalid_routes() local
2895 HASHMAP_FOREACH(route, network->routes_by_section) in network_drop_invalid_routes()
2896 if (route_section_verify(route, network) < 0) in network_drop_invalid_routes()
2897 route_free(route); in network_drop_invalid_routes()