[PATCH 2/3] Handle family-based parsing of IFLA_AF_SPEC attribute

Thomas Haller thaller at redhat.com
Wed Dec 2 03:29:16 PST 2015


On Wed, 2015-11-25 at 11:14 -0800, David Ahern wrote:
> The encoding of the IFLA_AF_SPEC attribute varies depending on the
> family
> used for the request (RTM_GETLINK) message. For AF_UNSPEC the
> encoding
> has another level of nesting for each address family with the type
> encoded
> first. i.e.,
>     af_spec = nla_nest_start(skb, IFLA_AF_SPEC)
>     for each family:
>         af = nla_nest_start(skb, af_ops->family)
>         af_ops->fill_link_af(skb, dev, ext_filter_mask)
>         nest_end
>     nest_end
> 
> This allows the parser to find the address family by looking at the
> first
> type.
> 
> Whereas AF_BRIDGE encoding is just:
>     af_spec = nla_nest_start(skb, IFLA_AF_SPEC)
>     br_fill_ifvlaninfo{_compressed}(skb, vg)
>     nest_end
> 
> which means the parser can not use the attribute itself to know the
> family
> to which the attribute belongs.
> 
> Signed-off-by: David Ahern <dsa at cumulusnetworks.com>
> ---
>  lib/route/link.c | 89
> ++++++++++++++++++++++++++++++++++++++++++++++----------
>  1 file changed, 74 insertions(+), 15 deletions(-)
> 
> 





> 			err = af_ops->ao_parse_af(link, af_attr,
> af_data);
> -				if (err < 0)
> -					goto errout;
> -			}
> -
> +		/* parsing of IFLA_AF_SPEC is dependent on the
> family used
> +		 * in the request message.
> +		 */
> +		switch(family) {
> +		case AF_BRIDGE:
> +			err = parse_af_spec_bridge(link,
> tb[IFLA_AF_SPEC]);
> +			break;
> +		case AF_UNSPEC:
> +			err = parse_af_spec_unspec(link,
> tb[IFLA_AF_SPEC]);
> +			break;
> +		default:
> +			err = -EINVAL;
> +			NL_DBG(1, "IFLA_AF_SPEC parsing not
> implemented for family %d\n",
> +				family);

isn't it a bit too severe to fail parsing entirely on an unknown
family?

Maybe just print the warning and continue parsing?

Note that usually we also just ignore unknown attributes (which allows
libnl to work also with newer kernels -- mostly).




Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/libnl/attachments/20151202/5bf28373/attachment.sig>


More information about the libnl mailing list