network: Show network and link file dropins in networkctl status

Fixes #24428
This commit is contained in:
Daan De Meyer
2023-01-12 13:44:52 +09:00
committed by Yu Watanabe
parent 9c5b8d46e5
commit a2640646f1
11 changed files with 116 additions and 7 deletions
+43 -3
View File
@@ -1536,13 +1536,29 @@ static int table_add_string_line(Table *table, const char *key, const char *valu
return 0;
}
static int format_dropins(char **dropins) {
STRV_FOREACH(d, dropins) {
_cleanup_free_ char *s = NULL;
int glyph = *(d + 1) == NULL ? SPECIAL_GLYPH_TREE_RIGHT : SPECIAL_GLYPH_TREE_BRANCH;
s = strjoin(special_glyph(glyph), *d);
if (!s)
return log_oom();
free_and_replace(*d, s);
}
return 0;
}
static int link_status_one(
sd_bus *bus,
sd_netlink *rtnl,
sd_hwdb *hwdb,
const LinkInfo *info) {
_cleanup_strv_free_ char **dns = NULL, **ntp = NULL, **sip = NULL, **search_domains = NULL, **route_domains = NULL;
_cleanup_strv_free_ char **dns = NULL, **ntp = NULL, **sip = NULL, **search_domains = NULL,
**route_domains = NULL, **link_dropins = NULL, **network_dropins = NULL;
_cleanup_free_ char *t = NULL, *network = NULL, *iaid = NULL, *duid = NULL,
*setup_state = NULL, *operational_state = NULL, *online_state = NULL, *activation_policy = NULL;
const char *driver = NULL, *path = NULL, *vendor = NULL, *model = NULL, *link = NULL,
@@ -1571,12 +1587,22 @@ static int link_status_one(
(void) sd_network_link_get_ntp(info->ifindex, &ntp);
(void) sd_network_link_get_sip(info->ifindex, &sip);
(void) sd_network_link_get_network_file(info->ifindex, &network);
(void) sd_network_link_get_network_file_dropins(info->ifindex, &network_dropins);
(void) sd_network_link_get_carrier_bound_to(info->ifindex, &carrier_bound_to);
(void) sd_network_link_get_carrier_bound_by(info->ifindex, &carrier_bound_by);
(void) sd_network_link_get_activation_policy(info->ifindex, &activation_policy);
if (info->sd_device) {
const char *joined;
(void) sd_device_get_property_value(info->sd_device, "ID_NET_LINK_FILE", &link);
if (sd_device_get_property_value(info->sd_device, "ID_NET_LINK_FILE_DROPINS", &joined) >= 0) {
r = strv_split_full(&link_dropins, joined, ":", EXTRACT_CUNESCAPE);
if (r < 0)
return r;
}
(void) sd_device_get_property_value(info->sd_device, "ID_NET_DRIVER", &driver);
(void) sd_device_get_property_value(info->sd_device, "ID_PATH", &path);
@@ -1596,6 +1622,20 @@ static int link_status_one(
(void) dhcp_lease_load(&lease, lease_file);
r = format_dropins(network_dropins);
if (r < 0)
return r;
if (strv_prepend(&network_dropins, network) < 0)
return log_oom();
r = format_dropins(link_dropins);
if (r < 0)
return r;
if (strv_prepend(&link_dropins, link) < 0)
return log_oom();
table = table_new("dot", "key", "value");
if (!table)
return log_oom();
@@ -1631,10 +1671,10 @@ static int link_status_one(
TABLE_EMPTY,
TABLE_STRING, "Link File:",
TABLE_SET_ALIGN_PERCENT, 100,
TABLE_STRING, strna(link),
TABLE_STRV, link_dropins ?: STRV_MAKE("n/a"),
TABLE_EMPTY,
TABLE_STRING, "Network File:",
TABLE_STRING, strna(network),
TABLE_STRV, network_dropins ?: STRV_MAKE("n/a"),
TABLE_EMPTY,
TABLE_STRING, "State:");
if (r < 0)
+12 -1
View File
@@ -464,6 +464,7 @@ static int network_build_json(Network *network, JsonVariant **ret) {
return json_build(ret, JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_STRING("NetworkFile", network->filename),
JSON_BUILD_PAIR_STRV("NetworkFileDropins", network->dropins),
JSON_BUILD_PAIR_BOOLEAN("RequiredForOnline", network->required_for_online),
JSON_BUILD_PAIR("RequiredOperationalStateForOnline",
JSON_BUILD_ARRAY(JSON_BUILD_STRING(link_operstate_to_string(network->required_operstate_for_online.min)),
@@ -475,7 +476,9 @@ static int network_build_json(Network *network, JsonVariant **ret) {
}
static int device_build_json(sd_device *device, JsonVariant **ret) {
const char *link = NULL, *path = NULL, *vendor = NULL, *model = NULL;
_cleanup_strv_free_ char **link_dropins = NULL;
const char *link = NULL, *path = NULL, *vendor = NULL, *model = NULL, *joined;
int r;
assert(ret);
@@ -485,6 +488,13 @@ static int device_build_json(sd_device *device, JsonVariant **ret) {
}
(void) sd_device_get_property_value(device, "ID_NET_LINK_FILE", &link);
if (sd_device_get_property_value(device, "ID_NET_LINK_FILE_DROPINS", &joined) >= 0) {
r = strv_split_full(&link_dropins, joined, ":", EXTRACT_CUNESCAPE);
if (r < 0)
return r;
}
(void) sd_device_get_property_value(device, "ID_PATH", &path);
if (sd_device_get_property_value(device, "ID_VENDOR_FROM_DATABASE", &vendor) < 0)
@@ -495,6 +505,7 @@ static int device_build_json(sd_device *device, JsonVariant **ret) {
return json_build(ret, JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_STRING_NON_EMPTY("LinkFile", link),
JSON_BUILD_PAIR_STRV_NON_EMPTY("LinkFileDropins", link_dropins),
JSON_BUILD_PAIR_STRING_NON_EMPTY("Path", path),
JSON_BUILD_PAIR_STRING_NON_EMPTY("Vendor", vendor),
JSON_BUILD_PAIR_STRING_NON_EMPTY("Model", model)));
+2 -1
View File
@@ -552,7 +552,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
CONFIG_PARSE_WARN,
network,
&network->stats_by_path,
NULL);
&network->dropins);
if (r < 0)
return r; /* config_parse_many() logs internally. */
@@ -670,6 +670,7 @@ static Network *network_free(Network *network) {
free(network->name);
free(network->filename);
free(network->description);
strv_free(network->dropins);
hashmap_free(network->stats_by_path);
/* conditions */
+1
View File
@@ -65,6 +65,7 @@ struct Network {
char *name;
char *filename;
char **dropins;
Hashmap *stats_by_path;
char *description;
+14 -1
View File
@@ -5,6 +5,7 @@
#include "alloc-util.h"
#include "dns-domain.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
@@ -515,7 +516,7 @@ int link_save(Link *link) {
if (link->network) {
const char *online_state;
bool space;
bool space = false;
online_state = link_online_state_to_string(link->online_state);
if (online_state)
@@ -538,6 +539,18 @@ int link_save(Link *link) {
fprintf(f, "NETWORK_FILE=%s\n", link->network->filename);
fputs("NETWORK_FILE_DROPINS=\"", f);
STRV_FOREACH(d, link->network->dropins) {
_cleanup_free_ char *escaped = NULL;
escaped = xescape(*d, ":");
if (!escaped)
return -ENOMEM;
fputs_with_space(f, escaped, ":", &space);
}
fputs("\"\n", f);
/************************************************************/
fputs("DNS=", f);