diff options
author | Alexis Bauvin <abauvin@scaleway.com> | 2018-12-03 10:54:38 +0100 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-12-03 23:15:26 +0100 |
commit | da5095d052860baa7fe2932fb1209628dd3e3813 (patch) | |
tree | 1a06b12df1f9c1e536477a1bf2b7ff9f8b6e0755 /net/ipv4/udp_tunnel.c | |
parent | Merge branch 'mlxsw-fw_load_policy' (diff) | |
download | linux-da5095d052860baa7fe2932fb1209628dd3e3813.tar.xz linux-da5095d052860baa7fe2932fb1209628dd3e3813.zip |
udp_tunnel: add config option to bind to a device
UDP tunnel sockets are always opened unbound to a specific device. This
patch allow the socket to be bound on a custom device, which
incidentally makes UDP tunnels VRF-aware if binding to an l3mdev.
Signed-off-by: Alexis Bauvin <abauvin@scaleway.com>
Reviewed-by: Amine Kherbouche <akherbouche@scaleway.com>
Tested-by: Amine Kherbouche <akherbouche@scaleway.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/udp_tunnel.c')
-rw-r--r-- | net/ipv4/udp_tunnel.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/net/ipv4/udp_tunnel.c b/net/ipv4/udp_tunnel.c index d0c412fc56ad..be8b5b2157d8 100644 --- a/net/ipv4/udp_tunnel.c +++ b/net/ipv4/udp_tunnel.c @@ -20,6 +20,23 @@ int udp_sock_create4(struct net *net, struct udp_port_cfg *cfg, if (err < 0) goto error; + if (cfg->bind_ifindex) { + struct net_device *dev; + + dev = dev_get_by_index(net, cfg->bind_ifindex); + if (!dev) { + err = -ENODEV; + goto error; + } + + err = kernel_setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, + dev->name, strlen(dev->name) + 1); + dev_put(dev); + + if (err < 0) + goto error; + } + udp_addr.sin_family = AF_INET; udp_addr.sin_addr = cfg->local_ip; udp_addr.sin_port = cfg->local_udp_port; |