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

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

index f25d0382581a3045a6687ffd721110b535297ba0..7b997f8f64528b24fa33c34e640486c344da9900 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "defs.h"
 #include "netlink_route.h"
+#include "nlattr.h"
 #include "print_fields.h"
 
 #include <linux/ip.h>
 #include "xlat/routing_protocols.h"
 #include "xlat/routing_table_ids.h"
 #include "xlat/routing_types.h"
+#include "xlat/rtnl_route_attrs.h"
 
 DECL_NETLINK_ROUTE_DECODER(decode_rtmsg)
 {
        struct rtmsg rtmsg = { .rtm_family = family };
-       const size_t offset = sizeof(rtmsg.rtm_family);
+       size_t offset = sizeof(rtmsg.rtm_family);
+       bool decode_nla = false;
 
        PRINT_FIELD_XVAL("{", rtmsg, rtm_family, addrfams, "AF_???");
 
@@ -67,8 +70,16 @@ DECL_NETLINK_ROUTE_DECODER(decode_rtmsg)
                                         routing_types, "RTN_???");
                        PRINT_FIELD_FLAGS(", ", rtmsg, rtm_flags,
                                          routing_flags, "RTM_F_???");
+                       decode_nla = true;
                }
        } else
                tprints("...");
        tprints("}");
+
+       offset = NLMSG_ALIGN(sizeof(rtmsg));
+       if (decode_nla && len > offset) {
+               tprints(", ");
+               decode_nlattr(tcp, addr + offset, len - offset,
+                             rtnl_route_attrs, "RTA_???", NULL, 0, NULL);
+       }
 }
diff --git a/xlat/rtnl_route_attrs.in b/xlat/rtnl_route_attrs.in
new file mode 100644 (file)
index 0000000..f5fa559
--- /dev/null
@@ -0,0 +1,27 @@
+RTA_UNSPEC             0
+RTA_DST                        1
+RTA_SRC                        2
+RTA_IIF                        3
+RTA_OIF                        4
+RTA_GATEWAY            5
+RTA_PRIORITY           6
+RTA_PREFSRC            7
+RTA_METRICS            8
+RTA_MULTIPATH          9
+RTA_PROTOINFO          10
+RTA_FLOW               11
+RTA_CACHEINFO          12
+RTA_SESSION            13
+RTA_MP_ALGO            14
+RTA_TABLE              15
+RTA_MARK               16
+RTA_MFC_STATS          17
+RTA_VIA                        18
+RTA_NEWDST             19
+RTA_PREF               20
+RTA_ENCAP_TYPE         21
+RTA_ENCAP              22
+RTA_EXPIRES            23
+RTA_PAD                        24
+RTA_UID                        25
+RTA_TTL_PROPAGATE      26