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
1129int bpf_obj_get_user(const char __user *pathname, int flags);1129int bpf_obj_get_user(const char __user *pathname, int flags);
1130 1130
1131#define BPF_ITER_FUNC_PREFIX "__bpf_iter__"1131#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; }
1132 1135
1133typedef int (*bpf_iter_init_seq_priv_t)(void *private_data);1136typedef int (*bpf_iter_init_seq_priv_t)(void *private_data);
1134typedef void (*bpf_iter_fini_seq_priv_t)(void *private_data);1137typedef void (*bpf_iter_fini_seq_priv_t)(void *private_data);
@@ -1141,12 +1144,20 @@ struct bpf_iter_reg { · 6 unmodified lines
1141 u32 seq_priv_size;1144 u32 seq_priv_size;
1142};1145};
1143 1146
1147struct bpf_iter_meta {
1148 __bpf_md_ptr(struct seq_file *, seq);
1149 u64 session_id;
1150 u64 seq_num;
1151};
1152
1144int bpf_iter_reg_target(struct bpf_iter_reg *reg_info);1153int bpf_iter_reg_target(struct bpf_iter_reg *reg_info);
1145void bpf_iter_unreg_target(const char *target);1154void bpf_iter_unreg_target(const char *target);
1146bool bpf_iter_prog_supported(struct bpf_prog *prog);1155bool bpf_iter_prog_supported(struct bpf_prog *prog);
1147int bpf_iter_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);1156int bpf_iter_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
1148int bpf_iter_new_fd(struct bpf_link *link);1157int bpf_iter_new_fd(struct bpf_link *link);
1149bool bpf_link_is_iter(struct bpf_link *link);1158bool bpf_link_is_iter(struct bpf_link *link);
1159struct bpf_prog *bpf_iter_get_info(struct bpf_iter_meta *meta, bool in_stop);
1160int bpf_iter_run_prog(struct bpf_prog *prog, void *ctx);
1150 1161
1151int bpf_percpu_hash_copy(struct bpf_map *map, void *key, void *value);1162int bpf_percpu_hash_copy(struct bpf_map *map, void *key, void *value);
1152int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value);1163int 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