summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2020-09-29 10:18:55 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2020-10-06 19:39:51 +0200
commitc133770a6b73b669219742768e93d5393dbc4ec7 (patch)
tree62d5dce1a76e247d748b936c1d26d7eab2f9522e /src
parentnetwork: introduce helper function to enumerate information using netlink (diff)
downloadsystemd-c133770a6b73b669219742768e93d5393dbc4ec7.tar.xz
systemd-c133770a6b73b669219742768e93d5393dbc4ec7.zip
network: move link_request_set_nexthop() to networkd-nexthop.c
Diffstat (limited to 'src')
-rw-r--r--src/network/networkd-link.c58
-rw-r--r--src/network/networkd-nexthop.c63
-rw-r--r--src/network/networkd-nexthop.h3
3 files changed, 61 insertions, 63 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 685cbd34cf..dca9b1550c 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -925,60 +925,6 @@ static void link_enter_configured(Link *link) {
link_dirty(link);
}
-static int nexthop_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
- int r;
-
- assert(link);
- assert(link->nexthop_messages > 0);
- assert(IN_SET(link->state, LINK_STATE_CONFIGURING,
- LINK_STATE_FAILED, LINK_STATE_LINGER));
-
- link->nexthop_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 nexthop");
- link_enter_failed(link);
- return 1;
- }
-
- if (link->nexthop_messages == 0) {
- log_link_debug(link, "Nexthop set");
- link->static_nexthops_configured = true;
- link_check_ready(link);
- }
-
- return 1;
-}
-
-static int link_request_set_nexthop(Link *link) {
- NextHop *nh;
- int r;
-
- link->static_nexthops_configured = false;
-
- LIST_FOREACH(nexthops, nh, link->network->static_nexthops) {
- r = nexthop_configure(nh, link, nexthop_handler);
- if (r < 0)
- return log_link_warning_errno(link, r, "Could not set nexthop: %m");
- if (r > 0)
- link->nexthop_messages++;
- }
-
- if (link->nexthop_messages == 0) {
- link->static_nexthops_configured = true;
- link_check_ready(link);
- } else {
- log_link_debug(link, "Setting nexthop");
- link_set_state(link, LINK_STATE_CONFIGURING);
- }
-
- return 1;
-}
-
static int route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
@@ -1002,7 +948,7 @@ static int route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
if (link->route_messages == 0) {
log_link_debug(link, "Routes set");
link->static_routes_configured = true;
- link_request_set_nexthop(link);
+ link_set_nexthop(link);
}
return 1;
@@ -1053,7 +999,7 @@ int link_request_set_routes(Link *link) {
if (link->route_messages == 0) {
link->static_routes_configured = true;
- link_request_set_nexthop(link);
+ link_set_nexthop(link);
} else {
log_link_debug(link, "Setting routes");
link_set_state(link, LINK_STATE_CONFIGURING);
diff --git a/src/network/networkd-nexthop.c b/src/network/networkd-nexthop.c
index 6d89be1a25..6b16c0f00a 100644
--- a/src/network/networkd-nexthop.c
+++ b/src/network/networkd-nexthop.c
@@ -319,10 +319,34 @@ int nexthop_remove(NextHop *nexthop, Link *link,
return 0;
}
-int nexthop_configure(
- NextHop *nexthop,
- Link *link,
- link_netlink_message_handler_t callback) {
+static int nexthop_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
+ int r;
+
+ assert(link);
+ assert(link->nexthop_messages > 0);
+
+ link->nexthop_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 nexthop");
+ link_enter_failed(link);
+ return 1;
+ }
+
+ if (link->nexthop_messages == 0) {
+ log_link_debug(link, "Nexthop set");
+ link->static_nexthops_configured = true;
+ link_check_ready(link);
+ }
+
+ return 1;
+}
+
+static int nexthop_configure(NextHop *nexthop, Link *link) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
int r;
@@ -331,7 +355,6 @@ int nexthop_configure(
assert(link->manager->rtnl);
assert(link->ifindex > 0);
assert(IN_SET(nexthop->family, AF_INET, AF_INET6));
- assert(callback);
if (DEBUG_LOGGING) {
_cleanup_free_ char *gw = NULL;
@@ -366,7 +389,7 @@ int nexthop_configure(
return log_link_error_errno(link, r, "Could not set nexthop family: %m");
}
- r = netlink_call_async(link->manager->rtnl, NULL, req, callback,
+ r = netlink_call_async(link->manager->rtnl, NULL, req, nexthop_handler,
link_netlink_destroy_callback, link);
if (r < 0)
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
@@ -380,6 +403,34 @@ int nexthop_configure(
return 1;
}
+int link_set_nexthop(Link *link) {
+ NextHop *nh;
+ int r;
+
+ assert(link);
+ assert(link->network);
+
+ link->static_nexthops_configured = false;
+
+ LIST_FOREACH(nexthops, nh, link->network->static_nexthops) {
+ r = nexthop_configure(nh, link);
+ if (r < 0)
+ return log_link_warning_errno(link, r, "Could not set nexthop: %m");
+ if (r > 0)
+ link->nexthop_messages++;
+ }
+
+ if (link->nexthop_messages == 0) {
+ link->static_nexthops_configured = true;
+ link_check_ready(link);
+ } else {
+ log_link_debug(link, "Setting nexthop");
+ link_set_state(link, LINK_STATE_CONFIGURING);
+ }
+
+ return 1;
+}
+
int nexthop_section_verify(NextHop *nh) {
if (section_is_invalid(nh->section))
return -EINVAL;
diff --git a/src/network/networkd-nexthop.h b/src/network/networkd-nexthop.h
index 28cbdad738..cd9958824c 100644
--- a/src/network/networkd-nexthop.h
+++ b/src/network/networkd-nexthop.h
@@ -34,9 +34,10 @@ extern const struct hash_ops nexthop_hash_ops;
int nexthop_new(NextHop **ret);
void nexthop_free(NextHop *nexthop);
-int nexthop_configure(NextHop *nexthop, Link *link, link_netlink_message_handler_t callback);
int nexthop_remove(NextHop *nexthop, Link *link, link_netlink_message_handler_t callback);
+int link_set_nexthop(Link *link);
+
int nexthop_get(Link *link, NextHop *in, NextHop **ret);
int nexthop_add(Link *link, NextHop *in, NextHop **ret);
int nexthop_add_foreign(Link *link, NextHop *in, NextHop **ret);