From nobody Fri Jan 31 14:57:58 2025 X-Original-To: freebsd-net@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YkzXW47kRz5mG5x for ; Fri, 31 Jan 2025 14:58:03 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YkzXV3LVmz3YwS for ; Fri, 31 Jan 2025 14:58:02 +0000 (UTC) (envelope-from markjdb@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20230601 header.b=bldzEYWx; spf=pass (mx1.freebsd.org: domain of markjdb@gmail.com designates 2607:f8b0:4864:20::f31 as permitted sender) smtp.mailfrom=markjdb@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=freebsd.org (policy=none) Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-6d8a3e99e32so18405886d6.2 for ; Fri, 31 Jan 2025 06:58:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738335481; x=1738940281; darn=freebsd.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=XLxhO5YcRtfuNElmrcL1LfYPGFQvRYYqBzyYDubFKjY=; b=bldzEYWxA9SbhfmQy72SKhGblmeNhByl5Odn/6Rt5UPuhGX6cKrHyOUu7bgwjthW5z qiZFczCAK2kKJ9thAwAn0BecMmsZIm1c4jBzhMo+r2AzjnorGogN86cBmGZOwLqhqQIS zBHtdGIBYVJ15XBt7mxNd+eRTH1NIV4s5tfXt4lD/79ibdU/FsmBBAr/sTzrSNTocPfY NemiDJYyhxCQvfAVpb9TWJ72GybFfjB0w+KiQ9uoLLAQo1YPXYXoa210z4PPmwveRY0y AjCtRwNodypr4lXysvzcL0cVRQObWk6CJaSaikETmztdiOOEybEhyp5gwXEV4Y5WIHel Gzow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738335481; x=1738940281; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:sender:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=XLxhO5YcRtfuNElmrcL1LfYPGFQvRYYqBzyYDubFKjY=; b=U/GyQ/0/kEOsuTvCuCoT78MFRnrSQXCeyDavSTLFCc6+2fygAFiLijW0SYL2Uy7rj8 1Is1k+5hyBLtY9fSrXJ3/0iZk0bEIRjazuMNNzw25ajDw4wkmUAHAY7djh18yjBCFKma UuUseFx+N696ApcRjGbsj7V1oExaIknO6VeT0V9Aa+40Oitq5K7dvbOhIyHPIENb1fQV DYNPug2Y721Ge2Ff8k7KQF1lF51gJ4XPga+Fhyg+m7i9rmokiramMxD2s87MIv623Ie6 3qkDom31jH7dBOSh1xaNMSGvMpYV07Xgw3uv2IvLDU/trMzcMzrutJ/xMRAXxT5dkjnJ 2hcQ== X-Gm-Message-State: AOJu0YxyxUsD3ygbArUqCDLVLeQXAdHIsWKIXoYdiF5qHHeyGwTak4Rw aPVgCR9bTX0iQhivyy7mldWAMz8+MQiNhDD0uAjgDpPhTvhnGEh+vnhKag== X-Gm-Gg: ASbGncsWBmlqrN0cj16giY8im81Z9MdZ/Id3ozGHj+WZf79n4kfbsUEiFU6fbC35ImK WgdjZXLpWahWAXFA9K0vX7kyi3liIi1Wjhkj/NvveyKqm+6EfKHCcHtnDbxmgo4QotLoJorj014 KL0XmsI6fWIeR7/nig+B5HskEKT7RIPh2PnN7p9x/fKMdxZrKhrQXd+6T9Z7qDdALiZM3E7g1zH c3L+jg+OGjOBiAVWjSk9vGCVfkBt+hqksKUxc0JtcYSsndjynBH7W7Ms5q0kMfiPfZye7QF8UO/ g9fqrJOuSC8MQf20xA9By4UcaGtN1A== X-Google-Smtp-Source: AGHT+IFVqL83vzKDApNseAo9FB9XTzSQwNy4wVGeRpw7iNn5LdfX8MtVqEcfLA2uhKzStWHUkCnuVg== X-Received: by 2002:a0c:aa16:0:b0:6e2:4ad7:24c8 with SMTP id 6a1803df08f44-6e24ad72dbdmr109978576d6.2.1738335481377; Fri, 31 Jan 2025 06:58:01 -0800 (PST) Received: from nuc (192-0-220-237.cpe.teksavvy.com. [192.0.220.237]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6e2547f2c61sm18727186d6.11.2025.01.31.06.58.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2025 06:58:00 -0800 (PST) Date: Fri, 31 Jan 2025 09:57:58 -0500 From: Mark Johnston To: freebsd-net@freebsd.org Subject: Re: per-FIB socket binding Message-ID: References: List-Id: Networking and TCP/IP with FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-net List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-net@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spamd-Result: default: False [-2.59 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.99)[-0.995]; MID_RHS_NOT_FQDN(0.50)[]; FORGED_SENDER(0.30)[markj@freebsd.org,markjdb@gmail.com]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20230601]; DMARC_POLICY_SOFTFAIL(0.10)[freebsd.org : SPF not aligned (relaxed), DKIM not aligned (relaxed),none]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_LAST(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MISSING_XM_UA(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_NEQ_ENVFROM(0.00)[markj@freebsd.org,markjdb@gmail.com]; DKIM_TRACE(0.00)[gmail.com:+]; PREVIOUSLY_DELIVERED(0.00)[freebsd-net@freebsd.org]; TO_DOM_EQ_FROM_DOM(0.00)[]; MLMMJ_DEST(0.00)[freebsd-net@freebsd.org]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::f31:from] X-Spamd-Bar: -- X-Rspamd-Queue-Id: 4YkzXV3LVmz3YwS On Tue, Dec 17, 2024 at 01:15:07PM -0500, Mark Johnston wrote: > Lately I've been working on adding FIB awareness to bind(2) and inpcb lookup. > Below I'll describe the project a bit. Any feedback/comments/suggestions would > be appreciated. > > Today, a TCP or UDP socket can receive connections or datagrams from any FIB. > Suppose a SYN arrives on an interface in FIB 1. A TCP listening socket attached > to FIB 0 may receive the SYN and create a new connection; the FIB of the new > socket is inherited from the listening socket, so the new connection will also > belong to FIB 0 even though the SYN was associated with FIB 1. As long as FIB 0 > has a route to the SYN's source address, the connection will work. > > For some applications, one may prefer to ensure that the connection is > associated with the FIB of the incoming SYN; if no socket is listening in that > FIB, the connection would be dropped. We could have a mode where accept() puts > the new socket in the FIB of the incoming SYN, rather than that of the listening > socket, but that doesn't help for connectionless sockets. > > This is useful if one has a service with per-FIB configurations and wants to run > multiple instances without having to specify non-overlapping addresses for them > to listen on. Or, if one wants to run a service only in a specific FIB for > whatever reason. > > To implement this, I propose having per-VNET tunables for TCP, UDP and raw > sockets, with the following effects: > - Multiple sockets can bind to the same addr/port (INADDR_ANY in particular), so > long as they belong to different FIBs and all are owned by the same user. > - SO_REUSEPORT and SO_REUSEPORT_LB can still be used to share a port among > sockets in the same FIB. > - When in_pcblookup() goes off to find an inpcb to handle a received packet, > only inpcbs belonging to the same FIB as the packet will be returned. If no > such inpcb exists, the packet is dropped, even if an inpcb in a different FIB > could handle the packet. The patch stack starting from this review contains all of my proposed changes: https://reviews.freebsd.org/D48660 Comments on the patches, whether on phabricator or here, are welcome. > This would be opt-in behaviour since it can easily break existing applications. > In particular, it'd be easy to lock oneself out of a system if, say, one relies > on being able to ssh in from a non-default FIB. That said, I do think these > semantics are a bit more intuitive than the default ones. > > I've implemented most of this locally; I'm still working on documentation and > test cases, so haven't posted patches for review yet, aside from some > preparatory cleanup and bind(2) test cases. I aim to have things in review > sometime in January. > > Any thoughts/comments?