From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 556695A026D for ; Sun, 7 Jan 2024 05:28:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1704601731; bh=uibU7B47hGSFbKRuCtck6G0T+eiMZzI5IzlMiaxM9kI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Pl+KYcpPjd40zRymhxzfjg3zFCPRjNnGZIuX6f5OicCtRF8nxN6iIRNy+RSysAnha HD6/l+MueKrd+egiXEH7nqcCZeL6k+wLh72Z2NwRiGBhxfq6FZwE3r4ods36CwgM2Y QVX5CzrrWu34twuQK5CWntk4w2nx9g6tJIOXnFf6fNoX1LY9tINJ9gTM+2/K9l/Ktw SIxJXaKqWC/grarVn63PdY3LYjy00YtD1zB1Ofht79NIfPbGyIQAzkkj/mHIib0yRy wukqlV+6TFOLWM0MVhJ4HETL7sq9B0KjbDimP9Ri4rIi8Fchhe61pgQMEGpczL6T5C jOapeRbrLSKrQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4T742W5dxXz4wdD; Sun, 7 Jan 2024 15:28:51 +1100 (AEDT) Date: Sun, 7 Jan 2024 11:38:47 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v2 06/12] icmp: Use -1 to represent "missing" sockets Message-ID: References: <20231221065327.1307827-1-david@gibson.dropbear.id.au> <20231221065327.1307827-7-david@gibson.dropbear.id.au> <20240106165932.1056c316@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="9/SrBtLQMX7WQCRl" Content-Disposition: inline In-Reply-To: <20240106165932.1056c316@elisabeth> Message-ID-Hash: NE3JT7TQ2RGWFDZFC5ZWNTQMAJNT3GWT X-Message-ID-Hash: NE3JT7TQ2RGWFDZFC5ZWNTQMAJNT3GWT 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: --9/SrBtLQMX7WQCRl Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Jan 06, 2024 at 04:59:32PM +0100, Stefano Brivio wrote: > On Thu, 21 Dec 2023 17:53:21 +1100 > David Gibson wrote: >=20 > > icmp_id_map[] contains, amongst other things, fds for "ping" sockets > > associated with various ICMP echo ids. However, we only lazily open() > > those sockets, so many will be missing. We currently represent that wi= th > > a 0, which isn't great, since that's technically a valid fd. Use -1 > > instead. This does require initializing the fields in icmp_id_map[] but > > we already have an obvious place to do that. > >=20 > > Signed-off-by: David Gibson > > --- > > icmp.c | 10 ++++++---- > > 1 file changed, 6 insertions(+), 4 deletions(-) > >=20 > > diff --git a/icmp.c b/icmp.c > > index 7a505b4..dd98c7f 100644 > > --- a/icmp.c > > +++ b/icmp.c > > @@ -179,7 +179,7 @@ int icmp_tap_handler(const struct ctx *c, uint8_t p= if, int af, > > =20 > > iref.id =3D id =3D ntohs(ih->un.echo.id); > > =20 > > - if ((s =3D icmp_id_map[V4][id].sock) <=3D 0) { > > + if ((s =3D icmp_id_map[V4][id].sock) < 0) { > > s =3D sock_l4(c, AF_INET, IPPROTO_ICMP, &c->ip4.addr_out, > > c->ip4.ifname_out, 0, iref.u32); > > if (s < 0) > > @@ -221,7 +221,7 @@ int icmp_tap_handler(const struct ctx *c, uint8_t p= if, int af, > > return 1; > > =20 > > iref.id =3D id =3D ntohs(ih->icmp6_identifier); > > - if ((s =3D icmp_id_map[V6][id].sock) <=3D 0) { > > + if ((s =3D icmp_id_map[V6][id].sock) < 0) { > > s =3D sock_l4(c, AF_INET6, IPPROTO_ICMPV6, > > &c->ip6.addr_out, > > c->ip6.ifname_out, 0, iref.u32); > > @@ -277,7 +277,7 @@ static void icmp_timer_one(const struct ctx *c, int= v6, uint16_t id, > > =20 > > epoll_ctl(c->epollfd, EPOLL_CTL_DEL, id_map->sock, NULL); > > close(id_map->sock); > > - id_map->sock =3D 0; > > + id_map->sock =3D -1; > > id_map->seq =3D -1; > > } > > =20 > > @@ -315,6 +315,8 @@ void icmp_init(void) > > { > > unsigned i; > > =20 > > - for (i =3D 0; i < ICMP_NUM_IDS; i++) > > + for (i =3D 0; i < ICMP_NUM_IDS; i++) { > > icmp_id_map[V4][i].seq =3D icmp_id_map[V6][i].seq =3D -1; > > + icmp_id_map[V4][i].sock =3D icmp_id_map[V6][i].sock =3D -1; > > + } >=20 > Another (well, kind of existing) use case for a 0xff-initialising > helper. Hm.. it's still not every field, so only sorta. --=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 --9/SrBtLQMX7WQCRl Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmWZ8ooACgkQzQJF27ox 2Gctqg//bmDpun1K4svqJqZXXOEu3OyBgere6lRZ7qAQWaL4Lv5uR5iJwtGI3YIq aYhNAQjYtJfdMEcg2fm+nnk0pPdAjOEwgBrUiBJIO5U0tifKHkou3CUwXYhQONYk QWFCmUX0wVHoQQHlY5DTXHCsyHd81uOiGe54caLxLXz7b89REshXqoEVg0kMqFJI vJhsRWOlItC2dLVT2R8rsLEDymPFUC3WpFjnylUCCSZZc8HW289nVwXZz4mEsLwi zQXoDuozD89W3ijjC2pS4wb1tzVglV3SerwLp9If3VoCVceHHWanBpsGoPZrKH4V 2SEeoFkZp47wGFwmAnQrWhnaDmYA+1RqZwc9WGY1m8qaUE2IFKR+b15MH4X7ZJyQ dGC8f6sbeJyH5/girm0wkA5Box24q1gRf/5BPsUxVBa4gZsrbwzJjwxs1qOen4yw hJSlk+amLpYckRbz73NcBG8+kccgqmcyXT5zIeCmv/T7UpKtMLP6yxkqBUL9J4zq oxejop8xj/Q8AyY7nimRmT3DFpM1d8uZtHgoL48d32DJz4u3cik5x3VaU5N+Hvv/ 5qQY6uLPqAxaE0Gf6NmLFvNAzDyoiGEiftKtqatsIH+u1RsJgHF33CzzJ2SEdc5l 2u2lIgc3/9Gze59wPbcbXyVWu6gPcyHG6M1QzEDA3CEXJW58Mws= =1nj6 -----END PGP SIGNATURE----- --9/SrBtLQMX7WQCRl--