All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aditi Ghag <aditi.ghag@isovalent.com>
To: bpf@vger.kernel.org
Cc: kafai@fb.com, sdf@google.com, aditi.ghag@isovalent.com,
	Martin KaFai Lau <martin.lau@kernel.org>
Subject: [PATCH v9 bpf-next 4/9] udp: seq_file: Remove bpf_seq_afinfo from udp_iter_state
Date: Fri, 19 May 2023 22:51:52 +0000	[thread overview]
Message-ID: <20230519225157.760788-5-aditi.ghag@isovalent.com> (raw)
In-Reply-To: <20230519225157.760788-1-aditi.ghag@isovalent.com>

This is a preparatory commit to remove the field. The field was
previously shared between proc fs and BPF UDP socket iterators. As the
follow-up commits will decouple the implementation for the iterators,
remove the field. As for BPF socket iterator, filtering of sockets is
exepected to be done in BPF programs.

Suggested-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Aditi Ghag <aditi.ghag@isovalent.com>
---
 include/net/udp.h |  1 -
 net/ipv4/udp.c    | 27 +++++++--------------------
 2 files changed, 7 insertions(+), 21 deletions(-)

diff --git a/include/net/udp.h b/include/net/udp.h
index de4b528522bb..5cad44318d71 100644
--- a/include/net/udp.h
+++ b/include/net/udp.h
@@ -437,7 +437,6 @@ struct udp_seq_afinfo {
 struct udp_iter_state {
 	struct seq_net_private  p;
 	int			bucket;
-	struct udp_seq_afinfo	*bpf_seq_afinfo;
 };
 
 void *udp_seq_start(struct seq_file *seq, loff_t *pos);
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index c426ebafeb13..289ef05b5c15 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -2993,14 +2993,18 @@ static bool seq_sk_match(struct seq_file *seq, const struct sock *sk)
 		net_eq(sock_net(sk), seq_file_net(seq)));
 }
 
+#ifdef CONFIG_BPF_SYSCALL
+static const struct seq_operations bpf_iter_udp_seq_ops;
+#endif
 static struct udp_table *udp_get_table_seq(struct seq_file *seq,
 					   struct net *net)
 {
-	const struct udp_iter_state *state = seq->private;
 	const struct udp_seq_afinfo *afinfo;
 
-	if (state->bpf_seq_afinfo)
+#ifdef CONFIG_BPF_SYSCALL
+	if (seq->op == &bpf_iter_udp_seq_ops)
 		return net->ipv4.udp_table;
+#endif
 
 	afinfo = pde_data(file_inode(seq->file));
 	return afinfo->udp_table ? : net->ipv4.udp_table;
@@ -3424,28 +3428,11 @@ DEFINE_BPF_ITER_FUNC(udp, struct bpf_iter_meta *meta,
 
 static int bpf_iter_init_udp(void *priv_data, struct bpf_iter_aux_info *aux)
 {
-	struct udp_iter_state *st = priv_data;
-	struct udp_seq_afinfo *afinfo;
-	int ret;
-
-	afinfo = kmalloc(sizeof(*afinfo), GFP_USER | __GFP_NOWARN);
-	if (!afinfo)
-		return -ENOMEM;
-
-	afinfo->family = AF_UNSPEC;
-	afinfo->udp_table = NULL;
-	st->bpf_seq_afinfo = afinfo;
-	ret = bpf_iter_init_seq_net(priv_data, aux);
-	if (ret)
-		kfree(afinfo);
-	return ret;
+	return bpf_iter_init_seq_net(priv_data, aux);
 }
 
 static void bpf_iter_fini_udp(void *priv_data)
 {
-	struct udp_iter_state *st = priv_data;
-
-	kfree(st->bpf_seq_afinfo);
 	bpf_iter_fini_seq_net(priv_data);
 }
 
-- 
2.34.1


  parent reply	other threads:[~2023-05-19 22:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-19 22:51 [PATCH v9 bpf-next 0/9] bpf: Add socket destroy capability Aditi Ghag
2023-05-19 22:51 ` [PATCH v9 bpf-next 1/9] bpf: tcp: Avoid taking fast sock lock in iterator Aditi Ghag
2023-05-19 22:51 ` [PATCH v9 bpf-next 2/9] udp: seq_file: Helper function to match socket attributes Aditi Ghag
2023-05-19 22:51 ` [PATCH v9 bpf-next 3/9] bpf: udp: Encapsulate logic to get udp table Aditi Ghag
2023-05-19 22:51 ` Aditi Ghag [this message]
2023-05-19 22:51 ` [PATCH v9 bpf-next 5/9] bpf: udp: Implement batching for sockets iterator Aditi Ghag
2023-09-20  0:38   ` Martin KaFai Lau
2023-09-20 17:16     ` Aditi Ghag
2023-09-25 23:34     ` Aditi Ghag
2023-09-26  5:02       ` Martin KaFai Lau
2023-09-26 16:07         ` Aditi Ghag
2023-10-24 22:50           ` Aditi Ghag
2023-09-26  5:07       ` Martin KaFai Lau
2023-05-19 22:51 ` [PATCH v9 bpf-next 6/9] bpf: Add kfunc filter function to 'struct btf_kfunc_id_set' Aditi Ghag
2023-05-19 22:51 ` [PATCH v9 bpf-next 7/9] bpf: Add bpf_sock_destroy kfunc Aditi Ghag
2023-05-19 22:51 ` [PATCH v9 bpf-next 8/9] selftests/bpf: Add helper to get port using getsockname Aditi Ghag
2023-05-19 22:51 ` [PATCH v9 bpf-next 9/9] selftests/bpf: Test bpf_sock_destroy Aditi Ghag
2023-05-20  6:00 ` [PATCH v9 bpf-next 0/9] bpf: Add socket destroy capability patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230519225157.760788-5-aditi.ghag@isovalent.com \
    --to=aditi.ghag@isovalent.com \
    --cc=bpf@vger.kernel.org \
    --cc=kafai@fb.com \
    --cc=martin.lau@kernel.org \
    --cc=sdf@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.