netlink_packet_route/link/link_info/gre/
gre_common.rs1use std::fmt::Display;
4
5const GRE_CSUM: u16 = 0x8000;
6const GRE_ROUTING: u16 = 0x4000;
7const GRE_KEY: u16 = 0x2000;
8const GRE_SEQ: u16 = 0x1000;
9const GRE_STRICT: u16 = 0x0800;
10const GRE_REC: u16 = 0x0700;
11const GRE_ACK: u16 = 0x0080;
12const GRE_FLAGS: u16 = 0x0078;
13const GRE_VERSION: u16 = 0x0007;
14
15const TUNNEL_ENCAP_FLAG_CSUM: u16 = 0x0100;
16const TUNNEL_ENCAP_FLAG_CSUM6: u16 = 0x0200;
17const TUNNEL_ENCAP_FLAG_REMCSUM: u16 = 0x0400;
18
19bitflags! {
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
47const TUNNEL_ENCAP_NONE: u16 = 0;
48const TUNNEL_ENCAP_FOU: u16 = 1;
49const TUNNEL_ENCAP_GUE: u16 = 2;
50
51#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
52#[non_exhaustive]
53pub enum GreEncapType {
54 #[default]
55 None,
56 Fou,
57 Gue,
58 Other(u16),
59}
60impl 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}
70impl 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
81impl 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
92pub(super) const IFLA_GRE_LINK: u16 = 1;
93pub(super) const IFLA_GRE_IFLAGS: u16 = 2;
94pub(super) const IFLA_GRE_OFLAGS: u16 = 3;
95pub(super) const IFLA_GRE_IKEY: u16 = 4;
96pub(super) const IFLA_GRE_OKEY: u16 = 5;
97pub(super) const IFLA_GRE_LOCAL: u16 = 6;
98pub(super) const IFLA_GRE_REMOTE: u16 = 7;
99pub(super) const IFLA_GRE_TTL: u16 = 8;
100pub(super) const IFLA_GRE_TOS: u16 = 9;
101pub(super) const IFLA_GRE_PMTUDISC: u16 = 10;
102pub(super) const IFLA_GRE_ENCAP_LIMIT: u16 = 11;
103pub(super) const IFLA_GRE_FLOWINFO: u16 = 12;
104pub(super) const IFLA_GRE_ENCAP_TYPE: u16 = 14;
106pub(super) const IFLA_GRE_ENCAP_FLAGS: u16 = 15;
107pub(super) const IFLA_GRE_ENCAP_SPORT: u16 = 16;
108pub(super) const IFLA_GRE_ENCAP_DPORT: u16 = 17;
109pub(super) const IFLA_GRE_COLLECT_METADATA: u16 = 18;
110pub(super) const IFLA_GRE_FWMARK: u16 = 20;