File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
src/vmm/src/devices/virtio/net Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -270,6 +270,13 @@ pub fn if_index(tap: &Tap) -> i32 {
270
270
unsafe { ifreq. ifr_ifru . ifru_ivalue }
271
271
}
272
272
273
+
274
+ pub fn drain_tap ( tap : & Tap ) {
275
+ let mut buf = [ 0u8 ; 1024 ] ;
276
+ // SAFETY: The call is safe since the parameters are valid.
277
+ while unsafe { libc:: read ( tap. as_raw_fd ( ) , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) ) != -1 } { }
278
+ }
279
+
273
280
/// Enable the tap interface.
274
281
pub fn enable ( tap : & Tap ) {
275
282
// Disable IPv6 router advertisment requests
@@ -294,6 +301,8 @@ pub fn enable(tap: &Tap) {
294
301
)
295
302
. execute ( & sock, c_ulong:: from ( super :: gen:: sockios:: SIOCSIFFLAGS ) )
296
303
. unwrap ( ) ;
304
+ // Drain the initial packets that might be in the tap interface.
305
+ drain_tap ( tap) ;
297
306
}
298
307
299
308
#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments