diff mbox series

[3/3] net/ipv6/udp_tunnel: prefer SO_BINDTOIF over SO_BINDTODEVICE

Message ID 20190110142529.14315-3-dh.herrmann@gmail.com
State Changes Requested
Delegated to: David Miller
Headers show
Series [1/3] net: introduce SO_BINDTOIF sockopt | expand

Commit Message

David Herrmann Jan. 10, 2019, 2:25 p.m. UTC
The udp-tunnel setup allows binding sockets to a network device. Prefer
the new SO_BINDTOIF to avoid temporarily resolving the device-name just
to look it up in the ioctl again.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
---
 net/ipv6/ip6_udp_tunnel.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

Comments

Tom Gundersen Jan. 10, 2019, 2:41 p.m. UTC | #1
On Thu, Jan 10, 2019 at 3:25 PM David Herrmann <dh.herrmann@gmail.com> wrote:
>
> The udp-tunnel setup allows binding sockets to a network device. Prefer
> the new SO_BINDTOIF to avoid temporarily resolving the device-name just
> to look it up in the ioctl again.
>
> Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Tom Gundersen <teg@jklm.no>
> ---
>  net/ipv6/ip6_udp_tunnel.c | 15 +++------------
>  1 file changed, 3 insertions(+), 12 deletions(-)
>
> diff --git a/net/ipv6/ip6_udp_tunnel.c b/net/ipv6/ip6_udp_tunnel.c
> index ad1a9ccd4b44..f5fd4e05ae81 100644
> --- a/net/ipv6/ip6_udp_tunnel.c
> +++ b/net/ipv6/ip6_udp_tunnel.c
> @@ -32,18 +32,9 @@ int udp_sock_create6(struct net *net, struct udp_port_cfg *cfg,
>                         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);
> -
> +               err = kernel_setsockopt(sock, SOL_SOCKET, SO_BINDTOIF,
> +                                       (void *)&cfg->bind_ifindex,
> +                                       sizeof(cfg->bind_ifindex));
>                 if (err < 0)
>                         goto error;
>         }
> --
> 2.20.1
>
diff mbox series

Patch

diff --git a/net/ipv6/ip6_udp_tunnel.c b/net/ipv6/ip6_udp_tunnel.c
index ad1a9ccd4b44..f5fd4e05ae81 100644
--- a/net/ipv6/ip6_udp_tunnel.c
+++ b/net/ipv6/ip6_udp_tunnel.c
@@ -32,18 +32,9 @@  int udp_sock_create6(struct net *net, struct udp_port_cfg *cfg,
 			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);
-
+		err = kernel_setsockopt(sock, SOL_SOCKET, SO_BINDTOIF,
+					(void *)&cfg->bind_ifindex,
+					sizeof(cfg->bind_ifindex));
 		if (err < 0)
 			goto error;
 	}