mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
net: Make locking in sock_bindtoindex optional
The sock_bindtoindex intended for kernel wide usage however it will lock the socket regardless of the context. This modification relax this behavior optionally: locking the socket will be optional by calling the sock_bindtoindex with lock_sk = true. The modification applied to all users of the sock_bindtoindex. Signed-off-by: Ferenc Fejes <fejes@inf.elte.hu> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/bee6355da40d9e991b2f2d12b67d55ebb5f5b207.1590871065.git.fejes@inf.elte.hu
This commit is contained in:
parent
bb2359f4db
commit
8ea204c2b6
4 changed files with 9 additions and 7 deletions
|
@ -2690,7 +2690,7 @@ static inline bool sk_dev_equal_l3scope(struct sock *sk, int dif)
|
||||||
|
|
||||||
void sock_def_readable(struct sock *sk);
|
void sock_def_readable(struct sock *sk);
|
||||||
|
|
||||||
int sock_bindtoindex(struct sock *sk, int ifindex);
|
int sock_bindtoindex(struct sock *sk, int ifindex, bool lock_sk);
|
||||||
void sock_enable_timestamps(struct sock *sk);
|
void sock_enable_timestamps(struct sock *sk);
|
||||||
void sock_no_linger(struct sock *sk);
|
void sock_no_linger(struct sock *sk);
|
||||||
void sock_set_keepalive(struct sock *sk);
|
void sock_set_keepalive(struct sock *sk);
|
||||||
|
|
|
@ -594,12 +594,14 @@ out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sock_bindtoindex(struct sock *sk, int ifindex)
|
int sock_bindtoindex(struct sock *sk, int ifindex, bool lock_sk)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (lock_sk)
|
||||||
lock_sock(sk);
|
lock_sock(sk);
|
||||||
ret = sock_bindtoindex_locked(sk, ifindex);
|
ret = sock_bindtoindex_locked(sk, ifindex);
|
||||||
|
if (lock_sk)
|
||||||
release_sock(sk);
|
release_sock(sk);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -646,7 +648,7 @@ static int sock_setbindtodevice(struct sock *sk, char __user *optval,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sock_bindtoindex(sk, index);
|
return sock_bindtoindex(sk, index, true);
|
||||||
out:
|
out:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ int udp_sock_create4(struct net *net, struct udp_port_cfg *cfg,
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (cfg->bind_ifindex) {
|
if (cfg->bind_ifindex) {
|
||||||
err = sock_bindtoindex(sock->sk, cfg->bind_ifindex);
|
err = sock_bindtoindex(sock->sk, cfg->bind_ifindex, true);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ int udp_sock_create6(struct net *net, struct udp_port_cfg *cfg,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (cfg->bind_ifindex) {
|
if (cfg->bind_ifindex) {
|
||||||
err = sock_bindtoindex(sock->sk, cfg->bind_ifindex);
|
err = sock_bindtoindex(sock->sk, cfg->bind_ifindex, true);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue