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.133.124]) by passt.top (Postfix) with ESMTP id E0BA05A005E for ; Tue, 13 Dec 2022 23:49:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670971763; 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=TYSogHn9uVTSRBXk9fkMlIfPh5jmOVwgsONoBikzDvE=; b=f3krDECLTU2l6I1K+ZX0Az2YL3ujqUKAFXcrYrA93FHZfE63ygNTdZcLDTaPy4rCdwoBVg VtLip0e+BMEzJP1KqjYarhLamxC5y4VkA0ntC8Q1lMsDcuH+DTIQYzKsw8XUouqt+/FxBW aNI+HmoOPSLNz1fzxtcB9+iiboe2QI0= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-624-ypRos-sRPKG1yQm6eGtrmA-1; Tue, 13 Dec 2022 17:49:21 -0500 X-MC-Unique: ypRos-sRPKG1yQm6eGtrmA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 06EA3382F1A2; Tue, 13 Dec 2022 22:49:21 +0000 (UTC) Received: from maya.cloud.tilaa.com (ovpn-208-4.brq.redhat.com [10.40.208.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C11CE492B00; Tue, 13 Dec 2022 22:49:20 +0000 (UTC) Date: Tue, 13 Dec 2022 23:49:18 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 7/8] udp: Decide whether to "splice" per datagram rather than per socket Message-ID: <20221213234918.0b51893d@elisabeth> In-Reply-To: <20221205081425.2614425-8-david@gibson.dropbear.id.au> References: <20221205081425.2614425-1-david@gibson.dropbear.id.au> <20221205081425.2614425-8-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: ICREIBMVMZC3KRYCRE6C3W2VWOMT7MUT X-Message-ID-Hash: ICREIBMVMZC3KRYCRE6C3W2VWOMT7MUT 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.3 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 Mon, 5 Dec 2022 19:14:24 +1100 David Gibson wrote: > Currently we have special sockets for receiving datagrams from locahost > which can use the optimized "splice" path rather than going across the tap > interface. > > We want to loosen this so that sockets can receive sockets that will be > forwarded by both the spliced and non-spliced paths. To do this, we alter > the meaning of the @splice bit in the reference to mean that packets > receieved on this socket *can* be spliced, not that they *will* be spliced. > They'll only actually be spliced if they come from 127.0.0.1 or ::1. > > We can't (for now) remove the splice bit entirely, unlike with TCP. Our > gateway mapping means that if the ns initiates communication to the gw > address, we'll translate that to target 127.0.0.1 on the host side. Reply > packets will therefore have source address 127.0.0.1 when received on the > host, but these need to go via the tap path where that will be translated > back to the gateway address. We need the @splice bit to distinguish that > case from packets going from localhost to a port mapped explicitly with > -u which should be spliced. > > Signed-off-by: David Gibson > --- > udp.c | 54 +++++++++++++++++++++++++++++++++++------------------- > udp.h | 2 +- > 2 files changed, 36 insertions(+), 20 deletions(-) > > diff --git a/udp.c b/udp.c > index 6ccfe8c..011a157 100644 > --- a/udp.c > +++ b/udp.c > @@ -513,16 +513,27 @@ static int udp_splice_new_ns(void *arg) > } > > /** > - * sa_port() - Determine port from a sockaddr_in or sockaddr_in6 > + * udp_mmh_splice_port() - Is source address of message suitable for splicing? > * @v6: Is @sa a sockaddr_in6 (otherwise sockaddr_in)? > - * @sa: Pointer to either sockaddr_in or sockaddr_in6 > + * @mmh: mmsghdr of incoming message > + * > + * Return: if @sa refers to localhost (127.0.0.1 or ::1) the port from > + * @sa, otherwise 0. > + * > + * NOTE: this relies on the fact that it's not valid to use UDP port 0 The port is reserved by IANA indeed, but... it can actually be used. On Linux, you can bind() it and you can connect() to it. As far as I can tell from the new version of udp_sock_handler() we would actually misdirect packets in that case. How bad would it be to use an int here? By the way, I think the comment should also mention that the port is returned in host order. -- Stefano