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 3BAF75A026F for ; Wed, 22 Nov 2023 07:10:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700633444; 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=FVy3vTK0rFbpevNlGGj1iCmT7I/+DJWKXUY1ynxWkZs=; b=FofEaBL8gH9JTUF/lM0u7VTow6HHDcWnVlic2jx+Fe1iQHMIuFWsz5u0Rats4NetZEYFgn d15cmDBrbS9+QlJVXf6Ackab34UC1/yJjbUJtyKmEFHXrVwcitZLZd9K2uSGyhcis2QNhA JautMXndA5obYw4k6ZsleRlecVNagA0= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-524-8Pn5d5wvPRmFEfThIXQlug-1; Wed, 22 Nov 2023 01:10:39 -0500 X-MC-Unique: 8Pn5d5wvPRmFEfThIXQlug-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 CE1612806047; Wed, 22 Nov 2023 06:10:38 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B74E3492BFA; Wed, 22 Nov 2023 06:10:37 +0000 (UTC) Date: Wed, 22 Nov 2023 07:10:35 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v2] port_fwd, util: Don't bind UDP ports with opposite-side bound TCP ports Message-ID: <20231122071035.6e19a563@elisabeth> In-Reply-To: References: <20231121180152.1364915-1-sbrivio@redhat.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.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: BMPKDBANECLSPP5JW43H7H5FQ7ZDIVUG X-Message-ID-Hash: BMPKDBANECLSPP5JW43H7H5FQ7ZDIVUG 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, Akihiro Suda 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 Wed, 22 Nov 2023 10:58:24 +1100 David Gibson wrote: > On Tue, Nov 21, 2023 at 07:01:52PM +0100, Stefano Brivio wrote: > > When pasta periodically scans bound ports and binds them on the other > > side in order to forward traffic, we bind UDP ports for corresponding > > TCP port numbers, too, to support protocols and applications such as > > iperf3 which use UDP port numbers matching the ones used by the TCP > > data connection. > > > > If we scan UDP ports in order to bind UDP ports, we skip detection of > > the UDP ports we already bound ourselves, to avoid looping back our > > own ports. Same with scanning and binding TCP ports. > > > > But if we scan for TCP ports in order to bind UDP ports, we need to > > skip bound TCP ports too, otherwise, as David pointed out: > > > > - we find a bound TCP port on side A, and bind the corresponding TCP > > and UDP ports on side B > > > > - at the next periodic scan, we find that UDP port bound on side B, > > and we bind the corresponding UDP port on side A > > > > - at this point, we unbind that UDP port on side B: we would > > otherwise loop back our own port. > > > > To fix this, we need to avoid binding UDP ports that we already > > bound, on the other side, as a consequence of finding a corresponding > > bound TCP port. > > > > Reproducing this issue is straightforward: > > > > ./pasta -- iperf3 -s > > > > # Wait one second, then from another terminal: > > iperf3 -c ::1 -u > > > > Reported-by: Akihiro Suda > > Analysed-by: David Gibson > > Fixes: 457ff122e33c ("udp,pasta: Periodically scan for ports to automatically forward") > > Signed-off-by: Stefano Brivio > > LGTM, except for one nit: > [...] > > +/** > > + * bitmap_sum() - Sum (logic or) of two bitmaps > > I don't like the name bitmap_sum() since this isn't really an addable > object in the usual sense. Hmm, yes, I went with "sum" in the sense of logical addition -- not that it really "sums" the bitmaps. But then... > I'd prefer either bitmap_or() (thinking of > the bits as bits) or bitmap_union() (thinking of the bitmaps as sets). I could just use "_or" like the Linux kernel does. Respinning. -- Stefano