Commit d18f4032 authored by Thomas Haller's avatar Thomas Haller

platform: merge NMPlatformError with nm-error

Platform had it's own scheme for reporting errors: NMPlatformError.
Before, NMPlatformError indicated success via zero, negative integer
values are numbers from <errno.h>, and positive integer values are
platform specific codes. This changes now according to nm-error:
success is still zero. Negative values indicate a failure, where the
numeric value is either from <errno.h> or one of our error codes.
The meaning of positive values depends on the functions. Most functions
can only report an error reason (negative) and success (zero). For such
functions, positive values should never be returned (but the caller
should anticipate them).
For some functions, positive values could mean additional information
(but still success). That depends.

This is also what systemd does, except that systemd only returns
(negative) integers from <errno.h>, while we merge our own error codes
into the range of <errno.h>.

The advantage is to get rid of one way how to signal errors. The other
advantage is, that these error codes are compatible with all other
nm-errno values. For example, previously negative values indicated error
codes from <errno.h>, but it did not entail error codes from netlink.
parent 18732c34
......@@ -27,18 +27,27 @@
NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_geterror, int,
NM_UTILS_LOOKUP_DEFAULT (NULL),
NM_UTILS_LOOKUP_ITEM (NME_UNSPEC, "NME_UNSPEC"),
NM_UTILS_LOOKUP_ITEM (NME_BUG, "NME_BUG"),
NM_UTILS_LOOKUP_ITEM (NME_NATIVE_ERRNO, "NME_NATIVE_ERRNO"),
NM_UTILS_LOOKUP_ITEM (NME_NL_ATTRSIZE, "NME_NL_ATTRSIZE"),
NM_UTILS_LOOKUP_ITEM (NME_NL_BAD_SOCK, "NME_NL_BAD_SOCK"),
NM_UTILS_LOOKUP_ITEM (NME_NL_DUMP_INTR, "NME_NL_DUMP_INTR"),
NM_UTILS_LOOKUP_ITEM (NME_NL_MSG_OVERFLOW, "NME_NL_MSG_OVERFLOW"),
NM_UTILS_LOOKUP_ITEM (NME_NL_MSG_TOOSHORT, "NME_NL_MSG_TOOSHORT"),
NM_UTILS_LOOKUP_ITEM (NME_NL_MSG_TRUNC, "NME_NL_MSG_TRUNC"),
NM_UTILS_LOOKUP_ITEM (NME_NL_SEQ_MISMATCH, "NME_NL_SEQ_MISMATCH"),
)
NM_UTILS_LOOKUP_STR_ITEM (NME_UNSPEC, "NME_UNSPEC"),
NM_UTILS_LOOKUP_STR_ITEM (NME_BUG, "NME_BUG"),
NM_UTILS_LOOKUP_STR_ITEM (NME_NATIVE_ERRNO, "NME_NATIVE_ERRNO"),
NM_UTILS_LOOKUP_STR_ITEM (NME_NL_ATTRSIZE, "NME_NL_ATTRSIZE"),
NM_UTILS_LOOKUP_STR_ITEM (NME_NL_BAD_SOCK, "NME_NL_BAD_SOCK"),
NM_UTILS_LOOKUP_STR_ITEM (NME_NL_DUMP_INTR, "NME_NL_DUMP_INTR"),
NM_UTILS_LOOKUP_STR_ITEM (NME_NL_MSG_OVERFLOW, "NME_NL_MSG_OVERFLOW"),
NM_UTILS_LOOKUP_STR_ITEM (NME_NL_MSG_TOOSHORT, "NME_NL_MSG_TOOSHORT"),
NM_UTILS_LOOKUP_STR_ITEM (NME_NL_MSG_TRUNC, "NME_NL_MSG_TRUNC"),
NM_UTILS_LOOKUP_STR_ITEM (NME_NL_SEQ_MISMATCH, "NME_NL_SEQ_MISMATCH"),
NM_UTILS_LOOKUP_STR_ITEM (NME_PL_NOT_FOUND, "not-found"),
NM_UTILS_LOOKUP_STR_ITEM (NME_PL_EXISTS, "exists"),
NM_UTILS_LOOKUP_STR_ITEM (NME_PL_WRONG_TYPE, "wrong-type"),
NM_UTILS_LOOKUP_STR_ITEM (NME_PL_NOT_SLAVE, "not-slave"),
NM_UTILS_LOOKUP_STR_ITEM (NME_PL_NO_FIRMWARE, "no-firmware"),
NM_UTILS_LOOKUP_STR_ITEM (NME_PL_OPNOTSUPP, "not-supported"),
NM_UTILS_LOOKUP_STR_ITEM (NME_PL_NETLINK, "netlink"),
NM_UTILS_LOOKUP_STR_ITEM (NME_PL_CANT_SET_MTU, "cant-set-mtu"),
);
const char *
nm_strerror (int nmerr)
......
......@@ -26,12 +26,23 @@
/*****************************************************************************/
enum {
_NM_ERRNO_MININT = G_MININT,
_NM_ERRNO_MAXINT = G_MAXINT,
_NM_ERRNO_RESERVED_FIRST = 100000,
/* an unspecified error. */
NME_UNSPEC = _NM_ERRNO_RESERVED_FIRST,
/* A bug, for example when an assertion failed.
* Should never happen. */
NME_BUG,
/* a native error number (from <errno.h>) cannot be mapped as
* an nm-error, because it is in the range [_NM_ERRNO_RESERVED_FIRST,
* _NM_ERRNO_RESERVED_LAST]. */
NME_NATIVE_ERRNO,
/* netlink errors. */
NME_NL_SEQ_MISMATCH,
NME_NL_MSG_TRUNC,
NME_NL_MSG_TOOSHORT,
......@@ -41,6 +52,16 @@ enum {
NME_NL_NOADDR,
NME_NL_MSG_OVERFLOW,
/* platform errors. */
NME_PL_NOT_FOUND,
NME_PL_EXISTS,
NME_PL_WRONG_TYPE,
NME_PL_NOT_SLAVE,
NME_PL_NO_FIRMWARE,
NME_PL_OPNOTSUPP,
NME_PL_NETLINK,
NME_PL_CANT_SET_MTU,
_NM_ERRNO_RESERVED_LAST_PLUS_1,
_NM_ERRNO_RESERVED_LAST = _NM_ERRNO_RESERVED_LAST_PLUS_1 - 1,
};
......
......@@ -196,6 +196,25 @@
/*****************************************************************************/
/* Our nm-error error numbers use negative values to signal failure.
* A non-negative value signals success. Hence, the correct way for checking
* is always (r < 0) vs. (r >= 0). Never (r == 0).
*
* For assertions in tests, we also want to assert that no positive values
* are returned. For a lot of functions, positive return values are unexpected
* and a bug. This macro evaluates @r to success or failure, while asserting
* that @r is not positive. */
#define NMTST_NM_ERR_SUCCESS(r) \
({ \
const int _r = (r); \
\
if (_r >= 0) \
g_assert_cmpint (_r, ==, 0); \
(_r >= 0); \
})
/*****************************************************************************/
struct __nmtst_internal
{
GRand *rand0;
......
......@@ -110,9 +110,9 @@ create_and_realize (NMDevice *device,
GError **error)
{
const char *iface = nm_device_get_iface (device);
NMPlatformError plerr;
NMSetting6Lowpan *s_6lowpan;
int parent_ifindex;
int r;
s_6lowpan = NM_SETTING_6LOWPAN (nm_connection_get_setting (connection, NM_TYPE_SETTING_6LOWPAN));
g_return_val_if_fail (s_6lowpan, FALSE);
......@@ -126,13 +126,13 @@ create_and_realize (NMDevice *device,
return FALSE;
}
plerr = nm_platform_link_6lowpan_add (nm_device_get_platform (device), iface, parent_ifindex, out_plink);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
r = nm_platform_link_6lowpan_add (nm_device_get_platform (device), iface, parent_ifindex, out_plink);
if (r < 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
"Failed to create 6lowpan interface '%s' for '%s': %s",
iface,
nm_connection_get_id (connection),
nm_platform_error_to_string_a (plerr));
nm_strerror (r));
return FALSE;
}
......
......@@ -459,17 +459,17 @@ create_and_realize (NMDevice *device,
GError **error)
{
const char *iface = nm_device_get_iface (device);
NMPlatformError plerr;
int r;
g_assert (iface);
plerr = nm_platform_link_bond_add (nm_device_get_platform (device), iface, out_plink);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
r = nm_platform_link_bond_add (nm_device_get_platform (device), iface, out_plink);
if (r < 0) {
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_error_to_string_a (plerr));
nm_strerror (r));
return FALSE;
}
return TRUE;
......
......@@ -459,7 +459,7 @@ create_and_realize (NMDevice *device,
const char *hwaddr;
gs_free char *hwaddr_cloned = NULL;
guint8 mac_address[NM_UTILS_HWADDR_LEN_MAX];
NMPlatformError plerr;
int r;
nm_assert (iface);
......@@ -486,17 +486,17 @@ create_and_realize (NMDevice *device,
}
}
plerr = nm_platform_link_bridge_add (nm_device_get_platform (device),
iface,
hwaddr ? mac_address : NULL,
hwaddr ? ETH_ALEN : 0,
out_plink);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
r = nm_platform_link_bridge_add (nm_device_get_platform (device),
iface,
hwaddr ? mac_address : NULL,
hwaddr ? ETH_ALEN : 0,
out_plink);
if (r < 0) {
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_error_to_string_a (plerr));
nm_strerror (r));
return FALSE;
}
......
......@@ -98,19 +98,19 @@ create_and_realize (NMDevice *device,
GError **error)
{
const char *iface = nm_device_get_iface (device);
NMPlatformError plerr;
NMSettingDummy *s_dummy;
int r;
s_dummy = nm_connection_get_setting_dummy (connection);
g_assert (s_dummy);
plerr = nm_platform_link_dummy_add (nm_device_get_platform (device), iface, out_plink);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
r = nm_platform_link_dummy_add (nm_device_get_platform (device), iface, out_plink);
if (r < 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
"Failed to create dummy interface '%s' for '%s': %s",
iface,
nm_connection_get_id (connection),
nm_platform_error_to_string_a (plerr));
nm_strerror (r));
return FALSE;
}
......
......@@ -235,7 +235,7 @@ create_and_realize (NMDevice *device,
{
NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE ((NMDeviceInfiniband *) device);
NMSettingInfiniband *s_infiniband;
NMPlatformError plerr;
int r;
s_infiniband = nm_connection_get_setting_infiniband (connection);
g_assert (s_infiniband);
......@@ -269,13 +269,13 @@ create_and_realize (NMDevice *device,
return FALSE;
}
plerr = nm_platform_link_infiniband_add (nm_device_get_platform (device), priv->parent_ifindex, priv->p_key, out_plink);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
r = nm_platform_link_infiniband_add (nm_device_get_platform (device), priv->parent_ifindex, priv->p_key, out_plink);
if (r < 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
"Failed to create InfiniBand P_Key interface '%s' for '%s': %s",
nm_device_get_iface (device),
nm_connection_get_id (connection),
nm_platform_error_to_string_a (plerr));
nm_strerror (r));
return FALSE;
}
......@@ -287,7 +287,7 @@ static gboolean
unrealize (NMDevice *device, GError **error)
{
NMDeviceInfinibandPrivate *priv;
NMPlatformError plerr;
int r;
g_return_val_if_fail (NM_IS_DEVICE_INFINIBAND (device), FALSE);
......@@ -299,12 +299,12 @@ unrealize (NMDevice *device, GError **error)
return FALSE;
}
plerr = nm_platform_link_infiniband_delete (nm_device_get_platform (device), priv->parent_ifindex, priv->p_key);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
r = nm_platform_link_infiniband_delete (nm_device_get_platform (device), priv->parent_ifindex, priv->p_key);
if (r < 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
"Failed to remove InfiniBand P_Key interface '%s': %s",
nm_device_get_iface (device),
nm_platform_error_to_string_a (plerr));
nm_strerror (r));
return FALSE;
}
......
......@@ -660,7 +660,6 @@ create_and_realize (NMDevice *device,
{
const char *iface = nm_device_get_iface (device);
NMSettingIPTunnel *s_ip_tunnel;
NMPlatformError plerr;
NMPlatformLnkGre lnk_gre = { };
NMPlatformLnkSit lnk_sit = { };
NMPlatformLnkIpIp lnk_ipip = { };
......@@ -668,6 +667,7 @@ create_and_realize (NMDevice *device,
const char *str;
gint64 val;
NMIPTunnelMode mode;
int r;
s_ip_tunnel = nm_connection_get_setting_ip_tunnel (connection);
g_assert (s_ip_tunnel);
......@@ -713,13 +713,13 @@ create_and_realize (NMDevice *device,
lnk_gre.output_flags = NM_GRE_KEY;
}
plerr = nm_platform_link_gre_add (nm_device_get_platform (device), iface, &lnk_gre, out_plink);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
r = nm_platform_link_gre_add (nm_device_get_platform (device), iface, &lnk_gre, out_plink);
if (r < 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
"Failed to create GRE interface '%s' for '%s': %s",
iface,
nm_connection_get_id (connection),
nm_platform_error_to_string_a (plerr));
nm_strerror (r));
return FALSE;
}
break;
......@@ -739,13 +739,13 @@ create_and_realize (NMDevice *device,
lnk_sit.tos = nm_setting_ip_tunnel_get_tos (s_ip_tunnel);
lnk_sit.path_mtu_discovery = nm_setting_ip_tunnel_get_path_mtu_discovery (s_ip_tunnel);
plerr = nm_platform_link_sit_add (nm_device_get_platform (device), iface, &lnk_sit, out_plink);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
r = nm_platform_link_sit_add (nm_device_get_platform (device), iface, &lnk_sit, out_plink);
if (r < 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
"Failed to create SIT interface '%s' for '%s': %s",
iface,
nm_connection_get_id (connection),
nm_platform_error_to_string_a (plerr));
nm_strerror (r));
return FALSE;
}
break;
......@@ -765,13 +765,13 @@ create_and_realize (NMDevice *device,
lnk_ipip.tos = nm_setting_ip_tunnel_get_tos (s_ip_tunnel);
lnk_ipip.path_mtu_discovery = nm_setting_ip_tunnel_get_path_mtu_discovery (s_ip_tunnel);
plerr = nm_platform_link_ipip_add (nm_device_get_platform (device), iface, &lnk_ipip, out_plink);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
r = nm_platform_link_ipip_add (nm_device_get_platform (device), iface, &lnk_ipip, out_plink);
if (r < 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
"Failed to create IPIP interface '%s' for '%s': %s",
iface,
nm_connection_get_id (connection),
nm_platform_error_to_string_a (plerr));
nm_strerror (r));
return FALSE;
}
break;
......@@ -820,21 +820,21 @@ create_and_realize (NMDevice *device,
lnk_ip6tnl.is_gre = TRUE;
lnk_ip6tnl.is_tap = (mode == NM_IP_TUNNEL_MODE_IP6GRETAP);
plerr = nm_platform_link_ip6gre_add (nm_device_get_platform (device),
iface, &lnk_ip6tnl, out_plink);
r = nm_platform_link_ip6gre_add (nm_device_get_platform (device),
iface, &lnk_ip6tnl, out_plink);
} else {
lnk_ip6tnl.proto = nm_setting_ip_tunnel_get_mode (s_ip_tunnel) == NM_IP_TUNNEL_MODE_IPIP6
? IPPROTO_IPIP
: IPPROTO_IPV6;
plerr = nm_platform_link_ip6tnl_add (nm_device_get_platform (device),
iface, &lnk_ip6tnl, out_plink);
r = nm_platform_link_ip6tnl_add (nm_device_get_platform (device),
iface, &lnk_ip6tnl, out_plink);
}
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
if (r < 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
"Failed to create IPv6 tunnel interface '%s' for '%s': %s",
iface,
nm_connection_get_id (connection),
nm_platform_error_to_string_a (plerr));
nm_strerror (r));
return FALSE;
}
break;
......
......@@ -657,7 +657,6 @@ create_and_realize (NMDevice *device,
GError **error)
{
const char *iface = nm_device_get_iface (device);
NMPlatformError plerr;
NMSettingMacsec *s_macsec;
NMPlatformLnkMacsec lnk = { };
int parent_ifindex;
......@@ -669,6 +668,7 @@ create_and_realize (NMDevice *device,
} s;
guint64 u;
} sci;
int r;
s_macsec = nm_connection_get_setting_macsec (connection);
g_assert (s_macsec);
......@@ -697,13 +697,13 @@ create_and_realize (NMDevice *device,
parent_ifindex = nm_device_get_ifindex (parent);
g_warn_if_fail (parent_ifindex > 0);
plerr = nm_platform_link_macsec_add (nm_device_get_platform (device), iface, parent_ifindex, &lnk, out_plink);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
r = nm_platform_link_macsec_add (nm_device_get_platform (device), iface, parent_ifindex, &lnk, out_plink);
if (r < 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
"Failed to create macsec interface '%s' for '%s': %s",
iface,
nm_connection_get_id (connection),
nm_platform_error_to_string_a (plerr));
nm_strerror (r));
return FALSE;
}
......
......@@ -227,10 +227,10 @@ create_and_realize (NMDevice *device,
GError **error)
{
const char *iface = nm_device_get_iface (device);
NMPlatformError plerr;
NMSettingMacvlan *s_macvlan;
NMPlatformLnkMacvlan lnk = { };
int parent_ifindex;
int r;
s_macvlan = nm_connection_get_setting_macvlan (connection);
g_return_val_if_fail (s_macvlan, FALSE);
......@@ -255,14 +255,14 @@ create_and_realize (NMDevice *device,
lnk.no_promisc = !nm_setting_macvlan_get_promiscuous (s_macvlan);
lnk.tap = nm_setting_macvlan_get_tap (s_macvlan);
plerr = nm_platform_link_macvlan_add (nm_device_get_platform (device), iface, parent_ifindex, &lnk, out_plink);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
r = nm_platform_link_macvlan_add (nm_device_get_platform (device), iface, parent_ifindex, &lnk, out_plink);
if (r < 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
"Failed to create %s interface '%s' for '%s': %s",
lnk.tap ? "macvtap" : "macvlan",
iface,
nm_connection_get_id (connection),
nm_platform_error_to_string_a (plerr));
nm_strerror (r));
return FALSE;
}
......
......@@ -231,9 +231,10 @@ create_and_realize (NMDevice *device,
{
const char *iface = nm_device_get_iface (device);
NMPlatformLnkTun props = { };
NMPlatformError plerr;
NMSettingTun *s_tun;
gint64 owner, group;
gint64 owner;
gint64 group;
int r;
s_tun = nm_connection_get_setting_tun (connection);
g_return_val_if_fail (s_tun, FALSE);
......@@ -261,17 +262,17 @@ create_and_realize (NMDevice *device,
props.multi_queue = nm_setting_tun_get_multi_queue (s_tun);
props.persist = TRUE;
plerr = nm_platform_link_tun_add (nm_device_get_platform (device),
iface,
&props,
out_plink,
NULL);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
r = nm_platform_link_tun_add (nm_device_get_platform (device),
iface,
&props,
out_plink,
NULL);
if (r < 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
"Failed to create TUN/TAP interface '%s' for '%s': %s",
iface,
nm_connection_get_id (connection),
nm_platform_error_to_string_a (plerr));
nm_strerror (r));
return FALSE;
}
......
......@@ -241,7 +241,7 @@ create_and_realize (NMDevice *device,
NMSettingVlan *s_vlan;
int parent_ifindex;
guint vlan_id;
NMPlatformError plerr;
int r;
s_vlan = nm_connection_get_setting_vlan (connection);
g_assert (s_vlan);
......@@ -271,18 +271,18 @@ create_and_realize (NMDevice *device,
vlan_id = nm_setting_vlan_get_id (s_vlan);
plerr = nm_platform_link_vlan_add (nm_device_get_platform (device),
iface,
parent_ifindex,
vlan_id,
nm_setting_vlan_get_flags (s_vlan),
out_plink);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
r = nm_platform_link_vlan_add (nm_device_get_platform (device),
iface,
parent_ifindex,
vlan_id,
nm_setting_vlan_get_flags (s_vlan),
out_plink);
if (r < 0) {
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_error_to_string_a (plerr));
nm_strerror (r));
return FALSE;
}
......
......@@ -171,11 +171,11 @@ create_and_realize (NMDevice *device,
GError **error)
{
const char *iface = nm_device_get_iface (device);
NMPlatformError plerr;
NMPlatformLnkVxlan props = { };
NMSettingVxlan *s_vxlan;
const char *str;
int ret;
int r;
s_vxlan = nm_connection_get_setting_vxlan (connection);
g_assert (s_vxlan);
......@@ -214,13 +214,13 @@ create_and_realize (NMDevice *device,
props.l2miss = nm_setting_vxlan_get_l2_miss (s_vxlan);
props.l3miss = nm_setting_vxlan_get_l3_miss (s_vxlan);
plerr = nm_platform_link_vxlan_add (nm_device_get_platform (device), iface, &props, out_plink);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
r = nm_platform_link_vxlan_add (nm_device_get_platform (device), iface, &props, out_plink);
if (r < 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
"Failed to create VXLAN interface '%s' for '%s': %s",
iface,
nm_connection_get_id (connection),
nm_platform_error_to_string_a (plerr));
nm_strerror (r));
return FALSE;
}
......
......@@ -9143,7 +9143,10 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config)
}
if (mtu_desired && mtu_desired != mtu_plat) {
if (nm_platform_link_set_mtu (nm_device_get_platform (self), ifindex, mtu_desired) == NM_PLATFORM_ERROR_CANT_SET_MTU) {
int r;
r = nm_platform_link_set_mtu (nm_device_get_platform (self), ifindex, mtu_desired);
if (r == -NME_PL_CANT_SET_MTU) {
anticipated_failure = TRUE;
success = FALSE;
_LOGW (LOGD_DEVICE, "mtu: failure to set MTU. %s",
......@@ -9562,18 +9565,20 @@ set_nm_ipv6ll (NMDevice *self, gboolean enable)
priv->ipv6ll_handle = enable;
if (ifindex > 0) {
NMPlatformError plerr;
const char *detail = enable ? "enable" : "disable";
int r;
_LOGD (LOGD_IP6, "will %s userland IPv6LL", detail);
plerr = nm_platform_link_set_user_ipv6ll_enabled (nm_device_get_platform (self), ifindex, enable);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
_NMLOG (( plerr == NM_PLATFORM_ERROR_NOT_FOUND
|| plerr == NM_PLATFORM_ERROR_OPNOTSUPP) ? LOGL_DEBUG : LOGL_WARN,
r = nm_platform_link_set_user_ipv6ll_enabled (nm_device_get_platform (self), ifindex, enable);
if (r < 0) {
_NMLOG ( NM_IN_SET (r, -NME_PL_NOT_FOUND
-NME_PL_OPNOTSUPP)
? LOGL_DEBUG
: LOGL_WARN,
LOGD_IP6,
"failed to %s userspace IPv6LL address handling (%s)",
detail,
nm_platform_error_to_string_a (plerr));
nm_strerror (r));
}
if (enable) {
......@@ -15467,7 +15472,7 @@ _hw_addr_set (NMDevice *self,
{
NMDevicePrivate *priv;
gboolean success = FALSE;
NMPlatformError plerr;
int r;
guint8 addr_bytes[NM_UTILS_HWADDR_LEN_MAX];
gsize addr_len;
gboolean was_taken_down = FALSE;
......@@ -15504,21 +15509,21 @@ _hw_addr_set (NMDevice *self,
}
again:
plerr = nm_platform_link_set_address (nm_device_get_platform (self), nm_device_get_ip_ifindex (self), addr_bytes, addr_len);
success = (plerr == NM_PLATFORM_ERROR_SUCCESS);
r = nm_platform_link_set_address (nm_device_get_platform (self), nm_device_get_ip_ifindex (self), addr_bytes, addr_len);
success = (r >= 0);
if (!success) {
retry_down = !was_taken_down
&& plerr != NM_PLATFORM_ERROR_NOT_FOUND
&& r != -NME_PL_NOT_FOUND
&& nm_platform_link_is_up (nm_device_get_platform (self),
nm_device_get_ip_ifindex (self));
_NMLOG ( retry_down
|| plerr == NM_PLATFORM_ERROR_NOT_FOUND
_NMLOG ( ( retry_down
|| r == -NME_PL_NOT_FOUND)
? LOGL_DEBUG
: LOGL_WARN,
LOGD_DEVICE,
"set-hw-addr: failed to %s MAC address to %s (%s) (%s)%s",
operation, addr, detail,
nm_platform_error_to_string_a (plerr),
nm_strerror (r),
retry_down ? " (retry with taking down)" : "");
} else {
/* MAC address successfully changed; update the current MAC to match */
......
......@@ -804,15 +804,15 @@ create_and_realize (NMDevice *device,
GError **error)
{
const char *iface = nm_device_get_iface (device);
NMPlatformError plerr;
int r;
plerr = nm_platform_link_team_add (nm_device_get_platform (device), iface, out_plink);
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
r = nm_platform_link_team_add (nm_device_get_platform (device), iface, out_plink);
if (r < 0) {
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_error_to_string_a (plerr));
nm_strerror (r));
return FALSE;
}
......
......@@ -563,7 +563,7 @@ link_set_noarp (NMPlatform *platform, int ifindex)
return TRUE;
}
static NMPlatformError
static int
link_set_address (NMPlatform *platform, int ifindex, gconstpointer addr, size_t len)
{
NMFakePlatformLink *device = link_get (platform, ifindex);
......@@ -572,10 +572,10 @@ link_set_address (NMPlatform *platform, int ifindex, gconstpointer addr, size_t
if ( len == 0
|| len > NM_UTILS_HWADDR_LEN_MAX
|| !addr)
g_return_val_if_reached (NM_PLATFORM_ERROR_BUG);
g_return_val_if_reached (-NME_BUG);
if (!device)
return NM_PLATFORM_ERROR_EXISTS;
return -NME_PL_EXISTS;
obj_tmp = nmp_object_clone (device->obj, FALSE);
obj_tmp->link.addr.len = len;
......@@ -583,10 +583,10 @@ link_set_address (NMPlatform *platform, int ifindex, gconstpointer addr, size_t
memcpy (obj_tmp->link.addr.data, addr, len);
link_set_obj (platform, device, obj_tmp);
return NM_PLATFORM_ERROR_SUCCESS;
return 0;
}
static NMPlatformError
static int
link_set_mtu (NMPlatform *platform, int ifindex, guint32 mtu)
{
NMFakePlatformLink *device = link_get (platform, ifindex);
......@@ -594,13 +594,13 @@ link_set_mtu (NMPlatform *platform, int ifindex, guint32 mtu)
if (!device) {
_LOGE ("failure changing link: netlink error (No such device)");
return NM_PLATFORM_ERROR_EXISTS;
return -NME_PL_EXISTS;
}
obj_tmp = nmp_object_clone (device->obj, FALSE);
obj_tmp->link.mtu = mtu;
link_set_obj (platform, device, obj_tmp);
return NM_PLATFORM_ERROR_SUCCESS;
return 0;
}
static const char *
......@@ -1187,7 +1187,7 @@ object_delete (NMPlatform *platform, const NMPObject *obj)
return ipx_route_delete (platform, AF_UNSPEC, -1, obj);
}
static NMPlatformError
static int
ip_route_add (NMPlatform *platform,
NMPNlmFlags flags,
int addr_family,
......@@ -1276,7 +1276,7 @@ ip_route_add (NMPlatform *platform,
nm_log_warn (LOGD_PLATFORM, "Fake platform: failure adding ip6-route '%d: %s/%d %d': Network Unreachable",
r->ifindex, nm_utils_inet6_ntop (&r6->network, sbuf), r->plen, r->metric);
}
return NM_PLATFORM_ERROR_UNSPECIFIED;
return -NME_UNSPEC;
}
}
......@@ -1338,7 +1338,7 @@ ip_route_add (NMPlatform *platform,
}
}
return NM_PLATFORM_ERROR_SUCCESS;
return 0;
}
/*****************************************************************************/
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -52,7 +52,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_link_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == NM_PLATFORM_ERROR_SUCCESS);
g_assert (NMTST_NM_ERR_SUCCESS (nm_platform_link_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL)));
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), NULL));
......
......@@ -1010,7 +1010,7 @@ void nmtstp_ip4_route_add (NMPlatform *platform,