summaryrefslogtreecommitdiff
path: root/src/platform/nm-netlink.h
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-02-16 15:03:42 +0100
committerThomas Haller <thaller@redhat.com>2018-02-21 12:08:46 +0100
commitb6f31a2d228466be556d02ea1b166453eba45c0a (patch)
tree87a5d62a7c5ce765688c2357bd2b9665819af736 /src/platform/nm-netlink.h
parentf3a0f60e9a9061e930e3e151700e791739c81ad5 (diff)
netlink: refactor error numbers from netlink
Originally, these were error numbers from libnl3. These error numbers are separate from errno, which is unfortunate, because sometimes we care about the native errno returned from kernel. Now, refactor them so that the error numbers are in the shared realm of errno, but failures from kernel or underlying API are still returned via their native errno. - NLE_INVAL doesn't exist anymore. Passing invalid arguments to a function is commonly a bug. g_return_*(NLE_BUG) is the right answer to that. - NLE_NOMEM and NLE_AGAIN is replaced by their errno counterparts. - drop several error numbers. If nobody cares about these numbers, there is no reason to have a specific error number for them. NLE_UNSPEC is sufficient.
Diffstat (limited to 'src/platform/nm-netlink.h')
-rw-r--r--src/platform/nm-netlink.h68
1 files changed, 39 insertions, 29 deletions
diff --git a/src/platform/nm-netlink.h b/src/platform/nm-netlink.h
index b3749de1d3..e5cf11f3e7 100644
--- a/src/platform/nm-netlink.h
+++ b/src/platform/nm-netlink.h
@@ -27,44 +27,54 @@
/*****************************************************************************/
-#define NLE_AGAIN EAGAIN
-#define NLE_NOMEM ENOMEM
-#define NLE_BAD_SOCK EBADF
-#define NLE_INVAL EINVAL
-#define NLE_RANGE ERANGE
-#define NLE_OBJ_NOTFOUND ENOENT
-#define NLE_NOADDR EADDRNOTAVAIL
-#define NLE_MSG_OVERFLOW EOVERFLOW
-#define NLE_AF_NOSUPPORT EAFNOSUPPORT
-
-#define NLE_SEQ_MISMATCH 10016
-#define NLE_MSG_TRUNC 10018
-#define NLE_MSG_TOOSHORT 10021
-#define NLE_DUMP_INTR 10033
-#define NLE_ATTRSIZE 10034
-#define NLE_BUG 19000
+#define _NLE_BASE 100000
+#define NLE_UNSPEC (_NLE_BASE + 0)
+#define NLE_BUG (_NLE_BASE + 1)
+#define NLE_NATIVE_ERRNO (_NLE_BASE + 2)
+#define NLE_SEQ_MISMATCH (_NLE_BASE + 3)
+#define NLE_MSG_TRUNC (_NLE_BASE + 4)
+#define NLE_MSG_TOOSHORT (_NLE_BASE + 5)
+#define NLE_DUMP_INTR (_NLE_BASE + 6)
+#define NLE_ATTRSIZE (_NLE_BASE + 7)
+#define NLE_BAD_SOCK (_NLE_BASE + 8)
+#define NLE_NOADDR (_NLE_BASE + 12)
+#define NLE_MSG_OVERFLOW (_NLE_BASE + 13)
+
+/* user errors, these errors are never returned by netlink functions themself,
+ * but are reserved for other components. */
+#define NLE_USER_NOBUFS (_NLE_BASE + 15)
+#define NLE_USER_MSG_TRUNC (_NLE_BASE + 16)
+
+#define _NLE_BASE_END (_NLE_BASE + 17)
static inline int
-nl_errno (int error)
+nl_errno (int err)
{
- /* the error codes from our netlink implementation are plain errno.
- * However, often we encode them as negative values.
+ /* the error codes from our netlink implementation are plain errno
+ * extended with our own error in a particular range starting from
+ * _NLE_BASE.
*
- * A negative errno is the same as it's positive counterpart.
- *
- * This function normalizes the error code and always returns a
- * non-negative value. */
- return error >= 0
- ? error
- : ((error == G_MININT) ? NLE_BUG : -errno);
+ * However, often we encode errors as negative values. This function
+ * normalizes the error and returns it's positive value. */
+ return err >= 0
+ ? err
+ : ((err == G_MININT) ? NLE_BUG : -errno);
}
-static inline const char *
-nl_geterror (int error)
+static inline int
+nl_syserr2nlerr (int err)
{
- return g_strerror (nl_errno (error));
+ if (err == G_MININT)
+ return NLE_NATIVE_ERRNO;
+ if (err < 0)
+ err = -err;
+ return (err >= _NLE_BASE && err < _NLE_BASE_END)
+ ? NLE_NATIVE_ERRNO
+ : err;
}
+const char *nl_geterror (int err);
+
/*****************************************************************************/
/* Basic attribute data types */