From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id DEEC45A0307 for ; Mon, 03 Jun 2024 03:33:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1717378380; bh=PXcmPXw6iScBPzjDaVAxrhTgt9nDTwI5uYiGrSGaiio=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QC1DrnPnx5Ua3yV/EonfHcPHPWbRo3QVqAoaqWPMOs2bsQDBLSiqHg6rP5MJ2eSU3 zQZYAT0b3BE/9KLmTjUO8sbjCkQMjyliNThdryEUBhl367z6dyNnXMEBaIwUfnQLOi e8H2kQlRQOJQWGc4DBO6Cm4EcYIt6CNiDl6HV2/OK8e+5p62U5mjKfvhaYoTeb8WBA oY6NBLBKXwdzKPP4aqiffItSKpm0DdJ2KJSpUJlkyehZ3m6F/HyJkrUQHAU0ZRGkM/ FBtM9A9NcCq7gFO+Oq1eodpYl+baa4lA4PGVJDfdtR4gIBXLFIUDW0q5Qhim24zInR jO2/qspMpI1hA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Vsx7J0wffz4wc8; Mon, 3 Jun 2024 11:33:00 +1000 (AEST) Date: Mon, 3 Jun 2024 11:32:17 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v4 04/10] tap: export pool_flush()/tapX_handler()/packet_add() Message-ID: References: <20240531142344.1420034-1-lvivier@redhat.com> <20240531142344.1420034-5-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="1jf84jidNV5g7t20" Content-Disposition: inline In-Reply-To: <20240531142344.1420034-5-lvivier@redhat.com> Message-ID-Hash: NHVSPTNQX7I5HOENXZSV5JWR6IRAL6UC X-Message-ID-Hash: NHVSPTNQX7I5HOENXZSV5JWR6IRAL6UC 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 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: --1jf84jidNV5g7t20 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, May 31, 2024 at 04:23:38PM +0200, Laurent Vivier wrote: Commit message, in particular mentioning why you're going to need this exported. Otherwise LGTM, except that.. > Signed-off-by: Laurent Vivier > --- > tap.c | 97 +++++++++++++++++++++++++++++------------------------------ > tap.h | 7 +++++ > 2 files changed, 55 insertions(+), 49 deletions(-) >=20 > diff --git a/tap.c b/tap.c > index 2ea08491a51f..ab8d760efb11 100644 > --- a/tap.c > +++ b/tap.c > @@ -920,6 +920,45 @@ append: > return in->count; > } > =20 =2E.function comments would be good on the new functions > +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 l2len, char *p, > + const char *func, int line) > +{ > + const struct ethhdr *eh; > + > + pcap(p, l2len); > + > + 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, l2len, p, func, line); > + break; > + case ETH_P_IPV6: > + packet_add_do(pool_tap6, l2len, p, func, line); > + break; > + default: > + break; > + } > +} > + > /** > * tap_sock_reset() - Handle closing or failure of connect AF_UNIX socket > * @c: Execution context > @@ -946,7 +985,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 > @@ -959,8 +997,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) { > @@ -987,38 +1024,18 @@ redo: > /* Complete the partial read above before discarding a malformed > * frame, otherwise the stream will be inconsistent. > */ > - if (l2len < (ssize_t)sizeof(*eh) || > + if (l2len < (ssize_t)sizeof(struct ethhdr) || > l2len > (ssize_t)ETH_MAX_MTU) > goto next; > =20 > - pcap(p, l2len); > - > - 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, l2len, p); > - break; > - case ETH_P_IPV6: > - packet_add(pool_tap6, l2len, p); > - break; > - default: > - break; > - } > + packet_add_all(c, l2len, p); > =20 > next: > p +=3D l2len; > n -=3D l2len; > } > =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) > @@ -1043,35 +1060,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; > @@ -1082,8 +1082,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 2285a87093f9..3ffb7d6c3a91 100644 > --- a/tap.h > +++ b/tap.h > @@ -70,5 +70,12 @@ void tap_handler_passt(struct ctx *c, uint32_t events, > const struct timespec *now); > int tap_sock_unix_open(char *sock_path); > 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_all_do(struct ctx *c, ssize_t l2len, char *p, > + const char *func, int line); > +#define packet_add_all(p, l2len, start) \ > + packet_add_all_do(p, l2len, 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 --1jf84jidNV5g7t20 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmZdHSAACgkQzQJF27ox 2GeQVA/8DTd8xYoMoWws6o8z+MMWCykk3U+/AHcdDhvY6rhfNSQWW51cSq52nTDR CK0N9kOZxnW7RkNrcVlKc90cdve/ve6R4dKcT4C9MNoeC2EJI6i0R4fKdd4F3vzG gNjK+bkkWhuR+1y3XyKdBFX25+0d62TGSM/pYlS9fyQomEZfjfH7MWw2Wc93llDV PW85UzUJaI5z3xxS/XitRXL4/gP/Kt4fwfsdae89AZ3JeQuR9qdoXMA6hR/TU74P FFcHm4v3GbqKV+yRtzrDwpN71D7NNLRORuA7kXFfUFQ2UR+vUYhXLxAh20S3lfXB wGShg6euo4zmjiPtqwGkBOEmLqordANYrhSvcPdq4+rG9uz7b57IlAra8yUReuRI ZJVCatwn+hGxZbBGUvl3EBzzRcKDRUy1igs/kaVW05g2lVLaevWuGYyiq8kMVkLK aE8QpFpeOGnF30Q7HJMVz++mIaNM6FnyOSOexIREoWtwlH7tIFi20CVazJjTk5xu RzHMzqRD+OBURYuZFk49S+7SDpS6KvSZfnxCk3ZuhV51zORNl8qaQ7zQBnQcDoca yTerVHoNwuXoB7VpX4u5W3VF2JWdn/rVtTpyWBodGm3ZPRWpeFbpZbjrWXcpDNo1 OFSQUag7K5nm88InyQHTH9fxO8FDWf3zKVTlTZPmiNOEmsRmWng= =xi8t -----END PGP SIGNATURE----- --1jf84jidNV5g7t20--