return r;
/* Reconfigure static routes as kernel may remove some routes when lease expires. */
- r = link_request_set_routes(link);
+ r = link_set_routes(link);
if (r < 0)
return r;
link_set_state(link, LINK_STATE_CONFIGURING);
link->dhcp4_configured = false;
- /* address_handler calls link_request_set_routes() and link_request_set_nexthop(). Before they
- * are called, the related flags must be cleared. Otherwise, the link becomes configured state
- * before routes are configured. */
+ /* address_handler calls link_set_routes() and link_set_nexthop(). Before they are called, the
+ * related flags must be cleared. Otherwise, the link becomes configured state before routes
+ * are configured. */
link->static_routes_configured = false;
link->static_nexthops_configured = false;
return 1;
}
- r = link_request_set_routes(link);
+ r = link_set_routes(link);
if (r < 0) {
link_enter_failed(link);
return 1;
link->dhcp6_pd_address_configured = true;
} else {
log_link_debug(link, "Setting DHCPv6 PD addresses");
- /* address_handler calls link_request_set_routes() and link_request_set_nexthop().
- * Before they are called, the related flags must be cleared. Otherwise, the link
- * becomes configured state before routes are configured. */
+ /* address_handler calls link_set_routes() and link_set_nexthop(). Before they are
+ * called, the related flags must be cleared. Otherwise, the link becomes configured
+ * state before routes are configured. */
link->static_routes_configured = false;
link->static_nexthops_configured = false;
}
return 1;
}
- r = link_request_set_routes(link);
+ r = link_set_routes(link);
if (r < 0) {
link_enter_failed(link);
return 1;
link->dhcp6_address_configured = true;
else {
log_link_debug(link, "Setting DHCPv6 addresses");
- /* address_handler calls link_request_set_routes() and link_request_set_nexthop().
- * Before they are called, the related flags must be cleared. Otherwise, the link
- * becomes configured state before routes are configured. */
+ /* address_handler calls link_set_routes() and link_set_nexthop(). Before they are
+ * called, the related flags must be cleared. Otherwise, the link becomes configured
+ * state before routes are configured. */
link->static_routes_configured = false;
link->static_nexthops_configured = false;
}
link_dirty(link);
}
-static int route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
- int r;
-
- assert(link);
- assert(link->route_messages > 0);
- assert(IN_SET(link->state, LINK_STATE_CONFIGURING,
- LINK_STATE_FAILED, LINK_STATE_LINGER));
-
- link->route_messages--;
-
- if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
- return 1;
-
- r = sd_netlink_message_get_errno(m);
- if (r < 0 && r != -EEXIST) {
- log_link_message_warning_errno(link, m, r, "Could not set route");
- link_enter_failed(link);
- return 1;
- }
-
- if (link->route_messages == 0) {
- log_link_debug(link, "Routes set");
- link->static_routes_configured = true;
- link_set_nexthop(link);
- }
-
- return 1;
-}
-
-int link_request_set_routes(Link *link) {
- enum {
- PHASE_NON_GATEWAY, /* First phase: Routes without a gateway */
- PHASE_GATEWAY, /* Second phase: Routes with a gateway */
- _PHASE_MAX
- } phase;
- Route *rt;
- int r;
-
- assert(link);
- assert(link->network);
- assert(link->state != _LINK_STATE_INVALID);
-
- link->static_routes_configured = false;
-
- if (!link->addresses_ready)
- return 0;
-
- if (!link_has_carrier(link) && !link->network->configure_without_carrier)
- /* During configuring addresses, the link lost its carrier. As networkd is dropping
- * the addresses now, let's not configure the routes either. */
- return 0;
-
- r = link_set_routing_policy_rules(link);
- if (r < 0)
- return r;
-
- /* First add the routes that enable us to talk to gateways, then add in the others that need a gateway. */
- for (phase = 0; phase < _PHASE_MAX; phase++)
- LIST_FOREACH(routes, rt, link->network->static_routes) {
- if (rt->gateway_from_dhcp)
- continue;
-
- if ((in_addr_is_null(rt->family, &rt->gw) && ordered_set_isempty(rt->multipath_routes)) != (phase == PHASE_NON_GATEWAY))
- continue;
-
- r = route_configure(rt, link, route_handler, NULL);
- if (r < 0)
- return log_link_warning_errno(link, r, "Could not set routes: %m");
- if (r > 0)
- link->route_messages++;
- }
-
- if (link->route_messages == 0) {
- link->static_routes_configured = true;
- link_set_nexthop(link);
- } else {
- log_link_debug(link, "Setting routes");
- link_set_state(link, LINK_STATE_CONFIGURING);
- }
-
- return 0;
-}
-
void link_check_ready(Link *link) {
Address *a;
link->addresses_ready = true;
- return link_request_set_routes(link);
+ return link_set_routes(link);
}
static int address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
if (link->address_messages == 0) {
link->addresses_configured = true;
link->addresses_ready = true;
- r = link_request_set_routes(link);
+ r = link_set_routes(link);
if (r < 0)
return r;
} else {
uint32_t link_get_vrf_table(Link *link);
uint32_t link_get_dhcp_route_table(Link *link);
uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
-int link_request_set_routes(Link *link);
int link_reconfigure(Link *link, bool force);
return 1;
}
- r = link_request_set_routes(link);
+ r = link_set_routes(link);
if (r < 0) {
link_enter_failed(link);
return 1;
else {
log_link_debug(link, "Setting SLAAC addresses.");
- /* address_handler calls link_request_set_routes() and link_request_set_nexthop().
- * Before they are called, the related flags must be cleared. Otherwise, the link
- * becomes configured state before routes are configured. */
+ /* address_handler calls link_set_routes() and link_set_nexthop(). Before they are
+ * called, the related flags must be cleared. Otherwise, the link becomes configured
+ * state before routes are configured. */
link->static_routes_configured = false;
link->static_nexthops_configured = false;
}
#include "networkd-ipv4ll.h"
#include "networkd-manager.h"
#include "networkd-ndisc.h"
+#include "networkd-nexthop.h"
#include "networkd-route.h"
+#include "networkd-routing-policy-rule.h"
#include "parse-util.h"
#include "set.h"
#include "socket-netlink.h"
return 1;
}
+static int route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
+ int r;
+
+ assert(link);
+ assert(link->route_messages > 0);
+ assert(IN_SET(link->state, LINK_STATE_CONFIGURING,
+ LINK_STATE_FAILED, LINK_STATE_LINGER));
+
+ link->route_messages--;
+
+ if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
+ return 1;
+
+ r = sd_netlink_message_get_errno(m);
+ if (r < 0 && r != -EEXIST) {
+ log_link_message_warning_errno(link, m, r, "Could not set route");
+ link_enter_failed(link);
+ return 1;
+ }
+
+ if (link->route_messages == 0) {
+ log_link_debug(link, "Routes set");
+ link->static_routes_configured = true;
+ link_set_nexthop(link);
+ }
+
+ return 1;
+}
+
+int link_set_routes(Link *link) {
+ enum {
+ PHASE_NON_GATEWAY, /* First phase: Routes without a gateway */
+ PHASE_GATEWAY, /* Second phase: Routes with a gateway */
+ _PHASE_MAX
+ } phase;
+ Route *rt;
+ int r;
+
+ assert(link);
+ assert(link->network);
+ assert(link->state != _LINK_STATE_INVALID);
+
+ link->static_routes_configured = false;
+
+ if (!link->addresses_ready)
+ return 0;
+
+ if (!link_has_carrier(link) && !link->network->configure_without_carrier)
+ /* During configuring addresses, the link lost its carrier. As networkd is dropping
+ * the addresses now, let's not configure the routes either. */
+ return 0;
+
+ r = link_set_routing_policy_rules(link);
+ if (r < 0)
+ return r;
+
+ /* First add the routes that enable us to talk to gateways, then add in the others that need a gateway. */
+ for (phase = 0; phase < _PHASE_MAX; phase++)
+ LIST_FOREACH(routes, rt, link->network->static_routes) {
+ if (rt->gateway_from_dhcp)
+ continue;
+
+ if ((in_addr_is_null(rt->family, &rt->gw) && ordered_set_isempty(rt->multipath_routes)) != (phase == PHASE_NON_GATEWAY))
+ continue;
+
+ r = route_configure(rt, link, route_handler, NULL);
+ if (r < 0)
+ return log_link_warning_errno(link, r, "Could not set routes: %m");
+ if (r > 0)
+ link->route_messages++;
+ }
+
+ if (link->route_messages == 0) {
+ link->static_routes_configured = true;
+ link_set_nexthop(link);
+ } else {
+ log_link_debug(link, "Setting routes");
+ link_set_state(link, LINK_STATE_CONFIGURING);
+ }
+
+ return 0;
+}
+
int network_add_ipv4ll_route(Network *network) {
_cleanup_(route_free_or_set_invalidp) Route *n = NULL;
int r;
int route_configure(Route *route, Link *link, link_netlink_message_handler_t callback, Route **ret);
int route_remove(Route *route, Link *link, link_netlink_message_handler_t callback);
+int link_set_routes(Link *link);
+
int route_get(Link *link, Route *in, Route **ret);
int route_add(Link *link, Route *in, Route **ret);
int route_add_foreign(Link *link, Route *in, Route **ret);