]> granicus.if.org Git - strace/commitdiff
rtnl_rule: decode fib_rule_hdr netlink attributes
authorJingPiao Chen <chenjingpiao@gmail.com>
Sun, 27 Aug 2017 16:33:30 +0000 (00:33 +0800)
committerJingPiao Chen <chenjingpiao@gmail.com>
Tue, 29 Aug 2017 07:13:12 +0000 (15:13 +0800)
* configure.ac (AC_CHECK_FUNCS): Add be64toh.
(AC_CHECK_TYPES): Check for struct fib_rule_uid_range
in <linux/fib_rules.h>.
* nlattr.c: Include <endian.h>.
(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
nlattr.c
nlattr.h
rtnl_rule.c

index f09ae5dca3d3ae2474bc499b1776d3ba71993f2d..bcf51297fe04a890d76271962b3a74047e821ac8 100644 (file)
@@ -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 <linux/if_link.h>])
 
+AC_CHECK_TYPES([struct fib_rule_uid_range],,, [#include <linux/fib_rules.h>])
+
 AC_CHECK_TYPES([struct statfs], [
        AC_CHECK_MEMBERS(m4_normalize([
                struct statfs.f_frsize,
index 76010c446d17c818ede8225b00456695ca54f7c4..847fa3935b5baf46fef2b4a084eecddb6a2d892f 100644 (file)
--- a/nlattr.c
+++ b/nlattr.c
@@ -28,6 +28,7 @@
  */
 
 #include "defs.h"
+#include <endian.h>
 #include "netlink.h"
 #include "nlattr.h"
 #include <linux/sock_diag.h>
@@ -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,             \
index 636c7872eb07133f52097e219beaaae8c4afb03e..db1fd69f27b075c142fdf1034a0ccb6a8bd0072a 100644 (file)
--- 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);
index 5a1dd2894cd4b02370254f4b461ca6480fc393d6..6bc49f517a87b6881f7bc40db2667adb4e822dc0 100644 (file)
 #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);
        }
 }