diff options
author | Alexei Starovoitov <ast@kernel.org> | 2020-03-27 19:40:39 -0700 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2020-03-27 19:40:43 -0700 |
commit | 2cf69d3fa50e15fd628c512a7d34ad759ac476cb (patch) | |
tree | 32f01659caf64cb51f6e92cb178eb2dde502a906 /net/core/net_namespace.c | |
parent | f54a5bba120398e4d404e9553e6b92e6822eade0 (diff) | |
parent | 23599ada0e9173e92d3cc26254b1e18e542c469d (diff) |
Merge branch 'cgroup-helpers'
Daniel Borkmann says:
====================
This adds various straight-forward helper improvements and additions to BPF
cgroup based connect(), sendmsg(), recvmsg() and bind-related hooks which
would allow to implement more fine-grained policies and improve current load
balancer limitations we're seeing. For details please see individual patches.
I've tested them on Kubernetes & Cilium and also added selftests for the small
verifier extension. Thanks!
====================
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'net/core/net_namespace.c')
-rw-r--r-- | net/core/net_namespace.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 757cc1d084e7..190ca66a383b 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -69,6 +69,20 @@ EXPORT_SYMBOL_GPL(pernet_ops_rwsem); static unsigned int max_gen_ptrs = INITIAL_NET_GEN_PTRS; +static atomic64_t cookie_gen; + +u64 net_gen_cookie(struct net *net) +{ + while (1) { + u64 res = atomic64_read(&net->net_cookie); + + if (res) + return res; + res = atomic64_inc_return(&cookie_gen); + atomic64_cmpxchg(&net->net_cookie, 0, res); + } +} + static struct net_generic *net_alloc_generic(void) { struct net_generic *ng; @@ -1087,6 +1101,7 @@ static int __init net_ns_init(void) panic("Could not allocate generic netns"); rcu_assign_pointer(init_net.gen, ng); + net_gen_cookie(&init_net); down_write(&pernet_ops_rwsem); if (setup_net(&init_net, &init_user_ns)) |