History

bpf: Implement common macros/helpers for target iterators

Macro DEFINE_BPF_ITER_FUNC is implemented so target can define an init function to capture the BTF type which represents the target. The bpf_iter_meta is a structure holding meta data, common to all targets in the bpf program. Additional marker functions are called before or after bpf_seq_read() show()/next()/stop() callback functions to help calculate precise seq_num and whether call bpf_prog inside stop(). Two functions, bpf_iter_get_info() and bpf_iter_run_prog(), are implemented so target can get needed information from bpf_iter infrastructure and can run the program.

Yonghong Song committed 6 years ago

Commit e5158d91 parent 367ec3e2 files · +91 −5Browse files

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

Unified · Split

include/linux/bpf.h+11−0
@@ -1129,6 +1129,9 @@ int bpf_obj_pin_user(u32 ufd, const char __user *pathname); · 1128 unmodified lines
11291129 int bpf_obj_get_user(const char __user *pathname, int flags);
11301130
11311131 #define BPF_ITER_FUNC_PREFIX "__bpf_iter__"
1132+#define DEFINE_BPF_ITER_FUNC(target, args...) \
1133+ extern int __bpf_iter__ ## target(args); \
1134+ int __init __bpf_iter__ ## target(args) { return 0; }
11321135
11331136 typedef int (*bpf_iter_init_seq_priv_t)(void *private_data);
11341137 typedef void (*bpf_iter_fini_seq_priv_t)(void *private_data);
@@ -1141,12 +1144,20 @@ struct bpf_iter_reg { · 6 unmodified lines
11411144 u32 seq_priv_size;
11421145 };
11431146
1147+struct bpf_iter_meta {
1148+ __bpf_md_ptr(struct seq_file *, seq);
1149+ u64 session_id;
1150+ u64 seq_num;
1151+};
1152+
11441153 int bpf_iter_reg_target(struct bpf_iter_reg *reg_info);
11451154 void bpf_iter_unreg_target(const char *target);
11461155 bool bpf_iter_prog_supported(struct bpf_prog *prog);
11471156 int bpf_iter_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
11481157 int bpf_iter_new_fd(struct bpf_link *link);
11491158 bool bpf_link_is_iter(struct bpf_link *link);
1159+struct bpf_prog *bpf_iter_get_info(struct bpf_iter_meta *meta, bool in_stop);
1160+int bpf_iter_run_prog(struct bpf_prog *prog, void *ctx);
11501161
11511162 int bpf_percpu_hash_copy(struct bpf_map *map, void *key, void *value);
11521163 int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t