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 E9BEB5A026D for ; Wed, 19 Jul 2023 16:10:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689775856; 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=bp9p4SHUkqURGAFtGtcj6XXxTVDTRfg5jwAnv3TEOTQ=; b=QH0T3bTlGeqXxnY4YcbOKmPCgL80INH6a3RtoiCHBZlWT44nCt3CnB4RtvJdEjjUb5oirl aOrEF7QTrurOBcUjYRUNncfBu51yHWLHoU6PKQx8/P7CxskvBE5TQjH38jEJLfE9OKRL6g 6kqCbSpg5DY/CKI5+v81SH4YbHfHU2s= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-573-zpzAJhoFOJafa53-PozZWQ-1; Wed, 19 Jul 2023 10:10:55 -0400 X-MC-Unique: zpzAJhoFOJafa53-PozZWQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 23C6688D121; Wed, 19 Jul 2023 14:10:55 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7BCB240C6F4C; Wed, 19 Jul 2023 14:10:54 +0000 (UTC) Date: Wed, 19 Jul 2023 16:10:52 +0200 From: Stefano Brivio To: Valtteri Vuorikoski Subject: Re: ip_nonlocal_bind causes havoc with local connection detection Message-ID: <20230719161052.5b28568e@elisabeth> In-Reply-To: References: Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: QPNVLPBFHAEVNWQNVIWIATQFM6A4M7L4 X-Message-ID-Hash: QPNVLPBFHAEVNWQNVIWIATQFM6A4M7L4 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 Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Tue, 18 Jul 2023 11:14:14 +0300 Valtteri Vuorikoski wrote: > If net.ipv4.ip_nonlocal_bind is enabled, the following code in > tcp_conn_from_tap gets very confused: > > if (!bind(s, sa, sl)) { > tcp_rst(c, conn); /* Nobody is listening then */ > return; > } > if (errno != EADDRNOTAVAIL && errno != EACCES) > conn_flag(c, conn, LOCAL); > > This is especially visible if net.ipv4.ip_unprivileged_port_start is > set to a value lower than the default. For example, if > net.ipv4.ip_unprivileged_port_start=443 and > net.ipv4.ip_nonlocal_bind=1, the bind()==0 branch will be hit for all > outgoing connections going to port 443 because bind() succeeds even > when "sa" contains the remote address, and pretty much nothing will > work. Ouch, I didn't think about that. > It might the best to skip the check and marking connections as LOCAL if > net.ipv4.ip_nonlocal_bind is enabled? This would mean that if ip_nonlocal_bind is set, we'll always override the MSS, which would break essentially any non-local connection. > If that doesn't seem reasonable, > then maybe show a warning at start and/or just document that the > ip_nonlocal_bind setting shouldn't be used with passt? That's not really friendly, nor future-proof: https://bugs.passt.top/show_bug.cgi?id=48 I think we should go the relatively hard way of extracting the relevant logic from procfs_scan_listen(), and understand from there if there's a local bind for the port at hand. I'm not sure, then, if we should always use this mechanism, even if ip_nonlocal_bind isn't set, because bind() gives us a lightweight way to check for three conditions in one, and we're on a latency-critical path here, so if this results in more syscalls, I would read from procfs just in case we really need to. Feel free to send a patch, or file a bug, or both, or none. :) -- Stefano