Skip to content

Commit 49b4994

Browse files
David Herrmanndavem330
authored andcommitted
net/ipv6/udp_tunnel: prefer SO_BINDTOIFINDEX over SO_BINDTODEVICE
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 <[email protected]> Signed-off-by: David Herrmann <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2eadee7 commit 49b4994

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

net/ipv6/ip6_udp_tunnel.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,9 @@ int udp_sock_create6(struct net *net, struct udp_port_cfg *cfg,
3232
goto error;
3333
}
3434
if (cfg->bind_ifindex) {
35-
struct net_device *dev;
36-
37-
dev = dev_get_by_index(net, cfg->bind_ifindex);
38-
if (!dev) {
39-
err = -ENODEV;
40-
goto error;
41-
}
42-
43-
err = kernel_setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE,
44-
dev->name, strlen(dev->name) + 1);
45-
dev_put(dev);
46-
35+
err = kernel_setsockopt(sock, SOL_SOCKET, SO_BINDTOIFINDEX,
36+
(void *)&cfg->bind_ifindex,
37+
sizeof(cfg->bind_ifindex));
4738
if (err < 0)
4839
goto error;
4940
}

0 commit comments

Comments
 (0)