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.
This commit is contained in:
parent
b2278dc30a
commit
a6a1bc9abc
1
nlattr.h
1
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 */
|
||||
|
17
rtnl_route.c
17
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,
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user