mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-07 23:00:19 +01:00
Merge branch 'ac/wip-empty-properties'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1088
This commit is contained in:
commit
dd3f96fa9c
4 changed files with 98 additions and 74 deletions
|
|
@ -682,3 +682,22 @@ nm_keyfile_key_decode(const char *key, char **out_to_free)
|
|||
#endif
|
||||
return name;
|
||||
}
|
||||
|
||||
void
|
||||
nm_keyfile_add_group(GKeyFile *keyfile, const char *group)
|
||||
{
|
||||
nm_assert(keyfile);
|
||||
nm_assert(group);
|
||||
|
||||
/* You can only call this function if the group doesn't exist yet.
|
||||
* Because, we are about to add a dummy key, so we would have to
|
||||
* be sure that the key doesn't exist. */
|
||||
nm_assert(!g_key_file_has_group(keyfile, group));
|
||||
|
||||
/* Ensure the group is present.
|
||||
* There is no API for that, so add and remove a dummy key.
|
||||
* For a profile it matters whether a setting is present or not,
|
||||
* and we need to ensure that we persist the presence of the setting to keyfile*/
|
||||
g_key_file_set_value(keyfile, group, ".X", "1");
|
||||
g_key_file_remove_key(keyfile, group, ".X", NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2305,8 +2305,21 @@ wired_s390_options_writer_full(KeyfileWriterInfo *info,
|
|||
{
|
||||
NMSettingWired *s_wired = NM_SETTING_WIRED(setting);
|
||||
guint i, n;
|
||||
const char *setting_alias;
|
||||
|
||||
n = nm_setting_wired_get_num_s390_options(s_wired);
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
setting_alias = nm_keyfile_plugin_get_alias_for_setting_name(NM_SETTING_WIRED_SETTING_NAME);
|
||||
if (!g_key_file_has_group(info->keyfile, NM_SETTING_WIRED_SETTING_NAME)
|
||||
&& !g_key_file_has_group(info->keyfile, setting_alias)) {
|
||||
/* groups in the keyfile are ordered. When we are about to add [ethernet-s390-options],
|
||||
* we want to also have an [ethernet] group, first. */
|
||||
|
||||
nm_keyfile_add_group(info->keyfile, setting_alias ?: NM_SETTING_WIRED_SETTING_NAME);
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
gs_free char *key_to_free = NULL;
|
||||
const char *opt_key;
|
||||
|
|
@ -2755,6 +2768,11 @@ struct _ParseInfoProperty {
|
|||
* default value. By setting this flag to TRUE, also
|
||||
* default values are written. */
|
||||
bool writer_persist_default : 1;
|
||||
|
||||
/* This flag indicates that the property should always
|
||||
* be written to keyfile, even if it's the default.
|
||||
* This is currently only implemented for STRV properties. */
|
||||
bool always_write : 1;
|
||||
};
|
||||
|
||||
#define PARSE_INFO_PROPERTY(_property_name, ...) \
|
||||
|
|
@ -2856,53 +2874,57 @@ static const ParseInfoSetting *const parse_infos[_NM_META_SETTING_TYPE_NUM] = {
|
|||
NM_META_SETTING_TYPE_INFINIBAND,
|
||||
PARSE_INFO_PROPERTIES(PARSE_INFO_PROPERTY(NM_SETTING_INFINIBAND_MAC_ADDRESS,
|
||||
.parser = mac_address_parser_INFINIBAND, ), ), ),
|
||||
PARSE_INFO_SETTING(NM_META_SETTING_TYPE_IP4_CONFIG,
|
||||
PARSE_INFO_PROPERTIES(
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_ADDRESSES,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser = ip_address_or_route_parser,
|
||||
.writer = addr_writer, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_DNS,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser = ip_dns_parser,
|
||||
.writer = dns_writer, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_GATEWAY, .writer_skip = TRUE, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_ROUTES,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser = ip_address_or_route_parser,
|
||||
.writer = route_writer, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_ROUTING_RULES,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser_full = ip_routing_rule_parser_full,
|
||||
.writer_full = ip_routing_rule_writer_full,
|
||||
.has_parser_full = TRUE,
|
||||
.has_writer_full = TRUE, ), ), ),
|
||||
PARSE_INFO_SETTING(NM_META_SETTING_TYPE_IP6_CONFIG,
|
||||
PARSE_INFO_PROPERTIES(
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser = ip6_addr_gen_mode_parser,
|
||||
.writer = ip6_addr_gen_mode_writer,
|
||||
.writer_persist_default = TRUE, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_ADDRESSES,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser = ip_address_or_route_parser,
|
||||
.writer = addr_writer, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_DNS,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser = ip_dns_parser,
|
||||
.writer = dns_writer, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_GATEWAY, .writer_skip = TRUE, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_ROUTES,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser = ip_address_or_route_parser,
|
||||
.writer = route_writer, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_ROUTING_RULES,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser_full = ip_routing_rule_parser_full,
|
||||
.writer_full = ip_routing_rule_writer_full,
|
||||
.has_parser_full = TRUE,
|
||||
.has_writer_full = TRUE, ), ), ),
|
||||
PARSE_INFO_SETTING(
|
||||
NM_META_SETTING_TYPE_IP4_CONFIG,
|
||||
PARSE_INFO_PROPERTIES(
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_ADDRESSES,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser = ip_address_or_route_parser,
|
||||
.writer = addr_writer, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_DNS,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser = ip_dns_parser,
|
||||
.writer = dns_writer, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_DNS_OPTIONS, .always_write = TRUE, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_GATEWAY, .writer_skip = TRUE, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_ROUTES,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser = ip_address_or_route_parser,
|
||||
.writer = route_writer, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_ROUTING_RULES,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser_full = ip_routing_rule_parser_full,
|
||||
.writer_full = ip_routing_rule_writer_full,
|
||||
.has_parser_full = TRUE,
|
||||
.has_writer_full = TRUE, ), ), ),
|
||||
PARSE_INFO_SETTING(
|
||||
NM_META_SETTING_TYPE_IP6_CONFIG,
|
||||
PARSE_INFO_PROPERTIES(
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser = ip6_addr_gen_mode_parser,
|
||||
.writer = ip6_addr_gen_mode_writer,
|
||||
.writer_persist_default = TRUE, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_ADDRESSES,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser = ip_address_or_route_parser,
|
||||
.writer = addr_writer, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_DNS,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser = ip_dns_parser,
|
||||
.writer = dns_writer, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_DNS_OPTIONS, .always_write = TRUE, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_GATEWAY, .writer_skip = TRUE, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_ROUTES,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser = ip_address_or_route_parser,
|
||||
.writer = route_writer, ),
|
||||
PARSE_INFO_PROPERTY(NM_SETTING_IP_CONFIG_ROUTING_RULES,
|
||||
.parser_no_check_key = TRUE,
|
||||
.parser_full = ip_routing_rule_parser_full,
|
||||
.writer_full = ip_routing_rule_writer_full,
|
||||
.has_parser_full = TRUE,
|
||||
.has_writer_full = TRUE, ), ), ),
|
||||
PARSE_INFO_SETTING(
|
||||
NM_META_SETTING_TYPE_OVS_EXTERNAL_IDS,
|
||||
PARSE_INFO_PROPERTIES(PARSE_INFO_PROPERTY(NM_SETTING_OVS_EXTERNAL_IDS_DATA,
|
||||
|
|
@ -3936,11 +3958,13 @@ write_setting_value(KeyfileWriterInfo *info,
|
|||
char **array;
|
||||
|
||||
array = (char **) g_value_get_boxed(&value);
|
||||
nm_keyfile_plugin_kf_set_string_list(info->keyfile,
|
||||
setting_info->setting_name,
|
||||
key,
|
||||
(const char **const) array,
|
||||
g_strv_length(array));
|
||||
if ((g_strv_length(array) != 0) || (pip && pip->always_write)) {
|
||||
nm_keyfile_plugin_kf_set_string_list(info->keyfile,
|
||||
setting_info->setting_name,
|
||||
key,
|
||||
(const char **const) array,
|
||||
g_strv_length(array));
|
||||
}
|
||||
} else if (type == G_TYPE_HASH_TABLE) {
|
||||
write_hash_of_string(info->keyfile, setting, key, &value);
|
||||
} else if (type == G_TYPE_ARRAY) {
|
||||
|
|
@ -4190,10 +4214,7 @@ nm_keyfile_write(NMConnection *connection,
|
|||
|| g_key_file_has_group(info.keyfile, setting_name)) {
|
||||
/* we have a section for the setting. Nothing to do. */
|
||||
} else {
|
||||
/* ensure the group is present. There is no API for that, so add and remove
|
||||
* a dummy key. */
|
||||
g_key_file_set_value(info.keyfile, setting_alias ?: setting_name, ".X", "1");
|
||||
g_key_file_remove_key(info.keyfile, setting_alias ?: setting_name, ".X", NULL);
|
||||
nm_keyfile_add_group(info.keyfile, setting_alias ?: setting_name);
|
||||
}
|
||||
|
||||
if (NM_IS_SETTING_WIREGUARD(setting)) {
|
||||
|
|
|
|||
|
|
@ -3587,20 +3587,16 @@ test_roundtrip_conversion(gconstpointer test_data)
|
|||
"uuid=%s\n"
|
||||
"type=ethernet\n"
|
||||
"interface-name=%s\n"
|
||||
"permissions=\n"
|
||||
"\n"
|
||||
"[ethernet]\n"
|
||||
"mac-address-blacklist=\n"
|
||||
"%s" /* mtu */
|
||||
"\n"
|
||||
"%s" /* [ethernet-s390-options] */
|
||||
"[ipv4]\n"
|
||||
"dns-search=\n"
|
||||
"method=auto\n"
|
||||
"\n"
|
||||
"[ipv6]\n"
|
||||
"addr-gen-mode=stable-privacy\n"
|
||||
"dns-search=\n"
|
||||
"method=auto\n"
|
||||
"\n"
|
||||
"[proxy]\n"
|
||||
|
|
@ -3618,20 +3614,16 @@ test_roundtrip_conversion(gconstpointer test_data)
|
|||
"uuid=%s\n"
|
||||
"type=ethernet\n"
|
||||
"interface-name=%s\n"
|
||||
"permissions=\n"
|
||||
"\n"
|
||||
"[ethernet]\n"
|
||||
"mac-address-blacklist=\n"
|
||||
"%s" /* mtu */
|
||||
"\n"
|
||||
"%s" /* [ethernet-s390-options] */
|
||||
"[ipv4]\n"
|
||||
"dns-search=\n"
|
||||
"method=auto\n"
|
||||
"\n"
|
||||
"[ipv6]\n"
|
||||
"addr-gen-mode=stable-privacy\n"
|
||||
"dns-search=\n"
|
||||
"method=auto\n"
|
||||
"",
|
||||
ID,
|
||||
|
|
@ -3661,17 +3653,14 @@ test_roundtrip_conversion(gconstpointer test_data)
|
|||
"uuid=%s\n"
|
||||
"type=wireguard\n"
|
||||
"interface-name=%s\n"
|
||||
"permissions=\n"
|
||||
"\n"
|
||||
"[wireguard]\n"
|
||||
"\n"
|
||||
"[ipv4]\n"
|
||||
"dns-search=\n"
|
||||
"method=disabled\n"
|
||||
"\n"
|
||||
"[ipv6]\n"
|
||||
"addr-gen-mode=stable-privacy\n"
|
||||
"dns-search=\n"
|
||||
"method=disabled\n"
|
||||
"\n"
|
||||
"[proxy]\n"
|
||||
|
|
@ -3713,7 +3702,6 @@ test_roundtrip_conversion(gconstpointer test_data)
|
|||
"uuid=%s\n"
|
||||
"type=wireguard\n"
|
||||
"interface-name=%s\n"
|
||||
"permissions=\n"
|
||||
"\n"
|
||||
"[wireguard]\n"
|
||||
"%s" /* fwmark */
|
||||
|
|
@ -3723,12 +3711,10 @@ test_roundtrip_conversion(gconstpointer test_data)
|
|||
"%s" /* [wireguard-peers*] */
|
||||
"\n"
|
||||
"[ipv4]\n"
|
||||
"dns-search=\n"
|
||||
"method=disabled\n"
|
||||
"\n"
|
||||
"[ipv6]\n"
|
||||
"addr-gen-mode=stable-privacy\n"
|
||||
"dns-search=\n"
|
||||
"method=disabled\n"
|
||||
"\n"
|
||||
"[proxy]\n"
|
||||
|
|
@ -3798,14 +3784,11 @@ test_roundtrip_conversion(gconstpointer test_data)
|
|||
"uuid=%s\n"
|
||||
"type=ethernet\n"
|
||||
"interface-name=%s\n"
|
||||
"permissions=\n"
|
||||
"\n"
|
||||
"[ethernet]\n"
|
||||
"mac-address-blacklist=\n"
|
||||
"%s" /* mtu */
|
||||
"\n"
|
||||
"[ipv4]\n"
|
||||
"dns-search=\n"
|
||||
"method=auto\n"
|
||||
"routing-rule1=priority 1 from 0.0.0.0/0 table 1000\n"
|
||||
"routing-rule2=priority 2 from 192.168.1.0/25 table 1001\n"
|
||||
|
|
@ -3813,7 +3796,6 @@ test_roundtrip_conversion(gconstpointer test_data)
|
|||
"\n"
|
||||
"[ipv6]\n"
|
||||
"addr-gen-mode=stable-privacy\n"
|
||||
"dns-search=\n"
|
||||
"method=auto\n"
|
||||
"routing-rule1=priority 1 from ::/0 table 1000\n"
|
||||
"routing-rule2=priority 2 from 1:2:3:b::/65 table 1001\n"
|
||||
|
|
|
|||
|
|
@ -92,4 +92,6 @@ const char *nm_keyfile_key_encode(const char *name, char **out_to_free);
|
|||
|
||||
const char *nm_keyfile_key_decode(const char *key, char **out_to_free);
|
||||
|
||||
void nm_keyfile_add_group(GKeyFile *keyfile, const char *group);
|
||||
|
||||
#endif /* __NM_KEYFILE_UTILS_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue