p4lang / p4c

P4_16 reference compiler
https://p4.org/
Apache License 2.0
642 stars 429 forks source link

custom extern implementation #4730

Open Arishbiswas opened 2 weeks ago

Arishbiswas commented 2 weeks ago

how can we add custom extern for psa-ebpf backend. is it possoble to write an (ebpf.c) extern and call it from the p4 program

fruffy commented 2 weeks ago

@osinstom @tatry

You can add the --extern-file command to the compiler, I would take a look at the https://github.com/p4lang/p4c/blob/main/backends/ebpf/CMakeLists.txt#L256C156-L256C169 ebpf_checksum_extern example.

sudo -E p4c/backends/ebpf/run-ebpf-test.py -t test -c "p4c/build/p4c-ebpf" p4c --extern-file p4c/testdata/extern_modules/extern-checksum-ebpf.c  p4c/testdata/p4_16_samples/ebpf_checksum_extern.p4

should run it.