diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2024-11-27 14:54:09 +1100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2024-11-28 14:03:16 +0100 |
commit | a6348cad51398346b1ce1009be87a718b8f72bba (patch) | |
tree | 614b4a482354552cc752ef3a461c052765237d9b /tcp_vu.c | |
parent | 2abf5ab7f3734eae9377cfab4759ae83fabf3a7e (diff) | |
download | passt-a6348cad51398346b1ce1009be87a718b8f72bba.tar passt-a6348cad51398346b1ce1009be87a718b8f72bba.tar.gz passt-a6348cad51398346b1ce1009be87a718b8f72bba.tar.bz2 passt-a6348cad51398346b1ce1009be87a718b8f72bba.tar.lz passt-a6348cad51398346b1ce1009be87a718b8f72bba.tar.xz passt-a6348cad51398346b1ce1009be87a718b8f72bba.tar.zst passt-a6348cad51398346b1ce1009be87a718b8f72bba.zip |
tcp: Merge tcp_fill_headers[46]() with each other
We have different versions of this function for IPv4 and IPv6, but the
caller already requires some IP version specific code to get the right
header pointers. Instead, have a common function that fills either an
IPv4 or an IPv6 header based on which header pointer it is passed. This
allows us to remove a small amount of code duplication and make a few
slightly ugly conditionals.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp_vu.c')
-rw-r--r-- | tcp_vu.c | 32 |
1 files changed, 12 insertions, 20 deletions
@@ -111,9 +111,9 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) size_t optlen, hdrlen; struct vu_virtq_element flags_elem[2]; struct ipv6hdr *ip6h = NULL; + struct iphdr *ip4h = NULL; struct iovec flags_iov[2]; struct tcp_syn_opts *opts; - struct iphdr *iph = NULL; struct iov_tail payload; struct tcphdr *th; struct ethhdr *eh; @@ -144,8 +144,8 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) if (CONN_V4(conn)) { eh->h_proto = htons(ETH_P_IP); - iph = vu_ip(flags_elem[0].in_sg[0].iov_base); - *iph = (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_TCP); + ip4h = vu_ip(flags_elem[0].in_sg[0].iov_base); + *ip4h = (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_TCP); th = vu_payloadv4(flags_elem[0].in_sg[0].iov_base); } else { @@ -171,12 +171,8 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) flags_elem[0].in_sg[0].iov_len = hdrlen + optlen; payload = IOV_TAIL(flags_elem[0].in_sg, 1, hdrlen); - if (CONN_V4(conn)) { - tcp_fill_headers4(conn, NULL, iph, th, &payload, - NULL, seq, true); - } else { - tcp_fill_headers6(conn, NULL, ip6h, th, &payload, seq, true); - } + tcp_fill_headers(conn, NULL, ip4h, ip6h, th, &payload, + NULL, seq, true); if (*c->pcap) { tcp_vu_update_check(tapside, &flags_elem[0].in_sg[0], 1); @@ -339,7 +335,7 @@ static void tcp_vu_prepare(const struct ctx *c, struct tcp_tap_conn *conn, struct iov_tail payload = IOV_TAIL(iov, iov_cnt, hdrlen); char *base = iov[0].iov_base; struct ipv6hdr *ip6h = NULL; - struct iphdr *iph = NULL; + struct iphdr *ip4h = NULL; struct tcphdr *th; struct ethhdr *eh; @@ -358,8 +354,8 @@ static void tcp_vu_prepare(const struct ctx *c, struct tcp_tap_conn *conn, if (!v6) { eh->h_proto = htons(ETH_P_IP); - iph = vu_ip(base); - *iph = (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_TCP); + ip4h = vu_ip(base); + *ip4h = (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_TCP); th = vu_payloadv4(base); } else { eh->h_proto = htons(ETH_P_IPV6); @@ -374,14 +370,10 @@ static void tcp_vu_prepare(const struct ctx *c, struct tcp_tap_conn *conn, th->doff = sizeof(*th) / 4; th->ack = 1; - if (!v6) { - tcp_fill_headers4(conn, NULL, iph, th, &payload, - *check, conn->seq_to_tap, true); - *check = &iph->check; - } else { - tcp_fill_headers6(conn, NULL, ip6h, th, &payload, - conn->seq_to_tap, true); - } + tcp_fill_headers(conn, NULL, ip4h, ip6h, th, &payload, + *check, conn->seq_to_tap, true); + if (ip4h) + *check = &ip4h->check; } /** |