e4d9c23207
A handful of samples and selftests fail to build on s390, because after commit 0ebeea8ca8a4 ("bpf: Restrict bpf_probe_read{, str}() only to archs where they work") bpf_probe_read is not available anymore. Fix by using bpf_probe_read_kernel. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200720114806.88823-1-iii@linux.ibm.com
65 lines
1.7 KiB
C
65 lines
1.7 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright (c) 2020 Facebook */
|
|
#include "bpf_iter.h"
|
|
#include "bpf_tracing_net.h"
|
|
#include <bpf/bpf_helpers.h>
|
|
#include <bpf/bpf_tracing.h>
|
|
|
|
char _license[] SEC("license") = "GPL";
|
|
|
|
static __attribute__((noinline)) struct inode *SOCK_INODE(struct socket *socket)
|
|
{
|
|
return &container_of(socket, struct socket_alloc, socket)->vfs_inode;
|
|
}
|
|
|
|
SEC("iter/netlink")
|
|
int dump_netlink(struct bpf_iter__netlink *ctx)
|
|
{
|
|
struct seq_file *seq = ctx->meta->seq;
|
|
struct netlink_sock *nlk = ctx->sk;
|
|
unsigned long group, ino;
|
|
struct inode *inode;
|
|
struct socket *sk;
|
|
struct sock *s;
|
|
|
|
if (nlk == (void *)0)
|
|
return 0;
|
|
|
|
if (ctx->meta->seq_num == 0)
|
|
BPF_SEQ_PRINTF(seq, "sk Eth Pid Groups "
|
|
"Rmem Wmem Dump Locks Drops "
|
|
"Inode\n");
|
|
|
|
s = &nlk->sk;
|
|
BPF_SEQ_PRINTF(seq, "%pK %-3d ", s, s->sk_protocol);
|
|
|
|
if (!nlk->groups) {
|
|
group = 0;
|
|
} else {
|
|
/* FIXME: temporary use bpf_probe_read_kernel here, needs
|
|
* verifier support to do direct access.
|
|
*/
|
|
bpf_probe_read_kernel(&group, sizeof(group), &nlk->groups[0]);
|
|
}
|
|
BPF_SEQ_PRINTF(seq, "%-10u %08x %-8d %-8d %-5d %-8d ",
|
|
nlk->portid, (u32)group,
|
|
s->sk_rmem_alloc.counter,
|
|
s->sk_wmem_alloc.refs.counter - 1,
|
|
nlk->cb_running, s->sk_refcnt.refs.counter);
|
|
|
|
sk = s->sk_socket;
|
|
if (!sk) {
|
|
ino = 0;
|
|
} else {
|
|
/* FIXME: container_of inside SOCK_INODE has a forced
|
|
* type conversion, and direct access cannot be used
|
|
* with current verifier.
|
|
*/
|
|
inode = SOCK_INODE(sk);
|
|
bpf_probe_read_kernel(&ino, sizeof(ino), &inode->i_ino);
|
|
}
|
|
BPF_SEQ_PRINTF(seq, "%-8u %-8lu\n", s->sk_drops.counter, ino);
|
|
|
|
return 0;
|
|
}
|