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 6C7D25A026D for ; Thu, 18 Jan 2024 17:23:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705595019; 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=q6JeC21bE9JGvd2zMTWG8UaIbk8DFqFXycmv/wZG8L4=; b=RJ1eyurUqMrOLFClK8PjqNr+fvTshdya451Ebq95G8LZ64YvLXUO6gVL+JAc3WpYXZrabc NQDc+IyZ9GwX4TSIQSKpzg9DmqR4D+0xS5AlbZz5vtiwQprxeLXY/T70lR+4l9JuRApyqf fV7Z9hwmoG8A9bXgsqm6J1ZMm1KOL0o= 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-193-E5L8rpzVNG-SPqqfWexqTQ-1; Thu, 18 Jan 2024 11:23:36 -0500 X-MC-Unique: E5L8rpzVNG-SPqqfWexqTQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 D04ED10C04E6; Thu, 18 Jan 2024 16:23:35 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7A9B2112131D; Thu, 18 Jan 2024 16:23:34 +0000 (UTC) Date: Thu, 18 Jan 2024 17:23:26 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v2] tcp.c: leverage MSG_PEEK with offset kernel capability when available Message-ID: <20240118172326.73b6f4ba@elisabeth> In-Reply-To: References: <20240114180755.1008481-1-jmaloy@redhat.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: I4KVBG7J7PJK2UULLOKVK2DI7ZXDS6JX X-Message-ID-Hash: I4KVBG7J7PJK2UULLOKVK2DI7ZXDS6JX 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: Jon Maloy , passt-dev@passt.top, 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: Not a full review, but a couple of comments, mostly about stuff I also had in pkt_selfie.c (review of v1): On Thu, 18 Jan 2024 14:05:38 +1100 David Gibson wrote: > On Sun, Jan 14, 2024 at 01:07:55PM -0500, Jon Maloy wrote: > > > > [...] > > > > + > > +=09s[0] =3D socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); > > +=09s[1] =3D socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP); > > +=09if (s[0] < 0 || s[1] < 0) { > > +=09=09perror("Temporary probe socket creation failed\n"); > > +=09=09goto out; > > +=09} > > +=09if (0 > bind(s[0], &a, sizeof(a))) { =20 >=20 > Since the socket address is unspecified, why do you need to bind at > all? It might be clearer to explicitly set a to localhost + a > specific port - because you're in a temporary namespace, you can rely > on every port being available. There are two advantages of bind() without port, and then getsockname(): first, ip_unprivileged_port_start might have whatever value in our new namespace (we don't touch it), and I wouldn't take for granted we'll have CAP_SYS_ADMIN in it for all the possible start-up combinations. Second, there's no need for a magic value. > > +=09=09perror("Temporary probe socket bind() failed\n"); > > +=09=09goto out; > > +=09} > > +=09if (0 > getsockname(s[0], &a, &((socklen_t) { sizeof(a) }))) { > > +=09=09perror("Temporary probe socket getsockname() failed\n"); > > +=09=09goto out; > > +=09} > > +=09if (0 > listen(s[0], 0)) { > > +=09=09perror("Temporary probe socket listen() failed\n"); > > +=09=09goto out; > > +=09} > > +=09if (0 <=3D connect(s[1], &a, sizeof(a)) || errno !=3D EINPROGRESS) = { > > +=09=09perror("Temporary probe socket connect() failed\n"); > > +=09=09goto out; > > +=09} =20 >=20 > This is assuming that a will now contain the correct address to > connect to. Although it will have the right port, I think the address > may still be unspecified for the listening socket. Hmm, why? From getsockname(2): getsockname() returns the current address to which the socket sockfd is bound [...] > > [...] > > > > +/** tcp_probe_msg_peek_offset_cap() - Probe kernel for MSG_PEEK with o= ffset support > > + */ > > +static bool tcp_probe_msg_peek_offset_cap() =20 >=20 > I believe we prefer the explicit foo(void) for declarations of > functions with no parameters, rather than just foo(). Right, because foo() isn't a prototype, while foo(void) is. Perhaps at some point we should enable -Wstrict-prototypes in CFLAGS (it's not in -Wextra, I just realised). Look: $ cat prototypes.c int a(void) { ; } int b() { ; } int main(char **argv) { a(); a(1); b(); b(1); } $ gcc prototypes.c prototypes.c: In function =E2=80=98main=E2=80=99: prototypes.c:3:30: error: too many arguments to function =E2=80=98a=E2=80= =99 3 | int main(char **argv) { a(); a(1); b(); b(1); } | ^ prototypes.c:1:5: note: declared here 1 | int a(void) { ; } | ^ note that calling b() with any number and type of arguments is fine. And: $ gcc -Wstrict-prototypes -Werror -Wfatal-errors prototypes.c prototypes.c:2:5: error: function declaration isn=E2=80=99t a prototype [-W= error=3Dstrict-prototypes] 2 | int b() { ; } | ^ compilation terminated due to -Wfatal-errors. cc1: all warnings being treated as errors > > [...] --=20 Stefano