newbie looking for libnl-gen examples

Thomas Graf tgraf at suug.ch
Sun Nov 11 10:02:38 EST 2012


On 11/11/12 at 01:59am, Matthew Monaco wrote:
> I'm new to Netlink sockets in both kernel and userspace. It's easy enough to
> find kernel side code to work off of, but I'm having trouble finding *any*
> examples of userspace code using libnl for generic sockets. The documentation on
> the libnl page is good, but it would be nice to have examples of a libnl-gen
> program.

A good example is libteam. It uses libnl-genl.

https://github.com/jpirko/libteam/blob/master/lib/libteam.c

> At the moment I'm trying to understand why the attributes / policy types differ
> in both kernel space and user space. Am I supposed to redefine the policy on
> each end? Is there no way to get the policy array in the same way that the
> family struct can be queried?

The reason for this is that most protocols are not symmetric in terms
of message formats, i.e. a message for cmd `foo` may look differently
depending on whether the direction is kernel -> user or
user -> kernel.

It should be relatively trivial to expose the nla_policy on the kernel
side though and write a small function for libnl that converts the
kernel nla_policy struct to a libnl nla_policy struct. I'd be happy
to accept a patch for that.



More information about the libnl mailing list