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=CgCW7y5T; 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 75DFA5A0262 for ; Fri, 06 Sep 2024 23:34:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725658479; 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=yBWMfarCvVLv07RIxh3053/sqrumbmNxctw4A6F1ANs=; b=CgCW7y5Tz/NLzsz/8GGRk3Tapjjil3oRswztDP1VJiYhkep7yGxijKL+h6VmNzOj8ZCAih lxUvpfJR5F6R+YBB1g9UL4fs/c17oIH09N4OF3Hj4Ioo0IMf6hxpXG0m7Zwjuj84nJv++8 wYBGRFeAAPKrSjYzakFkYBD6wLH3UUg= 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-595-ceILI49XNNi2xsjpyz2SJA-1; Fri, 06 Sep 2024 17:34:38 -0400 X-MC-Unique: ceILI49XNNi2xsjpyz2SJA-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 46700195608C for ; Fri, 6 Sep 2024 21:34:37 +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 EE57E19560AA; Fri, 6 Sep 2024 21:34:35 +0000 (UTC) From: Jon Maloy To: passt-dev@passt.top, sbrivio@redhat.com, lvivier@redhat.com, dgibson@redhat.com, jmaloy@redhat.com Subject: [PATCH 2/4] tcp: update ip address in l2 tap queues on the fly Date: Fri, 6 Sep 2024 17:34:25 -0400 Message-ID: <20240906213427.1915806-3-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: FLDLT7X6L57XYILACXLVC2O2HW7KWVXT X-Message-ID-Hash: FLDLT7X6L57XYILACXLVC2O2HW7KWVXT 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: l2 tap queue entries are currently initialized at system start, and reused with preset headers through its whole life time. The only fields we need to update per message are things like payload size and checksums. If we want to reuse these entries between ipv4 and ipv6 messages we will now need to initialize the complete ip header on the fly. We do this here. Signed-off-by: Jon Maloy --- tcp.c | 14 +++++++++----- tcp_buf.c | 6 ++++-- tcp_buf.h | 2 ++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tcp.c b/tcp.c index 77c62f0..006e503 100644 --- a/tcp.c +++ b/tcp.c @@ -920,6 +920,7 @@ static size_t tcp_fill_headers4(const struct tcp_tap_conn *conn, ASSERT(src4 && dst4); + *iph = tcp_payload_ip4; iph->tot_len = htons(l3len); iph->saddr = src4->s_addr; iph->daddr = dst4->s_addr; @@ -956,6 +957,7 @@ static size_t tcp_fill_headers6(const struct tcp_tap_conn *conn, const struct flowside *tapside = TAPFLOW(conn); size_t l4len = dlen + sizeof(*th); + *ip6h = tcp_payload_ip6; ip6h->payload_len = htons(l4len); ip6h->saddr = tapside->oaddr.a6; ip6h->daddr = tapside->eaddr.a6; @@ -995,16 +997,18 @@ size_t tcp_l2_buf_fill_headers(const struct tcp_tap_conn *conn, const struct in_addr *a4 = inany_v4(&tapside->oaddr); if (a4) { + iov[TCP_IOV_IP].iov_len = sizeof(struct iphdr); 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); + return tcp_fill_headers6(conn, iov[TCP_IOV_TAP].iov_base, + iov[TCP_IOV_IP].iov_base, + iov[TCP_IOV_PAYLOAD].iov_base, dlen, + seq); } - - return tcp_fill_headers6(conn, iov[TCP_IOV_TAP].iov_base, - iov[TCP_IOV_IP].iov_base, - iov[TCP_IOV_PAYLOAD].iov_base, dlen, - seq); } /** diff --git a/tcp_buf.c b/tcp_buf.c index 1af4786..6e6549f 100644 --- a/tcp_buf.c +++ b/tcp_buf.c @@ -84,6 +84,7 @@ static struct ethhdr tcp4_eth_src; static struct tap_hdr tcp4_payload_tap_hdr[TCP_FRAMES_MEM]; /* IPv4 headers */ +struct iphdr tcp_payload_ip4; static struct iphdr_t tcp4_payload_ip[TCP_FRAMES_MEM]; /* TCP segments with payload for IPv4 frames */ static struct tcp_payload_t tcp4_payload[TCP_FRAMES_MEM]; @@ -107,6 +108,7 @@ static struct ethhdr tcp6_eth_src; static struct tap_hdr tcp6_payload_tap_hdr[TCP_FRAMES_MEM]; /* IPv6 headers */ +struct ipv6hdr tcp_payload_ip6; static struct iphdr_t tcp6_payload_ip[TCP_FRAMES_MEM]; /* TCP headers and data for IPv6 frames */ static struct tcp_payload_t tcp6_payload[TCP_FRAMES_MEM]; @@ -154,9 +156,9 @@ void tcp_sock4_iov_init(const struct ctx *c) int i; tcp4_eth_src.h_proto = htons_constant(ETH_P_IP); + tcp_payload_ip4 = iph; for (i = 0; i < ARRAY_SIZE(tcp4_payload); i++) { - tcp4_payload_ip[i].ip4 = iph; tcp4_payload[i].th.doff = sizeof(struct tcphdr) / 4; tcp4_payload[i].th.ack = 1; } @@ -200,9 +202,9 @@ void tcp_sock6_iov_init(const struct ctx *c) int i; tcp6_eth_src.h_proto = htons_constant(ETH_P_IPV6); + tcp_payload_ip6 = ip6; for (i = 0; i < ARRAY_SIZE(tcp6_payload); i++) { - tcp6_payload_ip[i].ip6 = ip6; tcp6_payload[i].th.doff = sizeof(struct tcphdr) / 4; tcp6_payload[i].th.ack = 1; } diff --git a/tcp_buf.h b/tcp_buf.h index 3db4c56..d3d0d7f 100644 --- a/tcp_buf.h +++ b/tcp_buf.h @@ -13,4 +13,6 @@ 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 iphdr tcp_payload_ip4; +extern struct ipv6hdr tcp_payload_ip6; #endif /*TCP_BUF_H */ -- 2.45.2