xdp-tutorial icon indicating copy to clipboard operation
xdp-tutorial copied to clipboard

Testing "offline"?

Open PolynomialDivision opened this issue 4 years ago • 3 comments

Is there an easy way to simulate and test my functions? I want to play around with IPv6 headers and it would be easier to do the parsing and testing offline. I would need to get the struct xdp_md *ctx. Or maybe some function that crafts me a package?

PolynomialDivision avatar Nov 25 '20 08:11 PolynomialDivision

You could use the BPF_PROG_TEST_RUN kernel API to run your program with a given packet.

The bpftool also has support for doing this:

https://www.spinics.net/lists/netdev/msg584123.html

Guess you can create your IPv6 packet with scapy in python.

chaudron avatar Nov 25 '20 09:11 chaudron

Eelco Chaudron [email protected] writes:

You could use the BPF_PROG_TEST_RUN kernel API to run your program with a given packet.

The bpftool also has support for doing this:

https://www.spinics.net/lists/netdev/msg584123.html

The XDP testing framework we use for xdp-tools also has support for using bpf_prog_test_run:

https://github.com/shoracek/xdp-test-harness

See the Python tests for xdp-filter for examples:

https://github.com/xdp-project/xdp-tools/blob/master/xdp-filter/tests/test_basic.py

tohojo avatar Nov 25 '20 10:11 tohojo

Interesting. I have to go through it. Can I maybe capture an IPv6 packet with pcap and cut that out and then use this BPF_PROG_TEST_RUN? The perl -e 'print "\x0" x 14' is for tracing the binary data to the bpf-tool, or? So in realty it would be a much longer string?

PolynomialDivision avatar Nov 25 '20 14:11 PolynomialDivision