diff options
author | Laurent Vivier <lvivier@redhat.com> | 2025-09-02 09:52:41 +0200 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2025-09-03 20:43:31 +0200 |
commit | 20cd6d0b8632ad520fd90bf11310429fed04d9fb (patch) | |
tree | f583bab753e33344e5082d8d2dc10c9a42e9a805 | |
parent | 84a4d3e9dcd733f0c59881ca94ec761c1b64671e (diff) | |
download | passt-20cd6d0b8632ad520fd90bf11310429fed04d9fb.tar passt-20cd6d0b8632ad520fd90bf11310429fed04d9fb.tar.gz passt-20cd6d0b8632ad520fd90bf11310429fed04d9fb.tar.bz2 passt-20cd6d0b8632ad520fd90bf11310429fed04d9fb.tar.lz passt-20cd6d0b8632ad520fd90bf11310429fed04d9fb.tar.xz passt-20cd6d0b8632ad520fd90bf11310429fed04d9fb.tar.zst passt-20cd6d0b8632ad520fd90bf11310429fed04d9fb.zip |
ip: Use iov_tail in ipv6_l4hdr()
Use packet_data() and extract headers using IOV_REMOVE_HEADER()
and IOV_PEEK_HEADER() rather than packet_get().
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r-- | ip.c | 33 | ||||
-rw-r--r-- | ip.h | 3 | ||||
-rw-r--r-- | packet.c | 1 | ||||
-rw-r--r-- | tap.c | 4 |
4 files changed, 20 insertions, 21 deletions
@@ -23,50 +23,47 @@ /** * ipv6_l4hdr() - Find pointer to L4 header in IPv6 packet and extract protocol - * @p: Packet pool, packet number @idx has IPv6 header at @offset - * @idx: Index of packet in pool - * @offset: Pre-calculated IPv6 header offset + * @data: IPv6 packet * @proto: Filled with L4 protocol number * @dlen: Data length (payload excluding header extensions), set on return * - * Return: pointer to L4 header, NULL if not found + * Return: true if the L4 header is found and @data, @proto, @dlen are set, + * false on error. Outputs are indeterminate on failure. */ -char *ipv6_l4hdr(const struct pool *p, int idx, size_t offset, uint8_t *proto, - size_t *dlen) +bool ipv6_l4hdr(struct iov_tail *data, uint8_t *proto, size_t *dlen) { + struct ipv6_opt_hdr o_storage; const struct ipv6_opt_hdr *o; + struct ipv6hdr ip6h_storage; const struct ipv6hdr *ip6h; - char *base; int hdrlen; uint8_t nh; - base = packet_get(p, idx, 0, 0, NULL); - ip6h = packet_get(p, idx, offset, sizeof(*ip6h), dlen); + ip6h = IOV_REMOVE_HEADER(data, ip6h_storage); if (!ip6h) - return NULL; - - offset += sizeof(*ip6h); + return false; nh = ip6h->nexthdr; if (!IPV6_NH_OPT(nh)) goto found; - while ((o = packet_get_try(p, idx, offset, sizeof(*o), dlen))) { + while ((o = IOV_PEEK_HEADER(data, o_storage))) { nh = o->nexthdr; hdrlen = (o->hdrlen + 1) * 8; if (IPV6_NH_OPT(nh)) - offset += hdrlen; + iov_drop_header(data, hdrlen); else goto found; } - return NULL; + return false; found: - if (nh == 59) - return NULL; + if (nh == IPPROTO_NONE) + return false; + *dlen = iov_tail_size(data); *proto = nh; - return base + offset; + return true; } @@ -115,8 +115,7 @@ static inline uint32_t ip6_get_flow_lbl(const struct ipv6hdr *ip6h) ip6h->flow_lbl[2]; } -char *ipv6_l4hdr(const struct pool *p, int idx, size_t offset, uint8_t *proto, - size_t *dlen); +bool ipv6_l4hdr(struct iov_tail *data, uint8_t *proto, size_t *dlen); /* IPv6 link-local all-nodes multicast address, ff02::1 */ static const struct in6_addr in6addr_ll_all_nodes = { @@ -133,6 +133,7 @@ void packet_add_do(struct pool *p, struct iov_tail *data, * * Return: pointer to start of data range, NULL on invalid range or descriptor */ +/* cppcheck-suppress [staticFunction] */ void *packet_get_try_do(const struct pool *p, size_t idx, size_t offset, size_t len, size_t *left, const char *func, int line) { @@ -911,8 +911,10 @@ resume: if (plen != check) continue; - if (!(l4h = ipv6_l4hdr(in, i, sizeof(*eh), &proto, &l4len))) + data = IOV_TAIL_FROM_BUF(ip6h, sizeof(*ip6h) + check, 0); + if (!ipv6_l4hdr(&data, &proto, &l4len)) continue; + l4h = (char *)data.iov[0].iov_base + data.off; if (IN6_IS_ADDR_LOOPBACK(saddr) || IN6_IS_ADDR_LOOPBACK(daddr)) { char sstr[INET6_ADDRSTRLEN], dstr[INET6_ADDRSTRLEN]; |