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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// SPDX-License-Identifier: MIT
use std::net::IpAddr;
use super::{
PolicyDeleteRequest, PolicyFlushRequest, PolicyGetDefaultRequest, PolicyGetRequest,
PolicyGetSpdInfoRequest, PolicyModifyRequest, PolicySetDefaultRequest, PolicySetSpdInfoRequest,
};
use crate::Handle;
#[non_exhaustive]
pub struct PolicyHandle(Handle);
impl PolicyHandle {
pub fn new(handle: Handle) -> Self {
PolicyHandle(handle)
}
/// Add xfrm policy (equivalent to `ip xfrm policy add`)
pub fn add(
&self,
src_addr: IpAddr,
src_prefix_len: u8,
dst_addr: IpAddr,
dst_prefix_len: u8,
) -> PolicyModifyRequest {
PolicyModifyRequest::new(
self.0.clone(),
false,
src_addr,
src_prefix_len,
dst_addr,
dst_prefix_len,
)
}
/// Delete xfrm policy specifying selector parameters (equivalent to `ip xfrm policy delete <selector>`)
pub fn delete(
&self,
src_addr: IpAddr,
src_prefix_len: u8,
dst_addr: IpAddr,
dst_prefix_len: u8,
) -> PolicyDeleteRequest {
PolicyDeleteRequest::new(
self.0.clone(),
src_addr,
src_prefix_len,
dst_addr,
dst_prefix_len,
)
}
/// Delete xfrm policy specifying the index (equivalent to `ip xfrm policy delete index`)
pub fn delete_index(&self, index: u32) -> PolicyDeleteRequest {
PolicyDeleteRequest::new_index(self.0.clone(), index)
}
/// Flush xfrm policies (equivalent to `ip xfrm policy flush`)
pub fn flush(&self) -> PolicyFlushRequest {
PolicyFlushRequest::new(self.0.clone())
}
/// Get xfrm policy (equivalent to `ip xfrm policy get <selector>`)
pub fn get(
&self,
src_addr: IpAddr,
src_prefix_len: u8,
dst_addr: IpAddr,
dst_prefix_len: u8,
) -> PolicyGetRequest {
PolicyGetRequest::new(
self.0.clone(),
src_addr,
src_prefix_len,
dst_addr,
dst_prefix_len,
)
}
/// Get the default xfrm action for input, output, forward policies (equivalent to `ip xfrm policy getdefault`)
pub fn get_default_action(&self) -> PolicyGetDefaultRequest {
PolicyGetDefaultRequest::new(self.0.clone())
}
/// Get (dump) all xfrm policies (equivalent to `ip xfrm policy list`)
pub fn get_dump(&self) -> PolicyGetRequest {
PolicyGetRequest::new_dump(self.0.clone())
}
/// Get xfrm policy specifying the index (equivalent to `ip xfrm policy get index`)
pub fn get_index(&self, index: u32) -> PolicyGetRequest {
PolicyGetRequest::new_index(self.0.clone(), index)
}
/// Get xfrm spd statistics (equivalent to `ip xfrm policy count`)
pub fn get_spdinfo(&self) -> PolicyGetSpdInfoRequest {
PolicyGetSpdInfoRequest::new(self.0.clone())
}
/// Set the default xfrm action for input, output, forward policies (equivalent to `ip xfrm policy setdefault`)
pub fn set_default_action(
&self,
in_act: u8,
fwd_act: u8,
out_act: u8,
) -> PolicySetDefaultRequest {
PolicySetDefaultRequest::new(self.0.clone(), in_act, fwd_act, out_act)
}
/// Set xfrm spd statistics (equivalent to `ip xfrm policy set`)
pub fn set_spdinfo(&self) -> PolicySetSpdInfoRequest {
PolicySetSpdInfoRequest::new(self.0.clone())
}
/// Update xfrm policy (equivalent to `ip xfrm policy update`)
pub fn update(
&self,
src_addr: IpAddr,
src_prefix_len: u8,
dst_addr: IpAddr,
dst_prefix_len: u8,
) -> PolicyModifyRequest {
PolicyModifyRequest::new(
self.0.clone(),
true,
src_addr,
src_prefix_len,
dst_addr,
dst_prefix_len,
)
}
}