Skip to contentSkip to conversation

libmnl & rtnetlink questions

DISCUSSION Ian Pilcher 2 participants 3 messages Apr 13, 2020 – Apr 21, 2020 netfilter

lore
Share & tools
lore
#0 lore raw

First off, please let me know if this list isn't an appropriate place for these sorts of questions.

With that out of the way, I'm trying to understand the sample program at:

http://git.netfilter.org/libmnl/tree/examples/rtnl/rtnl-link-dump.c

I've been able to puzzle most of it out, but I'm confused by the use of the struct rtgenmsg (declared on line 88 and used on lines 95-96).

* Based on rtnetlink(7), shouldn't this more properly be a struct ifinfomsg (even though only rtgen_family/ifi_family is set)?

* More importantly, why is setting this to AF_PACKET required at all? Testing the program without setting it reveals that it definitely is required, but I haven't been able to find anything that explains *why* that is the case.

Thanks!

Signature · 3 lines
========================================================================
                 In Soviet Russia, Google searches you!
========================================================================
#1 lore raw
Quoted 6 lines · Ian Pilcher

First off, please let me know if this list isn't an appropriate place for these sorts of questions.

With that out of the way, I'm trying to understand the sample program at:

Quoted 8 lines

http://git.netfilter.org/libmnl/tree/examples/rtnl/rtnl-link-dump.c

I've been able to puzzle most of it out, but I'm confused by the use of the struct rtgenmsg (declared on line 88 and used on lines 95-96).

* Based on rtnetlink(7), shouldn't this more properly be a struct ifinfomsg (even though only rtgen_family/ifi_family is set)?

RTM_GETLINK expects ifinfomsg, yes.

Quoted 4 lines

* More importantly, why is setting this to AF_PACKET required at all? Testing the program without setting it reveals that it definitely is required, but I haven't been able to find anything that explains *why* that is the case.

Probably AF_UNSPEC is more appropriate there?

#2 lore raw
Quoted 9 lines · Pablo Neira Ayuso
Quoted 8 lines · Ian Pilcher

First off, please let me know if this list isn't an appropriate place for these sorts of questions.

With that out of the way, I'm trying to understand the sample program at:

http://git.netfilter.org/libmnl/tree/examples/rtnl/rtnl-link-dump.c

Quoted 8 lines
Quoted 6 lines

I've been able to puzzle most of it out, but I'm confused by the use of the struct rtgenmsg (declared on line 88 and used on lines 95-96).

* Based on rtnetlink(7), shouldn't this more properly be a struct ifinfomsg (even though only rtgen_family/ifi_family is set)?

RTM_GETLINK expects ifinfomsg, yes.

commit 905cf0abe8c2c892313f08e38d808eee4e794987

Author: David Ahern <[email protected]>
Date:   Sun Oct 7 20:16:30 2018 -0700

rtnetlink: Update rtnl_dump_ifinfo for strict data checking

Update rtnl_dump_ifinfo for strict data checking. If the flag is set, the dump request is expected to have an ifinfomsg struct as the header potentially followed by one or more attributes. Any data passed in the header or as an attribute is taken as a request to influence the data returned. Only values supported by the dump handler are allowed to be non-0 or set in the request. At the moment only the IFA_TARGET_NETNSID, IFLA_EXT_MASK, IFLA_MASTER, and IFLA_LINKINFO attributes are supported.

Probably this explains the reason why.

Quoted 6 lines
Quoted 4 lines

* More importantly, why is setting this to AF_PACKET required at all? Testing the program without setting it reveals that it definitely is required, but I haven't been able to find anything that explains *why* that is the case.

Probably AF_UNSPEC is more appropriate there?

Would you send a patch for this?

Thanks.