Skip to content

Commit a66c359

Browse files
committed
Add enum entries to InfoGreTun and InfoGreTun6
Signed-off-by: Julius Rüberg <[email protected]>
1 parent faf9d39 commit a66c359

File tree

11 files changed

+831
-202
lines changed

11 files changed

+831
-202
lines changed

src/link/link_info/gre.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/link/link_info/gre/gre_common.rs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
use std::fmt::Display;
4+
5+
const GRE_CSUM: u16 = 0x8000;
6+
const GRE_ROUTING: u16 = 0x4000;
7+
const GRE_KEY: u16 = 0x2000;
8+
const GRE_SEQ: u16 = 0x1000;
9+
const GRE_STRICT: u16 = 0x0800;
10+
const GRE_REC: u16 = 0x0700;
11+
const GRE_ACK: u16 = 0x0080;
12+
const GRE_FLAGS: u16 = 0x0078;
13+
const GRE_VERSION: u16 = 0x0007;
14+
15+
const TUNNEL_ENCAP_FLAG_CSUM: u16 = 0x0100;
16+
const TUNNEL_ENCAP_FLAG_CSUM6: u16 = 0x0200;
17+
const TUNNEL_ENCAP_FLAG_REMCSUM: u16 = 0x0400;
18+
19+
bitflags! {
20+
#[derive(Clone, Eq, PartialEq, Debug, Copy, Default)]
21+
#[non_exhaustive]
22+
pub struct GreIOFlags: u16 {
23+
const Checksum = GRE_CSUM;
24+
const Routing = GRE_ROUTING;
25+
const Key = GRE_KEY;
26+
const Seq = GRE_SEQ;
27+
const Strict0 = GRE_STRICT;
28+
const Rec = GRE_REC;
29+
const Ack = GRE_ACK;
30+
const Flags = GRE_FLAGS;
31+
const Version = GRE_VERSION;
32+
33+
const _ = !0;
34+
}
35+
36+
#[derive(Clone, Eq, PartialEq, Debug, Copy, Default)]
37+
#[non_exhaustive]
38+
pub struct GreEncapFlags: u16 {
39+
const Checksum = TUNNEL_ENCAP_FLAG_CSUM;
40+
const Checksum6 = TUNNEL_ENCAP_FLAG_CSUM6;
41+
const RemoteChecksum = TUNNEL_ENCAP_FLAG_REMCSUM;
42+
43+
const _ = !0;
44+
}
45+
}
46+
47+
const TUNNEL_ENCAP_NONE: u16 = 0;
48+
const TUNNEL_ENCAP_FOU: u16 = 1;
49+
const TUNNEL_ENCAP_GUE: u16 = 2;
50+
51+
#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
52+
#[non_exhaustive]
53+
pub enum GreEncapType {
54+
#[default]
55+
None,
56+
Fou,
57+
Gue,
58+
Other(u16),
59+
}
60+
impl From<u16> for GreEncapType {
61+
fn from(d: u16) -> Self {
62+
match d {
63+
TUNNEL_ENCAP_NONE => GreEncapType::None,
64+
TUNNEL_ENCAP_FOU => GreEncapType::Fou,
65+
TUNNEL_ENCAP_GUE => GreEncapType::Gue,
66+
_ => Self::Other(d),
67+
}
68+
}
69+
}
70+
impl From<&GreEncapType> for u16 {
71+
fn from(t: &GreEncapType) -> Self {
72+
match t {
73+
GreEncapType::None => TUNNEL_ENCAP_NONE,
74+
GreEncapType::Fou => TUNNEL_ENCAP_FOU,
75+
GreEncapType::Gue => TUNNEL_ENCAP_GUE,
76+
GreEncapType::Other(d) => *d,
77+
}
78+
}
79+
}
80+
81+
impl Display for GreEncapType {
82+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
83+
match self {
84+
GreEncapType::None => write!(f, "none"),
85+
GreEncapType::Fou => write!(f, "fou"),
86+
GreEncapType::Gue => write!(f, "gue"),
87+
GreEncapType::Other(d) => write!(f, "other({d})"),
88+
}
89+
}
90+
}
91+
92+
pub(super) const IFLA_GRE_LINK: u16 = 1;
93+
pub(super) const IFLA_GRE_IFLAGS: u16 = 2;
94+
pub(super) const IFLA_GRE_OFLAGS: u16 = 3;
95+
pub(super) const IFLA_GRE_IKEY: u16 = 4;
96+
pub(super) const IFLA_GRE_OKEY: u16 = 5;
97+
pub(super) const IFLA_GRE_LOCAL: u16 = 6;
98+
pub(super) const IFLA_GRE_REMOTE: u16 = 7;
99+
pub(super) const IFLA_GRE_TTL: u16 = 8;
100+
pub(super) const IFLA_GRE_TOS: u16 = 9;
101+
pub(super) const IFLA_GRE_PMTUDISC: u16 = 10;
102+
pub(super) const IFLA_GRE_ENCAP_LIMIT: u16 = 11;
103+
pub(super) const IFLA_GRE_FLOWINFO: u16 = 12;
104+
pub(super) const IFLA_GRE_FLAGS: u16 = 13;
105+
pub(super) const IFLA_GRE_ENCAP_TYPE: u16 = 14;
106+
pub(super) const IFLA_GRE_ENCAP_FLAGS: u16 = 15;
107+
pub(super) const IFLA_GRE_ENCAP_SPORT: u16 = 16;
108+
pub(super) const IFLA_GRE_ENCAP_DPORT: u16 = 17;
109+
pub(super) const IFLA_GRE_COLLECT_METADATA: u16 = 18;
110+
pub(super) const IFLA_GRE_FWMARK: u16 = 20;

src/link/link_info/gre/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
mod gre_common;
4+
pub mod info_gre;
5+
pub mod info_gre6;
6+
7+
pub use self::gre_common::{GreEncapFlags, GreEncapType, GreIOFlags};
8+
pub use self::info_gre::InfoGre;
9+
pub use self::info_gre6::InfoGre6;

src/link/link_info/gre6.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/link/link_info/gre_tap.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/link/link_info/gre_tap6.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/link/link_info/info_data.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use netlink_packet_utils::{
88
};
99

1010
use super::super::{
11-
InfoBond, InfoBridge, InfoGeneve, InfoGreTap, InfoGreTap6, InfoGreTun,
12-
InfoGreTun6, InfoGtp, InfoHsr, InfoIpVlan, InfoIpVtap, InfoIpoib, InfoKind,
13-
InfoMacSec, InfoMacVlan, InfoMacVtap, InfoSitTun, InfoTun, InfoVeth,
14-
InfoVlan, InfoVrf, InfoVti, InfoVxlan, InfoXfrm,
11+
InfoBond, InfoBridge, InfoGeneve, InfoGre, InfoGre6, InfoGtp, InfoHsr,
12+
InfoIpVlan, InfoIpVtap, InfoIpoib, InfoKind, InfoMacSec, InfoMacVlan,
13+
InfoMacVtap, InfoSitTun, InfoTun, InfoVeth, InfoVlan, InfoVrf, InfoVti,
14+
InfoVxlan, InfoXfrm,
1515
};
1616

1717
const IFLA_INFO_DATA: u16 = 2;
@@ -29,11 +29,11 @@ pub enum InfoData {
2929
IpVtap(Vec<InfoIpVtap>),
3030
MacVlan(Vec<InfoMacVlan>),
3131
MacVtap(Vec<InfoMacVtap>),
32-
GreTap(Vec<InfoGreTap>),
33-
GreTap6(Vec<InfoGreTap6>),
32+
GreTap(Vec<InfoGre>),
33+
GreTap6(Vec<InfoGre6>),
3434
SitTun(Vec<InfoSitTun>),
35-
GreTun(Vec<InfoGreTun>),
36-
GreTun6(Vec<InfoGreTun6>),
35+
GreTun(Vec<InfoGre>),
36+
GreTun6(Vec<InfoGre6>),
3737
Vti(Vec<InfoVti>),
3838
Vrf(Vec<InfoVrf>),
3939
Gtp(Vec<InfoGtp>),
@@ -227,7 +227,7 @@ impl InfoData {
227227
let nla = &nla.context(format!(
228228
"invalid IFLA_INFO_DATA for {kind} {payload:?}"
229229
))?;
230-
let parsed = InfoGreTap::parse(nla)?;
230+
let parsed = InfoGre::parse(nla)?;
231231
v.push(parsed);
232232
}
233233
InfoData::GreTap(v)
@@ -238,7 +238,7 @@ impl InfoData {
238238
let nla = &nla.context(format!(
239239
"invalid IFLA_INFO_DATA for {kind} {payload:?}"
240240
))?;
241-
let parsed = InfoGreTap6::parse(nla)?;
241+
let parsed = InfoGre6::parse(nla)?;
242242
v.push(parsed);
243243
}
244244
InfoData::GreTap6(v)
@@ -260,7 +260,7 @@ impl InfoData {
260260
let nla = &nla.context(format!(
261261
"invalid IFLA_INFO_DATA for {kind} {payload:?}"
262262
))?;
263-
let parsed = InfoGreTun::parse(nla)?;
263+
let parsed = InfoGre::parse(nla)?;
264264
v.push(parsed);
265265
}
266266
InfoData::GreTun(v)
@@ -271,7 +271,7 @@ impl InfoData {
271271
let nla = &nla.context(format!(
272272
"invalid IFLA_INFO_DATA for {kind} {payload:?}"
273273
))?;
274-
let parsed = InfoGreTun6::parse(nla)?;
274+
let parsed = InfoGre6::parse(nla)?;
275275
v.push(parsed);
276276
}
277277
InfoData::GreTun6(v)

src/link/link_info/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ mod bridge;
66
mod bridge_port;
77
mod geneve;
88
mod gre;
9-
mod gre6;
10-
mod gre_tap;
11-
mod gre_tap6;
129
mod gtp;
1310
mod hsr;
1411
mod info_data;
@@ -40,10 +37,9 @@ pub use self::bridge_port::{
4037
BridgePortMulticastRouter, BridgePortState, InfoBridgePort,
4138
};
4239
pub use self::geneve::{GeneveDf, InfoGeneve};
43-
pub use self::gre::InfoGreTun;
44-
pub use self::gre6::InfoGreTun6;
45-
pub use self::gre_tap::InfoGreTap;
46-
pub use self::gre_tap6::InfoGreTap6;
40+
pub use self::gre::{
41+
GreEncapFlags, GreEncapType, GreIOFlags, InfoGre, InfoGre6,
42+
};
4743
pub use self::gtp::InfoGtp;
4844
pub use self::hsr::{HsrProtocol, InfoHsr};
4945
pub use self::info_data::InfoData;

0 commit comments

Comments
 (0)