netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Gobert <richardbgobert@gmail.com>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, idosch@nvidia.com, razor@blackwall.org,
	amcohen@nvidia.com, petrm@nvidia.com, jbenc@redhat.com,
	b.galvani@gmail.com, bpoirier@nvidia.com, gavinl@nvidia.com,
	martin.lau@kernel.org, daniel@iogearbox.net,
	herbert@gondor.apana.org.au, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH net-next 1/2] net: vxlan: enable local address bind for vxlan sockets
Date: Thu, 22 Feb 2024 21:51:09 +0100	[thread overview]
Message-ID: <a4cd1adb-74d4-4eea-9f74-0d0ac3d79e44@gmail.com> (raw)
In-Reply-To: <df300a49-7811-4126-a56a-a77100c8841b@gmail.com>

This patch adds support for binding to a local address in vxlan sockets.
It achieves this by using vxlan_addr union to represent a local address
to bind to, and copying it to udp_port_cfg in vxlan_create_sock.

Signed-off-by: Richard Gobert <richardbgobert@gmail.com>
---
 drivers/net/vxlan/vxlan_core.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c
index 16106e088c63..b5f3f946ebcd 100644
--- a/drivers/net/vxlan/vxlan_core.c
+++ b/drivers/net/vxlan/vxlan_core.c
@@ -3479,8 +3479,9 @@ static const struct ethtool_ops vxlan_ethtool_ops = {
 	.get_link_ksettings	= vxlan_get_link_ksettings,
 };
 
-static struct socket *vxlan_create_sock(struct net *net, bool ipv6,
-					__be16 port, u32 flags, int ifindex)
+static struct socket *vxlan_create_sock(struct net *net, bool ipv6, __be16 port,
+					u32 flags, int ifindex,
+					union vxlan_addr addr)
 {
 	struct socket *sock;
 	struct udp_port_cfg udp_conf;
@@ -3493,8 +3494,15 @@ static struct socket *vxlan_create_sock(struct net *net, bool ipv6,
 		udp_conf.use_udp6_rx_checksums =
 		    !(flags & VXLAN_F_UDP_ZERO_CSUM6_RX);
 		udp_conf.ipv6_v6only = 1;
+		memcpy(&udp_conf.local_ip6.s6_addr32,
+		       &addr.sin6.sin6_addr.s6_addr32,
+		       sizeof(addr.sin6.sin6_addr.s6_addr32));
 	} else {
 		udp_conf.family = AF_INET;
+		udp_conf.local_ip.s_addr = addr.sin.sin_addr.s_addr;
+		memcpy(&udp_conf.local_ip.s_addr,
+		       &addr.sin.sin_addr.s_addr,
+		       sizeof(addr.sin.sin_addr.s_addr));
 	}
 
 	udp_conf.local_udp_port = port;
@@ -3512,7 +3520,8 @@ static struct socket *vxlan_create_sock(struct net *net, bool ipv6,
 /* Create new listen socket if needed */
 static struct vxlan_sock *vxlan_socket_create(struct net *net, bool ipv6,
 					      __be16 port, u32 flags,
-					      int ifindex)
+					      int ifindex,
+					      union vxlan_addr addr)
 {
 	struct vxlan_net *vn = net_generic(net, vxlan_net_id);
 	struct vxlan_sock *vs;
@@ -3527,7 +3536,7 @@ static struct vxlan_sock *vxlan_socket_create(struct net *net, bool ipv6,
 	for (h = 0; h < VNI_HASH_SIZE; ++h)
 		INIT_HLIST_HEAD(&vs->vni_list[h]);
 
-	sock = vxlan_create_sock(net, ipv6, port, flags, ifindex);
+	sock = vxlan_create_sock(net, ipv6, port, flags, ifindex, addr);
 	if (IS_ERR(sock)) {
 		kfree(vs);
 		return ERR_CAST(sock);
@@ -3591,7 +3600,7 @@ static int __vxlan_sock_add(struct vxlan_dev *vxlan, bool ipv6)
 	if (!vs)
 		vs = vxlan_socket_create(vxlan->net, ipv6,
 					 vxlan->cfg.dst_port, vxlan->cfg.flags,
-					 l3mdev_index);
+					 l3mdev_index, vxlan->cfg.saddr);
 	if (IS_ERR(vs))
 		return PTR_ERR(vs);
 #if IS_ENABLED(CONFIG_IPV6)
-- 
2.36.1

  reply	other threads:[~2024-02-22 20:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-22 20:48 [PATCH net-next 0/2] net: add local address bind support to vxlan and geneve Richard Gobert
2024-02-22 20:51 ` Richard Gobert [this message]
2024-02-23 17:49   ` [PATCH net-next 1/2] net: vxlan: enable local address bind for vxlan sockets kernel test robot
2024-02-24  5:58   ` kernel test robot
2024-02-22 20:53 ` [PATCH net-next 2/2] net: geneve: enable local address bind for geneve sockets Richard Gobert
2024-02-22 22:31   ` Eyal Birger
2024-02-27  9:02     ` Richard Gobert
2024-02-28 17:51       ` Eyal Birger
2024-02-24  9:01   ` kernel test robot
2024-02-24 10:06   ` Jiri Benc
2024-02-23 14:11 ` [PATCH net-next 0/2] net: add local address bind support to vxlan and geneve Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a4cd1adb-74d4-4eea-9f74-0d0ac3d79e44@gmail.com \
    --to=richardbgobert@gmail.com \
    --cc=amcohen@nvidia.com \
    --cc=b.galvani@gmail.com \
    --cc=bpoirier@nvidia.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gavinl@nvidia.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=idosch@nvidia.com \
    --cc=jbenc@redhat.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=petrm@nvidia.com \
    --cc=razor@blackwall.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).