]> granicus.if.org Git - strace/commitdiff
netlink: add basic decoding of NETLINK_ROUTE ifinfomsg attributes
authorJingPiao Chen <chenjingpiao@gmail.com>
Tue, 15 Aug 2017 04:41:10 +0000 (12:41 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 15 Aug 2017 22:34:46 +0000 (22:34 +0000)
* 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@epita.fr>
rtnl_link.c
xlat/rtnl_link_attrs.in [new file with mode: 0644]

index d1e9bb881b892209712fbfa281e5a006547a1a67..18897f3027af679e09ea8cbf862e4afc0812d4d0 100644 (file)
 
 #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 (file)
index 0000000..eb7f475
--- /dev/null
@@ -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