diff options
author | Dmitry V. Levin <ldv@altlinux.org> | 2017-08-29 10:09:04 +0000 |
---|---|---|
committer | Dmitry V. Levin <ldv@altlinux.org> | 2017-08-29 10:09:04 +0000 |
commit | a6a1bc9abcb22ed01bf9ffd6dbf8ccbadf79ba7d (patch) | |
tree | d9d2b11fbf877d9fe1e898ea5f9c7ff1e16e2b1c | |
parent | b2278dc30aa13ab1b268ab9267ddb4c517cce3fb (diff) | |
download | strace-a6a1bc9abcb22ed01bf9ffd6dbf8ccbadf79ba7d.tar.gz |
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) <RTA_TABLE>: Use it.
* tests/nlattr_rtmsg.c (main): Check RTA_TABLE decoding.
-rw-r--r-- | nlattr.h | 1 | ||||
-rw-r--r-- | rtnl_route.c | 17 | ||||
-rw-r--r-- | tests/nlattr_rtmsg.c | 6 |
3 files changed, 23 insertions, 1 deletions
@@ -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 7a04a9222..102b8057c 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 1e628c268..5f29f0c0c 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) |