~/bend-docscommunity

src/virtio/net.bend checks

raw source on the hub · import 0x2324e729258ea5021b37b97947af4c3f/src/virtio/net.bend as Net

6 imports
import Base
import ../lib/u64.bend as U
import ../lib/bytes.bend as B
import ../vmm/abi.bend as V
import ./queue.bend as Q
import ../net/wire.bend as W

Types

type NetTx source · line 32 · raw

Data

type NetRx source · line 35 · raw

Data

Definitions

def Net.config source · line 38 · raw

@mac:List<&2, U32> -> List<&2, U32>

def Net.hdr source · line 42 · raw

List<&2, U32>

The virtio_net_hdr the device writes: all zeros but num_buffers = 1.

def Net.room source · line 46 · raw

@ds:List<&2, 0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Desc> -> U32

The total length of a chain's writable descriptors.

def Net.keep source · line 55 · raw

@+bs:List<&2, U32> -> @+acc:List<&2, List<&2, U32>> -> List<&2, List<&2, U32>>

Prepends the frame in a chain's readable bytes to acc (newest first), when the bytes are longer than the header.

def Net.tcp_split source · line 61 · raw

@+bs:List<&2, U32> -> Pair(Nat, Nat)

The lengths of a frame's Ethernet, IPv4 and TCP headers and of its TCP payload, from its first bytes bs; (0, 0) when it is no TCP segment with data (or its headers pass bs).

def Net.max_tx source · line 72 · raw

U32

The most bytes of a plain frame read through Bend: a 64 KiB TSO segment with its Ethernet header (65550), after the 12-byte virtio_net_hdr. The rest of a longer chain is dropped.

def Net.tx.staged source · line 77 · raw

@-R:Type -> @short:Bool -> @+ss:List<&2, 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Iov> -> @+hl:Nat -> @q:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq -> @+h:U32 -> @hb:List<&2, U32> -> @acc:List<&2, List<&2, U32>> -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, Pair(0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq, List<&2, List<&2, U32>>)>

A TCP segment's payload pieces ss, staged on the host unless the chain is shorter than the IPv4 header says (short): such a frame is dropped.

def Net.tx.stage source · line 96 · raw

@-R:Type -> @plain:Bool -> @+hl:Nat -> @+pl:Nat -> @q:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq -> @+h:U32 -> @+r:List<&2, 0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Desc> -> @hb:List<&2, U32> -> @acc:List<&2, List<&2, U32>> -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, Pair(0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq, List<&2, List<&2, U32>>)>

A chain whose frame is a TCP segment with data (pl bytes after hl bytes of headers): the payload is staged on the host (V.Op.stage) before the chain goes back to the guest, and the frame keeps only the headers (W.Wire.staged_frame); a chain shorter than that is dropped. Any other frame is gathered, at most Net.max_tx() bytes of it.

def Net.tx.split source · line 110 · raw

@-R:Type -> @sp:Pair(Nat, Nat) -> @q:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq -> @+h:U32 -> @+r:List<&2, 0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Desc> -> @hb:List<&2, U32> -> @acc:List<&2, List<&2, U32>> -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, Pair(0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq, List<&2, List<&2, U32>>)>

def Net.tx.serve source · line 120 · raw

@-R:Type -> @q:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq -> @c:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Chain -> @acc:List<&2, List<&2, U32>> -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, Pair(0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq, List<&2, List<&2, U32>>)>

One transmit chain: its frame kept (TCP data staged on the host), the chain pushed used with length 0. Only the first 146 bytes (the virtio_net_hdr and the headers) are read through Bend.

def Net.tx.done source · line 129 · raw

@-R:Type -> @q:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq -> @acc:List<&2, List<&2, U32>> -> @used:Bool -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, NetTx>

def Net.tx.step source · line 134 · raw

@-R:Type -> @r:Pair(0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq, Maybe<&2, 0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Chain>) -> @acc:List<&2, List<&2, U32>> -> @used:Bool -> @k:(@_:Pair(0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq, List<&2, List<&2, U32>>) -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, NetTx>) -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, NetTx>

After a pop: stops on an empty queue, else serves the chain and continues with k.

def Net.tx.go source · line 146 · raw

@fuel:Nat -> @-R:Type -> @st:Pair(0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq, List<&2, List<&2, U32>>) -> @used:Bool -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, NetTx>

Pops and serves transmit chains, at most fuel of them; st is the queue and the frames so far (newest first).

def Net.host_hdr_of source · line 162 · raw

@+size:U32 -> @+hlen:U32 -> @+len:U32 -> List<&2, U32>

The virtio_net_hdr of a host frame whose headers are hlen bytes and whose payload is len bytes, which the guest takes as TCP segments of size bytes (the guest's MSS, W.Wire.host_seg).

def Net.host_hdr source · line 168 · raw

@+hlen:U32 -> @+len:U32 -> List<&2, U32>

The same, in 1460-byte segments.

def Net.rx.deliver.host source · line 174 · raw

@-R:Type -> @q:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq -> @+h:U32 -> @+w:List<&2, 0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Desc> -> @frame:List<&2, U32> -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, 0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq>

A host frame [256, conn, off, len, headers...] over a receive chain: the virtio_net_hdr and the headers through Bend, then the payload from the host straight into the memory after them.

def Net.rx.deliver.go source · line 185 · raw

@-R:Type -> @host:Bool -> @q:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq -> @+h:U32 -> @+w:List<&2, 0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Desc> -> @+frame:List<&2, U32> -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, 0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq>

def Net.rx.deliver source · line 197 · raw

@-R:Type -> @q:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq -> @c:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Chain -> @+frame:List<&2, U32> -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, 0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq>

Writes the header and the frame over a receive chain and pushes it used with 12 + frame length (a host frame: its headers and payload).

def Net.size source · line 204 · raw

@host:Bool -> @+frame:List<&2, U32> -> Nat

The bytes a frame takes in a receive buffer after the virtio_net_hdr: a host frame's headers and payload.

def Net.rx.fits source · line 212 · raw

@c:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Chain -> @+frame:List<&2, U32> -> Bool

Whether the header and the frame fit the chain's writable room.

def Net.rx.drop source · line 219 · raw

@-R:Type -> @host:Bool -> @q0:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq -> @used:Bool -> @k:(@_:Pair(0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq, Bool) -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, NetRx>) -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, NetRx>

A frame that does not fit is dropped; a host frame's loss stalls its TCP connection (the NAT does not retransmit), so it is logged.

def Net.rx.serve source · line 230 · raw

@-R:Type -> @fits:Bool -> @q0:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq -> @q:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq -> @c:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Chain -> @frame:List<&2, U32> -> @used:Bool -> @k:(@_:Pair(0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq, Bool) -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, NetRx>) -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, NetRx>

A popped chain: delivers the frame into it, or drops the frame and keeps the chain (continuing with q0, the queue before the pop).

def Net.rx.step source · line 242 · raw

@-R:Type -> @q0:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq -> @r:Pair(0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq, Maybe<&2, 0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Chain>) -> @+frame:List<&2, U32> -> @rest:List<&2, List<&2, U32>> -> @used:Bool -> @k:(@_:Pair(0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq, Bool) -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, NetRx>) -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, NetRx>

After a pop: stops on an empty queue with the frame and the rest left, else serves the chain and continues with k.

def Net.rx.go source · line 254 · raw

@frames:List<&2, List<&2, U32>> -> @-R:Type -> @st:Pair(0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq, Bool) -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, NetRx>

Delivers or drops each frame in turn; st is the queue and whether any chain was used. Every step takes one frame, so the frames bound the loop.

def Net.tx source · line 271 · raw

@-R:Type -> @q:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, NetTx>

Takes every available chain of transmitq1 (at most num): its readable bytes minus the 12-byte header form one frame (a chain of 12 bytes or less gives no frame), pushed used with length 0. Answers the queue, the frames in order, and whether any chain was used.

def Net.rx source · line 282 · raw

@-R:Type -> @q:0x2324e729258ea5021b37b97947af4c3f/src/virtio/queue.Vq -> @frames:List<&2, List<&2, U32>> -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, NetRx>

Delivers frames into receiveq1, one frame per available chain, in order: header then frame, scattered over the chain's writable descriptors, pushed used with 12 + frame length. A frame larger than the chain's room is dropped and the chain is kept for the next frame. Stops when frames or chains run out. Answers the queue, the frames not delivered, and whether any chain was used.