Skip to content

Libbpf eBPF macro bpf_stream_printk

v1.6.0

The bpf_stream_printk macro is used to make writing to streams easier.

Definition

#define bpf_stream_printk(stream_id, fmt, args...)              \
({                                      \
    static const char ___fmt[] = fmt;                   \
    unsigned long long ___param[___bpf_narg(args)];             \
                                        \
    _Pragma("GCC diagnostic push")                      \
    _Pragma("GCC diagnostic ignored \"-Wint-conversion\"")          \
    ___bpf_fill(___param, args);                        \
    _Pragma("GCC diagnostic pop")                       \
                                        \
    bpf_stream_vprintk(stream_id, ___fmt, ___param, sizeof(___param), NULL);\
})

Usage

This macro is a wrapper around the bpf_stream_vprintk helper. It places the literal format string in a global variable, this is necessary to get the compiler to emit code that will be accepted by the verifier.

Example

Docs could be improved

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