xdp-project/bpf-examples

pping: Debug prints in pping_kern.c

hundredmiles opened this issue · 1 comments

@simosund
I wanted to have some debug prints for the bpf program in the kernel space (pping_kern.c) as per XDP tutorial: Tracing03 - debug print where using the trace_pipe we can see the print statements.

Accordingly I am trying to use bpf_printk("Test print") function doing which fails to load the BPF program.

Starting ePPing in standard mode tracking TCP on lo
Failed pushing user-configration to pping_kern.o: Invalid argument
Failed loading and attaching BPF programs in pping_kern.o

Commenting out the line for printing works fine.

Anything that I should do to overcome this?

Hi,
Just answered your mail. In a meeting so will not be able to give much more details right now. But posting my mail answer here as well.

Unfortunatley it's a bit tricky to use bpf_printk() in pping. The problem is the string you put in the bpf_prinkt() is stored in the .ro (read-only) section of the program, which is also where the configuration set be the userspace program is stored. So when I try to set this config from userspace I write to this .ro section, but I don't know about whatever strings you may also have in your debug messages, so writing to this ro-section fails and the program will not be loaded.

To use bpf_printk you will have to comment out the call to init_rodata() on line 909 of pping.c. By doing that you any settings from userspace will be ignored, so you will have to initalize the config global constant on line 125 in pping_kern.c (you will probably at least set the track_tcp member to true, and perhaps rate_limit if you don't want very frequent measurements, you can see how the command line arguments set these from parse_arguments() function in pping.c). After that bpf_printk() should work. Not that bpf_prinkt can only accept at most 3 values in a single call, and that if you want to print out sequence numbers you may want to call bpf_ntohl() on them to convert from network byte order to host byte order.