From mboxrd@z Thu Jan 1 00:00:00 1970 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 519BA5A026D for ; Sat, 6 Jan 2024 16:59:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704556784; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=07rXiva3IItAHNbu4oqNqpcfisnVqBmzxZJt6Stzj9I=; b=HligZD4Rn1ZGhsWs7c6CBzP4O/TRQxrWjQefQ1bwds9mHbzoqRIezKtEz0LkjVZqTQjRI1 Y02LhC4Ds5VRm1gzliIm1BYiEabAZE/oi6jmm4m5fOYADKKmKFkl6ZaG5d/USMkDVzV0iF qBnPR5JhO0o7leEYgTj+Nr5MqcFkYSQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-1-YBOFeR_WO2W-nKmwuzi3Kw-1; Sat, 06 Jan 2024 10:59:36 -0500 X-MC-Unique: YBOFeR_WO2W-nKmwuzi3Kw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id EB2BC85A588; Sat, 6 Jan 2024 15:59:35 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 235F32026D66; Sat, 6 Jan 2024 15:59:34 +0000 (UTC) Date: Sat, 6 Jan 2024 16:59:32 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v2 06/12] icmp: Use -1 to represent "missing" sockets Message-ID: <20240106165932.1056c316@elisabeth> In-Reply-To: <20231221065327.1307827-7-david@gibson.dropbear.id.au> References: <20231221065327.1307827-1-david@gibson.dropbear.id.au> <20231221065327.1307827-7-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: U3SQI4V6WGBA5WYILVV2C55A5ZVDAVSE X-Message-ID-Hash: U3SQI4V6WGBA5WYILVV2C55A5ZVDAVSE X-MailFrom: sbrivio@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 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: On Thu, 21 Dec 2023 17:53:21 +1100 David Gibson wrote: > 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 with > 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. > > Signed-off-by: David Gibson > --- > icmp.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > 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 pif, int af, > > iref.id = id = ntohs(ih->un.echo.id); > > - if ((s = icmp_id_map[V4][id].sock) <= 0) { > + if ((s = icmp_id_map[V4][id].sock) < 0) { > s = 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 pif, int af, > return 1; > > iref.id = id = ntohs(ih->icmp6_identifier); > - if ((s = icmp_id_map[V6][id].sock) <= 0) { > + if ((s = icmp_id_map[V6][id].sock) < 0) { > s = 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, > > epoll_ctl(c->epollfd, EPOLL_CTL_DEL, id_map->sock, NULL); > close(id_map->sock); > - id_map->sock = 0; > + id_map->sock = -1; > id_map->seq = -1; > } > > @@ -315,6 +315,8 @@ void icmp_init(void) > { > unsigned i; > > - for (i = 0; i < ICMP_NUM_IDS; i++) > + for (i = 0; i < ICMP_NUM_IDS; i++) { > icmp_id_map[V4][i].seq = icmp_id_map[V6][i].seq = -1; > + icmp_id_map[V4][i].sock = icmp_id_map[V6][i].sock = -1; > + } Another (well, kind of existing) use case for a 0xff-initialising helper. -- Stefano