History

bpf: Print function name in addition to function id

The verifier currently prints raw function ids when printing CALL instructions or when complaining: 5: (85) call 23 unknown func 23 print a meaningful function name instead: 5: (85) call bpf_redirect#23 unknown func bpf_redirect#23 Moves the function documentation to a single comment and renames all helpers names in the list to conform to the bpf_ prefix notation so they can be greped in the kernel source.

Thomas Graf committed 10 years ago

Commit ebb676d1 parent 46b5ab12 files · +316 −293Browse files

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

Unified · Split

include/uapi/linux/bpf.h+289−285
@@ -143,297 +143,301 @@ union bpf_attr { · 142 unmodified lines
143 };143 };
144} __attribute__((aligned(8)));144} __attribute__((aligned(8)));
145 145
146/* BPF helper function descriptions:
147 *
148 * void *bpf_map_lookup_elem(&map, &key)
149 * Return: Map value or NULL
150 *
151 * int bpf_map_update_elem(&map, &key, &value, flags)
152 * Return: 0 on success or negative error
153 *
154 * int bpf_map_delete_elem(&map, &key)
155 * Return: 0 on success or negative error
156 *
157 * int bpf_probe_read(void *dst, int size, void *src)
158 * Return: 0 on success or negative error
159 *
160 * u64 bpf_ktime_get_ns(void)
161 * Return: current ktime
162 *
163 * int bpf_trace_printk(const char *fmt, int fmt_size, ...)
164 * Return: length of buffer written or negative error
165 *
166 * u32 bpf_prandom_u32(void)
167 * Return: random value
168 *
169 * u32 bpf_raw_smp_processor_id(void)
170 * Return: SMP processor ID
171 *
172 * int bpf_skb_store_bytes(skb, offset, from, len, flags)
173 * store bytes into packet
174 * @skb: pointer to skb
175 * @offset: offset within packet from skb->mac_header
176 * @from: pointer where to copy bytes from
177 * @len: number of bytes to store into packet
178 * @flags: bit 0 - if true, recompute skb->csum
179 * other bits - reserved
180 * Return: 0 on success or negative error
181 *
182 * int bpf_l3_csum_replace(skb, offset, from, to, flags)
183 * recompute IP checksum
184 * @skb: pointer to skb
185 * @offset: offset within packet where IP checksum is located
186 * @from: old value of header field
187 * @to: new value of header field
188 * @flags: bits 0-3 - size of header field
189 * other bits - reserved
190 * Return: 0 on success or negative error
191 *
192 * int bpf_l4_csum_replace(skb, offset, from, to, flags)
193 * recompute TCP/UDP checksum
194 * @skb: pointer to skb
195 * @offset: offset within packet where TCP/UDP checksum is located
196 * @from: old value of header field
197 * @to: new value of header field
198 * @flags: bits 0-3 - size of header field
199 * bit 4 - is pseudo header
200 * other bits - reserved
201 * Return: 0 on success or negative error
202 *
203 * int bpf_tail_call(ctx, prog_array_map, index)
204 * jump into another BPF program
205 * @ctx: context pointer passed to next program
206 * @prog_array_map: pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY
207 * @index: index inside array that selects specific program to run
208 * Return: 0 on success or negative error
209 *
210 * int bpf_clone_redirect(skb, ifindex, flags)
211 * redirect to another netdev
212 * @skb: pointer to skb
213 * @ifindex: ifindex of the net device
214 * @flags: bit 0 - if set, redirect to ingress instead of egress
215 * other bits - reserved
216 * Return: 0 on success or negative error
217 *
218 * u64 bpf_get_current_pid_tgid(void)
219 * Return: current->tgid << 32 | current->pid
220 *
221 * u64 bpf_get_current_uid_gid(void)
222 * Return: current_gid << 32 | current_uid
223 *
224 * int bpf_get_current_comm(char *buf, int size_of_buf)
225 * stores current->comm into buf
226 * Return: 0 on success or negative error
227 *
228 * u32 bpf_get_cgroup_classid(skb)
229 * retrieve a proc's classid
230 * @skb: pointer to skb
231 * Return: classid if != 0
232 *
233 * int bpf_skb_vlan_push(skb, vlan_proto, vlan_tci)
234 * Return: 0 on success or negative error
235 *
236 * int bpf_skb_vlan_pop(skb)
237 * Return: 0 on success or negative error
238 *
239 * int bpf_skb_get_tunnel_key(skb, key, size, flags)
240 * int bpf_skb_set_tunnel_key(skb, key, size, flags)
241 * retrieve or populate tunnel metadata
242 * @skb: pointer to skb
243 * @key: pointer to 'struct bpf_tunnel_key'
244 * @size: size of 'struct bpf_tunnel_key'
245 * @flags: room for future extensions
246 * Return: 0 on success or negative error
247 *
248 * u64 bpf_perf_event_read(&map, index)
249 * Return: Number events read or error code
250 *
251 * int bpf_redirect(ifindex, flags)
252 * redirect to another netdev
253 * @ifindex: ifindex of the net device
254 * @flags: bit 0 - if set, redirect to ingress instead of egress
255 * other bits - reserved
256 * Return: TC_ACT_REDIRECT
257 *
258 * u32 bpf_get_route_realm(skb)
259 * retrieve a dst's tclassid
260 * @skb: pointer to skb
261 * Return: realm if != 0
262 *
263 * int bpf_perf_event_output(ctx, map, index, data, size)
264 * output perf raw sample
265 * @ctx: struct pt_regs*
266 * @map: pointer to perf_event_array map
267 * @index: index of event in the map
268 * @data: data on stack to be output as raw data
269 * @size: size of data
270 * Return: 0 on success or negative error
271 *
272 * int bpf_get_stackid(ctx, map, flags)
273 * walk user or kernel stack and return id
274 * @ctx: struct pt_regs*
275 * @map: pointer to stack_trace map
276 * @flags: bits 0-7 - numer of stack frames to skip
277 * bit 8 - collect user stack instead of kernel
278 * bit 9 - compare stacks by hash only
279 * bit 10 - if two different stacks hash into the same stackid
280 * discard old
281 * other bits - reserved
282 * Return: >= 0 stackid on success or negative error
283 *
284 * s64 bpf_csum_diff(from, from_size, to, to_size, seed)
285 * calculate csum diff
286 * @from: raw from buffer
287 * @from_size: length of from buffer
288 * @to: raw to buffer
289 * @to_size: length of to buffer
290 * @seed: optional seed
291 * Return: csum result or negative error code
292 *
293 * int bpf_skb_get_tunnel_opt(skb, opt, size)
294 * retrieve tunnel options metadata
295 * @skb: pointer to skb
296 * @opt: pointer to raw tunnel option data
297 * @size: size of @opt
298 * Return: option size
299 *
300 * int bpf_skb_set_tunnel_opt(skb, opt, size)
301 * populate tunnel options metadata
302 * @skb: pointer to skb
303 * @opt: pointer to raw tunnel option data
304 * @size: size of @opt
305 * Return: 0 on success or negative error
306 *
307 * int bpf_skb_change_proto(skb, proto, flags)
308 * Change protocol of the skb. Currently supported is v4 -> v6,
309 * v6 -> v4 transitions. The helper will also resize the skb. eBPF
310 * program is expected to fill the new headers via skb_store_bytes
311 * and lX_csum_replace.
312 * @skb: pointer to skb
313 * @proto: new skb->protocol type
314 * @flags: reserved
315 * Return: 0 on success or negative error
316 *
317 * int bpf_skb_change_type(skb, type)
318 * Change packet type of skb.
319 * @skb: pointer to skb
320 * @type: new skb->pkt_type type
321 * Return: 0 on success or negative error
322 *
323 * int bpf_skb_under_cgroup(skb, map, index)
324 * Check cgroup2 membership of skb
325 * @skb: pointer to skb
326 * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
327 * @index: index of the cgroup in the bpf_map
328 * Return:
329 * == 0 skb failed the cgroup2 descendant test
330 * == 1 skb succeeded the cgroup2 descendant test
331 * < 0 error
332 *
333 * u32 bpf_get_hash_recalc(skb)
334 * Retrieve and possibly recalculate skb->hash.
335 * @skb: pointer to skb
336 * Return: hash
337 *
338 * u64 bpf_get_current_task(void)
339 * Returns current task_struct
340 * Return: current
341 *
342 * int bpf_probe_write_user(void *dst, void *src, int len)
343 * safely attempt to write to a location
344 * @dst: destination address in userspace
345 * @src: source address on stack
346 * @len: number of bytes to copy
347 * Return: 0 on success or negative error
348 *
349 * int bpf_current_task_under_cgroup(map, index)
350 * Check cgroup2 membership of current task
351 * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
352 * @index: index of the cgroup in the bpf_map
353 * Return:
354 * == 0 current failed the cgroup2 descendant test
355 * == 1 current succeeded the cgroup2 descendant test
356 * < 0 error
357 *
358 * int bpf_skb_change_tail(skb, len, flags)
359 * The helper will resize the skb to the given new size, to be used f.e.
360 * with control messages.
361 * @skb: pointer to skb
362 * @len: new skb length
363 * @flags: reserved
364 * Return: 0 on success or negative error
365 *
366 * int bpf_skb_pull_data(skb, len)
367 * The helper will pull in non-linear data in case the skb is non-linear
368 * and not all of len are part of the linear section. Only needed for
369 * read/write with direct packet access.
370 * @skb: pointer to skb
371 * @len: len to make read/writeable
372 * Return: 0 on success or negative error
373 *
374 * s64 bpf_csum_update(skb, csum)
375 * Adds csum into skb->csum in case of CHECKSUM_COMPLETE.
376 * @skb: pointer to skb
377 * @csum: csum to add
378 * Return: csum on success or negative error
379 *
380 * void bpf_set_hash_invalid(skb)
381 * Invalidate current skb->hash.
382 * @skb: pointer to skb
383 *
384 * int bpf_get_numa_node_id()
385 * Return: Id of current NUMA node.
386 */
387#define __BPF_FUNC_MAPPER(FN) \
388 FN(unspec), \
389 FN(map_lookup_elem), \
390 FN(map_update_elem), \
391 FN(map_delete_elem), \
392 FN(probe_read), \
393 FN(ktime_get_ns), \
394 FN(trace_printk), \
395 FN(get_prandom_u32), \
396 FN(get_smp_processor_id), \
397 FN(skb_store_bytes), \
398 FN(l3_csum_replace), \
399 FN(l4_csum_replace), \
400 FN(tail_call), \
401 FN(clone_redirect), \
402 FN(get_current_pid_tgid), \
403 FN(get_current_uid_gid), \
404 FN(get_current_comm), \
405 FN(get_cgroup_classid), \
406 FN(skb_vlan_push), \
407 FN(skb_vlan_pop), \
408 FN(skb_get_tunnel_key), \
409 FN(skb_set_tunnel_key), \
410 FN(perf_event_read), \
411 FN(redirect), \
412 FN(get_route_realm), \
413 FN(perf_event_output), \
414 FN(skb_load_bytes), \
415 FN(get_stackid), \
416 FN(csum_diff), \
417 FN(skb_get_tunnel_opt), \
418 FN(skb_set_tunnel_opt), \
419 FN(skb_change_proto), \
420 FN(skb_change_type), \
421 FN(skb_under_cgroup), \
422 FN(get_hash_recalc), \
423 FN(get_current_task), \
424 FN(probe_write_user), \
425 FN(current_task_under_cgroup), \
426 FN(skb_change_tail), \
427 FN(skb_pull_data), \
428 FN(csum_update), \
429 FN(set_hash_invalid), \
430 FN(get_numa_node_id),
431
146/* integer value in 'imm' field of BPF_CALL instruction selects which helper432/* integer value in 'imm' field of BPF_CALL instruction selects which helper
147 * function eBPF program intends to call433 * function eBPF program intends to call
148 */434 */
435#define __BPF_ENUM_FN(x) BPF_FUNC_ ## x
149enum bpf_func_id {436enum bpf_func_id {
150 BPF_FUNC_unspec,437 __BPF_FUNC_MAPPER(__BPF_ENUM_FN)
151 BPF_FUNC_map_lookup_elem, /* void *map_lookup_elem(&map, &key) */
152 BPF_FUNC_map_update_elem, /* int map_update_elem(&map, &key, &value, flags) */
153 BPF_FUNC_map_delete_elem, /* int map_delete_elem(&map, &key) */
154 BPF_FUNC_probe_read, /* int bpf_probe_read(void *dst, int size, void *src) */
155 BPF_FUNC_ktime_get_ns, /* u64 bpf_ktime_get_ns(void) */
156 BPF_FUNC_trace_printk, /* int bpf_trace_printk(const char *fmt, int fmt_size, ...) */
157 BPF_FUNC_get_prandom_u32, /* u32 prandom_u32(void) */
158 BPF_FUNC_get_smp_processor_id, /* u32 raw_smp_processor_id(void) */
159
160 /**
161 * skb_store_bytes(skb, offset, from, len, flags) - store bytes into packet
162 * @skb: pointer to skb
163 * @offset: offset within packet from skb->mac_header
164 * @from: pointer where to copy bytes from
165 * @len: number of bytes to store into packet
166 * @flags: bit 0 - if true, recompute skb->csum
167 * other bits - reserved
168 * Return: 0 on success
169 */
170 BPF_FUNC_skb_store_bytes,
171
172 /**
173 * l3_csum_replace(skb, offset, from, to, flags) - recompute IP checksum
174 * @skb: pointer to skb
175 * @offset: offset within packet where IP checksum is located
176 * @from: old value of header field
177 * @to: new value of header field
178 * @flags: bits 0-3 - size of header field
179 * other bits - reserved
180 * Return: 0 on success
181 */
182 BPF_FUNC_l3_csum_replace,
183
184 /**
185 * l4_csum_replace(skb, offset, from, to, flags) - recompute TCP/UDP checksum
186 * @skb: pointer to skb
187 * @offset: offset within packet where TCP/UDP checksum is located
188 * @from: old value of header field
189 * @to: new value of header field
190 * @flags: bits 0-3 - size of header field
191 * bit 4 - is pseudo header
192 * other bits - reserved
193 * Return: 0 on success
194 */
195 BPF_FUNC_l4_csum_replace,
196
197 /**
198 * bpf_tail_call(ctx, prog_array_map, index) - jump into another BPF program
199 * @ctx: context pointer passed to next program
200 * @prog_array_map: pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY
201 * @index: index inside array that selects specific program to run
202 * Return: 0 on success
203 */
204 BPF_FUNC_tail_call,
205
206 /**
207 * bpf_clone_redirect(skb, ifindex, flags) - redirect to another netdev
208 * @skb: pointer to skb
209 * @ifindex: ifindex of the net device
210 * @flags: bit 0 - if set, redirect to ingress instead of egress
211 * other bits - reserved
212 * Return: 0 on success
213 */
214 BPF_FUNC_clone_redirect,
215
216 /**
217 * u64 bpf_get_current_pid_tgid(void)
218 * Return: current->tgid << 32 | current->pid
219 */
220 BPF_FUNC_get_current_pid_tgid,
221
222 /**
223 * u64 bpf_get_current_uid_gid(void)
224 * Return: current_gid << 32 | current_uid
225 */
226 BPF_FUNC_get_current_uid_gid,
227
228 /**
229 * bpf_get_current_comm(char *buf, int size_of_buf)
230 * stores current->comm into buf
231 * Return: 0 on success
232 */
233 BPF_FUNC_get_current_comm,
234
235 /**
236 * bpf_get_cgroup_classid(skb) - retrieve a proc's classid
237 * @skb: pointer to skb
238 * Return: classid if != 0
239 */
240 BPF_FUNC_get_cgroup_classid,
241 BPF_FUNC_skb_vlan_push, /* bpf_skb_vlan_push(skb, vlan_proto, vlan_tci) */
242 BPF_FUNC_skb_vlan_pop, /* bpf_skb_vlan_pop(skb) */
243
244 /**
245 * bpf_skb_[gs]et_tunnel_key(skb, key, size, flags)
246 * retrieve or populate tunnel metadata
247 * @skb: pointer to skb
248 * @key: pointer to 'struct bpf_tunnel_key'
249 * @size: size of 'struct bpf_tunnel_key'
250 * @flags: room for future extensions
251 * Retrun: 0 on success
252 */
253 BPF_FUNC_skb_get_tunnel_key,
254 BPF_FUNC_skb_set_tunnel_key,
255 BPF_FUNC_perf_event_read, /* u64 bpf_perf_event_read(&map, index) */
256 /**
257 * bpf_redirect(ifindex, flags) - redirect to another netdev
258 * @ifindex: ifindex of the net device
259 * @flags: bit 0 - if set, redirect to ingress instead of egress
260 * other bits - reserved
261 * Return: TC_ACT_REDIRECT
262 */
263 BPF_FUNC_redirect,
264
265 /**
266 * bpf_get_route_realm(skb) - retrieve a dst's tclassid
267 * @skb: pointer to skb
268 * Return: realm if != 0
269 */
270 BPF_FUNC_get_route_realm,
271
272 /**
273 * bpf_perf_event_output(ctx, map, index, data, size) - output perf raw sample
274 * @ctx: struct pt_regs*
275 * @map: pointer to perf_event_array map
276 * @index: index of event in the map
277 * @data: data on stack to be output as raw data
278 * @size: size of data
279 * Return: 0 on success
280 */
281 BPF_FUNC_perf_event_output,
282 BPF_FUNC_skb_load_bytes,
283
284 /**
285 * bpf_get_stackid(ctx, map, flags) - walk user or kernel stack and return id
286 * @ctx: struct pt_regs*
287 * @map: pointer to stack_trace map
288 * @flags: bits 0-7 - numer of stack frames to skip
289 * bit 8 - collect user stack instead of kernel
290 * bit 9 - compare stacks by hash only
291 * bit 10 - if two different stacks hash into the same stackid
292 * discard old
293 * other bits - reserved
294 * Return: >= 0 stackid on success or negative error
295 */
296 BPF_FUNC_get_stackid,
297
298 /**
299 * bpf_csum_diff(from, from_size, to, to_size, seed) - calculate csum diff
300 * @from: raw from buffer
301 * @from_size: length of from buffer
302 * @to: raw to buffer
303 * @to_size: length of to buffer
304 * @seed: optional seed
305 * Return: csum result
306 */
307 BPF_FUNC_csum_diff,
308
309 /**
310 * bpf_skb_[gs]et_tunnel_opt(skb, opt, size)
311 * retrieve or populate tunnel options metadata
312 * @skb: pointer to skb
313 * @opt: pointer to raw tunnel option data
314 * @size: size of @opt
315 * Return: 0 on success for set, option size for get
316 */
317 BPF_FUNC_skb_get_tunnel_opt,
318 BPF_FUNC_skb_set_tunnel_opt,
319
320 /**
321 * bpf_skb_change_proto(skb, proto, flags)
322 * Change protocol of the skb. Currently supported is
323 * v4 -> v6, v6 -> v4 transitions. The helper will also
324 * resize the skb. eBPF program is expected to fill the
325 * new headers via skb_store_bytes and lX_csum_replace.
326 * @skb: pointer to skb
327 * @proto: new skb->protocol type
328 * @flags: reserved
329 * Return: 0 on success or negative error
330 */
331 BPF_FUNC_skb_change_proto,
332
333 /**
334 * bpf_skb_change_type(skb, type)
335 * Change packet type of skb.
336 * @skb: pointer to skb
337 * @type: new skb->pkt_type type
338 * Return: 0 on success or negative error
339 */
340 BPF_FUNC_skb_change_type,
341
342 /**
343 * bpf_skb_under_cgroup(skb, map, index) - Check cgroup2 membership of skb
344 * @skb: pointer to skb
345 * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
346 * @index: index of the cgroup in the bpf_map
347 * Return:
348 * == 0 skb failed the cgroup2 descendant test
349 * == 1 skb succeeded the cgroup2 descendant test
350 * < 0 error
351 */
352 BPF_FUNC_skb_under_cgroup,
353
354 /**
355 * bpf_get_hash_recalc(skb)
356 * Retrieve and possibly recalculate skb->hash.
357 * @skb: pointer to skb
358 * Return: hash
359 */
360 BPF_FUNC_get_hash_recalc,
361
362 /**
363 * u64 bpf_get_current_task(void)
364 * Returns current task_struct
365 * Return: current
366 */
367 BPF_FUNC_get_current_task,
368
369 /**
370 * bpf_probe_write_user(void *dst, void *src, int len)
371 * safely attempt to write to a location
372 * @dst: destination address in userspace
373 * @src: source address on stack
374 * @len: number of bytes to copy
375 * Return: 0 on success or negative error
376 */
377 BPF_FUNC_probe_write_user,
378
379 /**
380 * bpf_current_task_under_cgroup(map, index) - Check cgroup2 membership of current task
381 * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
382 * @index: index of the cgroup in the bpf_map
383 * Return:
384 * == 0 current failed the cgroup2 descendant test
385 * == 1 current succeeded the cgroup2 descendant test
386 * < 0 error
387 */
388 BPF_FUNC_current_task_under_cgroup,
389
390 /**
391 * bpf_skb_change_tail(skb, len, flags)
392 * The helper will resize the skb to the given new size,
393 * to be used f.e. with control messages.
394 * @skb: pointer to skb
395 * @len: new skb length
396 * @flags: reserved
397 * Return: 0 on success or negative error
398 */
399 BPF_FUNC_skb_change_tail,
400
401 /**
402 * bpf_skb_pull_data(skb, len)
403 * The helper will pull in non-linear data in case the
404 * skb is non-linear and not all of len are part of the
405 * linear section. Only needed for read/write with direct
406 * packet access.
407 * @skb: pointer to skb
408 * @len: len to make read/writeable
409 * Return: 0 on success or negative error
410 */
411 BPF_FUNC_skb_pull_data,
412
413 /**
414 * bpf_csum_update(skb, csum)
415 * Adds csum into skb->csum in case of CHECKSUM_COMPLETE.
416 * @skb: pointer to skb
417 * @csum: csum to add
418 * Return: csum on success or negative error
419 */
420 BPF_FUNC_csum_update,
421
422 /**
423 * bpf_set_hash_invalid(skb)
424 * Invalidate current skb>hash.
425 * @skb: pointer to skb
426 */
427 BPF_FUNC_set_hash_invalid,
428
429 /**
430 * bpf_get_numa_node_id()
431 * Returns the id of the current NUMA node.
432 */
433 BPF_FUNC_get_numa_node_id,
434
435 __BPF_FUNC_MAX_ID,438 __BPF_FUNC_MAX_ID,
436};439};
440#undef __BPF_ENUM_FN
437 441
438/* All flags used by eBPF helper functions, placed here. */442/* All flags used by eBPF helper functions, placed here. */
439 443

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