From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202408 header.b=GiXOc1kA; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 9D3895A004F for ; Mon, 09 Sep 2024 03:17:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1725844659; bh=jUJrV6LCXzR1aBVfsl+YlkPpUunuCRIMZtxGwP/cxi8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GiXOc1kACy1reU/8XQF/vBW/D99Ef121ajLGTLbQ2NhhurApV5zaJu6a//3Ng+fdD miXKsr955A8UyBaLkszvad/ni4zkkchX/7WYmYK1WhWEZYqwxyKGm3LJx/3Vg3nsfN DaZUfQDq0+kUNM8hm92enbE6Jc15T27AfSqi97SlFg2oUPzYEsLuy2dZzDCtheJJJV y0aTQ/SYfqUPrJqdlRlAEKC6tN6uAyJEP1Fc9TBaCyS17LHLZ3rymLiIMaW53IQTpA vc8Cw6Bx5GHYD6ging13crNzC0Qbx834U937cgfmveImHtqvsQ+gZSmNO2WiBvzqJ3 mld8TeK1xISaw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4X288M22vTz4wcL; Mon, 9 Sep 2024 11:17:39 +1000 (AEST) Date: Mon, 9 Sep 2024 11:08:26 +1000 From: David Gibson To: Jon Maloy Subject: Re: [PATCH 2/4] tcp: update ip address in l2 tap queues on the fly Message-ID: References: <20240906213427.1915806-1-jmaloy@redhat.com> <20240906213427.1915806-3-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="QFdfmU2iDz4sPX/X" Content-Disposition: inline In-Reply-To: <20240906213427.1915806-3-jmaloy@redhat.com> Message-ID-Hash: 76BTIROHM4VU3GPIHCLRVHQXVTTK5ZDH X-Message-ID-Hash: 76BTIROHM4VU3GPIHCLRVHQXVTTK5ZDH X-MailFrom: dgibson@gandalf.ozlabs.org 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 CC: passt-dev@passt.top, sbrivio@redhat.com, lvivier@redhat.com, dgibson@redhat.com 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: --QFdfmU2iDz4sPX/X Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Sep 06, 2024 at 05:34:25PM -0400, Jon Maloy wrote: > 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. >=20 > 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. >=20 > We do this here. Comments from 1/4 relevant here too. > Signed-off-by: Jon Maloy > --- > tcp.c | 14 +++++++++----- > tcp_buf.c | 6 ++++-- > tcp_buf.h | 2 ++ > 3 files changed, 15 insertions(+), 7 deletions(-) >=20 > 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, > =20 > ASSERT(src4 && dst4); > =20 > + *iph =3D tcp_payload_ip4; > iph->tot_len =3D htons(l3len); > iph->saddr =3D src4->s_addr; > iph->daddr =3D dst4->s_addr; > @@ -956,6 +957,7 @@ static size_t tcp_fill_headers6(const struct tcp_tap_= conn *conn, > const struct flowside *tapside =3D TAPFLOW(conn); > size_t l4len =3D dlen + sizeof(*th); > =20 > + *ip6h =3D tcp_payload_ip6; > ip6h->payload_len =3D htons(l4len); > ip6h->saddr =3D tapside->oaddr.a6; > ip6h->daddr =3D 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 =3D inany_v4(&tapside->oaddr); > =20 > if (a4) { > + iov[TCP_IOV_IP].iov_len =3D 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 =3D 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); Personally I marginally prefer this formatting, but one of the static checkers is going to whinge about an else clause after a 'return' in the if clause. > } > - > - 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); > } > =20 > /** > 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; > =20 > 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; > =20 > 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; > =20 > tcp4_eth_src.h_proto =3D htons_constant(ETH_P_IP); > + tcp_payload_ip4 =3D iph; > =20 > for (i =3D 0; i < ARRAY_SIZE(tcp4_payload); i++) { > - tcp4_payload_ip[i].ip4 =3D iph; > tcp4_payload[i].th.doff =3D sizeof(struct tcphdr) / 4; > tcp4_payload[i].th.ack =3D 1; > } > @@ -200,9 +202,9 @@ void tcp_sock6_iov_init(const struct ctx *c) > int i; > =20 > tcp6_eth_src.h_proto =3D htons_constant(ETH_P_IPV6); > + tcp_payload_ip6 =3D ip6; > =20 > for (i =3D 0; i < ARRAY_SIZE(tcp6_payload); i++) { > - tcp6_payload_ip[i].ip6 =3D ip6; > tcp6_payload[i].th.doff =3D sizeof(struct tcphdr) / 4; > tcp6_payload[i].th.ack =3D 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 flag= s); > =20 > +extern struct iphdr tcp_payload_ip4; > +extern struct ipv6hdr tcp_payload_ip6; > #endif /*TCP_BUF_H */ --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --QFdfmU2iDz4sPX/X Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmbeSokACgkQzQJF27ox 2GdRUQ/7B0aKhqBkeyyIvpwJXqNBI/HdjazSMFXsrjpVF69HjuYb2LenxNyxLs8H t85K3TgefcmWV/LuZAPt6Zrbp8WFY0rGGO6fhHEptJpf0BuZoysOubUcx6ucmV/h BkYSRy7qcU1IUmRiMuzrB9QKe8rSIKfkXRqG/Qyj4fQxDDN8roHttkuNUWpprpFr 0aDh/ZYtXEPA/GkhiEnAaehPmNxanuOfmmML1Lwd4NlcOAgFCKySyJOLxBTwJfPG VAVPgjSula5+bvIvFfw76E9VxszK+HoTr7Ay5+iMhdTEKAKEsEe/gaFHewLqzDTG 2yqeaI4OrCpNmVFi3sPo9nrvMQcbVWNI6faguoJibH9lFa3FmkEl3cVk3f4GBiuI WSIk5P3CEZqiFTiH6d8RcEq1AqTa6uJ05Lv9CwdJfH/7JxC8ooC+qqhi4poFkHsm 1BZCJEt5aBkTFOBSTjNtjJxhC3qbW2DrGwkgzLe+2F6cXxw7MTg8kWlb4YcAOSZd pybKGoviCEx6tclyslSaiqNBnWSWJXmnrTQNS3NWSO1a3uXBn5s9NHSMbPj3Japv 3fZc0kmB5Fg166CnRLsWkDbdhcAWlQRjUfaaRRcfcNdyvBDzb6m03KIZ3x2k9k3L GDj0cOjbd+r3Im4Cm7rv2/Hy2gPdy4rYzvMhw6lDdCOj7GPcCK8= =tKZB -----END PGP SIGNATURE----- --QFdfmU2iDz4sPX/X--