From: Yonghong Song <yhs@fb.com>
To: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>,
Martin KaFai Lau <kafai@fb.com>
Subject: [PATCH bpf-next v5 07/15] net: bpf: add bpf_seq_afinfo in udp_iter_state
Date: Tue, 23 Jun 2020 16:08:12 -0700 [thread overview]
Message-ID: <20200623230812.3988347-1-yhs@fb.com> (raw)
In-Reply-To: <20200623230803.3987674-1-yhs@fb.com>
Similar to tcp_iter_state, a new field bpf_seq_afinfo is
added to udp_iter_state to provide bpf udp iterator
afinfo.
This does not change /proc/net/{udp, udp6} behavior. But
it enables bpf iterator to avoid get afinfo from PDE_DATA
and iterate through all udp and udp6 sockets in one pass.
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Yonghong Song <yhs@fb.com>
---
include/net/udp.h | 1 +
net/ipv4/udp.c | 28 +++++++++++++++++++++++-----
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/include/net/udp.h b/include/net/udp.h
index a8fa6c0c6ded..67c8b7368845 100644
--- a/include/net/udp.h
+++ b/include/net/udp.h
@@ -440,6 +440,7 @@ 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 1b7ebbcae497..90355301b266 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -2826,10 +2826,15 @@ EXPORT_SYMBOL(udp_prot);
static struct sock *udp_get_first(struct seq_file *seq, int start)
{
struct sock *sk;
- struct udp_seq_afinfo *afinfo = PDE_DATA(file_inode(seq->file));
+ struct udp_seq_afinfo *afinfo;
struct udp_iter_state *state = seq->private;
struct net *net = seq_file_net(seq);
+ if (state->bpf_seq_afinfo)
+ afinfo = state->bpf_seq_afinfo;
+ else
+ afinfo = PDE_DATA(file_inode(seq->file));
+
for (state->bucket = start; state->bucket <= afinfo->udp_table->mask;
++state->bucket) {
struct udp_hslot *hslot = &afinfo->udp_table->hash[state->bucket];
@@ -2841,7 +2846,8 @@ static struct sock *udp_get_first(struct seq_file *seq, int start)
sk_for_each(sk, &hslot->head) {
if (!net_eq(sock_net(sk), net))
continue;
- if (sk->sk_family == afinfo->family)
+ if (afinfo->family == AF_UNSPEC ||
+ sk->sk_family == afinfo->family)
goto found;
}
spin_unlock_bh(&hslot->lock);
@@ -2853,13 +2859,20 @@ static struct sock *udp_get_first(struct seq_file *seq, int start)
static struct sock *udp_get_next(struct seq_file *seq, struct sock *sk)
{
- struct udp_seq_afinfo *afinfo = PDE_DATA(file_inode(seq->file));
+ struct udp_seq_afinfo *afinfo;
struct udp_iter_state *state = seq->private;
struct net *net = seq_file_net(seq);
+ if (state->bpf_seq_afinfo)
+ afinfo = state->bpf_seq_afinfo;
+ else
+ afinfo = PDE_DATA(file_inode(seq->file));
+
do {
sk = sk_next(sk);
- } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != afinfo->family));
+ } while (sk && (!net_eq(sock_net(sk), net) ||
+ (afinfo->family != AF_UNSPEC &&
+ sk->sk_family != afinfo->family)));
if (!sk) {
if (state->bucket <= afinfo->udp_table->mask)
@@ -2904,9 +2917,14 @@ EXPORT_SYMBOL(udp_seq_next);
void udp_seq_stop(struct seq_file *seq, void *v)
{
- struct udp_seq_afinfo *afinfo = PDE_DATA(file_inode(seq->file));
+ struct udp_seq_afinfo *afinfo;
struct udp_iter_state *state = seq->private;
+ if (state->bpf_seq_afinfo)
+ afinfo = state->bpf_seq_afinfo;
+ else
+ afinfo = PDE_DATA(file_inode(seq->file));
+
if (state->bucket <= afinfo->udp_table->mask)
spin_unlock_bh(&afinfo->udp_table->hash[state->bucket].lock);
}
--
2.24.1
next prev parent reply other threads:[~2020-06-23 23:08 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-23 23:08 [PATCH bpf-next v5 00/15] implement bpf iterator for tcp and udp sockets Yonghong Song
2020-06-23 23:08 ` [PATCH bpf-next v5 01/15] net: bpf: add bpf_seq_afinfo in tcp_iter_state Yonghong Song
2020-06-23 23:08 ` [PATCH bpf-next v5 02/15] net: bpf: implement bpf iterator for tcp Yonghong Song
2020-06-23 23:08 ` [PATCH bpf-next v5 03/15] bpf: support 'X' in bpf_seq_printf() helper Yonghong Song
2020-06-23 23:08 ` [PATCH bpf-next v5 04/15] bpf: allow tracing programs to use bpf_jiffies64() helper Yonghong Song
2020-06-23 23:08 ` [PATCH bpf-next v5 05/15] bpf: add bpf_skc_to_tcp6_sock() helper Yonghong Song
2020-06-23 23:08 ` [PATCH bpf-next v5 06/15] bpf: add bpf_skc_to_{tcp,tcp_timewait,tcp_request}_sock() helpers Yonghong Song
2020-06-23 23:08 ` Yonghong Song [this message]
2020-06-23 23:08 ` [PATCH bpf-next v5 08/15] net: bpf: implement bpf iterator for udp Yonghong Song
2020-06-23 23:08 ` [PATCH bpf-next v5 09/15] bpf: add bpf_skc_to_udp6_sock() helper Yonghong Song
2020-06-23 23:08 ` [PATCH bpf-next v5 10/15] selftests/bpf: move newer bpf_iter_* type redefining to a new header file Yonghong Song
2020-06-23 23:08 ` [PATCH bpf-next v5 11/15] selftests/bpf: refactor some net macros to bpf_tracing_net.h Yonghong Song
2020-06-23 23:08 ` [PATCH bpf-next v5 12/15] selftests/bpf: add more common " Yonghong Song
2020-06-23 23:08 ` [PATCH bpf-next v5 13/15] selftests/bpf: implement sample tcp/tcp6 bpf_iter programs Yonghong Song
2020-06-23 23:08 ` [PATCH bpf-next v5 14/15] selftests/bpf: implement sample udp/udp6 " Yonghong Song
2020-06-23 23:08 ` [PATCH bpf-next v5 15/15] selftests/bpf: add tcp/udp iterator programs to selftests Yonghong Song
2020-06-25 1:45 ` [PATCH bpf-next v5 00/15] implement bpf iterator for tcp and udp sockets Alexei Starovoitov
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=20200623230812.3988347-1-yhs@fb.com \
--to=yhs@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kafai@fb.com \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).