summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-01-14 14:03:36 +0100
committerThomas Haller <thaller@redhat.com>2021-01-19 16:41:45 +0100
commit7c05ff16322c5b5d5c8e382f94aefb09657aebdb (patch)
treec99780ac4e66603eb723e260dd6e0cc37874f1e8
parentbcb63affdd18cb5a246f332da35275adba443065 (diff)
downloadNetworkManager-7c05ff16322c5b5d5c8e382f94aefb09657aebdb.tar.gz
device: fix complete-connection for veth devices
Otherwise, $ nmcli device connect veth0 fails with Error: Failed to add/activate new connection: veth.peer: property is not specified In complete_connection(), we should by default complete ethernet connections, unless the caller already indicated to want a veth profile. Fixes: cd0cf9229d49 ('veth: add support to configure veth interfaces')
-rw-r--r--src/devices/nm-device-ethernet.c54
-rw-r--r--src/devices/nm-device-veth.c29
2 files changed, 54 insertions, 29 deletions
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
index f67baead46..35e6ac974b 100644
--- a/src/devices/nm-device-ethernet.c
+++ b/src/devices/nm-device-ethernet.c
@@ -1595,6 +1595,60 @@ complete_connection(NMDevice * device,
NMSettingWired *s_wired;
NMSettingPppoe *s_pppoe;
+ if (nm_streq0(nm_connection_get_connection_type(connection), NM_SETTING_VETH_SETTING_NAME)) {
+ NMSettingVeth *s_veth;
+ const char * peer_name = NULL;
+ const char * con_peer_name = NULL;
+ int ifindex;
+
+ nm_utils_complete_generic(nm_device_get_platform(device),
+ connection,
+ NM_SETTING_VETH_SETTING_NAME,
+ existing_connections,
+ NULL,
+ _("Veth connection"),
+ "veth",
+ NULL,
+ TRUE);
+
+ s_veth = _nm_connection_get_setting(connection, NM_TYPE_SETTING_VETH);
+ if (!s_veth) {
+ s_veth = (NMSettingVeth *) nm_setting_veth_new();
+ nm_connection_add_setting(connection, NM_SETTING(s_veth));
+ }
+
+ ifindex = nm_device_get_ip_ifindex(device);
+ if (ifindex > 0) {
+ const NMPlatformLink *pllink;
+
+ pllink = nm_platform_link_get(nm_device_get_platform(device), ifindex);
+ if (pllink && pllink->type == NM_LINK_TYPE_VETH && pllink->parent > 0) {
+ pllink = nm_platform_link_get(nm_device_get_platform(device), pllink->parent);
+
+ if (pllink && pllink->type == NM_LINK_TYPE_VETH) {
+ peer_name = pllink->name;
+ }
+ }
+ }
+
+ if (!peer_name) {
+ nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, "cannot find peer for veth device");
+ return FALSE;
+ }
+
+ con_peer_name = nm_setting_veth_get_peer(s_veth);
+ if (con_peer_name) {
+ nm_utils_error_set(error,
+ NM_UTILS_ERROR_UNKNOWN,
+ "mismatching veth peer \"%s\"",
+ con_peer_name);
+ return FALSE;
+ } else
+ g_object_set(s_veth, NM_SETTING_VETH_PEER, peer_name, NULL);
+
+ return TRUE;
+ }
+
s_pppoe = nm_connection_get_setting_pppoe(connection);
/* We can't telepathically figure out the service name or username, so if
diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c
index 0f08242c06..0fc76b1b86 100644
--- a/src/devices/nm-device-veth.c
+++ b/src/devices/nm-device-veth.c
@@ -121,34 +121,6 @@ get_generic_capabilities(NMDevice *device)
return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE;
}
-static gboolean
-complete_connection(NMDevice * device,
- NMConnection * connection,
- const char * specific_object,
- NMConnection *const *existing_connections,
- GError ** error)
-{
- NMSettingVeth *s_veth;
-
- nm_utils_complete_generic(nm_device_get_platform(device),
- connection,
- NM_SETTING_VETH_SETTING_NAME,
- existing_connections,
- NULL,
- _("Veth connection"),
- "veth",
- NULL,
- TRUE);
-
- s_veth = _nm_connection_get_setting(connection, NM_TYPE_SETTING_VETH);
- if (!s_veth) {
- s_veth = (NMSettingVeth *) nm_setting_veth_new();
- nm_connection_add_setting(connection, NM_SETTING(s_veth));
- }
-
- return TRUE;
-}
-
/*****************************************************************************/
static void
@@ -215,7 +187,6 @@ nm_device_veth_class_init(NMDeviceVethClass *klass)
device_class->link_changed = link_changed;
device_class->parent_changed_notify = parent_changed_notify;
device_class->create_and_realize = create_and_realize;
- device_class->complete_connection = complete_connection;
device_class->get_generic_capabilities = get_generic_capabilities;
obj_properties[PROP_PEER] = g_param_spec_string(NM_DEVICE_VETH_PEER,