]> granicus.if.org Git - strace/commitdiff
netlink: add basic decoding of NETLINK_ROUTE fib_rule_hdr attributes
authorJingPiao Chen <chenjingpiao@gmail.com>
Tue, 15 Aug 2017 04:41:13 +0000 (12:41 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 15 Aug 2017 22:34:46 +0000 (22:34 +0000)
* rtnl_rule.c: Include "nlattr.h" and "xlat/rtnl_rule_attrs.h".
(decode_fib_rule_hdr): Call decode_nlattr.
* xlat/rtnl_rule_attrs.in: New file.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
rtnl_rule.c
xlat/rtnl_rule_attrs.in [new file with mode: 0644]

index b3e6d5261812d6885faa87d22f29364c36e9b419..5a1dd2894cd4b02370254f4b461ca6480fc393d6 100644 (file)
@@ -30,6 +30,7 @@
 #include "defs.h"
 
 #include "netlink_route.h"
+#include "nlattr.h"
 #include "print_fields.h"
 
 #include "netlink.h"
@@ -40,6 +41,7 @@
 
 #include "xlat/fib_rule_actions.h"
 #include "xlat/fib_rule_flags.h"
+#include "xlat/rtnl_rule_attrs.h"
 
 DECL_NETLINK_ROUTE_DECODER(decode_fib_rule_hdr)
 {
@@ -49,7 +51,8 @@ DECL_NETLINK_ROUTE_DECODER(decode_fib_rule_hdr)
         * struct fib_rule_hdr.
         */
        struct rtmsg msg = { .rtm_family = family };
-       const size_t offset = sizeof(msg.rtm_family);
+       size_t offset = sizeof(msg.rtm_family);
+       bool decode_nla = false;
 
        tprints("{family=");
        printxval(addrfams, msg.rtm_family, "AF_???");
@@ -71,8 +74,16 @@ DECL_NETLINK_ROUTE_DECODER(decode_fib_rule_hdr)
                        tprints(", flags=");
                        printflags(fib_rule_flags, msg.rtm_flags,
                                   "FIB_RULE_???");
+                       decode_nla = true;
                }
        } else
                tprints("...");
        tprints("}");
+
+       offset = NLMSG_ALIGN(sizeof(msg));
+       if (decode_nla && len > offset) {
+               tprints(", ");
+               decode_nlattr(tcp, addr + offset, len - offset,
+                             rtnl_rule_attrs, "FRA_???", NULL, 0, NULL);
+       }
 }
diff --git a/xlat/rtnl_rule_attrs.in b/xlat/rtnl_rule_attrs.in
new file mode 100644 (file)
index 0000000..971f118
--- /dev/null
@@ -0,0 +1,21 @@
+FRA_UNSPEC             0
+FRA_DST                        1
+FRA_SRC                        2
+FRA_IIFNAME            3
+FRA_GOTO               4
+FRA_UNUSED2            5
+FRA_PRIORITY           6
+FRA_UNUSED3            7
+FRA_UNUSED4            8
+FRA_UNUSED5            9
+FRA_FWMARK             10
+FRA_FLOW               11
+FRA_TUN_ID             12
+FRA_SUPPRESS_IFGROUP   13
+FRA_SUPPRESS_PREFIXLEN 14
+FRA_TABLE              15
+FRA_FWMASK             16
+FRA_OIFNAME            17
+FRA_PAD                        18
+FRA_L3MDEV             19
+FRA_UID_RANGE          20