File tree Expand file tree Collapse file tree 2 files changed +17
-15
lines changed
src/devices/src/virtio/net Expand file tree Collapse file tree 2 files changed +17
-15
lines changed Original file line number Diff line number Diff line change 1
1
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
- use std:: { io, result} ;
4
+ use std:: { io, mem, result} ;
5
+ use virtio_bindings:: virtio_net:: virtio_net_hdr_v1;
6
+
5
7
pub const MAX_BUFFER_SIZE : usize = 65562 ;
6
8
pub const QUEUE_SIZE : u16 = 1024 ;
7
9
pub const NUM_QUEUES : usize = 2 ;
@@ -17,6 +19,18 @@ mod unixgram;
17
19
mod unixstream;
18
20
mod worker;
19
21
22
+ fn vnet_hdr_len ( ) -> usize {
23
+ mem:: size_of :: < virtio_net_hdr_v1 > ( )
24
+ }
25
+
26
+ // This initializes to all 0 the virtio_net_hdr part of a buf and return the length of the header
27
+ // https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html#x1-2050006
28
+ fn write_virtio_net_hdr ( buf : & mut [ u8 ] ) -> usize {
29
+ let len = vnet_hdr_len ( ) ;
30
+ buf[ 0 ..len] . fill ( 0 ) ;
31
+ len
32
+ }
33
+
20
34
pub use self :: device:: Net ;
21
35
#[ derive( Debug ) ]
22
36
pub enum Error {
Original file line number Diff line number Diff line change @@ -5,27 +5,15 @@ use crate::virtio::{InterruptTransport, Queue};
5
5
6
6
use super :: backend:: { NetBackend , ReadError , WriteError } ;
7
7
use super :: device:: { FrontendError , RxError , TxError , VirtioNetBackend } ;
8
+ use super :: { vnet_hdr_len, write_virtio_net_hdr} ;
8
9
9
10
use std:: os:: fd:: AsRawFd ;
10
11
use std:: thread;
11
- use std:: { cmp, mem , result} ;
12
+ use std:: { cmp, result} ;
12
13
use utils:: epoll:: { ControlOperation , Epoll , EpollEvent , EventSet } ;
13
14
use utils:: eventfd:: EventFd ;
14
- use virtio_bindings:: virtio_net:: virtio_net_hdr_v1;
15
15
use vm_memory:: { Bytes , GuestAddress , GuestMemoryMmap } ;
16
16
17
- fn vnet_hdr_len ( ) -> usize {
18
- mem:: size_of :: < virtio_net_hdr_v1 > ( )
19
- }
20
-
21
- // This initializes to all 0 the virtio_net_hdr part of a buf and return the length of the header
22
- // https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html#x1-2050006
23
- fn write_virtio_net_hdr ( buf : & mut [ u8 ] ) -> usize {
24
- let len = vnet_hdr_len ( ) ;
25
- buf[ 0 ..len] . fill ( 0 ) ;
26
- len
27
- }
28
-
29
17
pub struct NetWorker {
30
18
queues : Vec < Queue > ,
31
19
queue_evts : Vec < EventFd > ,
You can’t perform that action at this time.
0 commit comments