summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/network/networkd-manager.c119
-rw-r--r--src/network/networkd-nexthop.c119
-rw-r--r--src/network/networkd-nexthop.h2
3 files changed, 121 insertions, 119 deletions
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 2dc6ef0933..94b036e81e 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -966,125 +966,6 @@ static int manager_rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *messa
return 1;
}
-static int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message, Manager *m) {
- _cleanup_(nexthop_freep) NextHop *tmp = NULL;
- _cleanup_free_ char *gateway = NULL;
- NextHop *nexthop = NULL;
- Link *link = NULL;
- uint16_t type;
- int r;
-
- assert(rtnl);
- assert(message);
- assert(m);
-
- if (sd_netlink_message_is_error(message)) {
- r = sd_netlink_message_get_errno(message);
- if (r < 0)
- log_message_warning_errno(message, r, "rtnl: failed to receive rule message, ignoring");
-
- return 0;
- }
-
- r = sd_netlink_message_get_type(message, &type);
- if (r < 0) {
- log_warning_errno(r, "rtnl: could not get message type, ignoring: %m");
- return 0;
- } else if (!IN_SET(type, RTM_NEWNEXTHOP, RTM_DELNEXTHOP)) {
- log_warning("rtnl: received unexpected message type %u when processing nexthop, ignoring.", type);
- return 0;
- }
-
- r = nexthop_new(&tmp);
- if (r < 0)
- return log_oom();
-
- r = sd_rtnl_message_get_family(message, &tmp->family);
- if (r < 0) {
- log_warning_errno(r, "rtnl: could not get nexthop family, ignoring: %m");
- return 0;
- } else if (!IN_SET(tmp->family, AF_INET, AF_INET6)) {
- log_debug("rtnl: received nexthop message with invalid family %d, ignoring.", tmp->family);
- return 0;
- }
-
- switch (tmp->family) {
- case AF_INET:
- r = sd_netlink_message_read_in_addr(message, NHA_GATEWAY, &tmp->gw.in);
- if (r < 0 && r != -ENODATA) {
- log_warning_errno(r, "rtnl: could not get NHA_GATEWAY attribute, ignoring: %m");
- return 0;
- }
- break;
-
- case AF_INET6:
- r = sd_netlink_message_read_in6_addr(message, NHA_GATEWAY, &tmp->gw.in6);
- if (r < 0 && r != -ENODATA) {
- log_warning_errno(r, "rtnl: could not get NHA_GATEWAY attribute, ignoring: %m");
- return 0;
- }
- break;
-
- default:
- assert_not_reached("Received rule message with unsupported address family");
- }
-
- r = sd_netlink_message_read_u32(message, NHA_ID, &tmp->id);
- if (r < 0 && r != -ENODATA) {
- log_warning_errno(r, "rtnl: could not get NHA_ID attribute, ignoring: %m");
- return 0;
- }
-
- r = sd_netlink_message_read_u32(message, NHA_OIF, &tmp->oif);
- if (r < 0 && r != -ENODATA) {
- log_warning_errno(r, "rtnl: could not get NHA_OIF attribute, ignoring: %m");
- return 0;
- } else if (tmp->oif <= 0) {
- log_warning("rtnl: received nexthop message with invalid ifindex %d, ignoring.", tmp->oif);
- return 0;
- }
-
- r = link_get(m, tmp->oif, &link);
- if (r < 0 || !link) {
- if (!m->enumerating)
- log_warning("rtnl: received nexthop message for link (%d) we do not know about, ignoring", tmp->oif);
- return 0;
- }
-
- (void) nexthop_get(link, tmp, &nexthop);
-
- if (DEBUG_LOGGING)
- (void) in_addr_to_string(tmp->family, &tmp->gw, &gateway);
-
- switch (type) {
- case RTM_NEWNEXTHOP:
- if (nexthop)
- log_link_debug(link, "Received remembered nexthop: %s, oif: %d, id: %d", strna(gateway), tmp->oif, tmp->id);
- else {
- log_link_debug(link, "Remembering foreign nexthop: %s, oif: %d, id: %d", strna(gateway), tmp->oif, tmp->id);
- r = nexthop_add_foreign(link, tmp, &nexthop);
- if (r < 0) {
- log_link_warning_errno(link, r, "Could not remember foreign nexthop, ignoring: %m");
- return 0;
- }
- }
- break;
- case RTM_DELNEXTHOP:
- if (nexthop) {
- log_link_debug(link, "Forgetting nexthop: %s, oif: %d, id: %d", strna(gateway), tmp->oif, tmp->id);
- nexthop_free(nexthop);
- } else
- log_link_debug(link, "Kernel removed a nexthop we don't remember: %s, oif: %d, id: %d, ignoring.",
- strna(gateway), tmp->oif, tmp->id);
- break;
-
- default:
- assert_not_reached("Received invalid RTNL message type");
- }
-
- return 1;
-}
-
static int systemd_netlink_fd(void) {
int n, fd, rtnl_fd = -EINVAL;
diff --git a/src/network/networkd-nexthop.c b/src/network/networkd-nexthop.c
index 6b16c0f00a..a4189e8b5a 100644
--- a/src/network/networkd-nexthop.c
+++ b/src/network/networkd-nexthop.c
@@ -431,6 +431,125 @@ int link_set_nexthop(Link *link) {
return 1;
}
+int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message, Manager *m) {
+ _cleanup_(nexthop_freep) NextHop *tmp = NULL;
+ _cleanup_free_ char *gateway = NULL;
+ NextHop *nexthop = NULL;
+ Link *link = NULL;
+ uint16_t type;
+ int r;
+
+ assert(rtnl);
+ assert(message);
+ assert(m);
+
+ if (sd_netlink_message_is_error(message)) {
+ r = sd_netlink_message_get_errno(message);
+ if (r < 0)
+ log_message_warning_errno(message, r, "rtnl: failed to receive rule message, ignoring");
+
+ return 0;
+ }
+
+ r = sd_netlink_message_get_type(message, &type);
+ if (r < 0) {
+ log_warning_errno(r, "rtnl: could not get message type, ignoring: %m");
+ return 0;
+ } else if (!IN_SET(type, RTM_NEWNEXTHOP, RTM_DELNEXTHOP)) {
+ log_warning("rtnl: received unexpected message type %u when processing nexthop, ignoring.", type);
+ return 0;
+ }
+
+ r = nexthop_new(&tmp);
+ if (r < 0)
+ return log_oom();
+
+ r = sd_rtnl_message_get_family(message, &tmp->family);
+ if (r < 0) {
+ log_warning_errno(r, "rtnl: could not get nexthop family, ignoring: %m");
+ return 0;
+ } else if (!IN_SET(tmp->family, AF_INET, AF_INET6)) {
+ log_debug("rtnl: received nexthop message with invalid family %d, ignoring.", tmp->family);
+ return 0;
+ }
+
+ switch (tmp->family) {
+ case AF_INET:
+ r = sd_netlink_message_read_in_addr(message, NHA_GATEWAY, &tmp->gw.in);
+ if (r < 0 && r != -ENODATA) {
+ log_warning_errno(r, "rtnl: could not get NHA_GATEWAY attribute, ignoring: %m");
+ return 0;
+ }
+ break;
+
+ case AF_INET6:
+ r = sd_netlink_message_read_in6_addr(message, NHA_GATEWAY, &tmp->gw.in6);
+ if (r < 0 && r != -ENODATA) {
+ log_warning_errno(r, "rtnl: could not get NHA_GATEWAY attribute, ignoring: %m");
+ return 0;
+ }
+ break;
+
+ default:
+ assert_not_reached("Received rule message with unsupported address family");
+ }
+
+ r = sd_netlink_message_read_u32(message, NHA_ID, &tmp->id);
+ if (r < 0 && r != -ENODATA) {
+ log_warning_errno(r, "rtnl: could not get NHA_ID attribute, ignoring: %m");
+ return 0;
+ }
+
+ r = sd_netlink_message_read_u32(message, NHA_OIF, &tmp->oif);
+ if (r < 0 && r != -ENODATA) {
+ log_warning_errno(r, "rtnl: could not get NHA_OIF attribute, ignoring: %m");
+ return 0;
+ } else if (tmp->oif <= 0) {
+ log_warning("rtnl: received nexthop message with invalid ifindex %d, ignoring.", tmp->oif);
+ return 0;
+ }
+
+ r = link_get(m, tmp->oif, &link);
+ if (r < 0 || !link) {
+ if (!m->enumerating)
+ log_warning("rtnl: received nexthop message for link (%d) we do not know about, ignoring", tmp->oif);
+ return 0;
+ }
+
+ (void) nexthop_get(link, tmp, &nexthop);
+
+ if (DEBUG_LOGGING)
+ (void) in_addr_to_string(tmp->family, &tmp->gw, &gateway);
+
+ switch (type) {
+ case RTM_NEWNEXTHOP:
+ if (nexthop)
+ log_link_debug(link, "Received remembered nexthop: %s, oif: %d, id: %d", strna(gateway), tmp->oif, tmp->id);
+ else {
+ log_link_debug(link, "Remembering foreign nexthop: %s, oif: %d, id: %d", strna(gateway), tmp->oif, tmp->id);
+ r = nexthop_add_foreign(link, tmp, &nexthop);
+ if (r < 0) {
+ log_link_warning_errno(link, r, "Could not remember foreign nexthop, ignoring: %m");
+ return 0;
+ }
+ }
+ break;
+ case RTM_DELNEXTHOP:
+ if (nexthop) {
+ log_link_debug(link, "Forgetting nexthop: %s, oif: %d, id: %d", strna(gateway), tmp->oif, tmp->id);
+ nexthop_free(nexthop);
+ } else
+ log_link_debug(link, "Kernel removed a nexthop we don't remember: %s, oif: %d, id: %d, ignoring.",
+ strna(gateway), tmp->oif, tmp->id);
+ break;
+
+ default:
+ assert_not_reached("Received invalid RTNL message type");
+ }
+
+ 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 cd9958824c..64d92f62be 100644
--- a/src/network/networkd-nexthop.h
+++ b/src/network/networkd-nexthop.h
@@ -38,6 +38,8 @@ int nexthop_remove(NextHop *nexthop, Link *link, link_netlink_message_handler_t
int link_set_nexthop(Link *link);
+int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);
+
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);