]> granicus.if.org Git - libnl/commitdiff
lib/attr: add nla utility functions for signed integers
authorThomas Haller <thaller@redhat.com>
Mon, 5 Oct 2015 14:52:07 +0000 (16:52 +0200)
committerThomas Haller <thaller@redhat.com>
Mon, 5 Oct 2015 14:52:41 +0000 (16:52 +0200)
Commit 7bb956501ccd58ed3bbffc59de996f056e178683 added nla functions for
s32. We preferibly add all signed integer operations at the same time.
Thus, also add s8, s16, and s64.

Also, previously the NLA_TYPE_MAX enum was not extended to have
NLA_S32. Fix that too.

Reported-By: Jiri Pirko <jiri@resnulli.us>
Fixes: 7bb956501ccd58ed3bbffc59de996f056e178683
Signed-off-by: Thomas Haller <thaller@redhat.com>
include/netlink/attr.h
lib/attr.c
libnl-3.sym

index fd8e299f3325922870f3bb965d1cf12de165e91a..ee159aab49e558aede7181c405f925998144790b 100644 (file)
@@ -44,6 +44,13 @@ enum {
        NLA_FLAG,       /**< Flag */
        NLA_MSECS,      /**< Micro seconds (64bit) */
        NLA_NESTED,     /**< Nested attributes */
+       NLA_NESTED_COMPAT,
+       NLA_NUL_STRING,
+       NLA_BINARY,
+       NLA_S8,
+       NLA_S16,
+       NLA_S32,
+       NLA_S64,
        __NLA_TYPE_MAX,
 };
 
@@ -99,14 +106,20 @@ extern int         nla_put_data(struct nl_msg *, int,
 extern int             nla_put_addr(struct nl_msg *, int, struct nl_addr *);
 
 /* Integer attribute */
+extern int8_t           nla_get_s8(const struct nlattr *);
+extern int              nla_put_s8(struct nl_msg *, int, int8_t);
 extern uint8_t         nla_get_u8(const struct nlattr *);
 extern int             nla_put_u8(struct nl_msg *, int, uint8_t);
+extern int16_t          nla_get_s16(const struct nlattr *);
+extern int              nla_put_s16(struct nl_msg *, int, int16_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 int64_t          nla_get_s64(const struct nlattr *);
+extern int              nla_put_s64(struct nl_msg *, int, int64_t);
 extern uint64_t                nla_get_u64(const struct nlattr *);
 extern int             nla_put_u64(struct nl_msg *, int, uint64_t);
 
@@ -166,6 +179,15 @@ extern int         nla_is_nested(const struct nlattr *);
                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 integer attribute to netlink message.
  * @arg msg            Netlink message.
@@ -175,6 +197,15 @@ extern int         nla_is_nested(const struct nlattr *);
 #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.
@@ -185,7 +216,7 @@ extern int          nla_is_nested(const struct nlattr *);
        NLA_PUT_TYPE(msg, uint16_t, attrtype, value)
 
 /**
- * Add 32 bit integer attribute to netlink message.
+ * Add 32 bit signed integer attribute to netlink message.
  * @arg msg            Netlink message.
  * @arg attrtype       Attribute type.
  * @arg value          Numeric value.
@@ -202,6 +233,15 @@ extern int         nla_is_nested(const struct nlattr *);
 #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.
index 86284ee1068d5a2b96f502e298127c89be715bd3..9d8bb266fdf2a4837e6546d4318bd638ffc6148c 100644 (file)
@@ -551,6 +551,31 @@ int nla_put_addr(struct nl_msg *msg, int attrtype, struct nl_addr *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.
+ */
+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.
+ */
+int8_t nla_get_s8(const struct nlattr *nla)
+{
+       return *(const int8_t *) nla_data(nla);
+}
+
 /**
  * Add 8 bit integer attribute to netlink message.
  * @arg msg            Netlink message.
@@ -576,6 +601,31 @@ uint8_t nla_get_u8(const struct nlattr *nla)
        return *(const 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.
+ */
+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.
+ */
+int16_t nla_get_s16(const struct nlattr *nla)
+{
+       return *(const int16_t *) nla_data(nla);
+}
+
 /**
  * Add 16 bit integer attribute to netlink message.
  * @arg msg            Netlink message.
@@ -602,10 +652,10 @@ uint16_t nla_get_u16(const struct nlattr *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.
+ * Add 32 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.
@@ -616,8 +666,8 @@ int nla_put_s32(struct nl_msg *msg, int attrtype, int32_t value)
 }
 
 /**
- * Return payload of 32 bit integer attribute.
- * @arg nla            32 bit integer attribute.
+ * Return payload of 32 bit signed integer attribute.
+ * @arg nla             32 bit integer attribute.
  *
  * @return Payload as 32 bit integer.
  */
@@ -651,6 +701,36 @@ uint32_t nla_get_u32(const struct nlattr *nla)
        return *(const 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.
+ */
+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.
+ */
+int64_t nla_get_s64(const struct nlattr *nla)
+{
+       int64_t tmp = 0;
+
+       if (nla && nla_len(nla) >= sizeof(tmp))
+               memcpy(&tmp, nla_data(nla), sizeof(tmp));
+
+       return tmp;
+}
+
 /**
  * Add 64 bit integer attribute to netlink message.
  * @arg msg            Netlink message.
index a467ab234bb6deafbc30cd91f779e9a561e98b4a..97859571bf1b2c513936d815dd81966171997143 100644 (file)
@@ -337,6 +337,12 @@ global:
 
 libnl_3_2_27 {
 global:
+       nla_get_s8;
+       nla_put_s8;
+       nla_get_s16;
+       nla_put_s16;
        nla_get_s32;
        nla_put_s32;
+       nla_get_s64;
+       nla_put_s64;
 } libnl_3_2_26;