summaryrefslogtreecommitdiffhomepage
path: root/src/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/socket.c')
-rw-r--r--src/socket.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/socket.c b/src/socket.c
index 8ef44c1..75780b0 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -345,7 +345,7 @@ static void set_sock_opts(struct socket *sock)
sk_set_memalloc(sock->sk);
}
-int wg_socket_init(struct wg_device *wg, u16 port)
+int wg_socket_init(struct wg_device *wg, u16 port, u32 socketdev)
{
struct net *net;
int ret;
@@ -359,7 +359,8 @@ int wg_socket_init(struct wg_device *wg, u16 port)
.family = AF_INET,
.local_ip.s_addr = htonl(INADDR_ANY),
.local_udp_port = htons(port),
- .use_udp_checksums = true
+ .use_udp_checksums = true,
+ .bind_ifindex = socketdev,
};
#if IS_ENABLED(CONFIG_IPV6)
int retries = 0;
@@ -368,20 +369,11 @@ int wg_socket_init(struct wg_device *wg, u16 port)
.local_ip6 = IN6ADDR_ANY_INIT,
.use_udp6_tx_checksums = true,
.use_udp6_rx_checksums = true,
- .ipv6_v6only = true
+ .ipv6_v6only = true,
+ .bind_ifindex = socketdev,
};
- if (wg->socketdev_index > 0) {
- port6.bind_ifindex = wg->socketdev_index;
- } else {
- port6.bind_ifindex = 0;
- }
#endif
- if (wg->socketdev_index > 0) {
- port4.bind_ifindex = wg->socketdev_index;
- } else {
- port4.bind_ifindex = 0;
- }
rcu_read_lock();
net = rcu_dereference(wg->creating_net);
net = net ? maybe_get_net(net) : NULL;
@@ -437,8 +429,10 @@ void wg_socket_reinit(struct wg_device *wg, struct sock *new4,
lockdep_is_held(&wg->socket_update_lock));
rcu_assign_pointer(wg->sock4, new4);
rcu_assign_pointer(wg->sock6, new6);
- if (new4)
+ if (new4) {
wg->incoming_port = ntohs(inet_sk(new4)->inet_sport);
+ wg->socketdev_index = new4->sk_bound_dev_if;
+ }
mutex_unlock(&wg->socket_update_lock);
synchronize_net();
sock_free(old4);