]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: introduce link_call_getlink()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 26 May 2021 04:44:02 +0000 (13:44 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 7 Jun 2021 21:39:48 +0000 (06:39 +0900)
src/network/networkd-link.c
src/network/networkd-link.h

index 67c6b5519f7fef9de33c6461eb7016a65749d173..998c4c4c8eccb5e2720ffe8dee18047fd2b5035e 100644 (file)
@@ -2764,6 +2764,65 @@ int manager_rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *message, Man
         return 1;
 }
 
+int link_getlink_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *error_msg) {
+        uint16_t message_type;
+        int r;
+
+        assert(m);
+        assert(link);
+        assert(error_msg);
+
+        if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
+                return 0;
+
+        r = sd_netlink_message_get_errno(m);
+        if (r < 0) {
+                log_link_message_warning_errno(link, m, r, error_msg);
+                link_enter_failed(link);
+                return 0;
+        }
+
+        r = sd_netlink_message_get_type(m, &message_type);
+        if (r < 0) {
+                log_link_debug_errno(link, r, "rtnl: failed to read link message type, ignoring: %m");
+                return 0;
+        }
+        if (message_type != RTM_NEWLINK) {
+                log_link_debug(link, "rtnl: received invalid link message type, ignoring.");
+                return 0;
+        }
+
+        r = link_update(link, m);
+        if (r < 0) {
+                link_enter_failed(link);
+                return 0;
+        }
+
+        return 1;
+}
+
+int link_call_getlink(Link *link, link_netlink_message_handler_t callback) {
+        _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
+        int r;
+
+        assert(link);
+        assert(link->manager);
+        assert(link->manager->rtnl);
+        assert(callback);
+
+        r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_GETLINK, link->ifindex);
+        if (r < 0)
+                return r;
+
+        r = netlink_call_async(link->manager->rtnl, NULL, req, callback,
+                               link_netlink_destroy_callback, link);
+        if (r < 0)
+                return r;
+
+        link_ref(link);
+        return 0;
+}
+
 static const char* const link_state_table[_LINK_STATE_MAX] = {
         [LINK_STATE_PENDING] = "pending",
         [LINK_STATE_INITIALIZED] = "initialized",
index 2305bf8d42dc5c08fbcdbb63203c17c54756bc67..bd6c1b2774ee93f3f9f6900e5b15f55448c69c96 100644 (file)
@@ -221,6 +221,8 @@ int link_get(Manager *m, int ifindex, Link **ret);
 int link_get_by_name(Manager *m, const char *ifname, Link **ret);
 int link_get_master(Link *link, Link **ret);
 
+int link_getlink_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *error_msg);
+int link_call_getlink(Link *link, link_netlink_message_handler_t callback);
 int link_up(Link *link);
 int link_down(Link *link, link_netlink_message_handler_t callback);
 int link_activate(Link *link);