1
0
mirror of https://passt.top/passt synced 2024-09-28 18:15:49 +00:00

tcp: Allow checksum to be disabled

We can need not to set TCP checksum. Add a parameter to
tcp_fill_headers4() and tcp_fill_headers6() to disable it.

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>
This commit is contained in:
Laurent Vivier 2024-09-18 15:13:28 +02:00 committed by Stefano Brivio
parent 4fe5f4e813
commit 8f8c4d27eb
3 changed files with 38 additions and 25 deletions

52
tcp.c
View File

@ -899,13 +899,14 @@ static void tcp_fill_header(struct tcphdr *th,
/** /**
* tcp_fill_headers4() - Fill 802.3, IPv4, TCP headers in pre-cooked buffers * tcp_fill_headers4() - Fill 802.3, IPv4, TCP headers in pre-cooked buffers
* @conn: Connection pointer * @conn: Connection pointer
* @taph: tap backend specific header * @taph: tap backend specific header
* @iph: Pointer to IPv4 header * @iph: Pointer to IPv4 header
* @th: Pointer to TCP header * @th: Pointer to TCP header
* @dlen: TCP payload length * @dlen: TCP payload length
* @check: Checksum, if already known * @check: Checksum, if already known
* @seq: Sequence number for this segment * @seq: Sequence number for this segment
* @no_tcp_csum: Do not set TCP checksum
* *
* Return: The IPv4 payload length, host order * Return: The IPv4 payload length, host order
*/ */
@ -913,7 +914,7 @@ static size_t tcp_fill_headers4(const struct tcp_tap_conn *conn,
struct tap_hdr *taph, struct tap_hdr *taph,
struct iphdr *iph, struct tcphdr *th, struct iphdr *iph, struct tcphdr *th,
size_t dlen, const uint16_t *check, size_t dlen, const uint16_t *check,
uint32_t seq) uint32_t seq, bool no_tcp_csum)
{ {
const struct flowside *tapside = TAPFLOW(conn); const struct flowside *tapside = TAPFLOW(conn);
const struct in_addr *src4 = inany_v4(&tapside->oaddr); const struct in_addr *src4 = inany_v4(&tapside->oaddr);
@ -932,7 +933,10 @@ static size_t tcp_fill_headers4(const struct tcp_tap_conn *conn,
tcp_fill_header(th, conn, seq); tcp_fill_header(th, conn, seq);
tcp_update_check_tcp4(iph, th); if (no_tcp_csum)
th->check = 0;
else
tcp_update_check_tcp4(iph, th);
tap_hdr_update(taph, l3len + sizeof(struct ethhdr)); tap_hdr_update(taph, l3len + sizeof(struct ethhdr));
@ -941,20 +945,21 @@ static size_t tcp_fill_headers4(const struct tcp_tap_conn *conn,
/** /**
* tcp_fill_headers6() - Fill 802.3, IPv6, TCP headers in pre-cooked buffers * tcp_fill_headers6() - Fill 802.3, IPv6, TCP headers in pre-cooked buffers
* @conn: Connection pointer * @conn: Connection pointer
* @taph: tap backend specific header * @taph: tap backend specific header
* @ip6h: Pointer to IPv6 header * @ip6h: Pointer to IPv6 header
* @th: Pointer to TCP header * @th: Pointer to TCP header
* @dlen: TCP payload length * @dlen: TCP payload length
* @check: Checksum, if already known * @check: Checksum, if already known
* @seq: Sequence number for this segment * @seq: Sequence number for this segment
* @no_tcp_csum: Do not set TCP checksum
* *
* Return: The IPv6 payload length, host order * Return: The IPv6 payload length, host order
*/ */
static size_t tcp_fill_headers6(const struct tcp_tap_conn *conn, static size_t tcp_fill_headers6(const struct tcp_tap_conn *conn,
struct tap_hdr *taph, struct tap_hdr *taph,
struct ipv6hdr *ip6h, struct tcphdr *th, struct ipv6hdr *ip6h, struct tcphdr *th,
size_t dlen, uint32_t seq) size_t dlen, uint32_t seq, bool no_tcp_csum)
{ {
const struct flowside *tapside = TAPFLOW(conn); const struct flowside *tapside = TAPFLOW(conn);
size_t l4len = dlen + sizeof(*th); size_t l4len = dlen + sizeof(*th);
@ -973,7 +978,10 @@ static size_t tcp_fill_headers6(const struct tcp_tap_conn *conn,
tcp_fill_header(th, conn, seq); tcp_fill_header(th, conn, seq);
tcp_update_check_tcp6(ip6h, th); if (no_tcp_csum)
th->check = 0;
else
tcp_update_check_tcp6(ip6h, th);
tap_hdr_update(taph, l4len + sizeof(*ip6h) + sizeof(struct ethhdr)); tap_hdr_update(taph, l4len + sizeof(*ip6h) + sizeof(struct ethhdr));
@ -987,12 +995,14 @@ static size_t tcp_fill_headers6(const struct tcp_tap_conn *conn,
* @dlen: TCP payload length * @dlen: TCP payload length
* @check: Checksum, if already known * @check: Checksum, if already known
* @seq: Sequence number for this segment * @seq: Sequence number for this segment
* @no_tcp_csum: Do not set TCP checksum
* *
* Return: IP payload length, host order * Return: IP payload length, host order
*/ */
size_t tcp_l2_buf_fill_headers(const struct tcp_tap_conn *conn, size_t tcp_l2_buf_fill_headers(const struct tcp_tap_conn *conn,
struct iovec *iov, size_t dlen, struct iovec *iov, size_t dlen,
const uint16_t *check, uint32_t seq) const uint16_t *check, uint32_t seq,
bool no_tcp_csum)
{ {
const struct flowside *tapside = TAPFLOW(conn); const struct flowside *tapside = TAPFLOW(conn);
const struct in_addr *a4 = inany_v4(&tapside->oaddr); const struct in_addr *a4 = inany_v4(&tapside->oaddr);
@ -1001,13 +1011,13 @@ size_t tcp_l2_buf_fill_headers(const struct tcp_tap_conn *conn,
return tcp_fill_headers4(conn, iov[TCP_IOV_TAP].iov_base, return tcp_fill_headers4(conn, iov[TCP_IOV_TAP].iov_base,
iov[TCP_IOV_IP].iov_base, iov[TCP_IOV_IP].iov_base,
iov[TCP_IOV_PAYLOAD].iov_base, dlen, iov[TCP_IOV_PAYLOAD].iov_base, dlen,
check, seq); check, seq, no_tcp_csum);
} }
return tcp_fill_headers6(conn, iov[TCP_IOV_TAP].iov_base, return tcp_fill_headers6(conn, iov[TCP_IOV_TAP].iov_base,
iov[TCP_IOV_IP].iov_base, iov[TCP_IOV_IP].iov_base,
iov[TCP_IOV_PAYLOAD].iov_base, dlen, iov[TCP_IOV_PAYLOAD].iov_base, dlen,
seq); seq, no_tcp_csum);
} }
/** /**

View File

@ -320,7 +320,7 @@ int tcp_buf_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags)
return ret; return ret;
} }
l4len = tcp_l2_buf_fill_headers(conn, iov, optlen, NULL, seq); l4len = tcp_l2_buf_fill_headers(conn, iov, optlen, NULL, seq, false);
iov[TCP_IOV_PAYLOAD].iov_len = l4len; iov[TCP_IOV_PAYLOAD].iov_len = l4len;
if (flags & DUP_ACK) { if (flags & DUP_ACK) {
@ -381,7 +381,8 @@ static void tcp_data_to_tap(const struct ctx *c, struct tcp_tap_conn *conn,
tcp4_frame_conns[tcp4_payload_used] = conn; tcp4_frame_conns[tcp4_payload_used] = conn;
iov = tcp4_l2_iov[tcp4_payload_used++]; iov = tcp4_l2_iov[tcp4_payload_used++];
l4len = tcp_l2_buf_fill_headers(conn, iov, dlen, check, seq); l4len = tcp_l2_buf_fill_headers(conn, iov, dlen, check, seq,
false);
iov[TCP_IOV_PAYLOAD].iov_len = l4len; iov[TCP_IOV_PAYLOAD].iov_len = l4len;
if (tcp4_payload_used > TCP_FRAMES_MEM - 1) if (tcp4_payload_used > TCP_FRAMES_MEM - 1)
tcp_payload_flush(c); tcp_payload_flush(c);
@ -389,7 +390,8 @@ static void tcp_data_to_tap(const struct ctx *c, struct tcp_tap_conn *conn,
tcp6_frame_conns[tcp6_payload_used] = conn; tcp6_frame_conns[tcp6_payload_used] = conn;
iov = tcp6_l2_iov[tcp6_payload_used++]; iov = tcp6_l2_iov[tcp6_payload_used++];
l4len = tcp_l2_buf_fill_headers(conn, iov, dlen, NULL, seq); l4len = tcp_l2_buf_fill_headers(conn, iov, dlen, NULL, seq,
false);
iov[TCP_IOV_PAYLOAD].iov_len = l4len; iov[TCP_IOV_PAYLOAD].iov_len = l4len;
if (tcp6_payload_used > TCP_FRAMES_MEM - 1) if (tcp6_payload_used > TCP_FRAMES_MEM - 1)
tcp_payload_flush(c); tcp_payload_flush(c);

View File

@ -91,7 +91,8 @@ void tcp_rst_do(const struct ctx *c, struct tcp_tap_conn *conn);
size_t tcp_l2_buf_fill_headers(const struct tcp_tap_conn *conn, size_t tcp_l2_buf_fill_headers(const struct tcp_tap_conn *conn,
struct iovec *iov, size_t dlen, struct iovec *iov, size_t dlen,
const uint16_t *check, uint32_t seq); const uint16_t *check, uint32_t seq,
bool no_tcp_csum);
int tcp_update_seqack_wnd(const struct ctx *c, struct tcp_tap_conn *conn, int tcp_update_seqack_wnd(const struct ctx *c, struct tcp_tap_conn *conn,
bool force_seq, struct tcp_info *tinfo); bool force_seq, struct tcp_info *tinfo);
int tcp_prepare_flags(const struct ctx *c, struct tcp_tap_conn *conn, int flags, int tcp_prepare_flags(const struct ctx *c, struct tcp_tap_conn *conn, int flags,