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 8EB735A026E
	for <passt-dev@passt.top>; Thu, 25 Apr 2024 00:02:18 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
	s=mimecast20190719; t=1713996137;
	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=H41H1GgfxJR047mlX7HEF8tGdW46ii0riujgjJBstUM=;
	b=GUP9u+70GofWxopeIxh79AtBy+GuPyG6t0cyeE3kCLAZhQLUZnL3D+WJwo2zFemUdE9q5i
	7srqdL56bxlM21sonhfXdeNJ0I1GsZltPxjQRFDKb5Fdaxq/28bXffqIoF8+2p2B6KzUqL
	/j3634A2Shi2ns3Jao4Sm4AYnrYsRfg=
Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com
 [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-312-JKetDaEpMwWyYXNr2E-ejQ-1; Wed, 24 Apr 2024 18:02:16 -0400
X-MC-Unique: JKetDaEpMwWyYXNr2E-ejQ-1
Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a5238ca77adso155171366b.1
        for <passt-dev@passt.top>; Wed, 24 Apr 2024 15:02:15 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1713996133; x=1714600933;
        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=H41H1GgfxJR047mlX7HEF8tGdW46ii0riujgjJBstUM=;
        b=l5lTih1vNP86ty8ETeC6dwO2UfQF5IQTtyKVzlZnYq7h/+IJoJF/S4aB5ySAxvfspI
         NSTYP19HWMN/JbwmyTFeKz5EZBFHNWICVztznrtQX8OSDXdVqCJLIAEBb43ZLUvC2gfb
         ejkfDfumsTkczbDC55fs7VwMiVbUx4mPDInQZT1H+unrXOazrTSu347Ja0K8lFswFyV/
         iyaVTCE4IJTGpS9CihjNeRE+O0xM7VMeYikuBW+d/1UUyKIa5K0JpvSbFUQR9ogvysQ5
         sO/4YT6Fa/Sax/6FKiS8UicYYn4vbOHwniPC5jBN2h8fKU3asPj+G1bswVcjE5kgYOYs
         nWVg==
X-Gm-Message-State: AOJu0YxJdejjYRo4Jyl6WAgQmchUuYR3O4/UBbkeaHH30ma3MZtEQhhZ
	m2rKV4RQHUeEYMd7VAExFx9G7oSHYN/qOW9oUAMVOmDw7QW1HL4DjPbm86oGdpkDh+43ykkeX3x
	DUH6t4jnBvS9Bs8+AA+90qlPI7s4x9WVq1rmpZedcmd5KqweXaOH/hRWcssZn
X-Received: by 2002:a17:906:15cf:b0:a55:b10c:8f6d with SMTP id l15-20020a17090615cf00b00a55b10c8f6dmr925736ejd.29.1713996133513;
        Wed, 24 Apr 2024 15:02:13 -0700 (PDT)
X-Google-Smtp-Source: AGHT+IHZk/vNMkIovhh4g9xYTWCo6tz71CdqE9raibz3oPM51VhR1/rFOnkOyML9eLEUwttYEgjfmA==
X-Received: by 2002:a17:906:15cf:b0:a55:b10c:8f6d with SMTP id l15-20020a17090615cf00b00a55b10c8f6dmr925716ejd.29.1713996133035;
        Wed, 24 Apr 2024 15:02:13 -0700 (PDT)
Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33])
        by smtp.gmail.com with ESMTPSA id q26-20020a1709066b1a00b00a53c746b499sm8750593ejr.137.2024.04.24.15.02.12
        (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 24 Apr 2024 15:02:12 -0700 (PDT)
Date: Thu, 25 Apr 2024 00:01:39 +0200
From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [PATCH] udp: Correctly look up outbound socket with port
 remappings
Message-ID: <20240425000139.62cbe490@elisabeth>
In-Reply-To: <20240424010534.496003-1-david@gibson.dropbear.id.au>
References: <20240424010534.496003-1-david@gibson.dropbear.id.au>
Organization: Red Hat
X-Mailer: Claws Mail 4.2.0 (GTK 3.24.36; x86_64-pc-linux-gnu)
MIME-Version: 1.0
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Message-ID-Hash: RBKZOUTLCCTRFQ4754C472O2XM5PM7A3
X-Message-ID-Hash: RBKZOUTLCCTRFQ4754C472O2XM5PM7A3
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 <passt-dev.passt.top>
Archived-At: <https://archives.passt.top/passt-dev/20240425000139.62cbe490@elisabeth/>
Archived-At: <https://passt.top/hyperkitty/list/passt-dev@passt.top/message/RBKZOUTLCCTRFQ4754C472O2XM5PM7A3/>
List-Archive: <https://archives.passt.top/passt-dev/>
List-Archive: <https://passt.top/hyperkitty/list/passt-dev@passt.top/>
List-Help: <mailto:passt-dev-request@passt.top?subject=help>
List-Owner: <mailto:passt-dev-owner@passt.top>
List-Post: <mailto:passt-dev@passt.top>
List-Subscribe: <mailto:passt-dev-join@passt.top>
List-Unsubscribe: <mailto:passt-dev-leave@passt.top>

On Wed, 24 Apr 2024 11:05:34 +1000
David Gibson <david@gibson.dropbear.id.au> wrote:

> Commit bb9bf0bb ("tcp, udp: Don't precompute port remappings in epoll
> references") changed the epoll reference for UDP sockets to include the
> bound port as seen by the socket itself, rather than the bound port it
> would be translated to on the guest side.  As a side effect, it also means
> that udp_tap_map[] is indexed by the bound port on the host side, rather
> than on the guest side.  This is consistent and a good idea, however we
> forgot to account for it when finding the correct outgoing socket for
> packets originating in the guest.  This means that if forwarding UDP
> inbound with a port number change, reply packets would be misdirected.
> 
> Fix this by applying the reverse mapping before looking up the socket in
> udp_tap_handler().  While we're at it, use 'port' directly instead of
> 'uref.port' in udp_sock_init().  Those now always have the same value -
> failing to realise that is the same error as above.
> 
> Link: https://bugs.passt.top/show_bug.cgi?id=87
> Fixes: bb9bf0bb ("tcp, udp: Don't precompute port remappings in epoll
>                   references")
> 
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>

Applied.

-- 
Stefano