Skip to content

Helper function bpf_seq_printf

v5.8

Definition

Copyright (c) 2015 The Libbpf Authors. All rights reserved.

bpf_seq_printf() uses seq_file seq_printf() to print out the format string. The m represents the seq_file. The fmt and fmt_size are for the format string itself. The data and data_len are format string arguments. The data are a u64 array and corresponding format string values are stored in the array. For strings and pointers where pointees are accessed, only the pointer values are stored in the data array. The data_len is the size of data in bytes - must be a multiple of 8.

Formats %s, %p{i,I}{4,6} requires to read kernel memory. Reading kernel memory may fail due to either invalid address or valid address but requiring a major memory fault. If reading kernel memory fails, the string for %s will be an empty string, and the ip address for %p{i,I}{4,6} will be 0. Not returning error to bpf program is consistent with what bpf_trace_printk() does for now.

Returns

0 on success, or a negative error in case of failure:

-EBUSY if per-CPU memory copy buffer is busy, can try again by returning 1 from bpf program.

-EINVAL if arguments are invalid, or if fmt is invalid/unsupported.

-E2BIG if fmt contains too many format specifiers.

-EOVERFLOW if an overflow happened: The same object will be tried again.

static long (* const bpf_seq_printf)(struct seq_file *m, const char *fmt, __u32 fmt_size, const void *data, __u32 data_len) = (void *) 126;

Usage

Docs could be improved

This part of the docs is incomplete, contributions are very welcome

Program types

This helper call can be used in the following program types:

Example

Docs could be improved

This part of the docs is incomplete, contributions are very welcome