Repository navigation
Conversation
cathay4t
force-pushed
the
ff/ipip_support
branch
from
April 8, 2025 05:01
2f4128b to
b3e49c6
Compare
cathay4t
reviewed
Apr 8, 2025
ffmancera
force-pushed
the
ff/ipip_support
branch
from
April 8, 2025 06:53
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 <ffmancera@riseup.net>
ffmancera
force-pushed
the
ff/ipip_support
branch
from
April 9, 2025 07:25
ddc92e7 to
ebd2c35
Compare
cathay4t
requested changes
Apr 30, 2025
| } | ||
|
|
||
| impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoIpTunnel { | ||
| fn parse(buf: &NlaBuffer<&'a T>) -> Result<Self, DecodeError> { |
Member
There was a problem hiding this comment.
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 },
Contributor
There was a problem hiding this comment.
@ffmancera , can you apply the followin patch? Thanks!
commit 88882770944e6aa034d29cf9eb2e28c41a2d33a1
Author: Wen Liang <wenliang@redhat.com>
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,
Member
|
closing in the favor of #167 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.