* configure.ac (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 |  2 ++
 nlattr.c     | 17 +++++++++++++++++
 nlattr.h     |  1 +
 rtnl_rule.c  | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index f09ae5d..2bcd302 100644
--- a/configure.ac
+++ b/configure.ac
@@ -459,6 +459,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,
diff --git a/nlattr.c b/nlattr.c
index 76010c4..fa514e1 100644
--- 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,22 @@ 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)
+{
+       uint64_t num;
+
+       if (len < sizeof(num))
+               return false;
+       else if (!umove_or_printaddr(tcp, addr, &num))
+               tprintf("htobe64(%" PRIu64 ")", be64toh(num));
+
+       return true;
+}
+
 #define DECODE_NLA_INTEGER(name, type, fmt)            \
 bool                                                   \
 decode_nla_ ## name(struct tcb *const tcp,             \
diff --git a/nlattr.h b/nlattr.h
index 636c787..db1fd69 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 5a1dd28..6bc49f5 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.7.4


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to