[PATCH 02/27] netlink: add basic attribute parser of ifinfomsg of NETLINK_ROUTE

JingPiao Chen chenjingpiao at gmail.com
Tue Aug 15 04:41:10 UTC 2017


* rtnl_link.c: Include "nlattr.h" and "xlat/rtnl_link_attrs.h".
(decode_ifinfomsg): Call decode_nlattr.
* xlat/rtnl_link_attrs.in: New file.

Co-authored-by: Fabien Siron <fabien.siron at epita.fr>
---
 rtnl_link.c             | 14 +++++++++++++-
 xlat/rtnl_link_attrs.in | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 xlat/rtnl_link_attrs.in

diff --git a/rtnl_link.c b/rtnl_link.c
index d1e9bb8..18897f3 100644
--- a/rtnl_link.c
+++ b/rtnl_link.c
@@ -29,15 +29,19 @@
 
 #include "defs.h"
 #include "netlink_route.h"
+#include "nlattr.h"
 #include "print_fields.h"
 
 #include "netlink.h"
 #include <linux/rtnetlink.h>
 
+#include "xlat/rtnl_link_attrs.h"
+
 DECL_NETLINK_ROUTE_DECODER(decode_ifinfomsg)
 {
 	struct ifinfomsg ifinfo = { .ifi_family = family };
-	const size_t offset = sizeof(ifinfo.ifi_family);
+	size_t offset = sizeof(ifinfo.ifi_family);
+	bool decode_nla = false;
 
 	PRINT_FIELD_XVAL("{", ifinfo, ifi_family, addrfams, "AF_???");
 
@@ -52,8 +56,16 @@ DECL_NETLINK_ROUTE_DECODER(decode_ifinfomsg)
 			PRINT_FIELD_FLAGS(", ", ifinfo, ifi_flags,
 					  iffflags, "IFF_???");
 			PRINT_FIELD_X(", ", ifinfo, ifi_change);
+			decode_nla = true;
 		}
 	} else
 		tprints("...");
 	tprints("}");
+
+	offset = NLMSG_ALIGN(sizeof(ifinfo));
+	if (decode_nla && len > offset) {
+		tprints(", ");
+		decode_nlattr(tcp, addr + offset, len - offset,
+			      rtnl_link_attrs, "IFLA_???", NULL, 0, NULL);
+	}
 }
diff --git a/xlat/rtnl_link_attrs.in b/xlat/rtnl_link_attrs.in
new file mode 100644
index 0000000..eb7f475
--- /dev/null
+++ b/xlat/rtnl_link_attrs.in
@@ -0,0 +1,45 @@
+IFLA_UNSPEC		0
+IFLA_ADDRESS		1
+IFLA_BROADCAST		2
+IFLA_IFNAME		3
+IFLA_MTU		4
+IFLA_LINK		5
+IFLA_QDISC		6
+IFLA_STATS		7
+IFLA_COST		8
+IFLA_PRIORITY		9
+IFLA_MASTER		10
+IFLA_WIRELESS		11
+IFLA_PROTINFO		12
+IFLA_TXQLEN		13
+IFLA_MAP		14
+IFLA_WEIGHT		15
+IFLA_OPERSTATE		16
+IFLA_LINKMODE		17
+IFLA_LINKINFO		18
+IFLA_NET_NS_PID		19
+IFLA_IFALIAS		20
+IFLA_NUM_VF		21
+IFLA_VFINFO_LIST	22
+IFLA_STATS64		23
+IFLA_VF_PORTS		24
+IFLA_PORT_SELF		25
+IFLA_AF_SPEC		26
+IFLA_GROUP		27
+IFLA_NET_NS_FD		28
+IFLA_EXT_MASK		29
+IFLA_PROMISCUITY	30
+IFLA_NUM_TX_QUEUES	31
+IFLA_NUM_RX_QUEUES	32
+IFLA_CARRIER		33
+IFLA_PHYS_PORT_ID	34
+IFLA_CARRIER_CHANGES	35
+IFLA_PHYS_SWITCH_ID	36
+IFLA_LINK_NETNSID	37
+IFLA_PHYS_PORT_NAME	38
+IFLA_PROTO_DOWN		39
+IFLA_GSO_MAX_SEGS	40
+IFLA_GSO_MAX_SIZE	41
+IFLA_PAD		42
+IFLA_XDP		43
+IFLA_EVENT		44
-- 
2.7.4





More information about the Strace-devel mailing list