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 {
270270 unsafe { ifreq. ifr_ifru . ifru_ivalue }
271271}
272272
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+
273280/// Enable the tap interface.
274281pub fn enable ( tap : & Tap ) {
275282 // Disable IPv6 router advertisment requests
@@ -294,6 +301,8 @@ pub fn enable(tap: &Tap) {
294301 )
295302 . execute ( & sock, c_ulong:: from ( super :: gen:: sockios:: SIOCSIFFLAGS ) )
296303 . unwrap ( ) ;
304+ // Drain the initial packets that might be in the tap interface.
305+ drain_tap ( tap) ;
297306}
298307
299308#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments