summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-12-22 14:13:05 +0100
committerThomas Haller <thaller@redhat.com>2018-12-27 21:33:59 +0100
commitd18f40320d1a5bb5f43a61f473d2cb6105da9b4e (patch)
treedaba3a93ff449446f9e92b75064f178d29402018
parent18732c349310fa84f2b565b7d4efa347b5f172d5 (diff)
downloadNetworkManager-d18f40320d1a5bb5f43a61f473d2cb6105da9b4e.tar.gz
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.
-rw-r--r--shared/nm-utils/nm-errno.c33
-rw-r--r--shared/nm-utils/nm-errno.h21
-rw-r--r--shared/nm-utils/nm-test-utils.h19
-rw-r--r--src/devices/nm-device-6lowpan.c8
-rw-r--r--src/devices/nm-device-bond.c8
-rw-r--r--src/devices/nm-device-bridge.c16
-rw-r--r--src/devices/nm-device-dummy.c8
-rw-r--r--src/devices/nm-device-infiniband.c16
-rw-r--r--src/devices/nm-device-ip-tunnel.c32
-rw-r--r--src/devices/nm-device-macsec.c8
-rw-r--r--src/devices/nm-device-macvlan.c8
-rw-r--r--src/devices/nm-device-tun.c19
-rw-r--r--src/devices/nm-device-vlan.c18
-rw-r--r--src/devices/nm-device-vxlan.c8
-rw-r--r--src/devices/nm-device.c33
-rw-r--r--src/devices/team/nm-device-team.c8
-rw-r--r--src/platform/nm-fake-platform.c20
-rw-r--r--src/platform/nm-linux-platform.c121
-rw-r--r--src/platform/nm-platform.c489
-rw-r--r--src/platform/nm-platform.h228
-rw-r--r--src/platform/tests/test-cleanup.c2
-rw-r--r--src/platform/tests/test-common.c32
-rw-r--r--src/platform/tests/test-common.h2
-rw-r--r--src/platform/tests/test-link.c34
-rw-r--r--src/platform/tests/test-route.c14
-rw-r--r--src/vpn/nm-vpn-connection.c4
26 files changed, 591 insertions, 618 deletions
diff --git a/shared/nm-utils/nm-errno.c b/shared/nm-utils/nm-errno.c
index 0eb4df56da..c87f0b48d6 100644
--- a/shared/nm-utils/nm-errno.c
+++ b/shared/nm-utils/nm-errno.c
@@ -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)
diff --git a/shared/nm-utils/nm-errno.h b/shared/nm-utils/nm-errno.h
index 0f94d00796..c3008f1fed 100644
--- a/shared/nm-utils/nm-errno.h
+++ b/shared/nm-utils/nm-errno.h
@@ -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,
};
diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h
index 64a024ca4e..3216593e70 100644
--- a/shared/nm-utils/nm-test-utils.h
+++ b/shared/nm-utils/nm-test-utils.h
@@ -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;
diff --git a/src/devices/nm-device-6lowpan.c b/src/devices/nm-device-6lowpan.c
index b6b9157ca4..4010374717 100644
--- a/src/devices/nm-device-6lowpan.c
+++ b/src/devices/nm-device-6lowpan.c
@@ -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;
}
diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c
index ae986ae3c0..78cba9bb1d 100644
--- a/src/devices/nm-device-bond.c
+++ b/src/devices/nm-device-bond.c
@@ -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;
diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c
index e79de95cd4..be53f30dc3 100644
--- a/src/devices/nm-device-bridge.c
+++ b/src/devices/nm-device-bridge.c
@@ -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;
}
diff --git a/src/devices/nm-device-dummy.c b/src/devices/nm-device-dummy.c
index a905938369..eb90456a97 100644
--- a/src/devices/nm-device-dummy.c
+++ b/src/devices/nm-device-dummy.c
@@ -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;
}
diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c
index 01edf80749..4db7d8a723 100644
--- a/src/devices/nm-device-infiniband.c
+++ b/src/devices/nm-device-infiniband.c
@@ -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;
}
diff --git a/src/devices/nm-device-ip-tunnel.c b/src/devices/nm-device-ip-tunnel.c
index 79d2720b4c..ca5f9c3f5d 100644
--- a/src/devices/nm-device-ip-tunnel.c
+++ b/src/devices/nm-device-ip-tunnel.c
@@ -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;
diff --git a/src/devices/nm-device-macsec.c b/src/devices/nm-device-macsec.c
index 60e2fc2fb9..1a6b64a49a 100644
--- a/src/devices/nm-device-macsec.c
+++ b/src/devices/nm-device-macsec.c
@@ -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;
}
diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c
index 2b21215451..bb629713fc 100644
--- a/src/devices/nm-device-macvlan.c
+++ b/src/devices/nm-device-macvlan.c
@@ -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;
}
diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c
index 0f76b23a4b..3fe3dfd4a4 100644
--- a/src/devices/nm-device-tun.c
+++ b/src/devices/nm-device-tun.c
@@ -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;
}
diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c
index c07112ab98..ace6a24bdb 100644
--- a/src/devices/nm-device-vlan.c
+++ b/src/devices/nm-device-vlan.c
@@ -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;
}
diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c
index 229fbda4c9..50730320e0 100644
--- a/src/devices/nm-device-vxlan.c
+++ b/src/devices/nm-device-vxlan.c
@@ -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;
}
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 20bf8bf8f1..9c76a2c887 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -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 */
diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c
index 64ec92a8e1..38a6dd8c6c 100644
--- a/src/devices/team/nm-device-team.c
+++ b/src/devices/team/nm-device-team.c
@@ -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;
}
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index f03668a7d8..74c36a0b75 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -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;
}
/*****************************************************************************/
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 32234c5301..7eb35a34e3 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -475,14 +475,14 @@ static struct nl_sock *_genl_sock (NMLinuxPlatform *platform);
/*****************************************************************************/
-static NMPlatformError
-wait_for_nl_response_to_plerr (WaitForNlResponseResult seq_result)
+static int
+wait_for_nl_response_to_nmerr (WaitForNlResponseResult seq_result)
{
if (seq_result == WAIT_FOR_NL_RESPONSE_RESULT_RESPONSE_OK)
- return NM_PLATFORM_ERROR_SUCCESS;
+ return 0;
if (seq_result < 0)
- return (NMPlatformError) seq_result;
- return NM_PLATFORM_ERROR_NETLINK;
+ return (int) seq_result;
+ return -NME_PL_NETLINK;
}
static const char *
@@ -5169,7 +5169,7 @@ do_add_link_with_lookup (NMPlatform *platform,
return seq_result == WAIT_FOR_NL_RESPONSE_RESULT_RESPONSE_OK;
}
-static NMPlatformError
+static int
do_add_addrroute (NMPlatform *platform,
const NMPObject *obj_id,
struct nl_msg *nlmsg,
@@ -5192,7 +5192,7 @@ do_add_addrroute (NMPlatform *platform,
NMP_OBJECT_GET_CLASS (obj_id)->obj_type_name,
nmp_object_to_string (obj_id, NMP_OBJECT_TO_STRING_ID, NULL, 0),
nm_strerror (nle), -nle);
- return NM_PLATFORM_ERROR_NETLINK;
+ return -NME_PL_NETLINK;
}
delayed_action_handle_all (platform, FALSE);
@@ -5221,7 +5221,7 @@ do_add_addrroute (NMPlatform *platform,
do_request_one_type (platform, NMP_OBJECT_GET_TYPE (obj_id));
}
- return wait_for_nl_response_to_plerr (seq_result);
+ return wait_for_nl_response_to_nmerr (seq_result);
}
static gboolean
@@ -5289,7 +5289,7 @@ do_delete_object (NMPlatform *platform, const NMPObject *obj_id, struct nl_msg *
return success;
}
-static NMPlatformError
+static int
do_change_link (NMPlatform *platform,
ChangeLinkType change_link_type,
int ifindex,
@@ -5301,7 +5301,7 @@ do_change_link (NMPlatform *platform,
WaitForNlResponseResult seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN;
gs_free char *errmsg = NULL;
char s_buf[256];
- NMPlatformError result = NM_PLATFORM_ERROR_SUCCESS;
+ int result = 0;
NMLogLevel log_level = LOGL_DEBUG;
const char *log_result = "failure";
const char *log_detail = "";
@@ -5344,11 +5344,11 @@ retry:
/* */
} else if (NM_IN_SET (-((int) seq_result), ESRCH, ENOENT)) {
log_detail = ", firmware not found";
- result = NM_PLATFORM_ERROR_NO_FIRMWARE;
+ result = -NME_PL_NO_FIRMWARE;
} else if ( NM_IN_SET (-((int) seq_result), ERANGE)
&& change_link_type == CHANGE_LINK_TYPE_SET_MTU) {
log_detail = ", setting MTU to requested size is not possible";
- result = NM_PLATFORM_ERROR_CANT_SET_MTU;
+ result = -NME_PL_CANT_SET_MTU;
} else if ( NM_IN_SET (-((int) seq_result), ENFILE)
&& change_link_type == CHANGE_LINK_TYPE_SET_ADDRESS
&& (obj_cache = nmp_cache_lookup_link (nm_platform_get_cache (platform), ifindex))
@@ -5358,16 +5358,16 @@ retry:
* If the MAC address is as expected, assume success? */
log_result = "success";
log_detail = " (assume success changing address)";
- result = NM_PLATFORM_ERROR_SUCCESS;
+ result = 0;
} else if (NM_IN_SET (-((int) seq_result), ENODEV)) {
log_level = LOGL_DEBUG;
- result = NM_PLATFORM_ERROR_NOT_FOUND;
+ result = -NME_PL_NOT_FOUND;
} else if (-((int) seq_result) == EAFNOSUPPORT) {
log_level = LOGL_DEBUG;
- result = NM_PLATFORM_ERROR_OPNOTSUPP;
+ result = -NME_PL_OPNOTSUPP;
} else {
log_level = LOGL_WARN;
- result = NM_PLATFORM_ERROR_UNSPECIFIED;
+ result = -NME_UNSPEC;
}
out:
@@ -5475,13 +5475,13 @@ link_set_netns (NMPlatform *platform,
return FALSE;
NLA_PUT (nlmsg, IFLA_NET_NS_FD, 4, &netns_fd);
- return do_change_link (platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL) == NM_PLATFORM_ERROR_SUCCESS;
+ return (do_change_link (platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL) >= 0);
nla_put_failure:
g_return_val_if_reached (FALSE);
}
-static NMPlatformError
+static int
link_change_flags (NMPlatform *platform,
int ifindex,
unsigned flags_mask,
@@ -5504,37 +5504,36 @@ link_change_flags (NMPlatform *platform,
flags_mask,
flags_set);
if (!nlmsg)
- return NM_PLATFORM_ERROR_UNSPECIFIED;
+ return -NME_UNSPEC;
return do_change_link (platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL);
}
static gboolean
link_set_up (NMPlatform *platform, int ifindex, gboolean *out_no_firmware)
{
- NMPlatformError plerr;
+ int r;
- plerr = link_change_flags (platform, ifindex, IFF_UP, IFF_UP);
- if (out_no_firmware)
- *out_no_firmware = plerr == NM_PLATFORM_ERROR_NO_FIRMWARE;
- return plerr == NM_PLATFORM_ERROR_SUCCESS;
+ r = link_change_flags (platform, ifindex, IFF_UP, IFF_UP);
+ NM_SET_OUT (out_no_firmware, (r == -NME_PL_NO_FIRMWARE));
+ return r >= 0;
}
static gboolean
link_set_down (NMPlatform *platform, int ifindex)
{
- return link_change_flags (platform, ifindex, IFF_UP, 0) == NM_PLATFORM_ERROR_SUCCESS;
+ return (link_change_flags (platform, ifindex, IFF_UP, 0) >= 0);
}
static gboolean
link_set_arp (NMPlatform *platform, int ifindex)
{
- return link_change_flags (platform, ifindex, IFF_NOARP, 0) == NM_PLATFORM_ERROR_SUCCESS;
+ return (link_change_flags (platform, ifindex, IFF_NOARP, 0) >= 0);
}
static gboolean
link_set_noarp (NMPlatform *platform, int ifindex)
{
- return link_change_flags (platform, ifindex, IFF_NOARP, IFF_NOARP) == NM_PLATFORM_ERROR_SUCCESS;
+ return (link_change_flags (platform, ifindex, IFF_NOARP, IFF_NOARP) >= 0);
}
static const char *
@@ -5549,7 +5548,7 @@ link_get_udi (NMPlatform *platform, int ifindex)
return udev_device_get_syspath (obj->_link.udev.device);
}
-static NMPlatformError
+static int
link_set_user_ipv6ll_enabled (NMPlatform *platform, int ifindex, gboolean enabled)
{
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
@@ -5561,7 +5560,7 @@ link_set_user_ipv6ll_enabled (NMPlatform *platform, int ifindex, gboolean enable
if (!_support_user_ipv6ll_get ()) {
_LOGD ("link: change %d: user-ipv6ll: not supported", ifindex);
- return NM_PLATFORM_ERROR_OPNOTSUPP;
+ return -NME_PL_OPNOTSUPP;
}
nlmsg = _nl_msg_new_link (RTM_NEWLINK,
@@ -5572,7 +5571,7 @@ link_set_user_ipv6ll_enabled (NMPlatform *platform, int ifindex, gboolean enable
0);
if ( !nlmsg
|| !_nl_msg_new_link_set_afspec (nlmsg, mode, NULL))
- g_return_val_if_reached (NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_reached (-NME_BUG);
return do_change_link (platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL);
}
@@ -5590,7 +5589,7 @@ link_set_token (NMPlatform *platform, int ifindex, NMUtilsIPv6IfaceId iid)
if (!nlmsg || !_nl_msg_new_link_set_afspec (nlmsg, -1, &iid))
g_return_val_if_reached (FALSE);
- return do_change_link (platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL) == NM_PLATFORM_ERROR_SUCCESS;
+ return (do_change_link (platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL) >= 0);
}
static gboolean
@@ -5650,7 +5649,7 @@ link_supports_sriov (NMPlatform *platform, int ifindex)
return total > 0;
}
-static NMPlatformError
+static int
link_set_address (NMPlatform *platform, int ifindex, gconstpointer address, size_t length)
{
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
@@ -5662,7 +5661,7 @@ link_set_address (NMPlatform *platform, int ifindex, gconstpointer address, size
};
if (!address || !length)
- g_return_val_if_reached (NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_reached (-NME_BUG);
nlmsg = _nl_msg_new_link (RTM_NEWLINK,
0,
@@ -5671,16 +5670,16 @@ link_set_address (NMPlatform *platform, int ifindex, gconstpointer address, size
0,
0);
if (!nlmsg)
- g_return_val_if_reached (NM_PLATFORM_ERROR_UNSPECIFIED);
+ g_return_val_if_reached (-NME_BUG);
NLA_PUT (nlmsg, IFLA_ADDRESS, length, address);
return do_change_link (platform, CHANGE_LINK_TYPE_SET_ADDRESS, ifindex, nlmsg, &d);
nla_put_failure:
- g_return_val_if_reached (NM_PLATFORM_ERROR_UNSPECIFIED);
+ g_return_val_if_reached (-NME_BUG);
}
-static NMPlatformError
+static int
link_set_name (NMPlatform *platform, int ifindex, const char *name)
{
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
@@ -5692,11 +5691,11 @@ link_set_name (NMPlatform *platform, int ifindex, const char *name)
0,
0);
if (!nlmsg)
- g_return_val_if_reached (NM_PLATFORM_ERROR_UNSPECIFIED);
+ g_return_val_if_reached (-NME_BUG);
NLA_PUT (nlmsg, IFLA_IFNAME, strlen (name) + 1, name);
- return do_change_link (platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL) == NM_PLATFORM_ERROR_SUCCESS;
+ return (do_change_link (platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL) >= 0);
nla_put_failure:
g_return_val_if_reached (FALSE);
}
@@ -5715,7 +5714,7 @@ link_get_permanent_address (NMPlatform *platform,
return nmp_utils_ethtool_get_permanent_address (ifindex, buf, length);
}
-static NMPlatformError
+static int
link_set_mtu (NMPlatform *platform, int ifindex, guint32 mtu)
{
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
@@ -5841,7 +5840,7 @@ link_set_sriov_vfs (NMPlatform *platform, int ifindex, const NMPlatformVF *const
0,
0);
if (!nlmsg)
- g_return_val_if_reached (NM_PLATFORM_ERROR_UNSPECIFIED);
+ g_return_val_if_reached (-NME_BUG);
if (!(list = nla_nest_start (nlmsg, IFLA_VFINFO_LIST)))
goto nla_put_failure;
@@ -5917,7 +5916,7 @@ link_set_sriov_vfs (NMPlatform *platform, int ifindex, const NMPlatformVF *const
}
nla_nest_end (nlmsg, list);
- return do_change_link (platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL) == NM_PLATFORM_ERROR_SUCCESS;
+ return (do_change_link (platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL) >= 0);
nla_put_failure:
g_return_val_if_reached (FALSE);
}
@@ -6645,7 +6644,7 @@ link_vlan_change (NMPlatform *platform,
new_n_egress_map))
g_return_val_if_reached (FALSE);
- return do_change_link (platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL) == NM_PLATFORM_ERROR_SUCCESS;
+ return (do_change_link (platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL) >= 0);
}
static gboolean
@@ -6665,7 +6664,7 @@ link_enslave (NMPlatform *platform, int master, int slave)
NLA_PUT_U32 (nlmsg, IFLA_MASTER, master);
- return do_change_link (platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL) == NM_PLATFORM_ERROR_SUCCESS;
+ return (do_change_link (platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL) >= 0);
nla_put_failure:
g_return_val_if_reached (FALSE);
}
@@ -7033,7 +7032,7 @@ ip4_address_add (NMPlatform *platform,
label);
nmp_object_stackinit_id_ip4_address (&obj_id, ifindex, addr, plen, peer_addr);
- return do_add_addrroute (platform, &obj_id, nlmsg, FALSE) == NM_PLATFORM_ERROR_SUCCESS;
+ return (do_add_addrroute (platform, &obj_id, nlmsg, FALSE) >= 0);
}
static gboolean
@@ -7063,7 +7062,7 @@ ip6_address_add (NMPlatform *platform,
NULL);
nmp_object_stackinit_id_ip6_address (&obj_id, ifindex, &addr);
- return do_add_addrroute (platform, &obj_id, nlmsg, FALSE) == NM_PLATFORM_ERROR_SUCCESS;
+ return (do_add_addrroute (platform, &obj_id, nlmsg, FALSE) >= 0);
}
static gboolean
@@ -7118,7 +7117,7 @@ ip6_address_delete (NMPlatform *platform, int ifindex, struct in6_addr addr, gui
/*****************************************************************************/
-static NMPlatformError
+static int
ip_route_add (NMPlatform *platform,
NMPNlmFlags flags,
int addr_family,
@@ -7142,7 +7141,7 @@ ip_route_add (NMPlatform *platform,
nlmsg = _nl_msg_new_route (RTM_NEWROUTE, flags & NMP_NLM_FLAG_FMASK, &obj);
if (!nlmsg)
- g_return_val_if_reached (NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_reached (-NME_BUG);
return do_add_addrroute (platform,
&obj,
nlmsg,
@@ -7181,7 +7180,7 @@ object_delete (NMPlatform *platform,
/*****************************************************************************/
-static NMPlatformError
+static int
ip_route_get (NMPlatform *platform,
int addr_family,
gconstpointer address,
@@ -7231,7 +7230,7 @@ ip_route_get (NMPlatform *platform,
if (nle < 0) {
_LOGE ("get-route: failure sending netlink request \"%s\" (%d)",
g_strerror (-nle), -nle);
- return NM_PLATFORM_ERROR_UNSPECIFIED;
+ return -NME_UNSPEC;
}
delayed_action_handle_all (platform, FALSE);
@@ -7243,24 +7242,24 @@ ip_route_get (NMPlatform *platform,
if (seq_result < 0) {
/* negative seq_result is an errno from kernel. Map it to negative
- * NMPlatformError (which are also errno). */
- return (NMPlatformError) seq_result;
+ * int (which are also errno). */
+ return (int) seq_result;
}
if (seq_result == WAIT_FOR_NL_RESPONSE_RESULT_RESPONSE_OK) {
if (route) {
NM_SET_OUT (out_route, g_steal_pointer (&route));
- return NM_PLATFORM_ERROR_SUCCESS;
+ return 0;
}
seq_result = WAIT_FOR_NL_RESPONSE_RESULT_RESPONSE_UNKNOWN;
}
- return NM_PLATFORM_ERROR_UNSPECIFIED;
+ return -NME_UNSPEC;
}
/*****************************************************************************/
-static NMPlatformError
+static int
qdisc_add (NMPlatform *platform,
NMPNlmFlags flags,
const NMPlatformQdisc *qdisc)
@@ -7279,7 +7278,7 @@ qdisc_add (NMPlatform *platform,
if (nle < 0) {
_LOGE ("do-add-qdisc: failed sending netlink request \"%s\" (%d)",
nm_strerror (nle), -nle);
- return NM_PLATFORM_ERROR_NETLINK;
+ return -NME_PL_NETLINK;
}
delayed_action_handle_all (platform, FALSE);
@@ -7293,14 +7292,14 @@ qdisc_add (NMPlatform *platform,
wait_for_nl_response_to_string (seq_result, errmsg, s_buf, sizeof (s_buf)));
if (seq_result == WAIT_FOR_NL_RESPONSE_RESULT_RESPONSE_OK)
- return NM_PLATFORM_ERROR_SUCCESS;
+ return 0;
- return NM_PLATFORM_ERROR_UNSPECIFIED;
+ return -NME_UNSPEC;
}
/*****************************************************************************/
-static NMPlatformError
+static int
tfilter_add (NMPlatform *platform,
NMPNlmFlags flags,
const NMPlatformTfilter *tfilter)
@@ -7319,7 +7318,7 @@ tfilter_add (NMPlatform *platform,
if (nle < 0) {
_LOGE ("do-add-tfilter: failed sending netlink request \"%s\" (%d)",
nm_strerror (nle), -nle);
- return NM_PLATFORM_ERROR_NETLINK;
+ return -NME_PL_NETLINK;
}
delayed_action_handle_all (platform, FALSE);
@@ -7333,9 +7332,9 @@ tfilter_add (NMPlatform *platform,
wait_for_nl_response_to_string (seq_result, errmsg, s_buf, sizeof (s_buf)));
if (seq_result == WAIT_FOR_NL_RESPONSE_RESULT_RESPONSE_OK)
- return NM_PLATFORM_ERROR_SUCCESS;
+ return 0;
- return NM_PLATFORM_ERROR_UNSPECIFIED;
+ return -NME_UNSPEC;
}
/*****************************************************************************/
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index fc90c452f3..c773ddf6df 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -41,6 +41,7 @@
#include "nm-core-internal.h"
#include "nm-utils/nm-dedup-multi.h"
#include "nm-utils/nm-udev-utils.h"
+#include "nm-utils/nm-errno.h"
#include "nm-core-utils.h"
#include "nm-platform-utils.h"
@@ -255,58 +256,6 @@ nm_platform_get_multi_idx (NMPlatform *self)
/*****************************************************************************/
-NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_nm_platform_error_to_string, NMPlatformError,
- NM_UTILS_LOOKUP_DEFAULT (NULL),
- NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_SUCCESS, "success"),
- NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_BUG, "bug"),
- NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_UNSPECIFIED, "unspecified"),
- NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_NOT_FOUND, "not-found"),
- NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_EXISTS, "exists"),
- NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_WRONG_TYPE, "wrong-type"),
- NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_NOT_SLAVE, "not-slave"),
- NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_NO_FIRMWARE, "no-firmware"),
- NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_OPNOTSUPP, "not-supported"),
- NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_NETLINK, "netlink"),
- NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_CANT_SET_MTU, "cant-set-mtu"),
- NM_UTILS_LOOKUP_ITEM_IGNORE (_NM_PLATFORM_ERROR_MININT),
-);
-
-/**
- * nm_platform_error_to_string:
- * @error_code: the error code to stringify.
- * @buf: (allow-none): buffer
- * @buf_len: size of buffer
- *
- * Returns: A string representation of the error.
- * For negative numbers, this function interprets
- * the code as -errno.
- * For invalid (positive) numbers it returns NULL.
- */
-const char *
-nm_platform_error_to_string (NMPlatformError error_code, char *buf, gsize buf_len)
-{
- const char *s;
-
- if (error_code < 0) {
- int errsv = -((int) error_code);
-
- nm_utils_to_string_buffer_init (&buf, &buf_len);
- g_snprintf (buf, buf_len, "%s (%d)", g_strerror (errsv), errsv);
- } else {
- s = _nm_platform_error_to_string (error_code);
- if (s) {
- if (!buf)
- return s;
- g_strlcpy (buf, s, buf_len);
- } else {
- nm_utils_to_string_buffer_init (&buf, &buf_len);
- g_snprintf (buf, buf_len, "(%d)", (int) error_code);
- }
- }
-
- return buf;
-}
-
NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_nmp_nlm_flag_to_string_lookup, NMPNlmFlags,
NM_UTILS_LOOKUP_DEFAULT (NULL),
NM_UTILS_LOOKUP_ITEM (NMP_NLM_FLAG_ADD, "add"),
@@ -938,7 +887,7 @@ nm_platform_link_get_by_address (NMPlatform *self,
return NMP_OBJECT_CAST_LINK (obj);
}
-static NMPlatformError
+static int
_link_add_check_existing (NMPlatform *self, const char *name, NMLinkType type, const NMPlatformLink **out_link)
{
const NMPlatformLink *pllink;
@@ -955,12 +904,12 @@ _link_add_check_existing (NMPlatform *self, const char *name, NMLinkType type, c
if (out_link)
*out_link = pllink;
if (wrong_type)
- return NM_PLATFORM_ERROR_WRONG_TYPE;
- return NM_PLATFORM_ERROR_EXISTS;
+ return -NME_PL_WRONG_TYPE;
+ return -NME_PL_EXISTS;
}
if (out_link)
*out_link = NULL;
- return NM_PLATFORM_ERROR_SUCCESS;
+ return 0;
}
/**
@@ -974,16 +923,16 @@ _link_add_check_existing (NMPlatform *self, const char *name, NMLinkType type, c
* @out_link: on success, the link object
*
* Add a software interface. If the interface already exists and is of type
- * @type, return NM_PLATFORM_ERROR_EXISTS and returns the link
+ * @type, return -NME_PL_EXISTS and returns the link
* in @out_link. If the interface already exists and is not of type @type,
- * return NM_PLATFORM_ERROR_WRONG_TYPE.
+ * return -NME_PL_WRONG_TYPE.
*
* Any link-changed ADDED signal will be emitted directly, before this
* function finishes.
*
- * Returns: the error reason or NM_PLATFORM_ERROR_SUCCESS.
+ * Returns: the negative nm-error on failure.
*/
-static NMPlatformError
+static int
nm_platform_link_add (NMPlatform *self,
const char *name,
NMLinkType type,
@@ -992,19 +941,19 @@ nm_platform_link_add (NMPlatform *self,
size_t address_len,
const NMPlatformLink **out_link)
{
- NMPlatformError plerr;
+ int r;
char addr_buf[NM_UTILS_HWADDR_LEN_MAX * 3];
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
- g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail ((address != NULL) ^ (address_len == 0) , NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail (address_len <= NM_UTILS_HWADDR_LEN_MAX, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail ((!!veth_peer) == (type == NM_LINK_TYPE_VETH), NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (name, -NME_BUG);
+ g_return_val_if_fail ((address != NULL) ^ (address_len == 0) , -NME_BUG);
+ g_return_val_if_fail (address_len <= NM_UTILS_HWADDR_LEN_MAX, -NME_BUG);
+ g_return_val_if_fail ((!!veth_peer) == (type == NM_LINK_TYPE_VETH), -NME_BUG);
- plerr = _link_add_check_existing (self, name, type, out_link);
- if (plerr != NM_PLATFORM_ERROR_SUCCESS)
- return plerr;
+ r = _link_add_check_existing (self, name, type, out_link);
+ if (r < 0)
+ return r;
_LOG2D ("link: adding link: %s (%d)"
"%s%s" /* address */
@@ -1018,11 +967,11 @@ nm_platform_link_add (NMPlatform *self,
veth_peer ?: "");
if (!klass->link_add (self, name, type, veth_peer, address, address_len, out_link))
- return NM_PLATFORM_ERROR_UNSPECIFIED;
- return NM_PLATFORM_ERROR_SUCCESS;
+ return -NME_UNSPEC;
+ return 0;
}
-NMPlatformError
+int
nm_platform_link_veth_add (NMPlatform *self,
const char *name,
const char *peer,
@@ -1039,7 +988,7 @@ nm_platform_link_veth_add (NMPlatform *self,
*
* Create a software ethernet-like interface
*/
-NMPlatformError
+int
nm_platform_link_dummy_add (NMPlatform *self,
const char *name,
const NMPlatformLink **out_link)
@@ -1423,14 +1372,14 @@ nm_platform_link_get_user_ipv6ll_enabled (NMPlatform *self, int ifindex)
* platform or OS doesn't support changing the IPv6LL address mode, this call
* will fail and return %FALSE.
*
- * Returns: %NM_PLATFORM_ERROR_SUCCESS if the operation was successful or an error code otherwise.
+ * Returns: the negative nm-error on failure.
*/
-NMPlatformError
+int
nm_platform_link_set_user_ipv6ll_enabled (NMPlatform *self, int ifindex, gboolean enabled)
{
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
- g_return_val_if_fail (ifindex > 0, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (ifindex > 0, -NME_BUG);
return klass->link_set_user_ipv6ll_enabled (self, ifindex, enabled);
}
@@ -1443,16 +1392,16 @@ nm_platform_link_set_user_ipv6ll_enabled (NMPlatform *self, int ifindex, gboolea
*
* Set interface MAC address.
*/
-NMPlatformError
+int
nm_platform_link_set_address (NMPlatform *self, int ifindex, gconstpointer address, size_t length)
{
gs_free char *mac = NULL;
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
- g_return_val_if_fail (ifindex > 0, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail (address, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail (length > 0, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (ifindex > 0, -NME_BUG);
+ g_return_val_if_fail (address, -NME_BUG);
+ g_return_val_if_fail (length > 0, -NME_BUG);
_LOG3D ("link: setting hardware address to %s",
(mac = nm_utils_hwaddr_ntoa (address, length)));
@@ -1668,7 +1617,7 @@ nm_platform_link_set_noarp (NMPlatform *self, int ifindex)
*
* Set interface MTU.
*/
-NMPlatformError
+int
nm_platform_link_set_mtu (NMPlatform *self, int ifindex, guint32 mtu)
{
_CHECK_SELF (self, klass, FALSE);
@@ -2048,7 +1997,7 @@ nm_platform_link_get_lnk_wireguard (NMPlatform *self, int ifindex, const NMPlatf
*
* Create a software bridge.
*/
-NMPlatformError
+int
nm_platform_link_bridge_add (NMPlatform *self,
const char *name,
const void *address,
@@ -2066,7 +2015,7 @@ nm_platform_link_bridge_add (NMPlatform *self,
*
* Create a software bonding device.
*/
-NMPlatformError
+int
nm_platform_link_bond_add (NMPlatform *self,
const char *name,
const NMPlatformLink **out_link)
@@ -2082,7 +2031,7 @@ nm_platform_link_bond_add (NMPlatform *self,
*
* Create a software teaming device.
*/
-NMPlatformError
+int
nm_platform_link_team_add (NMPlatform *self,
const char *name,
const NMPlatformLink **out_link)
@@ -2100,7 +2049,7 @@ nm_platform_link_team_add (NMPlatform *self,
*
* Create a software VLAN device.
*/
-NMPlatformError
+int
nm_platform_link_vlan_add (NMPlatform *self,
const char *name,
int parent,
@@ -2108,24 +2057,24 @@ nm_platform_link_vlan_add (NMPlatform *self,
guint32 vlanflags,
const NMPlatformLink **out_link)
{
- NMPlatformError plerr;
+ int r;
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
- 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 (parent >= 0, -NME_BUG);
+ g_return_val_if_fail (vlanid >= 0, -NME_BUG);
+ g_return_val_if_fail (name, -NME_BUG);
- plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_VLAN, out_link);
- if (plerr != NM_PLATFORM_ERROR_SUCCESS)
- return plerr;
+ r = _link_add_check_existing (self, name, NM_LINK_TYPE_VLAN, out_link);
+ if (r < 0)
+ return r;
_LOG2D ("link: adding link vlan parent %d vlanid %d vlanflags %x",
parent, vlanid, vlanflags);
if (!klass->vlan_add (self, name, parent, vlanid, vlanflags, out_link))
- return NM_PLATFORM_ERROR_UNSPECIFIED;
- return NM_PLATFORM_ERROR_SUCCESS;
+ return -NME_UNSPEC;
+ return 0;
}
/**
@@ -2137,27 +2086,27 @@ nm_platform_link_vlan_add (NMPlatform *self,
*
* Create a VXLAN device.
*/
-NMPlatformError
+int
nm_platform_link_vxlan_add (NMPlatform *self,
const char *name,
const NMPlatformLnkVxlan *props,
const NMPlatformLink **out_link)
{
- NMPlatformError plerr;
+ int r;
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
- g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (props, -NME_BUG);
- plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_VXLAN, out_link);
- if (plerr != NM_PLATFORM_ERROR_SUCCESS)
- return plerr;
+ r = _link_add_check_existing (self, name, NM_LINK_TYPE_VXLAN, out_link);
+ if (r < 0)
+ return r;
_LOG2D ("link: adding link %s", nm_platform_lnk_vxlan_to_string (props, NULL, 0));
if (!klass->link_vxlan_add (self, name, props, out_link))
- return NM_PLATFORM_ERROR_UNSPECIFIED;
- return NM_PLATFORM_ERROR_SUCCESS;
+ return -NME_UNSPEC;
+ return 0;
}
/**
@@ -2179,7 +2128,7 @@ nm_platform_link_vxlan_add (NMPlatform *self,
*
* Create a TUN or TAP interface.
*/
-NMPlatformError
+int
nm_platform_link_tun_add (NMPlatform *self,
const char *name,
const NMPlatformLnkTun *props,
@@ -2187,29 +2136,29 @@ nm_platform_link_tun_add (NMPlatform *self,
int *out_fd)
{
char b[255];
- NMPlatformError plerr;
+ int r;
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
- g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail (NM_IN_SET (props->type, IFF_TUN, IFF_TAP), NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (name, -NME_BUG);
+ g_return_val_if_fail (props, -NME_BUG);
+ g_return_val_if_fail (NM_IN_SET (props->type, IFF_TUN, IFF_TAP), -NME_BUG);
/* creating a non-persistant device requires that the caller handles
* the file descriptor. */
- g_return_val_if_fail (props->persist || out_fd, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (props->persist || out_fd, -NME_BUG);
NM_SET_OUT (out_fd, -1);
- plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_TUN, out_link);
- if (plerr != NM_PLATFORM_ERROR_SUCCESS)
- return plerr;
+ r = _link_add_check_existing (self, name, NM_LINK_TYPE_TUN, out_link);
+ if (r < 0)
+ return r;
_LOG2D ("link: adding link %s", nm_platform_lnk_tun_to_string (props, b, sizeof (b)));
if (!klass->link_tun_add (self, name, props, out_link, out_fd))
- return NM_PLATFORM_ERROR_UNSPECIFIED;
- return NM_PLATFORM_ERROR_SUCCESS;
+ return -NME_UNSPEC;
+ return 0;
}
/**
@@ -2221,27 +2170,27 @@ nm_platform_link_tun_add (NMPlatform *self,
*
* Create a 6LoWPAN interface.
*/
-NMPlatformError
+int
nm_platform_link_6lowpan_add (NMPlatform *self,
const char *name,
int parent,
const NMPlatformLink **out_link)
{
- NMPlatformError plerr;
+ int r;
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
- g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (name, -NME_BUG);
- plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_6LOWPAN, out_link);
- if (plerr != NM_PLATFORM_ERROR_SUCCESS)
- return plerr;
+ r = _link_add_check_existing (self, name, NM_LINK_TYPE_6LOWPAN, out_link);
+ if (r < 0)
+ return r;
_LOG2D ("adding link 6lowpan parent %u", parent);
if (!klass->link_6lowpan_add (self, name, parent, out_link))
- return NM_PLATFORM_ERROR_UNSPECIFIED;
- return NM_PLATFORM_ERROR_SUCCESS;
+ return -NME_UNSPEC;
+ return 0;
}
gboolean
@@ -2491,31 +2440,31 @@ nm_platform_link_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, i
*
* Create a software GRE device.
*/
-NMPlatformError
+int
nm_platform_link_gre_add (NMPlatform *self,
const char *name,
const NMPlatformLnkGre *props,
const NMPlatformLink **out_link)
{
- NMPlatformError plerr;
+ int r;
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
- g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (props, -NME_BUG);
+ g_return_val_if_fail (name, -NME_BUG);
- plerr = _link_add_check_existing (self, name, props->is_tap ? NM_LINK_TYPE_GRETAP : NM_LINK_TYPE_GRE, out_link);
- if (plerr != NM_PLATFORM_ERROR_SUCCESS)
- return plerr;
+ r = _link_add_check_existing (self, name, props->is_tap ? NM_LINK_TYPE_GRETAP : NM_LINK_TYPE_GRE, out_link);
+ if (r < 0)
+ return r;
_LOG2D ("adding link %s", nm_platform_lnk_gre_to_string (props, NULL, 0));
if (!klass->link_gre_add (self, name, props, out_link))
- return NM_PLATFORM_ERROR_UNSPECIFIED;
- return NM_PLATFORM_ERROR_SUCCESS;
+ return -NME_UNSPEC;
+ return 0;
}
-static NMPlatformError
+static int
_infiniband_add_add_or_delete (NMPlatform *self,
int ifindex,
int p_key,
@@ -2524,45 +2473,45 @@ _infiniband_add_add_or_delete (NMPlatform *self,
{
char name[IFNAMSIZ];
const NMPlatformLink *parent_link;
- NMPlatformError plerr;
+ int r;
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
- g_return_val_if_fail (ifindex >= 0, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail (p_key >= 0 && p_key <= 0xffff, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (ifindex >= 0, -NME_BUG);
+ g_return_val_if_fail (p_key >= 0 && p_key <= 0xffff, -NME_BUG);
/* the special keys 0x0000 and 0x8000 are not allowed. */
if (NM_IN_SET (p_key, 0, 0x8000))
- return NM_PLATFORM_ERROR_UNSPECIFIED;
+ return -NME_UNSPEC;
parent_link = nm_platform_link_get (self, ifindex);
if (!parent_link)
- return NM_PLATFORM_ERROR_NOT_FOUND;
+ return -NME_PL_NOT_FOUND;
if (parent_link->type != NM_LINK_TYPE_INFINIBAND)
- return NM_PLATFORM_ERROR_WRONG_TYPE;
+ return -NME_PL_WRONG_TYPE;
nm_utils_new_infiniband_name (name, parent_link->name, p_key);
if (add) {
- plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_INFINIBAND, out_link);
- if (plerr != NM_PLATFORM_ERROR_SUCCESS)
- return plerr;
+ r = _link_add_check_existing (self, name, NM_LINK_TYPE_INFINIBAND, out_link);
+ if (r < 0)
+ return r;
_LOG3D ("link: adding infiniband partition %s, key %d", name, p_key);
if (!klass->infiniband_partition_add (self, ifindex, p_key, out_link))
- return NM_PLATFORM_ERROR_UNSPECIFIED;
+ return -NME_UNSPEC;
} else {
_LOG3D ("link: deleting infiniband partition %s, key %d", name, p_key);
if (!klass->infiniband_partition_delete (self, ifindex, p_key))
- return NM_PLATFORM_ERROR_UNSPECIFIED;
+ return -NME_UNSPEC;
}
- return NM_PLATFORM_ERROR_SUCCESS;
+ return 0;
}
-NMPlatformError
+int
nm_platform_link_infiniband_add (NMPlatform *self,
int parent,
int p_key,
@@ -2571,7 +2520,7 @@ nm_platform_link_infiniband_add (NMPlatform *self,
return _infiniband_add_add_or_delete (self, parent, p_key, TRUE, out_link);
}
-NMPlatformError
+int
nm_platform_link_infiniband_delete (NMPlatform *self,
int parent,
int p_key)
@@ -2648,29 +2597,29 @@ nm_platform_link_infiniband_get_properties (NMPlatform *self,
*
* Create an IPv6 tunnel.
*/
-NMPlatformError
+int
nm_platform_link_ip6tnl_add (NMPlatform *self,
const char *name,
const NMPlatformLnkIp6Tnl *props,
const NMPlatformLink **out_link)
{
- NMPlatformError plerr;
+ int r;
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
- g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail (!props->is_gre, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (props, -NME_BUG);
+ g_return_val_if_fail (name, -NME_BUG);
+ g_return_val_if_fail (!props->is_gre, -NME_BUG);
- plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_IP6TNL, out_link);
- if (plerr != NM_PLATFORM_ERROR_SUCCESS)
- return plerr;
+ r = _link_add_check_existing (self, name, NM_LINK_TYPE_IP6TNL, out_link);
+ if (r < 0)
+ return r;
_LOG2D ("adding link %s", nm_platform_lnk_ip6tnl_to_string (props, NULL, 0));
if (!klass->link_ip6tnl_add (self, name, props, out_link))
- return NM_PLATFORM_ERROR_UNSPECIFIED;
- return NM_PLATFORM_ERROR_SUCCESS;
+ return -NME_UNSPEC;
+ return 0;
}
/**
@@ -2682,34 +2631,34 @@ nm_platform_link_ip6tnl_add (NMPlatform *self,
*
* Create an IPv6 GRE/GRETAP tunnel.
*/
-NMPlatformError
+int
nm_platform_link_ip6gre_add (NMPlatform *self,
const char *name,
const NMPlatformLnkIp6Tnl *props,
const NMPlatformLink **out_link)
{
- NMPlatformError plerr;
+ int r;
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
- g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail (props->is_gre, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (props, -NME_BUG);
+ g_return_val_if_fail (name, -NME_BUG);
+ g_return_val_if_fail (props->is_gre, -NME_BUG);
- plerr = _link_add_check_existing (self,
- name,
- props->is_tap
- ? NM_LINK_TYPE_IP6GRETAP
- : NM_LINK_TYPE_IP6GRE,
- out_link);
- if (plerr != NM_PLATFORM_ERROR_SUCCESS)
- return plerr;
+ r = _link_add_check_existing (self,
+ name,
+ props->is_tap
+ ? NM_LINK_TYPE_IP6GRETAP
+ : NM_LINK_TYPE_IP6GRE,
+ out_link);
+ if (r < 0)
+ return r;
_LOG2D ("adding link %s", nm_platform_lnk_ip6tnl_to_string (props, NULL, 0));
if (!klass->link_ip6gre_add (self, name, props, out_link))
- return NM_PLATFORM_ERROR_UNSPECIFIED;
- return NM_PLATFORM_ERROR_SUCCESS;
+ return -NME_UNSPEC;
+ return 0;
}
/**
@@ -2721,28 +2670,28 @@ nm_platform_link_ip6gre_add (NMPlatform *self,
*
* Create an IPIP tunnel.
*/
-NMPlatformError
+int
nm_platform_link_ipip_add (NMPlatform *self,
const char *name,
const NMPlatformLnkIpIp *props,
const NMPlatformLink **out_link)
{
- NMPlatformError plerr;
+ int r;
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
- g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (props, -NME_BUG);
+ g_return_val_if_fail (name, -NME_BUG);
- plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_IPIP, out_link);
- if (plerr != NM_PLATFORM_ERROR_SUCCESS)
- return plerr;
+ r = _link_add_check_existing (self, name, NM_LINK_TYPE_IPIP, out_link);
+ if (r < 0)
+ return r;
_LOG2D ("adding link %s", nm_platform_lnk_ipip_to_string (props, NULL, 0));
if (!klass->link_ipip_add (self, name, props, out_link))
- return NM_PLATFORM_ERROR_UNSPECIFIED;
- return NM_PLATFORM_ERROR_SUCCESS;
+ return -NME_UNSPEC;
+ return 0;
}
/**
@@ -2755,29 +2704,29 @@ nm_platform_link_ipip_add (NMPlatform *self,
*
* Create a MACsec interface.
*/
-NMPlatformError
+int
nm_platform_link_macsec_add (NMPlatform *self,
const char *name,
int parent,
const NMPlatformLnkMacsec *props,
const NMPlatformLink **out_link)
{
- NMPlatformError plerr;
+ int r;
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
- g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (props, -NME_BUG);
+ g_return_val_if_fail (name, -NME_BUG);
- plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_MACSEC, out_link);
- if (plerr != NM_PLATFORM_ERROR_SUCCESS)
- return plerr;
+ r = _link_add_check_existing (self, name, NM_LINK_TYPE_MACSEC, out_link);
+ if (r < 0)
+ return r;
_LOG2D ("adding link %s", nm_platform_lnk_macsec_to_string (props, NULL, 0));
if (!klass->link_macsec_add (self, name, parent, props, out_link))
- return NM_PLATFORM_ERROR_UNSPECIFIED;
- return NM_PLATFORM_ERROR_SUCCESS;
+ return -NME_UNSPEC;
+ return 0;
}
/**
@@ -2789,32 +2738,32 @@ nm_platform_link_macsec_add (NMPlatform *self,
*
* Create a MACVLAN or MACVTAP device.
*/
-NMPlatformError
+int
nm_platform_link_macvlan_add (NMPlatform *self,
const char *name,
int parent,
const NMPlatformLnkMacvlan *props,
const NMPlatformLink **out_link)
{
- NMPlatformError plerr;
+ int r;
NMLinkType type;
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
- g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (props, -NME_BUG);
+ g_return_val_if_fail (name, -NME_BUG);
type = props->tap ? NM_LINK_TYPE_MACVTAP : NM_LINK_TYPE_MACVLAN;
- plerr = _link_add_check_existing (self, name, type, out_link);
- if (plerr != NM_PLATFORM_ERROR_SUCCESS)
- return plerr;
+ r = _link_add_check_existing (self, name, type, out_link);
+ if (r < 0)
+ return r;
_LOG2D ("adding link %s", nm_platform_lnk_macvlan_to_string (props, NULL, 0));
if (!klass->link_macvlan_add (self, name, parent, props, out_link))
- return NM_PLATFORM_ERROR_UNSPECIFIED;
- return NM_PLATFORM_ERROR_SUCCESS;
+ return -NME_UNSPEC;
+ return 0;
}
/**
@@ -2826,28 +2775,28 @@ nm_platform_link_macvlan_add (NMPlatform *self,
*
* Create a software SIT device.
*/
-NMPlatformError
+int
nm_platform_link_sit_add (NMPlatform *self,
const char *name,
const NMPlatformLnkSit *props,
const NMPlatformLink **out_link)
{
- NMPlatformError plerr;
+ int r;
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
- g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (props, -NME_BUG);
+ g_return_val_if_fail (name, -NME_BUG);
- plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_SIT, out_link);
- if (plerr != NM_PLATFORM_ERROR_SUCCESS)
- return plerr;
+ r = _link_add_check_existing (self, name, NM_LINK_TYPE_SIT, out_link);
+ if (r < 0)
+ return r;
_LOG2D ("adding link %s", nm_platform_lnk_sit_to_string (props, NULL, 0));
if (!klass->link_sit_add (self, name, props, out_link))
- return NM_PLATFORM_ERROR_UNSPECIFIED;
- return NM_PLATFORM_ERROR_SUCCESS;
+ return -NME_UNSPEC;
+ return 0;
}
gboolean
@@ -4234,7 +4183,6 @@ nm_platform_ip_route_sync (NMPlatform *self,
gboolean success = TRUE;
char sbuf1[sizeof (_nm_utils_to_string_buffer)];
char sbuf2[sizeof (_nm_utils_to_string_buffer)];
- char sbuf_err[60];
nm_assert (NM_IS_PLATFORM (self));
nm_assert (NM_IN_SET (addr_family, AF_INET, AF_INET6));
@@ -4246,7 +4194,7 @@ nm_platform_ip_route_sync (NMPlatform *self,
for (i_type = 0; routes && i_type < 2; i_type++) {
for (i = 0; i < routes->len; i++) {
- NMPlatformError plerr, plerr2;
+ int r, r2;
gboolean gateway_route_added = FALSE;
conf_o = routes->pdata[i];
@@ -4294,12 +4242,12 @@ nm_platform_ip_route_sync (NMPlatform *self,
}
sync_route_add:
- plerr = nm_platform_ip_route_add (self,
- NMP_NLM_FLAG_APPEND
- | NMP_NLM_FLAG_SUPPRESS_NETLINK_FAILURE,
- conf_o);
- if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
- if (-((int) plerr) == EEXIST) {
+ r = nm_platform_ip_route_add (self,
+ NMP_NLM_FLAG_APPEND
+ | NMP_NLM_FLAG_SUPPRESS_NETLINK_FAILURE,
+ conf_o);
+ if (r < 0) {
+ if (r == -EEXIST) {
/* Don't fail for EEXIST. It's not clear that the existing route
* is identical to the one that we were about to add. However,
* above we should have deleted conflicting (non-identical) routes. */
@@ -4322,69 +4270,69 @@ sync_route_add:
_LOG3D ("route-sync: ignore failure to add IPv%c route: %s: %s",
vt->is_ip4 ? '4' : '6',
nmp_object_to_string (conf_o, NMP_OBJECT_TO_STRING_PUBLIC, sbuf1, sizeof (sbuf1)),
- nm_platform_error_to_string (plerr, sbuf_err, sizeof (sbuf_err)));
- } else if ( -((int) plerr) == EINVAL
+ nm_strerror (r));
+ } else if ( r == -EINVAL
&& out_temporary_not_available
&& _err_inval_due_to_ipv6_tentative_pref_src (self, conf_o)) {
_LOG3D ("route-sync: ignore failure to add IPv6 route with tentative IPv6 pref-src: %s: %s",
nmp_object_to_string (conf_o, NMP_OBJECT_TO_STRING_PUBLIC, sbuf1, sizeof (sbuf1)),
- nm_platform_error_to_string (plerr, sbuf_err, sizeof (sbuf_err)));
+ nm_strerror (r));
if (!*out_temporary_not_available)
*out_temporary_not_available = g_ptr_array_new_full (0, (GDestroyNotify) nmp_object_unref);
g_ptr_array_add (*out_temporary_not_available, (gpointer) nmp_object_ref (conf_o));
} else if ( !gateway_route_added
- && ( ( -((int) plerr) == ENETUNREACH
+ && ( ( r == -ENETUNREACH
&& vt->is_ip4
&& !!NMP_OBJECT_CAST_IP4_ROUTE (conf_o)->gateway)
- || ( -((int) plerr) == EHOSTUNREACH
+ || ( r == -EHOSTUNREACH
&& !vt->is_ip4
&& !IN6_IS_ADDR_UNSPECIFIED (&NMP_OBJECT_CAST_IP6_ROUTE (conf_o)->gateway)))) {
NMPObject oo;
if (vt->is_ip4) {
- const NMPlatformIP4Route *r = NMP_OBJECT_CAST_IP4_ROUTE (conf_o);
+ const NMPlatformIP4Route *rt = NMP_OBJECT_CAST_IP4_ROUTE (conf_o);
nmp_object_stackinit (&oo,
NMP_OBJECT_TYPE_IP4_ROUTE,
&((NMPlatformIP4Route) {
- .ifindex = r->ifindex,
- .network = r->gateway,
+ .ifindex = rt->ifindex,
+ .network = rt->gateway,
.plen = 32,
- .metric = r->metric,
- .rt_source = r->rt_source,
- .table_coerced = r->table_coerced,
+ .metric = rt->metric,
+ .rt_source = rt->rt_source,
+ .table_coerced = rt->table_coerced,
}));
} else {
- const NMPlatformIP6Route *r = NMP_OBJECT_CAST_IP6_ROUTE (conf_o);
+ const NMPlatformIP6Route *rt = NMP_OBJECT_CAST_IP6_ROUTE (conf_o);
nmp_object_stackinit (&oo,
NMP_OBJECT_TYPE_IP6_ROUTE,
&((NMPlatformIP6Route) {
- .ifindex = r->ifindex,
- .network = r->gateway,
+ .ifindex = rt->ifindex,
+ .network = rt->gateway,
.plen = 128,
- .metric = r->metric,
- .rt_source = r->rt_source,
- .table_coerced = r->table_coerced,
+ .metric = rt->metric,
+ .rt_source = rt->rt_source,
+ .table_coerced = rt->table_coerced,
}));
}
_LOG3D ("route-sync: failure to add IPv%c route: %s: %s; try adding direct route to gateway %s",
vt->is_ip4 ? '4' : '6',
nmp_object_to_string (conf_o, NMP_OBJECT_TO_STRING_PUBLIC, sbuf1, sizeof (sbuf1)),
- nm_platform_error_to_string (plerr, sbuf_err, sizeof (sbuf_err)),
+ nm_strerror (r),
nmp_object_to_string (&oo, NMP_OBJECT_TO_STRING_PUBLIC, sbuf2, sizeof (sbuf2)));
- plerr2 = nm_platform_ip_route_add (self,
- NMP_NLM_FLAG_APPEND
- | NMP_NLM_FLAG_SUPPRESS_NETLINK_FAILURE,
- &oo);
+ r2 = nm_platform_ip_route_add (self,
+ NMP_NLM_FLAG_APPEND
+ | NMP_NLM_FLAG_SUPPRESS_NETLINK_FAILURE,
+ &oo);
- if (plerr2 != NM_PLATFORM_ERROR_SUCCESS) {
+ if (r2 < 0) {
_LOG3D ("route-sync: failure to add gateway IPv%c route: %s: %s",
vt->is_ip4 ? '4' : '6',
nmp_object_to_string (conf_o, NMP_OBJECT_TO_STRING_PUBLIC, sbuf1, sizeof (sbuf1)),
- nm_platform_error_to_string (plerr, sbuf_err, sizeof (sbuf_err)));
+ nm_strerror (r2));
}
gateway_route_added = TRUE;
@@ -4393,7 +4341,7 @@ sync_route_add:
_LOG3W ("route-sync: failure to add IPv%c route: %s: %s",
vt->is_ip4 ? '4' : '6',
nmp_object_to_string (conf_o, NMP_OBJECT_TO_STRING_PUBLIC, sbuf1, sizeof (sbuf1)),
- nm_platform_error_to_string (plerr, sbuf_err, sizeof (sbuf_err)));
+ nm_strerror (r));
success = FALSE;
}
}
@@ -4535,7 +4483,7 @@ nm_platform_ip_route_normalize (int addr_family,
}
}
-static NMPlatformError
+static int
_ip_route_add (NMPlatform *self,
NMPNlmFlags flags,
int addr_family,
@@ -4560,7 +4508,7 @@ _ip_route_add (NMPlatform *self,
return klass->ip_route_add (self, flags, addr_family, route);
}
-NMPlatformError
+int
nm_platform_ip_route_add (NMPlatform *self,
NMPNlmFlags flags,
const NMPObject *route)
@@ -4581,7 +4529,7 @@ nm_platform_ip_route_add (NMPlatform *self,
return _ip_route_add (self, flags, addr_family, NMP_OBJECT_CAST_IP_ROUTE (route));
}
-NMPlatformError
+int
nm_platform_ip4_route_add (NMPlatform *self,
NMPNlmFlags flags,
const NMPlatformIP4Route *route)
@@ -4589,7 +4537,7 @@ nm_platform_ip4_route_add (NMPlatform *self,
return _ip_route_add (self, flags, AF_INET, route);
}
-NMPlatformError
+int
nm_platform_ip6_route_add (NMPlatform *self,
NMPNlmFlags flags,
const NMPlatformIP6Route *route)
@@ -4619,7 +4567,7 @@ nm_platform_object_delete (NMPlatform *self,
/*****************************************************************************/
-NMPlatformError
+int
nm_platform_ip_route_get (NMPlatform *self,
int addr_family,
gconstpointer address /* in_addr_t or struct in6_addr */,
@@ -4627,16 +4575,15 @@ nm_platform_ip_route_get (NMPlatform *self,
NMPObject **out_route)
{
nm_auto_nmpobj NMPObject *route = NULL;
- NMPlatformError result;
+ int result;
char buf[NM_UTILS_INET_ADDRSTRLEN];
- char buf_err[200];
char buf_oif[64];
_CHECK_SELF (self, klass, FALSE);
- g_return_val_if_fail (address, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (address, -NME_BUG);
g_return_val_if_fail (NM_IN_SET (addr_family, AF_INET,
- AF_INET6), NM_PLATFORM_ERROR_BUG);
+ AF_INET6), -NME_BUG);
_LOGT ("route: get IPv%c route for: %s%s",
nm_utils_addr_family_to_char (addr_family),
@@ -4644,7 +4591,7 @@ nm_platform_ip_route_get (NMPlatform *self,
oif_ifindex > 0 ? nm_sprintf_buf (buf_oif, " oif %d", oif_ifindex) : "");
if (!klass->ip_route_get)
- result = NM_PLATFORM_ERROR_OPNOTSUPP;
+ result = -NME_PL_OPNOTSUPP;
else {
result = klass->ip_route_get (self,
addr_family,
@@ -4653,12 +4600,12 @@ nm_platform_ip_route_get (NMPlatform *self,
&route);
}
- if (result != NM_PLATFORM_ERROR_SUCCESS) {
+ if (result < 0) {
nm_assert (!route);
_LOGW ("route: get IPv%c route for: %s failed with %s",
nm_utils_addr_family_to_char (addr_family),
inet_ntop (addr_family, address, buf, sizeof (buf)),
- nm_platform_error_to_string (result, buf_err, sizeof (buf_err)));
+ nm_strerror (result));
} else {
nm_assert (NM_IN_SET (NMP_OBJECT_GET_TYPE (route), NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE));
nm_assert (!NMP_OBJECT_IS_STACKINIT (route));
@@ -4942,13 +4889,13 @@ nm_platform_ip4_dev_route_blacklist_set (NMPlatform *self,
/*****************************************************************************/
-NMPlatformError
+int
nm_platform_qdisc_add (NMPlatform *self,
NMPNlmFlags flags,
const NMPlatformQdisc *qdisc)
{
int ifindex = qdisc->ifindex;
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
_LOG3D ("adding or updating a qdisc: %s", nm_platform_qdisc_to_string (qdisc, NULL, 0));
return klass->qdisc_add (self, flags, qdisc);
@@ -4999,7 +4946,7 @@ nm_platform_qdisc_sync (NMPlatform *self,
const NMPObject *q = g_ptr_array_index (known_qdiscs, i);
success &= (nm_platform_qdisc_add (self, NMP_NLM_FLAG_ADD,
- NMP_OBJECT_CAST_QDISC (q)) == NM_PLATFORM_ERROR_SUCCESS);
+ NMP_OBJECT_CAST_QDISC (q)) >= 0);
}
}
@@ -5008,13 +4955,13 @@ nm_platform_qdisc_sync (NMPlatform *self,
/*****************************************************************************/
-NMPlatformError
+int
nm_platform_tfilter_add (NMPlatform *self,
NMPNlmFlags flags,
const NMPlatformTfilter *tfilter)
{
int ifindex = tfilter->ifindex;
- _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
+ _CHECK_SELF (self, klass, -NME_BUG);
_LOG3D ("adding or updating a tfilter: %s", nm_platform_tfilter_to_string (tfilter, NULL, 0));
return klass->tfilter_add (self, flags, tfilter);
@@ -5065,7 +5012,7 @@ nm_platform_tfilter_sync (NMPlatform *self,
const NMPObject *q = g_ptr_array_index (known_tfilters, i);
success &= (nm_platform_tfilter_add (self, NMP_NLM_FLAG_ADD,
- NMP_OBJECT_CAST_TFILTER (q)) == NM_PLATFORM_ERROR_SUCCESS);
+ NMP_OBJECT_CAST_TFILTER (q)) >= 0);
}
}
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 59d4eb45c5..210c400a85 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -29,6 +29,7 @@
#include "nm-setting-wired.h"
#include "nm-setting-wireless.h"
#include "nm-setting-ip-tunnel.h"
+#include "nm-utils/nm-errno.h"
#define NM_TYPE_PLATFORM (nm_platform_get_type ())
#define NM_PLATFORM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_PLATFORM, NMPlatform))
@@ -149,29 +150,6 @@ typedef enum {
} NMPlatformIPRouteCmpType;
-typedef enum { /*< skip >*/
-
- /* dummy value, to enforce that the enum type is signed and has a size
- * to hold an integer. We want to encode errno from <errno.h> as negative
- * values. */
- _NM_PLATFORM_ERROR_MININT = G_MININT,
-
- NM_PLATFORM_ERROR_SUCCESS = 0,
-
- NM_PLATFORM_ERROR_BUG,
-
- NM_PLATFORM_ERROR_UNSPECIFIED,
-
- NM_PLATFORM_ERROR_NOT_FOUND,
- NM_PLATFORM_ERROR_EXISTS,
- NM_PLATFORM_ERROR_WRONG_TYPE,
- NM_PLATFORM_ERROR_NOT_SLAVE,
- NM_PLATFORM_ERROR_NO_FIRMWARE,
- NM_PLATFORM_ERROR_OPNOTSUPP,
- NM_PLATFORM_ERROR_NETLINK,
- NM_PLATFORM_ERROR_CANT_SET_MTU,
-} NMPlatformError;
-
typedef enum {
/* match-flags are strictly inclusive. That means,
@@ -815,15 +793,15 @@ typedef struct {
const char *(*link_get_udi) (NMPlatform *self, int ifindex);
struct udev_device *(*link_get_udev_device) (NMPlatform *self, int ifindex);
- NMPlatformError (*link_set_user_ipv6ll_enabled) (NMPlatform *, int ifindex, gboolean enabled);
+ int (*link_set_user_ipv6ll_enabled) (NMPlatform *, int ifindex, gboolean enabled);
gboolean (*link_set_token) (NMPlatform *, int ifindex, NMUtilsIPv6IfaceId iid);
gboolean (*link_get_permanent_address) (NMPlatform *,
int ifindex,
guint8 *buf,
size_t *length);
- NMPlatformError (*link_set_address) (NMPlatform *, int ifindex, gconstpointer address, size_t length);
- NMPlatformError (*link_set_mtu) (NMPlatform *, int ifindex, guint32 mtu);
+ int (*link_set_address) (NMPlatform *, int ifindex, gconstpointer address, size_t length);
+ int (*link_set_mtu) (NMPlatform *, int ifindex, guint32 mtu);
gboolean (*link_set_name) (NMPlatform *, int ifindex, const char *name);
gboolean (*link_set_sriov_params) (NMPlatform *, int ifindex, guint num_vfs, int autoprobe);
gboolean (*link_set_sriov_vfs) (NMPlatform *self, int ifindex, const NMPlatformVF *const *vfs);
@@ -951,23 +929,23 @@ typedef struct {
gboolean (*ip4_address_delete) (NMPlatform *, int ifindex, in_addr_t address, guint8 plen, in_addr_t peer_address);
gboolean (*ip6_address_delete) (NMPlatform *, int ifindex, struct in6_addr address, guint8 plen);
- NMPlatformError (*ip_route_add) (NMPlatform *,
- NMPNlmFlags flags,
- int addr_family,
- const NMPlatformIPRoute *route);
- NMPlatformError (*ip_route_get) (NMPlatform *self,
- int addr_family,
- gconstpointer address,
- int oif_ifindex,
- NMPObject **out_route);
+ int (*ip_route_add) (NMPlatform *,
+ NMPNlmFlags flags,
+ int addr_family,
+ const NMPlatformIPRoute *route);
+ int (*ip_route_get) (NMPlatform *self,
+ int addr_family,
+ gconstpointer address,
+ int oif_ifindex,
+ NMPObject **out_route);
- NMPlatformError (*qdisc_add) (NMPlatform *self,
- NMPNlmFlags flags,
- const NMPlatformQdisc *qdisc);
+ int (*qdisc_add) (NMPlatform *self,
+ NMPNlmFlags flags,
+ const NMPlatformQdisc *qdisc);
- NMPlatformError (*tfilter_add) (NMPlatform *self,
- NMPNlmFlags flags,
- const NMPlatformTfilter *tfilter);
+ int (*tfilter_add) (NMPlatform *self,
+ NMPNlmFlags flags,
+ const NMPlatformTfilter *tfilter);
NMPlatformKernelSupportFlags (*check_kernel_support) (NMPlatform * self,
NMPlatformKernelSupportFlags request_flags);
@@ -1096,12 +1074,6 @@ gboolean nm_platform_netns_push (NMPlatform *platform, NMPNetns **netns);
const char *nm_link_type_to_string (NMLinkType link_type);
-const char *nm_platform_error_to_string (NMPlatformError error,
- char *buf,
- gsize buf_len);
-#define nm_platform_error_to_string_a(error) \
- (nm_platform_error_to_string ((error), g_alloca (30), 30))
-
#define NMP_SYSCTL_PATHID_ABSOLUTE(path) \
((const char *) NULL), -1, (path)
@@ -1171,11 +1143,11 @@ const NMPlatformLink *nm_platform_link_get_by_ifname (NMPlatform *self, const ch
const NMPlatformLink *nm_platform_link_get_by_address (NMPlatform *self, NMLinkType link_type, gconstpointer address, size_t length);
GPtrArray *nm_platform_link_get_all (NMPlatform *self, gboolean sort_by_name);
-NMPlatformError nm_platform_link_dummy_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
-NMPlatformError nm_platform_link_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, const NMPlatformLink **out_link);
-NMPlatformError nm_platform_link_bond_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
-NMPlatformError nm_platform_link_team_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
-NMPlatformError nm_platform_link_veth_add (NMPlatform *self, const char *name, const char *peer, const NMPlatformLink **out_link);
+int nm_platform_link_dummy_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
+int nm_platform_link_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, const NMPlatformLink **out_link);
+int nm_platform_link_bond_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
+int nm_platform_link_team_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
+int nm_platform_link_veth_add (NMPlatform *self, const char *name, const char *peer, const NMPlatformLink **out_link);
gboolean nm_platform_link_delete (NMPlatform *self, int ifindex);
@@ -1246,12 +1218,12 @@ const char *nm_platform_link_get_udi (NMPlatform *self, int ifindex);
struct udev_device *nm_platform_link_get_udev_device (NMPlatform *self, int ifindex);
-NMPlatformError nm_platform_link_set_user_ipv6ll_enabled (NMPlatform *self, int ifindex, gboolean enabled);
+int nm_platform_link_set_user_ipv6ll_enabled (NMPlatform *self, int ifindex, gboolean enabled);
gboolean nm_platform_link_set_ipv6_token (NMPlatform *self, int ifindex, NMUtilsIPv6IfaceId iid);
gboolean nm_platform_link_get_permanent_address (NMPlatform *self, int ifindex, guint8 *buf, size_t *length);
-NMPlatformError nm_platform_link_set_address (NMPlatform *self, int ifindex, const void *address, size_t length);
-NMPlatformError nm_platform_link_set_mtu (NMPlatform *self, int ifindex, guint32 mtu);
+int nm_platform_link_set_address (NMPlatform *self, int ifindex, const void *address, size_t length);
+int nm_platform_link_set_mtu (NMPlatform *self, int ifindex, guint32 mtu);
gboolean nm_platform_link_set_name (NMPlatform *self, int ifindex, const char *name);
gboolean nm_platform_link_set_sriov_params (NMPlatform *self, int ifindex, guint num_vfs, int autoprobe);
gboolean nm_platform_link_set_sriov_vfs (NMPlatform *self, int ifindex, const NMPlatformVF *const *vfs);
@@ -1295,12 +1267,12 @@ const NMPlatformLnkVlan *nm_platform_link_get_lnk_vlan (NMPlatform *self, int if
const NMPlatformLnkVxlan *nm_platform_link_get_lnk_vxlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link);
const NMPlatformLnkWireGuard *nm_platform_link_get_lnk_wireguard (NMPlatform *self, int ifindex, const NMPlatformLink **out_link);
-NMPlatformError nm_platform_link_vlan_add (NMPlatform *self,
- const char *name,
- int parent,
- int vlanid,
- guint32 vlanflags,
- const NMPlatformLink **out_link);
+int nm_platform_link_vlan_add (NMPlatform *self,
+ const char *name,
+ int parent,
+ int vlanid,
+ guint32 vlanflags,
+ const NMPlatformLink **out_link);
gboolean nm_platform_link_vlan_set_ingress_map (NMPlatform *self, int ifindex, int from, int to);
gboolean nm_platform_link_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, int to);
gboolean nm_platform_link_vlan_change (NMPlatform *self,
@@ -1314,18 +1286,18 @@ gboolean nm_platform_link_vlan_change (NMPlatform *self,
const NMVlanQosMapping *egress_map,
gsize n_egress_map);
-NMPlatformError nm_platform_link_vxlan_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkVxlan *props,
- const NMPlatformLink **out_link);
-
-NMPlatformError nm_platform_link_infiniband_add (NMPlatform *self,
- int parent,
- int p_key,
- const NMPlatformLink **out_link);
-NMPlatformError nm_platform_link_infiniband_delete (NMPlatform *self,
- int parent,
- int p_key);
+int nm_platform_link_vxlan_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLnkVxlan *props,
+ const NMPlatformLink **out_link);
+
+int nm_platform_link_infiniband_add (NMPlatform *self,
+ int parent,
+ int p_key,
+ const NMPlatformLink **out_link);
+int nm_platform_link_infiniband_delete (NMPlatform *self,
+ int parent,
+ int p_key);
gboolean nm_platform_link_infiniband_get_properties (NMPlatform *self, int ifindex, int *parent, int *p_key, const char **mode);
gboolean nm_platform_link_veth_get_properties (NMPlatform *self, int ifindex, int *out_peer_ifindex);
@@ -1361,45 +1333,45 @@ const struct in6_addr *nm_platform_ip6_address_get_peer (const NMPlatformIP6Addr
const NMPlatformIP4Address *nm_platform_ip4_address_get (NMPlatform *self, int ifindex, in_addr_t address, guint8 plen, in_addr_t peer_address);
-NMPlatformError nm_platform_link_gre_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkGre *props,
- const NMPlatformLink **out_link);
-NMPlatformError nm_platform_link_ip6tnl_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkIp6Tnl *props,
- const NMPlatformLink **out_link);
-NMPlatformError nm_platform_link_ip6gre_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkIp6Tnl *props,
- const NMPlatformLink **out_link);
-NMPlatformError nm_platform_link_ipip_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkIpIp *props,
- const NMPlatformLink **out_link);
-NMPlatformError nm_platform_link_macsec_add (NMPlatform *self,
- const char *name,
- int parent,
- const NMPlatformLnkMacsec *props,
- const NMPlatformLink **out_link);
-NMPlatformError nm_platform_link_macvlan_add (NMPlatform *self,
- const char *name,
- int parent,
- const NMPlatformLnkMacvlan *props,
- const NMPlatformLink **out_link);
-NMPlatformError nm_platform_link_sit_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkSit *props,
- const NMPlatformLink **out_link);
-NMPlatformError nm_platform_link_tun_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkTun *props,
- const NMPlatformLink **out_link,
- int *out_fd);
-NMPlatformError nm_platform_link_6lowpan_add (NMPlatform *self,
- const char *name,
- int parent,
- const NMPlatformLink **out_link);
+int nm_platform_link_gre_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLnkGre *props,
+ const NMPlatformLink **out_link);
+int nm_platform_link_ip6tnl_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLnkIp6Tnl *props,
+ const NMPlatformLink **out_link);
+int nm_platform_link_ip6gre_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLnkIp6Tnl *props,
+ const NMPlatformLink **out_link);
+int nm_platform_link_ipip_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLnkIpIp *props,
+ const NMPlatformLink **out_link);
+int nm_platform_link_macsec_add (NMPlatform *self,
+ const char *name,
+ int parent,
+ const NMPlatformLnkMacsec *props,
+ const NMPlatformLink **out_link);
+int nm_platform_link_macvlan_add (NMPlatform *self,
+ const char *name,
+ int parent,
+ const NMPlatformLnkMacvlan *props,
+ const NMPlatformLink **out_link);
+int nm_platform_link_sit_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLnkSit *props,
+ const NMPlatformLink **out_link);
+int nm_platform_link_tun_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLnkTun *props,
+ const NMPlatformLink **out_link,
+ int *out_fd);
+int nm_platform_link_6lowpan_add (NMPlatform *self,
+ const char *name,
+ int parent,
+ const NMPlatformLink **out_link);
gboolean nm_platform_link_6lowpan_get_properties (NMPlatform *self,
int ifindex,
int *out_parent);
@@ -1436,11 +1408,11 @@ gboolean nm_platform_ip_address_flush (NMPlatform *self,
void nm_platform_ip_route_normalize (int addr_family,
NMPlatformIPRoute *route);
-NMPlatformError nm_platform_ip_route_add (NMPlatform *self,
- NMPNlmFlags flags,
- const NMPObject *route);
-NMPlatformError nm_platform_ip4_route_add (NMPlatform *self, NMPNlmFlags flags, const NMPlatformIP4Route *route);
-NMPlatformError nm_platform_ip6_route_add (NMPlatform *self, NMPNlmFlags flags, const NMPlatformIP6Route *route);
+int nm_platform_ip_route_add (NMPlatform *self,
+ NMPNlmFlags flags,
+ const NMPObject *route);
+int nm_platform_ip4_route_add (NMPlatform *self, NMPNlmFlags flags, const NMPlatformIP4Route *route);
+int nm_platform_ip6_route_add (NMPlatform *self, NMPNlmFlags flags, const NMPlatformIP6Route *route);
GPtrArray *nm_platform_ip_route_get_prune_list (NMPlatform *self,
int addr_family,
@@ -1458,22 +1430,22 @@ gboolean nm_platform_ip_route_flush (NMPlatform *self,
int addr_family,
int ifindex);
-NMPlatformError nm_platform_ip_route_get (NMPlatform *self,
- int addr_family,
- gconstpointer address,
- int oif_ifindex,
- NMPObject **out_route);
+int nm_platform_ip_route_get (NMPlatform *self,
+ int addr_family,
+ gconstpointer address,
+ int oif_ifindex,
+ NMPObject **out_route);
-NMPlatformError nm_platform_qdisc_add (NMPlatform *self,
- NMPNlmFlags flags,
- const NMPlatformQdisc *qdisc);
+int nm_platform_qdisc_add (NMPlatform *self,
+ NMPNlmFlags flags,
+ const NMPlatformQdisc *qdisc);
gboolean nm_platform_qdisc_sync (NMPlatform *self,
int ifindex,
GPtrArray *known_qdiscs);
-NMPlatformError nm_platform_tfilter_add (NMPlatform *self,
- NMPNlmFlags flags,
- const NMPlatformTfilter *tfilter);
+int nm_platform_tfilter_add (NMPlatform *self,
+ NMPNlmFlags flags,
+ const NMPlatformTfilter *tfilter);
gboolean nm_platform_tfilter_sync (NMPlatform *self,
int ifindex,
GPtrArray *known_tfilters);
diff --git a/src/platform/tests/test-cleanup.c b/src/platform/tests/test-cleanup.c
index 962ae16b63..6c73a63ed8 100644
--- a/src/platform/tests/test-cleanup.c
+++ b/src/platform/tests/test-cleanup.c
@@ -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));
diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c
index 5e935b6d77..8e29b5ce8d 100644
--- a/src/platform/tests/test-common.c
+++ b/src/platform/tests/test-common.c
@@ -1010,7 +1010,7 @@ void nmtstp_ip4_route_add (NMPlatform *platform,
route.metric = metric;
route.mss = mss;
- g_assert_cmpint (nm_platform_ip4_route_add (platform, NMP_NLM_FLAG_REPLACE, &route), ==, NM_PLATFORM_ERROR_SUCCESS);
+ g_assert (NMTST_NM_ERR_SUCCESS (nm_platform_ip4_route_add (platform, NMP_NLM_FLAG_REPLACE, &route)));
}
void nmtstp_ip6_route_add (NMPlatform *platform,
@@ -1034,7 +1034,7 @@ void nmtstp_ip6_route_add (NMPlatform *platform,
route.metric = metric;
route.mss = mss;
- g_assert_cmpint (nm_platform_ip6_route_add (platform, NMP_NLM_FLAG_REPLACE, &route), ==, NM_PLATFORM_ERROR_SUCCESS);
+ g_assert (NMTST_NM_ERR_SUCCESS (nm_platform_ip6_route_add (platform, NMP_NLM_FLAG_REPLACE, &route)));
}
/*****************************************************************************/
@@ -1203,7 +1203,7 @@ nmtstp_link_veth_add (NMPlatform *platform,
nmtstp_assert_wait_for_link (platform, peer, NM_LINK_TYPE_VETH, 10);
}
} else
- success = nm_platform_link_veth_add (platform, name, peer, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
+ success = NMTST_NM_ERR_SUCCESS (nm_platform_link_veth_add (platform, name, peer, &pllink));
g_assert (success);
_assert_pllink (platform, success, pllink, name, NM_LINK_TYPE_VETH);
@@ -1230,7 +1230,7 @@ nmtstp_link_dummy_add (NMPlatform *platform,
if (success)
pllink = nmtstp_assert_wait_for_link (platform, name, NM_LINK_TYPE_DUMMY, 100);
} else
- success = nm_platform_link_dummy_add (platform, name, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
+ success = NMTST_NM_ERR_SUCCESS (nm_platform_link_dummy_add (platform, name, &pllink));
g_assert (success);
_assert_pllink (platform, success, pllink, name, NM_LINK_TYPE_DUMMY);
@@ -1279,7 +1279,7 @@ nmtstp_link_gre_add (NMPlatform *platform,
if (success)
pllink = nmtstp_assert_wait_for_link (platform, name, link_type, 100);
} else
- success = nm_platform_link_gre_add (platform, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
+ success = NMTST_NM_ERR_SUCCESS (nm_platform_link_gre_add (platform, name, lnk, &pllink));
_assert_pllink (platform, success, pllink, name, link_type);
@@ -1342,7 +1342,7 @@ nmtstp_link_ip6tnl_add (NMPlatform *platform,
if (success)
pllink = nmtstp_assert_wait_for_link (platform, name, NM_LINK_TYPE_IP6TNL, 100);
} else
- success = nm_platform_link_ip6tnl_add (platform, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
+ success = NMTST_NM_ERR_SUCCESS (nm_platform_link_ip6tnl_add (platform, name, lnk, &pllink));
_assert_pllink (platform, success, pllink, name, NM_LINK_TYPE_IP6TNL);
@@ -1393,7 +1393,7 @@ nmtstp_link_ip6gre_add (NMPlatform *platform,
100);
}
} else
- success = nm_platform_link_ip6gre_add (platform, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
+ success = NMTST_NM_ERR_SUCCESS (nm_platform_link_ip6gre_add (platform, name, lnk, &pllink));
_assert_pllink (platform, success, pllink, name, lnk->is_tap ? NM_LINK_TYPE_IP6GRETAP : NM_LINK_TYPE_IP6GRE);
@@ -1434,7 +1434,7 @@ nmtstp_link_ipip_add (NMPlatform *platform,
if (success)
pllink = nmtstp_assert_wait_for_link (platform, name, NM_LINK_TYPE_IPIP, 100);
} else
- success = nm_platform_link_ipip_add (platform, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
+ success = NMTST_NM_ERR_SUCCESS (nm_platform_link_ipip_add (platform, name, lnk, &pllink));
_assert_pllink (platform, success, pllink, name, NM_LINK_TYPE_IPIP);
@@ -1482,7 +1482,7 @@ nmtstp_link_macvlan_add (NMPlatform *platform,
if (success)
pllink = nmtstp_assert_wait_for_link (platform, name, link_type, 100);
} else
- success = nm_platform_link_macvlan_add (platform, name, parent, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
+ success = NMTST_NM_ERR_SUCCESS (nm_platform_link_macvlan_add (platform, name, parent, lnk, &pllink));
_assert_pllink (platform, success, pllink, name, link_type);
@@ -1528,7 +1528,7 @@ nmtstp_link_sit_add (NMPlatform *platform,
if (success)
pllink = nmtstp_assert_wait_for_link (platform, name, NM_LINK_TYPE_SIT, 100);
} else
- success = nm_platform_link_sit_add (platform, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
+ success = NMTST_NM_ERR_SUCCESS (nm_platform_link_sit_add (platform, name, lnk, &pllink));
_assert_pllink (platform, success, pllink, name, NM_LINK_TYPE_SIT);
@@ -1543,8 +1543,8 @@ nmtstp_link_tun_add (NMPlatform *platform,
int *out_fd)
{
const NMPlatformLink *pllink = NULL;
- NMPlatformError plerr;
int err;
+ int r;
g_assert (nm_utils_is_valid_iface_name (name, NULL));
g_assert (lnk);
@@ -1589,8 +1589,8 @@ nmtstp_link_tun_add (NMPlatform *platform,
g_error ("failure to add tun/tap device via ip-route");
} else {
g_assert (lnk->persist || out_fd);
- plerr = nm_platform_link_tun_add (platform, name, lnk, &pllink, out_fd);
- g_assert_cmpint (plerr, ==, NM_PLATFORM_ERROR_SUCCESS);
+ r = nm_platform_link_tun_add (platform, name, lnk, &pllink, out_fd);
+ g_assert_cmpint (r, ==, 0);
}
g_assert (pllink);
@@ -1606,8 +1606,8 @@ nmtstp_link_vxlan_add (NMPlatform *platform,
const NMPlatformLnkVxlan *lnk)
{
const NMPlatformLink *pllink = NULL;
- NMPlatformError plerr;
int err;
+ int r;
g_assert (nm_utils_is_valid_iface_name (name, NULL));
@@ -1656,8 +1656,8 @@ nmtstp_link_vxlan_add (NMPlatform *platform,
_LOGI ("Adding vxlan device via iproute2 failed. Assume iproute2 is not up to the task.");
}
if (!pllink) {
- plerr = nm_platform_link_vxlan_add (platform, name, lnk, &pllink);
- g_assert_cmpint (plerr, ==, NM_PLATFORM_ERROR_SUCCESS);
+ r = nm_platform_link_vxlan_add (platform, name, lnk, &pllink);
+ g_assert (NMTST_NM_ERR_SUCCESS (r));
g_assert (pllink);
}
diff --git a/src/platform/tests/test-common.h b/src/platform/tests/test-common.h
index c49fc0b87e..048fd9dd8d 100644
--- a/src/platform/tests/test-common.h
+++ b/src/platform/tests/test-common.h
@@ -352,7 +352,7 @@ _nmtstp_env1_wrapper_setup (const NmtstTestData *test_data)
nmtstp_link_delete (NM_PLATFORM_GET, -1, -1, DEVICE_NAME, FALSE);
- g_assert_cmpint (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)));
*p_ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME);
g_assert_cmpint (*p_ifindex, >, 0);
diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c
index fd72a1aa70..b3fd2bc0ae 100644
--- a/src/platform/tests/test-link.c
+++ b/src/platform/tests/test-link.c
@@ -47,7 +47,7 @@
#define MTU 1357
#define _ADD_DUMMY(platform, name) \
- g_assert_cmpint (nm_platform_link_dummy_add ((platform), (name), NULL), ==, NM_PLATFORM_ERROR_SUCCESS)
+ g_assert (NMTST_NM_ERR_SUCCESS (nm_platform_link_dummy_add ((platform), (name), NULL)))
static void
test_bogus(void)
@@ -77,7 +77,7 @@ test_bogus(void)
g_assert (!addrlen);
g_assert (!nm_platform_link_get_address (NM_PLATFORM_GET, BOGUS_IFINDEX, NULL));
- g_assert (nm_platform_link_set_mtu (NM_PLATFORM_GET, BOGUS_IFINDEX, MTU) != NM_PLATFORM_ERROR_SUCCESS);
+ g_assert (!NMTST_NM_ERR_SUCCESS (nm_platform_link_set_mtu (NM_PLATFORM_GET, BOGUS_IFINDEX, MTU)));
g_assert (!nm_platform_link_get_mtu (NM_PLATFORM_GET, BOGUS_IFINDEX));
@@ -107,30 +107,30 @@ software_add (NMLinkType link_type, const char *name)
{
switch (link_type) {
case NM_LINK_TYPE_DUMMY:
- return nm_platform_link_dummy_add (NM_PLATFORM_GET, name, NULL) == NM_PLATFORM_ERROR_SUCCESS;
+ return NMTST_NM_ERR_SUCCESS (nm_platform_link_dummy_add (NM_PLATFORM_GET, name, NULL));
case NM_LINK_TYPE_BRIDGE:
- return nm_platform_link_bridge_add (NM_PLATFORM_GET, name, NULL, 0, NULL) == NM_PLATFORM_ERROR_SUCCESS;
+ return NMTST_NM_ERR_SUCCESS (nm_platform_link_bridge_add (NM_PLATFORM_GET, name, NULL, 0, NULL));
case NM_LINK_TYPE_BOND:
{
gboolean bond0_exists = !!nm_platform_link_get_by_ifname (NM_PLATFORM_GET, "bond0");
- NMPlatformError plerr;
+ int r;
- plerr = nm_platform_link_bond_add (NM_PLATFORM_GET, name, NULL);
+ r = nm_platform_link_bond_add (NM_PLATFORM_GET, name, NULL);
/* Check that bond0 is *not* automatically created. */
if (!bond0_exists)
g_assert (!nm_platform_link_get_by_ifname (NM_PLATFORM_GET, "bond0"));
- return plerr == NM_PLATFORM_ERROR_SUCCESS;
+ return r >= 0;
}
case NM_LINK_TYPE_TEAM:
- return nm_platform_link_team_add (NM_PLATFORM_GET, name, NULL) == NM_PLATFORM_ERROR_SUCCESS;
+ return NMTST_NM_ERR_SUCCESS (nm_platform_link_team_add (NM_PLATFORM_GET, name, NULL));
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_link_bridge_add (NM_PLATFORM_GET, PARENT_NAME, NULL, 0, NULL) == NM_PLATFORM_ERROR_SUCCESS)
+ if (NMTST_NM_ERR_SUCCESS (nm_platform_link_bridge_add (NM_PLATFORM_GET, PARENT_NAME, NULL, 0, NULL)))
accept_signal (parent_added);
free_signal (parent_added);
@@ -147,7 +147,7 @@ software_add (NMLinkType link_type, const char *name)
accept_signals (parent_changed, 1, 2);
free_signal (parent_changed);
- return nm_platform_link_vlan_add (NM_PLATFORM_GET, name, parent_ifindex, VLAN_ID, 0, NULL) == NM_PLATFORM_ERROR_SUCCESS;
+ return NMTST_NM_ERR_SUCCESS (nm_platform_link_vlan_add (NM_PLATFORM_GET, name, parent_ifindex, VLAN_ID, 0, NULL));
}
}
default:
@@ -502,7 +502,7 @@ test_bridge_addr (void)
nm_utils_hwaddr_aton ("de:ad:be:ef:00:11", addr, sizeof (addr));
- g_assert_cmpint (nm_platform_link_bridge_add (NM_PLATFORM_GET, DEVICE_NAME, addr, sizeof (addr), &plink), ==, NM_PLATFORM_ERROR_SUCCESS);
+ g_assert (NMTST_NM_ERR_SUCCESS (nm_platform_link_bridge_add (NM_PLATFORM_GET, DEVICE_NAME, addr, sizeof (addr), &plink)));
g_assert (plink);
link = *plink;
g_assert_cmpstr (link.name, ==, DEVICE_NAME);
@@ -518,13 +518,13 @@ test_bridge_addr (void)
g_assert (!nm_platform_link_get_user_ipv6ll_enabled (NM_PLATFORM_GET, link.ifindex));
g_assert_cmpint (_nm_platform_uint8_inv (plink->inet6_addr_gen_mode_inv), ==, NM_IN6_ADDR_GEN_MODE_EUI64);
- g_assert (nm_platform_link_set_user_ipv6ll_enabled (NM_PLATFORM_GET, link.ifindex, TRUE) == NM_PLATFORM_ERROR_SUCCESS);
+ g_assert (NMTST_NM_ERR_SUCCESS (nm_platform_link_set_user_ipv6ll_enabled (NM_PLATFORM_GET, link.ifindex, TRUE)));
g_assert (nm_platform_link_get_user_ipv6ll_enabled (NM_PLATFORM_GET, link.ifindex));
plink = nm_platform_link_get (NM_PLATFORM_GET, link.ifindex);
g_assert (plink);
g_assert_cmpint (_nm_platform_uint8_inv (plink->inet6_addr_gen_mode_inv), ==, NM_IN6_ADDR_GEN_MODE_NONE);
- g_assert (nm_platform_link_set_user_ipv6ll_enabled (NM_PLATFORM_GET, link.ifindex, FALSE) == NM_PLATFORM_ERROR_SUCCESS);
+ g_assert (NMTST_NM_ERR_SUCCESS (nm_platform_link_set_user_ipv6ll_enabled (NM_PLATFORM_GET, link.ifindex, FALSE)));
g_assert (!nm_platform_link_get_user_ipv6ll_enabled (NM_PLATFORM_GET, link.ifindex));
plink = nm_platform_link_get (NM_PLATFORM_GET, link.ifindex);
g_assert (plink);
@@ -554,11 +554,11 @@ test_internal (void)
g_assert (!nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME));
/* Add 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);
/* Try to add again */
- g_assert (nm_platform_link_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == NM_PLATFORM_ERROR_EXISTS);
+ g_assert (nm_platform_link_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == -NME_PL_EXISTS);
/* Check device index, name and type */
ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME);
@@ -595,7 +595,7 @@ test_internal (void)
g_assert (nm_platform_link_supports_vlans (NM_PLATFORM_GET, ifindex));
/* Set MAC address */
- g_assert (nm_platform_link_set_address (NM_PLATFORM_GET, ifindex, mac, sizeof (mac)) == NM_PLATFORM_ERROR_SUCCESS);
+ g_assert (NMTST_NM_ERR_SUCCESS (nm_platform_link_set_address (NM_PLATFORM_GET, ifindex, mac, sizeof (mac))));
address = nm_platform_link_get_address (NM_PLATFORM_GET, ifindex, &addrlen);
g_assert (addrlen == sizeof(mac));
g_assert (!memcmp (address, mac, addrlen));
@@ -604,7 +604,7 @@ test_internal (void)
accept_signal (link_changed);
/* Set MTU */
- g_assert (nm_platform_link_set_mtu (NM_PLATFORM_GET, ifindex, MTU) == NM_PLATFORM_ERROR_SUCCESS);
+ g_assert (NMTST_NM_ERR_SUCCESS (nm_platform_link_set_mtu (NM_PLATFORM_GET, ifindex, MTU)));
g_assert_cmpint (nm_platform_link_get_mtu (NM_PLATFORM_GET, ifindex), ==, MTU);
accept_signal (link_changed);
diff --git a/src/platform/tests/test-route.c b/src/platform/tests/test-route.c
index 85b14b57ac..4c0f686f4e 100644
--- a/src/platform/tests/test-route.c
+++ b/src/platform/tests/test-route.c
@@ -427,7 +427,7 @@ test_ip4_route_get (void)
{
int ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME);
in_addr_t a;
- NMPlatformError result;
+ int result;
nm_auto_nmpobj NMPObject *route = NULL;
const NMPlatformIP4Route *r;
@@ -446,7 +446,7 @@ test_ip4_route_get (void)
nmtst_get_rand_int () % 2 ? 0 : ifindex,
&route);
- g_assert (result == NM_PLATFORM_ERROR_SUCCESS);
+ g_assert (NMTST_NM_ERR_SUCCESS (result));
g_assert (NMP_OBJECT_GET_TYPE (route) == NMP_OBJECT_TYPE_IP4_ROUTE);
g_assert (!NMP_OBJECT_IS_STACKINIT (route));
g_assert (route->parent._ref_count == 1);
@@ -565,7 +565,7 @@ test_ip4_route_options (gconstpointer test_data)
}
for (i = 0; i < rts_n; i++)
- g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, NMP_NLM_FLAG_REPLACE, &rts_add[i]) == NM_PLATFORM_ERROR_SUCCESS);
+ g_assert (NMTST_NM_ERR_SUCCESS (nm_platform_ip4_route_add (NM_PLATFORM_GET, NMP_NLM_FLAG_REPLACE, &rts_add[i])));
for (i = 0; i < rts_n; i++) {
rts_cmp[i] = rts_add[i];
@@ -589,7 +589,7 @@ test_ip6_route_get (void)
{
int ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME);
const struct in6_addr *a;
- NMPlatformError result;
+ int result;
nm_auto_nmpobj NMPObject *route = NULL;
const NMPlatformIP6Route *r;
@@ -608,7 +608,7 @@ test_ip6_route_get (void)
nmtst_get_rand_int () % 2 ? 0 : ifindex,
&route);
- g_assert (result == NM_PLATFORM_ERROR_SUCCESS);
+ g_assert (NMTST_NM_ERR_SUCCESS (result));
g_assert (NMP_OBJECT_GET_TYPE (route) == NMP_OBJECT_TYPE_IP6_ROUTE);
g_assert (!NMP_OBJECT_IS_STACKINIT (route));
g_assert (route->parent._ref_count == 1);
@@ -724,7 +724,7 @@ test_ip6_route_options (gconstpointer test_data)
_wait_for_ipv6_addr_non_tentative (NM_PLATFORM_GET, 400, IFINDEX, addr_n, addr_in6);
for (i = 0; i < rts_n; i++)
- g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, NMP_NLM_FLAG_REPLACE, &rts_add[i]) == NM_PLATFORM_ERROR_SUCCESS);
+ g_assert (NMTST_NM_ERR_SUCCESS (nm_platform_ip6_route_add (NM_PLATFORM_GET, NMP_NLM_FLAG_REPLACE, &rts_add[i])));
for (i = 0; i < rts_n; i++) {
rts_cmp[i] = rts_add[i];
@@ -823,7 +823,7 @@ again_find_idx:
order_idx[order_len++] = idx;
r->ifindex = iface_data[idx].ifindex;
- g_assert (nm_platform_ip4_route_add (platform, NMP_NLM_FLAG_APPEND, r) == NM_PLATFORM_ERROR_SUCCESS);
+ g_assert (NMTST_NM_ERR_SUCCESS (nm_platform_ip4_route_add (platform, NMP_NLM_FLAG_APPEND, r)));
} else {
i = nmtst_get_rand_int () % order_len;
idx = order_idx[i];
diff --git a/src/vpn/nm-vpn-connection.c b/src/vpn/nm-vpn-connection.c
index a4a38f45fe..26c9a7a5ea 100644
--- a/src/vpn/nm-vpn-connection.c
+++ b/src/vpn/nm-vpn-connection.c
@@ -725,7 +725,7 @@ add_ip4_vpn_gateway_route (NMIP4Config *config,
AF_INET,
&vpn_gw,
ifindex,
- (NMPObject **) &route_resolved) == NM_PLATFORM_ERROR_SUCCESS) {
+ (NMPObject **) &route_resolved) >= 0) {
const NMPlatformIP4Route *r = NMP_OBJECT_CAST_IP4_ROUTE (route_resolved);
if (r->ifindex == ifindex) {
@@ -799,7 +799,7 @@ add_ip6_vpn_gateway_route (NMIP6Config *config,
AF_INET6,
vpn_gw,
ifindex,
- (NMPObject **) &route_resolved) == NM_PLATFORM_ERROR_SUCCESS) {
+ (NMPObject **) &route_resolved) >= 0) {
const NMPlatformIP6Route *r = NMP_OBJECT_CAST_IP6_ROUTE (route_resolved);
if (r->ifindex == ifindex) {