From: Valentin Hăloiu Date: Sun, 11 May 2025 00:33:28 +0000 (+0100) Subject: Add netdev files associated with link to networkd JSON output (#37402) X-Git-Tag: v258-rc1~650 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1dbeb98feaefe873e7e58ee9db53432fa55523aa;p=thirdparty%2Fsystemd.git Add netdev files associated with link to networkd JSON output (#37402) `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. --- diff --git a/src/network/networkd-json.c b/src/network/networkd-json.c index 2572b8961fb..59af619d137 100644 --- a/src/network/networkd-json.c +++ b/src/network/networkd-json.c @@ -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;