From nobody Tue Nov 26 22:14:36 2024 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 6FAC51AA7B4 for ; Wed, 16 Oct 2024 01:04:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729040658; cv=none; b=DBqU7xa6wEHaZotkYJVz4lcRgPTI5qrLwpwwdJu0wS0KKxNrxqmg8GJEPK06WCF1RNb/fphhgoMIKo/V4P61WCq7pqAKeCAZxFBRe4HUBCgHhPjWifwagtZaEco2iBB6G/sRHp3e71zW1IwldUP4ksCGy/u5rs+ie/7H5e/Xb9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729040658; c=relaxed/simple; bh=wcrv5vDIBCgquenyyeflyML2Rh+TBSULYHxIEBJctjY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KZ0MOWz5dPi4nfaiJ/qxcfisOwGNoXoaE7PMpoD4i/it5yDjtFbd8n6bON8CZRJIxzcX9TdgoaDudjmzciq7bKTxRfa7/8kauMCoi9V4+j085RnGrWvKJqQ2kR1w9xyKRYSvf/XpjwilDqX8DpdA2a4RRC7hlnSj2AG7pRo0RuU= 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=e94d2SOy; arc=none smtp.client-ip=209.85.221.47 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="e94d2SOy" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-37d518f9abcso3307756f8f.2 for ; Tue, 15 Oct 2024 18:04:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1729040654; x=1729645454; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ChnIuUCSP0kqnENSs3HRLRGEcxuQeK/etR6vsQ0JSww=; b=e94d2SOykI4tZyMN+y7l6tD3n+l+NMgTzN+81qtZQ0MqQq9CgYbtBBlyrX9gDG68D4 7F2CbCe82SaJRStKoQ3pL+3gPaUSfSfGZ2xmCwcyeJxDOrwMV5bqT7fpp0OE77Wlstma pxow/oiXd3Bwhu90s+S9GlYjqjU7nz897HIyiWv/C+Md13oN4Mx8eJFsPobIeOWhdrGY 8zh7vBIBGXhfukzL42p77+6cQqG+G6qnmTaQ2L3xN8kSXt+WK68rjG2xWUiL6SdVml14 yPTF6EXiHwHt+Ns/X/ay0EOW4eug914VlHZh9Q1foWzIDB6oZOdDEEd7d+CNVTCYTY8W 3RxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729040654; x=1729645454; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ChnIuUCSP0kqnENSs3HRLRGEcxuQeK/etR6vsQ0JSww=; b=NyBQCux7WoSwlthL0R7qOFpwwmDDAdZ3Bv6xQAxSjOOkgqlJRvqNwlfJ0dmQsrm3Rx RsC18drsU+5Wp+ibuTZIwEWVqvlaw48LKbBONpR30FXGh64WDquv8z5lgywC569AdN+R y+ZDCQs0FWsoIDST34wN75ZjLbXhZMyJBdXroVZz1GocQZ2RfdrVExY+QCYQ+1xy1rDt QYLt2bt3EFSbYqCvl/2IrdvYaw2XPZWDihmfxpyqO3b6zn75WemW0sR7voJqUoww88D1 IMMDoiEfEn3/LER2+v38xNEMPxxPZWxlFcEXCX2HCW4UXq5uwmNjHL3Rzx3OOJHeeeN5 nu0A== X-Forwarded-Encrypted: i=1; AJvYcCXpCHuIxKFVkJmgsfY3ZTz6f7MteX6tTFr1l6YPR5dLvXGI8mW4sXeR/gnPn9A8SB3CkodRi2wi34ayl+M=@vger.kernel.org X-Gm-Message-State: AOJu0Yyr+7aV1tgNJRB4XwxMZeIcFpqt4v7KjXrdMi4L9TPaZJuougrk TreC+Op83zy4td3O5THhfJmDJn4h8Huvjnt85P3qsHKtvSQdhi+4R77+HtX7Kj8= X-Google-Smtp-Source: AGHT+IE7wXhjo5SnBaFKlMDPSjAWhWNI4DkLi1mcYGrN3mBifWUDVNxwRaCf0o64CPXroMk4Z5tP6A== X-Received: by 2002:adf:979a:0:b0:37d:4ebe:163e with SMTP id ffacd0b85a97d-37d86d69785mr1327510f8f.53.1729040653767; Tue, 15 Oct 2024 18:04:13 -0700 (PDT) Received: from serenity.mandelbit.com ([2001:67c:2fbc:1:4c1a:a7c8:72f5:4282]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d7fa8778csm2886765f8f.25.2024.10.15.18.04.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2024 18:04:12 -0700 (PDT) From: Antonio Quartulli Date: Wed, 16 Oct 2024 03:03:16 +0200 Subject: [PATCH net-next v9 16/23] ovpn: add support for updating local UDP endpoint Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241016-b4-ovpn-v9-16-aabe9d225ad5@openvpn.net> References: <20241016-b4-ovpn-v9-0-aabe9d225ad5@openvpn.net> In-Reply-To: <20241016-b4-ovpn-v9-0-aabe9d225ad5@openvpn.net> To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Donald Hunter , Antonio Quartulli , Shuah Khan , donald.hunter@gmail.com, sd@queasysnail.net, ryazanov.s.a@gmail.com, Andrew Lunn Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, openvpn-devel@lists.sourceforge.net, linux-kselftest@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2783; i=antonio@openvpn.net; h=from:subject:message-id; bh=wcrv5vDIBCgquenyyeflyML2Rh+TBSULYHxIEBJctjY=; b=owEBbQGS/pANAwAIAQtw5TqgONWHAcsmYgBnDxDwdn3sHTKgsc8bpNPW+2syO0oFdCBTe2XHs nQ4ck4gTCmJATMEAAEIAB0WIQSZq9xs+NQS5N5fwPwLcOU6oDjVhwUCZw8Q8AAKCRALcOU6oDjV h5LdCACZYPdMqsOGmhv1PHvTJ+E30Nh8fsmf1xnVslUHiu4MAp+H6XpmhfCgrcq7YIYw4kSElBL 9LSXybx0wZ8gc8eAXs/cv9sSzraAj5eGOXgET1dPjb/iYJ7HypKk6VUpjPrsMZDNQV3RmfZBtST WG5G3+ppce02F2l/65t1VCOaKyYN95kW7xNsiXxRS76EZAsHj8DWN/9Jolfr7bVi7D64MVkcB0L R2KSm2zuVLjVJcHScbWv8+0PQAa8LUU7of1NKk2IdOrTP6Om0tTBNS1VdEsZqkc+XWGbqOYpBZK w1P0noN8yKK0c/K/6kHgm9aJTgJhlIj8Pi7kzBad4IQOKAaC X-Developer-Key: i=antonio@openvpn.net; a=openpgp; fpr=CABDA1282017C267219885C748F0CCB68F59D14C In case of UDP links, the local endpoint used to communicate with a given peer may change without a connection restart. Add support for learning the new address in case of change. Signed-off-by: Antonio Quartulli --- drivers/net/ovpn/peer.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ drivers/net/ovpn/peer.h | 3 +++ 2 files changed, 48 insertions(+) diff --git a/drivers/net/ovpn/peer.c b/drivers/net/ovpn/peer.c index fa1883d12dfd6ce3e2ad1f9835f15aa7db5c8290..f3b20a561d614da98a8bee80272= 095b15bc6650d 100644 --- a/drivers/net/ovpn/peer.c +++ b/drivers/net/ovpn/peer.c @@ -416,6 +416,51 @@ struct ovpn_peer *ovpn_peer_get_by_id(struct ovpn_stru= ct *ovpn, u32 peer_id) return peer; } =20 +/** + * ovpn_peer_update_local_endpoint - update local endpoint for peer + * @peer: peer to update the endpoint for + * @skb: incoming packet to retrieve the destination address (local) from + */ +void ovpn_peer_update_local_endpoint(struct ovpn_peer *peer, + struct sk_buff *skb) +{ + struct ovpn_bind *bind; + + rcu_read_lock(); + bind =3D rcu_dereference(peer->bind); + if (unlikely(!bind)) + goto unlock; + + spin_lock_bh(&peer->lock); + switch (skb_protocol_to_family(skb)) { + case AF_INET: + if (unlikely(bind->local.ipv4.s_addr !=3D ip_hdr(skb)->daddr)) { + netdev_dbg(peer->ovpn->dev, + "%s: learning local IPv4 for peer %d (%pI4 -> %pI4)\n", + __func__, peer->id, &bind->local.ipv4.s_addr, + &ip_hdr(skb)->daddr); + bind->local.ipv4.s_addr =3D ip_hdr(skb)->daddr; + } + break; + case AF_INET6: + if (unlikely(!ipv6_addr_equal(&bind->local.ipv6, + &ipv6_hdr(skb)->daddr))) { + netdev_dbg(peer->ovpn->dev, + "%s: learning local IPv6 for peer %d (%pI6c -> %pI6c\n", + __func__, peer->id, &bind->local.ipv6, + &ipv6_hdr(skb)->daddr); + bind->local.ipv6 =3D ipv6_hdr(skb)->daddr; + } + break; + default: + break; + } + spin_unlock_bh(&peer->lock); + +unlock: + rcu_read_unlock(); +} + /** * ovpn_peer_get_by_dst - Lookup peer to send skb to * @ovpn: the private data representing the current VPN session diff --git a/drivers/net/ovpn/peer.h b/drivers/net/ovpn/peer.h index 952927ae78a3ab753aaf2c6cc6f77121bdac34be..1a8638d266b11a4a80ee2f08839= 4d47a7798c3af 100644 --- a/drivers/net/ovpn/peer.h +++ b/drivers/net/ovpn/peer.h @@ -152,4 +152,7 @@ bool ovpn_peer_check_by_src(struct ovpn_struct *ovpn, s= truct sk_buff *skb, void ovpn_peer_keepalive_set(struct ovpn_peer *peer, u32 interval, u32 tim= eout); void ovpn_peer_keepalive_work(struct work_struct *work); =20 +void ovpn_peer_update_local_endpoint(struct ovpn_peer *peer, + struct sk_buff *skb); + #endif /* _NET_OVPN_OVPNPEER_H_ */ --=20 2.45.2