diff options
author | Eugene Syromyatnikov <evgsyr@gmail.com> | 2018-08-19 14:30:59 +0200 |
---|---|---|
committer | Dmitry V. Levin <ldv@strace.io> | 2021-11-11 08:00:00 +0000 |
commit | 7d6d181720d56537a4f7975fb4d38febb4b2b54a (patch) | |
tree | e4548d5eeb90696f049c2c3929236692f8abd905 /src/rtnl_cachereport.c | |
parent | f76cf11ea25386abfe5480a45b61c2ccdc22c6a0 (diff) | |
download | strace-7d6d181720d56537a4f7975fb4d38febb4b2b54a.tar.gz |
netlink_route: implement RTM_NEWCACHEREPORT message decoding
* bundled/linux/include/uapi/linux/mroute.h: New file, copied from
headers_install'ed Linux kernel v5.15.
* bundled/linux/include/uapi/linux/mroute6.h: Likewise.
* bundled/Makefile.am (EXTRA_DIST): Add them.
* src/xlat/rtnl_family.in: New file.
* src/xlat/rtnl_ip6mra_creport_attr.in: Likewise.
* src/xlat/rtnl_ip6mra_msg_types.in: Likewise.
* src/xlat/rtnl_ipmra_creport_attr.in: Likewise.
* src/xlat/rtnl_ipmra_msg_types.in: Likewise.
* src/rtnl_cachereport.c: Likewise.
* src/Makefile.am (strace_SOURCES): Add it.
* src/netlink_route.c (route_decoders) <[RTM_NEWCACHEREPORT - RTM_BASE]>:
New decoder, call decode_cachereport.
* src/netlink_route.h (decode_cachereport): New declaration.
* tests/.gitignore: Add nlattr_cachereport, nlattr_cachereport-Xabbrev,
nlattr_cachereport-Xraw, and nlattr_cachereport-Xverbose.
* tests/pure_executables.list: Likewise.
* tests/netlink_route.c (test_rtnl_rtgen) <types>: Add
RTM_NEWCACHEREPORT.
(test_rtnl_rtgen): Move RTM_NEWCACHEREPORT-related unknown message
checks from...
(main): ...here. Remove the unsupported message check
for RTM_NEWCACHEREPORT.
* tests/nlattr_cachereport.c: New file.
* tests/nlattr_cachereport-Xabbrev.c: Likewise.
* tests/nlattr_cachereport-Xraw.c: Likewise.
* tests/nlattr_cachereport-Xverbose.c: Likewise.
* tests/gen_tests.in (nlattr_cachereport, nlattr_cachereport-Xabbrev,
nlattr_cachereport-Xraw, nlattr_cachereport-Xverbose): New tests.
* NEWS: Mention it.
Diffstat (limited to 'src/rtnl_cachereport.c')
-rw-r--r-- | src/rtnl_cachereport.c | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/rtnl_cachereport.c b/src/rtnl_cachereport.c new file mode 100644 index 000000000..ad0c224ce --- /dev/null +++ b/src/rtnl_cachereport.c @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2018-2021 Eugene Syromyatnikov <evgsyr@gmail.com> + * All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "defs.h" +#include "netlink_route.h" +#include "nlattr.h" +#include "print_fields.h" + +#include "netlink.h" +#include <linux/mroute.h> +#include <linux/mroute6.h> +#include <linux/rtnetlink.h> + +#include "xlat/rtnl_ip6mra_creport_attr.h" +#include "xlat/rtnl_ip6mra_msg_types.h" +#include "xlat/rtnl_ipmra_creport_attr.h" +#include "xlat/rtnl_ipmra_msg_types.h" +#include "xlat/rtnl_family.h" + +static bool +decode_nla_ipmra_msg_type(struct tcb *const tcp, + const kernel_ulong_t addr, + const unsigned int len, + const void *const opaque_data) +{ + const struct decode_nla_xlat_opts opts = { + .xlat = rtnl_ipmra_msg_types, + .dflt = "IGMPMSG_???", + .size = 1, + }; + + return decode_nla_xval(tcp, addr, len, &opts); +} + +static const nla_decoder_t rtnl_creport_ipmra_decoders[] = { + [IPMRA_CREPORT_UNSPEC] = NULL, + [IPMRA_CREPORT_MSGTYPE] = decode_nla_ipmra_msg_type, + [IPMRA_CREPORT_VIF_ID] = decode_nla_u32, + [IPMRA_CREPORT_SRC_ADDR] = decode_nla_in_addr, + [IPMRA_CREPORT_DST_ADDR] = decode_nla_in_addr, + [IPMRA_CREPORT_PKT] = NULL, /* raw packet data */ + [IPMRA_CREPORT_TABLE] = decode_nla_u32, +}; + +static bool +decode_nla_ip6mra_msg_type(struct tcb *const tcp, + const kernel_ulong_t addr, + const unsigned int len, + const void *const opaque_data) +{ + const struct decode_nla_xlat_opts opts = { + .xlat = rtnl_ip6mra_msg_types, + .dflt = "MRT6MSG_???", + .size = 1, + }; + + return decode_nla_xval(tcp, addr, len, &opts); +} + +static const nla_decoder_t rtnl_creport_ip6mra_decoders[] = { + [IP6MRA_CREPORT_UNSPEC] = NULL, + [IP6MRA_CREPORT_MSGTYPE] = decode_nla_ip6mra_msg_type, + [IP6MRA_CREPORT_MIF_ID] = decode_nla_u32, + [IP6MRA_CREPORT_SRC_ADDR] = decode_nla_in6_addr, + [IP6MRA_CREPORT_DST_ADDR] = decode_nla_in6_addr, + [IP6MRA_CREPORT_PKT] = NULL, /* raw packet data */ +}; + +DECL_NETLINK_ROUTE_DECODER(decode_cachereport) +{ + static const struct af_spec_decoder_desc cachereport_descs[] = { + { RTNL_FAMILY_IPMR, + rtnl_ipmra_creport_attr, "IPMRA_CREPORT_???", + ARRSZ_PAIR(rtnl_creport_ipmra_decoders) }, + { RTNL_FAMILY_IP6MR, + rtnl_ip6mra_creport_attr, "IP6MRA_CREPORT_???", + ARRSZ_PAIR(rtnl_creport_ip6mra_decoders) }, + }; + + struct rtgenmsg rtgenmsg = { .rtgen_family = family }; + + tprint_struct_begin(); + tprints_field_name("rtgen_family"); + printxvals_ex(rtgenmsg.rtgen_family, "RTNL_FAMILY_???", + XLAT_STYLE_DEFAULT, rtnl_family, addrfams, NULL); + tprint_struct_end(); + + const size_t offset = NLMSG_ALIGN(sizeof(rtgenmsg)); + + if (len > offset) { + tprint_array_next(); + decode_nla_af_spec(tcp, addr + offset, len - offset, + rtgenmsg.rtgen_family, + ARRSZ_PAIR(cachereport_descs)); + } +} |