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 789B05A004E for ; Sun, 21 Jul 2024 11:21:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721553667; 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=klc3dIIlC7BE2GO4VFyTs1p+NnXyHRN43ERGSGAMDmc=; b=fRk4GJsodUzTnPqz3Mt38D1n8G/YlVy3FeO91vaZStdjIKT7lb6O3HR4oroe8WCyHZLZon 74tqc8lcNYD67M8hmz8TG6WJJGDlWRITcj6IXJSmAfTCwRB8l1gAvN8umfs9RL1P8bO6Mw bpoIazMXKszbMbFhrQo0AmuDb7lxHfE= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-679-Zs1o3rtqOn2KHdHcul9Kxg-1; Sun, 21 Jul 2024 05:21:05 -0400 X-MC-Unique: Zs1o3rtqOn2KHdHcul9Kxg-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-44df73f9ee2so44876331cf.2 for ; Sun, 21 Jul 2024 02:21:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721553664; x=1722158464; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=LhLvOLUerW0Cp4vhMYsEYV3ABdWfE7gAjFwWGfV/zcQ=; b=dc+aQbcNv7zk2yXYYS2uN7woP9pzfa4AT5IMz5hg0gj7T45Ac8mEFsBejGgKxXm8gg 6SDrNEmfCySxr3W2djtO8aDZjpZi+tISdRRDObp16za1HR5sU7aOBXraTw4jHf09q2eI I7Q+lHHFy0vrxZCbgT70Jk6cnqmbIiarlTRkyhAXdhBW56PCc4pxedZPx/jGU0IRPO94 0WPEpku0SWqnqcAkCBR48vryKG/yOFYVqZH5aPn3jhcgPYRRgx3UtKl7shCZxgWHJ/58 Jjd6HGoCEqnRjlbSk3TDqnDk8DeS+lN7c93M77W5FgsGiSc5hT1gy5JM3h0I9dTfLITl kOIA== X-Gm-Message-State: AOJu0YyyiYjguDKTE02EoAAbN8JWHeJX+9nxUcoBRrUUjHK0hL152i1e XG5A5y1gbDkyN0+TSgqxQHBWKXO4d/RVfxE0AkPihnLSP8k0hbr8NDSm5ARxQ1XQSQ5mfeCGMrY Wr4DZPgoJ/T/I9/NYZSaB25QJ3rJjTCcpyXv14r+69ZRSh1p7DIiLB6CDPPzci+OTaWBzjhXmtq hzAmnBVlcpMmWlTIhLGvhPB7pt5iCKqwAvK4I= X-Received: by 2002:a05:622a:10b:b0:447:f73b:6e2f with SMTP id d75a77b69052e-44fa531d970mr57081781cf.39.1721553664033; Sun, 21 Jul 2024 02:21:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpQ+nE4FMWXLkkDZVa1H7KEbKWh5bCH9NGGptfxqq0AQ7DHQDpyVp0eCDMZS3JDFsL48Z3Mg== X-Received: by 2002:a05:622a:10b:b0:447:f73b:6e2f with SMTP id d75a77b69052e-44fa531d970mr57081591cf.39.1721553663642; Sun, 21 Jul 2024 02:21:03 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-44f9cd007cesm23967381cf.21.2024.07.21.02.21.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Jul 2024 02:21:02 -0700 (PDT) Date: Sun, 21 Jul 2024 11:20:27 +0200 From: Stefano Brivio To: Jon Maloy Subject: Re: [PATCH] tcp: probe for SO_PEEK_OFF both in tcpv4 and tcp6 Message-ID: <20240721112027.6b2ad140@elisabeth> In-Reply-To: <20240720135453.2694694-1-jmaloy@redhat.com> References: <20240720135453.2694694-1-jmaloy@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 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: WREVPPVNM6JJFCO5PUCWEXE5WCIIBMGA X-Message-ID-Hash: WREVPPVNM6JJFCO5PUCWEXE5WCIIBMGA 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, 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: On Sat, 20 Jul 2024 09:54:53 -0400 Jon Maloy wrote: > The recently added socket option SO_PEEK_OFF is not supported for > TCP/IPv6 sockets. Until we get that support into the kernel we need to > test for support in both protocols to set the global 'peek_offset_cap=C2= =B4 > to true. >=20 > Signed-off-by: Jon Maloy > --- > tcp.c | 36 +++++++++++++++++++++++++----------- > 1 file changed, 25 insertions(+), 11 deletions(-) >=20 > diff --git a/tcp.c b/tcp.c > index c5431f1..32026ca 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -2717,6 +2717,28 @@ static void tcp_sock_refill_init(const struct ctx = *c) > =09} > } > =20 > +/** > + * tcp_probe_peek_offset_cap() - Check if SO_PEEK_OFF is supported by ke= rnel > + * @af:=09=09Address family, IPv4 or IPv6 > + * > + * Return: true if supported, false otherwise > + */ > +bool tcp_probe_peek_offset_cap(int af) > +{ > +=09bool ret =3D false; > +=09int s, optv =3D 0; > + > +=09s =3D socket(af, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); > +=09if (s < 0) { > +=09=09warn_perror("Temporary TCP socket creation failed"); > +=09} else { > +=09=09if (!setsockopt(s, SOL_SOCKET, SO_PEEK_OFF, &optv, sizeof(int))) > +=09=09=09ret =3D true; > +=09=09close(s); > +=09} > +=09return ret; > +} > + > /** > * tcp_init() - Get initial sequence, hash secret, initialise per-socket= data > * @c:=09=09Execution context > @@ -2725,8 +2747,7 @@ static void tcp_sock_refill_init(const struct ctx *= c) > */ > int tcp_init(struct ctx *c) > { > -=09unsigned int b, optv =3D 0; > -=09int s; > +=09unsigned int b; > =20 > =09ASSERT(!c->no_tcp); > =20 > @@ -2752,15 +2773,8 @@ int tcp_init(struct ctx *c) > =09=09NS_CALL(tcp_ns_socks_init, c); > =09} > =20 > -=09/* Probe for SO_PEEK_OFF support */ > -=09s =3D socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); > -=09if (s < 0) { > -=09=09warn_perror("Temporary TCP socket creation failed"); > -=09} else { > -=09=09if (!setsockopt(s, SOL_SOCKET, SO_PEEK_OFF, &optv, sizeof(int))) > -=09=09=09peek_offset_cap =3D true; > -=09=09close(s); > -=09} > +=09peek_offset_cap =3D tcp_probe_peek_offset_cap(AF_INET) && > +=09=09tcp_probe_peek_offset_cap(AF_INET6); I think we shouldn't probe for IPv4 SO_PEEK_OFF support if we're not interested in it, and the same applies for IPv6: those two checks should depend on whether c->ifi4 and c->ifi6 are set (following the same logic as tcp_sock_init()). In practice, since you just submitted the fix to have SO_PEEK_OFF support also for IPv6 sockets, it doesn't matter so much, but it might still be relevant for users who will stick to 6.9 and 6.10 kernel versions for a while, for whatever reason. Eventually, we might want to support IPv6 operation on IPv4-only hosts, maybe even with default options, making this even less relevant. But the day we get to it, it should be simpler to just replace all the checks of c->ifi4 / c->ifi6 used to represent IPv4 / IPv6 support, rather than replacing slightly different bits of logic. --=20 Stefano