@@ -123,7 +123,6 @@ pub trait NetDevBackend: Debug + Send + Sync + AsRawFd {
123123 // if name as str no. but there should be a way to store and retrieve the interface name for persistence
124124 // set_offload ? idk, don't really understand
125125 // read and write iovec ? for sure
126- fn set_vnet_hdr_size ( & mut self , size : c_int ) -> Result < ( ) , TapError > ;
127126 // check if we can make them default implementations
128127 fn read_iovec ( & mut self , buffer : & mut [ libc:: iovec ] ) -> Result < usize , IoError > ;
129128 // heyy
@@ -133,6 +132,8 @@ pub trait NetDevBackend: Debug + Send + Sync + AsRawFd {
133132 // fetch back the NetDevBackendType from the trait
134133 fn save ( & self ) -> NetDevBackendType ;
135134 // set offload
135+ // ammar: whats the fate of offload on the socket backend ? it should be: if you know your socket backend will
136+ // handle offload, let it do that. otherwise, tell the vmm to do it itself. does qemu do that ?
136137 fn set_offload ( & self , flags : c_uint ) -> Result < ( ) , TapError > ;
137138}
138139
@@ -144,7 +145,7 @@ pub struct SocketBacked {
144145}
145146
146147impl SocketBacked {
147- pub fn new ( path : String ) -> Result < Self , std :: io :: Error > {
148+ pub fn new ( path : String ) -> Result < Self , IoError > {
148149 // open a socket and set its path to path
149150 let stream = UnixStream :: connect ( path. clone ( ) ) ?;
150151 stream. set_nonblocking ( true ) ?;
@@ -163,15 +164,6 @@ impl AsRawFd for SocketBacked {
163164}
164165
165166impl NetDevBackend for SocketBacked {
166- // if i need to make it change the header size then won't i need a mutable reference ? if i
167- // make the tap function take a mutable reference would this fuck up ownership somewhere ?
168- // nah didn't cause much damage, just needed to declare the tap as mut
169- // maybe we don't need that
170- fn set_vnet_hdr_size ( & mut self , size : c_int ) -> Result < ( ) , TapError > {
171- self . hdr_size = size;
172- Ok ( ( ) )
173- }
174-
175167 fn read_iovec ( & mut self , buffer : & mut [ libc:: iovec ] ) -> Result < usize , IoError > {
176168 let iov = buffer. as_mut_ptr ( ) ;
177169
@@ -181,6 +173,9 @@ impl NetDevBackend for SocketBacked {
181173 iov_len : unsafe { ( * iov) . iov_len - vnet_hdr_len ( ) } ,
182174 } ;
183175
176+ // ammar: we are saying this is a "Socket" backend. not a passt backend. so should we really
177+ // be having passt specific handling ? also on some level how well do we even understand passt ?
178+ // is using it as in the test the standard way even ?
184179 // create a 4 byte buffer, read the size that passt prepends into the packet and discard those
185180 // bytes. we only care about the data packets
186181 let mut len_buf = [ 0u8 ; 4 ] ;
@@ -220,13 +215,16 @@ impl NetDevBackend for SocketBacked {
220215 } ;
221216
222217 let data_iov = unsafe { * ( buffer. as_iovec_ptr ( ) ) } ;
218+ // ammar: we need to check if we have a mininum of vnet hdr len bytes
223219 let data_iov = unsafe {
224220 libc:: iovec {
225- iov_base : ( data_iov. iov_base as * mut u8 ) . add ( 12 ) as * mut core:: ffi:: c_void ,
226- iov_len : data_iov. iov_len - 12 ,
221+ iov_base : ( data_iov. iov_base as * mut u8 ) . add ( vnet_hdr_len ( ) )
222+ as * mut core:: ffi:: c_void ,
223+ iov_len : data_iov. iov_len - vnet_hdr_len ( ) ,
227224 }
228225 } ;
229226
227+ // ammar: can this function absolutely guarantee it will get one iov in the buffer
230228 let iovs: [ libc:: iovec ; 2 ] = [ size_iov, data_iov] ;
231229 iovcnt += 1 ;
232230
@@ -238,8 +236,7 @@ impl NetDevBackend for SocketBacked {
238236 }
239237
240238 fn identifier ( & self ) -> String {
241- // ammar: fix. this sucks
242- self . path . to_str ( ) . unwrap ( ) . to_string ( )
239+ self . path . display ( ) . to_string ( )
243240 }
244241
245242 fn save ( & self ) -> NetDevBackendType {
@@ -252,19 +249,7 @@ impl NetDevBackend for SocketBacked {
252249 }
253250}
254251
255- // should it be a trait or just an enum that contains both?
256252impl NetDevBackend for Tap {
257- /// Set the size of the vnet hdr.
258- // ammar: on a socket backend this would just set a field on the backing struct
259- fn set_vnet_hdr_size ( & mut self , size : c_int ) -> Result < ( ) , TapError > {
260- // SAFETY: ioctl is safe. Called with a valid tap fd, and we check the return.
261- if unsafe { ioctl_with_ref ( & self . tap_file , TUNSETVNETHDRSZ ( ) , & size) } < 0 {
262- return Err ( TapError :: SetSizeOfVnetHdr ( IoError :: last_os_error ( ) ) ) ;
263- }
264-
265- Ok ( ( ) )
266- }
267-
268253 /// Write an `IoVecBuffer` to tap
269254 fn write_iovec ( & mut self , buffer : & IoVecBuffer ) -> Result < usize , IoError > {
270255 let iovcnt = i32:: try_from ( buffer. iovec_count ( ) ) . unwrap ( ) ;
@@ -359,6 +344,16 @@ impl Tap {
359344 . unwrap_or ( IFACE_NAME_MAX_LEN ) ;
360345 std:: str:: from_utf8 ( & self . if_name [ ..len] ) . unwrap_or ( "" )
361346 }
347+
348+ /// Set the size of the vnet hdr.
349+ pub fn set_vnet_hdr_size ( & mut self , size : c_int ) -> Result < ( ) , TapError > {
350+ // SAFETY: ioctl is safe. Called with a valid tap fd, and we check the return.
351+ if unsafe { ioctl_with_ref ( & self . tap_file , TUNSETVNETHDRSZ ( ) , & size) } < 0 {
352+ return Err ( TapError :: SetSizeOfVnetHdr ( IoError :: last_os_error ( ) ) ) ;
353+ }
354+
355+ Ok ( ( ) )
356+ }
362357}
363358
364359impl AsRawFd for Tap {
0 commit comments