@@ -28,10 +28,9 @@ use anyhow::anyhow;
28
28
use containerd_sandbox:: error:: Result ;
29
29
use futures_util:: TryStreamExt ;
30
30
use libc:: { IFF_MULTI_QUEUE , IFF_NO_PI , IFF_TAP , IFF_VNET_HDR } ;
31
- use netlink_packet_route:: {
32
- link:: nlas:: { Info , InfoData , InfoIpVlan , InfoKind , InfoMacVlan , InfoMacVtap , InfoVlan } ,
33
- nlas:: link:: InfoVxlan ,
34
- LinkMessage ,
31
+ use netlink_packet_route:: link:: {
32
+ InfoData , InfoIpVlan , InfoKind , InfoMacVlan , InfoMacVtap , InfoVlan , InfoVxlan , LinkFlag ,
33
+ LinkInfo , LinkMessage ,
35
34
} ;
36
35
use nix:: {
37
36
ioctl_read_bad, ioctl_write_ptr_bad, libc,
@@ -44,7 +43,7 @@ use serde_derive::{Deserialize, Serialize};
44
43
use crate :: {
45
44
device:: { DeviceInfo , PhysicalDeviceInfo , TapDeviceInfo , VhostUserDeviceInfo } ,
46
45
network:: {
47
- address:: { convert_to_ip_address , CniIPAddress , IpNet , MacAddress } ,
46
+ address:: { CniIPAddress , IpNet , MacAddress } ,
48
47
create_netlink_handle, execute_in_netns, run_in_new_netns,
49
48
} ,
50
49
sandbox:: KuasarSandbox ,
@@ -98,7 +97,6 @@ pub enum LinkType {
98
97
Ipvlan ( u16 ) ,
99
98
Macvlan ( u32 ) ,
100
99
Macvtap ( u32 ) ,
101
- Iptun ,
102
100
Tun ,
103
101
VhostUser ( String ) ,
104
102
Physical ( String , String ) ,
@@ -124,7 +122,6 @@ impl Display for LinkType {
124
122
LinkType :: Ipvlan ( _) => "ipvlan" . to_string ( ) ,
125
123
LinkType :: Macvlan ( _) => "macvlan" . to_string ( ) ,
126
124
LinkType :: Macvtap ( _) => "macvtap" . to_string ( ) ,
127
- LinkType :: Iptun => "iptun" . to_string ( ) ,
128
125
LinkType :: Tun => "tun" . to_string ( ) ,
129
126
LinkType :: VhostUser ( _) => "vhostuser" . to_string ( ) ,
130
127
LinkType :: Physical ( _, _) => "physical" . to_string ( ) ,
@@ -167,7 +164,6 @@ impl From<InfoData> for LinkType {
167
164
return Self :: Macvtap ( * i) ;
168
165
}
169
166
}
170
- InfoData :: IpTun ( _) => return Self :: Iptun ,
171
167
_ => return Self :: Unkonwn ,
172
168
}
173
169
Self :: Unkonwn
@@ -210,6 +206,19 @@ pub struct NetworkInterface {
210
206
pub queue : u32 ,
211
207
}
212
208
209
+ // netlink-packet-route-0.19.0/src/link/link_flag.rs:26
210
+ pub ( crate ) struct VecLinkFlag ( pub Vec < LinkFlag > ) ;
211
+
212
+ impl From < & VecLinkFlag > for u32 {
213
+ fn from ( v : & VecLinkFlag ) -> u32 {
214
+ let mut d: u32 = 0 ;
215
+ for flag in & v. 0 {
216
+ d += u32:: from ( * flag) ;
217
+ }
218
+ d
219
+ }
220
+ }
221
+
213
222
impl NetworkInterface {
214
223
pub async fn parse_from_message (
215
224
msg : LinkMessage ,
@@ -218,31 +227,31 @@ impl NetworkInterface {
218
227
handle : & Handle ,
219
228
) -> Result < Self > {
220
229
let mut intf = NetworkInterface {
221
- flags : msg. header . flags ,
230
+ flags : u32 :: from ( & VecLinkFlag ( msg. header . flags ) ) ,
222
231
index : msg. header . index ,
223
232
..NetworkInterface :: default ( )
224
233
} ;
225
- for nla in msg . nlas . into_iter ( ) {
226
- use netlink_packet_route :: nlas :: link :: Nla ;
227
- match nla {
228
- Nla :: Info ( infos) => {
234
+ use netlink_packet_route :: link :: LinkAttribute ;
235
+ for attribute in msg . attributes . into_iter ( ) {
236
+ match attribute {
237
+ LinkAttribute :: LinkInfo ( infos) => {
229
238
for info in infos {
230
- if let Info :: Data ( d) = info {
239
+ if let LinkInfo :: Data ( d) = info {
231
240
intf. r#type = d. into ( ) ;
232
- } else if let Info :: Kind ( InfoKind :: Veth ) = info {
233
- // for veth, there is no Info::Data, but SlaveKind and SlaveData
241
+ } else if let LinkInfo :: Kind ( InfoKind :: Veth ) = info {
242
+ // for veth, there is no Info::Data, but SlaveKind and SlaveData,
234
243
// so we have to get the type from Info::Kind
235
244
intf. queue = queue;
236
245
intf. r#type = LinkType :: Veth ;
237
246
}
238
247
}
239
248
}
240
- Nla :: IfName ( s) => {
249
+ LinkAttribute :: IfName ( s) => {
241
250
intf. name = s;
242
251
}
243
- Nla :: IfAlias ( a) => intf. alias = a,
244
- Nla :: Mtu ( m) => intf. mtu = m,
245
- Nla :: Address ( u) => intf. mac_address = MacAddress ( u) ,
252
+ LinkAttribute :: IfAlias ( a) => intf. alias = a,
253
+ LinkAttribute :: Mtu ( m) => intf. mtu = m,
254
+ LinkAttribute :: Address ( u) => intf. mac_address = MacAddress ( u) ,
246
255
_ => { }
247
256
}
248
257
}
@@ -252,10 +261,9 @@ impl NetworkInterface {
252
261
. set_link_index_filter ( msg. header . index )
253
262
. execute ( ) ;
254
263
while let Some ( msg) = addresses. try_next ( ) . await . map_err ( |e| anyhow ! ( e) ) ? {
255
- use netlink_packet_route:: nlas:: address:: Nla ;
256
- for nla in msg. nlas . into_iter ( ) {
257
- if let Nla :: Address ( addr) = nla {
258
- let address = convert_to_ip_address ( addr) ?;
264
+ use netlink_packet_route:: address:: AddressAttribute ;
265
+ for nla in msg. attributes . into_iter ( ) {
266
+ if let AddressAttribute :: Address ( address) = nla {
259
267
let mask_len = msg. header . prefix_len ;
260
268
if address. is_loopback ( ) {
261
269
intf. r#type = LinkType :: Loopback ;
0 commit comments