[PATCH 1/3] lib/attr: add nla utility functions for s32

Thomas Haller thaller at redhat.com
Fri Aug 14 08:32:36 PDT 2015


---
 include/netlink/attr.h | 11 +++++++++++
 lib/attr.c             | 25 +++++++++++++++++++++++++
 libnl-3.sym            |  6 ++++++
 3 files changed, 42 insertions(+)

diff --git a/include/netlink/attr.h b/include/netlink/attr.h
index b84b62e..183d481 100644
--- a/include/netlink/attr.h
+++ b/include/netlink/attr.h
@@ -103,6 +103,8 @@ extern uint8_t		nla_get_u8(const struct nlattr *);
 extern int		nla_put_u8(struct nl_msg *, int, uint8_t);
 extern uint16_t		nla_get_u16(const struct nlattr *);
 extern int		nla_put_u16(struct nl_msg *, int, uint16_t);
+extern int32_t		nla_get_s32(const struct nlattr *);
+extern int		nla_put_s32(struct nl_msg *, int, int32_t);
 extern uint32_t		nla_get_u32(const struct nlattr *);
 extern int		nla_put_u32(struct nl_msg *, int, uint32_t);
 extern uint64_t		nla_get_u64(const struct nlattr *);
@@ -188,6 +190,15 @@ extern int		nla_is_nested(const struct nlattr *);
  * @arg attrtype	Attribute type.
  * @arg value		Numeric value.
  */
+#define NLA_PUT_S32(msg, attrtype, value) \
+	NLA_PUT_TYPE(msg, int32_t, attrtype, value)
+
+/**
+ * Add 32 bit integer attribute to netlink message.
+ * @arg msg		Netlink message.
+ * @arg attrtype	Attribute type.
+ * @arg value		Numeric value.
+ */
 #define NLA_PUT_U32(msg, attrtype, value) \
 	NLA_PUT_TYPE(msg, uint32_t, attrtype, value)
 
diff --git a/lib/attr.c b/lib/attr.c
index 838d0a9..86284ee 100644
--- a/lib/attr.c
+++ b/lib/attr.c
@@ -610,6 +610,31 @@ uint16_t nla_get_u16(const struct nlattr *nla)
  * @see nla_put
  * @return 0 on success or a negative error code.
  */
+int nla_put_s32(struct nl_msg *msg, int attrtype, int32_t value)
+{
+	return nla_put(msg, attrtype, sizeof(int32_t), &value);
+}
+
+/**
+ * Return payload of 32 bit integer attribute.
+ * @arg nla		32 bit integer attribute.
+ *
+ * @return Payload as 32 bit integer.
+ */
+int32_t nla_get_s32(const struct nlattr *nla)
+{
+	return *(const int32_t *) nla_data(nla);
+}
+
+/**
+ * Add 32 bit 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.
+ */
 int nla_put_u32(struct nl_msg *msg, int attrtype, uint32_t value)
 {
 	return nla_put(msg, attrtype, sizeof(uint32_t), &value);
diff --git a/libnl-3.sym b/libnl-3.sym
index 621bfe0..a467ab2 100644
--- a/libnl-3.sym
+++ b/libnl-3.sym
@@ -334,3 +334,9 @@ libnl_3_2_26 {
 global:
 	nl_socket_set_fd;
 } libnl_3;
+
+libnl_3_2_27 {
+global:
+	nla_get_s32;
+	nla_put_s32;
+} libnl_3_2_26;
-- 
2.4.3




More information about the libnl mailing list