[PATCH 2/3] rtnl_route: find lwtunnel encap type
Mathis Marion
Mathis.Marion at silabs.com
Mon Oct 23 08:56:35 UTC 2023
From: Mathis Marion <mathis.marion at silabs.com>
This is necessary to decode RTA_ENCAP attributes. Therer are no
requirement regarding the placement of RTA_ENCAP_TYPE in relation to
RTA_ENCAP, so it must be found before decoding.
---
src/rtnl_route.c | 37 +++++++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/src/rtnl_route.c b/src/rtnl_route.c
index 331d35f53..6bb34cfd1 100644
--- a/src/rtnl_route.c
+++ b/src/rtnl_route.c
@@ -245,6 +245,34 @@ static const nla_decoder_t rtmsg_nla_decoders[] = {
[RTA_DPORT] = decode_nla_u16
};
+static uint16_t
+find_lwt_encap_type(struct tcb *const tcp,
+ kernel_ulong_t addr,
+ unsigned int len)
+{
+ uint16_t lwt_encap_type;
+ unsigned int nla_len;
+ struct nlattr nla;
+
+ while (len >= sizeof(struct nlattr)) {
+ if (!tfetch_obj(tcp, addr, &nla))
+ return 0;
+ if (nla.nla_len < NLA_HDRLEN)
+ return 0;
+
+ nla_len = MIN(nla.nla_len, len);
+ if ((nla.nla_type & NLA_TYPE_MASK) == RTA_ENCAP_TYPE &&
+ nla_len - NLA_HDRLEN >= sizeof(lwt_encap_type) &&
+ !umove(tcp, addr + NLA_HDRLEN, &lwt_encap_type))
+ return lwt_encap_type;
+
+ nla_len = NLA_ALIGN(nla.nla_len);
+ len -= MIN(len, nla_len);
+ addr += nla_len;
+ }
+ return 0;
+}
+
/*
* RTA_MULTIPATH payload is a list of struct rtnexthop-headed RTA_* netlink
* attributes:
@@ -258,6 +286,7 @@ decode_rta_multipath(struct tcb *const tcp,
const unsigned int len,
const void *const opaque_data)
{
+ struct rtmsg_ctx ctx = *(const struct rtmsg_ctx *)opaque_data;
bool is_array = false;
struct rtnexthop nh;
kernel_ulong_t cur = addr;
@@ -294,12 +323,14 @@ decode_rta_multipath(struct tcb *const tcp,
tprint_struct_end();
if (rtnh_len > offset) {
+ ctx.lwt_encap_type = find_lwt_encap_type(tcp,
+ addr + offset,
+ len - offset);
tprint_array_next();
decode_nlattr(tcp, cur + offset, rtnh_len - offset,
rtnl_route_attrs, "RTA_???",
rtmsg_nla_decoders,
- ARRAY_SIZE(rtmsg_nla_decoders),
- opaque_data);
+ ARRAY_SIZE(rtmsg_nla_decoders), &ctx);
}
if (rtnh_len > offset)
@@ -361,6 +392,8 @@ DECL_NETLINK_ROUTE_DECODER(decode_rtmsg)
offset = NLMSG_ALIGN(sizeof(ctx.rtmsg));
if (decode_nla && len > offset) {
+ ctx.lwt_encap_type = find_lwt_encap_type(tcp, addr + offset,
+ len - offset);
tprint_array_next();
decode_nlattr(tcp, addr + offset, len - offset,
rtnl_route_attrs, "RTA_???",
--
2.42.0
More information about the Strace-devel
mailing list