From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 581285A0276 for ; Tue, 6 Feb 2024 02:52:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1707184366; bh=swr3OYNF8dHjSgnI4wAlGGBtCkcy1xgY9MVvuevAwu8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dJZb7uSub1qUonfCGhQbfmMXu0AELpb3tetsDppB9eDL8CqjWjY3nKevALKrVG/Ht 2IR75uJyBTD8ecSSxapUcPSenra7V2z2rzhgzziOLviTe9g00OU7sve0VQIWb51pQ3 EgqLbzXJ+QBDcemRDmvcGyhAs8rSdpgPn+TRcdk03PeQdJJe+rXYvUBFcSHhv3dVd6 bM7a+S54AHNBkh+k20v5oR8e9QhAoWkkS5j0Q/GLMlvsoeokECIVgs8OG7czGKL5tF X9wguujaqRs0OrVgrIU6UdMFmHGuvGYbfzIsAOI9i9Kov7CpnDGIN+tpSz+q759Y7f FTWXIdZzvafDw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TTR8Z0Ffsz4wyY; Tue, 6 Feb 2024 12:52:46 +1100 (AEDT) Date: Tue, 6 Feb 2024 12:52:40 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH 13/24] tap: export pool_flush()/tapX_handler()/packet_add() Message-ID: References: <20240202141151.3762941-1-lvivier@redhat.com> <20240202141151.3762941-14-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="XP4sfu76hFUe7+J6" Content-Disposition: inline In-Reply-To: <20240202141151.3762941-14-lvivier@redhat.com> Message-ID-Hash: XU4MJ2Q565JGYO47X4BUBJ4BOAGUDBBJ X-Message-ID-Hash: XU4MJ2Q565JGYO47X4BUBJ4BOAGUDBBJ 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, Laurent Vivier 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: --XP4sfu76hFUe7+J6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 02, 2024 at 03:11:40PM +0100, Laurent Vivier wrote: > From: Laurent Vivier Rationale? > Signed-off-by: Laurent Vivier Otherwise LGTM. > --- > tap.c | 98 +++++++++++++++++++++++++++++------------------------------ > tap.h | 7 +++++ > 2 files changed, 56 insertions(+), 49 deletions(-) >=20 > diff --git a/tap.c b/tap.c > index 29f389057ac1..5b1b61550c13 100644 > --- a/tap.c > +++ b/tap.c > @@ -911,6 +911,45 @@ append: > return in->count; > } > =20 > +void pool_flush_all(void) > +{ > + pool_flush(pool_tap4); > + pool_flush(pool_tap6); > +} > + > +void tap_handler_all(struct ctx *c, const struct timespec *now) > +{ > + tap4_handler(c, pool_tap4, now); > + tap6_handler(c, pool_tap6, now); > +} > + > +void packet_add_all_do(struct ctx *c, ssize_t len, char *p, > + const char *func, int line) > +{ > + const struct ethhdr *eh; > + > + pcap(p, len); > + > + eh =3D (struct ethhdr *)p; > + > + if (memcmp(c->mac_guest, eh->h_source, ETH_ALEN)) { > + memcpy(c->mac_guest, eh->h_source, ETH_ALEN); > + proto_update_l2_buf(c->mac_guest, NULL); > + } > + > + switch (ntohs(eh->h_proto)) { > + case ETH_P_ARP: > + case ETH_P_IP: > + packet_add_do(pool_tap4, len, p, func, line); > + break; > + case ETH_P_IPV6: > + packet_add_do(pool_tap6, len, p, func, line); > + break; > + default: > + break; > + } > +} > + > /** > * tap_sock_reset() - Handle closing or failure of connect AF_UNIX socket > * @c: Execution context > @@ -937,7 +976,6 @@ static void tap_sock_reset(struct ctx *c) > void tap_handler_passt(struct ctx *c, uint32_t events, > const struct timespec *now) > { > - const struct ethhdr *eh; > ssize_t n, rem; > char *p; > =20 > @@ -950,8 +988,7 @@ redo: > p =3D pkt_buf; > rem =3D 0; > =20 > - pool_flush(pool_tap4); > - pool_flush(pool_tap6); > + pool_flush_all(); > =20 > n =3D recv(c->fd_tap, p, TAP_BUF_FILL, MSG_DONTWAIT); > if (n < 0) { > @@ -978,37 +1015,18 @@ redo: > /* Complete the partial read above before discarding a malformed > * frame, otherwise the stream will be inconsistent. > */ > - if (len < (ssize_t)sizeof(*eh) || len > (ssize_t)ETH_MAX_MTU) > + if (len < (ssize_t)sizeof(struct ethhdr) || > + len > (ssize_t)ETH_MAX_MTU) > goto next; > =20 > - pcap(p, len); > - > - eh =3D (struct ethhdr *)p; > - > - if (memcmp(c->mac_guest, eh->h_source, ETH_ALEN)) { > - memcpy(c->mac_guest, eh->h_source, ETH_ALEN); > - proto_update_l2_buf(c->mac_guest, NULL); > - } > - > - switch (ntohs(eh->h_proto)) { > - case ETH_P_ARP: > - case ETH_P_IP: > - packet_add(pool_tap4, len, p); > - break; > - case ETH_P_IPV6: > - packet_add(pool_tap6, len, p); > - break; > - default: > - break; > - } > + packet_add_all(c, len, p); > =20 > next: > p +=3D len; > n -=3D len; > } > =20 > - tap4_handler(c, pool_tap4, now); > - tap6_handler(c, pool_tap6, now); > + tap_handler_all(c, now); > =20 > /* We can't use EPOLLET otherwise. */ > if (rem) > @@ -1033,35 +1051,18 @@ void tap_handler_pasta(struct ctx *c, uint32_t ev= ents, > redo: > n =3D 0; > =20 > - pool_flush(pool_tap4); > - pool_flush(pool_tap6); > + pool_flush_all(); > restart: > while ((len =3D read(c->fd_tap, pkt_buf + n, TAP_BUF_BYTES - n)) > 0) { > - const struct ethhdr *eh =3D (struct ethhdr *)(pkt_buf + n); > =20 > - if (len < (ssize_t)sizeof(*eh) || len > (ssize_t)ETH_MAX_MTU) { > + if (len < (ssize_t)sizeof(struct ethhdr) || > + len > (ssize_t)ETH_MAX_MTU) { > n +=3D len; > continue; > } > =20 > - pcap(pkt_buf + n, len); > =20 > - if (memcmp(c->mac_guest, eh->h_source, ETH_ALEN)) { > - memcpy(c->mac_guest, eh->h_source, ETH_ALEN); > - proto_update_l2_buf(c->mac_guest, NULL); > - } > - > - switch (ntohs(eh->h_proto)) { > - case ETH_P_ARP: > - case ETH_P_IP: > - packet_add(pool_tap4, len, pkt_buf + n); > - break; > - case ETH_P_IPV6: > - packet_add(pool_tap6, len, pkt_buf + n); > - break; > - default: > - break; > - } > + packet_add_all(c, len, pkt_buf + n); > =20 > if ((n +=3D len) =3D=3D TAP_BUF_BYTES) > break; > @@ -1072,8 +1073,7 @@ restart: > =20 > ret =3D errno; > =20 > - tap4_handler(c, pool_tap4, now); > - tap6_handler(c, pool_tap6, now); > + tap_handler_all(c, now); > =20 > if (len > 0 || ret =3D=3D EAGAIN) > return; > diff --git a/tap.h b/tap.h > index 437b9aa2b43f..7157ef37ee6e 100644 > --- a/tap.h > +++ b/tap.h > @@ -82,5 +82,12 @@ void tap_handler_pasta(struct ctx *c, uint32_t events, > void tap_handler_passt(struct ctx *c, uint32_t events, > const struct timespec *now); > void tap_sock_init(struct ctx *c); > +void pool_flush_all(void); > +void tap_handler_all(struct ctx *c, const struct timespec *now); > + > +void packet_add_do(struct pool *p, size_t len, const char *start, > + const char *func, int line); > +#define packet_add_all(p, len, start) \ > + packet_add_all_do(p, len, start, __func__, __LINE__) > =20 > #endif /* TAP_H */ --=20 David Gibson | 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 --XP4sfu76hFUe7+J6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmXBkOcACgkQzQJF27ox 2GcmFQ//XBMPYP5HV/SbxGhb9P/u3Xt3AHl8EsPAdnZW3r7KAzk7o0kVqY8ckveR VbNAOS+d6pe5sLpzRAYraZxmAm/JMeUQXviyNR6izX/a/yFwBaDYUodCETMAlNvy lp4ZpGSuEa+CQ4u9FOhe7y/PftKqvgN3J4hfqzbd8Xts8/ox7spjCa84aQ5jdwo/ mCaCUsYDMecsQfvCG9cSwRq3KWPwjlguRlAqWlk7gU64IRkE8maeqxJxW2ErHfYp Tupx9dA1rwkyNGeYWwjNPvner3vThYE91jSk6kkNGKXTNAIhf8UfvdAEGklFrBL2 VF0OmDIp7nCGT8S5L+O5dRDIyF5b9GEfG4qC1eQx8iYQb5MROMhfIWF0GnfFTTl8 MnmwKy+oZatGBKnirr+uNeXk0YL98Q1sdKsugPf3YDXGm5/7Ukz8GczIsmO2bESo zOHH+USwJNeU3zXn8Twy+rSPOmuv+iN1fpBA1pgtDBxnhJs3SujYAIlUvvRP2v9K ZFTaOEMhQdeRikWBWZuRemYe0gvExvgy1s2MyNH6EjxrcG5onWwoA0e8rWpkkT/u Ezokzck1kjC+/TYaerIu56/8FqmxgQmquk/9nn5pg9OGvMDCoopvZ6bRAS1jVSle 2e+VhcOKb17R3p2WSygJN2NXYN6q9QNuPvn3H4KYh1UP+8ayUro= =YwK2 -----END PGP SIGNATURE----- --XP4sfu76hFUe7+J6--