1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-09 01:18:19 +03:00

network: store netdev drop-in paths and dump into state file

This commit is contained in:
Mike Yuan 2024-09-07 19:51:55 +02:00
parent 4c8dc66438
commit 2cf9b1a0ee
No known key found for this signature in database
GPG Key ID: 417471C0A40F58B3
3 changed files with 39 additions and 16 deletions

View File

@ -215,6 +215,7 @@ static NetDev *netdev_free(NetDev *netdev) {
condition_free_list(netdev->conditions);
free(netdev->filename);
strv_free(netdev->dropins);
free(netdev->description);
free(netdev->ifname);
@ -832,7 +833,9 @@ int netdev_load_one(Manager *manager, const char *filename) {
NETDEV_VTABLE(netdev)->sections,
config_item_perf_lookup, network_netdev_gperf_lookup,
CONFIG_PARSE_WARN,
netdev, NULL, NULL);
netdev,
NULL,
&netdev->dropins);
if (r < 0)
return r; /* config_parse_many() logs internally. */

View File

@ -116,6 +116,7 @@ typedef struct NetDev {
unsigned n_ref;
char *filename;
char **dropins;
LIST_HEAD(Condition, conditions);

View File

@ -561,6 +561,30 @@ static void link_save_domains(Link *link, FILE *f, OrderedSet *static_domains, U
}
}
static int serialize_config_files(FILE *f, const char *prefix, const char *main_config, char * const *dropins) {
assert(f);
assert(prefix);
assert(main_config);
fprintf(f, "%s_FILE=%s\n", prefix, main_config);
bool space = false;
fprintf(f, "%s_FILE_DROPINS=\"", prefix);
STRV_FOREACH(d, dropins) {
_cleanup_free_ char *escaped = NULL;
escaped = xescape(*d, ":");
if (!escaped)
return -ENOMEM;
fputs_with_separator(f, escaped, ":", &space);
}
fputs("\"\n", f);
return 0;
}
static int link_save(Link *link) {
const char *admin_state, *oper_state, *carrier_state, *address_state, *ipv4_address_state, *ipv6_address_state;
_cleanup_(unlink_and_freep) char *temp_path = NULL;
@ -622,19 +646,15 @@ static int link_save(Link *link) {
fprintf(f, "ACTIVATION_POLICY=%s\n",
activation_policy_to_string(link->network->activation_policy));
fprintf(f, "NETWORK_FILE=%s\n", link->network->filename);
r = serialize_config_files(f, "NETWORK", link->network->filename, link->network->dropins);
if (r < 0)
return r;
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_separator(f, escaped, ":", &space);
if (link->netdev) {
r = serialize_config_files(f, "NETDEV", link->netdev->filename, link->netdev->dropins);
if (r < 0)
return r;
}
fputs("\"\n", f);
/************************************************************/
@ -759,8 +779,9 @@ static int link_save(Link *link) {
if (!set_isempty(nta_anchors)) {
const char *n;
fputs("DNSSEC_NTA=", f);
space = false;
fputs("DNSSEC_NTA=", f);
SET_FOREACH(n, nta_anchors)
fputs_with_separator(f, n, NULL, &space);
fputc('\n', f);
@ -775,9 +796,7 @@ static int link_save(Link *link) {
if (r < 0)
return r;
fprintf(f,
"DHCP_LEASE=%s\n",
link->lease_file);
fprintf(f, "DHCP_LEASE=%s\n", link->lease_file);
} else
(void) unlink(link->lease_file);