push_packet/rules/action.rs
1/// An action to take on matching rules.
2#[non_exhaustive]
3#[derive(Clone, Copy)]
4pub enum Action {
5 /// Instructs the kernel to do nothing, and should be used to override other rules.
6 Pass,
7 /// Drops the packet.
8 Drop,
9 /// Copies the packet to userspace, but it is processed as normal by the kernel. The `take`
10 /// field optionally limits the copied data to a certain number of bytes.
11 Copy {
12 /// Maximum bytes to copy from each packet. `None` copies the entire packet.
13 take: Option<u32>,
14 },
15 /// Routes the packet to userspace.
16 Route,
17}
18
19impl Action {
20 /// Convenience constant to copy the entire packet
21 pub const COPY_ALL: Action = Action::Copy { take: None };
22
23 pub(crate) fn into_common_action(self) -> (push_packet_common::Action, Option<u32>) {
24 match self {
25 Self::Pass => (push_packet_common::Action::Pass, None),
26 Self::Drop => (push_packet_common::Action::Drop, None),
27 Self::Copy { take } => (push_packet_common::Action::Copy, take),
28 Self::Route => (push_packet_common::Action::Route, None),
29 }
30 }
31}