libnl 3 with kernel < 2.6.38
Thierry Reding
thierry.reding at avionic-design.de
Wed Mar 23 09:14:24 EDT 2011
* Thomas Graf wrote:
> On Wed, Mar 23, 2011 at 01:03:29PM +0100, Thierry Reding wrote:
>
> > -- Original message: type=0x13 length=36 flags=<REQUEST,ACK> sequence-nr=1009839803 pid=1980
> > -- Debug: Sent Message:
> > -------------------------- BEGIN NETLINK MESSAGE ---------------------------
> > [HEADER] 16 octets
> > .nlmsg_len = 36
> > .nlmsg_type = 19 <route/link::set>
> > .nlmsg_flags = 5 <REQUEST,ACK>
> > .nlmsg_seq = 1009839804
> > .nlmsg_pid = 1980
> > [PAYLOAD] 16 octets
> > 00 00 00 00 04 00 00 00 03 10 00 00 00 00 00 00 ................
> > [ATTR 26] 0 octets
> > --------------------------- END NETLINK MESSAGE ---------------------------
>
> Problem is this empty nested atribtue (IFLA_AF_SPEC)
>
> Fixed with the following commit:
>
> commit a0fe7a1c9abe3ab5bf8c9253fab50e114b02b87b
> Author: Thomas Graf <tgraf at suug.ch>
> Date: Wed Mar 23 13:39:18 2011 +0100
>
> Omit empty nested attributes
>
> Check for empty nested attributes in nla_nest_end() and omit the
> attribute alltogether if is is the case.
>
> diff --git a/lib/attr.c b/lib/attr.c
> index cccd50d..a045351 100644
> --- a/lib/attr.c
> +++ b/lib/attr.c
> @@ -1151,10 +1151,22 @@ struct nlattr *nla_nest_start(struct nl_msg *msg, int attrtype)
> */
> int nla_nest_end(struct nl_msg *msg, struct nlattr *start)
> {
> - size_t pad;
> + size_t pad, len;
>
> - start->nla_len = (unsigned char *) nlmsg_tail(msg->nm_nlh) -
> - (unsigned char *) start;
> + len = (void *) nlmsg_tail(msg->nm_nlh) - (void *) start;
> +
> + if (len == NLA_HDRLEN) {
> + /*
> + * Kernel can't handle empty nested attributes, trim the
> + * attribute header again
> + */
> + msg->nm_nlh->nlmsg_len -= NLA_HDRLEN;
> + memset(nlmsg_tail(msg->nm_nlh), 0, NLA_HDRLEN);
> +
> + return 0;
> + }
> +
> + start->nla_len = len;
>
> pad = NLMSG_ALIGN(msg->nm_nlh->nlmsg_len) - msg->nm_nlh->nlmsg_len;
> if (pad > 0) {
I can confirm that this patch works.
Cheers,
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/libnl/attachments/20110323/54a58b12/attachment.sig>
More information about the libnl
mailing list