|
| 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; |
0 commit comments