From nobody Thu Nov 28 12:56:35 2024 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 43CF61C0DCB for ; Wed, 2 Oct 2024 09:03:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727859822; cv=none; b=nG5Ae34sxi1+cd8dez6efZWzr9qPvf/dUS5W5OW31NLeLG6AnVxo5IzmieBAalGBtTw95ymH5u4lzbZr1T8TfIoYe3WRxzN2QBjqiOBxGlBwxQHnNjuA1Yz9Fgew/008h1Mf4bpBdQ7MObn9eg9NCiCUnGI1nvcdMuLGuTa3Fk0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727859822; c=relaxed/simple; bh=em86kif804PfCNBmcFWnuObwa9l8Vt83cqY4INjENwo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ILdCOCGwBDQCnBaEatUp6kAwevJO5bGe61O5OSoivPM+2htjAUJuB0bcq2C0RZ1kEGClrS1bqKc8ZmHrPIOY/De5yYg33N5lEvAJ783GIfIT4GIqDUmfqfeU1DFWeoMv5o47sDVme/jTKFGJ11mfTXP1kZCq6zOVWJyXiCVHzGY= 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=QWl555ky; arc=none smtp.client-ip=209.85.128.50 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="QWl555ky" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-42cacabd2e0so50597685e9.3 for ; Wed, 02 Oct 2024 02:03:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1727859817; x=1728464617; 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=M4U2CGV7Muz0s4AKHAl9CLluIYCvToAM/yW8K6lT7kw=; b=QWl555ky6tsmFx1W+LFjVV195OajZjc0dIE3Ha5IaVhZW1rOffRHFofbDelY0mA/+f mF3MSR1ouq84eddhvKB1ARvduG0L1RZxN6pofsBcNFdbQBxKpkH6i20sGIOuRrdSOrZ9 vVZ8p3AGNIIs7pR1Jaz+RxO7aVFwczMFxm/4DB+sKTDYWYWbGBJQdotHV9gsqNRFrcbP HYCIrCNd9SmXw58AaP58q8L5/w/bqnXa0mHH0haeFW/odDE9h6C0rWm/XLAiSULnlm0a TwFTnyN+qn7/baEtQ4nuA3grqsA39RHyDEJjUq3TvmYa7xnqxPT/geArsUCLz4Albim+ hHaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727859817; x=1728464617; 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=M4U2CGV7Muz0s4AKHAl9CLluIYCvToAM/yW8K6lT7kw=; b=FYcgnCBycnv7tHQ4uSPBzuHR1ph03YUe74v1hXXEYVHIeIMLHL0Sbj/UedV27hAty7 FLcdjRwsiuBLjossrqgB6q6nKaCbBimY9+2hRWY+V3FpFoXxYRUdsdvPCTTuztcI84mP gXEYVwYYxUi1wq/w/WH8xs8pIPIKIXPTacAqjnjyykZGFRSjFoi4WtF6ELqK0FIZtPjc mgFxNx9rYzd7E2irdra7TYr8d61e0PHEUPsdoiCtUPW8z8ereaNJXI5bxhRUz3e+Jd2F B2Xi2XLImWp3FIjgC2MA0ITtgO+ZQ52LuCWKPnFH3HgDdWKK2O7PjGg036KU4M1Lj2md hgMA== X-Forwarded-Encrypted: i=1; AJvYcCWx74G176AV/778k/y2gy3N3m2iA/bKfyQinIMe3EjF2zZpxT7ZNOC3fHmr1ETYBVWM4VS4f7n08BcnCbE=@vger.kernel.org X-Gm-Message-State: AOJu0Ywmsbq4Wwu1hBuCY6RsjbFz4ocRDPub63IvRmgECj+qlip5+q37 RghUMmj5QYIT1vsYyv0glwqFbZb0rA08hb+4DQbdmh0/gq5+ZmElhZTsaVxRBDbdl2P6vqbdtr7 R X-Google-Smtp-Source: AGHT+IH9aZ1vVNBI6bT6zIA82+8YSkypRqTem5OODRt/ezqjNhFnFYCWf59vLNgAuurWVB/PeYOr5g== X-Received: by 2002:a05:600c:1d26:b0:42c:bae0:f05b with SMTP id 5b1f17b1804b1-42f777b0b18mr16920025e9.1.1727859817534; Wed, 02 Oct 2024 02:03:37 -0700 (PDT) Received: from serenity.mandelbit.com ([2001:67c:2fbc:1:da6e:ecd8:2234:c32e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd56e8822sm13602320f8f.50.2024.10.02.02.03.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 02:03:37 -0700 (PDT) From: Antonio Quartulli Date: Wed, 02 Oct 2024 11:02:31 +0200 Subject: [PATCH net-next v8 17/24] 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: <20241002-b4-ovpn-v8-17-37ceffcffbde@openvpn.net> References: <20241002-b4-ovpn-v8-0-37ceffcffbde@openvpn.net> In-Reply-To: <20241002-b4-ovpn-v8-0-37ceffcffbde@openvpn.net> To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Donald Hunter , Antonio Quartulli , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, sd@queasysnail.net, ryazanov.s.a@gmail.com 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=em86kif804PfCNBmcFWnuObwa9l8Vt83cqY4INjENwo=; b=owEBbQGS/pANAwAIAQtw5TqgONWHAcsmYgBm/QxSiIvZ1T7l6cNYuhG2aSBM1H2D74AI73/f7 FoyNbdLNvuJATMEAAEIAB0WIQSZq9xs+NQS5N5fwPwLcOU6oDjVhwUCZv0MUgAKCRALcOU6oDjV hxk9B/9/NHMXXWFPR1PVGYzYsGDBAAgpL83X4pLra9JkQ2gXTuMrvCzVc3aqkQx84VXDCHuorFH C+ZSB1qMARRATAba7CrYfEwHi7DRKze4yXYY72NyOMgWD+XhhwOSF/bUPSIPOFprhtyphENHLiR 5evjJD3mRg6RNWJ12kwHYAIq+0xDvW/q9INN1aZcEWtUELz8h5xarg+AhugrtKm4tfxxG2I2O4Z sEYqzSPg8dWhXrbpoD+G837vVYavVgMW3dtxi5lYexcuyLc2cdeSJ5t6He9DeDtbHr3huaN97/Y Hin8iY/qh3/4FnjGBHKXoUmhSXif7v0ikdLFfkWFM8l8FayT 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 dfaa4c7c012215b3dcd451b9bd1d7ffce9b1291c..f9d8f1d1827fe67dc4b4e0bba41= a5b110bb90819 100644 --- a/drivers/net/ovpn/peer.c +++ b/drivers/net/ovpn/peer.c @@ -418,6 +418,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 e0d8d1255b837b7ddfdcedc5a56e7e747f13e2c5..6b66e169b33510a794f8f43dff7= 57f0357e3e5de 100644 --- a/drivers/net/ovpn/peer.h +++ b/drivers/net/ovpn/peer.h @@ -159,4 +159,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