Function rbpf::helpers::bpf_trace_printf [] [src]

pub fn bpf_trace_printf(
    unused1: u64,
    unused2: u64,
    arg3: u64,
    arg4: u64,
    arg5: u64
) -> u64

Prints its last three arguments to standard output. The first two arguments are unused. Returns 0.

By ignoring the first two arguments, it creates a helper that will have a behavior similar to the one of the equivalent helper bpf_trace_printk() from Linux kernel.

Examples

use rbpf::helpers;

helpers::bpf_trace_printf(1, 15, 32, 0, 0);

This will print bpf_trace_printf: 0x1, 0xf, 0x20.

The eBPF code produced would be nearly the same as when compiling the following code from C to eBPF with clang:

#include <linux/bpf.h>
#include "path/to/linux/samples/bpf/bpf_helpers.h"

int main(struct __sk_buff *skb)
{
    char *fmt = "bpf_trace_printk %lx %lx %lx\n";
    return bpf_trace_printk(fmt, sizeof(fmt), 1, 15, 32);
}

This would equally print the three numbers in /sys/kernel/debug/tracing file each time the program is run.