]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
wait-online: move manager_process_link() to link.c
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 12 Apr 2025 15:30:58 +0000 (00:30 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 13 Apr 2025 01:03:40 +0000 (10:03 +0900)
Then, rename it to rtnl_process_link().

No functional change, just refactoring.

src/network/wait-online/link.c
src/network/wait-online/link.h
src/network/wait-online/manager.c

index 7fd46c848acb6bdc26884e3e0db0af7878dcb591..7515579edbbf47366a1f08d38d5fea4796e3b641 100644 (file)
@@ -11,7 +11,7 @@
 #include "string-util.h"
 #include "strv.h"
 
-Link* link_free(Link *l) {
+static Link* link_free(Link *l) {
 
         if (!l)
                 return NULL;
@@ -32,12 +32,14 @@ Link* link_free(Link *l) {
         return mfree(l);
 }
 
+DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_free);
+
 DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
                 link_hash_ops_by_index,
                 void, trivial_hash_func, trivial_compare_func,
                 Link, link_free);
 
-int link_new(Manager *m, Link **ret, int ifindex, const char *ifname) {
+static int link_new(Manager *m, Link **ret, int ifindex, const char *ifname) {
         _cleanup_(link_freep) Link *l = NULL;
         _cleanup_free_ char *n = NULL;
         int r;
@@ -154,7 +156,7 @@ static int link_update_altnames(Link *l, sd_netlink_message *m) {
         return 0;
 }
 
-int link_update_rtnl(Link *l, sd_netlink_message *m) {
+static int link_update_rtnl(Link *l, sd_netlink_message *m) {
         int r;
 
         assert(l);
@@ -176,6 +178,75 @@ int link_update_rtnl(Link *l, sd_netlink_message *m) {
         return 0;
 }
 
+int rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *mm, void *userdata) {
+        Manager *m = ASSERT_PTR(userdata);
+        uint16_t type;
+        Link *l;
+        const char *ifname;
+        int ifindex, r;
+
+        assert(rtnl);
+        assert(mm);
+
+        r = sd_netlink_message_get_type(mm, &type);
+        if (r < 0) {
+                log_warning_errno(r, "rtnl: Could not get message type, ignoring: %m");
+                return 0;
+        }
+
+        r = sd_rtnl_message_link_get_ifindex(mm, &ifindex);
+        if (r < 0) {
+                log_warning_errno(r, "rtnl: Could not get ifindex from link, ignoring: %m");
+                return 0;
+        } else if (ifindex <= 0) {
+                log_warning("rtnl: received link message with invalid ifindex %d, ignoring", ifindex);
+                return 0;
+        }
+
+        r = sd_netlink_message_read_string(mm, IFLA_IFNAME, &ifname);
+        if (r < 0) {
+                log_warning_errno(r, "rtnl: Received link message without ifname, ignoring: %m");
+                return 0;
+        }
+
+        l = hashmap_get(m->links_by_index, INT_TO_PTR(ifindex));
+
+        switch (type) {
+
+        case RTM_NEWLINK:
+                if (!l) {
+                        log_debug("Found link %s(%i)", ifname, ifindex);
+
+                        r = link_new(m, &l, ifindex, ifname);
+                        if (r < 0) {
+                                log_warning_errno(r, "Failed to create link object for %s(%i), ignoring: %m", ifname, ifindex);
+                                return 0;
+                        }
+                }
+
+                r = link_update_rtnl(l, mm);
+                if (r < 0)
+                        log_link_warning_errno(l, r, "Failed to process RTNL link message, ignoring: %m");
+
+                r = link_update_monitor(l);
+                if (r < 0)
+                        log_link_full_errno(l, IN_SET(r, -ENODATA, -ENOENT) ? LOG_DEBUG : LOG_WARNING, r,
+                                            "Failed to update link state, ignoring: %m");
+
+                break;
+
+        case RTM_DELLINK:
+                if (l) {
+                        log_link_debug(l, "Removing link");
+                        link_free(l);
+                }
+
+                break;
+        }
+
+        return 0;
+}
+
 int link_update_monitor(Link *l) {
         _cleanup_free_ char *required_operstate = NULL, *required_family = NULL,
                 *ipv4_address_state = NULL, *ipv6_address_state = NULL, *state = NULL;
index ec352c41132b8f7eb77c076c70b0d86e95fc58a4..33d0a85e8dc5c6998d0c3b2518b265fd56d944ed 100644 (file)
@@ -28,9 +28,5 @@ struct Link {
         DNSConfiguration *dns_configuration;
 };
 
-int link_new(Manager *m, Link **ret, int ifindex, const char *ifname);
-Link *link_free(Link *l);
-int link_update_rtnl(Link *l, sd_netlink_message *m);
+int rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *mm, void *userdata);
 int link_update_monitor(Link *l);
-
-DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_free);
index 02d11961773c5f52e6458a86441ab3bab1bae447..597598abc6b11c56434410ffb43d7e31eb6650a4 100644 (file)
@@ -234,80 +234,11 @@ bool manager_configured(Manager *m) {
         return !m->any && has_online;
 }
 
-static int manager_process_link(sd_netlink *rtnl, sd_netlink_message *mm, void *userdata) {
-        Manager *m = ASSERT_PTR(userdata);
-        uint16_t type;
-        Link *l;
-        const char *ifname;
-        int ifindex, r;
-
-        assert(rtnl);
-        assert(mm);
-
-        r = sd_netlink_message_get_type(mm, &type);
-        if (r < 0) {
-                log_warning_errno(r, "rtnl: Could not get message type, ignoring: %m");
-                return 0;
-        }
-
-        r = sd_rtnl_message_link_get_ifindex(mm, &ifindex);
-        if (r < 0) {
-                log_warning_errno(r, "rtnl: Could not get ifindex from link, ignoring: %m");
-                return 0;
-        } else if (ifindex <= 0) {
-                log_warning("rtnl: received link message with invalid ifindex %d, ignoring", ifindex);
-                return 0;
-        }
-
-        r = sd_netlink_message_read_string(mm, IFLA_IFNAME, &ifname);
-        if (r < 0) {
-                log_warning_errno(r, "rtnl: Received link message without ifname, ignoring: %m");
-                return 0;
-        }
-
-        l = hashmap_get(m->links_by_index, INT_TO_PTR(ifindex));
-
-        switch (type) {
-
-        case RTM_NEWLINK:
-                if (!l) {
-                        log_debug("Found link %s(%i)", ifname, ifindex);
-
-                        r = link_new(m, &l, ifindex, ifname);
-                        if (r < 0) {
-                                log_warning_errno(r, "Failed to create link object for %s(%i), ignoring: %m", ifname, ifindex);
-                                return 0;
-                        }
-                }
-
-                r = link_update_rtnl(l, mm);
-                if (r < 0)
-                        log_link_warning_errno(l, r, "Failed to process RTNL link message, ignoring: %m");
-
-                r = link_update_monitor(l);
-                if (r < 0)
-                        log_link_full_errno(l, IN_SET(r, -ENODATA, -ENOENT) ? LOG_DEBUG : LOG_WARNING, r,
-                                            "Failed to update link state, ignoring: %m");
-
-                break;
-
-        case RTM_DELLINK:
-                if (l) {
-                        log_link_debug(l, "Removing link");
-                        link_free(l);
-                }
-
-                break;
-        }
-
-        return 0;
-}
-
 static int on_rtnl_event(sd_netlink *rtnl, sd_netlink_message *mm, void *userdata) {
         Manager *m = userdata;
         int r;
 
-        r = manager_process_link(rtnl, mm, m);
+        r = rtnl_process_link(rtnl, mm, m);
         if (r < 0)
                 return r;
 
@@ -354,7 +285,7 @@ static int manager_rtnl_listen(Manager *m) {
                 return r;
 
         for (sd_netlink_message *i = reply; i; i = sd_netlink_message_next(i)) {
-                r = manager_process_link(m->rtnl, i, m);
+                r = rtnl_process_link(m->rtnl, i, m);
                 if (r < 0)
                         return r;
         }