forked from TencentOS/TencentOS-kernel
bpf: Refactor to provide aux info to bpf_iter_init_seq_priv_t
[upstream commit f9c792729581bd8b8473af163e8ab426c2c61d89] This patch refactored target bpf_iter_init_seq_priv_t callback function to accept additional information. This will be needed in later patches for map element targets since a particular map should be passed to traverse elements for that particular map. In the future, other information may be passed to target as well, e.g., pid, cgroup id, etc. to customize the iterator. Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200723184110.590156-1-yhs@fb.com
This commit is contained in:
parent
e9286febe8
commit
708ed9baab
|
|
@ -82,7 +82,7 @@ static const struct file_operations proc_net_seq_fops = {
|
|||
.release = seq_release_net,
|
||||
};
|
||||
|
||||
int bpf_iter_init_seq_net(void *priv_data)
|
||||
int bpf_iter_init_seq_net(void *priv_data, struct bpf_iter_aux_info *aux)
|
||||
{
|
||||
#ifdef CONFIG_NET_NS
|
||||
struct seq_net_private *p = priv_data;
|
||||
|
|
|
|||
|
|
@ -32,11 +32,13 @@ struct btf;
|
|||
struct btf_type;
|
||||
struct exception_table_entry;
|
||||
struct seq_operations;
|
||||
struct bpf_iter_aux_info;
|
||||
|
||||
extern struct idr btf_idr;
|
||||
extern spinlock_t btf_idr_lock;
|
||||
|
||||
typedef int (*bpf_iter_init_seq_priv_t)(void *private_data);
|
||||
typedef int (*bpf_iter_init_seq_priv_t)(void *private_data,
|
||||
struct bpf_iter_aux_info *aux);
|
||||
typedef void (*bpf_iter_fini_seq_priv_t)(void *private_data);
|
||||
struct bpf_iter_seq_info {
|
||||
const struct seq_operations *seq_ops;
|
||||
|
|
@ -1108,6 +1110,9 @@ int bpf_obj_get_user(const char __user *pathname, int flags);
|
|||
extern int bpf_iter_ ## target(args); \
|
||||
int __init bpf_iter_ ## target(args) { return 0; }
|
||||
|
||||
struct bpf_iter_aux_info {
|
||||
};
|
||||
|
||||
#define BPF_ITER_CTX_ARG_MAX 2
|
||||
struct bpf_iter_reg {
|
||||
const char *target;
|
||||
|
|
|
|||
|
|
@ -79,7 +79,8 @@ extern struct pid *tgid_pidfd_to_pid(const struct file *file);
|
|||
extern struct net init_net;
|
||||
extern struct list_head sysctl_restrict_list;
|
||||
|
||||
extern int bpf_iter_init_seq_net(void *priv_data);
|
||||
struct bpf_iter_aux_info;
|
||||
extern int bpf_iter_init_seq_net(void *priv_data, struct bpf_iter_aux_info *aux);
|
||||
extern void bpf_iter_fini_seq_net(void *priv_data);
|
||||
|
||||
#ifdef CONFIG_PROC_PID_ARCH_STATUS
|
||||
|
|
|
|||
|
|
@ -442,7 +442,7 @@ static int prepare_seq_file(struct file *file, struct bpf_iter_link *link)
|
|||
}
|
||||
|
||||
if (tinfo->reg_info->seq_info->init_seq_private) {
|
||||
err = tinfo->reg_info->seq_info->init_seq_private(priv_data->target_private);
|
||||
err = tinfo->reg_info->seq_info->init_seq_private(priv_data->target_private, NULL);
|
||||
if (err)
|
||||
goto release_seq_file;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -287,7 +287,7 @@ static void task_file_seq_stop(struct seq_file *seq, void *v)
|
|||
}
|
||||
}
|
||||
|
||||
static int init_seq_pidns(void *priv_data)
|
||||
static int init_seq_pidns(void *priv_data, struct bpf_iter_aux_info *aux)
|
||||
{
|
||||
struct bpf_iter_seq_task_common *common = priv_data;
|
||||
|
||||
|
|
|
|||
|
|
@ -2885,7 +2885,7 @@ static struct pernet_operations __net_initdata tcp_sk_ops = {
|
|||
DEFINE_BPF_ITER_FUNC(tcp, struct bpf_iter_meta *meta,
|
||||
struct sock_common *sk_common, uid_t uid)
|
||||
|
||||
static int bpf_iter_init_tcp(void *priv_data)
|
||||
static int bpf_iter_init_tcp(void *priv_data, struct bpf_iter_aux_info *aux)
|
||||
{
|
||||
struct tcp_iter_state *st = priv_data;
|
||||
struct tcp_seq_afinfo *afinfo;
|
||||
|
|
@ -2897,7 +2897,7 @@ static int bpf_iter_init_tcp(void *priv_data)
|
|||
|
||||
afinfo->family = AF_UNSPEC;
|
||||
st->bpf_seq_afinfo = afinfo;
|
||||
ret = bpf_iter_init_seq_net(priv_data);
|
||||
ret = bpf_iter_init_seq_net(priv_data, aux);
|
||||
if (ret)
|
||||
kfree(afinfo);
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -3203,7 +3203,7 @@ static struct pernet_operations __net_initdata udp_sysctl_ops = {
|
|||
DEFINE_BPF_ITER_FUNC(udp, struct bpf_iter_meta *meta,
|
||||
struct udp_sock *udp_sk, uid_t uid, int bucket)
|
||||
|
||||
static int bpf_iter_init_udp(void *priv_data)
|
||||
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;
|
||||
|
|
@ -3216,7 +3216,7 @@ static int bpf_iter_init_udp(void *priv_data)
|
|||
afinfo->family = AF_UNSPEC;
|
||||
afinfo->udp_table = &udp_table;
|
||||
st->bpf_seq_afinfo = afinfo;
|
||||
ret = bpf_iter_init_seq_net(priv_data);
|
||||
ret = bpf_iter_init_seq_net(priv_data, aux);
|
||||
if (ret)
|
||||
kfree(afinfo);
|
||||
return ret;
|
||||
|
|
|
|||
Loading…
Reference in New Issue