From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Y/B5Uopp; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id E52C45A004E for ; Fri, 06 Sep 2024 23:34:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725658485; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YipXg8bVnkjkY6Y0kGXW8Rdn70vl2P6Q3lN/+oi5FdQ=; b=Y/B5UopprPB27IqqXtfouE4us5OhYOhtz1iDMSk6NDnqiookl8/jFWm2Q84UWIO8DbDIF6 yHAxdpBWbXQ6gLOWH414CWk/OJHGvcDeeWEg5jN/sLj4exptA67CsRY2xCWfkUixjGtQdw Oi7yp8RIPmQXdEqmvOe38+muXYInOGc= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-673-6g4GR0C6M_6xe9EcruL3nw-1; Fri, 06 Sep 2024 17:34:44 -0400 X-MC-Unique: 6g4GR0C6M_6xe9EcruL3nw-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 85A841956077 for ; Fri, 6 Sep 2024 21:34:43 +0000 (UTC) Received: from jmaloy-thinkpadp16vgen1.rmtcaqc.csb (unknown [10.22.64.73]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9192E19560B0; Fri, 6 Sep 2024 21:34:40 +0000 (UTC) From: Jon Maloy To: passt-dev@passt.top, sbrivio@redhat.com, lvivier@redhat.com, dgibson@redhat.com, jmaloy@redhat.com Subject: [PATCH 4/4] tcp: change prefix tcp4_ to tcp_ where applicable Date: Fri, 6 Sep 2024 17:34:27 -0400 Message-ID: <20240906213427.1915806-5-jmaloy@redhat.com> In-Reply-To: <20240906213427.1915806-1-jmaloy@redhat.com> References: <20240906213427.1915806-1-jmaloy@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: RG5KT26QHL6V5WV3MVRU6YSF7S2VB6I6 X-Message-ID-Hash: RG5KT26QHL6V5WV3MVRU6YSF7S2VB6I6 X-MailFrom: jmaloy@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The queues and structures previously used for TCPv4 traffic are now used for both IP protocols. We therefore need to replace the prefix tcp4_* with the generic tcp_ everywhere applicable. There are no functional changes in this commit. Signed-off-by: Jon Maloy --- tcp.c | 4 +- tcp_buf.c | 115 +++++++++++++++++++++++++++--------------------------- tcp_buf.h | 2 +- 3 files changed, 60 insertions(+), 61 deletions(-) diff --git a/tcp.c b/tcp.c index 19cf9e5..433dce4 100644 --- a/tcp.c +++ b/tcp.c @@ -998,14 +998,14 @@ size_t tcp_l2_buf_fill_headers(const struct tcp_tap_conn *conn, if (a4) { iov[TCP_IOV_IP].iov_len = sizeof(struct iphdr); - tcp4_eth_src.h_proto = htons_constant(ETH_P_IP); + tcp_eth_src.h_proto = htons_constant(ETH_P_IP); return tcp_fill_headers4(conn, iov[TCP_IOV_TAP].iov_base, iov[TCP_IOV_IP].iov_base, iov[TCP_IOV_PAYLOAD].iov_base, dlen, check, seq); } else { iov[TCP_IOV_IP].iov_len = sizeof(struct ipv6hdr); - tcp4_eth_src.h_proto = htons_constant(ETH_P_IPV6); + tcp_eth_src.h_proto = htons_constant(ETH_P_IPV6); return tcp_fill_headers6(conn, iov[TCP_IOV_TAP].iov_base, iov[TCP_IOV_IP].iov_base, iov[TCP_IOV_PAYLOAD].iov_base, dlen, diff --git a/tcp_buf.c b/tcp_buf.c index 92c4d73..0476184 100644 --- a/tcp_buf.c +++ b/tcp_buf.c @@ -80,28 +80,27 @@ struct tcp_flags_t { #endif /* Ethernet header for IPv4 frames */ -struct ethhdr tcp4_eth_src; +struct ethhdr tcp_eth_src; -static struct tap_hdr tcp4_payload_tap_hdr[TCP_FRAMES_MEM]; +static struct tap_hdr tcp_payload_tap_hdr[TCP_FRAMES_MEM]; /* IPv4 headers */ struct iphdr tcp_payload_ip4; -static struct iphdr_t tcp4_payload_ip[TCP_FRAMES_MEM]; +static struct iphdr_t tcp_payload_ip[TCP_FRAMES_MEM]; /* TCP segments with payload for IPv4 frames */ -static struct tcp_payload_t tcp4_payload[TCP_FRAMES_MEM]; +static struct tcp_payload_t tcp_payload[TCP_FRAMES_MEM]; -static_assert(MSS4 <= sizeof(tcp4_payload[0].data), "MSS4 is greater than 65516"); +static_assert(sizeof(tcp_payload[0].data) > MSS4, "MSS4 is greater than 65516"); /* References tracking the owner connection of frames in the tap outqueue */ -static struct tcp_tap_conn *tcp4_frame_conns[TCP_FRAMES_MEM]; -static unsigned int tcp4_payload_used; +static struct tcp_tap_conn *tcp_frame_conns[TCP_FRAMES_MEM]; +static unsigned int tcp_payload_used; -static struct tap_hdr tcp4_flags_tap_hdr[TCP_FRAMES_MEM]; +static struct tap_hdr tcp_flags_tap_hdr[TCP_FRAMES_MEM]; /* IPv4 headers for TCP segment without payload */ -static struct iphdr_t tcp4_flags_ip[TCP_FRAMES_MEM]; +static struct iphdr_t tcp_flags_ip[TCP_FRAMES_MEM]; /* TCP segments without payload for IPv4 frames */ -static struct tcp_flags_t tcp4_flags[TCP_FRAMES_MEM]; - -static unsigned int tcp4_flags_used; +static struct tcp_flags_t tcp_flags[TCP_FRAMES_MEM]; +static unsigned int tcp_flags_used; /* Ethernet header for IPv6 frames */ struct ipv6hdr tcp_payload_ip6; @@ -109,8 +108,8 @@ struct ipv6hdr tcp_payload_ip6; /* recvmsg()/sendmsg() data for tap */ static struct iovec iov_sock [TCP_FRAMES_MEM + 1]; -static struct iovec tcp4_l2_iov [TCP_FRAMES_MEM][TCP_NUM_IOVS]; -static struct iovec tcp4_l2_flags_iov [TCP_FRAMES_MEM][TCP_NUM_IOVS]; +static struct iovec tcp_l2_iov[TCP_FRAMES_MEM][TCP_NUM_IOVS]; +static struct iovec tcp_l2_flags_iov[TCP_FRAMES_MEM][TCP_NUM_IOVS]; /** * tcp_update_l2_buf() - Update Ethernet header buffers with addresses @@ -119,7 +118,7 @@ static struct iovec tcp4_l2_flags_iov [TCP_FRAMES_MEM][TCP_NUM_IOVS]; */ void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s) { - eth_update_mac(&tcp4_eth_src, eth_d, eth_s); + eth_update_mac(&tcp_eth_src, eth_d, eth_s); } /** @@ -132,39 +131,39 @@ void tcp_sock4_iov_init(const struct ctx *c) struct iovec *iov; int i; - tcp4_eth_src.h_proto = htons_constant(ETH_P_IP); + tcp_eth_src.h_proto = htons_constant(ETH_P_IP); tcp_payload_ip4 = iph; - for (i = 0; i < ARRAY_SIZE(tcp4_payload); i++) { - tcp4_payload[i].th.doff = sizeof(struct tcphdr) / 4; - tcp4_payload[i].th.ack = 1; + for (i = 0; i < ARRAY_SIZE(tcp_payload); i++) { + tcp_payload[i].th.doff = sizeof(struct tcphdr) / 4; + tcp_payload[i].th.ack = 1; } - for (i = 0; i < ARRAY_SIZE(tcp4_flags); i++) { - tcp4_flags_ip[i].ip4 = iph; - tcp4_flags[i].th.doff = sizeof(struct tcphdr) / 4; - tcp4_flags[i].th.ack = 1; + for (i = 0; i < ARRAY_SIZE(tcp_flags); i++) { + tcp_flags_ip[i].ip4 = iph; + tcp_flags[i].th.doff = sizeof(struct tcphdr) / 4; + tcp_flags[i].th.ack = 1; } for (i = 0; i < TCP_FRAMES_MEM; i++) { - iov = tcp4_l2_iov[i]; + iov = tcp_l2_iov[i]; - iov[TCP_IOV_TAP] = tap_hdr_iov(c, &tcp4_payload_tap_hdr[i]); - iov[TCP_IOV_ETH] = IOV_OF_LVALUE(tcp4_eth_src); - iov[TCP_IOV_IP].iov_base = &tcp4_payload_ip[i]; - iov[TCP_IOV_IP].iov_len = sizeof(tcp4_payload_ip[i].ip4); - iov[TCP_IOV_PAYLOAD].iov_base = &tcp4_payload[i]; + iov[TCP_IOV_TAP] = tap_hdr_iov(c, &tcp_payload_tap_hdr[i]); + iov[TCP_IOV_ETH] = IOV_OF_LVALUE(tcp_eth_src); + iov[TCP_IOV_IP].iov_base = &tcp_payload_ip[i]; + iov[TCP_IOV_IP].iov_len = sizeof(tcp_payload_ip[i].ip4); + iov[TCP_IOV_PAYLOAD].iov_base = &tcp_payload[i]; } for (i = 0; i < TCP_FRAMES_MEM; i++) { - iov = tcp4_l2_flags_iov[i]; - - iov[TCP_IOV_TAP] = tap_hdr_iov(c, &tcp4_flags_tap_hdr[i]); - iov[TCP_IOV_ETH].iov_base = &tcp4_eth_src; - iov[TCP_IOV_ETH] = IOV_OF_LVALUE(tcp4_eth_src); - iov[TCP_IOV_IP].iov_base = &tcp4_flags_ip[i]; - iov[TCP_IOV_IP].iov_len = sizeof(tcp4_flags_ip[i].ip4); - iov[TCP_IOV_PAYLOAD].iov_base = &tcp4_flags[i]; + iov = tcp_l2_flags_iov[i]; + + iov[TCP_IOV_TAP] = tap_hdr_iov(c, &tcp_flags_tap_hdr[i]); + iov[TCP_IOV_ETH].iov_base = &tcp_eth_src; + iov[TCP_IOV_ETH] = IOV_OF_LVALUE(tcp_eth_src); + iov[TCP_IOV_IP].iov_base = &tcp_flags_ip[i]; + iov[TCP_IOV_IP].iov_len = sizeof(tcp_flags_ip[i].ip4); + iov[TCP_IOV_PAYLOAD].iov_base = &tcp_flags[i]; } } @@ -174,9 +173,9 @@ void tcp_sock4_iov_init(const struct ctx *c) */ void tcp_flags_flush(const struct ctx *c) { - tap_send_frames(c, &tcp4_l2_flags_iov[0][0], TCP_NUM_IOVS, - tcp4_flags_used); - tcp4_flags_used = 0; + tap_send_frames(c, &tcp_l2_flags_iov[0][0], TCP_NUM_IOVS, + tcp_flags_used); + tcp_flags_used = 0; } /** @@ -215,13 +214,13 @@ void tcp_payload_flush(struct ctx *c) { size_t m; - m = tap_send_frames(c, &tcp4_l2_iov[0][0], TCP_NUM_IOVS, - tcp4_payload_used); - if (m != tcp4_payload_used) { - tcp_revert_seq(c, &tcp4_frame_conns[m], &tcp4_l2_iov[m], - tcp4_payload_used - m); + m = tap_send_frames(c, &tcp_l2_iov[0][0], TCP_NUM_IOVS, + tcp_payload_used); + if (m != tcp_payload_used) { + tcp_revert_seq(c, &tcp_frame_conns[m], &tcp_l2_iov[m], + tcp_payload_used - m); } - tcp4_payload_used = 0; + tcp_payload_used = 0; } /** @@ -241,13 +240,13 @@ int tcp_buf_send_flag(struct ctx *c, struct tcp_tap_conn *conn, int flags) uint32_t seq; int ret; - iov = tcp4_l2_flags_iov[tcp4_flags_used++]; + iov = tcp_l2_flags_iov[tcp_flags_used++]; payload = iov[TCP_IOV_PAYLOAD].iov_base; seq = conn->seq_to_tap; ret = tcp_prepare_flags(c, conn, flags, &payload->th, payload->opts, &optlen); if (ret <= 0) { - tcp4_flags_used--; + tcp_flags_used--; return ret; } @@ -258,7 +257,7 @@ int tcp_buf_send_flag(struct ctx *c, struct tcp_tap_conn *conn, int flags) struct iovec *dup_iov; int i; - dup_iov = tcp4_l2_flags_iov[tcp4_flags_used++]; + dup_iov = tcp_l2_flags_iov[tcp_flags_used++]; for (i = 0; i < TCP_NUM_IOVS; i++) memcpy(dup_iov[i].iov_base, iov[i].iov_base, @@ -266,7 +265,7 @@ int tcp_buf_send_flag(struct ctx *c, struct tcp_tap_conn *conn, int flags) dup_iov[TCP_IOV_PAYLOAD].iov_len = iov[TCP_IOV_PAYLOAD].iov_len; } - if (tcp4_flags_used > TCP_FRAMES_MEM - 2) + if (tcp_flags_used > TCP_FRAMES_MEM - 2) tcp_flags_flush(c); return 0; @@ -283,7 +282,7 @@ int tcp_buf_send_flag(struct ctx *c, struct tcp_tap_conn *conn, int flags) static void tcp_data_to_tap(struct ctx *c, struct tcp_tap_conn *conn, ssize_t dlen, int no_csum, uint32_t seq) { - struct iovec *iov_prev = tcp4_l2_iov[tcp4_payload_used - 1]; + struct iovec *iov_prev = tcp_l2_iov[tcp_payload_used - 1]; const uint16_t *check = NULL; struct iovec *iov; size_t l4len; @@ -296,12 +295,12 @@ static void tcp_data_to_tap(struct ctx *c, struct tcp_tap_conn *conn, check = &iph->check; } - tcp4_frame_conns[tcp4_payload_used] = conn; + tcp_frame_conns[tcp_payload_used] = conn; - iov = tcp4_l2_iov[tcp4_payload_used++]; + iov = tcp_l2_iov[tcp_payload_used++]; l4len = tcp_l2_buf_fill_headers(conn, iov, dlen, check, seq); iov[TCP_IOV_PAYLOAD].iov_len = l4len; - if (tcp4_payload_used > TCP_FRAMES_MEM - 1) + if (tcp_payload_used > TCP_FRAMES_MEM - 1) tcp_payload_flush(c); } @@ -366,15 +365,15 @@ int tcp_buf_data_from_sock(struct ctx *c, struct tcp_tap_conn *conn) mh_sock.msg_iovlen = fill_bufs; } - if ((v4 && tcp4_payload_used + fill_bufs > TCP_FRAMES_MEM)) { + if ((v4 && tcp_payload_used + fill_bufs > TCP_FRAMES_MEM)) { tcp_payload_flush(c); /* Silence Coverity CWE-125 false positive */ - tcp4_payload_used = 0; + tcp_payload_used = 0; } for (i = 0, iov = iov_sock + 1; i < fill_bufs; i++, iov++) { - iov->iov_base = &tcp4_payload[tcp4_payload_used + i].data; + iov->iov_base = &tcp_payload[tcp_payload_used + i].data; iov->iov_len = mss; } if (iov_rem) @@ -422,7 +421,7 @@ int tcp_buf_data_from_sock(struct ctx *c, struct tcp_tap_conn *conn) dlen = mss; seq = conn->seq_to_tap; for (i = 0; i < send_bufs; i++) { - int no_csum = i && i != send_bufs - 1 && tcp4_payload_used; + int no_csum = i && i != send_bufs - 1 && tcp_payload_used; if (i == send_bufs - 1) dlen = last_len; diff --git a/tcp_buf.h b/tcp_buf.h index d7cdbaf..3dc3c95 100644 --- a/tcp_buf.h +++ b/tcp_buf.h @@ -13,7 +13,7 @@ void tcp_payload_flush(struct ctx *c); int tcp_buf_data_from_sock(struct ctx *c, struct tcp_tap_conn *conn); int tcp_buf_send_flag(struct ctx *c, struct tcp_tap_conn *conn, int flags); -extern struct ethhdr tcp4_eth_src; +extern struct ethhdr tcp_eth_src; extern struct iphdr tcp_payload_ip4; extern struct ipv6hdr tcp_payload_ip6; #endif /*TCP_BUF_H */ -- 2.45.2