Skip to content

Commit 2fac888

Browse files
committed
API break: change InfoVxlan::Df from u8 to VxlanDf enum
Signed-off-by: Gris Ge <cnfourt@gmail.com>
1 parent aad6df2 commit 2fac888

4 files changed

Lines changed: 49 additions & 11 deletions

File tree

src/link/link_info/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub use self::{
6969
vrf::InfoVrf,
7070
vti::InfoVti,
7171
vxcan::InfoVxcan,
72-
vxlan::InfoVxlan,
72+
vxlan::{InfoVxlan, VxlanDf},
7373
xfrm::InfoXfrm,
7474
xstats::LinkXstats,
7575
};

src/link/link_info/vxlan.rs

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,45 @@ const IFLA_VXLAN_LABEL: u16 = 26;
3636
const IFLA_VXLAN_GPE: u16 = 27;
3737
const IFLA_VXLAN_TTL_INHERIT: u16 = 28;
3838
const IFLA_VXLAN_DF: u16 = 29;
39+
40+
const VXLAN_DF_UNSET: u8 = 0;
41+
const VXLAN_DF_SET: u8 = 1;
42+
const VXLAN_DF_INHERIT: u8 = 2;
43+
44+
/// VxLAN Don't Fragment flag
45+
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
46+
#[non_exhaustive]
47+
pub enum VxlanDf {
48+
/// Set to 0
49+
Unset,
50+
/// Set to 1
51+
Set,
52+
/// Copy from original IP header
53+
Inherit,
54+
Other(u8),
55+
}
56+
57+
impl From<u8> for VxlanDf {
58+
fn from(d: u8) -> Self {
59+
match d {
60+
VXLAN_DF_UNSET => Self::Unset,
61+
VXLAN_DF_SET => Self::Set,
62+
VXLAN_DF_INHERIT => Self::Inherit,
63+
_ => Self::Other(d),
64+
}
65+
}
66+
}
67+
68+
impl From<VxlanDf> for u8 {
69+
fn from(d: VxlanDf) -> Self {
70+
match d {
71+
VxlanDf::Unset => VXLAN_DF_UNSET,
72+
VxlanDf::Set => VXLAN_DF_SET,
73+
VxlanDf::Inherit => VXLAN_DF_INHERIT,
74+
VxlanDf::Other(value) => value,
75+
}
76+
}
77+
}
3978
const IFLA_VXLAN_VNIFILTER: u16 = 30;
4079
const IFLA_VXLAN_LOCALBYPASS: u16 = 31;
4180
const IFLA_VXLAN_LABEL_POLICY: u16 = 32;
@@ -73,7 +112,7 @@ pub enum InfoVxlan {
73112
Gpe(bool),
74113
RemCsumNoPartial(bool),
75114
TtlInherit(bool),
76-
Df(u8),
115+
Df(VxlanDf),
77116
Vnifilter(bool),
78117
Localbypass(bool),
79118
LabelPolicy(u32),
@@ -136,9 +175,8 @@ impl Nla for InfoVxlan {
136175
Self::Gbp(_value)
137176
| Self::Gpe(_value)
138177
| Self::RemCsumNoPartial(_value) => (),
139-
Self::Tos(value) | Self::Ttl(value) | Self::Df(value) => {
140-
buffer[0] = *value
141-
}
178+
Self::Tos(value) | Self::Ttl(value) => buffer[0] = *value,
179+
Self::Df(value) => buffer[0] = u8::from(*value),
142180
Self::Vnifilter(value)
143181
| Self::Localbypass(value)
144182
| Self::Learning(value)
@@ -348,9 +386,9 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoVxlan {
348386
.context("invalid IFLA_VXLAN_REMCSUM_RX value")?
349387
> 0,
350388
),
351-
IFLA_VXLAN_DF => Self::Df(
389+
IFLA_VXLAN_DF => Self::Df(VxlanDf::from(
352390
parse_u8(payload).context("invalid IFLA_VXLAN_DF value")?,
353-
),
391+
)),
354392
IFLA_VXLAN_GBP => Self::Gbp(true),
355393
IFLA_VXLAN_GPE => Self::Gpe(true),
356394
IFLA_VXLAN_REMCSUM_NOPARTIAL => Self::RemCsumNoPartial(true),

src/link/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub use self::{
6363
MacVlanFlags, MacVlanMacAddressMode, MacVlanMode, MacVtapFlags,
6464
MacVtapMacAddressMode, MacVtapMode, MiiStatus, NetkitMode,
6565
NetkitPolicy, NetkitScrub, TunnelEncapFlags, TunnelEncapType,
66-
VlanFlags, VlanQosMapping,
66+
VlanFlags, VlanQosMapping, VxlanDf,
6767
},
6868
link_layer_type::LinkLayerType,
6969
link_mode::LinkMode,

src/link/tests/vxlan.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
AfSpecUnspec, Inet6CacheInfo, Inet6DevConf, Inet6IfaceFlags,
1414
InetDevConf, InfoData, InfoKind, InfoVxlan, LinkAttribute, LinkHeader,
1515
LinkInfo, LinkLayerType, LinkMessage, LinkMessageBuffer, LinkMode,
16-
LinkXdp, Map, State, XdpAttached,
16+
LinkXdp, Map, State, VxlanDf, XdpAttached,
1717
},
1818
AddressFamily,
1919
};
@@ -163,7 +163,7 @@ fn test_parsing_link_vxlan() {
163163
InfoVxlan::Ttl(0),
164164
InfoVxlan::TtlInherit(false),
165165
InfoVxlan::Tos(0),
166-
InfoVxlan::Df(0),
166+
InfoVxlan::Df(VxlanDf::Unset),
167167
InfoVxlan::Label(0),
168168
InfoVxlan::LabelPolicy(0),
169169
InfoVxlan::Learning(true),
@@ -411,7 +411,7 @@ fn test_parsing_link_vxlan_ipv6() {
411411
InfoVxlan::Ttl(0),
412412
InfoVxlan::TtlInherit(false),
413413
InfoVxlan::Tos(0),
414-
InfoVxlan::Df(0),
414+
InfoVxlan::Df(VxlanDf::Unset),
415415
InfoVxlan::Label(0),
416416
InfoVxlan::LabelPolicy(0),
417417
InfoVxlan::Learning(true),

0 commit comments

Comments
 (0)