From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 476341F03D2 for ; Thu, 6 Mar 2025 10:02:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741255378; cv=none; b=O5NSxJFYqyJ6RlEwX5wEEwnKHH8etMir3+8bCO4XIUXCfkvgRgF7XpKWARZfNynSr4BZxfvouzAiVPma2dQOY1LTqrw07TIx9pwXI8wjGTVPOwMhxn6ejgjJW6JP76vPxxspTc7/ym4hOWaiZRW81v3xfrj2xGFox6uGmUJAXAI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741255378; c=relaxed/simple; bh=a8PePnP6Da9TatKC4r183l014uL/MB4JIaip0KYl0eY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=C6568ZZ0t0o5j7MVJv1QMkINieuAnltQgUV8fl5xVQw0udZIlIr26QMJ2/0IZBs0OQPmx+50Nh3rqQKQd0NHiP8LQvAhMoH2wBrZVctc9sJnSnycMb8UcnmO75oGq+h6GVy36nJDZaS1+fqTSrNSxDscM0ECMSI3igyqiqG1BM4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=openvpn.net; spf=pass smtp.mailfrom=openvpn.com; dkim=pass (2048-bit key) header.d=openvpn.net header.i=@openvpn.net header.b=NzqatPjf; arc=none smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=openvpn.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=openvpn.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=openvpn.net header.i=@openvpn.net header.b="NzqatPjf" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5e0813bd105so678081a12.1 for ; Thu, 06 Mar 2025 02:02:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1741255374; x=1741860174; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=NjA/0x1ULbdGmJAhtVrbQ19bSfwG1MXXmI+NBV/yxT4=; b=NzqatPjf/88cIsrrdK2V0c9AyyKpREboscok1bxm74kRAG2AuKOuQMBMGtg13ZVtOP m+xKY7PMa3sOxUS+qHFYicBJQfeLVxm8xQ0fHxtfxytkL4sC0vO97uWe8VFYl2o5B/Al DZspDKSISf+79caWhxfOu8nmN8X3uoBmPrqDm90VvWjwXfb5PVzpGJcNUqirhLiUyPdl aDzblB1IBqbhgEKge4nM/+PQC+vibx3mKeP9t+Ek04BAgPMgd3M4bVZzoyDocvGrtgbq ViBDTte4pJdOG2h6AwG3kWuDKZA6hT+GpiyV88uJydK+FuxLg1dJCj6NAv3qNZmrOG7D xcHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741255374; x=1741860174; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=NjA/0x1ULbdGmJAhtVrbQ19bSfwG1MXXmI+NBV/yxT4=; b=DHhNLovkK+s2qpvMfSjSRL6qBpQflA7T2KE4uRkSKx6YrPsblBFsWixpr53w0yHUCI e+6sdAmUmWdKBx8ZR0qy7/x1BBhbEamJRTOP6HCwKO+dG8zV95Wk4M9BZ7WHKBSZXL2v mb2j7K/PSHlNOVjtYf55b+Ssry3q5t6snkS5HKC2+S1yDKjJdc2jAofvpFKYPakKkLWD TgOrlaCU+3dWXfIKZ9NtJvhRN965MPkatYLlcfcMbfIUuK1ROwFJt8/xyT1Rxvg35xOl Tdl9zM94gh8YBaFnUO85heielLxGH/DjCJt1QTb8yEgwZu4N1K6BEvSnAk0rVY+y3ACh FgYg== X-Forwarded-Encrypted: i=1; AJvYcCXb6Ekwkw+qmxVJVcZH9v43TmzkMFsm3stYL93RP6+WtX7YWYOZ5Y2WMF+KDgF12B9rs3vXoPRHAZOOagk=@vger.kernel.org X-Gm-Message-State: AOJu0YwF3LfwCRp1dAOa3ORhFHgw/N6Ka2QLPDrmKawOhSw1DFXXYjNU yC/irzb2gNWTZqmoO71wULXGzC/79iB2+yKBKO/aFb9r9AvZLxUuLtLsxxBeNBY= X-Gm-Gg: ASbGncvzLVDtoh67J9qNPVOQltfUzoAda+hFujZamvr5yE73HJGYSDEHH+w0BIb3vQU WDZ3So5OpG0GJPdBcsmqPb43cGovFbebqZyZNybpPaw634/epqzUgsnx+TzmGoZi/rPNbqvsQmg SNYTIyqaoWKQzeRxm8idbEnFX1PfzXOzcEg+jJVlIyYybrOTENj4/+ro4e9EVhPfXuDRJHpyzjx 61bCUjDSYkyQwFWS2rFVSsyAms0mDXfaLFPTRNDudDi2vLR8hHsUd7hMjfNVkCbOa7mIzPRRfM4 nqSb89sw6F3YFfv6ok6lFKF0De47HlpinWf//q76KSaMMSHzDp6zws4smSRiGX0eWj/WGp45dfY 5s4fR8Ug= X-Google-Smtp-Source: AGHT+IG/MX6Ctc3Sop+bjN6l6wOSX1XkN7zoXS/g0txiaNk9dp7eFWZRrKBRB2smH9x66Qm1lITf3Q== X-Received: by 2002:a05:6402:540c:b0:5de:5263:ae79 with SMTP id 4fb4d7f45d1cf-5e59f3d6532mr6189327a12.12.1741255373377; Thu, 06 Mar 2025 02:02:53 -0800 (PST) Received: from ?IPV6:2001:67c:2fbc:1:b199:f7fb:728b:9279? ([2001:67c:2fbc:1:b199:f7fb:728b:9279]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e5c7669fd0sm678988a12.51.2025.03.06.02.02.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 Mar 2025 02:02:52 -0800 (PST) Message-ID: Date: Thu, 6 Mar 2025 11:02:50 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v21 18/24] ovpn: add support for peer floating To: Sabrina Dubroca Cc: netdev@vger.kernel.org, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Donald Hunter , Shuah Khan , ryazanov.s.a@gmail.com, Andrew Lunn , Simon Horman , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Xiao Liang References: <20250304-b4-ovpn-tmp-v21-0-d3cbb74bb581@openvpn.net> <20250304-b4-ovpn-tmp-v21-18-d3cbb74bb581@openvpn.net> <9c919407-fb91-48d7-bf2d-8437c2f3f4da@openvpn.net> Content-Language: en-US From: Antonio Quartulli Autocrypt: addr=antonio@openvpn.net; keydata= xsFNBFN3k+ABEADEvXdJZVUfqxGOKByfkExNpKzFzAwHYjhOb3MTlzSLlVKLRIHxe/Etj13I X6tcViNYiIiJxmeHAH7FUj/yAISW56lynAEt7OdkGpZf3HGXRQz1Xi0PWuUINa4QW+ipaKmv voR4b1wZQ9cZ787KLmu10VF1duHW/IewDx9GUQIzChqQVI3lSHRCo90Z/NQ75ZL/rbR3UHB+ EWLIh8Lz1cdE47VaVyX6f0yr3Itx0ZuyIWPrctlHwV5bUdA4JnyY3QvJh4yJPYh9I69HZWsj qplU2WxEfM6+OlaM9iKOUhVxjpkFXheD57EGdVkuG0YhizVF4p9MKGB42D70pfS3EiYdTaKf WzbiFUunOHLJ4hyAi75d4ugxU02DsUjw/0t0kfHtj2V0x1169Hp/NTW1jkqgPWtIsjn+dkde dG9mXk5QrvbpihgpcmN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OlfRufuDrWwAv+em2uOT BnRX9nFx9kPSO42TkFK55Dr5EDeBO3v33recscuB8VVN5xvh0GV57Qre+9sJrEq7Es9W609a +M0yRJWJEjFnMa/jsGZ+QyLD5QTL6SGuZ9gKI3W1SfFZOzV7hHsxPTZ6 Organization: OpenVPN Inc. In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 05/03/2025 17:56, Sabrina Dubroca wrote: > 2025-03-05, 14:14:36 +0100, Antonio Quartulli wrote: >> On 05/03/2025 12:20, Sabrina Dubroca wrote: >>> 2025-03-05, 00:19:32 +0100, Antonio Quartulli wrote: >>>> On 04/03/2025 19:37, Sabrina Dubroca wrote: >>>>> 2025-03-04, 01:33:48 +0100, Antonio Quartulli wrote: >>>>>> A peer connected via UDP may change its IP address without reconnecting >>>>>> (float). >>>>> >>>>> Should that trigger a reset of the peer->dst_cache? And same when >>>>> userspace updates the remote address? Otherwise it seems we could be >>>>> stuck with a cached dst that cannot reach the peer. >>>> >>>> Yeah, that make sense, otherwise ovpn_udpX_output would just try over and >>>> over to re-use the cached source address (unless it becomes unavailable). >>> >>> Not just the source address, the routing entry too. I'm more concerned >>> about that: trying to reuse a a cached routing entry that was good for >>> the previous remote address, but not for the new one. >>> >>> >>> [adding your next email] >>>> I spent some more time thinking about this. >>>> It makes sense to reset the dst cache when the local address changes, but >>>> not in case of float (remote address changed). >>>> >>>> That's because we always want to first attempt sending packets using the >>>> address where the remote peer sent the traffic to. >>>> Should that not work (quite rare), then we have code in ovpn_udpX_output >>>> that will reset the cache and attempt a different address. >>> >>> I don't think the code in ovpn_udpX_output will reset the cache unless >>> it was made invalid by a system-wide routing table update (see >>> dst_cache_per_cpu_get). >>> >>> rt = dst_cache_get_ip4(cache, &fl.saddr); >>> if (rt) >>> goto transmit; >>> ... >>> transmit: >>> udp_tunnel_xmit_skb(rt, sk, skb, fl.saddr, fl.daddr, 0, >>> ip4_dst_hoplimit(&rt->dst), 0, fl.fl4_sport, >>> fl.fl4_dport, false, sk->sk_no_check_tx); >>> >>> >>> So it seems that as long as dst_cache_get_ip4 gets us a dst (which >>> AFAIU will happen, unless we did a dst_cache_reset or something else >>> made the cached dst invalid -- and ovpn's floating/endpoint update >>> doesn't do that), we'll just use it. >> >> Mh yeah, you're right. >> Then I'll reset the cache also when a float is detected. > > Ok, thanks. > >>> >>> >>>>>> +void ovpn_peer_endpoints_update(struct ovpn_peer *peer, struct sk_buff *skb) >>>>>> +{ >>>>>> + struct hlist_nulls_head *nhead; >>>>>> + struct sockaddr_storage ss; >>>>>> + const u8 *local_ip = NULL; >>>>>> + struct sockaddr_in6 *sa6; >>>>>> + struct sockaddr_in *sa; >>>>>> + struct ovpn_bind *bind; >>>>>> + size_t salen = 0; >>>>>> + >>>>>> + spin_lock_bh(&peer->lock); >>>>>> + bind = rcu_dereference_protected(peer->bind, >>>>>> + lockdep_is_held(&peer->lock)); >>>>>> + if (unlikely(!bind)) >>>>>> + goto unlock; >>>>>> + >>>>>> + switch (skb->protocol) { >>>>>> + case htons(ETH_P_IP): >>>>>> + /* float check */ >>>>>> + if (unlikely(!ovpn_bind_skb_src_match(bind, skb))) { >>>>>> + if (bind->remote.in4.sin_family == AF_INET) >>>>>> + local_ip = (u8 *)&bind->local; >>>>> >>>>> If I'm reading this correctly, we always reuse the existing local >>>>> address when we have to re-create the bind, even if it doesn't match >>>>> the skb? The "local endpoint update" chunk below is doing that, but >>>>> only if we're keeping the same remote? It'll get updated the next time >>>>> we receive a packet and call ovpn_peer_endpoints_update. >>>>> >>>>> That might irritate the RPF check on the other side, if we still use >>>>> our "old" source to talk to the new dest? >>>>> >>>>>> + sa = (struct sockaddr_in *)&ss; >>>>>> + sa->sin_family = AF_INET; >>>>>> + sa->sin_addr.s_addr = ip_hdr(skb)->saddr; >>>>>> + sa->sin_port = udp_hdr(skb)->source; >>>>>> + salen = sizeof(*sa); >>>>>> + break; >>>> >>>> I think the issue is simply this 'break' above - by removing it, everything >>>> should work as expected. >>> >>> Only if the bind was of the correct family? Checking an IPv4 local >>> address (in the bind) against an IPv6 source address in the packet (or >>> the other way around) isn't going to work well. >> >> Ah I understand what you mean. >> >> The purpose of "local_ip" is to provide a working local endpoint to be used >> with the new remote address. >> However, if the float is switching family we can't re-use the same old local >> endpoint (hence the check). >> In this case we'll learn the "new" local address later. >> >> Does it make sense? > > Sure, but we could have learned it immediately from the packet we just > got, whether we're changing family or not. No need to wait for the > next RX packet to also learn the new local address. Indeed. > > But if we now do a dst_cache_reset with the peer float, > ovpn_udp*_output will have to do a new route/local address lookup and > I guess that should clean up the local address stored in the bind, and > then update the dst_cache with the local address we just found. Right and this may not truly be what we want. If peer X is sending packets to our IP1, we should at least try to reply from the same address. If we have two IPs, IP1 and IP2, and both can be used to reach peer X, we should always try to use the one where we received traffic from X in the first place. OTOH hand it is also true that with floating detection on both sides, the situation will converge quickly, but there might be a reason why X chose IP1 as destination, therefore we should do our best to respect that. So, even in case of float, we should still store the local endpoint and attempt fetching a route that takes that into consideration. Which I think is what is happening (assuming we reset the dst_cache on float). ovpn_udpX_output() will: * get no rt from the cache * possibly confirm that saddr is ok * fetch the new rt using the provided saddr and daddr * update the cache. That makes sense to me. Would you agree? -- Antonio Quartulli OpenVPN Inc.