structethhdr*eth= (structethhdr*)data;
structiphdr*iph= (structiphdr*)(eth+1);
structtcphdr*tcphdr= (structtcphdr*)(iph+1);
...
/* sanity check needed by the eBPF verifier */if ((void*)(tcphdr+1) >data_end)
return0;
use the offset, like sth beblow:
void*data_end= (void*)(long)ctx->data_end;
void*data= (void*)(long)ctx->data;
structethhdr*eth=data;
...
// use the offsetoff=sizeof(structethhdr);
if (data+off>data_end)
returnXDP_PASS;
I learn that they are both for BPF verifier and I am wondering what's the difference between them, and when should I use one of them?
Feel free to correct me if I misunderstood something.