core: don't have IP4 and IP6 configs on slaves
Although it's convenient in some places to have IP configs on all connections, it makes more sense in other places to not have IP configs on slaves. (eg, it's confusing for nmcli, etc, to report a full NMSettingIP4Config on a slave device). So revert parts of the earlier patch. However, it's still safe to assume that s_ip4 != NULL if method != DISABLED, so some of the earlier simplifications can stay. Also, add nm_utils_get_ip_config_method(), which returns the correct IP config method for a connection, whether the connection has IP4 and IP6 settings objects or not, and use that to keep some more of the simplifications from the earlier patch.
This commit is contained in:
@@ -294,13 +294,9 @@ nm_utils_get_shared_wifi_permission (NMConnection *connection)
|
||||
{
|
||||
NMSettingWireless *s_wifi;
|
||||
NMSettingWirelessSecurity *s_wsec;
|
||||
NMSettingIP4Config *s_ip4;
|
||||
const char *method = NULL;
|
||||
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
method = nm_setting_ip4_config_get_method (s_ip4);
|
||||
g_assert (method);
|
||||
|
||||
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
|
||||
if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) != 0)
|
||||
return NULL; /* Not shared */
|
||||
|
||||
@@ -592,33 +588,30 @@ nm_utils_normalize_connection (NMConnection *connection,
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
s_ip6 = nm_connection_get_setting_ip6_config (connection);
|
||||
|
||||
/* Slave connections don't have IP configuration. */
|
||||
if (nm_setting_connection_get_master (s_con)) {
|
||||
default_ip4_method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
|
||||
default_ip6_method = NM_SETTING_IP6_CONFIG_METHOD_IGNORE;
|
||||
/* Slave connections don't have IP configuration. */
|
||||
|
||||
if (s_ip4) {
|
||||
method = nm_setting_ip4_config_get_method (s_ip4);
|
||||
if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) != 0) {
|
||||
nm_log_warn (LOGD_SETTINGS, "ignoring IP4 config on slave '%s'",
|
||||
nm_connection_get_id (connection));
|
||||
}
|
||||
nm_connection_remove_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
|
||||
s_ip4 = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (s_ip6) {
|
||||
method = nm_setting_ip6_config_get_method (s_ip6);
|
||||
if (g_strcmp0 (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) != 0) {
|
||||
nm_log_warn (LOGD_SETTINGS, "ignoring IP6 config on slave '%s'",
|
||||
nm_connection_get_id (connection));
|
||||
}
|
||||
nm_connection_remove_setting (connection, NM_TYPE_SETTING_IP6_CONFIG);
|
||||
s_ip6 = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Ensure all connections have IP4 and IP6 settings objects. If no
|
||||
} else {
|
||||
/* Ensure all non-slave connections have IP4 and IP6 settings objects. If no
|
||||
* IP6 setting was specified, then assume that means IP6 config is allowed
|
||||
* to fail. But if no IP4 setting was specified, assume the caller was just
|
||||
* being lazy.
|
||||
@@ -641,6 +634,50 @@ nm_utils_normalize_connection (NMConnection *connection,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_utils_get_ip_config_method (NMConnection *connection,
|
||||
GType ip_setting_type)
|
||||
{
|
||||
NMSettingConnection *s_con;
|
||||
NMSettingIP4Config *s_ip4;
|
||||
NMSettingIP6Config *s_ip6;
|
||||
const char *method;
|
||||
|
||||
s_con = nm_connection_get_setting_connection (connection);
|
||||
|
||||
if (ip_setting_type == NM_TYPE_SETTING_IP4_CONFIG) {
|
||||
g_return_val_if_fail (s_con != NULL, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
|
||||
|
||||
if (nm_setting_connection_get_master (s_con))
|
||||
return NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
|
||||
else {
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
g_return_val_if_fail (s_ip4 != NULL, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
|
||||
method = nm_setting_ip4_config_get_method (s_ip4);
|
||||
g_return_val_if_fail (method != NULL, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
} else if (ip_setting_type == NM_TYPE_SETTING_IP6_CONFIG) {
|
||||
g_return_val_if_fail (s_con != NULL, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
|
||||
|
||||
if (nm_setting_connection_get_master (s_con))
|
||||
return NM_SETTING_IP6_CONFIG_METHOD_IGNORE;
|
||||
else {
|
||||
s_ip6 = nm_connection_get_setting_ip6_config (connection);
|
||||
g_return_val_if_fail (s_ip6 != NULL, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
|
||||
method = nm_setting_ip6_config_get_method (s_ip6);
|
||||
g_return_val_if_fail (method != NULL, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
} else
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
void
|
||||
nm_utils_complete_generic (NMConnection *connection,
|
||||
|
@@ -84,6 +84,8 @@ gboolean nm_utils_get_proc_sys_net_value_with_bounds (const char *path,
|
||||
|
||||
void nm_utils_normalize_connection (NMConnection *connection,
|
||||
gboolean default_enable_ipv6);
|
||||
const char *nm_utils_get_ip_config_method (NMConnection *connection,
|
||||
GType ip_setting_type);
|
||||
|
||||
void nm_utils_complete_generic (NMConnection *connection,
|
||||
const char *ctype,
|
||||
|
@@ -1298,7 +1298,6 @@ can_auto_connect (NMDevice *dev,
|
||||
NMDeviceWifi *self = NM_DEVICE_WIFI (dev);
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
GSList *ap_iter;
|
||||
NMSettingIP4Config *s_ip4;
|
||||
const char *method = NULL;
|
||||
guint64 timestamp = 0;
|
||||
|
||||
@@ -1315,8 +1314,7 @@ can_auto_connect (NMDevice *dev,
|
||||
}
|
||||
|
||||
/* Use the connection if it's a shared connection */
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
method = nm_setting_ip4_config_get_method (s_ip4);
|
||||
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
|
||||
if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
|
||||
return TRUE;
|
||||
|
||||
@@ -1490,15 +1488,14 @@ scanning_allowed (NMDeviceWifi *self)
|
||||
req = nm_device_get_act_request (NM_DEVICE (self));
|
||||
if (req) {
|
||||
NMConnection *connection;
|
||||
NMSettingIP4Config *s_ip4;
|
||||
NMSettingWireless *s_wifi;
|
||||
const char *ip4_method = NULL;
|
||||
const GByteArray *bssid;
|
||||
|
||||
/* Don't scan when a shared connection is active; it makes drivers mad */
|
||||
connection = nm_act_request_get_connection (req);
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
ip4_method = nm_setting_ip4_config_get_method (s_ip4);
|
||||
ip4_method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
|
||||
|
||||
if (!strcmp (ip4_method, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
|
||||
return FALSE;
|
||||
|
||||
|
@@ -1012,18 +1012,14 @@ nm_device_release_one_slave (NMDevice *dev, NMDevice *slave, gboolean failed)
|
||||
static gboolean
|
||||
connection_is_static (NMConnection *connection)
|
||||
{
|
||||
NMSettingIP4Config *s_ip4;
|
||||
NMSettingIP6Config *s_ip6;
|
||||
const char *method;
|
||||
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
method = nm_setting_ip4_config_get_method (s_ip4);
|
||||
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
|
||||
if ( strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) != 0
|
||||
&& strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) != 0)
|
||||
return FALSE;
|
||||
|
||||
s_ip6 = nm_connection_get_setting_ip6_config (connection);
|
||||
method = nm_setting_ip6_config_get_method (s_ip6);
|
||||
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
|
||||
if ( strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) != 0
|
||||
&& strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) != 0)
|
||||
return FALSE;
|
||||
@@ -2170,8 +2166,7 @@ nm_device_handle_autoip4_event (NMDevice *self,
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
||||
NMConnection *connection = NULL;
|
||||
NMSettingIP4Config *s_ip4 = NULL;
|
||||
const char *iface, *method = NULL;
|
||||
const char *iface, *method;
|
||||
NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
|
||||
|
||||
g_return_if_fail (event != NULL);
|
||||
@@ -2183,9 +2178,8 @@ nm_device_handle_autoip4_event (NMDevice *self,
|
||||
g_assert (connection);
|
||||
|
||||
/* Ignore if the connection isn't an AutoIP connection */
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
method = nm_setting_ip4_config_get_method (s_ip4);
|
||||
if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL) != 0)
|
||||
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
|
||||
if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL) != 0)
|
||||
return;
|
||||
|
||||
iface = nm_device_get_iface (self);
|
||||
@@ -2695,11 +2689,9 @@ have_any_ready_slaves (NMDevice *device, const GSList *slaves)
|
||||
static gboolean
|
||||
ip4_requires_slaves (NMConnection *connection)
|
||||
{
|
||||
NMSettingIP4Config *s_ip4;
|
||||
const char *method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
|
||||
const char *method;
|
||||
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
method = nm_setting_ip4_config_get_method (s_ip4);
|
||||
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
|
||||
return strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0;
|
||||
}
|
||||
|
||||
@@ -2710,9 +2702,8 @@ act_stage3_ip4_config_start (NMDevice *self,
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
||||
NMConnection *connection;
|
||||
NMSettingIP4Config *s_ip4;
|
||||
NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
|
||||
const char *method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
|
||||
const char *method;
|
||||
GSList *slaves;
|
||||
gboolean ready_slaves;
|
||||
|
||||
@@ -2721,8 +2712,9 @@ act_stage3_ip4_config_start (NMDevice *self,
|
||||
connection = nm_device_get_connection (self);
|
||||
g_assert (connection);
|
||||
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
method = nm_setting_ip4_config_get_method (s_ip4);
|
||||
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
|
||||
if (priv->master)
|
||||
g_assert_cmpstr (method, ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED);
|
||||
|
||||
if ( strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) != 0
|
||||
&& nm_device_is_master (self)
|
||||
@@ -3228,11 +3220,9 @@ done:
|
||||
static gboolean
|
||||
ip6_requires_slaves (NMConnection *connection)
|
||||
{
|
||||
NMSettingIP6Config *s_ip6;
|
||||
const char *method = NM_SETTING_IP6_CONFIG_METHOD_AUTO;
|
||||
const char *method;
|
||||
|
||||
s_ip6 = nm_connection_get_setting_ip6_config (connection);
|
||||
method = nm_setting_ip6_config_get_method (s_ip6);
|
||||
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
|
||||
|
||||
/* SLAAC, DHCP, and Link-Local depend on connectivity (and thus slaves)
|
||||
* to complete addressing. SLAAC and DHCP obviously need a peer to
|
||||
@@ -3252,8 +3242,7 @@ act_stage3_ip6_config_start (NMDevice *self,
|
||||
const char *ip_iface;
|
||||
NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
|
||||
NMConnection *connection;
|
||||
NMSettingIP6Config *s_ip6;
|
||||
const char *method = NM_SETTING_IP6_CONFIG_METHOD_AUTO;
|
||||
const char *method;
|
||||
int conf_use_tempaddr;
|
||||
NMSettingIP6ConfigPrivacy ip6_privacy = NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN;
|
||||
const char *ip6_privacy_str = "0\n";
|
||||
@@ -3267,8 +3256,9 @@ act_stage3_ip6_config_start (NMDevice *self,
|
||||
connection = nm_device_get_connection (self);
|
||||
g_assert (connection);
|
||||
|
||||
s_ip6 = nm_connection_get_setting_ip6_config (connection);
|
||||
method = nm_setting_ip6_config_get_method (s_ip6);
|
||||
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
|
||||
if (priv->master)
|
||||
g_assert_cmpstr (method, ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
|
||||
|
||||
if ( strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) != 0
|
||||
&& nm_device_is_master (self)
|
||||
@@ -3343,8 +3333,12 @@ act_stage3_ip6_config_start (NMDevice *self,
|
||||
conf_use_tempaddr = ip6_use_tempaddr ();
|
||||
if (conf_use_tempaddr >= 0)
|
||||
ip6_privacy = conf_use_tempaddr;
|
||||
else
|
||||
else {
|
||||
NMSettingIP6Config *s_ip6 = nm_connection_get_setting_ip6_config (connection);
|
||||
|
||||
if (s_ip6)
|
||||
ip6_privacy = nm_setting_ip6_config_get_ip6_privacy (s_ip6);
|
||||
}
|
||||
ip6_privacy = CLAMP (ip6_privacy, NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN, NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR);
|
||||
|
||||
switch (ip6_privacy) {
|
||||
@@ -3856,9 +3850,8 @@ nm_device_activate_ip4_config_commit (gpointer user_data)
|
||||
NMDevice *self = NM_DEVICE (user_data);
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
||||
NMActRequest *req;
|
||||
const char *iface, *method = NULL;
|
||||
const char *iface, *method;
|
||||
NMConnection *connection;
|
||||
NMSettingIP4Config *s_ip4;
|
||||
NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
|
||||
int ifindex;
|
||||
|
||||
@@ -3889,8 +3882,7 @@ nm_device_activate_ip4_config_commit (gpointer user_data)
|
||||
}
|
||||
|
||||
/* Start IPv4 sharing if we need it */
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
method = nm_setting_ip4_config_get_method (s_ip4);
|
||||
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
|
||||
|
||||
if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0) {
|
||||
if (!start_sharing (self, priv->ip4_config)) {
|
||||
@@ -5003,8 +4995,7 @@ dispose (GObject *object)
|
||||
*/
|
||||
if (nm_device_can_assume_connections (self) && (priv->state == NM_DEVICE_STATE_ACTIVATED)) {
|
||||
NMConnection *connection;
|
||||
NMSettingIP4Config *s_ip4 = NULL;
|
||||
const char *method = NULL;
|
||||
const char *method;
|
||||
|
||||
connection = nm_device_get_connection (self);
|
||||
if (connection) {
|
||||
@@ -5012,8 +5003,7 @@ dispose (GObject *object)
|
||||
* All IPv6 connections can be left up, so we don't have
|
||||
* to check that.
|
||||
*/
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
method = nm_setting_ip4_config_get_method (s_ip4);
|
||||
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
|
||||
if ( !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)
|
||||
|| !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)
|
||||
|| !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED))
|
||||
@@ -6404,8 +6394,6 @@ ip4_match_config (NMDevice *self, NMConnection *connection)
|
||||
NMDHCPManager *dhcp_mgr;
|
||||
const char *method;
|
||||
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
|
||||
/* Get any saved leases that apply to this connection */
|
||||
dhcp_mgr = nm_dhcp_manager_get ();
|
||||
leases = nm_dhcp_manager_get_lease_config (dhcp_mgr,
|
||||
@@ -6414,7 +6402,7 @@ ip4_match_config (NMDevice *self, NMConnection *connection)
|
||||
FALSE);
|
||||
g_object_unref (dhcp_mgr);
|
||||
|
||||
method = nm_setting_ip4_config_get_method (s_ip4);
|
||||
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
|
||||
if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
|
||||
gboolean found = FALSE;
|
||||
|
||||
@@ -6455,6 +6443,8 @@ ip4_match_config (NMDevice *self, NMConnection *connection)
|
||||
/* Everything below for static addressing */
|
||||
|
||||
/* Find all IP4 addresses of this connection on the device */
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
if (s_ip4) {
|
||||
num = nm_setting_ip4_config_get_num_addresses (s_ip4);
|
||||
for (i = 0; i < num; i++) {
|
||||
NMIP4Address *addr = nm_setting_ip4_config_get_address (s_ip4, i);
|
||||
@@ -6464,6 +6454,7 @@ ip4_match_config (NMDevice *self, NMConnection *connection)
|
||||
nm_ip4_address_get_prefix (addr)))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Success; all the connection's static IP addresses are assigned to the device */
|
||||
return TRUE;
|
||||
|
@@ -143,14 +143,15 @@ get_best_ip4_device (NMManager *manager, gboolean fully_activated)
|
||||
connection = nm_act_request_get_connection (req);
|
||||
g_assert (connection);
|
||||
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
|
||||
/* Never set the default route through an IPv4LL-addressed device */
|
||||
method = nm_setting_ip4_config_get_method (s_ip4);
|
||||
if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL))
|
||||
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
|
||||
/* If IPv4 is disabled or link-local-only, it can't be the default */
|
||||
if ( !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)
|
||||
|| !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL))
|
||||
continue;
|
||||
|
||||
/* 'never-default' devices can't ever be the default */
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
g_assert (s_ip4);
|
||||
if (nm_setting_ip4_config_get_never_default (s_ip4))
|
||||
continue;
|
||||
|
||||
@@ -221,12 +222,13 @@ get_best_ip6_device (NMManager *manager, gboolean fully_activated)
|
||||
connection = nm_act_request_get_connection (req);
|
||||
g_assert (connection);
|
||||
|
||||
s_ip6 = nm_connection_get_setting_ip6_config (connection);
|
||||
|
||||
method = nm_setting_ip6_config_get_method (s_ip6);
|
||||
if (!strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL))
|
||||
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
|
||||
if ( !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)
|
||||
|| !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL))
|
||||
continue;
|
||||
|
||||
s_ip6 = nm_connection_get_setting_ip6_config (connection);
|
||||
g_assert (s_ip6);
|
||||
if (nm_setting_ip6_config_get_never_default (s_ip6))
|
||||
continue;
|
||||
|
||||
|
Reference in New Issue
Block a user