1use super::raw::scmp_filter_attr::{self, *};
3use crate::action::Action;
4use std::fmt;
5
6pub enum OptimizeStrategy {
8 PriorityAndComplexity,
10
11 BinaryTree,
13}
14
15pub enum Attribute {
17 BadArchAction(Action),
19
20 NoNewPrivileges(bool),
22
23 ThreadSync(bool),
25
26 NegativeSyscalls(bool),
28
29 Log(bool),
31
32 DisableSSB(bool),
34
35 Optimize(OptimizeStrategy),
37
38 ReturnSystemReturnCodes(bool),
40}
41impl Attribute {
42 pub fn name(&self) -> scmp_filter_attr {
44 match self {
45 Attribute::BadArchAction(_) => SCMP_FLTATR_ACT_BADARCH,
46 Attribute::NoNewPrivileges(_) => SCMP_FLTATR_CTL_NNP,
47 Attribute::ThreadSync(_) => SCMP_FLTATR_CTL_TSYNC,
48 Attribute::NegativeSyscalls(_) => SCMP_FLTATR_API_TSKIP,
49 Attribute::Log(_) => SCMP_FLTATR_CTL_LOG,
50 Attribute::DisableSSB(_) => SCMP_FLTATR_CTL_SSB,
51 Attribute::Optimize(_) => SCMP_FLTATR_CTL_OPTIMIZE,
52 Attribute::ReturnSystemReturnCodes(_) => SCMP_FLTATR_API_SYSRAWRC,
53 }
54 }
55
56 pub fn value(&self) -> u32 {
58 match self {
59 Attribute::BadArchAction(action) => (*action).into(),
60 Attribute::NoNewPrivileges(set) => *set as u32,
61 Attribute::ThreadSync(set) => *set as u32,
62 Attribute::NegativeSyscalls(set) => *set as u32,
63 Attribute::Log(set) => *set as u32,
64 Attribute::DisableSSB(set) => *set as u32,
65 Attribute::Optimize(strategy) => match strategy {
66 OptimizeStrategy::PriorityAndComplexity => 1,
67 OptimizeStrategy::BinaryTree => 2,
68 },
69 Attribute::ReturnSystemReturnCodes(set) => *set as u32,
70 }
71 }
72
73 pub fn str(&self) -> &'static str {
75 match self {
76 Attribute::BadArchAction(_) => "Bad Arch Action",
77 Attribute::NoNewPrivileges(_) => "No New Privileges",
78 Attribute::ThreadSync(_) => "Thread Sync",
79 Attribute::NegativeSyscalls(_) => "Negative Syscalls",
80 Attribute::Log(_) => "Log",
81 Attribute::DisableSSB(_) => "Disable SSB",
82 Attribute::Optimize(_) => "Optimize",
83 Attribute::ReturnSystemReturnCodes(_) => "Return System Return Codes",
84 }
85 }
86}
87impl fmt::Display for Attribute {
88 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
89 write!(f, "{}", self.str())
90 }
91}
92impl fmt::Debug for Attribute {
93 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
94 write!(f, "{}", self.str())
95 }
96}