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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
use crate::constants::*;

/// Represent the flags field in a netlink packet header.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub struct NetlinkFlags(u16);

impl From<u16> for NetlinkFlags {
    fn from(flags: u16) -> Self {
        NetlinkFlags(flags)
    }
}

impl<'a> From<&'a NetlinkFlags> for u16 {
    fn from(flags: &'a NetlinkFlags) -> u16 {
        flags.0
    }
}

impl From<NetlinkFlags> for u16 {
    fn from(flags: NetlinkFlags) -> u16 {
        flags.0
    }
}

impl Default for NetlinkFlags {
    fn default() -> Self {
        NetlinkFlags::new()
    }
}

impl NetlinkFlags {
    /// Create a new empty flags field (no flag is set)
    pub fn new() -> Self {
        NetlinkFlags(0)
    }

    /// Set the `NLM_F_REQUEST` flag
    pub fn set_request(&mut self) -> &mut Self {
        self.0 |= NLM_F_REQUEST;
        self
    }

    /// Check if the `NLM_F_REQUEST` flag is set
    pub fn has_request(self) -> bool {
        self.0 & NLM_F_REQUEST == NLM_F_REQUEST
    }

    /// Set the `NLM_F_MULTIPART` flag
    pub fn set_multipart(&mut self) -> &mut Self {
        self.0 |= NLM_F_MULTIPART;
        self
    }
    /// Check if the `NLM_F_MULTIPART` flag is set
    pub fn has_multipart(self) -> bool {
        self.0 & NLM_F_MULTIPART == NLM_F_MULTIPART
    }

    /// Set the `NLM_F_ACK` flag
    pub fn set_ack(&mut self) -> &mut Self {
        self.0 |= NLM_F_ACK;
        self
    }
    /// Check if the `NLM_F_ACK` flag is set
    pub fn has_ack(self) -> bool {
        self.0 & NLM_F_ACK == NLM_F_ACK
    }

    /// Set the `NLM_F_ECHO` flag
    pub fn set_echo(&mut self) -> &mut Self {
        self.0 |= NLM_F_ECHO;
        self
    }
    /// Check if the `NLM_F_ECHO` flag is set
    pub fn has_echo(self) -> bool {
        self.0 & NLM_F_ECHO == NLM_F_ECHO
    }

    /// Set the `NLM_F_DUMP_INTR` flag
    pub fn set_dump_intr(&mut self) -> &mut Self {
        self.0 |= NLM_F_DUMP_INTR;
        self
    }
    /// Check if the `NLM_F_DUMP_INTR` flag is set
    pub fn has_dump_intr(self) -> bool {
        self.0 & NLM_F_DUMP_INTR == NLM_F_DUMP_INTR
    }

    /// Set the `NLM_F_DUMP_FILTERED` flag
    pub fn set_dump_filterd(&mut self) -> &mut Self {
        self.0 |= NLM_F_DUMP_FILTERED;
        self
    }
    /// Check if the `NLM_F_DUMP_FILTERED` flag is set
    pub fn has_dump_filterd(self) -> bool {
        self.0 & NLM_F_DUMP_FILTERED == NLM_F_DUMP_FILTERED
    }

    /// Set the `NLM_F_ROOT` flag
    pub fn set_root(&mut self) -> &mut Self {
        self.0 |= NLM_F_ROOT;
        self
    }
    /// Check if the `NLM_F_ROOT` flag is set
    pub fn has_root(self) -> bool {
        self.0 & NLM_F_ROOT == NLM_F_ROOT
    }

    /// Set the `NLM_F_MATCH` flag
    pub fn set_match(&mut self) -> &mut Self {
        self.0 |= NLM_F_MATCH;
        self
    }
    /// Check if the `NLM_F_MATCH` flag is set
    pub fn has_match(self) -> bool {
        self.0 & NLM_F_MATCH == NLM_F_MATCH
    }

    /// Set the `NLM_F_ATOMIC` flag
    pub fn set_atomic(&mut self) -> &mut Self {
        self.0 |= NLM_F_ATOMIC;
        self
    }
    /// Check if the `NLM_F_ATOMIC` flag is set
    pub fn has_atomic(self) -> bool {
        self.0 & NLM_F_ATOMIC == NLM_F_ATOMIC
    }

    /// Set the `NLM_F_DUMP` flag
    pub fn set_dump(&mut self) -> &mut Self {
        self.0 |= NLM_F_DUMP;
        self
    }
    /// Check if the `NLM_F_DUMP` flag is set
    pub fn has_dump(self) -> bool {
        self.0 & NLM_F_DUMP == NLM_F_DUMP
    }

    /// Set the `NLM_F_REPLACE` flag
    pub fn set_replace(&mut self) -> &mut Self {
        self.0 |= NLM_F_REPLACE;
        self
    }
    /// Check if the `NLM_F_REPLACE` flag is set
    pub fn has_replace(self) -> bool {
        self.0 & NLM_F_REPLACE == NLM_F_REPLACE
    }

    /// Set the `NLM_F_EXCL` flag
    pub fn set_excl(&mut self) -> &mut Self {
        self.0 |= NLM_F_EXCL;
        self
    }
    /// Check if the `NLM_F_EXCL` flag is set
    pub fn has_excl(self) -> bool {
        self.0 & NLM_F_EXCL == NLM_F_EXCL
    }

    /// Set the `NLM_F_CREATE` flag
    pub fn set_create(&mut self) -> &mut Self {
        self.0 |= NLM_F_CREATE;
        self
    }
    /// Check if the `NLM_F_CREATE` flag is set
    pub fn has_create(self) -> bool {
        self.0 & NLM_F_CREATE == NLM_F_CREATE
    }

    /// Set the `NLM_F_APPEND` flag
    pub fn set_append(&mut self) -> &mut Self {
        self.0 |= NLM_F_APPEND;
        self
    }
    /// Check if the `NLM_F_APPEND` flag is set
    pub fn has_append(self) -> bool {
        self.0 & NLM_F_APPEND == NLM_F_APPEND
    }

    /// Set the `NLM_F_NONREC` flag
    pub fn set_nonrec(&mut self) -> &mut Self {
        self.0 |= NLM_F_NONREC;
        self
    }
    /// Check if the `NLM_F_NONREC` flag is set
    pub fn has_nonrec(self) -> bool {
        self.0 & NLM_F_NONREC == NLM_F_NONREC
    }

    /// Set the `NLM_F_ACK_TLVS` flag
    pub fn set_ack_tvls(&mut self) -> &mut Self {
        self.0 |= NLM_F_ACK_TLVS;
        self
    }
    /// Check if the `NLM_F_ACK_TLVS` flag is set
    pub fn has_ack_tvls(self) -> bool {
        self.0 & NLM_F_ACK_TLVS == NLM_F_ACK_TLVS
    }

    /// Set the `NLM_F_CAPPED` flag
    pub fn set_capped(&mut self) -> &mut Self {
        self.0 |= NLM_F_CAPPED;
        self
    }

    /// Check if the `NLM_F_CAPPED` flag is set
    pub fn has_capped(self) -> bool {
        self.0 & NLM_F_CAPPED == NLM_F_CAPPED
    }
}