Skip to content

Commit 1418939

Browse files
committed
link: vxlan: Change Gbp, Gpe, RemCsumNoPartial to bool
Signed-off-by: Gris Ge <[email protected]>
1 parent c993811 commit 1418939

File tree

1 file changed

+129
-117
lines changed

1 file changed

+129
-117
lines changed

src/link/link_info/vxlan.rs

Lines changed: 129 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ pub enum InfoVxlan {
6868
UDPZeroCsumRX(bool),
6969
RemCsumTX(bool),
7070
RemCsumRX(bool),
71-
Gbp(u8),
72-
Gpe(u8),
73-
RemCsumNoPartial(u8),
71+
Gbp(bool),
72+
Gpe(bool),
73+
RemCsumNoPartial(bool),
7474
TtlInherit(bool),
7575
Df(u8),
7676
Vnifilter(bool),
@@ -80,151 +80,168 @@ pub enum InfoVxlan {
8080

8181
impl Nla for InfoVxlan {
8282
fn value_len(&self) -> usize {
83-
use self::InfoVxlan::*;
84-
match *self {
85-
Tos(_) | Ttl(_) | Learning(_) | Proxy(_) | Rsc(_) | L2Miss(_)
86-
| L3Miss(_) | CollectMetadata(_) | UDPCsum(_)
87-
| UDPZeroCsumTX(_) | UDPZeroCsumRX(_) | RemCsumTX(_)
88-
| RemCsumRX(_) | Gbp(_) | Gpe(_) | RemCsumNoPartial(_)
89-
| TtlInherit(_) | Df(_) | Vnifilter(_) | Localbypass(_) => 1,
90-
Port(_) => 2,
91-
Id(_) | Label(_) | Link(_) | Ageing(_) | Limit(_)
92-
| PortRange(_) => 4,
93-
Local(ref bytes) | Local6(ref bytes) | Group(ref bytes)
94-
| Group6(ref bytes) => bytes.len(),
95-
Other(ref nla) => nla.value_len(),
83+
match self {
84+
Self::Tos(_)
85+
| Self::Ttl(_)
86+
| Self::Learning(_)
87+
| Self::Proxy(_)
88+
| Self::Rsc(_)
89+
| Self::L2Miss(_)
90+
| Self::L3Miss(_)
91+
| Self::CollectMetadata(_)
92+
| Self::UDPCsum(_)
93+
| Self::UDPZeroCsumTX(_)
94+
| Self::UDPZeroCsumRX(_)
95+
| Self::RemCsumTX(_)
96+
| Self::RemCsumRX(_)
97+
| Self::TtlInherit(_)
98+
| Self::Df(_)
99+
| Self::Vnifilter(_)
100+
| Self::Localbypass(_) => 1,
101+
Self::Gbp(_) | Self::Gpe(_) | Self::RemCsumNoPartial(_) => 0,
102+
Self::Port(_) => 2,
103+
Self::Id(_)
104+
| Self::Label(_)
105+
| Self::Link(_)
106+
| Self::Ageing(_)
107+
| Self::Limit(_)
108+
| Self::PortRange(_) => 4,
109+
Self::Local(bytes)
110+
| Self::Local6(bytes)
111+
| Self::Group(bytes)
112+
| Self::Group6(bytes) => bytes.len(),
113+
Self::Other(nla) => nla.value_len(),
96114
}
97115
}
98116

99117
fn emit_value(&self, buffer: &mut [u8]) {
100-
use self::InfoVxlan::*;
101118
match self {
102-
Id(ref value) | Label(ref value) | Link(ref value)
103-
| Ageing(ref value) | Limit(ref value) => {
104-
NativeEndian::write_u32(buffer, *value)
119+
Self::Id(value)
120+
| Self::Label(value)
121+
| Self::Link(value)
122+
| Self::Ageing(value)
123+
| Self::Limit(value) => NativeEndian::write_u32(buffer, *value),
124+
Self::Gbp(_value)
125+
| Self::Gpe(_value)
126+
| Self::RemCsumNoPartial(_value) => (),
127+
Self::Tos(value) | Self::Ttl(value) | Self::Df(value) => {
128+
buffer[0] = *value
105129
}
106-
Tos(ref value)
107-
| Gbp(ref value)
108-
| Gpe(ref value)
109-
| RemCsumNoPartial(ref value)
110-
| Ttl(ref value)
111-
| Df(ref value) => buffer[0] = *value,
112-
Vnifilter(ref value)
113-
| Localbypass(ref value)
114-
| Learning(ref value)
115-
| Proxy(ref value)
116-
| Rsc(ref value)
117-
| L2Miss(ref value)
118-
| L3Miss(ref value)
119-
| CollectMetadata(ref value)
120-
| UDPCsum(ref value)
121-
| UDPZeroCsumTX(ref value)
122-
| UDPZeroCsumRX(ref value)
123-
| RemCsumTX(ref value)
124-
| RemCsumRX(ref value)
125-
| TtlInherit(ref value) => buffer[0] = *value as u8,
126-
Local(ref value) | Group(ref value) | Group6(ref value)
127-
| Local6(ref value) => buffer.copy_from_slice(value.as_slice()),
128-
Port(ref value) => BigEndian::write_u16(buffer, *value),
129-
PortRange(ref range) => {
130+
Self::Vnifilter(value)
131+
| Self::Localbypass(value)
132+
| Self::Learning(value)
133+
| Self::Proxy(value)
134+
| Self::Rsc(value)
135+
| Self::L2Miss(value)
136+
| Self::L3Miss(value)
137+
| Self::CollectMetadata(value)
138+
| Self::UDPCsum(value)
139+
| Self::UDPZeroCsumTX(value)
140+
| Self::UDPZeroCsumRX(value)
141+
| Self::RemCsumTX(value)
142+
| Self::RemCsumRX(value)
143+
| Self::TtlInherit(value) => buffer[0] = *value as u8,
144+
Self::Local(value)
145+
| Self::Group(value)
146+
| Self::Group6(value)
147+
| Self::Local6(value) => buffer.copy_from_slice(value.as_slice()),
148+
Self::Port(value) => BigEndian::write_u16(buffer, *value),
149+
Self::PortRange(range) => {
130150
BigEndian::write_u16(buffer, range.0);
131151
BigEndian::write_u16(&mut buffer[2..], range.1)
132152
}
133-
Other(ref nla) => nla.emit_value(buffer),
153+
Self::Other(nla) => nla.emit_value(buffer),
134154
}
135155
}
136156

137157
fn kind(&self) -> u16 {
138-
use self::InfoVxlan::*;
139-
140158
match self {
141-
Id(_) => IFLA_VXLAN_ID,
142-
Group(_) => IFLA_VXLAN_GROUP,
143-
Group6(_) => IFLA_VXLAN_GROUP6,
144-
Link(_) => IFLA_VXLAN_LINK,
145-
Local(_) => IFLA_VXLAN_LOCAL,
146-
Local6(_) => IFLA_VXLAN_LOCAL6,
147-
Tos(_) => IFLA_VXLAN_TOS,
148-
Ttl(_) => IFLA_VXLAN_TTL,
149-
Label(_) => IFLA_VXLAN_LABEL,
150-
Learning(_) => IFLA_VXLAN_LEARNING,
151-
Ageing(_) => IFLA_VXLAN_AGEING,
152-
Limit(_) => IFLA_VXLAN_LIMIT,
153-
PortRange(_) => IFLA_VXLAN_PORT_RANGE,
154-
Proxy(_) => IFLA_VXLAN_PROXY,
155-
Rsc(_) => IFLA_VXLAN_RSC,
156-
L2Miss(_) => IFLA_VXLAN_L2MISS,
157-
L3Miss(_) => IFLA_VXLAN_L3MISS,
158-
CollectMetadata(_) => IFLA_VXLAN_COLLECT_METADATA,
159-
Port(_) => IFLA_VXLAN_PORT,
160-
UDPCsum(_) => IFLA_VXLAN_UDP_CSUM,
161-
UDPZeroCsumTX(_) => IFLA_VXLAN_UDP_ZERO_CSUM6_TX,
162-
UDPZeroCsumRX(_) => IFLA_VXLAN_UDP_ZERO_CSUM6_RX,
163-
RemCsumTX(_) => IFLA_VXLAN_REMCSUM_TX,
164-
RemCsumRX(_) => IFLA_VXLAN_REMCSUM_RX,
165-
Gbp(_) => IFLA_VXLAN_GBP,
166-
Gpe(_) => IFLA_VXLAN_GPE,
167-
RemCsumNoPartial(_) => IFLA_VXLAN_REMCSUM_NOPARTIAL,
168-
TtlInherit(_) => IFLA_VXLAN_TTL_INHERIT,
169-
Df(_) => IFLA_VXLAN_DF,
170-
Vnifilter(_) => IFLA_VXLAN_VNIFILTER,
171-
Localbypass(_) => IFLA_VXLAN_LOCALBYPASS,
172-
Other(nla) => nla.kind(),
159+
Self::Id(_) => IFLA_VXLAN_ID,
160+
Self::Group(_) => IFLA_VXLAN_GROUP,
161+
Self::Group6(_) => IFLA_VXLAN_GROUP6,
162+
Self::Link(_) => IFLA_VXLAN_LINK,
163+
Self::Local(_) => IFLA_VXLAN_LOCAL,
164+
Self::Local6(_) => IFLA_VXLAN_LOCAL6,
165+
Self::Tos(_) => IFLA_VXLAN_TOS,
166+
Self::Ttl(_) => IFLA_VXLAN_TTL,
167+
Self::Label(_) => IFLA_VXLAN_LABEL,
168+
Self::Learning(_) => IFLA_VXLAN_LEARNING,
169+
Self::Ageing(_) => IFLA_VXLAN_AGEING,
170+
Self::Limit(_) => IFLA_VXLAN_LIMIT,
171+
Self::PortRange(_) => IFLA_VXLAN_PORT_RANGE,
172+
Self::Proxy(_) => IFLA_VXLAN_PROXY,
173+
Self::Rsc(_) => IFLA_VXLAN_RSC,
174+
Self::L2Miss(_) => IFLA_VXLAN_L2MISS,
175+
Self::L3Miss(_) => IFLA_VXLAN_L3MISS,
176+
Self::CollectMetadata(_) => IFLA_VXLAN_COLLECT_METADATA,
177+
Self::Port(_) => IFLA_VXLAN_PORT,
178+
Self::UDPCsum(_) => IFLA_VXLAN_UDP_CSUM,
179+
Self::UDPZeroCsumTX(_) => IFLA_VXLAN_UDP_ZERO_CSUM6_TX,
180+
Self::UDPZeroCsumRX(_) => IFLA_VXLAN_UDP_ZERO_CSUM6_RX,
181+
Self::RemCsumTX(_) => IFLA_VXLAN_REMCSUM_TX,
182+
Self::RemCsumRX(_) => IFLA_VXLAN_REMCSUM_RX,
183+
Self::Gbp(_) => IFLA_VXLAN_GBP,
184+
Self::Gpe(_) => IFLA_VXLAN_GPE,
185+
Self::RemCsumNoPartial(_) => IFLA_VXLAN_REMCSUM_NOPARTIAL,
186+
Self::TtlInherit(_) => IFLA_VXLAN_TTL_INHERIT,
187+
Self::Df(_) => IFLA_VXLAN_DF,
188+
Self::Vnifilter(_) => IFLA_VXLAN_VNIFILTER,
189+
Self::Localbypass(_) => IFLA_VXLAN_LOCALBYPASS,
190+
Self::Other(nla) => nla.kind(),
173191
}
174192
}
175193
}
176194

177195
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoVxlan {
178196
fn parse(buf: &NlaBuffer<&'a T>) -> Result<Self, DecodeError> {
179-
use self::InfoVxlan::*;
180197
let payload = buf.value();
181198
Ok(match buf.kind() {
182199
IFLA_VXLAN_ID => {
183-
Id(parse_u32(payload).context("invalid IFLA_VXLAN_ID value")?)
200+
Self::Id(parse_u32(payload).context("invalid IFLA_VXLAN_ID value")?)
184201
}
185-
IFLA_VXLAN_GROUP => Group(payload.to_vec()),
186-
IFLA_VXLAN_GROUP6 => Group6(payload.to_vec()),
187-
IFLA_VXLAN_LINK => Link(
202+
IFLA_VXLAN_GROUP => Self::Group(payload.to_vec()),
203+
IFLA_VXLAN_GROUP6 => Self::Group6(payload.to_vec()),
204+
IFLA_VXLAN_LINK => Self::Link(
188205
parse_u32(payload).context("invalid IFLA_VXLAN_LINK value")?,
189206
),
190-
IFLA_VXLAN_LOCAL => Local(payload.to_vec()),
191-
IFLA_VXLAN_LOCAL6 => Local6(payload.to_vec()),
207+
IFLA_VXLAN_LOCAL => Self::Local(payload.to_vec()),
208+
IFLA_VXLAN_LOCAL6 => Self::Local6(payload.to_vec()),
192209
IFLA_VXLAN_TOS => {
193-
Tos(parse_u8(payload)
210+
Self::Tos(parse_u8(payload)
194211
.context("invalid IFLA_VXLAN_TOS value")?)
195212
}
196213
IFLA_VXLAN_TTL => {
197-
Ttl(parse_u8(payload)
214+
Self::Ttl(parse_u8(payload)
198215
.context("invalid IFLA_VXLAN_TTL value")?)
199216
}
200-
IFLA_VXLAN_LABEL => Label(
217+
IFLA_VXLAN_LABEL => Self::Label(
201218
parse_u32(payload).context("invalid IFLA_VXLAN_LABEL value")?,
202219
),
203-
IFLA_VXLAN_LEARNING => Learning(
220+
IFLA_VXLAN_LEARNING => Self::Learning(
204221
parse_u8(payload)
205222
.context("invalid IFLA_VXLAN_LEARNING value")? > 0,
206223
),
207-
IFLA_VXLAN_AGEING => Ageing(
224+
IFLA_VXLAN_AGEING => Self::Ageing(
208225
parse_u32(payload)
209226
.context("invalid IFLA_VXLAN_AGEING value")?,
210227
),
211-
IFLA_VXLAN_LIMIT => Limit(
228+
IFLA_VXLAN_LIMIT => Self::Limit(
212229
parse_u32(payload).context("invalid IFLA_VXLAN_LIMIT value")?,
213230
),
214-
IFLA_VXLAN_PROXY => Proxy(
231+
IFLA_VXLAN_PROXY => Self::Proxy(
215232
parse_u8(payload).context("invalid IFLA_VXLAN_PROXY value")? > 0,
216233
),
217234
IFLA_VXLAN_RSC => {
218-
Rsc(parse_u8(payload)
235+
Self::Rsc(parse_u8(payload)
219236
.context("invalid IFLA_VXLAN_RSC value")?> 0)
220237
}
221-
IFLA_VXLAN_L2MISS => L2Miss(
238+
IFLA_VXLAN_L2MISS => Self::L2Miss(
222239
parse_u8(payload).context("invalid IFLA_VXLAN_L2MISS value")? > 0,
223240
),
224-
IFLA_VXLAN_L3MISS => L3Miss(
241+
IFLA_VXLAN_L3MISS => Self::L3Miss(
225242
parse_u8(payload).context("invalid IFLA_VXLAN_L3MISS value")? > 0,
226243
),
227-
IFLA_VXLAN_COLLECT_METADATA => CollectMetadata(
244+
IFLA_VXLAN_COLLECT_METADATA => Self::CollectMetadata(
228245
parse_u8(payload)
229246
.context("invalid IFLA_VXLAN_COLLECT_METADATA value")? >0,
230247
),
@@ -235,60 +252,55 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoVxlan {
235252
}
236253
let low = parse_u16_be(&payload[0..2]).context(err)?;
237254
let high = parse_u16_be(&payload[2..]).context(err)?;
238-
PortRange((low, high))
255+
Self::PortRange((low, high))
239256
}
240-
IFLA_VXLAN_PORT => Port(
257+
IFLA_VXLAN_PORT => Self::Port(
241258
parse_u16_be(payload)
242259
.context("invalid IFLA_VXLAN_PORT value")?,
243260
),
244-
IFLA_VXLAN_UDP_CSUM => UDPCsum(
261+
IFLA_VXLAN_UDP_CSUM => Self::UDPCsum(
245262
parse_u8(payload)
246263
.context("invalid IFLA_VXLAN_UDP_CSUM value")? > 0,
247264
),
248-
IFLA_VXLAN_UDP_ZERO_CSUM6_TX => UDPZeroCsumTX(
265+
IFLA_VXLAN_UDP_ZERO_CSUM6_TX => Self::UDPZeroCsumTX(
249266
parse_u8(payload)
250267
.context("invalid IFLA_VXLAN_UDP_ZERO_CSUM6_TX value")? > 0,
251268
),
252-
IFLA_VXLAN_UDP_ZERO_CSUM6_RX => UDPZeroCsumRX(
269+
IFLA_VXLAN_UDP_ZERO_CSUM6_RX => Self::UDPZeroCsumRX(
253270
parse_u8(payload)
254271
.context("invalid IFLA_VXLAN_UDP_ZERO_CSUM6_RX value")? > 0,
255272
),
256-
IFLA_VXLAN_REMCSUM_TX => RemCsumTX(
273+
IFLA_VXLAN_REMCSUM_TX => Self::RemCsumTX(
257274
parse_u8(payload)
258275
.context("invalid IFLA_VXLAN_REMCSUM_TX value")? > 0,
259276
),
260-
IFLA_VXLAN_REMCSUM_RX => RemCsumRX(
277+
IFLA_VXLAN_REMCSUM_RX => Self::RemCsumRX(
261278
parse_u8(payload)
262279
.context("invalid IFLA_VXLAN_REMCSUM_RX value")? > 0,
263280
),
264281
IFLA_VXLAN_DF => {
265-
Df(parse_u8(payload).context("invalid IFLA_VXLAN_DF value")?)
282+
Self::Df(parse_u8(payload).context("invalid IFLA_VXLAN_DF value")?)
266283
}
267284
IFLA_VXLAN_GBP => {
268-
Gbp(parse_u8(payload)
269-
.context("invalid IFLA_VXLAN_GBP value")?)
285+
Self::Gbp(true)
270286
}
271287
IFLA_VXLAN_GPE => {
272-
Gpe(parse_u8(payload)
273-
.context("invalid IFLA_VXLAN_GPE value")?)
288+
Self::Gpe(true)
274289
}
275-
IFLA_VXLAN_REMCSUM_NOPARTIAL => RemCsumNoPartial(
276-
parse_u8(payload)
277-
.context("invalid IFLA_VXLAN_REMCSUM_NO_PARTIAL")?,
278-
),
279-
IFLA_VXLAN_TTL_INHERIT => TtlInherit(
290+
IFLA_VXLAN_REMCSUM_NOPARTIAL => Self::RemCsumNoPartial(true),
291+
IFLA_VXLAN_TTL_INHERIT => Self::TtlInherit(
280292
parse_u8(payload)
281293
.context("invalid IFLA_VXLAN_TTL_INHERIT value")? > 0,
282294
),
283-
IFLA_VXLAN_VNIFILTER => Vnifilter(
295+
IFLA_VXLAN_VNIFILTER => Self::Vnifilter(
284296
parse_u8(payload)
285297
.context("invalid IFLA_VXLAN_VNIFILTER value")? > 0,
286298
),
287-
IFLA_VXLAN_LOCALBYPASS => Localbypass(
299+
IFLA_VXLAN_LOCALBYPASS => Self::Localbypass(
288300
parse_u8(payload)
289301
.context("invalid IFLA_VXLAN_LOCALBYPASS value")? > 0,
290302
),
291-
unknown_kind => Other(DefaultNla::parse(buf).context(format!(
303+
unknown_kind => Self::Other(DefaultNla::parse(buf).context(format!(
292304
"Failed to parse IFLA_INFO_DATA(vxlan) NLA type: {unknown_kind} as DefaultNla"
293305
))?),
294306
})

0 commit comments

Comments
 (0)