Message ID | 20230315133743.26787-1-vincent@systemli.org |
---|---|
State | Superseded |
Delegated to: | Hauke Mehrtens |
Headers | show |
Series | attr: add NLA_S8 | expand |
On Wed, Mar 15, 2023 at 02:37:43PM +0100, Nick Hainke wrote: > NLA_S8 is used by newer hostapd versions. > > Signed-off-by: Nick Hainke <vincent@systemli.org> What is the target project of this patch? > --- > attr.c | 1 + > include/netlink/attr.h | 35 +++++++++++++++++++++++++++++++++++ > 2 files changed, 36 insertions(+) > > diff --git a/attr.c b/attr.c > index eae91e5..abde67f 100644 > --- a/attr.c > +++ b/attr.c > @@ -437,6 +437,7 @@ 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), > }; > > static int validate_nla(struct nlattr *nla, int maxtype, > diff --git a/include/netlink/attr.h b/include/netlink/attr.h > index 3e3047f..3a5d53d 100644 > --- a/include/netlink/attr.h > +++ b/include/netlink/attr.h > @@ -45,6 +45,7 @@ enum { > NLA_FLAG, /**< Flag */ > NLA_MSECS, /**< Micro seconds (64bit) */ > NLA_NESTED, /**< Nested attributes */ > + NLA_S8, > __NLA_TYPE_MAX, > }; > > @@ -248,6 +249,31 @@ static inline int nla_put_addr(struct nl_msg *msg, int attrtype, struct nl_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. > + */ > +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(const struct nlattr *nla) > +{ > + return *(const int8_t *) nla_data(nla); > +} > + > /** > * Add 8 bit integer attribute to netlink message. > * @arg msg Netlink message. > @@ -638,6 +664,15 @@ static inline size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dst > 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. > -- > 2.40.0 > > > _______________________________________________ > openwrt-devel mailing list > openwrt-devel@lists.openwrt.org > https://lists.openwrt.org/mailman/listinfo/openwrt-devel
On 3/15/23 07:30, Christian Marangi wrote: > On Wed, Mar 15, 2023 at 02:37:43PM +0100, Nick Hainke wrote: >> NLA_S8 is used by newer hostapd versions. >> >> Signed-off-by: Nick Hainke <vincent@systemli.org> > What is the target project of this patch? libnl-tiny
On 3/15/23 14:37, Nick Hainke wrote: > NLA_S8 is used by newer hostapd versions. > > Signed-off-by: Nick Hainke <vincent@systemli.org> > --- > attr.c | 1 + > include/netlink/attr.h | 35 +++++++++++++++++++++++++++++++++++ > 2 files changed, 36 insertions(+) > > diff --git a/attr.c b/attr.c > index eae91e5..abde67f 100644 > --- a/attr.c > +++ b/attr.c > @@ -437,6 +437,7 @@ 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), > }; > > static int validate_nla(struct nlattr *nla, int maxtype, > diff --git a/include/netlink/attr.h b/include/netlink/attr.h > index 3e3047f..3a5d53d 100644 > --- a/include/netlink/attr.h > +++ b/include/netlink/attr.h > @@ -45,6 +45,7 @@ enum { > NLA_FLAG, /**< Flag */ > NLA_MSECS, /**< Micro seconds (64bit) */ > NLA_NESTED, /**< Nested attributes */ > + NLA_S8, > __NLA_TYPE_MAX, > }; I think this has to match the kernel definitions of the same enum. https://elixir.bootlin.com/linux/v6.1.20/source/include/net/netlink.h#L178 Please add the other definitions added in this commit too: https://github.com/thom311/libnl/commit/6263a11bfcd033a88583faa719d3911850f0c4f5 I think you should also add all the nla_put_s* and nla_get_s* definitions for s8, s16, s32 and s64. libnl-tiny adds them to the header only so they do not make the binary bigger when they are not used. Hauke
On 3/19/23 20:25, Hauke Mehrtens wrote: > On 3/15/23 14:37, Nick Hainke wrote: >> NLA_S8 is used by newer hostapd versions. >> >> Signed-off-by: Nick Hainke <vincent@systemli.org> >> --- >> attr.c | 1 + >> include/netlink/attr.h | 35 +++++++++++++++++++++++++++++++++++ >> 2 files changed, 36 insertions(+) >> >> diff --git a/attr.c b/attr.c >> index eae91e5..abde67f 100644 >> --- a/attr.c >> +++ b/attr.c >> @@ -437,6 +437,7 @@ 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), >> }; >> static int validate_nla(struct nlattr *nla, int maxtype, >> diff --git a/include/netlink/attr.h b/include/netlink/attr.h >> index 3e3047f..3a5d53d 100644 >> --- a/include/netlink/attr.h >> +++ b/include/netlink/attr.h >> @@ -45,6 +45,7 @@ enum { >> NLA_FLAG, /**< Flag */ >> NLA_MSECS, /**< Micro seconds (64bit) */ >> NLA_NESTED, /**< Nested attributes */ >> + NLA_S8, >> __NLA_TYPE_MAX, >> }; > > I think this has to match the kernel definitions of the same enum. > https://elixir.bootlin.com/linux/v6.1.20/source/include/net/netlink.h#L178 > > So I have to add all enum types? > Please add the other definitions added in this commit too: > https://github.com/thom311/libnl/commit/6263a11bfcd033a88583faa719d3911850f0c4f5 > > > I think you should also add all the nla_put_s* and nla_get_s* > definitions for s8, s16, s32 and s64. libnl-tiny adds them to the > header only so they do not make the binary bigger when they are not used. I can add them.
On 3/30/23 11:43, Nick wrote: > > On 3/19/23 20:25, Hauke Mehrtens wrote: >> On 3/15/23 14:37, Nick Hainke wrote: >>> NLA_S8 is used by newer hostapd versions. >>> >>> Signed-off-by: Nick Hainke <vincent@systemli.org> >>> --- >>> attr.c | 1 + >>> include/netlink/attr.h | 35 +++++++++++++++++++++++++++++++++++ >>> 2 files changed, 36 insertions(+) >>> >>> diff --git a/attr.c b/attr.c >>> index eae91e5..abde67f 100644 >>> --- a/attr.c >>> +++ b/attr.c >>> @@ -437,6 +437,7 @@ 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), >>> }; >>> static int validate_nla(struct nlattr *nla, int maxtype, >>> diff --git a/include/netlink/attr.h b/include/netlink/attr.h >>> index 3e3047f..3a5d53d 100644 >>> --- a/include/netlink/attr.h >>> +++ b/include/netlink/attr.h >>> @@ -45,6 +45,7 @@ enum { >>> NLA_FLAG, /**< Flag */ >>> NLA_MSECS, /**< Micro seconds (64bit) */ >>> NLA_NESTED, /**< Nested attributes */ >>> + NLA_S8, >>> __NLA_TYPE_MAX, >>> }; >> >> I think this has to match the kernel definitions of the same enum. >> https://elixir.bootlin.com/linux/v6.1.20/source/include/net/netlink.h#L178 >> >> > So I have to add all enum types? libnl is also not having all types: https://github.com/thom311/libnl/blob/main/include/netlink/attr.h#L33-L51
On 30.03.23 11:47, Nick wrote: > > On 3/30/23 11:43, Nick wrote: >> >> On 3/19/23 20:25, Hauke Mehrtens wrote: >>> On 3/15/23 14:37, Nick Hainke wrote: >>>> NLA_S8 is used by newer hostapd versions. >>>> >>>> Signed-off-by: Nick Hainke <vincent@systemli.org> >>>> --- >>>> attr.c | 1 + >>>> include/netlink/attr.h | 35 +++++++++++++++++++++++++++++++++++ >>>> 2 files changed, 36 insertions(+) >>>> >>>> diff --git a/attr.c b/attr.c >>>> index eae91e5..abde67f 100644 >>>> --- a/attr.c >>>> +++ b/attr.c >>>> @@ -437,6 +437,7 @@ 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), >>>> }; >>>> static int validate_nla(struct nlattr *nla, int maxtype, >>>> diff --git a/include/netlink/attr.h b/include/netlink/attr.h >>>> index 3e3047f..3a5d53d 100644 >>>> --- a/include/netlink/attr.h >>>> +++ b/include/netlink/attr.h >>>> @@ -45,6 +45,7 @@ enum { >>>> NLA_FLAG, /**< Flag */ >>>> NLA_MSECS, /**< Micro seconds (64bit) */ >>>> NLA_NESTED, /**< Nested attributes */ >>>> + NLA_S8, >>>> __NLA_TYPE_MAX, >>>> }; >>> >>> I think this has to match the kernel definitions of the same enum. >>> https://elixir.bootlin.com/linux/v6.1.20/source/include/net/netlink.h#L178 >>> >>> >> So I have to add all enum types? > libnl is also not having all types: > https://github.com/thom311/libnl/blob/main/include/netlink/attr.h#L33-L51 You can leave out entries at the end you don't need, but the values must match. So please add everything in between until you reach NLA_S8. While you're at it, it might be a good idea to add at least the other NLA_S* types as well. - Felix
diff --git a/attr.c b/attr.c index eae91e5..abde67f 100644 --- a/attr.c +++ b/attr.c @@ -437,6 +437,7 @@ 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), }; static int validate_nla(struct nlattr *nla, int maxtype, diff --git a/include/netlink/attr.h b/include/netlink/attr.h index 3e3047f..3a5d53d 100644 --- a/include/netlink/attr.h +++ b/include/netlink/attr.h @@ -45,6 +45,7 @@ enum { NLA_FLAG, /**< Flag */ NLA_MSECS, /**< Micro seconds (64bit) */ NLA_NESTED, /**< Nested attributes */ + NLA_S8, __NLA_TYPE_MAX, }; @@ -248,6 +249,31 @@ static inline int nla_put_addr(struct nl_msg *msg, int attrtype, struct nl_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. + */ +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(const struct nlattr *nla) +{ + return *(const int8_t *) nla_data(nla); +} + /** * Add 8 bit integer attribute to netlink message. * @arg msg Netlink message. @@ -638,6 +664,15 @@ static inline size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dst 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.
NLA_S8 is used by newer hostapd versions. Signed-off-by: Nick Hainke <vincent@systemli.org> --- attr.c | 1 + include/netlink/attr.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)