-
Notifications
You must be signed in to change notification settings - Fork 60
iptun: add support to ipip, ipip6 and ip6ip6 tunnels #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
2f4128b
to
b3e49c6
Compare
b3e49c6
to
ddc92e7
Compare
All these tunnels use the IFLA_IPTUN_* netlink API. Therefore, both IFLAN_INFO_KIND "ipip" and "ip6tnl" data is serialized using the IpTunnel struct. Unit tests added. Signed-off-by: Fernando Fernandez Mancera <[email protected]>
ddc92e7
to
ebd2c35
Compare
} | ||
|
||
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoIpTunnel { | ||
fn parse(buf: &NlaBuffer<&'a T>) -> Result<Self, DecodeError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should do ParseableParametrized
with InfoKind as argument because IFLA_IPTUN_FLAGS
has different size:
net/ipv6/ip6_tunnel.c
1992: if (data[IFLA_IPTUN_FLAGS])
1993: parms->flags = nla_get_u32(data[IFLA_IPTUN_FLAGS]);
2099: /* IFLA_IPTUN_FLAGS */
2129: nla_put_u32(skb, IFLA_IPTUN_FLAGS, parm->flags) ||
2165: [IFLA_IPTUN_FLAGS] = { .type = NLA_U32 },
net/ipv6/sit.c
1664: /* IFLA_IPTUN_FLAGS */
1704: nla_put_be16(skb, IFLA_IPTUN_FLAGS,
1744: [IFLA_IPTUN_FLAGS] = { .type = NLA_U16 },
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ffmancera , can you apply the followin patch? Thanks!
commit 88882770944e6aa034d29cf9eb2e28c41a2d33a1
Author: Wen Liang <[email protected]>
Date: Sun May 18 20:46:09 2025 -0400
fixup! iptunnel: add support to ipip, ipip6 and ip6ip6 tunnels
diff --git a/src/link/link_info/info_data.rs b/src/link/link_info/info_data.rs
index d0d902e..e26930b 100644
--- a/src/link/link_info/info_data.rs
+++ b/src/link/link_info/info_data.rs
@@ -4,7 +4,7 @@ use anyhow::Context;
use netlink_packet_utils::{
nla::{Nla, NlaBuffer, NlasIterator},
- DecodeError, Emitable, Parseable,
+ DecodeError, Emitable, Parseable, ParseableParametrized,
};
use super::super::{
@@ -362,7 +362,8 @@ impl InfoData {
let nla = &nla.context(format!(
"invalid IFLA_INFO_DATA for {kind} {payload:?}"
))?;
- let parsed = InfoIpTunnel::parse(nla)?;
+ let parsed =
+ InfoIpTunnel::parse_with_param(nla, kind.clone())?;
v.push(parsed);
}
InfoData::IpTunnel(v)
diff --git a/src/link/link_info/iptunnel.rs b/src/link/link_info/iptunnel.rs
index 7ab50f2..04af70a 100644
--- a/src/link/link_info/iptunnel.rs
+++ b/src/link/link_info/iptunnel.rs
@@ -8,7 +8,7 @@ use byteorder::{ByteOrder, NativeEndian};
use netlink_packet_utils::{
nla::{DefaultNla, Nla, NlaBuffer},
parsers::{parse_u16, parse_u32, parse_u8},
- traits::Parseable,
+ traits::{Parseable, ParseableParametrized},
DecodeError,
};
@@ -146,8 +146,13 @@ impl Nla for InfoIpTunnel {
}
}
-impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoIpTunnel {
- fn parse(buf: &NlaBuffer<&'a T>) -> Result<Self, DecodeError> {
+impl<'a, T: AsRef<[u8]> + ?Sized>
+ ParseableParametrized<NlaBuffer<&'a T>, super::InfoKind> for InfoIpTunnel
+{
+ fn parse_with_param(
+ buf: &NlaBuffer<&'a T>,
+ kind: super::InfoKind,
+ ) -> Result<Self, DecodeError> {
use self::InfoIpTunnel::*;
let payload = buf.value();
Ok(match buf.kind() {
@@ -204,9 +209,23 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoIpTunnel {
parse_u32(payload)
.context("invalid IFLA_IPTUN_FLOWINFO value")?,
),
- IFLA_IPTUN_FLAGS => Flags(TunnelFlags::from_bits_retain(
- parse_u32(payload).context("invalid IFLA_IPTUN_FLAGS value")?,
- )),
+ IFLA_IPTUN_FLAGS => match kind {
+ super::InfoKind::SitTun => {
+ // Parse as u16 for SIT tunnels
+ Flags(TunnelFlags::from_bits_retain(
+ parse_u16(payload)
+ .context("invalid IFLA_IPTUN_FLAGS value for SIT")?
+ as u32,
+ ))
+ }
+ _ => {
+ // Default: parse as u32 for other tunnel types
+ Flags(TunnelFlags::from_bits_retain(
+ parse_u32(payload)
+ .context("invalid IFLA_IPTUN_FLAGS value")?,
+ ))
+ }
+ },
IFLA_IPTUN_PROTO => Protocol(IpProtocol::from(
parse_u8(payload).context("invalid IFLA_IPTUN_PROTO value")?
as i32,
All these tunnels use the IFLA_IPTUN_* netlink API. Therefore, both IFLAN_INFO_KIND "ipip" and "ip6tnl" data is serialized using the IpTun struct.
Unit tests added.