From b9a437c1471f946e93ab33e7befecc7bc8ff6694 Mon Sep 17 00:00:00 2001 From: JingPiao Chen Date: Mon, 28 Aug 2017 00:33:30 +0800 Subject: [PATCH] rtnl_rule: decode fib_rule_hdr netlink attributes * configure.ac (AC_CHECK_FUNCS): Add be64toh. (AC_CHECK_TYPES): Check for struct fib_rule_uid_range in . * nlattr.c: Include . (decode_nla_be64): New function. * nlattr.h (decode_nla_be64): New prototype. * rtnl_rule.c (decode_rule_addr, decode_fib_rule_uid_range): New functions. (fib_rule_hdr_nla_decoders): New array. (decode_fib_rule_hdr): Use it. --- configure.ac | 3 +++ nlattr.c | 21 +++++++++++++++++++ nlattr.h | 1 + rtnl_rule.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 83 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index f09ae5dc..bcf51297 100644 --- a/configure.ac +++ b/configure.ac @@ -268,6 +268,7 @@ AC_TYPE_UID_T AC_CHECK_FUNCS(m4_normalize([ accept4 + be64toh fallocate fanotify_mark fopen64 @@ -459,6 +460,8 @@ AC_CHECK_MEMBERS(m4_normalize([ struct rtnl_link_stats64.rx_nohandler ]),,, [#include ]) +AC_CHECK_TYPES([struct fib_rule_uid_range],,, [#include ]) + AC_CHECK_TYPES([struct statfs], [ AC_CHECK_MEMBERS(m4_normalize([ struct statfs.f_frsize, diff --git a/nlattr.c b/nlattr.c index 76010c44..847fa393 100644 --- a/nlattr.c +++ b/nlattr.c @@ -28,6 +28,7 @@ */ #include "defs.h" +#include #include "netlink.h" #include "nlattr.h" #include @@ -220,6 +221,26 @@ decode_nla_ifindex(struct tcb *const tcp, return true; } +bool +decode_nla_be64(struct tcb *const tcp, + const kernel_ulong_t addr, + const unsigned int len, + const void *const opaque_data) +{ +#if defined HAVE_BE64TOH || defined be64toh + uint64_t num; + + if (len < sizeof(num)) + return false; + else if (!umove_or_printaddr(tcp, addr, &num)) + tprintf("htobe64(%" PRIu64 ")", be64toh(num)); + + return true; +#else + return false; +#endif +} + #define DECODE_NLA_INTEGER(name, type, fmt) \ bool \ decode_nla_ ## name(struct tcb *const tcp, \ diff --git a/nlattr.h b/nlattr.h index 636c7872..db1fd69f 100644 --- a/nlattr.h +++ b/nlattr.h @@ -56,6 +56,7 @@ DECL_NLA(s8); DECL_NLA(s16); DECL_NLA(s32); DECL_NLA(s64); +DECL_NLA(be64); DECL_NLA(str); DECL_NLA(strn); DECL_NLA(ifindex); diff --git a/rtnl_rule.c b/rtnl_rule.c index 5a1dd289..6bc49f51 100644 --- a/rtnl_rule.c +++ b/rtnl_rule.c @@ -43,6 +43,61 @@ #include "xlat/fib_rule_flags.h" #include "xlat/rtnl_rule_attrs.h" +static bool +decode_rule_addr(struct tcb *const tcp, + const kernel_ulong_t addr, + const unsigned int len, + const void *const opaque_data) +{ + const struct rtmsg *const rtmsg = opaque_data; + + decode_inet_addr(tcp, addr, len, rtmsg->rtm_family, NULL); + + return true; +} + +static bool +decode_fib_rule_uid_range(struct tcb *const tcp, + const kernel_ulong_t addr, + const unsigned int len, + const void *const opaque_data) +{ +#ifdef HAVE_STRUCT_FIB_RULE_UID_RANGE + struct fib_rule_uid_range range; + + if (len < sizeof(range)) + return false; + else if (!umove_or_printaddr(tcp, addr, &range)) { + PRINT_FIELD_U("{", range, start); + PRINT_FIELD_U(", ", range, end); + tprints("}"); + } + + return true; +#else + return false; +#endif +} + +static const nla_decoder_t fib_rule_hdr_nla_decoders[] = { + [FRA_DST] = decode_rule_addr, + [FRA_SRC] = decode_rule_addr, + [FRA_IIFNAME] = decode_nla_str, + [FRA_GOTO] = decode_nla_u32, + [FRA_PRIORITY] = decode_nla_u32, + [FRA_FWMARK] = decode_nla_u32, + [FRA_FLOW] = decode_nla_u32, + [FRA_TUN_ID] = decode_nla_be64, + [FRA_SUPPRESS_IFGROUP] = decode_nla_u32, + [FRA_SUPPRESS_PREFIXLEN] = decode_nla_u32, + [FRA_TABLE] = decode_nla_u32, + [FRA_FWMASK] = decode_nla_u32, + [FRA_OIFNAME] = decode_nla_str, + [FRA_PAD] = NULL, + [FRA_L3MDEV] = decode_nla_u8, + [FRA_UID_RANGE] = decode_fib_rule_uid_range +}; + DECL_NETLINK_ROUTE_DECODER(decode_fib_rule_hdr) { /* @@ -84,6 +139,8 @@ DECL_NETLINK_ROUTE_DECODER(decode_fib_rule_hdr) if (decode_nla && len > offset) { tprints(", "); decode_nlattr(tcp, addr + offset, len - offset, - rtnl_rule_attrs, "FRA_???", NULL, 0, NULL); + rtnl_rule_attrs, "FRA_???", + fib_rule_hdr_nla_decoders, + ARRAY_SIZE(fib_rule_hdr_nla_decoders), &msg); } } -- 2.40.0