mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-07 03:10:16 +01:00
platform: return NMPlatformError from link-add functions
Later remove nm_platform_get_error() and signal errors via return error codes. Also, fix nm_platform_infiniband_partition_add() and nm_platform_vlan_add() to check the type of the existing link and fail with WRONG_TYPE otherwise.
This commit is contained in:
parent
f7fb68755c
commit
d7fe907c32
13 changed files with 145 additions and 107 deletions
|
|
@ -571,16 +571,17 @@ create_virtual_device_for_connection (NMDeviceFactory *factory,
|
|||
GError **error)
|
||||
{
|
||||
const char *iface = nm_connection_get_interface_name (connection);
|
||||
NMPlatformError plerr;
|
||||
|
||||
g_assert (iface);
|
||||
|
||||
if ( !nm_platform_bond_add (NM_PLATFORM_GET, iface, NULL)
|
||||
&& nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) {
|
||||
plerr = nm_platform_bond_add (NM_PLATFORM_GET, iface, NULL);
|
||||
if (plerr != NM_PLATFORM_ERROR_SUCCESS && plerr != NM_PLATFORM_ERROR_EXISTS) {
|
||||
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
|
||||
"Failed to create bond interface '%s' for '%s': %s",
|
||||
iface,
|
||||
nm_connection_get_id (connection),
|
||||
nm_platform_get_error_msg (NM_PLATFORM_GET));
|
||||
nm_platform_error_to_string (plerr));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -498,6 +498,7 @@ create_virtual_device_for_connection (NMDeviceFactory *factory,
|
|||
NMSettingBridge *s_bridge;
|
||||
const char *mac_address_str;
|
||||
guint8 mac_address[NM_UTILS_HWADDR_LEN_MAX];
|
||||
NMPlatformError plerr;
|
||||
|
||||
g_assert (iface);
|
||||
|
||||
|
|
@ -510,17 +511,17 @@ create_virtual_device_for_connection (NMDeviceFactory *factory,
|
|||
mac_address_str = NULL;
|
||||
}
|
||||
|
||||
if ( !nm_platform_bridge_add (NM_PLATFORM_GET,
|
||||
plerr = nm_platform_bridge_add (NM_PLATFORM_GET,
|
||||
iface,
|
||||
mac_address_str ? mac_address : NULL,
|
||||
mac_address_str ? ETH_ALEN : 0,
|
||||
NULL)
|
||||
&& nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) {
|
||||
NULL);
|
||||
if (plerr != NM_PLATFORM_ERROR_SUCCESS && plerr != NM_PLATFORM_ERROR_EXISTS) {
|
||||
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
|
||||
"Failed to create bridge interface '%s' for '%s': %s",
|
||||
iface,
|
||||
nm_connection_get_id (connection),
|
||||
nm_platform_get_error_msg (NM_PLATFORM_GET));
|
||||
nm_platform_error_to_string (plerr));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -326,6 +326,7 @@ create_virtual_device_for_connection (NMDeviceFactory *factory,
|
|||
NMSettingInfiniband *s_infiniband;
|
||||
int p_key, parent_ifindex;
|
||||
const char *iface;
|
||||
NMPlatformError plerr;
|
||||
|
||||
if (!NM_IS_DEVICE_INFINIBAND (parent)) {
|
||||
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
|
||||
|
|
@ -342,13 +343,13 @@ create_virtual_device_for_connection (NMDeviceFactory *factory,
|
|||
parent_ifindex = nm_device_get_ifindex (parent);
|
||||
p_key = nm_setting_infiniband_get_p_key (s_infiniband);
|
||||
|
||||
if ( !nm_platform_infiniband_partition_add (NM_PLATFORM_GET, parent_ifindex, p_key, NULL)
|
||||
&& nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) {
|
||||
plerr = nm_platform_infiniband_partition_add (NM_PLATFORM_GET, parent_ifindex, p_key, NULL);
|
||||
if (plerr != NM_PLATFORM_ERROR_SUCCESS && plerr != NM_PLATFORM_ERROR_EXISTS) {
|
||||
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
|
||||
"Failed to create InfiniBand P_Key interface '%s' for '%s': %s",
|
||||
iface,
|
||||
nm_connection_get_id (connection),
|
||||
nm_platform_get_error_msg (NM_PLATFORM_GET));
|
||||
nm_platform_error_to_string (plerr));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -656,6 +656,7 @@ create_virtual_device_for_connection (NMDeviceFactory *factory,
|
|||
NMDevice *device;
|
||||
NMSettingVlan *s_vlan;
|
||||
gs_free char *iface = NULL;
|
||||
NMPlatformError plerr;
|
||||
|
||||
if (!NM_IS_DEVICE (parent)) {
|
||||
g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
|
||||
|
|
@ -672,18 +673,18 @@ create_virtual_device_for_connection (NMDeviceFactory *factory,
|
|||
nm_setting_vlan_get_id (s_vlan));
|
||||
}
|
||||
|
||||
if ( !nm_platform_vlan_add (NM_PLATFORM_GET,
|
||||
plerr = nm_platform_vlan_add (NM_PLATFORM_GET,
|
||||
iface,
|
||||
nm_device_get_ifindex (parent),
|
||||
nm_setting_vlan_get_id (s_vlan),
|
||||
nm_setting_vlan_get_flags (s_vlan),
|
||||
NULL)
|
||||
&& nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) {
|
||||
NULL);
|
||||
if (plerr != NM_PLATFORM_ERROR_SUCCESS && plerr != NM_PLATFORM_ERROR_EXISTS) {
|
||||
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
|
||||
"Failed to create VLAN interface '%s' for '%s': %s",
|
||||
iface,
|
||||
nm_connection_get_id (connection),
|
||||
nm_platform_get_error_msg (NM_PLATFORM_GET));
|
||||
nm_platform_error_to_string (plerr));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -689,16 +689,17 @@ NMDevice *
|
|||
nm_device_team_new_for_connection (NMConnection *connection, GError **error)
|
||||
{
|
||||
const char *iface = nm_connection_get_interface_name (connection);
|
||||
NMPlatformError plerr;
|
||||
|
||||
g_assert (iface);
|
||||
|
||||
if ( !nm_platform_team_add (NM_PLATFORM_GET, iface, NULL)
|
||||
&& nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) {
|
||||
plerr = nm_platform_team_add (NM_PLATFORM_GET, iface, NULL);
|
||||
if (plerr != NM_PLATFORM_ERROR_SUCCESS && plerr != NM_PLATFORM_ERROR_EXISTS) {
|
||||
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
|
||||
"Failed to create team master interface '%s' for '%s': %s",
|
||||
iface,
|
||||
nm_connection_get_id (connection),
|
||||
nm_platform_get_error_msg (NM_PLATFORM_GET));
|
||||
nm_platform_error_to_string (plerr));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -573,6 +573,38 @@ nm_platform_link_get_by_address (NMPlatform *self,
|
|||
return !!klass->link_get_by_address (self, address, length, link);
|
||||
}
|
||||
|
||||
static NMPlatformError
|
||||
_link_add_check_existing (NMPlatform *self, const char *name, NMLinkType type, NMPlatformLink *out_link)
|
||||
{
|
||||
int ifindex;
|
||||
NMPlatformLink pllink;
|
||||
|
||||
ifindex = nm_platform_link_get_ifindex (self, name);
|
||||
if (ifindex > 0) {
|
||||
if (nm_platform_link_get (self, ifindex, &pllink)) {
|
||||
gboolean wrong_type;
|
||||
|
||||
wrong_type = type != NM_LINK_TYPE_NONE && pllink.type != type;
|
||||
debug ("link: skip adding link due to existing interface '%s' of type %s%s%s",
|
||||
name,
|
||||
nm_link_type_to_string (pllink.type),
|
||||
wrong_type ? ", expected " : "",
|
||||
wrong_type ? nm_link_type_to_string (type) : "");
|
||||
if (out_link)
|
||||
*out_link = pllink;
|
||||
if (wrong_type) {
|
||||
nm_platform_set_error (self, NM_PLATFORM_ERROR_WRONG_TYPE);
|
||||
return NM_PLATFORM_ERROR_WRONG_TYPE;
|
||||
}
|
||||
nm_platform_set_error (self, NM_PLATFORM_ERROR_EXISTS);
|
||||
return NM_PLATFORM_ERROR_EXISTS;
|
||||
}
|
||||
/* strange, nm_platform_link_get_ifindex() returned a valid ifindex, but nm_platform_link_get() failed.
|
||||
* This is unexpected... proceed with "SUCCESS". */
|
||||
}
|
||||
return NM_PLATFORM_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_platform_link_add:
|
||||
* @self: platform instance
|
||||
|
|
@ -583,12 +615,16 @@ nm_platform_link_get_by_address (NMPlatform *self,
|
|||
* @out_link: on success, the link object
|
||||
*
|
||||
* Add a software interface. If the interface already exists and is of type
|
||||
* @type, sets platform->error to NM_PLATFORM_ERROR_EXISTS and returns the link
|
||||
* @type, return NM_PLATFORM_ERROR_EXISTS and returns the link
|
||||
* in @out_link. If the interface already exists and is not of type @type,
|
||||
* sets platform->error to NM_PLATFORM_ERROR_WRONG_TYPE. Any link-changed ADDED
|
||||
* signal will be emitted directly, before this function finishes.
|
||||
* return NM_PLATFORM_ERROR_WRONG_TYPE.
|
||||
*
|
||||
* Any link-changed ADDED signal will be emitted directly, before this
|
||||
* function finishes.
|
||||
*
|
||||
* Returns: the error reason or NM_PLATFORM_ERROR_SUCCESS.
|
||||
*/
|
||||
static gboolean
|
||||
static NMPlatformError
|
||||
nm_platform_link_add (NMPlatform *self,
|
||||
const char *name,
|
||||
NMLinkType type,
|
||||
|
|
@ -596,29 +632,27 @@ nm_platform_link_add (NMPlatform *self,
|
|||
size_t address_len,
|
||||
NMPlatformLink *out_link)
|
||||
{
|
||||
int ifindex;
|
||||
NMPlatformError plerr;
|
||||
|
||||
_CHECK_SELF (self, klass, FALSE);
|
||||
_CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
|
||||
reset_error (self);
|
||||
|
||||
g_return_val_if_fail (name, FALSE);
|
||||
g_return_val_if_fail (klass->link_add, FALSE);
|
||||
g_return_val_if_fail ( (address != NULL) ^ (address_len == 0) , FALSE);
|
||||
g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
|
||||
g_return_val_if_fail (klass->link_add, NM_PLATFORM_ERROR_BUG);
|
||||
g_return_val_if_fail ( (address != NULL) ^ (address_len == 0) , NM_PLATFORM_ERROR_BUG);
|
||||
|
||||
ifindex = nm_platform_link_get_ifindex (self, name);
|
||||
if (ifindex > 0) {
|
||||
debug ("link: already exists");
|
||||
if (nm_platform_link_get_type (self, ifindex) != type)
|
||||
self->error = NM_PLATFORM_ERROR_WRONG_TYPE;
|
||||
else {
|
||||
self->error = NM_PLATFORM_ERROR_EXISTS;
|
||||
(void) nm_platform_link_get (self, ifindex, out_link);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
plerr = _link_add_check_existing (self, name, type, out_link);
|
||||
if (plerr != NM_PLATFORM_ERROR_SUCCESS)
|
||||
return plerr;
|
||||
|
||||
debug ("link: adding %s '%s'", nm_link_type_to_string (type), name);
|
||||
reset_error(self);
|
||||
return klass->link_add (self, name, type, address, address_len, out_link);
|
||||
if (!klass->link_add (self, name, type, address, address_len, out_link)) {
|
||||
nm_platform_set_error (self, NM_PLATFORM_ERROR_UNSPECIFIED);
|
||||
return NM_PLATFORM_ERROR_UNSPECIFIED;
|
||||
}
|
||||
reset_error (self);
|
||||
return NM_PLATFORM_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -629,12 +663,9 @@ nm_platform_link_add (NMPlatform *self,
|
|||
*
|
||||
* Create a software ethernet-like interface
|
||||
*/
|
||||
gboolean
|
||||
NMPlatformError
|
||||
nm_platform_dummy_add (NMPlatform *self, const char *name, NMPlatformLink *out_link)
|
||||
{
|
||||
g_return_val_if_fail (name, FALSE);
|
||||
|
||||
debug ("link: adding dummy '%s'", name);
|
||||
return nm_platform_link_add (self, name, NM_LINK_TYPE_DUMMY, NULL, 0, out_link);
|
||||
}
|
||||
|
||||
|
|
@ -1416,14 +1447,13 @@ nm_platform_link_get_master (NMPlatform *self, int slave)
|
|||
*
|
||||
* Create a software bridge.
|
||||
*/
|
||||
gboolean
|
||||
NMPlatformError
|
||||
nm_platform_bridge_add (NMPlatform *self,
|
||||
const char *name,
|
||||
const void *address,
|
||||
size_t address_len,
|
||||
NMPlatformLink *out_link)
|
||||
{
|
||||
debug ("link: adding bridge '%s'", name);
|
||||
return nm_platform_link_add (self, name, NM_LINK_TYPE_BRIDGE, address, address_len, out_link);
|
||||
}
|
||||
|
||||
|
|
@ -1435,10 +1465,9 @@ nm_platform_bridge_add (NMPlatform *self,
|
|||
*
|
||||
* Create a software bonding device.
|
||||
*/
|
||||
gboolean
|
||||
NMPlatformError
|
||||
nm_platform_bond_add (NMPlatform *self, const char *name, NMPlatformLink *out_link)
|
||||
{
|
||||
debug ("link: adding bond '%s'", name);
|
||||
return nm_platform_link_add (self, name, NM_LINK_TYPE_BOND, NULL, 0, out_link);
|
||||
}
|
||||
|
||||
|
|
@ -1450,10 +1479,9 @@ nm_platform_bond_add (NMPlatform *self, const char *name, NMPlatformLink *out_li
|
|||
*
|
||||
* Create a software teaming device.
|
||||
*/
|
||||
gboolean
|
||||
NMPlatformError
|
||||
nm_platform_team_add (NMPlatform *self, const char *name, NMPlatformLink *out_link)
|
||||
{
|
||||
debug ("link: adding team '%s'", name);
|
||||
return nm_platform_link_add (self, name, NM_LINK_TYPE_TEAM, NULL, 0, out_link);
|
||||
}
|
||||
|
||||
|
|
@ -1467,7 +1495,7 @@ nm_platform_team_add (NMPlatform *self, const char *name, NMPlatformLink *out_li
|
|||
*
|
||||
* Create a software VLAN device.
|
||||
*/
|
||||
gboolean
|
||||
NMPlatformError
|
||||
nm_platform_vlan_add (NMPlatform *self,
|
||||
const char *name,
|
||||
int parent,
|
||||
|
|
@ -1475,23 +1503,25 @@ nm_platform_vlan_add (NMPlatform *self,
|
|||
guint32 vlanflags,
|
||||
NMPlatformLink *out_link)
|
||||
{
|
||||
_CHECK_SELF (self, klass, FALSE);
|
||||
NMPlatformError plerr;
|
||||
|
||||
_CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
|
||||
reset_error (self);
|
||||
|
||||
g_return_val_if_fail (parent >= 0, FALSE);
|
||||
g_return_val_if_fail (vlanid >= 0, FALSE);
|
||||
g_return_val_if_fail (name, FALSE);
|
||||
g_return_val_if_fail (klass->vlan_add, FALSE);
|
||||
g_return_val_if_fail (parent >= 0, NM_PLATFORM_ERROR_BUG);
|
||||
g_return_val_if_fail (vlanid >= 0, NM_PLATFORM_ERROR_BUG);
|
||||
g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
|
||||
g_return_val_if_fail (klass->vlan_add, NM_PLATFORM_ERROR_BUG);
|
||||
|
||||
if (nm_platform_link_exists (self, name)) {
|
||||
debug ("link already exists: %s", name);
|
||||
self->error = NM_PLATFORM_ERROR_EXISTS;
|
||||
return FALSE;
|
||||
}
|
||||
plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_VLAN, out_link);
|
||||
if (plerr != NM_PLATFORM_ERROR_SUCCESS)
|
||||
return plerr;
|
||||
|
||||
debug ("link: adding vlan '%s' parent %d vlanid %d vlanflags %x",
|
||||
name, parent, vlanid, vlanflags);
|
||||
return klass->vlan_add (self, name, parent, vlanid, vlanflags, out_link);
|
||||
name, parent, vlanid, vlanflags);
|
||||
if (!klass->vlan_add (self, name, parent, vlanid, vlanflags, out_link))
|
||||
return NM_PLATFORM_ERROR_UNSPECIFIED;
|
||||
return NM_PLATFORM_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
|
@ -1591,35 +1621,37 @@ nm_platform_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, int to
|
|||
return klass->vlan_set_egress_map (self, ifindex, from, to);
|
||||
}
|
||||
|
||||
gboolean
|
||||
NMPlatformError
|
||||
nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key, NMPlatformLink *out_link)
|
||||
{
|
||||
const char *parent_name;
|
||||
char *name;
|
||||
gs_free char *parent_name = NULL;
|
||||
gs_free char *name = NULL;
|
||||
NMPlatformError plerr;
|
||||
|
||||
_CHECK_SELF (self, klass, FALSE);
|
||||
_CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
|
||||
reset_error (self);
|
||||
|
||||
g_return_val_if_fail (parent >= 0, FALSE);
|
||||
g_return_val_if_fail (p_key >= 0, FALSE);
|
||||
g_return_val_if_fail (klass->infiniband_partition_add, FALSE);
|
||||
g_return_val_if_fail (parent >= 0, NM_PLATFORM_ERROR_BUG);
|
||||
g_return_val_if_fail (p_key >= 0, NM_PLATFORM_ERROR_BUG);
|
||||
g_return_val_if_fail (klass->infiniband_partition_add, NM_PLATFORM_ERROR_BUG);
|
||||
|
||||
if (nm_platform_link_get_type (self, parent) != NM_LINK_TYPE_INFINIBAND) {
|
||||
parent_name = g_strdup (nm_platform_link_get_name (self, parent));
|
||||
if ( !parent_name
|
||||
|| nm_platform_link_get_type (self, parent) != NM_LINK_TYPE_INFINIBAND) {
|
||||
self->error = NM_PLATFORM_ERROR_WRONG_TYPE;
|
||||
return FALSE;
|
||||
return NM_PLATFORM_ERROR_WRONG_TYPE;
|
||||
}
|
||||
|
||||
parent_name = nm_platform_link_get_name (self, parent);
|
||||
name = g_strdup_printf ("%s.%04x", parent_name, p_key);
|
||||
if (nm_platform_link_exists (self, name)) {
|
||||
debug ("infiniband: already exists");
|
||||
self->error = NM_PLATFORM_ERROR_EXISTS;
|
||||
g_free (name);
|
||||
return FALSE;
|
||||
}
|
||||
g_free (name);
|
||||
plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_INFINIBAND, out_link);
|
||||
if (plerr != NM_PLATFORM_ERROR_SUCCESS)
|
||||
return plerr;
|
||||
|
||||
return klass->infiniband_partition_add (self, parent, p_key, out_link);
|
||||
debug ("link: adding infiniband partition %s for parent '%s' (%d), key %d",
|
||||
name, parent_name, parent, p_key);
|
||||
if (!klass->infiniband_partition_add (self, parent, p_key, out_link))
|
||||
return NM_PLATFORM_ERROR_UNSPECIFIED;
|
||||
return NM_PLATFORM_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
|
|
|||
|
|
@ -604,10 +604,10 @@ gboolean nm_platform_sysctl_set_ip6_hop_limit_safe (NMPlatform *self, const char
|
|||
gboolean nm_platform_link_get (NMPlatform *self, int ifindex, NMPlatformLink *link);
|
||||
GArray *nm_platform_link_get_all (NMPlatform *self);
|
||||
gboolean nm_platform_link_get_by_address (NMPlatform *self, gconstpointer address, size_t length, NMPlatformLink *link);
|
||||
gboolean nm_platform_dummy_add (NMPlatform *self, const char *name, NMPlatformLink *out_link);
|
||||
gboolean nm_platform_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, NMPlatformLink *out_link);
|
||||
gboolean nm_platform_bond_add (NMPlatform *self, const char *name, NMPlatformLink *out_link);
|
||||
gboolean nm_platform_team_add (NMPlatform *self, const char *name, NMPlatformLink *out_link);
|
||||
NMPlatformError nm_platform_dummy_add (NMPlatform *self, const char *name, NMPlatformLink *out_link);
|
||||
NMPlatformError nm_platform_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, NMPlatformLink *out_link);
|
||||
NMPlatformError nm_platform_bond_add (NMPlatform *self, const char *name, NMPlatformLink *out_link);
|
||||
NMPlatformError nm_platform_team_add (NMPlatform *self, const char *name, NMPlatformLink *out_link);
|
||||
gboolean nm_platform_link_exists (NMPlatform *self, const char *name);
|
||||
gboolean nm_platform_link_delete (NMPlatform *self, int ifindex);
|
||||
int nm_platform_link_get_ifindex (NMPlatform *self, const char *name);
|
||||
|
|
@ -662,12 +662,12 @@ char *nm_platform_master_get_option (NMPlatform *self, int ifindex, const char *
|
|||
gboolean nm_platform_slave_set_option (NMPlatform *self, int ifindex, const char *option, const char *value);
|
||||
char *nm_platform_slave_get_option (NMPlatform *self, int ifindex, const char *option);
|
||||
|
||||
gboolean nm_platform_vlan_add (NMPlatform *self, const char *name, int parent, int vlanid, guint32 vlanflags, NMPlatformLink *out_link);
|
||||
NMPlatformError nm_platform_vlan_add (NMPlatform *self, const char *name, int parent, int vlanid, guint32 vlanflags, NMPlatformLink *out_link);
|
||||
gboolean nm_platform_vlan_get_info (NMPlatform *self, int ifindex, int *parent, int *vlanid);
|
||||
gboolean nm_platform_vlan_set_ingress_map (NMPlatform *self, int ifindex, int from, int to);
|
||||
gboolean nm_platform_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, int to);
|
||||
|
||||
gboolean nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key, NMPlatformLink *out_link);
|
||||
NMPlatformError nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key, NMPlatformLink *out_link);
|
||||
gboolean nm_platform_infiniband_get_info (NMPlatform *self, int ifindex, int *parent, int *p_key, const char **mode);
|
||||
|
||||
gboolean nm_platform_veth_get_properties (NMPlatform *self, int ifindex, NMPlatformVethProperties *properties);
|
||||
|
|
|
|||
|
|
@ -93,25 +93,25 @@ do_link_get_all (char **argv)
|
|||
static gboolean
|
||||
do_dummy_add (char **argv)
|
||||
{
|
||||
return nm_platform_dummy_add (NM_PLATFORM_GET, argv[0], NULL);
|
||||
return nm_platform_dummy_add (NM_PLATFORM_GET, argv[0], NULL) == NM_PLATFORM_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
do_bridge_add (char **argv)
|
||||
{
|
||||
return nm_platform_bridge_add (NM_PLATFORM_GET, argv[0], NULL, 0, NULL);
|
||||
return nm_platform_bridge_add (NM_PLATFORM_GET, argv[0], NULL, 0, NULL) == NM_PLATFORM_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
do_bond_add (char **argv)
|
||||
{
|
||||
return nm_platform_bond_add (NM_PLATFORM_GET, argv[0], NULL);
|
||||
return nm_platform_bond_add (NM_PLATFORM_GET, argv[0], NULL) == NM_PLATFORM_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
do_team_add (char **argv)
|
||||
{
|
||||
return nm_platform_team_add (NM_PLATFORM_GET, argv[0], NULL);
|
||||
return nm_platform_team_add (NM_PLATFORM_GET, argv[0], NULL) == NM_PLATFORM_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -122,7 +122,7 @@ do_vlan_add (char **argv)
|
|||
int vlanid = strtol (*argv++, NULL, 10);
|
||||
guint32 vlan_flags = strtol (*argv++, NULL, 10);
|
||||
|
||||
return nm_platform_vlan_add (NM_PLATFORM_GET, name, parent, vlanid, vlan_flags, NULL);
|
||||
return nm_platform_vlan_add (NM_PLATFORM_GET, name, parent, vlanid, vlan_flags, NULL) == NM_PLATFORM_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ setup_tests (void)
|
|||
|
||||
nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME));
|
||||
g_assert (!nm_platform_link_exists (NM_PLATFORM_GET, DEVICE_NAME));
|
||||
g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL));
|
||||
g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == NM_PLATFORM_ERROR_SUCCESS);
|
||||
accept_signal (link_added);
|
||||
free_signal (link_added);
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ test_cleanup_internal (void)
|
|||
inet_pton (AF_INET6, "2001:db8:e:f:1:2:3:4", &gateway6);
|
||||
|
||||
/* Create and set up device */
|
||||
g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL));
|
||||
g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == NM_PLATFORM_ERROR_SUCCESS);
|
||||
accept_signal (link_added);
|
||||
free_signal (link_added);
|
||||
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME)));
|
||||
|
|
|
|||
|
|
@ -85,36 +85,37 @@ test_loopback (void)
|
|||
g_assert (!nm_platform_link_supports_vlans (NM_PLATFORM_GET, LO_INDEX));
|
||||
}
|
||||
|
||||
static int
|
||||
static gboolean
|
||||
software_add (NMLinkType link_type, const char *name)
|
||||
{
|
||||
switch (link_type) {
|
||||
case NM_LINK_TYPE_DUMMY:
|
||||
return nm_platform_dummy_add (NM_PLATFORM_GET, name, NULL);
|
||||
return nm_platform_dummy_add (NM_PLATFORM_GET, name, NULL) == NM_PLATFORM_ERROR_SUCCESS;
|
||||
case NM_LINK_TYPE_BRIDGE:
|
||||
return nm_platform_bridge_add (NM_PLATFORM_GET, name, NULL, 0, NULL);
|
||||
return nm_platform_bridge_add (NM_PLATFORM_GET, name, NULL, 0, NULL) == NM_PLATFORM_ERROR_SUCCESS;
|
||||
case NM_LINK_TYPE_BOND:
|
||||
{
|
||||
gboolean bond0_exists = nm_platform_link_exists (NM_PLATFORM_GET, "bond0");
|
||||
gboolean result = nm_platform_bond_add (NM_PLATFORM_GET, name, NULL);
|
||||
NMPlatformError error = nm_platform_get_error (NM_PLATFORM_GET);
|
||||
NMPlatformError plerr;
|
||||
|
||||
plerr = nm_platform_bond_add (NM_PLATFORM_GET, name, NULL);
|
||||
|
||||
/* Check that bond0 is *not* automatically created. */
|
||||
if (!bond0_exists)
|
||||
g_assert (!nm_platform_link_exists (NM_PLATFORM_GET, "bond0"));
|
||||
|
||||
nm_platform_set_error (NM_PLATFORM_GET, error);
|
||||
return result;
|
||||
nm_platform_set_error (NM_PLATFORM_GET, plerr);
|
||||
return plerr == NM_PLATFORM_ERROR_SUCCESS;
|
||||
}
|
||||
case NM_LINK_TYPE_TEAM:
|
||||
return nm_platform_team_add (NM_PLATFORM_GET, name, NULL);
|
||||
return nm_platform_team_add (NM_PLATFORM_GET, name, NULL) == NM_PLATFORM_ERROR_SUCCESS;
|
||||
case NM_LINK_TYPE_VLAN: {
|
||||
SignalData *parent_added;
|
||||
SignalData *parent_changed;
|
||||
|
||||
/* Don't call link_callback for the bridge interface */
|
||||
parent_added = add_signal_ifname (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_ADDED, link_callback, PARENT_NAME);
|
||||
if (nm_platform_bridge_add (NM_PLATFORM_GET, PARENT_NAME, NULL, 0, NULL))
|
||||
if (nm_platform_bridge_add (NM_PLATFORM_GET, PARENT_NAME, NULL, 0, NULL) == NM_PLATFORM_ERROR_SUCCESS)
|
||||
accept_signal (parent_added);
|
||||
free_signal (parent_added);
|
||||
|
||||
|
|
@ -131,7 +132,7 @@ software_add (NMLinkType link_type, const char *name)
|
|||
accept_signal (parent_changed);
|
||||
free_signal (parent_changed);
|
||||
|
||||
return nm_platform_vlan_add (NM_PLATFORM_GET, name, parent_ifindex, VLAN_ID, 0, NULL);
|
||||
return nm_platform_vlan_add (NM_PLATFORM_GET, name, parent_ifindex, VLAN_ID, 0, NULL) == NM_PLATFORM_ERROR_SUCCESS;
|
||||
}
|
||||
}
|
||||
default:
|
||||
|
|
@ -440,12 +441,12 @@ test_internal (void)
|
|||
error (NM_PLATFORM_ERROR_NOT_FOUND);
|
||||
|
||||
/* Add device */
|
||||
g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL));
|
||||
g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == NM_PLATFORM_ERROR_SUCCESS);
|
||||
no_error ();
|
||||
accept_signal (link_added);
|
||||
|
||||
/* Try to add again */
|
||||
g_assert (!nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL));
|
||||
g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == NM_PLATFORM_ERROR_EXISTS);
|
||||
error (NM_PLATFORM_ERROR_EXISTS);
|
||||
|
||||
/* Check device index, name and type */
|
||||
|
|
|
|||
|
|
@ -323,7 +323,7 @@ setup_tests (void)
|
|||
|
||||
nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME));
|
||||
g_assert (!nm_platform_link_exists (NM_PLATFORM_GET, DEVICE_NAME));
|
||||
g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL));
|
||||
g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == NM_PLATFORM_ERROR_SUCCESS);
|
||||
accept_signal (link_added);
|
||||
free_signal (link_added);
|
||||
|
||||
|
|
|
|||
|
|
@ -648,7 +648,7 @@ fixture_setup (test_fixture *fixture, gconstpointer user_data)
|
|||
"nm-test-device0");
|
||||
nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, "nm-test-device0"));
|
||||
g_assert (!nm_platform_link_exists (NM_PLATFORM_GET, "nm-test-device0"));
|
||||
g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, "nm-test-device0", NULL));
|
||||
g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, "nm-test-device0", NULL) == NM_PLATFORM_ERROR_SUCCESS);
|
||||
accept_signal (link_added);
|
||||
free_signal (link_added);
|
||||
fixture->ifindex0 = nm_platform_link_get_ifindex (NM_PLATFORM_GET, "nm-test-device0");
|
||||
|
|
@ -660,7 +660,7 @@ fixture_setup (test_fixture *fixture, gconstpointer user_data)
|
|||
"nm-test-device1");
|
||||
nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, "nm-test-device1"));
|
||||
g_assert (!nm_platform_link_exists (NM_PLATFORM_GET, "nm-test-device1"));
|
||||
g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, "nm-test-device1", NULL));
|
||||
g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, "nm-test-device1", NULL) == NM_PLATFORM_ERROR_SUCCESS);
|
||||
accept_signal (link_added);
|
||||
free_signal (link_added);
|
||||
fixture->ifindex1 = nm_platform_link_get_ifindex (NM_PLATFORM_GET, "nm-test-device1");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue