]> git.ipfire.org Git - network.git/commitdiff
ports: Add link stuff to JSON output
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Jun 2023 14:19:04 +0000 (14:19 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Jun 2023 14:19:04 +0000 (14:19 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/networkd/link.c
src/networkd/link.h
src/networkd/port.c

index 603aabe884f1a94e0ab446c903362ff8e1dd36f4..60abd466dd5c7edb2472fc14c1f2517a813d6961 100644 (file)
@@ -27,6 +27,7 @@
 #include <systemd/sd-netlink.h>
 
 #include "daemon.h"
+#include "json.h"
 #include "link.h"
 #include "links.h"
 #include "logging.h"
@@ -529,3 +530,16 @@ ERROR:
 
        return r;
 }
+
+// JSON
+
+int nw_link_to_json(nw_link* link, struct json_object* o) {
+       int r;
+
+       // Add ifindex
+       r = json_object_add_int64(o, "LinkIndex", link->ifindex);
+       if (r < 0)
+               return r;
+
+       return 0;
+}
index 2bab47c5c90b2be718f3e928aafc4a6f1eae3c5a..36c7d9dd6c29e4804bdf0df389f16b89e70014c9 100644 (file)
@@ -26,6 +26,7 @@
 typedef struct nw_link nw_link;
 
 #include "daemon.h"
+#include "json.h"
 
 int nw_link_create(nw_link** link, nw_daemon* daemon, int ifindex);
 
@@ -45,4 +46,7 @@ int nw_link_process(sd_netlink* rtnl, sd_netlink_message* message, void* data);
 
 int nw_link_destroy(nw_link* link);
 
+// JSON
+int nw_link_to_json(nw_link* link, struct json_object* o);
+
 #endif /* NETWORKD_LINK_H */
index fb62520703f9a33e1ed36799e466320576907dc5..84fceee885ad04ff32e942487b910e59c24e8f2c 100644 (file)
@@ -682,6 +682,13 @@ int nw_port_to_json(nw_port* port, struct json_object** object) {
                        goto ERROR;
        }
 
+       // Add link stuff
+       if (port->link) {
+               r = nw_link_to_json(port->link, o);
+               if (r < 0)
+                       goto ERROR;
+       }
+
        // Call custom stuff
        if (NW_PORT_TYPE(port)->to_json) {
                r = NW_PORT_TYPE(port)->to_json(port, o);