1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2019-2020 Authors of Red Sift
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
/*!
Linux Socket Filtering API.
This module exposes the original Socket Filtering API. While still useful, you
can often use [`XDP`](../../api/redbpf_probes/xdp/index.html) for faster
performance and a nicer API.
# Example
In the following example, all TCP traffic is forwarded to userspace.
```
use core::mem;
use memoffset::offset_of;
use redbpf_probes::socket_filter::prelude::*;
#[socket_filter]
fn forward_tcp(skb: SkBuff) -> SkBuffResult {
let eth_len = mem::size_of::<ethhdr>();
let eth_proto: u16 = skb.load(offset_of!(ethhdr, h_proto))?;
let ip_proto: u8 = skb.load(eth_len + offset_of!(iphdr, protocol))?;
// only parse TCP
if !(eth_proto as u32 == ETH_P_IP && ip_proto as u32 == IPPROTO_TCP) {
return Ok(SkBuffAction::Ignore);
}
Ok(SkBuffAction::SendToUserspace)
}
```
*/
use crateSocketError;
/// The return type for successful socket filter programs.
pub use crateSkBuff;
/// Result type for socket filter programs.
pub type SkBuffResult = ;