mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 14:53:58 -04:00
sock: Introduce sk->sk_prot->psock_update_sk_prot()
Currently sockmap calls into each protocol to update the struct proto and replace it. This certainly won't work when the protocol is implemented as a module, for example, AF_UNIX. Introduce a new ops sk->sk_prot->psock_update_sk_prot(), so each protocol can implement its own way to replace the struct proto. This also helps get rid of symbol dependencies on CONFIG_INET. Signed-off-by: Cong Wang <cong.wang@bytedance.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20210331023237.41094-11-xiyou.wangcong@gmail.com
This commit is contained in:
committed by
Alexei Starovoitov
parent
a7ba4558e6
commit
8a59f9d1e3
@@ -41,12 +41,23 @@ static int __init udp_bpf_v4_build_proto(void)
|
||||
}
|
||||
core_initcall(udp_bpf_v4_build_proto);
|
||||
|
||||
struct proto *udp_bpf_get_proto(struct sock *sk, struct sk_psock *psock)
|
||||
int udp_bpf_update_proto(struct sock *sk, bool restore)
|
||||
{
|
||||
int family = sk->sk_family == AF_INET ? UDP_BPF_IPV4 : UDP_BPF_IPV6;
|
||||
struct sk_psock *psock = sk_psock(sk);
|
||||
|
||||
if (restore) {
|
||||
sk->sk_write_space = psock->saved_write_space;
|
||||
/* Pairs with lockless read in sk_clone_lock() */
|
||||
WRITE_ONCE(sk->sk_prot, psock->sk_proto);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sk->sk_family == AF_INET6)
|
||||
udp_bpf_check_v6_needs_rebuild(psock->sk_proto);
|
||||
|
||||
return &udp_bpf_prots[family];
|
||||
/* Pairs with lockless read in sk_clone_lock() */
|
||||
WRITE_ONCE(sk->sk_prot, &udp_bpf_prots[family]);
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(udp_bpf_update_proto);
|
||||
|
||||
Reference in New Issue
Block a user