-
Notifications
You must be signed in to change notification settings - Fork 59
iptunnel: add support to ipip, ipip6 and ip6ip6 tunnels #167
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
liangwen12year
commented
May 19, 2025
669f960
to
24fa311
Compare
)?, | ||
))) | ||
} | ||
_ => { |
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.
There is no default in kernel for parsing this:
net/ipv4/ip_tunnel_core.c
1158: if (data[IFLA_IPTUN_FLAGS]) {
1161: flags = nla_get_be16(data[IFLA_IPTUN_FLAGS]);
net/ipv6/ip6_tunnel.c
1992: if (data[IFLA_IPTUN_FLAGS])
1993: parms->flags = nla_get_u32(data[IFLA_IPTUN_FLAGS]);
2104: /* IFLA_IPTUN_FLAGS */
2134: nla_put_u32(skb, IFLA_IPTUN_FLAGS, parm->flags) ||
2170: [IFLA_IPTUN_FLAGS] = { .type = NLA_U32 },
net/ipv6/sit.c
1668: /* IFLA_IPTUN_FLAGS */
1708: nla_put_be16(skb, IFLA_IPTUN_FLAGS,
1748: [IFLA_IPTUN_FLAGS] = { .type = NLA_U16 },
Always do explicit kind matching and fail for unknown kind.
src/link/link_info/iptunnel.rs
Outdated
Flags(TunnelFlags::from_bits_retain(u32::from( | ||
parse_u16(payload).context( | ||
"invalid IFLA_IPTUN_FLAGS value for SIT", | ||
)?, |
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.
Instead of storing u16 into u32.
I prefer InfoIpTunnel::Ipv6SitFlags(u16)
, InfoIpTunnel::Ipv6Flags(u32)
, InfoIpTunnel::Ipv4Flags(u16)
.
src/link/link_info/iptunnel.rs
Outdated
| Ipv6RdRelayPrefixLen(value) => { | ||
NativeEndian::write_u16(buffer, *value) | ||
} | ||
Protocol(value) => buffer[0] = i32::from(*value) as u8, |
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.
The as
is dangerous keyword because it discard data silently.
According to https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml , it is always u8.
So implement From<u8> for IpProtocol
there instead of using as
. When you do that, please fix src/rule/attribute.rs
also.
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.
Please also include unit test for ipv6 site support.
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]>
According to the IANA protocol number specification (https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml), protocol numbers are always within the u8 range. Using `as` for type conversion is dangerous because it can silently discard higher-order data, leading to bugs that are hard to detect. This change ensures all protocol number conversions are type-safe and explicit, avoiding accidental data loss and aligning the code with the protocol specification.
24fa311
to
a75e419
Compare