Skip to contentSkip to conversation

examples: rtnl: fix rtnl-link-dump* extra header

PATCH New Jonas Gorski 1 participant 1 message May 27 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 examples: rtnl: fix rtnl-link-dump* extra header

RTM_GETLINK takes an ifinfomsg, not a rtgenmsg header, so use the correct type.

Als fix the family to AF_UNSPEC, as this is what is effectively requested.

This just happened to work as rtgenmsg::rtgen_family aliases ifinfomsg::ifi_family, and the kernel only checks the family for PF_BRIDGE or not.

---
 examples/rtnl/rtnl-link-dump.c  | 6 +++---
 examples/rtnl/rtnl-link-dump2.c | 6 +++---
 examples/rtnl/rtnl-link-dump3.c | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
examples/rtnl/rtnl-link-dump.c +3 -3
index 031346fbf61a..c9ab445349a5 100644
@@ -84,16 +84,16 @@ int main(void)
 	char buf[MNL_SOCKET_DUMP_SIZE];
 	unsigned int seq, portid;
 	struct mnl_socket *nl;
+	struct ifinfomsg *ifm;
 	struct nlmsghdr *nlh;
-	struct rtgenmsg *rt;
 	int ret;
 
 	nlh = mnl_nlmsg_put_header(buf);
 	nlh->nlmsg_type	= RTM_GETLINK;
 	nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
 	nlh->nlmsg_seq = seq = time(NULL);
-	rt = mnl_nlmsg_put_extra_header(nlh, sizeof(struct rtgenmsg));
-	rt->rtgen_family = AF_PACKET;
+	ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(struct ifinfomsg));
+	ifm->ifi_family = AF_UNSPEC;
 
 	nl = mnl_socket_open(NETLINK_ROUTE);
 	if (nl == NULL) {
examples/rtnl/rtnl-link-dump2.c +3 -3
index 890e51ad43d0..c33d4e010052 100644
@@ -57,16 +57,16 @@ int main(void)
 	char buf[MNL_SOCKET_DUMP_SIZE];
 	unsigned int seq, portid;
 	struct mnl_socket *nl;
+	struct ifinfomsg *ifm;
 	struct nlmsghdr *nlh;
-	struct rtgenmsg *rt;
 	int ret;
 
 	nlh = mnl_nlmsg_put_header(buf);
 	nlh->nlmsg_type	= RTM_GETLINK;
 	nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
 	nlh->nlmsg_seq = seq = time(NULL);
-	rt = mnl_nlmsg_put_extra_header(nlh, sizeof(struct rtgenmsg));
-	rt->rtgen_family = AF_PACKET;
+	ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(struct ifinfomsg));
+	ifm->ifi_family = AF_UNSPEC;
 
 	nl = mnl_socket_open(NETLINK_ROUTE);
 	if (nl == NULL) {
examples/rtnl/rtnl-link-dump3.c +3 -3
index a381da1bd697..0dd1a1c8834d 100644
@@ -57,16 +57,16 @@ int main(void)
 	char buf[MNL_SOCKET_DUMP_SIZE];
 	unsigned int seq, portid;
 	struct mnl_socket *nl;
+	struct ifinfomsg *ifm;
 	struct nlmsghdr *nlh;
-	struct rtgenmsg *rt;
 	int ret;
 
 	nlh = mnl_nlmsg_put_header(buf);
 	nlh->nlmsg_type	= RTM_GETLINK;
 	nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
 	nlh->nlmsg_seq = seq = time(NULL);
-	rt = mnl_nlmsg_put_extra_header(nlh, sizeof(struct rtgenmsg));
-	rt->rtgen_family = AF_PACKET;
+	ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(struct ifinfomsg));
+	ifm->ifi_family = AF_UNSPEC;
 
 	nl = mnl_socket_open(NETLINK_ROUTE);
 	if (nl == NULL) {
Signature · 1 line
2.54.0