src/virtio/lan.bend checks
raw source on the hub · import 0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/lan.bend as Lan
7 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 import ../net/dhcp.bend as D
Types
type LanRx source · line 43 · raw
Data
What waits for the guest: a frame built here (a DHCP answer), or the frame the host holds (its length).
Local@frame:List<&2, U32> -> LanRx
Held@len:U32 -> LanRx
type Lan source · line 47 · raw
Data
Lan@mac:List<&2, U32> -> @ip:U32 -> @prefix:U32 -> @rx:List<&2, LanRx> -> Lan
type Route source · line 139 · raw
Data
Where a frame the guest sends goes, from its first bytes (after the virtio_net_hdr): its DHCP request answered here (when the device has an address), to the socket of a unicast destination MAC, to every socket (broadcast, multicast), or nowhere (too short, or to its own MAC).
ToDhcpRoute
ToMac@mac:List<&2, U32> -> Route
ToAllRoute
NowhereRoute
type LanTx source · line 168 · raw
Data
LanTx@q:0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq -> @lan:Lan -> @used:Bool -> LanTx
type LanRxOut source · line 270 · raw
Data
LanRxOut@q:0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq -> @left:List<&2, LanRx> -> @used:Bool -> LanRxOut
Definitions
def Lan.new source · line 50 · raw
@mac:List<&2, U32> -> @ip:U32 -> @prefix:U32 -> Lan
def Lan.mtu source · line 56 · raw
U32
The LAN's MTU: an Ethernet frame (14 bytes of header) and the 12-byte virtio_net_hdr in 2048 bytes, the most a macOS Unix datagram carries by default (net.local.dgram.maxdgram).
def Lan.features source · line 61 · raw
0x2bd5a34a6e8be8eb2ccde942133379fd/src/lib/u64.U64
VIRTIO_F_VERSION_1 and VIRTIO_NET_F_CSUM (bit 0), GUEST_CSUM (1), MTU (3), MAC (5), GUEST_TSO4 (7), GUEST_TSO6 (8), HOST_TSO4 (11), HOST_TSO6 (12).
def Lan.config source · line 65 · raw
@mac:List<&2, U32> -> List<&2, U32>
virtio_net_config: mac[6], status[2], max_virtqueue_pairs[2], mtu[2].
def Lan.max_local source · line 69 · raw
Nat
The most answers kept for the guest (it asks again).
def Lan.mask source · line 75 · raw
@+prefix:U32 -> U32
def Lan.server_ip source · line 80 · raw
@+ip:U32 -> @+prefix:U32 -> U32
The DHCP server's address: the subnet's last address but one (x.y.z.254 in a /24).
def Lan.server_mac source · line 84 · raw
List<&2, U32>
def Lan.bcast_mac source · line 88 · raw
List<&2, U32>
def Lan.be32 source · line 94 · raw
@x:U32 -> List<&2, U32>
def Lan.dhcp_options source · line 99 · raw
@t:U32 -> @+server:U32 -> @+mask:U32 -> List<&2, U32>
The options of an answer of type t: type, server id, lease (never ends), netmask, end.
def Lan.dhcp_build source · line 104 · raw
@t:U32 -> @+msg:List<&2, U32> -> @+ip:U32 -> @+server:U32 -> @+mask:U32 -> List<&2, U32>
The answer of type t (2 OFFER, 5 ACK) to msg: xid, flags and chaddr copied; yiaddr ip, siaddr the server.
def Lan.dhcp_pick source · line 108 · raw
@t:Maybe<&2, U32> -> @+msg:List<&2, U32> -> @+ip:U32 -> @+server:U32 -> @+mask:U32 -> Maybe<&2, List<&2, U32>>
def Lan.dhcp_reply source · line 118 · raw
@+msg:List<&2, U32> -> @+ip:U32 -> @+prefix:U32 -> Maybe<&2, List<&2, U32>>
The DHCP payload's answer for a device with address ip/prefix: DISCOVER gets OFFER, REQUEST gets ACK, anything else nothing.
def Lan.dhcp_frame source · line 122 · raw
@r:Maybe<&2, List<&2, U32>> -> @+ip:U32 -> @+prefix:U32 -> Maybe<&2, List<&2, U32>>
The answer's frame: from the server, port 67, to 255.255.255.255 port 68.
def Lan.is_dhcp source · line 145 · raw
@+head:List<&2, U32> -> Bool
def Lan.same source · line 149 · raw
@a:List<&2, U32> -> @b:List<&2, U32> -> Bool
def Lan.route source · line 158 · raw
@+head:List<&2, U32> -> @+len:U32 -> @+mac:List<&2, U32> -> @+ip:U32 -> Route
def Lan.room source · line 171 · raw
@ds:List<&2, 0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Desc> -> U32
def Lan.keep.add source · line 178 · raw
@+rx:List<&2, LanRx> -> @f:Maybe<&2, List<&2, U32>> -> List<&2, LanRx>
def Lan.keep source · line 186 · raw
@l:Lan -> @f:Maybe<&2, List<&2, U32>> -> Lan
A DHCP answer, if any, queued for the guest (at most Lan.max_local()).
def Lan.ip_of source · line 191 · raw
@l:Lan -> U32
def Lan.mac_of source · line 196 · raw
@l:Lan -> List<&2, U32>
def Lan.prefix_of source · line 201 · raw
@l:Lan -> U32
def Lan.tx.send source · line 207 · raw
@-R:Type -> @rt:Route -> @+l:Lan -> @+r:List<&2, 0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Desc> -> @+len:U32 -> 0x2bd5a34a6e8be8eb2ccde942133379fd/src/vmm/abi.Op<R, Lan>
One frame of len bytes in the readable descriptors r, by its route.
def Lan.tx.serve source · line 226 · raw
@-R:Type -> @q:0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq -> @c:0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Chain -> @+l:Lan -> 0x2bd5a34a6e8be8eb2ccde942133379fd/src/vmm/abi.Op<R, Pair(0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq, Lan)>
def Lan.tx.done source · line 236 · raw
@-R:Type -> @st:Pair(0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq, Lan) -> @used:Bool -> 0x2bd5a34a6e8be8eb2ccde942133379fd/src/vmm/abi.Op<R, LanTx>
def Lan.tx.step source · line 241 · raw
@-R:Type -> @r:Pair(0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq, Maybe<&2, 0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Chain>) -> @l:Lan -> @used:Bool -> @k:(@_:Pair(0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq, Lan) -> 0x2bd5a34a6e8be8eb2ccde942133379fd/src/vmm/abi.Op<R, LanTx>) -> 0x2bd5a34a6e8be8eb2ccde942133379fd/src/vmm/abi.Op<R, LanTx>
def Lan.tx.go source · line 248 · raw
@fuel:Nat -> @-R:Type -> @st:Pair(0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq, Lan) -> @used:Bool -> 0x2bd5a34a6e8be8eb2ccde942133379fd/src/vmm/abi.Op<R, LanTx>
def Lan.tx source · line 262 · raw
@-R:Type -> @l:Lan -> @q:0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq -> 0x2bd5a34a6e8be8eb2ccde942133379fd/src/vmm/abi.Op<R, LanTx>
Takes every available chain of the transmit queue (at most num): each is one frame after its 12-byte header, sent by its route (Lan.route), pushed used with length 0.
def Lan.hdr source · line 274 · raw
List<&2, U32>
The virtio_net_hdr: zeros but num_buffers = 1.
def Lan.size source · line 279 · raw
@x:LanRx -> U32
The bytes an item takes in a chain: a frame built here and its header; a held packet came with its own (from the sending device).
def Lan.rx.deliver source · line 287 · raw
@-R:Type -> @x:LanRx -> @q:0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq -> @+h:U32 -> @+w:List<&2, 0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Desc> -> 0x2bd5a34a6e8be8eb2ccde942133379fd/src/vmm/abi.Op<R, 0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq>
One item into a chain that fits it: the header and the frame, pushed used.
def Lan.rx.drop source · line 301 · raw
@-R:Type -> @x:LanRx -> @q:0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq -> @+h:U32 -> 0x2bd5a34a6e8be8eb2ccde942133379fd/src/vmm/abi.Op<R, 0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq>
An item too large for the chain: dropped (a held frame released); the chain is pushed used with length 0.
def Lan.rx.fit source · line 310 · raw
@-R:Type -> @fits:Bool -> @x:LanRx -> @q:0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq -> @+h:U32 -> @+w:List<&2, 0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Desc> -> 0x2bd5a34a6e8be8eb2ccde942133379fd/src/vmm/abi.Op<R, 0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq>
def Lan.rx.serve source · line 317 · raw
@-R:Type -> @+x:LanRx -> @q:0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq -> @c:0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Chain -> 0x2bd5a34a6e8be8eb2ccde942133379fd/src/vmm/abi.Op<R, 0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq>
def Lan.rx.step source · line 322 · raw
@-R:Type -> @r:Pair(0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq, Maybe<&2, 0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Chain>) -> @+x:LanRx -> @rest:List<&2, LanRx> -> @used:Bool -> @k:(@_:Pair(0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq, Bool) -> 0x2bd5a34a6e8be8eb2ccde942133379fd/src/vmm/abi.Op<R, LanRxOut>) -> 0x2bd5a34a6e8be8eb2ccde942133379fd/src/vmm/abi.Op<R, LanRxOut>
def Lan.rx.go source · line 329 · raw
@items:List<&2, LanRx> -> @-R:Type -> @st:Pair(0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq, Bool) -> 0x2bd5a34a6e8be8eb2ccde942133379fd/src/vmm/abi.Op<R, LanRxOut>
def Lan.rx source · line 343 · raw
@-R:Type -> @l:Lan -> @q:0x2bd5a34a6e8be8eb2ccde942133379fd/src/virtio/queue.Vq -> 0x2bd5a34a6e8be8eb2ccde942133379fd/src/vmm/abi.Op<R, LanRxOut>
Delivers what waits, in order, one item per available chain.
def Lan.with_rx source · line 348 · raw
@l:Lan -> @rx:List<&2, LanRx> -> Lan
def Lan.ready source · line 354 · raw
@l:Lan -> @+len:U32 -> Lan
The host holds a frame of len bytes for the guest.
def Lan.pending source · line 360 · raw
@l:Lan -> Bool
Whether anything waits for the guest.
def Lan.forget_held.go source · line 366 · raw
@rx:List<&2, LanRx> -> List<&2, LanRx>
After a restore the host holds nothing: the held frame is forgotten.
def Lan.forget_held source · line 375 · raw
@l:Lan -> Lan
def Lan.rx_of source · line 380 · raw
@l:Lan -> List<&2, LanRx>