From 2bffff88820ddd71a54b8c8244faf028c361dfaf Mon Sep 17 00:00:00 2001 From: Mateusz Kossakowski Date: Wed, 25 May 2022 18:57:34 +0200 Subject: [PATCH] Use 0 as default PSA_PORT_RECIRCULATE value (#3360) --- backends/ebpf/psa/README.md | 17 +++++++++++++++-- backends/ebpf/psa/ebpfPsaGen.cpp | 4 +--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/backends/ebpf/psa/README.md b/backends/ebpf/psa/README.md index 8a7ca0fea96..8a5e6d55a86 100644 --- a/backends/ebpf/psa/README.md +++ b/backends/ebpf/psa/README.md @@ -435,14 +435,14 @@ $ python3 backends/ebpf/build_libbpf You can compile a P4-16 PSA program for eBPF in a single step using: ```bash -make -f backends/ebpf/runtime/kernel.mk BPFOBJ=out.o ARGS="-DPSA_PORT_RECIRCULATE=" P4FILE=.p4 P4C=p4c-ebpf psa +make -f backends/ebpf/runtime/kernel.mk BPFOBJ=out.o P4FILE=.p4 P4C=p4c-ebpf psa ``` You can also perform compilation step by step: ``` $ p4c-ebpf --arch psa --target kernel -o out.c .p4 -$ clang -Ibackends/ebpf/runtime -Ibackends/ebpf/runtime/usr/include -O2 -g -c -emit-llvm -DBTF -DPSA_PORT_RECIRCULATE= -o out.bc out.c +$ clang -Ibackends/ebpf/runtime -Ibackends/ebpf/runtime/usr/include -O2 -g -c -emit-llvm -o out.bc out.c $ llc -march=bpf -mcpu=generic -filetype=obj -o out.o out.bc ``` @@ -450,6 +450,19 @@ Note that you can use `-mcpu` flag to define the eBPF instruction set. Visit [th The above steps generate `out.o` BPF object file that can be loaded to the kernel. +#### Optional flags + +Supposing we want to use a packet recirculation we have to specify the `PSA_PORT_RECIRCULATE` port. +We can use `-DPSA_PORT_RECIRCULATE=` Clang flag via `kernel.mk` +```bash +make -f backends/ebpf/runtime/kernel.mk BPFOBJ=out.o ARGS="-DPSA_PORT_RECIRCULATE=" P4FILE=.p4 P4C=p4c-ebpf psa +``` +or directly: +`clang ... -DPSA_PORT_RECIRCULATE= ...`, +where `RECIRCULATE_PORT_IDX` is a number of a `psa_recirc` interface (this number can be obtained from `ip -n switch link`). + +By default `PSA_PORT_RECIRCULATE` is set to 0. + ### psabpf API and psabpf-ctl We provide the `psabpf` C API and the `psabpf-ctl` CLI tool that can be used to manage eBPF programs generated by P4-eBPF compiler. diff --git a/backends/ebpf/psa/ebpfPsaGen.cpp b/backends/ebpf/psa/ebpfPsaGen.cpp index 6da7d0d2c17..7f45542b4e6 100644 --- a/backends/ebpf/psa/ebpfPsaGen.cpp +++ b/backends/ebpf/psa/ebpfPsaGen.cpp @@ -79,9 +79,7 @@ void PSAEbpfGenerator::emitPreamble(CodeBuilder *builder) const { builder->newline(); builder->appendLine("#ifndef PSA_PORT_RECIRCULATE\n" - "#error \"PSA_PORT_RECIRCULATE not specified, " - "please use -DPSA_PORT_RECIRCULATE=n option to specify index of recirculation " - "interface (see the result of command 'ip link')\"\n" + "#define PSA_PORT_RECIRCULATE 0\n" "#endif"); builder->appendLine("#define P4C_PSA_PORT_RECIRCULATE 0xfffffffa"); builder->newline();