diff options
author | Jordan Rife <jordan@jrife.io> | 2025-05-02 09:15:22 -0700 |
---|---|---|
committer | Martin KaFai Lau <martin.lau@kernel.org> | 2025-05-02 10:54:38 -0700 |
commit | 3fae8959cda5d9d90ea1554385514d71e9103b02 (patch) | |
tree | fd976fc8a1fcced8459ad2b05f1a479e2feff346 | |
parent | 66d454e99d71857faf249486912e381ec83760b4 (diff) |
bpf: udp: Get rid of st_bucket_done
Get rid of the st_bucket_done field to simplify UDP iterator state and
logic. Before, st_bucket_done could be false if bpf_iter_udp_batch
returned a partial batch; however, with the last patch ("bpf: udp: Make
sure iter->batch always contains a full bucket snapshot"),
st_bucket_done == true is equivalent to iter->cur_sk == iter->end_sk.
Signed-off-by: Jordan Rife <jordan@jrife.io>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
-rw-r--r-- | net/ipv4/udp.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 426a8b7c5cde..f2740802ee86 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -3420,7 +3420,6 @@ struct bpf_udp_iter_state { unsigned int max_sk; int offset; struct sock **batch; - bool st_bucket_done; }; static int bpf_iter_udp_realloc_batch(struct bpf_udp_iter_state *iter, @@ -3441,7 +3440,7 @@ static struct sock *bpf_iter_udp_batch(struct seq_file *seq) resume_offset = iter->offset; /* The current batch is done, so advance the bucket. */ - if (iter->st_bucket_done) + if (iter->cur_sk == iter->end_sk) state->bucket++; udptable = udp_get_table_seq(seq, net); @@ -3456,7 +3455,6 @@ again: */ iter->cur_sk = 0; iter->end_sk = 0; - iter->st_bucket_done = true; batch_sks = 0; for (; state->bucket <= udptable->mask; state->bucket++) { @@ -3619,8 +3617,10 @@ unlock: static void bpf_iter_udp_put_batch(struct bpf_udp_iter_state *iter) { - while (iter->cur_sk < iter->end_sk) - sock_put(iter->batch[iter->cur_sk++]); + unsigned int cur_sk = iter->cur_sk; + + while (cur_sk < iter->end_sk) + sock_put(iter->batch[cur_sk++]); } static void bpf_iter_udp_seq_stop(struct seq_file *seq, void *v) @@ -3636,10 +3636,8 @@ static void bpf_iter_udp_seq_stop(struct seq_file *seq, void *v) (void)udp_prog_seq_show(prog, &meta, v, 0, 0); } - if (iter->cur_sk < iter->end_sk) { + if (iter->cur_sk < iter->end_sk) bpf_iter_udp_put_batch(iter); - iter->st_bucket_done = false; - } } static const struct seq_operations bpf_iter_udp_seq_ops = { @@ -3925,6 +3923,8 @@ static int bpf_iter_init_udp(void *priv_data, struct bpf_iter_aux_info *aux) if (ret) bpf_iter_fini_seq_net(priv_data); + iter->state.bucket = -1; + return ret; } |