Re: [PATCH bpf-next v2 2/4] net: Allow iterating sockmap and sockhash

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 9/2/20 6:31 PM, Andrii Nakryiko wrote:
On Tue, Sep 1, 2020 at 3:33 AM Lorenz Bauer <lmb@xxxxxxxxxxxxxx> wrote:

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.

Signed-off-by: Lorenz Bauer <lmb@xxxxxxxxxxxxxx>
---
  net/core/sock_map.c | 283 ++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 283 insertions(+)

diff --git a/net/core/sock_map.c b/net/core/sock_map.c
index ffdf94a30c87..4767f9df2b8b 100644
--- a/net/core/sock_map.c
+++ b/net/core/sock_map.c
@@ -703,6 +703,114 @@ const struct bpf_func_proto bpf_msg_redirect_map_proto = {
         .arg4_type      = ARG_ANYTHING,
  };

+struct sock_map_seq_info {
+       struct bpf_map *map;
+       struct sock *sk;
+       u32 index;
+};
+
+struct bpf_iter__sockmap {
+       __bpf_md_ptr(struct bpf_iter_meta *, meta);
+       __bpf_md_ptr(struct bpf_map *, map);
+       __bpf_md_ptr(void *, key);

For sockhash, the key can be of an arbitrary size, right? Should the
key_size be part of bpf_iter__sockmap then?

key_size is available from map->key_size. map->value_size is
for value size.


+       __bpf_md_ptr(struct bpf_sock *, sk);
+};
+

[...]




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux