]> granicus.if.org Git - strace/commitdiff
rtnl_route: enhance RTA_TABLE decoding
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 29 Aug 2017 10:09:04 +0000 (10:09 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 29 Aug 2017 10:09:04 +0000 (10:09 +0000)
The attribute of RTA_TABLE is not just a 32-bit integer, some constants
have well-known symbolic names like RT_TABLE_DEFAULT.

* nlattr.h (decode_nla_rt_class): New prototype.
* rtnl_route.c (decode_nla_rt_class): New function.
(rtmsg_nla_decoders) <RTA_TABLE>: Use it.
* tests/nlattr_rtmsg.c (main): Check RTA_TABLE decoding.

nlattr.h
rtnl_route.c
tests/nlattr_rtmsg.c

index 09c233e76d0546e470fdf649593e73d16877ba82..6e7d1a7b5695ec2be60b2f792d9d3580892ab973 100644 (file)
--- a/nlattr.h
+++ b/nlattr.h
@@ -62,5 +62,6 @@ DECL_NLA(str);
 DECL_NLA(strn);
 DECL_NLA(ifindex);
 DECL_NLA(meminfo);
+DECL_NLA(rt_class);
 
 #endif /* !STRACE_NLATTR_H */
index 7a04a922293764f38574caec752cd5b257692e71..102b8057cf23ae9368667f8fe17ba4e2be331a8a 100644 (file)
 #include "xlat/rtnl_route_attrs.h"
 #include "xlat/rtnl_rta_metrics_attrs.h"
 
+bool
+decode_nla_rt_class(struct tcb *const tcp,
+                   const kernel_ulong_t addr,
+                   const unsigned int len,
+                   const void *const opaque_data)
+{
+       uint32_t num;
+
+       if (len < sizeof(num))
+               return false;
+       if (!umove_or_printaddr(tcp, addr, &num))
+               printxval(routing_table_ids, num, NULL);
+       return true;
+}
+
 static bool
 decode_route_addr(struct tcb *const tcp,
                  const kernel_ulong_t addr,
@@ -207,7 +222,7 @@ static const nla_decoder_t rtmsg_nla_decoders[] = {
        [RTA_CACHEINFO]         = decode_rta_cacheinfo,
        [RTA_SESSION]           = NULL, /* unused */
        [RTA_MP_ALGO]           = decode_nla_u32,
-       [RTA_TABLE]             = decode_nla_u32,
+       [RTA_TABLE]             = decode_nla_rt_class,
        [RTA_MARK]              = decode_nla_u32,
        [RTA_MFC_STATS]         = decode_rta_mfc_stats,
        [RTA_VIA]               = decode_rtvia,
index 1e628c2689da5ef1655e8af1b263e0f16136075a..5f29f0c0ce2024f97034121d75293dc9ebeabfbb 100644 (file)
@@ -106,6 +106,12 @@ main(void)
                           RTA_OIF, pattern, ifindex,
                           printf(IFINDEX_LO_STR));
 
+       const uint32_t rt_class_id = RT_TABLE_DEFAULT;
+       TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+                          init_rtmsg, print_rtmsg,
+                          RTA_TABLE, pattern, rt_class_id,
+                          printf("RT_TABLE_DEFAULT"));
+
        struct nlattr nla = {
                .nla_type = RTAX_LOCK,
                .nla_len = sizeof(nla)