@@ -28,10 +28,9 @@ use anyhow::anyhow;
2828use containerd_sandbox:: error:: Result ;
2929use futures_util:: TryStreamExt ;
3030use 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 ,
3534} ;
3635use nix:: {
3736 ioctl_read_bad, ioctl_write_ptr_bad, libc,
@@ -44,7 +43,7 @@ use serde_derive::{Deserialize, Serialize};
4443use crate :: {
4544 device:: { DeviceInfo , PhysicalDeviceInfo , TapDeviceInfo , VhostUserDeviceInfo } ,
4645 network:: {
47- address:: { convert_to_ip_address , CniIPAddress , IpNet , MacAddress } ,
46+ address:: { CniIPAddress , IpNet , MacAddress } ,
4847 create_netlink_handle, execute_in_netns, run_in_new_netns,
4948 } ,
5049 sandbox:: KuasarSandbox ,
@@ -98,7 +97,6 @@ pub enum LinkType {
9897 Ipvlan ( u16 ) ,
9998 Macvlan ( u32 ) ,
10099 Macvtap ( u32 ) ,
101- Iptun ,
102100 Tun ,
103101 VhostUser ( String ) ,
104102 Physical ( String , String ) ,
@@ -124,7 +122,6 @@ impl Display for LinkType {
124122 LinkType :: Ipvlan ( _) => "ipvlan" . to_string ( ) ,
125123 LinkType :: Macvlan ( _) => "macvlan" . to_string ( ) ,
126124 LinkType :: Macvtap ( _) => "macvtap" . to_string ( ) ,
127- LinkType :: Iptun => "iptun" . to_string ( ) ,
128125 LinkType :: Tun => "tun" . to_string ( ) ,
129126 LinkType :: VhostUser ( _) => "vhostuser" . to_string ( ) ,
130127 LinkType :: Physical ( _, _) => "physical" . to_string ( ) ,
@@ -167,7 +164,6 @@ impl From<InfoData> for LinkType {
167164 return Self :: Macvtap ( * i) ;
168165 }
169166 }
170- InfoData :: IpTun ( _) => return Self :: Iptun ,
171167 _ => return Self :: Unkonwn ,
172168 }
173169 Self :: Unkonwn
@@ -210,6 +206,19 @@ pub struct NetworkInterface {
210206 pub queue : u32 ,
211207}
212208
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+
213222impl NetworkInterface {
214223 pub async fn parse_from_message (
215224 msg : LinkMessage ,
@@ -218,31 +227,31 @@ impl NetworkInterface {
218227 handle : & Handle ,
219228 ) -> Result < Self > {
220229 let mut intf = NetworkInterface {
221- flags : msg. header . flags ,
230+ flags : u32 :: from ( & VecLinkFlag ( msg. header . flags ) ) ,
222231 index : msg. header . index ,
223232 ..NetworkInterface :: default ( )
224233 } ;
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) => {
229238 for info in infos {
230- if let Info :: Data ( d) = info {
239+ if let LinkInfo :: Data ( d) = info {
231240 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,
234243 // so we have to get the type from Info::Kind
235244 intf. queue = queue;
236245 intf. r#type = LinkType :: Veth ;
237246 }
238247 }
239248 }
240- Nla :: IfName ( s) => {
249+ LinkAttribute :: IfName ( s) => {
241250 intf. name = s;
242251 }
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) ,
246255 _ => { }
247256 }
248257 }
@@ -252,10 +261,9 @@ impl NetworkInterface {
252261 . set_link_index_filter ( msg. header . index )
253262 . execute ( ) ;
254263 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 {
259267 let mask_len = msg. header . prefix_len ;
260268 if address. is_loopback ( ) {
261269 intf. r#type = LinkType :: Loopback ;
0 commit comments