Attribute Macro redbpf_macros::stream_verdict[][src]

#[stream_verdict]
Expand description

Attribute macro for defining BPF programs of stream verdicts. A sockmap can be attached to the stream verdict. The role of stream verdicts is to predicate to which socket a message should be redirected.

Example

use redbpf_probes::sockmap::prelude::*;
#[map(link_section = "maps/echo_sockmap")]
static mut SOCKMAP: SockMap = SockMap::with_max_entries(10240);

#[stream_verdict]
fn verdict(skb: SkBuff) -> SkAction {
    match unsafe { SOCKMAP.redirect(skb.skb as *mut _, 0) } {
        Ok(_) => SkAction::Pass,
        Err(_) => SkAction::Drop,
    }
}