core: move netlink errors to nm-errno.h
No other changes (yet).
This commit is contained in:
@@ -23,3 +23,33 @@
|
||||
#include "nm-errno.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_geterror, int,
|
||||
NM_UTILS_LOOKUP_DEFAULT (NULL),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_UNSPEC, "NLE_UNSPEC"),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_BUG, "NLE_BUG"),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_NATIVE_ERRNO, "NLE_NATIVE_ERRNO"),
|
||||
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_ATTRSIZE, "NLE_ATTRSIZE"),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_BAD_SOCK, "NLE_BAD_SOCK"),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_DUMP_INTR, "NLE_DUMP_INTR"),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_MSG_OVERFLOW, "NLE_MSG_OVERFLOW"),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_MSG_TOOSHORT, "NLE_MSG_TOOSHORT"),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_MSG_TRUNC, "NLE_MSG_TRUNC"),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_SEQ_MISMATCH, "NLE_SEQ_MISMATCH"),
|
||||
)
|
||||
|
||||
const char *
|
||||
nl_geterror (int nlerr)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
nlerr = nl_errno (nlerr);
|
||||
|
||||
if (nlerr >= _NLE_BASE) {
|
||||
s = _geterror (nlerr);
|
||||
if (s)
|
||||
return s;
|
||||
}
|
||||
return g_strerror (nlerr);
|
||||
}
|
||||
|
@@ -23,4 +23,69 @@
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#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 + 9)
|
||||
#define NLE_MSG_OVERFLOW (_NLE_BASE + 10)
|
||||
|
||||
#define _NLE_BASE_END (_NLE_BASE + 11)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline int
|
||||
nl_errno (int nlerr)
|
||||
{
|
||||
/* Normalizes an netlink error to be positive. Various API returns negative
|
||||
* error codes, and this function converts the negative value to its
|
||||
* positive.
|
||||
*
|
||||
* It's very similar to nm_errno(), but not exactly. The difference is that
|
||||
* nm_errno() is for plain errno, while nl_errno() is for netlink error numbers.
|
||||
* Yes, netlink error number are ~almost~ the same as errno, except that a particular
|
||||
* range (_NLE_BASE, _NLE_BASE_END) is reserved. The difference between the two
|
||||
* functions is only how G_MININT is mapped.
|
||||
*
|
||||
* See also nl_syserr2nlerr() below. */
|
||||
return nlerr >= 0
|
||||
? nlerr
|
||||
: ((nlerr == G_MININT) ? NLE_BUG : -nlerr);
|
||||
}
|
||||
|
||||
static inline int
|
||||
nl_syserr2nlerr (int errsv)
|
||||
{
|
||||
/* this maps a native errno to a (always non-negative) netlink error number.
|
||||
*
|
||||
* Note that netlink error numbers are embedded into the range of regular
|
||||
* errno. The only difference is, that netlink error numbers reserve a
|
||||
* range (_NLE_BASE, _NLE_BASE_END) for their own purpose.
|
||||
*
|
||||
* That means, converting an errno to netlink error number means in
|
||||
* most cases just returning itself (negative values are normalized
|
||||
* to be positive). Only values G_MININT and [_NLE_BASE, _NLE_BASE_END]
|
||||
* are coerced to the special value NLE_NATIVE_ERRNO, as they cannot
|
||||
* otherwise be represented in netlink error number domain. */
|
||||
if (errsv == G_MININT)
|
||||
return NLE_NATIVE_ERRNO;
|
||||
if (errsv < 0)
|
||||
errsv = -errsv;
|
||||
return (errsv >= _NLE_BASE && errsv < _NLE_BASE_END)
|
||||
? NLE_NATIVE_ERRNO
|
||||
: errsv;
|
||||
}
|
||||
|
||||
const char *nl_geterror (int nlerr);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#endif /* __NM_ERRNO_H__ */
|
||||
|
@@ -44,6 +44,7 @@
|
||||
#include "nm-core-internal.h"
|
||||
#include "nm-setting-vlan.h"
|
||||
|
||||
#include "nm-utils/nm-errno.h"
|
||||
#include "nm-utils/nm-secret-utils.h"
|
||||
#include "nm-netlink.h"
|
||||
#include "nm-core-utils.h"
|
||||
|
@@ -25,6 +25,8 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "nm-utils/nm-errno.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef SOL_NETLINK
|
||||
@@ -67,38 +69,6 @@ struct nl_sock {
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_geterror, int,
|
||||
NM_UTILS_LOOKUP_DEFAULT (NULL),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_UNSPEC, "NLE_UNSPEC"),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_BUG, "NLE_BUG"),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_NATIVE_ERRNO, "NLE_NATIVE_ERRNO"),
|
||||
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_ATTRSIZE, "NLE_ATTRSIZE"),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_BAD_SOCK, "NLE_BAD_SOCK"),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_DUMP_INTR, "NLE_DUMP_INTR"),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_MSG_OVERFLOW, "NLE_MSG_OVERFLOW"),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_MSG_TOOSHORT, "NLE_MSG_TOOSHORT"),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_MSG_TRUNC, "NLE_MSG_TRUNC"),
|
||||
NM_UTILS_LOOKUP_ITEM (NLE_SEQ_MISMATCH, "NLE_SEQ_MISMATCH"),
|
||||
)
|
||||
|
||||
const char *
|
||||
nl_geterror (int nlerr)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
nlerr = nl_errno (nlerr);
|
||||
|
||||
if (nlerr >= _NLE_BASE) {
|
||||
s = _geterror (nlerr);
|
||||
if (s)
|
||||
return s;
|
||||
}
|
||||
return g_strerror (nlerr);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NM_UTILS_ENUM2STR_DEFINE (nl_nlmsgtype2str, int,
|
||||
NM_UTILS_ENUM2STR (NLMSG_NOOP, "NOOP"),
|
||||
NM_UTILS_ENUM2STR (NLMSG_ERROR, "ERROR"),
|
||||
|
@@ -26,20 +26,6 @@
|
||||
#include <linux/genetlink.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
#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 + 9)
|
||||
#define NLE_MSG_OVERFLOW (_NLE_BASE + 10)
|
||||
|
||||
#define _NLE_BASE_END (_NLE_BASE + 11)
|
||||
|
||||
#define NLMSGERR_ATTR_UNUSED 0
|
||||
#define NLMSGERR_ATTR_MSG 1
|
||||
@@ -51,50 +37,6 @@
|
||||
#define NLM_F_ACK_TLVS 0x200
|
||||
#endif
|
||||
|
||||
static inline int
|
||||
nl_errno (int nlerr)
|
||||
{
|
||||
/* Normalizes an netlink error to be positive. Various API returns negative
|
||||
* error codes, and this function converts the negative value to its
|
||||
* positive.
|
||||
*
|
||||
* It's very similar to nm_errno(), but not exactly. The difference is that
|
||||
* nm_errno() is for plain errno, while nl_errno() is for netlink error numbers.
|
||||
* Yes, netlink error number are ~almost~ the same as errno, except that a particular
|
||||
* range (_NLE_BASE, _NLE_BASE_END) is reserved. The difference between the two
|
||||
* functions is only how G_MININT is mapped.
|
||||
*
|
||||
* See also nl_syserr2nlerr() below. */
|
||||
return nlerr >= 0
|
||||
? nlerr
|
||||
: ((nlerr == G_MININT) ? NLE_BUG : -nlerr);
|
||||
}
|
||||
|
||||
static inline int
|
||||
nl_syserr2nlerr (int errsv)
|
||||
{
|
||||
/* this maps a native errno to a (always non-negative) netlink error number.
|
||||
*
|
||||
* Note that netlink error numbers are embedded into the range of regular
|
||||
* errno. The only difference is, that netlink error numbers reserve a
|
||||
* range (_NLE_BASE, _NLE_BASE_END) for their own purpose.
|
||||
*
|
||||
* That means, converting an errno to netlink error number means in
|
||||
* most cases just returning itself (negative values are normalized
|
||||
* to be positive). Only values G_MININT and [_NLE_BASE, _NLE_BASE_END]
|
||||
* are coerced to the special value NLE_NATIVE_ERRNO, as they cannot
|
||||
* otherwise be represented in netlink error number domain. */
|
||||
if (errsv == G_MININT)
|
||||
return NLE_NATIVE_ERRNO;
|
||||
if (errsv < 0)
|
||||
errsv = -errsv;
|
||||
return (errsv >= _NLE_BASE && errsv < _NLE_BASE_END)
|
||||
? NLE_NATIVE_ERRNO
|
||||
: errsv;
|
||||
}
|
||||
|
||||
const char *nl_geterror (int nlerr);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* Basic attribute data types */
|
||||
|
@@ -32,6 +32,7 @@
|
||||
#include <linux/nl80211.h>
|
||||
#include <linux/if.h>
|
||||
|
||||
#include "nm-utils/nm-errno.h"
|
||||
#include "platform/nm-netlink.h"
|
||||
#include "nm-wifi-utils-private.h"
|
||||
#include "platform/nm-platform.h"
|
||||
|
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <linux/if.h>
|
||||
|
||||
#include "nm-utils/nm-errno.h"
|
||||
#include "platform/linux/nl802154.h"
|
||||
#include "platform/nm-netlink.h"
|
||||
#include "platform/nm-platform-utils.h"
|
||||
|
Reference in New Issue
Block a user