Skip to content

Commit 669f960

Browse files
fixup! iptunnel: add support to ipip, ipip6 and ip6ip6 tunnels
1 parent 0d085ae commit 669f960

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/link/link_info/info_data.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use anyhow::Context;
44

55
use netlink_packet_utils::{
66
nla::{Nla, NlaBuffer, NlasIterator},
7-
DecodeError, Emitable, Parseable,
7+
DecodeError, Emitable, Parseable, ParseableParametrized,
88
};
99

1010
use super::super::{
@@ -362,7 +362,8 @@ impl InfoData {
362362
let nla = &nla.context(format!(
363363
"invalid IFLA_INFO_DATA for {kind} {payload:?}"
364364
))?;
365-
let parsed = InfoIpTunnel::parse(nla)?;
365+
let parsed =
366+
InfoIpTunnel::parse_with_param(nla, kind.clone())?;
366367
v.push(parsed);
367368
}
368369
InfoData::IpTunnel(v)

src/link/link_info/iptunnel.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use byteorder::{ByteOrder, NativeEndian};
88
use netlink_packet_utils::{
99
nla::{DefaultNla, Nla, NlaBuffer},
1010
parsers::{parse_u16, parse_u32, parse_u8},
11-
traits::Parseable,
11+
traits::{Parseable, ParseableParametrized},
1212
DecodeError,
1313
};
1414

@@ -146,8 +146,13 @@ impl Nla for InfoIpTunnel {
146146
}
147147
}
148148

149-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoIpTunnel {
150-
fn parse(buf: &NlaBuffer<&'a T>) -> Result<Self, DecodeError> {
149+
impl<'a, T: AsRef<[u8]> + ?Sized>
150+
ParseableParametrized<NlaBuffer<&'a T>, super::InfoKind> for InfoIpTunnel
151+
{
152+
fn parse_with_param(
153+
buf: &NlaBuffer<&'a T>,
154+
kind: super::InfoKind,
155+
) -> Result<Self, DecodeError> {
151156
use self::InfoIpTunnel::*;
152157
let payload = buf.value();
153158
Ok(match buf.kind() {
@@ -202,9 +207,23 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoIpTunnel {
202207
parse_u32(payload)
203208
.context("invalid IFLA_IPTUN_FLOWINFO value")?,
204209
),
205-
IFLA_IPTUN_FLAGS => Flags(TunnelFlags::from_bits_retain(
206-
parse_u32(payload).context("invalid IFLA_IPTUN_FLAGS value")?,
207-
)),
210+
IFLA_IPTUN_FLAGS => match kind {
211+
super::InfoKind::SitTun => {
212+
// Parse as u16 for SIT tunnels
213+
Flags(TunnelFlags::from_bits_retain(
214+
parse_u16(payload)
215+
.context("invalid IFLA_IPTUN_FLAGS value for SIT")?
216+
as u32,
217+
))
218+
}
219+
_ => {
220+
// Default: parse as u32 for other tunnel types
221+
Flags(TunnelFlags::from_bits_retain(
222+
parse_u32(payload)
223+
.context("invalid IFLA_IPTUN_FLAGS value")?,
224+
))
225+
}
226+
},
208227
IFLA_IPTUN_PROTO => Protocol(IpProtocol::from(
209228
parse_u8(payload).context("invalid IFLA_IPTUN_PROTO value")?
210229
as i32,

0 commit comments

Comments
 (0)