[PATCH v2] attr: add NLA_S* definitions

Nick Hainke vincent at systemli.org
Thu Mar 30 04:17:15 PDT 2023


NLA_S8 is used by newer hostapd versions. Directly add all NLA_S*
definitions.

Signed-off-by: Nick Hainke <vincent at systemli.org>
---
 attr.c                 |   4 ++
 include/netlink/attr.h | 122 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 126 insertions(+)

diff --git a/attr.c b/attr.c
index eae91e5..fd10b25 100644
--- a/attr.c
+++ b/attr.c
@@ -437,6 +437,10 @@ static uint16_t nla_attr_minlen[NLA_TYPE_MAX+1] = {
 	[NLA_U32]	= sizeof(uint32_t),
 	[NLA_U64]	= sizeof(uint64_t),
 	[NLA_STRING]	= 1,
+	[NLA_S8]	= sizeof(int8_t),
+	[NLA_S16]	= sizeof(int16_t),
+	[NLA_S32]	= sizeof(int32_t),
+	[NLA_S64]	= sizeof(int64_t),
 };
 
 static int validate_nla(struct nlattr *nla, int maxtype,
diff --git a/include/netlink/attr.h b/include/netlink/attr.h
index 3e3047f..28fac87 100644
--- a/include/netlink/attr.h
+++ b/include/netlink/attr.h
@@ -45,6 +45,13 @@ enum {
 	NLA_FLAG,	/**< Flag */
 	NLA_MSECS,	/**< Micro seconds (64bit) */
 	NLA_NESTED,	/**< Nested attributes */
+	NLA_NESTED_ARRAY,
+	NLA_NUL_STRING,
+	NLA_BINARY,
+	NLA_S8,
+	NLA_S16,
+	NLA_S32,
+	NLA_S64,
 	__NLA_TYPE_MAX,
 };
 
@@ -248,6 +255,31 @@ static inline int nla_put_addr(struct nl_msg *msg, int attrtype, struct nl_addr
  * @name Integer Attributes
  */
 
+/**
+ * Add 8 bit signed integer attribute to netlink message.
+ * @arg msg             Netlink message.
+ * @arg attrtype        Attribute type.
+ * @arg value           Numeric value to store as payload.
+ *
+ * @see nla_put
+ * @return 0 on success or a negative error code.
+ */
+static inline int nla_put_s8(struct nl_msg *msg, int attrtype, int8_t value)
+{
+	return nla_put(msg, attrtype, sizeof(int8_t), &value);
+}
+
+/**
+ * Return value of 8 bit signed integer attribute.
+ * @arg nla             8 bit integer attribute
+ *
+ * @return Payload as 8 bit integer.
+ */
+static inline int8_t nla_get_s8(struct nlattr *nla)
+{
+	return *(int8_t *) nla_data(nla);
+}
+
 /**
  * Add 8 bit integer attribute to netlink message.
  * @arg msg		Netlink message.
@@ -273,6 +305,31 @@ static inline uint8_t nla_get_u8(struct nlattr *nla)
 	return *(uint8_t *) nla_data(nla);
 }
 
+/**
+ * Add 16 bit signed integer attribute to netlink message.
+ * @arg msg             Netlink message.
+ * @arg attrtype        Attribute type.
+ * @arg value           Numeric value to store as payload.
+ *
+ * @see nla_put
+ * @return 0 on success or a negative error code.
+ */
+static inline int nla_put_s16(struct nl_msg *msg, int attrtype, int16_t value)
+{
+	return nla_put(msg, attrtype, sizeof(int16_t), &value);
+}
+
+/**
+ * Return payload of 16 bit signed integer attribute.
+ * @arg nla             16 bit integer attribute
+ *
+ * @return Payload as 16 bit integer.
+ */
+static inline int16_t nla_get_s16(struct nlattr *nla)
+{
+	return *(int16_t *) nla_data(nla);
+}
+
 /**
  * Add 16 bit integer attribute to netlink message.
  * @arg msg		Netlink message.
@@ -348,6 +405,35 @@ static inline uint32_t nla_get_u32(struct nlattr *nla)
 	return *(uint32_t *) nla_data(nla);
 }
 
+/**
+ * Add 64 bit signed integer attribute to netlink message.
+ * @arg msg             Netlink message.
+ * @arg attrtype        Attribute type.
+ * @arg value           Numeric value to store as payload.
+ *
+ * @see nla_put
+ * @return 0 on success or a negative error code.
+ */
+static inline int nla_put_s64(struct nl_msg *msg, int attrtype, int64_t value)
+{
+	return nla_put(msg, attrtype, sizeof(int64_t), &value);
+}
+
+/**
+ * Return payload of s64 attribute
+ * @arg nla             s64 netlink attribute
+ *
+ * @return Payload as 64 bit integer.
+ */
+static inline int64_t nla_get_s64(struct nlattr *nla)
+{
+	int64_t tmp;
+
+	nla_memcpy(&tmp, nla, sizeof(tmp));
+
+	return tmp;
+}
+
 /**
  * Add 64 bit integer attribute to netlink message.
  * @arg msg		Netlink message.
@@ -638,6 +724,24 @@ static inline size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dst
 		NLA_PUT(msg, attrtype, sizeof(type), &__tmp); \
 	} while(0)
 
+/**
+ * Add 8 bit signed integer attribute to netlink message.
+ * @arg msg		Netlink message.
+ * @arg attrtype	Attribute type.
+ * @arg value		Numeric value.
+ */
+#define NLA_PUT_S8(msg, attrtype, value) \
+	NLA_PUT_TYPE(msg, int8_t, attrtype, value)
+
+/**
+ * Add 8 bit signed integer attribute to netlink message.
+ * @arg msg		Netlink message.
+ * @arg attrtype	Attribute type.
+ * @arg value		Numeric value.
+ */
+#define NLA_PUT_S8(msg, attrtype, value) \
+	NLA_PUT_TYPE(msg, int8_t, attrtype, value)
+
 /**
  * Add 8 bit integer attribute to netlink message.
  * @arg msg		Netlink message.
@@ -647,6 +751,15 @@ static inline size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dst
 #define NLA_PUT_U8(msg, attrtype, value) \
 	NLA_PUT_TYPE(msg, uint8_t, attrtype, value)
 
+/**
+ * Add 16 bit signed integer attribute to netlink message.
+ * @arg msg		Netlink message.
+ * @arg attrtype	Attribute type.
+ * @arg value		Numeric value.
+ */
+#define NLA_PUT_S16(msg, attrtype, value) \
+	NLA_PUT_TYPE(msg, int16_t, attrtype, value)
+
 /**
  * Add 16 bit integer attribute to netlink message.
  * @arg msg		Netlink message.
@@ -674,6 +787,15 @@ static inline size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dst
 #define NLA_PUT_U32(msg, attrtype, value) \
 	NLA_PUT_TYPE(msg, uint32_t, attrtype, value)
 
+/**
+ * Add 64 bit signed integer attribute to netlink message.
+ * @arg msg		Netlink message.
+ * @arg attrtype	Attribute type.
+ * @arg value		Numeric value.
+ */
+#define NLA_PUT_S64(msg, attrtype, value) \
+	NLA_PUT_TYPE(msg, int64_t, attrtype, value)
+
 /**
  * Add 64 bit integer attribute to netlink message.
  * @arg msg		Netlink message.
-- 
2.40.0




More information about the openwrt-devel mailing list