From: Dmitry V. Levin Date: Tue, 29 Aug 2017 10:09:04 +0000 (+0000) Subject: rtnl_route: enhance RTA_TABLE decoding X-Git-Tag: v4.19~29 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a6a1bc9abcb22ed01bf9ffd6dbf8ccbadf79ba7d;p=strace rtnl_route: enhance RTA_TABLE decoding 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) : Use it. * tests/nlattr_rtmsg.c (main): Check RTA_TABLE decoding. --- diff --git a/nlattr.h b/nlattr.h index 09c233e7..6e7d1a7b 100644 --- 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 */ diff --git a/rtnl_route.c b/rtnl_route.c index 7a04a922..102b8057 100644 --- a/rtnl_route.c +++ b/rtnl_route.c @@ -46,6 +46,21 @@ #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, diff --git a/tests/nlattr_rtmsg.c b/tests/nlattr_rtmsg.c index 1e628c26..5f29f0c0 100644 --- a/tests/nlattr_rtmsg.c +++ b/tests/nlattr_rtmsg.c @@ -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)