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 /lib | |
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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/attr.c | 92 |
1 files changed, 86 insertions, 6 deletions
@@ -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. |