diff options
author | Thomas Haller <thaller@redhat.com> | 2015-10-05 14:52:07 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-10-05 14:52:41 (GMT) |
commit | 6263a11bfcd033a88583faa719d3911850f0c4f5 (patch) | |
tree | 4f81ecd3204d02cec9672d1693800a74061d67cc | |
parent | 2a8a7c31e6accf1a22caebace8da4c03028d5500 (diff) | |
download | libnl-6263a11bfcd033a88583faa719d3911850f0c4f5.zip libnl-6263a11bfcd033a88583faa719d3911850f0c4f5.tar.gz libnl-6263a11bfcd033a88583faa719d3911850f0c4f5.tar.bz2 |
lib/attr: add nla utility functions for signed integers
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>
-rw-r--r-- | include/netlink/attr.h | 42 | ||||
-rw-r--r-- | lib/attr.c | 92 | ||||
-rw-r--r-- | libnl-3.sym | 6 |
3 files changed, 133 insertions, 7 deletions
diff --git a/include/netlink/attr.h b/include/netlink/attr.h index fd8e299..ee159aa 100644 --- a/include/netlink/attr.h +++ b/include/netlink/attr.h @@ -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); @@ -167,6 +180,15 @@ extern int nla_is_nested(const struct nlattr *); } 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. * @arg attrtype Attribute type. @@ -176,6 +198,15 @@ extern int nla_is_nested(const struct nlattr *); 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. * @arg attrtype Attribute type. @@ -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. @@ -203,6 +234,15 @@ extern int nla_is_nested(const struct nlattr *); 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. * @arg attrtype Attribute type. @@ -552,6 +552,31 @@ int nla_put_addr(struct nl_msg *msg, int attrtype, struct nl_addr *addr) */ /** + * 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. * @arg attrtype Attribute type. @@ -577,6 +602,31 @@ uint8_t nla_get_u8(const struct nlattr *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. * @arg attrtype Attribute type. @@ -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. */ @@ -652,6 +702,36 @@ uint32_t nla_get_u32(const struct nlattr *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. * @arg attrtype Attribute type. diff --git a/libnl-3.sym b/libnl-3.sym index a467ab2..9785957 100644 --- a/libnl-3.sym +++ b/libnl-3.sym @@ -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; |