summary refs log tree commit diff
path: root/src/platform/nm-netlink.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/nm-netlink.h')
-rw-r--r--src/platform/nm-netlink.h70
1 files changed, 51 insertions, 19 deletions
diff --git a/src/platform/nm-netlink.h b/src/platform/nm-netlink.h
index 185269ba..d5df7ab9 100644
--- a/src/platform/nm-netlink.h
+++ b/src/platform/nm-netlink.h
@@ -52,32 +52,48 @@
 #endif
 
 static inline int
-nl_errno (int err)
+nl_errno (int nlerr)
 {
-	/* the error codes from our netlink implementation are plain errno
-	 * extended with our own error in a particular range starting from
-	 * _NLE_BASE.
+	/* Normalizes an netlink error to be positive. Various API returns negative
+	 * error codes, and this function converts the negative value to its
+	 * positive.
 	 *
-	 * However, often we encode errors as negative values. This function
-	 * normalizes the error and returns its positive value. */
-	return err >= 0
-	       ? err
-	       : ((err == G_MININT) ? NLE_BUG : -errno);
+	 * 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 err)
+nl_syserr2nlerr (int errsv)
 {
-	if (err == G_MININT)
+	/* 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 (err < 0)
-		err = -err;
-	return (err >= _NLE_BASE && err < _NLE_BASE_END)
+	if (errsv < 0)
+		errsv = -errsv;
+	return (errsv >= _NLE_BASE && errsv < _NLE_BASE_END)
 	       ? NLE_NATIVE_ERRNO
-	       : err;
+	       : errsv;
 }
 
-const char *nl_geterror (int err);
+const char *nl_geterror (int nlerr);
 
 /*****************************************************************************/
 
@@ -177,6 +193,12 @@ nla_get_u8 (const struct nlattr *nla)
 }
 
 static inline uint8_t
+nla_get_s8 (const struct nlattr *nla)
+{
+	return *(const int8_t *) nla_data (nla);
+}
+
+static inline uint8_t
 nla_get_u8_cond (/*const*/ struct nlattr *const*tb, int attr, uint8_t default_val)
 {
 	nm_assert (tb);
@@ -197,6 +219,12 @@ nla_get_u32(const struct nlattr *nla)
 	return *(const uint32_t *) nla_data (nla);
 }
 
+static inline int32_t
+nla_get_s32(const struct nlattr *nla)
+{
+	return *(const int32_t *) nla_data (nla);
+}
+
 uint64_t nla_get_u64 (const struct nlattr *nla);
 
 static inline char *
@@ -232,12 +260,18 @@ nla_put_string (struct nl_msg *msg, int attrtype, const char *str)
 #define NLA_PUT_U8(msg, attrtype, value) \
 	NLA_PUT_TYPE(msg, uint8_t, attrtype, value)
 
+#define NLA_PUT_S8(msg, attrtype, value) \
+	NLA_PUT_TYPE(msg, int8_t, attrtype, value)
+
 #define NLA_PUT_U16(msg, attrtype, value) \
 	NLA_PUT_TYPE(msg, uint16_t, attrtype, value)
 
 #define NLA_PUT_U32(msg, attrtype, value) \
 	NLA_PUT_TYPE(msg, uint32_t, attrtype, value)
 
+#define NLA_PUT_S32(msg, attrtype, value) \
+	NLA_PUT_TYPE(msg, int32_t, attrtype, value)
+
 #define NLA_PUT_U64(msg, attrtype, value) \
 	NLA_PUT_TYPE(msg, uint64_t, attrtype, value)
 
@@ -252,7 +286,7 @@ struct nlattr *nla_find (const struct nlattr *head, int len, int attrtype);
 static inline int
 nla_ok (const struct nlattr *nla, int remaining)
 {
-	return remaining >= sizeof(*nla) &&
+	return remaining >= (int) sizeof(*nla) &&
 	       nla->nla_len >= sizeof(*nla) &&
 	       nla->nla_len <= remaining;
 }
@@ -296,8 +330,6 @@ struct nl_msg *nlmsg_alloc (void);
 
 struct nl_msg *nlmsg_alloc_size (size_t max);
 
-struct nl_msg *nlmsg_alloc_inherit (struct nlmsghdr *hdr);
-
 struct nl_msg *nlmsg_alloc_convert (struct nlmsghdr *hdr);
 
 struct nl_msg *nlmsg_alloc_simple (int nlmsgtype, int flags);