netlink_packet/netlink/
flags.rs1use crate::constants::*;
2
3#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
5pub struct NetlinkFlags(u16);
6
7impl From<u16> for NetlinkFlags {
8 fn from(flags: u16) -> Self {
9 NetlinkFlags(flags)
10 }
11}
12
13impl<'a> From<&'a NetlinkFlags> for u16 {
14 fn from(flags: &'a NetlinkFlags) -> u16 {
15 flags.0
16 }
17}
18
19impl From<NetlinkFlags> for u16 {
20 fn from(flags: NetlinkFlags) -> u16 {
21 flags.0
22 }
23}
24
25impl Default for NetlinkFlags {
26 fn default() -> Self {
27 NetlinkFlags::new()
28 }
29}
30
31impl NetlinkFlags {
32 pub fn new() -> Self {
34 NetlinkFlags(0)
35 }
36
37 pub fn set_request(&mut self) -> &mut Self {
39 self.0 |= NLM_F_REQUEST;
40 self
41 }
42
43 pub fn has_request(self) -> bool {
45 self.0 & NLM_F_REQUEST == NLM_F_REQUEST
46 }
47
48 pub fn set_multipart(&mut self) -> &mut Self {
50 self.0 |= NLM_F_MULTIPART;
51 self
52 }
53 pub fn has_multipart(self) -> bool {
55 self.0 & NLM_F_MULTIPART == NLM_F_MULTIPART
56 }
57
58 pub fn set_ack(&mut self) -> &mut Self {
60 self.0 |= NLM_F_ACK;
61 self
62 }
63 pub fn has_ack(self) -> bool {
65 self.0 & NLM_F_ACK == NLM_F_ACK
66 }
67
68 pub fn set_echo(&mut self) -> &mut Self {
70 self.0 |= NLM_F_ECHO;
71 self
72 }
73 pub fn has_echo(self) -> bool {
75 self.0 & NLM_F_ECHO == NLM_F_ECHO
76 }
77
78 pub fn set_dump_intr(&mut self) -> &mut Self {
80 self.0 |= NLM_F_DUMP_INTR;
81 self
82 }
83 pub fn has_dump_intr(self) -> bool {
85 self.0 & NLM_F_DUMP_INTR == NLM_F_DUMP_INTR
86 }
87
88 pub fn set_dump_filterd(&mut self) -> &mut Self {
90 self.0 |= NLM_F_DUMP_FILTERED;
91 self
92 }
93 pub fn has_dump_filterd(self) -> bool {
95 self.0 & NLM_F_DUMP_FILTERED == NLM_F_DUMP_FILTERED
96 }
97
98 pub fn set_root(&mut self) -> &mut Self {
100 self.0 |= NLM_F_ROOT;
101 self
102 }
103 pub fn has_root(self) -> bool {
105 self.0 & NLM_F_ROOT == NLM_F_ROOT
106 }
107
108 pub fn set_match(&mut self) -> &mut Self {
110 self.0 |= NLM_F_MATCH;
111 self
112 }
113 pub fn has_match(self) -> bool {
115 self.0 & NLM_F_MATCH == NLM_F_MATCH
116 }
117
118 pub fn set_atomic(&mut self) -> &mut Self {
120 self.0 |= NLM_F_ATOMIC;
121 self
122 }
123 pub fn has_atomic(self) -> bool {
125 self.0 & NLM_F_ATOMIC == NLM_F_ATOMIC
126 }
127
128 pub fn set_dump(&mut self) -> &mut Self {
130 self.0 |= NLM_F_DUMP;
131 self
132 }
133 pub fn has_dump(self) -> bool {
135 self.0 & NLM_F_DUMP == NLM_F_DUMP
136 }
137
138 pub fn set_replace(&mut self) -> &mut Self {
140 self.0 |= NLM_F_REPLACE;
141 self
142 }
143 pub fn has_replace(self) -> bool {
145 self.0 & NLM_F_REPLACE == NLM_F_REPLACE
146 }
147
148 pub fn set_excl(&mut self) -> &mut Self {
150 self.0 |= NLM_F_EXCL;
151 self
152 }
153 pub fn has_excl(self) -> bool {
155 self.0 & NLM_F_EXCL == NLM_F_EXCL
156 }
157
158 pub fn set_create(&mut self) -> &mut Self {
160 self.0 |= NLM_F_CREATE;
161 self
162 }
163 pub fn has_create(self) -> bool {
165 self.0 & NLM_F_CREATE == NLM_F_CREATE
166 }
167
168 pub fn set_append(&mut self) -> &mut Self {
170 self.0 |= NLM_F_APPEND;
171 self
172 }
173 pub fn has_append(self) -> bool {
175 self.0 & NLM_F_APPEND == NLM_F_APPEND
176 }
177
178 pub fn set_nonrec(&mut self) -> &mut Self {
180 self.0 |= NLM_F_NONREC;
181 self
182 }
183 pub fn has_nonrec(self) -> bool {
185 self.0 & NLM_F_NONREC == NLM_F_NONREC
186 }
187
188 pub fn set_ack_tvls(&mut self) -> &mut Self {
190 self.0 |= NLM_F_ACK_TLVS;
191 self
192 }
193 pub fn has_ack_tvls(self) -> bool {
195 self.0 & NLM_F_ACK_TLVS == NLM_F_ACK_TLVS
196 }
197
198 pub fn set_capped(&mut self) -> &mut Self {
200 self.0 |= NLM_F_CAPPED;
201 self
202 }
203
204 pub fn has_capped(self) -> bool {
206 self.0 & NLM_F_CAPPED == NLM_F_CAPPED
207 }
208}