From 4ee22cabea44c8e8031fb63d34df6f7b2c1be8af Mon Sep 17 00:00:00 2001 From: JingPiao Chen <chenjingpiao@gmail.com> Date: Tue, 15 Aug 2017 12:41:13 +0800 Subject: [PATCH] netlink: add basic decoding of NETLINK_ROUTE fib_rule_hdr attributes * 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 | 13 ++++++++++++- xlat/rtnl_rule_attrs.in | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 xlat/rtnl_rule_attrs.in diff --git a/rtnl_rule.c b/rtnl_rule.c index b3e6d526..5a1dd289 100644 --- a/rtnl_rule.c +++ b/rtnl_rule.c @@ -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 index 00000000..971f1180 --- /dev/null +++ b/xlat/rtnl_rule_attrs.in @@ -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 -- 2.40.0