Below BPF prgram in cpp is throwing error when binding to udp socket using SO_ATTACH_REUSEPORT_CBPF
struct sock_filter code[] = {
{BPF_LD | BPF_MEM, 0, 0, 0x00000000}, // load memory to accumulator
//{BPF_ALU | BPF_ADD, 0, 0, 0x00000001}, // add 1
//{BPF_ALU | BPF_MOD, 0, 0, 0x00000003}, //module 3
//{BPF_ST , 0, 0, 0x00000000}, // save in scratch memory
//{BPF_RET | BPF_A, 0, 0, 0x00000000}, // return value in accumulator
};
But when i am changing bpf program to
struct sock_filter code[] = {
{BPF_RET, 0, 0, 0x00000000}
};
My code is running fine.
What is problem in 1st bpf program??
I tried executing with both bpf program, expecting that first bpf program attach succesfully to my udp socket.
Both the BPF program is valid. I made mistake when declaring struct sock_fprog.
Initially it was
So that's why bpf program
run correctly as it has only one instruction.
Now i changed the struct code to run for any number of instructions: