src/virtio/lan.bend checks
raw source on the hub · import 0x7fea7bfac3f0390a60760e0485feacff/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 38 · 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 42 · raw
Data
Lan@mac:List<&2, U32> -> @ip:U32 -> @prefix:U32 -> @rx:List<&2, LanRx> -> Lan
type Route source · line 132 · 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 161 · raw
Data
LanTx@q:0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq -> @lan:Lan -> @used:Bool -> LanTx
type LanRxOut source · line 263 · raw
Data
LanRxOut@q:0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq -> @left:List<&2, LanRx> -> @used:Bool -> LanRxOut
Definitions
def Lan.new source · line 45 · raw
@mac:List<&2, U32> -> @ip:U32 -> @prefix:U32 -> Lan
def Lan.mtu source · line 50 · raw
U32
The LAN's MTU: an Ethernet frame of 2048 bytes (14 of header), the most a macOS Unix datagram carries by default (net.local.dgram.maxdgram).
def Lan.features source · line 54 · raw
0x7fea7bfac3f0390a60760e0485feacff/src/lib/u64.U64
VIRTIO_F_VERSION_1, VIRTIO_NET_F_MTU (bit 3) and VIRTIO_NET_F_MAC (bit 5).
def Lan.config source · line 58 · 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 62 · raw
Nat
The most answers kept for the guest (it asks again).
def Lan.mask source · line 68 · raw
@+prefix:U32 -> U32
def Lan.server_ip source · line 73 · 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 77 · raw
List<&2, U32>
def Lan.bcast_mac source · line 81 · raw
List<&2, U32>
def Lan.be32 source · line 87 · raw
@x:U32 -> List<&2, U32>
def Lan.dhcp_options source · line 92 · 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 97 · 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 101 · 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 111 · 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 115 · 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 138 · raw
@+head:List<&2, U32> -> Bool
def Lan.same source · line 142 · raw
@a:List<&2, U32> -> @b:List<&2, U32> -> Bool
def Lan.route source · line 151 · raw
@+head:List<&2, U32> -> @+len:U32 -> @+mac:List<&2, U32> -> @+ip:U32 -> Route
def Lan.room source · line 164 · raw
@ds:List<&2, 0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Desc> -> U32
def Lan.keep.add source · line 171 · raw
@+rx:List<&2, LanRx> -> @f:Maybe<&2, List<&2, U32>> -> List<&2, LanRx>
def Lan.keep source · line 179 · 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 184 · raw
@l:Lan -> U32
def Lan.mac_of source · line 189 · raw
@l:Lan -> List<&2, U32>
def Lan.prefix_of source · line 194 · raw
@l:Lan -> U32
def Lan.tx.send source · line 200 · raw
@-R:Type -> @rt:Route -> @+l:Lan -> @+r:List<&2, 0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Desc> -> @+len:U32 -> 0x7fea7bfac3f0390a60760e0485feacff/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 219 · raw
@-R:Type -> @q:0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq -> @c:0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Chain -> @+l:Lan -> 0x7fea7bfac3f0390a60760e0485feacff/src/vmm/abi.Op<R, Pair(0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq, Lan)>
def Lan.tx.done source · line 229 · raw
@-R:Type -> @st:Pair(0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq, Lan) -> @used:Bool -> 0x7fea7bfac3f0390a60760e0485feacff/src/vmm/abi.Op<R, LanTx>
def Lan.tx.step source · line 234 · raw
@-R:Type -> @r:Pair(0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq, Maybe<&2, 0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Chain>) -> @l:Lan -> @used:Bool -> @k:(@_:Pair(0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq, Lan) -> 0x7fea7bfac3f0390a60760e0485feacff/src/vmm/abi.Op<R, LanTx>) -> 0x7fea7bfac3f0390a60760e0485feacff/src/vmm/abi.Op<R, LanTx>
def Lan.tx.go source · line 241 · raw
@fuel:Nat -> @-R:Type -> @st:Pair(0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq, Lan) -> @used:Bool -> 0x7fea7bfac3f0390a60760e0485feacff/src/vmm/abi.Op<R, LanTx>
def Lan.tx source · line 255 · raw
@-R:Type -> @l:Lan -> @q:0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq -> 0x7fea7bfac3f0390a60760e0485feacff/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 267 · raw
List<&2, U32>
The virtio_net_hdr: zeros but num_buffers = 1.
def Lan.size source · line 270 · raw
@x:LanRx -> U32
def Lan.rx.deliver source · line 278 · raw
@-R:Type -> @x:LanRx -> @q:0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq -> @+h:U32 -> @+w:List<&2, 0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Desc> -> 0x7fea7bfac3f0390a60760e0485feacff/src/vmm/abi.Op<R, 0x7fea7bfac3f0390a60760e0485feacff/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 293 · raw
@-R:Type -> @x:LanRx -> @q:0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq -> @+h:U32 -> 0x7fea7bfac3f0390a60760e0485feacff/src/vmm/abi.Op<R, 0x7fea7bfac3f0390a60760e0485feacff/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 302 · raw
@-R:Type -> @fits:Bool -> @x:LanRx -> @q:0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq -> @+h:U32 -> @+w:List<&2, 0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Desc> -> 0x7fea7bfac3f0390a60760e0485feacff/src/vmm/abi.Op<R, 0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq>
def Lan.rx.serve source · line 309 · raw
@-R:Type -> @+x:LanRx -> @q:0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq -> @c:0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Chain -> 0x7fea7bfac3f0390a60760e0485feacff/src/vmm/abi.Op<R, 0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq>
def Lan.rx.step source · line 314 · raw
@-R:Type -> @r:Pair(0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq, Maybe<&2, 0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Chain>) -> @+x:LanRx -> @rest:List<&2, LanRx> -> @used:Bool -> @k:(@_:Pair(0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq, Bool) -> 0x7fea7bfac3f0390a60760e0485feacff/src/vmm/abi.Op<R, LanRxOut>) -> 0x7fea7bfac3f0390a60760e0485feacff/src/vmm/abi.Op<R, LanRxOut>
def Lan.rx.go source · line 321 · raw
@items:List<&2, LanRx> -> @-R:Type -> @st:Pair(0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq, Bool) -> 0x7fea7bfac3f0390a60760e0485feacff/src/vmm/abi.Op<R, LanRxOut>
def Lan.rx source · line 335 · raw
@-R:Type -> @l:Lan -> @q:0x7fea7bfac3f0390a60760e0485feacff/src/virtio/queue.Vq -> 0x7fea7bfac3f0390a60760e0485feacff/src/vmm/abi.Op<R, LanRxOut>
Delivers what waits, in order, one item per available chain.
def Lan.with_rx source · line 340 · raw
@l:Lan -> @rx:List<&2, LanRx> -> Lan
def Lan.ready source · line 346 · raw
@l:Lan -> @+len:U32 -> Lan
The host holds a frame of len bytes for the guest.
def Lan.pending source · line 352 · raw
@l:Lan -> Bool
Whether anything waits for the guest.
def Lan.forget_held.go source · line 358 · 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 367 · raw
@l:Lan -> Lan
def Lan.rx_of source · line 372 · raw
@l:Lan -> List<&2, LanRx>