]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkctl: add new call that unifies link data acquisition between "status" and...
authorLennart Poettering <lennart@poettering.net>
Fri, 19 Feb 2016 17:26:18 +0000 (18:26 +0100)
committerLennart Poettering <lennart@poettering.net>
Sun, 21 Feb 2016 19:40:57 +0000 (20:40 +0100)
src/network/networkctl.c

index 0c5a3031740cb8ea3cb5c59e2b1a3f6e909f7320..9838e7a5a675a33de41e594af618a02f951a0920 100644 (file)
@@ -197,13 +197,13 @@ static void setup_state_to_color(const char *state, const char **on, const char
                 *on = *off = "";
 }
 
-static int list_links(int argc, char *argv[], void *userdata) {
+static int acquire_link_info(LinkInfo **ret) {
         _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL, *reply = NULL;
         _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
-        _cleanup_free_ LinkInfo *links = NULL;
-        int r, c, i;
 
-        pager_open_if_enabled();
+        int r;
+
+        assert(ret);
 
         r = sd_netlink_open(&rtnl);
         if (r < 0)
@@ -221,12 +221,30 @@ static int list_links(int argc, char *argv[], void *userdata) {
         if (r < 0)
                 return log_error_errno(r, "Failed to enumerate links: %m");
 
-        if (arg_legend)
-                printf("%3s %-16s %-18s %-11s %-10s\n", "IDX", "LINK", "TYPE", "OPERATIONAL", "SETUP");
+        r = decode_and_sort_links(reply, ret);
+        if (r < 0)
+                return rtnl_log_parse_error(r);
+
+        return r;
+}
 
-        c = decode_and_sort_links(reply, &links);
+static int list_links(int argc, char *argv[], void *userdata) {
+        _cleanup_free_ LinkInfo *links = NULL;
+        int c, i;
+
+        c = acquire_link_info(&links);
         if (c < 0)
-                return rtnl_log_parse_error(c);
+                return c;
+
+        pager_open_if_enabled();
+
+        if (arg_legend)
+                printf("%3s %-16s %-18s %-11s %-10s\n",
+                       "IDX",
+                       "LINK",
+                       "TYPE",
+                       "OPERATIONAL",
+                       "SETUP");
 
         for (i = 0; i < c; i++) {
                 _cleanup_free_ char *setup_state = NULL, *operational_state = NULL;
@@ -772,32 +790,14 @@ static char *lldp_capabilities_to_string(uint16_t x) {
 }
 
 static int link_lldp_status(int argc, char *argv[], void *userdata) {
-        _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL, *reply = NULL;
-        _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
         _cleanup_free_ LinkInfo *links = NULL;
         int i, r, c, j;
 
-        pager_open_if_enabled();
-
-        r = sd_netlink_open(&rtnl);
-        if (r < 0)
-                return log_error_errno(r, "Failed to connect to netlink: %m");
-
-        r = sd_rtnl_message_new_link(rtnl, &req, RTM_GETLINK, 0);
-        if (r < 0)
-                return rtnl_log_create_error(r);
-
-        r = sd_netlink_message_request_dump(req, true);
-        if (r < 0)
-                return rtnl_log_create_error(r);
-
-        r = sd_netlink_call(rtnl, req, 0, &reply);
-        if (r < 0)
-                return log_error_errno(r, "Failed to enumerate links: %m");
-
-        c = decode_and_sort_links(reply, &links);
+        c = acquire_link_info(&links);
         if (c < 0)
-                return rtnl_log_parse_error(c);
+                return c;
+
+        pager_open_if_enabled();
 
         if (arg_legend)
                 printf("%-16s %-17s %-16s %-11s %-17s %-16s\n",