Skip to content

Commit 7625d2e

Browse files
aditighagMartin KaFai Lau
authored andcommitted
bpf: udp: Encapsulate logic to get udp table
This is a preparatory commit that encapsulates the logic to get udp table in iterator inside udp_get_table_afinfo, and renames the function to `udp_get_table_seq` accordingly. Suggested-by: Martin KaFai Lau <martin.lau@kernel.org> Signed-off-by: Aditi Ghag <aditi.ghag@isovalent.com> Link: https://lore.kernel.org/r/20230519225157.760788-4-aditi.ghag@isovalent.com Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
1 parent f44b1c5 commit 7625d2e

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

net/ipv4/udp.c

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,26 +2998,27 @@ static bool seq_sk_match(struct seq_file *seq, const struct sock *sk)
29982998
net_eq(sock_net(sk), seq_file_net(seq)));
29992999
}
30003000

3001-
static struct udp_table *udp_get_table_afinfo(struct udp_seq_afinfo *afinfo,
3002-
struct net *net)
3001+
static struct udp_table *udp_get_table_seq(struct seq_file *seq,
3002+
struct net *net)
30033003
{
3004+
const struct udp_iter_state *state = seq->private;
3005+
const struct udp_seq_afinfo *afinfo;
3006+
3007+
if (state->bpf_seq_afinfo)
3008+
return net->ipv4.udp_table;
3009+
3010+
afinfo = pde_data(file_inode(seq->file));
30043011
return afinfo->udp_table ? : net->ipv4.udp_table;
30053012
}
30063013

30073014
static struct sock *udp_get_first(struct seq_file *seq, int start)
30083015
{
30093016
struct udp_iter_state *state = seq->private;
30103017
struct net *net = seq_file_net(seq);
3011-
struct udp_seq_afinfo *afinfo;
30123018
struct udp_table *udptable;
30133019
struct sock *sk;
30143020

3015-
if (state->bpf_seq_afinfo)
3016-
afinfo = state->bpf_seq_afinfo;
3017-
else
3018-
afinfo = pde_data(file_inode(seq->file));
3019-
3020-
udptable = udp_get_table_afinfo(afinfo, net);
3021+
udptable = udp_get_table_seq(seq, net);
30213022

30223023
for (state->bucket = start; state->bucket <= udptable->mask;
30233024
++state->bucket) {
@@ -3042,20 +3043,14 @@ static struct sock *udp_get_next(struct seq_file *seq, struct sock *sk)
30423043
{
30433044
struct udp_iter_state *state = seq->private;
30443045
struct net *net = seq_file_net(seq);
3045-
struct udp_seq_afinfo *afinfo;
30463046
struct udp_table *udptable;
30473047

3048-
if (state->bpf_seq_afinfo)
3049-
afinfo = state->bpf_seq_afinfo;
3050-
else
3051-
afinfo = pde_data(file_inode(seq->file));
3052-
30533048
do {
30543049
sk = sk_next(sk);
30553050
} while (sk && !seq_sk_match(seq, sk));
30563051

30573052
if (!sk) {
3058-
udptable = udp_get_table_afinfo(afinfo, net);
3053+
udptable = udp_get_table_seq(seq, net);
30593054

30603055
if (state->bucket <= udptable->mask)
30613056
spin_unlock_bh(&udptable->hash[state->bucket].lock);
@@ -3101,15 +3096,9 @@ EXPORT_SYMBOL(udp_seq_next);
31013096
void udp_seq_stop(struct seq_file *seq, void *v)
31023097
{
31033098
struct udp_iter_state *state = seq->private;
3104-
struct udp_seq_afinfo *afinfo;
31053099
struct udp_table *udptable;
31063100

3107-
if (state->bpf_seq_afinfo)
3108-
afinfo = state->bpf_seq_afinfo;
3109-
else
3110-
afinfo = pde_data(file_inode(seq->file));
3111-
3112-
udptable = udp_get_table_afinfo(afinfo, seq_file_net(seq));
3101+
udptable = udp_get_table_seq(seq, seq_file_net(seq));
31133102

31143103
if (state->bucket <= udptable->mask)
31153104
spin_unlock_bh(&udptable->hash[state->bucket].lock);

0 commit comments

Comments
 (0)