Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions src/link/link_info/info_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub enum InfoData {
MacVtap(Vec<InfoMacVtap>),
GreTap(Vec<InfoGreTap>),
GreTap6(Vec<InfoGreTap6>),
SitTun(Vec<InfoIpTunnel>),
GreTun(Vec<InfoGreTun>),
GreTun6(Vec<InfoGreTun6>),
Vti(Vec<InfoVti>),
Expand Down Expand Up @@ -64,7 +63,6 @@ impl Nla for InfoData {
Self::Tun(nlas) => nlas.as_slice().buffer_len(),
Self::GreTap(nlas) => nlas.as_slice().buffer_len(),
Self::GreTap6(nlas) => nlas.as_slice().buffer_len(),
Self::SitTun(nlas) => nlas.as_slice().buffer_len(),
Self::GreTun(nlas) => nlas.as_slice().buffer_len(),
Self::GreTun6(nlas) => nlas.as_slice().buffer_len(),
Self::Vti(nlas) => nlas.as_slice().buffer_len(),
Expand Down Expand Up @@ -94,7 +92,6 @@ impl Nla for InfoData {
Self::Tun(nlas) => nlas.as_slice().emit(buffer),
Self::GreTap(nlas) => nlas.as_slice().emit(buffer),
Self::GreTap6(nlas) => nlas.as_slice().emit(buffer),
Self::SitTun(nlas) => nlas.as_slice().emit(buffer),
Self::GreTun(nlas) => nlas.as_slice().emit(buffer),
Self::GreTun6(nlas) => nlas.as_slice().emit(buffer),
Self::Vti(nlas) => nlas.as_slice().emit(buffer),
Expand Down Expand Up @@ -244,18 +241,6 @@ impl InfoData {
}
InfoData::GreTap6(v)
}
InfoKind::SitTun => {
let mut v = Vec::new();
for nla in NlasIterator::new(payload) {
let nla = &nla.context(format!(
"invalid IFLA_INFO_DATA for {kind} {payload:?}"
))?;
let parsed =
InfoIpTunnel::parse_with_param(nla, kind.clone())?;
v.push(parsed);
}
InfoData::SitTun(v)
}
InfoKind::GreTun => {
let mut v = Vec::new();
for nla in NlasIterator::new(payload) {
Expand Down Expand Up @@ -355,7 +340,7 @@ impl InfoData {
}
InfoData::Hsr(v)
}
InfoKind::IpIp | InfoKind::Ip6Tnl => {
InfoKind::IpIp | InfoKind::Ip6Tnl | InfoKind::SitTun => {
let mut v = Vec::new();
for nla in NlasIterator::new(payload) {
let nla = &nla.context(format!(
Expand Down
24 changes: 17 additions & 7 deletions src/link/link_info/iptunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub enum InfoIpTunnel {
FlowInfo(u32),
Ipv6SitFlags(u16),
Ipv4Flags(u16),
Ipv6Flags(u32),
Ipv6Flags(Ip6TunnelFlags),
Protocol(IpProtocol),
PMtuDisc(bool),
Ipv6RdPrefix(Ipv6Addr),
Expand Down Expand Up @@ -92,7 +92,7 @@ impl Nla for InfoIpTunnel {
Link(value) | FwMark(value) | FlowInfo(value) => {
emit_u32(buffer, *value).unwrap()
}
Ipv6Flags(val) => emit_u32(buffer, *val).unwrap(),
Ipv6Flags(f) => emit_u32(buffer, f.bits()).unwrap(),
Ipv6SitFlags(val) | Ipv4Flags(val) => {
emit_u16_be(buffer, *val).unwrap()
}
Expand Down Expand Up @@ -193,10 +193,12 @@ impl<'a, T: AsRef<[u8]> + ?Sized>
parse_u16_be(payload)
.context("invalid IFLA_IPTUN_FLAGS for SIT")?,
),
super::InfoKind::Ip6Tnl => InfoIpTunnel::Ipv6Flags(
parse_u32(payload)
.context("invalid IFLA_IPTUN_FLAGS for IP6")?,
),
super::InfoKind::Ip6Tnl => {
InfoIpTunnel::Ipv6Flags(Ip6TunnelFlags::from_bits_retain(
parse_u32(payload)
.context("invalid IFLA_IPTUN_FLAGS for IP6")?,
))
}
_ => {
return Err(DecodeError::from(format!(
"unsupported InfoKind for IFLA_IPTUN_FLAGS: {kind:?}"
Expand Down Expand Up @@ -354,16 +356,24 @@ const IP6_TNL_F_RCV_DSCP_COPY: u32 = 0x10;
const IP6_TNL_F_USE_ORIG_FWMARK: u32 = 0x20;
const IP6_TNL_F_ALLOW_LOCAL_REMOTE: u32 = 0x40;

const IP6_TNL_F_CAP_XMIT: u32 = 0x10000;
const IP6_TNL_F_CAP_RCV: u32 = 0x20000;
const IP6_TNL_F_CAP_PER_PACKET: u32 = 0x40000;

bitflags! {
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TunnelFlags: u32 {
pub struct Ip6TunnelFlags: u32 {
const IgnEncapLimit = IP6_TNL_F_IGN_ENCAP_LIMIT;
const UseOrigTclass = IP6_TNL_F_USE_ORIG_TCLASS;
const UseOrigFlowlabel = IP6_TNL_F_USE_ORIG_FLOWLABEL;
const Mip6Dev = IP6_TNL_F_MIP6_DEV;
const RcvDscpCopy = IP6_TNL_F_RCV_DSCP_COPY;
const UseOrigFwMark = IP6_TNL_F_USE_ORIG_FWMARK;
const AllowLocalRemote = IP6_TNL_F_ALLOW_LOCAL_REMOTE;
const CapXmit = IP6_TNL_F_CAP_XMIT;
const CapRcv = IP6_TNL_F_CAP_RCV;
const CapPerPacket = IP6_TNL_F_CAP_PER_PACKET;
const _ = !0;
}
}
4 changes: 3 additions & 1 deletion src/link/link_info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ pub use self::{
info_port::{InfoPortData, InfoPortKind, InfoVrfPort},
infos::{InfoKind, LinkInfo},
ipoib::InfoIpoib,
iptunnel::{InfoIpTunnel, TunnelEncapFlags, TunnelEncapType},
iptunnel::{
InfoIpTunnel, Ip6TunnelFlags, TunnelEncapFlags, TunnelEncapType,
},
ipvlan::{
InfoIpVlan, InfoIpVtap, IpVlanFlags, IpVlanMode, IpVtapFlags,
IpVtapMode,
Expand Down
4 changes: 2 additions & 2 deletions src/link/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ pub use self::{
InfoGreTap6, InfoGreTun, InfoGreTun6, InfoGtp, InfoHsr, InfoIpTunnel,
InfoIpVlan, InfoIpVtap, InfoIpoib, InfoKind, InfoMacSec, InfoMacVlan,
InfoMacVtap, InfoPortData, InfoPortKind, InfoTun, InfoVeth, InfoVlan,
InfoVrf, InfoVrfPort, InfoVti, InfoVxlan, InfoXfrm, IpVlanFlags,
IpVlanMode, IpVtapFlags, IpVtapMode, LinkInfo, LinkXstats,
InfoVrf, InfoVrfPort, InfoVti, InfoVxlan, InfoXfrm, Ip6TunnelFlags,
IpVlanFlags, IpVlanMode, IpVtapFlags, IpVtapMode, LinkInfo, LinkXstats,
MacSecCipherId, MacSecOffload, MacSecValidate, MacVlanMode,
MacVtapMode, MiiStatus, TunnelEncapFlags, TunnelEncapType,
VlanQosMapping,
Expand Down
16 changes: 10 additions & 6 deletions src/link/tests/iptunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use netlink_packet_core::{Emitable, Parseable};

use crate::{
link::{
InfoData, InfoIpTunnel, InfoKind, LinkAttribute, LinkFlags, LinkHeader,
LinkInfo, LinkLayerType, LinkMessage, LinkMessageBuffer,
TunnelEncapFlags, TunnelEncapType,
InfoData, InfoIpTunnel, InfoKind, Ip6TunnelFlags, LinkAttribute,
LinkFlags, LinkHeader, LinkInfo, LinkLayerType, LinkMessage,
LinkMessageBuffer, TunnelEncapFlags, TunnelEncapType,
},
AddressFamily, IpProtocol,
};
Expand Down Expand Up @@ -127,7 +127,9 @@ fn test_iptunnel_ipip6_link_info() {
InfoIpTunnel::Ttl(64),
InfoIpTunnel::EncapLimit(4),
InfoIpTunnel::FlowInfo(0),
InfoIpTunnel::Ipv6Flags(0x30000),
InfoIpTunnel::Ipv6Flags(
Ip6TunnelFlags::CapXmit | Ip6TunnelFlags::CapRcv,
),
InfoIpTunnel::Protocol(IpProtocol::Ipip),
InfoIpTunnel::FwMark(0),
InfoIpTunnel::EncapType(TunnelEncapType::None),
Expand Down Expand Up @@ -196,7 +198,9 @@ fn test_iptunnel_ip6ip6_link_info() {
InfoIpTunnel::Ttl(64),
InfoIpTunnel::EncapLimit(4),
InfoIpTunnel::FlowInfo(0),
InfoIpTunnel::Ipv6Flags(0x30000),
InfoIpTunnel::Ipv6Flags(
Ip6TunnelFlags::CapXmit | Ip6TunnelFlags::CapRcv,
),
InfoIpTunnel::Protocol(IpProtocol::Ipv6),
InfoIpTunnel::FwMark(0),
InfoIpTunnel::EncapType(TunnelEncapType::None),
Expand Down Expand Up @@ -252,7 +256,7 @@ fn test_iptunnel_sit_link_info() {
},
attributes: vec![LinkAttribute::LinkInfo(vec![
LinkInfo::Kind(InfoKind::SitTun),
LinkInfo::Data(InfoData::SitTun(vec![
LinkInfo::Data(InfoData::IpTunnel(vec![
InfoIpTunnel::Link(0),
InfoIpTunnel::Local(std::net::IpAddr::V4(
Ipv4Addr::from_str("192.168.122.183").unwrap(),
Expand Down
Loading