History

bpf: Implement an interface to register bpf_iter targets

The target can call bpf_iter_reg_target() to register itself. The needed information: target: target name seq_ops: the seq_file operations for the target init_seq_private target callback to initialize seq_priv during file open fini_seq_private target callback to clean up seq_priv during file release seq_priv_size: the private_data size needed by the seq_file operations The target name represents a target which provides a seq_ops for iterating objects. The target can provide two callback functions, init_seq_private and fini_seq_private, called during file open/release time. For example, /proc/net/{tcp6, ipv6_route, netlink, ...}, net name space needs to be setup properly during file open and released properly during file release. Function bpf_iter_unreg_target() is also implemented to unregister a particular target.

Yonghong Song committed 6 years ago

Commit ae243451 parent 8086fba3 files · +75 −1Browse files

Showing the changes to include/linux (1 of 3 files). Show all

Unified · Split

include/linux/bpf.h+15−0
@@ -31,6 +31,7 @@ struct seq_file; · 30 unmodified lines
3131 struct btf;
3232 struct btf_type;
3333 struct exception_table_entry;
34+struct seq_operations;
3435
3536 extern struct idr btf_idr;
3637 extern spinlock_t btf_idr_lock;
@@ -1126,6 +1127,20 @@ struct bpf_link *bpf_link_get_from_fd(u32 ufd); · 1089 unmodified lines
11261127 int bpf_obj_pin_user(u32 ufd, const char __user *pathname);
11271128 int bpf_obj_get_user(const char __user *pathname, int flags);
11281129
1130+typedef int (*bpf_iter_init_seq_priv_t)(void *private_data);
1131+typedef void (*bpf_iter_fini_seq_priv_t)(void *private_data);
1132+
1133+struct bpf_iter_reg {
1134+ const char *target;
1135+ const struct seq_operations *seq_ops;
1136+ bpf_iter_init_seq_priv_t init_seq_private;
1137+ bpf_iter_fini_seq_priv_t fini_seq_private;
1138+ u32 seq_priv_size;
1139+};
1140+
1141+int bpf_iter_reg_target(struct bpf_iter_reg *reg_info);
1142+void bpf_iter_unreg_target(const char *target);
1143+
11291144 int bpf_percpu_hash_copy(struct bpf_map *map, void *key, void *value);
11301145 int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value);
11311146 int bpf_percpu_hash_update(struct bpf_map *map, void *key, void *value,