aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorJon Maloy <jmaloy@redhat.com>2025-03-06 13:00:05 -0500
committerStefano Brivio <sbrivio@redhat.com>2025-03-07 02:21:24 +0100
commit87e6a464429372dfaa7212b61e5062dad87179dc (patch)
treece7dd33f989a521a8a5cbdc6bd25d72a82627edc
parent55431f0077b6a25c264bd2492680d7f99815cc5f (diff)
downloadpasst-87e6a464429372dfaa7212b61e5062dad87179dc.tar
passt-87e6a464429372dfaa7212b61e5062dad87179dc.tar.gz
passt-87e6a464429372dfaa7212b61e5062dad87179dc.tar.bz2
passt-87e6a464429372dfaa7212b61e5062dad87179dc.tar.lz
passt-87e6a464429372dfaa7212b61e5062dad87179dc.tar.xz
passt-87e6a464429372dfaa7212b61e5062dad87179dc.tar.zst
passt-87e6a464429372dfaa7212b61e5062dad87179dc.zip
tap: break out building of udp header from tap_udp6_send function
We will need to build the UDP header at other locations than in function tap_udp6_send(), so we break that part out to a separate function. Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Jon Maloy <jmaloy@redhat.com> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--tap.c40
-rw-r--r--tap.h4
2 files changed, 35 insertions, 9 deletions
diff --git a/tap.c b/tap.c
index 57d0795..7082620 100644
--- a/tap.c
+++ b/tap.c
@@ -265,7 +265,7 @@ void *tap_push_ip6h(struct ipv6hdr *ip6h,
}
/**
- * tap_udp6_send() - Send UDP over IPv6 packet
+ * tap_push_uh6() - Build UDPv6 header with checksum
* @c: Execution context
* @src: IPv6 source address
* @sport: UDP source port
@@ -274,18 +274,15 @@ void *tap_push_ip6h(struct ipv6hdr *ip6h,
* @flow: Flow label
* @in: UDP payload contents (not including UDP header)
* @dlen: UDP payload length (not including UDP header)
+ *
+ * Return: pointer at which to write the packet's payload
*/
-void tap_udp6_send(const struct ctx *c,
+void *tap_push_uh6(struct udphdr *uh,
const struct in6_addr *src, in_port_t sport,
const struct in6_addr *dst, in_port_t dport,
- uint32_t flow, void *in, size_t dlen)
+ void *in, size_t dlen)
{
size_t l4len = dlen + sizeof(struct udphdr);
- char buf[USHRT_MAX];
- struct ipv6hdr *ip6h = tap_push_l2h(c, buf, ETH_P_IPV6);
- struct udphdr *uh = tap_push_ip6h(ip6h, src, dst,
- l4len, IPPROTO_UDP, flow);
- char *data = (char *)(uh + 1);
const struct iovec iov = {
.iov_base = in,
.iov_len = dlen
@@ -296,8 +293,33 @@ void tap_udp6_send(const struct ctx *c,
uh->dest = htons(dport);
uh->len = htons(l4len);
csum_udp6(uh, src, dst, &payload);
- memcpy(data, in, dlen);
+ return (char *)uh + sizeof(*uh);
+}
+/**
+ * tap_udp6_send() - Send UDP over IPv6 packet
+ * @c: Execution context
+ * @src: IPv6 source address
+ * @sport: UDP source port
+ * @dst: IPv6 destination address
+ * @dport: UDP destination port
+ * @flow: Flow label
+ * @in: UDP payload contents (not including UDP header)
+ * @dlen: UDP payload length (not including UDP header)
+ */
+void tap_udp6_send(const struct ctx *c,
+ const struct in6_addr *src, in_port_t sport,
+ const struct in6_addr *dst, in_port_t dport,
+ uint32_t flow, void *in, size_t dlen)
+{
+ size_t l4len = dlen + sizeof(struct udphdr);
+ char buf[USHRT_MAX];
+ struct ipv6hdr *ip6h = tap_push_l2h(c, buf, ETH_P_IPV6);
+ struct udphdr *uh = tap_push_ip6h(ip6h, src, dst,
+ l4len, IPPROTO_UDP, flow);
+ char *data = tap_push_uh6(uh, src, sport, dst, dport, in, dlen);
+
+ memcpy(data, in, dlen);
tap_send_single(c, buf, dlen + (data - buf));
}
diff --git a/tap.h b/tap.h
index 9ac17ce..b53a5b8 100644
--- a/tap.h
+++ b/tap.h
@@ -50,6 +50,10 @@ void *tap_push_ip4h(struct iphdr *ip4h, struct in_addr src,
void *tap_push_uh4(struct udphdr *uh, struct in_addr src, in_port_t sport,
struct in_addr dst, in_port_t dport,
const void *in, size_t dlen);
+void *tap_push_uh6(struct udphdr *uh,
+ const struct in6_addr *src, in_port_t sport,
+ const struct in6_addr *dst, in_port_t dport,
+ void *in, size_t dlen);
void *tap_push_ip4h(struct iphdr *ip4h, struct in_addr src,
struct in_addr dst, size_t l4len, uint8_t proto);
void tap_udp4_send(const struct ctx *c, struct in_addr src, in_port_t sport,