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: cd0cf9229d ('veth: add support to configure veth interfaces')
This commit is contained in:
Thomas Haller 2021-01-14 14:03:36 +01:00
parent bcb63affdd
commit 7c05ff1632
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 54 additions and 29 deletions

View file

@ -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

View file

@ -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,