mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-09 03:00:20 +01:00
core: tweak NMSettingIP[46]Config generation
NMIP4Config and NMIP6Config had methods to update an existing NMSetting. However, the functions would really only work correctly if the passed-in setting was empty. Change them from "update_setting" to "create_setting", and have them create the NMSetting themselves, and update NMDevice for that. (If we need update_setting later, we can add it, after figuring out exactly how it's actually supposed to work.)
This commit is contained in:
parent
dae8391436
commit
6fd76323e0
5 changed files with 45 additions and 37 deletions
|
|
@ -1837,19 +1837,11 @@ nm_device_generate_connection (NMDevice *device)
|
|||
NULL);
|
||||
} else {
|
||||
/* Only regular and master devices get IP configuration; slaves do not */
|
||||
s_ip4 = nm_setting_ip4_config_new ();
|
||||
s_ip4 = nm_ip4_config_create_setting (priv->ip4_config);
|
||||
nm_connection_add_setting (connection, s_ip4);
|
||||
if (priv->ip4_config)
|
||||
nm_ip4_config_update_setting (priv->ip4_config, (NMSettingIP4Config *) s_ip4);
|
||||
else
|
||||
g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED, NULL);
|
||||
|
||||
s_ip6 = nm_setting_ip6_config_new ();
|
||||
s_ip6 = nm_ip6_config_create_setting (priv->ip6_config);
|
||||
nm_connection_add_setting (connection, s_ip6);
|
||||
if (priv->ip6_config)
|
||||
nm_ip6_config_update_setting (priv->ip6_config, (NMSettingIP6Config *) s_ip6);
|
||||
else
|
||||
g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL);
|
||||
}
|
||||
|
||||
klass->update_connection (device, connection);
|
||||
|
|
|
|||
|
|
@ -379,16 +379,23 @@ nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIP4Config *setting)
|
|||
g_object_thaw_notify (G_OBJECT (config));
|
||||
}
|
||||
|
||||
void
|
||||
nm_ip4_config_update_setting (const NMIP4Config *config, NMSettingIP4Config *setting)
|
||||
NMSetting *
|
||||
nm_ip4_config_create_setting (const NMIP4Config *config)
|
||||
{
|
||||
NMSettingIP4Config *s_ip4;
|
||||
guint32 gateway;
|
||||
guint naddresses, nroutes, nnameservers, nsearches;
|
||||
const char *method = NULL;
|
||||
int i;
|
||||
|
||||
if (!config)
|
||||
return;
|
||||
s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
|
||||
|
||||
if (!config) {
|
||||
g_object_set (s_ip4,
|
||||
NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
|
||||
NULL);
|
||||
return NM_SETTING (s_ip4);
|
||||
}
|
||||
|
||||
gateway = nm_ip4_config_get_gateway (config);
|
||||
naddresses = nm_ip4_config_get_num_addresses (config);
|
||||
|
|
@ -422,17 +429,16 @@ nm_ip4_config_update_setting (const NMIP4Config *config, NMSettingIP4Config *set
|
|||
nm_ip4_address_set_gateway (s_addr, gateway);
|
||||
|
||||
if (*address->label)
|
||||
NM_UTIL_PRIVATE_CALL (nm_setting_ip4_config_add_address_with_label (setting, s_addr, address->label));
|
||||
NM_UTIL_PRIVATE_CALL (nm_setting_ip4_config_add_address_with_label (s_ip4, s_addr, address->label));
|
||||
else
|
||||
nm_setting_ip4_config_add_address (setting, s_addr);
|
||||
nm_setting_ip4_config_add_address (s_ip4, s_addr);
|
||||
nm_ip4_address_unref (s_addr);
|
||||
}
|
||||
|
||||
/* Only use 'disabled' if the method wasn't previously set */
|
||||
if (!method && !nm_setting_ip4_config_get_method (setting))
|
||||
/* Use 'disabled' if the method wasn't previously set */
|
||||
if (!method)
|
||||
method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
|
||||
if (method)
|
||||
g_object_set (setting, NM_SETTING_IP4_CONFIG_METHOD, method, NULL);
|
||||
g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, method, NULL);
|
||||
|
||||
/* Routes */
|
||||
for (i = 0; i < nroutes; i++) {
|
||||
|
|
@ -449,7 +455,7 @@ nm_ip4_config_update_setting (const NMIP4Config *config, NMSettingIP4Config *set
|
|||
nm_ip4_route_set_next_hop (s_route, route->gateway);
|
||||
nm_ip4_route_set_metric (s_route, route->metric);
|
||||
|
||||
nm_setting_ip4_config_add_route (setting, s_route);
|
||||
nm_setting_ip4_config_add_route (s_ip4, s_route);
|
||||
nm_ip4_route_unref (s_route);
|
||||
}
|
||||
|
||||
|
|
@ -457,13 +463,15 @@ nm_ip4_config_update_setting (const NMIP4Config *config, NMSettingIP4Config *set
|
|||
for (i = 0; i < nnameservers; i++) {
|
||||
guint32 nameserver = nm_ip4_config_get_nameserver (config, i);
|
||||
|
||||
nm_setting_ip4_config_add_dns (setting, nameserver);
|
||||
nm_setting_ip4_config_add_dns (s_ip4, nameserver);
|
||||
}
|
||||
for (i = 0; i < nsearches; i++) {
|
||||
const char *search = nm_ip4_config_get_search (config, i);
|
||||
|
||||
nm_setting_ip4_config_add_dns_search (setting, search);
|
||||
nm_setting_ip4_config_add_dns_search (s_ip4, search);
|
||||
}
|
||||
|
||||
return NM_SETTING (s_ip4);
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ const char * nm_ip4_config_get_dbus_path (const NMIP4Config *config);
|
|||
NMIP4Config *nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf);
|
||||
gboolean nm_ip4_config_commit (const NMIP4Config *config, int ifindex, int priority);
|
||||
void nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIP4Config *setting);
|
||||
void nm_ip4_config_update_setting (const NMIP4Config *config, NMSettingIP4Config *setting);
|
||||
NMSetting *nm_ip4_config_create_setting (const NMIP4Config *config);
|
||||
|
||||
/* Utility functions */
|
||||
void nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src);
|
||||
|
|
|
|||
|
|
@ -481,16 +481,23 @@ nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIP6Config *setting)
|
|||
g_object_thaw_notify (G_OBJECT (config));
|
||||
}
|
||||
|
||||
void
|
||||
nm_ip6_config_update_setting (const NMIP6Config *config, NMSettingIP6Config *setting)
|
||||
NMSetting *
|
||||
nm_ip6_config_create_setting (const NMIP6Config *config)
|
||||
{
|
||||
NMSettingIP6Config *s_ip6;
|
||||
const struct in6_addr *gateway;
|
||||
guint naddresses, nroutes, nnameservers, nsearches;
|
||||
const char *method = NULL;
|
||||
int i;
|
||||
|
||||
if (!config)
|
||||
return;
|
||||
s_ip6 = NM_SETTING_IP6_CONFIG (nm_setting_ip6_config_new ());
|
||||
|
||||
if (!config) {
|
||||
g_object_set (s_ip6,
|
||||
NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
|
||||
NULL);
|
||||
return NM_SETTING (s_ip6);
|
||||
}
|
||||
|
||||
gateway = nm_ip6_config_get_gateway (config);
|
||||
naddresses = nm_ip6_config_get_num_addresses (config);
|
||||
|
|
@ -527,15 +534,14 @@ nm_ip6_config_update_setting (const NMIP6Config *config, NMSettingIP6Config *set
|
|||
if (gateway)
|
||||
nm_ip6_address_set_gateway (s_addr, gateway);
|
||||
|
||||
nm_setting_ip6_config_add_address (setting, s_addr);
|
||||
nm_setting_ip6_config_add_address (s_ip6, s_addr);
|
||||
nm_ip6_address_unref (s_addr);
|
||||
}
|
||||
|
||||
/* Only use 'ignore' if the method wasn't previously set */
|
||||
if (!method && !nm_setting_ip6_config_get_method (setting))
|
||||
/* Use 'ignore' if the method wasn't previously set */
|
||||
if (!method)
|
||||
method = NM_SETTING_IP6_CONFIG_METHOD_IGNORE;
|
||||
if (method)
|
||||
g_object_set (setting, NM_SETTING_IP6_CONFIG_METHOD, method, NULL);
|
||||
g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_METHOD, method, NULL);
|
||||
|
||||
/* Routes */
|
||||
for (i = 0; i < nroutes; i++) {
|
||||
|
|
@ -557,7 +563,7 @@ nm_ip6_config_update_setting (const NMIP6Config *config, NMSettingIP6Config *set
|
|||
nm_ip6_route_set_next_hop (s_route, &route->gateway);
|
||||
nm_ip6_route_set_metric (s_route, route->metric);
|
||||
|
||||
nm_setting_ip6_config_add_route (setting, s_route);
|
||||
nm_setting_ip6_config_add_route (s_ip6, s_route);
|
||||
nm_ip6_route_unref (s_route);
|
||||
}
|
||||
|
||||
|
|
@ -565,13 +571,15 @@ nm_ip6_config_update_setting (const NMIP6Config *config, NMSettingIP6Config *set
|
|||
for (i = 0; i < nnameservers; i++) {
|
||||
const struct in6_addr *nameserver = nm_ip6_config_get_nameserver (config, i);
|
||||
|
||||
nm_setting_ip6_config_add_dns (setting, nameserver);
|
||||
nm_setting_ip6_config_add_dns (s_ip6, nameserver);
|
||||
}
|
||||
for (i = 0; i < nsearches; i++) {
|
||||
const char *search = nm_ip6_config_get_search (config, i);
|
||||
|
||||
nm_setting_ip6_config_add_dns_search (setting, search);
|
||||
nm_setting_ip6_config_add_dns_search (s_ip6, search);
|
||||
}
|
||||
|
||||
return NM_SETTING (s_ip6);
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ const char * nm_ip6_config_get_dbus_path (const NMIP6Config *config);
|
|||
NMIP6Config *nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary);
|
||||
gboolean nm_ip6_config_commit (const NMIP6Config *config, int ifindex, int priority);
|
||||
void nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIP6Config *setting);
|
||||
void nm_ip6_config_update_setting (const NMIP6Config *config, NMSettingIP6Config *setting);
|
||||
NMSetting *nm_ip6_config_create_setting (const NMIP6Config *config);
|
||||
|
||||
/* Utility functions */
|
||||
void nm_ip6_config_merge (NMIP6Config *dst, const NMIP6Config *src);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue