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.
Showing the changes to include/linux (1 of 3 files). Show all
Unified · Split
| @@ -31,6 +31,7 @@ struct seq_file; · 30 unmodified lines | ||
| 31 | 31 | struct btf; |
| 32 | 32 | struct btf_type; |
| 33 | 33 | struct exception_table_entry; |
| 34 | +struct seq_operations; | |
| 34 | 35 | |
| 35 | 36 | extern struct idr btf_idr; |
| 36 | 37 | extern spinlock_t btf_idr_lock; |
| @@ -1126,6 +1127,20 @@ struct bpf_link *bpf_link_get_from_fd(u32 ufd); · 1089 unmodified lines | ||
| 1126 | 1127 | int bpf_obj_pin_user(u32 ufd, const char __user *pathname); |
| 1127 | 1128 | int bpf_obj_get_user(const char __user *pathname, int flags); |
| 1128 | 1129 | |
| 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 | + | |
| 1129 | 1144 | int bpf_percpu_hash_copy(struct bpf_map *map, void *key, void *value); |
| 1130 | 1145 | int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value); |
| 1131 | 1146 | int bpf_percpu_hash_update(struct bpf_map *map, void *key, void *value, |