ip-tunnel: allow wired setting for some tunnel modes

gretap and ip6gretap ip-tunnel interfaces encapsulate L2 packets over
IP. Allow adding a wired setting for such connections so that users
can change the interface MAC.
This commit is contained in:
Beniamino Galvani 2018-06-26 10:48:03 +02:00
parent 3f9f9f7fa2
commit fc99aad378
4 changed files with 52 additions and 0 deletions

View file

@ -7778,6 +7778,7 @@ const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[] = {
.valid_parts = NM_META_SETTING_VALID_PARTS (
NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE),
NM_META_SETTING_VALID_PART_ITEM (IP_TUNNEL, TRUE),
NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE),
),
),
SETTING_INFO (MACSEC,

View file

@ -1157,6 +1157,26 @@ _normalize_ovs_interface_type (NMConnection *self, GHashTable *parameters)
return modified;
}
static gboolean
_normalize_ip_tunnel_wired_setting (NMConnection *self, GHashTable *parameters)
{
NMSettingIPTunnel *s_ip_tunnel;
s_ip_tunnel = nm_connection_get_setting_ip_tunnel (self);
if (!s_ip_tunnel)
return FALSE;
if ( nm_connection_get_setting_wired (self)
&& !NM_IN_SET (nm_setting_ip_tunnel_get_mode (s_ip_tunnel),
NM_IP_TUNNEL_MODE_GRETAP,
NM_IP_TUNNEL_MODE_IP6GRETAP)) {
nm_connection_remove_setting (self, NM_TYPE_SETTING_WIRED);
return TRUE;
}
return FALSE;
}
static gboolean
_normalize_required_settings (NMConnection *self, GHashTable *parameters)
{
@ -1502,6 +1522,7 @@ nm_connection_normalize (NMConnection *connection,
was_modified |= _normalize_team_port_config (connection, parameters);
was_modified |= _normalize_bluetooth_type (connection, parameters);
was_modified |= _normalize_ovs_interface_type (connection, parameters);
was_modified |= _normalize_ip_tunnel_wired_setting (connection, parameters);
/* Verify anew. */
success = _nm_connection_verify (connection, error);

View file

@ -458,6 +458,20 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
if ( nm_connection_get_setting_wired (connection)
&& !NM_IN_SET (priv->mode,
NM_IP_TUNNEL_MODE_GRETAP,
NM_IP_TUNNEL_MODE_IP6GRETAP)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("wired setting not allowed for mode %s"),
nm_utils_enum_to_str (nm_ip_tunnel_mode_get_type (), priv->mode));
g_prefix_error (error, "%s.%s: ", NM_SETTING_IP_TUNNEL_SETTING_NAME,
NM_SETTING_IP_TUNNEL_MODE);
return NM_SETTING_VERIFY_NORMALIZABLE_ERROR;
}
return TRUE;
}

View file

@ -952,6 +952,21 @@ set_property (GObject *object, guint prop_id,
}
}
static NMActStageReturn
act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason)
{
NMActStageReturn ret;
ret = NM_DEVICE_CLASS (nm_device_ip_tunnel_parent_class)->act_stage1_prepare (device, out_failure_reason);
if (ret != NM_ACT_STAGE_RETURN_SUCCESS)
return ret;
if (!nm_device_hw_addr_set_cloned (device, nm_device_get_applied_connection (device), FALSE))
return NM_ACT_STAGE_RETURN_FAILURE;
return NM_ACT_STAGE_RETURN_SUCCESS;
}
/*****************************************************************************/
static void
@ -1028,6 +1043,7 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *klass)
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_device_ip_tunnel);
device_class->act_stage1_prepare = act_stage1_prepare;
device_class->link_changed = link_changed;
device_class->can_reapply_change = can_reapply_change;
device_class->complete_connection = complete_connection;