netstack3_filter/
actions.rs1use netstack3_base::Mark;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum MarkAction {
10 SetMark {
14 mark: u32,
17 clearing_mask: u32,
20 },
21}
22
23impl MarkAction {
24 pub fn apply(self, mark: &mut Mark) {
26 let Mark(cur) = mark;
27 match self {
28 MarkAction::SetMark { clearing_mask, mark } => {
29 *cur = Some(match cur {
30 Some(v) => (*v & !clearing_mask) | mark,
31 None => mark,
32 });
33 }
34 }
35 }
36}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41 use test_case::test_case;
42
43 #[test_case(Mark(None), MarkAction::SetMark { mark: 1, clearing_mask: 0 } => Mark(Some(1))
44 ; "set new mark")]
45 #[test_case(Mark(Some(1)), MarkAction::SetMark { mark: 2, clearing_mask: 1 } => Mark(Some(2))
46 ; "clear with mask")]
47 #[test_case(Mark(Some(1)), MarkAction::SetMark { mark: 2, clearing_mask: 0 } => Mark(Some(3))
48 ; "or mark")]
49 fn apply_mark_action(mut mark: Mark, action: MarkAction) -> Mark {
50 action.apply(&mut mark);
51 mark
52 }
53}