net: Allow iterating sockmap and sockhash
authorLorenz Bauer <lmb@cloudflare.com>
Wed, 9 Sep 2020 16:27:11 +0000 (17:27 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 10 Sep 2020 19:31:55 +0000 (12:31 -0700)
commit0365351524d7560d8ed7a42801a15252c6c56f41
tree7fd76c80163d4dc5a5a439e3c4ce7603c6dd0965
parent654785a1afe1b1428106c322c7ea650e3f8d29e9
net: Allow iterating sockmap and sockhash

Add bpf_iter support for sockmap / sockhash, based on the bpf_sk_storage and
hashtable implementation. sockmap and sockhash share the same iteration
context: a pointer to an arbitrary key and a pointer to a socket. Both
pointers may be NULL, and so BPF has to perform a NULL check before accessing
them. Technically it's not possible for sockhash iteration to yield a NULL
socket, but we ignore this to be able to use a single iteration point.

Iteration will visit all keys that remain unmodified during the lifetime of
the iterator. It may or may not visit newly added ones.

Switch from using rcu_dereference_raw to plain rcu_dereference, so we gain
another guard rail if CONFIG_PROVE_RCU is enabled.

Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20200909162712.221874-3-lmb@cloudflare.com
net/core/sock_map.c