message attribute mismatch

Thomas Haller thaller at redhat.com
Thu Jun 4 22:50:50 PDT 2015


On Mo, 2015-06-01 at 17:58 -0700, Sergiy Lozovsky wrote:
> Hi,
> 
> it looks like libnl-3.2.25 doesn't support following attribute types:
> NLA_NUL_STRING and NLA_BINARY. These types are supported by kernel,
> Python Netlink packages, etc.
> 
> We have a kernel module and Python scripts that use these types. Is
> there any workaround? What is the best way to handle that?

Hi Sergiy,


Usually, you can use libnl to create libnl objects of certain known
types. For example libnl3-route can create 'struct rtnl_route' objects
via:
  rtnl_route_parse().
Obviously, as libnl doesn't know about these attributes, none of its
known types will make use of those attributes. I.e. there is no libnl
object for your the objects from your kernel module.



In your case, you would anyway parse your messages generically with:

    int nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[],
                    int maxtype, struct nla_policy *policy);
    int nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int len,
                  struct nla_policy *policy);

if you now try to pass a policy argument like:

struct nla_policy my_type_policy[IFLA_MY_TYPE_MAX + 1] = {
    [IFLA_MY_TYPE_DATA] = { .type = NLA_BINARY },
};

libnl will barf on the unknown type. But the @policy argument is only there to validate
the message. You can pass %NULL and it will do no validation at all. Obviously, you must then
somehow validate the message youself.


You could still use nlmsg_parse() to fill the @tb argument without
validation. Afterwards, you validate the message yourself by
reimplementing validate_nla() to support the new message types:
  https://github.com/thom311/libnl/blob/e206c255d8fff8b51938945c8f57575
0c418a95e/lib/attr.c#L188



Not very satisfying. Patches very welcome!! ;-)


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/20150605/a2a050a6/attachment.sig>


More information about the libnl mailing list