diff options
author | Eric Dumazet <edumazet@google.com> | 2021-02-10 06:41:44 -0800 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2021-02-11 14:10:07 -0800 |
commit | 3d368ab87cf6681f928de1ddf804d69600671bb2 (patch) | |
tree | 87071c9aa3fd53cdbadadd99deaefec3100d270b /net/core/filter.c | |
parent | 06e56697bd98d33ab101920bb5380fcd7efed4df (diff) | |
download | linux-stable-3d368ab87cf6681f928de1ddf804d69600671bb2.tar.gz linux-stable-3d368ab87cf6681f928de1ddf804d69600671bb2.tar.bz2 linux-stable-3d368ab87cf6681f928de1ddf804d69600671bb2.zip |
net: initialize net->net_cookie at netns setup
It is simpler to make net->net_cookie a plain u64
written once in setup_net() instead of looping
and using atomic64 helpers.
Lorenz Bauer wants to add SO_NETNS_COOKIE socket option
and this patch would makes his patch series simpler.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Lorenz Bauer <lmb@cloudflare.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Tested-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/filter.c')
-rw-r--r-- | net/core/filter.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/net/core/filter.c b/net/core/filter.c index 9ab94e90d660..74bd401bf483 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4645,11 +4645,9 @@ static const struct bpf_func_proto bpf_get_socket_cookie_sock_ops_proto = { static u64 __bpf_get_netns_cookie(struct sock *sk) { -#ifdef CONFIG_NET_NS - return __net_gen_cookie(sk ? sk->sk_net.net : &init_net); -#else - return 0; -#endif + const struct net *net = sk ? sock_net(sk) : &init_net; + + return net->net_cookie; } BPF_CALL_1(bpf_get_netns_cookie_sock, struct sock *, ctx) |