]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Add netdev files associated with link to networkd JSON output (#37402)
authorValentin Hăloiu <valentin.haloiu@gmail.com>
Sun, 11 May 2025 00:33:28 +0000 (01:33 +0100)
committerGitHub <noreply@github.com>
Sun, 11 May 2025 00:33:28 +0000 (09:33 +0900)
`networkctl status LINK` gained support for showing the netdev
configuration files associated with a link in
c9837c17d57d7e0fd9d3e2a4f2693f389ca76c24, but these netdev files were
never added to the JSON output too.

This pull-request fixes that by adding two new fields (`NetDevFile` and
`NetDevFileDropins`) to the `networkctl` (and `D-Bus`) JSON output.

src/network/networkd-json.c

index 2572b8961fb850a56c8f30cd2a0131fccf2f70af..59af619d1375b4b7471568292a6f9216a8cef2bd 100644 (file)
@@ -450,6 +450,18 @@ static int network_append_json(Network *network, sd_json_variant **v) {
                                                   activation_policy_to_string(network->activation_policy)));
 }
 
+static int netdev_append_json(NetDev *netdev, sd_json_variant **v) {
+        assert(v);
+
+        if (!netdev)
+                return 0;
+
+        return sd_json_variant_merge_objectbo(
+                        v,
+                        SD_JSON_BUILD_PAIR_STRING("NetDevFile", netdev->filename),
+                        SD_JSON_BUILD_PAIR_STRV("NetDevFileDropins", netdev->dropins));
+}
+
 static int device_append_json(sd_device *device, sd_json_variant **v) {
         _cleanup_strv_free_ char **link_dropins = NULL;
         const char *link = NULL, *path = NULL, *vendor = NULL, *model = NULL, *joined;
@@ -1448,6 +1460,10 @@ int link_build_json(Link *link, sd_json_variant **ret) {
         if (r < 0)
                 return r;
 
+        r = netdev_append_json(link->netdev, &v);
+        if (r < 0)
+                return r;
+
         r = device_append_json(link->dev, &v);
         if (r < 0)
                 return r;