Skip to content

Commit

Permalink
net/ipv6/udp_tunnel: prefer SO_BINDTOIFINDEX over SO_BINDTODEVICE
Browse files Browse the repository at this point in the history
The udp-tunnel setup allows binding sockets to a network device. Prefer
the new SO_BINDTOIFINDEX to avoid temporarily resolving the device-name
just to look it up in the ioctl again.

Reviewed-by: Tom Gundersen <teg@jklm.no>
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David Herrmann authored and David S. Miller committed Jan 17, 2019
1 parent 2eadee7 commit 49b4994
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions net/ipv6/ip6_udp_tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_BINDTOIFINDEX,
(void *)&cfg->bind_ifindex,
sizeof(cfg->bind_ifindex));
if (err < 0)
goto error;
}
Expand Down

0 comments on commit 49b4994

Please sign in to comment.