foniod / redbpf

Rust library for building and running BPF/eBPF modules
Apache License 2.0
1.71k stars 136 forks source link

XDP: how to use Redirect verdict #79

Open trinity-1686a opened 4 years ago

trinity-1686a commented 4 years ago

Hi, I wanted to build a simple XDP-based router using these crates as a test project, but I'm a little puzzled on how to use XdpAction::Redirect. Looking at some C examples over the net, it appears one is supposed to use bpf_redirect/bpf_redirect_map to get the right action number, however this returns a c_int (i32), which can't be cast to a XdpAction without transmuting it (which is safe due to repr(u32), but not convenient nor intuitive). Am I correct, or is there a better way/an helper function I missed?

rsdy commented 4 years ago

I don't think we have the APIs fleshed out for this use case at the moment. I'll need to take a look into improving the XDP API also due to #78 , so if you have any concrete ideas or code examples you've tried, they would be welcome.