diff options
| author | Nick Hainke | 2023-03-30 11:17:15 +0000 |
|---|---|---|
| committer | Hauke Mehrtens | 2023-04-02 00:19:37 +0000 |
| commit | 11b7c5f0745af2637b48131287f28689bb80ed3e (patch) | |
| tree | 79abe4627ffe196237f908db07bb1d1785e8986e | |
| parent | f5d9b7e4f534a69cbd35c3f150fa6d57b9d631e4 (diff) | |
| download | libnl-tiny-11b7c5f0745af2637b48131287f28689bb80ed3e.tar.gz | |
attr: add NLA_S* definitions
NLA_S8 is used by newer hostapd versions. Directly add all NLA_S*
definitions.
Signed-off-by: Nick Hainke <vincent@systemli.org>
| -rw-r--r-- | attr.c | 4 | ||||
| -rw-r--r-- | include/netlink/attr.h | 122 |
2 files changed, 126 insertions, 0 deletions
@@ -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, }; @@ -249,6 +256,31 @@ static inline int nla_put_addr(struct nl_msg *msg, int attrtype, struct nl_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. + */ +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. * @arg attrtype Attribute type. @@ -274,6 +306,31 @@ static inline uint8_t nla_get_u8(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. + */ +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. * @arg attrtype Attribute type. @@ -349,6 +406,35 @@ static inline uint32_t nla_get_u32(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. + */ +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. * @arg attrtype Attribute type. @@ -639,6 +725,24 @@ static inline size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dst } 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. * @arg attrtype Attribute type. @@ -648,6 +752,15 @@ static inline size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dst 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. @@ -675,6 +788,15 @@ static inline size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dst 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. |