aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
authorJakub Kicinski <jakub.kicinski@netronome.com>2018-05-10 13:24:41 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-05-10 19:40:52 -0400
commit2eb57bb8f6769fe94f8f9865342ffa0f6c257e0a (patch)
tree5f190595b795093ddf2fa8e76a1e82615d3b41fb /tools/lib
parentd0cabbb021bee5c4b831a0235af9534ad07f8d3d (diff)
tools: bpf: improve comments in libbpf.h
Fix spelling mistakes, improve and clarify the language of comments in libbpf.h. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/bpf/libbpf.h48
1 files changed, 24 insertions, 24 deletions
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index ce681097584e..4574b9563278 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -52,8 +52,8 @@ enum libbpf_errno {
52int libbpf_strerror(int err, char *buf, size_t size); 52int libbpf_strerror(int err, char *buf, size_t size);
53 53
54/* 54/*
55 * In include/linux/compiler-gcc.h, __printf is defined. However 55 * __printf is defined in include/linux/compiler-gcc.h. However,
56 * it should be better if libbpf.h doesn't depend on Linux header file. 56 * it would be better if libbpf.h didn't depend on Linux header files.
57 * So instead of __printf, here we use gcc attribute directly. 57 * So instead of __printf, here we use gcc attribute directly.
58 */ 58 */
59typedef int (*libbpf_print_fn_t)(const char *, ...) 59typedef int (*libbpf_print_fn_t)(const char *, ...)
@@ -92,7 +92,7 @@ int bpf_object__set_priv(struct bpf_object *obj, void *priv,
92 bpf_object_clear_priv_t clear_priv); 92 bpf_object_clear_priv_t clear_priv);
93void *bpf_object__priv(struct bpf_object *prog); 93void *bpf_object__priv(struct bpf_object *prog);
94 94
95/* Accessors of bpf_program. */ 95/* Accessors of bpf_program */
96struct bpf_program; 96struct bpf_program;
97struct bpf_program *bpf_program__next(struct bpf_program *prog, 97struct bpf_program *bpf_program__next(struct bpf_program *prog,
98 struct bpf_object *obj); 98 struct bpf_object *obj);
@@ -121,28 +121,28 @@ struct bpf_insn;
121 121
122/* 122/*
123 * Libbpf allows callers to adjust BPF programs before being loaded 123 * Libbpf allows callers to adjust BPF programs before being loaded
124 * into kernel. One program in an object file can be transform into 124 * into kernel. One program in an object file can be transformed into
125 * multiple variants to be attached to different code. 125 * multiple variants to be attached to different hooks.
126 * 126 *
127 * bpf_program_prep_t, bpf_program__set_prep and bpf_program__nth_fd 127 * bpf_program_prep_t, bpf_program__set_prep and bpf_program__nth_fd
128 * are APIs for this propose. 128 * form an API for this purpose.
129 * 129 *
130 * - bpf_program_prep_t: 130 * - bpf_program_prep_t:
131 * It defines 'preprocessor', which is a caller defined function 131 * Defines a 'preprocessor', which is a caller defined function
132 * passed to libbpf through bpf_program__set_prep(), and will be 132 * passed to libbpf through bpf_program__set_prep(), and will be
133 * called before program is loaded. The processor should adjust 133 * called before program is loaded. The processor should adjust
134 * the program one time for each instances according to the number 134 * the program one time for each instance according to the instance id
135 * passed to it. 135 * passed to it.
136 * 136 *
137 * - bpf_program__set_prep: 137 * - bpf_program__set_prep:
138 * Attachs a preprocessor to a BPF program. The number of instances 138 * Attaches a preprocessor to a BPF program. The number of instances
139 * whould be created is also passed through this function. 139 * that should be created is also passed through this function.
140 * 140 *
141 * - bpf_program__nth_fd: 141 * - bpf_program__nth_fd:
142 * After the program is loaded, get resuling fds from bpf program for 142 * After the program is loaded, get resulting FD of a given instance
143 * each instances. 143 * of the BPF program.
144 * 144 *
145 * If bpf_program__set_prep() is not used, the program whould be loaded 145 * If bpf_program__set_prep() is not used, the program would be loaded
146 * without adjustment during bpf_object__load(). The program has only 146 * without adjustment during bpf_object__load(). The program has only
147 * one instance. In this case bpf_program__fd(prog) is equal to 147 * one instance. In this case bpf_program__fd(prog) is equal to
148 * bpf_program__nth_fd(prog, 0). 148 * bpf_program__nth_fd(prog, 0).
@@ -156,7 +156,7 @@ struct bpf_prog_prep_result {
156 struct bpf_insn *new_insn_ptr; 156 struct bpf_insn *new_insn_ptr;
157 int new_insn_cnt; 157 int new_insn_cnt;
158 158
159 /* If not NULL, result fd is set to it */ 159 /* If not NULL, result FD is written to it. */
160 int *pfd; 160 int *pfd;
161}; 161};
162 162
@@ -169,8 +169,8 @@ struct bpf_prog_prep_result {
169 * - res: Output parameter, result of transformation. 169 * - res: Output parameter, result of transformation.
170 * 170 *
171 * Return value: 171 * Return value:
172 * - Zero: pre-processing success. 172 * - Zero: pre-processing success.
173 * - Non-zero: pre-processing, stop loading. 173 * - Non-zero: pre-processing error, stop loading.
174 */ 174 */
175typedef int (*bpf_program_prep_t)(struct bpf_program *prog, int n, 175typedef int (*bpf_program_prep_t)(struct bpf_program *prog, int n,
176 struct bpf_insn *insns, int insns_cnt, 176 struct bpf_insn *insns, int insns_cnt,
@@ -182,7 +182,7 @@ int bpf_program__set_prep(struct bpf_program *prog, int nr_instance,
182int bpf_program__nth_fd(struct bpf_program *prog, int n); 182int bpf_program__nth_fd(struct bpf_program *prog, int n);
183 183
184/* 184/*
185 * Adjust type of bpf program. Default is kprobe. 185 * Adjust type of BPF program. Default is kprobe.
186 */ 186 */
187int bpf_program__set_socket_filter(struct bpf_program *prog); 187int bpf_program__set_socket_filter(struct bpf_program *prog);
188int bpf_program__set_tracepoint(struct bpf_program *prog); 188int bpf_program__set_tracepoint(struct bpf_program *prog);
@@ -206,10 +206,10 @@ bool bpf_program__is_xdp(struct bpf_program *prog);
206bool bpf_program__is_perf_event(struct bpf_program *prog); 206bool bpf_program__is_perf_event(struct bpf_program *prog);
207 207
208/* 208/*
209 * We don't need __attribute__((packed)) now since it is 209 * No need for __attribute__((packed)), all members of 'bpf_map_def'
210 * unnecessary for 'bpf_map_def' because they are all aligned. 210 * are all aligned. In addition, using __attribute__((packed))
211 * In addition, using it will trigger -Wpacked warning message, 211 * would trigger a -Wpacked warning message, and lead to an error
212 * and will be treated as an error due to -Werror. 212 * if -Werror is set.
213 */ 213 */
214struct bpf_map_def { 214struct bpf_map_def {
215 unsigned int type; 215 unsigned int type;
@@ -220,8 +220,8 @@ struct bpf_map_def {
220}; 220};
221 221
222/* 222/*
223 * There is another 'struct bpf_map' in include/linux/map.h. However, 223 * The 'struct bpf_map' in include/linux/bpf.h is internal to the kernel,
224 * it is not a uapi header so no need to consider name clash. 224 * so no need to worry about a name clash.
225 */ 225 */
226struct bpf_map; 226struct bpf_map;
227struct bpf_map * 227struct bpf_map *
@@ -229,7 +229,7 @@ bpf_object__find_map_by_name(struct bpf_object *obj, const char *name);
229 229
230/* 230/*
231 * Get bpf_map through the offset of corresponding struct bpf_map_def 231 * Get bpf_map through the offset of corresponding struct bpf_map_def
232 * in the bpf object file. 232 * in the BPF object file.
233 */ 233 */
234struct bpf_map * 234struct bpf_map *
235bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset); 235bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset);