Skip to content

Commit 0d085ae

Browse files
ffmanceraliangwen12year
authored andcommitted
iptunnel: add support to ipip, ipip6 and ip6ip6 tunnels
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]>
1 parent fe678df commit 0d085ae

File tree

7 files changed

+628
-13
lines changed

7 files changed

+628
-13
lines changed

src/link/link_info/info_data.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use netlink_packet_utils::{
99

1010
use super::super::{
1111
InfoBond, InfoBridge, InfoGeneve, InfoGreTap, InfoGreTap6, InfoGreTun,
12-
InfoGreTun6, InfoGtp, InfoHsr, InfoIpVlan, InfoIpVtap, InfoIpoib, InfoKind,
13-
InfoMacSec, InfoMacVlan, InfoMacVtap, InfoSitTun, InfoTun, InfoVeth,
14-
InfoVlan, InfoVrf, InfoVti, InfoVxlan, InfoXfrm,
12+
InfoGreTun6, InfoGtp, InfoHsr, InfoIpTunnel, InfoIpVlan, InfoIpVtap,
13+
InfoIpoib, InfoKind, InfoMacSec, InfoMacVlan, InfoMacVtap, InfoSitTun,
14+
InfoTun, InfoVeth, InfoVlan, InfoVrf, InfoVti, InfoVxlan, InfoXfrm,
1515
};
1616

1717
const IFLA_INFO_DATA: u16 = 2;
@@ -42,6 +42,7 @@ pub enum InfoData {
4242
MacSec(Vec<InfoMacSec>),
4343
Hsr(Vec<InfoHsr>),
4444
Geneve(Vec<InfoGeneve>),
45+
IpTunnel(Vec<InfoIpTunnel>),
4546
Other(Vec<u8>),
4647
}
4748

@@ -71,6 +72,7 @@ impl Nla for InfoData {
7172
Self::Vti(nlas) => nlas.as_slice().buffer_len(),
7273
Self::Gtp(nlas) => nlas.as_slice().buffer_len(),
7374
Self::Geneve(nlas) => nlas.as_slice().buffer_len(),
75+
Self::IpTunnel(nlas) => nlas.as_slice().buffer_len(),
7476
Self::Other(v) => v.len(),
7577
}
7678
}
@@ -100,6 +102,7 @@ impl Nla for InfoData {
100102
Self::Vti(nlas) => nlas.as_slice().emit(buffer),
101103
Self::Gtp(nlas) => nlas.as_slice().emit(buffer),
102104
Self::Geneve(nlas) => nlas.as_slice().emit(buffer),
105+
Self::IpTunnel(nlas) => nlas.as_slice().emit(buffer),
103106
Self::Other(v) => buffer.copy_from_slice(v.as_slice()),
104107
}
105108
}
@@ -353,6 +356,17 @@ impl InfoData {
353356
}
354357
InfoData::Hsr(v)
355358
}
359+
InfoKind::IpIp | InfoKind::Ip6Tnl => {
360+
let mut v = Vec::new();
361+
for nla in NlasIterator::new(payload) {
362+
let nla = &nla.context(format!(
363+
"invalid IFLA_INFO_DATA for {kind} {payload:?}"
364+
))?;
365+
let parsed = InfoIpTunnel::parse(nla)?;
366+
v.push(parsed);
367+
}
368+
InfoData::IpTunnel(v)
369+
}
356370
InfoKind::Geneve => {
357371
let mut v = Vec::new();
358372
for nla in NlasIterator::new(payload) {

src/link/link_info/infos.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const MACVTAP: &str = "macvtap";
3131
const GRETAP: &str = "gretap";
3232
const IP6GRETAP: &str = "ip6gretap";
3333
const IPIP: &str = "ipip";
34+
const IP6TNL: &str = "ip6tnl";
3435
const SIT: &str = "sit";
3536
const GRE: &str = "gre";
3637
const IP6GRE: &str = "ip6gre";
@@ -188,7 +189,8 @@ pub enum InfoKind {
188189
MacVtap,
189190
GreTap,
190191
GreTap6,
191-
IpTun,
192+
IpIp,
193+
Ip6Tnl,
192194
SitTun,
193195
GreTun,
194196
GreTun6,
@@ -225,7 +227,8 @@ impl std::fmt::Display for InfoKind {
225227
Self::MacVtap => MACVTAP,
226228
Self::GreTap => GRETAP,
227229
Self::GreTap6 => IP6GRETAP,
228-
Self::IpTun => IPIP,
230+
Self::IpIp => IPIP,
231+
Self::Ip6Tnl => IP6TNL,
229232
Self::SitTun => SIT,
230233
Self::GreTun => GRE,
231234
Self::GreTun6 => IP6GRE,
@@ -262,7 +265,8 @@ impl Nla for InfoKind {
262265
Self::MacVtap => MACVTAP.len(),
263266
Self::GreTap => GRETAP.len(),
264267
Self::GreTap6 => IP6GRETAP.len(),
265-
Self::IpTun => IPIP.len(),
268+
Self::IpIp => IPIP.len(),
269+
Self::Ip6Tnl => IP6TNL.len(),
266270
Self::SitTun => SIT.len(),
267271
Self::GreTun => GRE.len(),
268272
Self::GreTun6 => IP6GRE.len(),
@@ -319,7 +323,8 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoKind {
319323
MACVTAP => Self::MacVtap,
320324
GRETAP => Self::GreTap,
321325
IP6GRETAP => Self::GreTap6,
322-
IPIP => Self::IpTun,
326+
IPIP => Self::IpIp,
327+
IP6TNL => Self::Ip6Tnl,
323328
SIT => Self::SitTun,
324329
GRE => Self::GreTun,
325330
IP6GRE => Self::GreTun6,

0 commit comments

Comments
 (0)