src/virtio/lan.bend checks
raw source on the hub · import 0xd0e7b290a9710a97d85853bd4c530f3f/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 36 · 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 40 · raw
Data
Lan@mac:List<&2, U32> -> @ip:U32 -> @prefix:U32 -> @rx:List<&2, LanRx> -> Lan
type Route source · line 124 · 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 153 · raw
Data
LanTx@q:0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq -> @lan:Lan -> @used:Bool -> LanTx
type LanRxOut source · line 255 · raw
Data
LanRxOut@q:0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq -> @left:List<&2, LanRx> -> @used:Bool -> LanRxOut
Definitions
def Lan.new source · line 43 · raw
@mac:List<&2, U32> -> @ip:U32 -> @prefix:U32 -> Lan
def Lan.features source · line 47 · raw
0xd0e7b290a9710a97d85853bd4c530f3f/src/lib/u64.U64
VIRTIO_F_VERSION_1 and VIRTIO_NET_F_MAC (bit 5).
def Lan.config source · line 50 · raw
@mac:List<&2, U32> -> List<&2, U32>
def Lan.max_local source · line 54 · raw
Nat
The most answers kept for the guest (it asks again).
def Lan.mask source · line 60 · raw
@+prefix:U32 -> U32
def Lan.server_ip source · line 65 · 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 69 · raw
List<&2, U32>
def Lan.bcast_mac source · line 73 · raw
List<&2, U32>
def Lan.be32 source · line 79 · raw
@x:U32 -> List<&2, U32>
def Lan.dhcp_options source · line 84 · 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 89 · 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 93 · 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 103 · 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 107 · 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 130 · raw
@+head:List<&2, U32> -> Bool
def Lan.same source · line 134 · raw
@a:List<&2, U32> -> @b:List<&2, U32> -> Bool
def Lan.route source · line 143 · raw
@+head:List<&2, U32> -> @+len:U32 -> @+mac:List<&2, U32> -> @+ip:U32 -> Route
def Lan.room source · line 156 · raw
@ds:List<&2, 0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Desc> -> U32
def Lan.keep.add source · line 163 · raw
@+rx:List<&2, LanRx> -> @f:Maybe<&2, List<&2, U32>> -> List<&2, LanRx>
def Lan.keep source · line 171 · 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 176 · raw
@l:Lan -> U32
def Lan.mac_of source · line 181 · raw
@l:Lan -> List<&2, U32>
def Lan.prefix_of source · line 186 · raw
@l:Lan -> U32
def Lan.tx.send source · line 192 · raw
@-R:Type -> @rt:Route -> @+l:Lan -> @+r:List<&2, 0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Desc> -> @+len:U32 -> 0xd0e7b290a9710a97d85853bd4c530f3f/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 211 · raw
@-R:Type -> @q:0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq -> @c:0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Chain -> @+l:Lan -> 0xd0e7b290a9710a97d85853bd4c530f3f/src/vmm/abi.Op<R, Pair(0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq, Lan)>
def Lan.tx.done source · line 221 · raw
@-R:Type -> @st:Pair(0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq, Lan) -> @used:Bool -> 0xd0e7b290a9710a97d85853bd4c530f3f/src/vmm/abi.Op<R, LanTx>
def Lan.tx.step source · line 226 · raw
@-R:Type -> @r:Pair(0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq, Maybe<&2, 0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Chain>) -> @l:Lan -> @used:Bool -> @k:(@_:Pair(0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq, Lan) -> 0xd0e7b290a9710a97d85853bd4c530f3f/src/vmm/abi.Op<R, LanTx>) -> 0xd0e7b290a9710a97d85853bd4c530f3f/src/vmm/abi.Op<R, LanTx>
def Lan.tx.go source · line 233 · raw
@fuel:Nat -> @-R:Type -> @st:Pair(0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq, Lan) -> @used:Bool -> 0xd0e7b290a9710a97d85853bd4c530f3f/src/vmm/abi.Op<R, LanTx>
def Lan.tx source · line 247 · raw
@-R:Type -> @l:Lan -> @q:0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq -> 0xd0e7b290a9710a97d85853bd4c530f3f/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 259 · raw
List<&2, U32>
The virtio_net_hdr: zeros but num_buffers = 1.
def Lan.size source · line 262 · raw
@x:LanRx -> U32
def Lan.rx.deliver source · line 270 · raw
@-R:Type -> @x:LanRx -> @q:0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq -> @+h:U32 -> @+w:List<&2, 0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Desc> -> 0xd0e7b290a9710a97d85853bd4c530f3f/src/vmm/abi.Op<R, 0xd0e7b290a9710a97d85853bd4c530f3f/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 285 · raw
@-R:Type -> @x:LanRx -> @q:0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq -> @+h:U32 -> 0xd0e7b290a9710a97d85853bd4c530f3f/src/vmm/abi.Op<R, 0xd0e7b290a9710a97d85853bd4c530f3f/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 294 · raw
@-R:Type -> @fits:Bool -> @x:LanRx -> @q:0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq -> @+h:U32 -> @+w:List<&2, 0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Desc> -> 0xd0e7b290a9710a97d85853bd4c530f3f/src/vmm/abi.Op<R, 0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq>
def Lan.rx.serve source · line 301 · raw
@-R:Type -> @+x:LanRx -> @q:0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq -> @c:0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Chain -> 0xd0e7b290a9710a97d85853bd4c530f3f/src/vmm/abi.Op<R, 0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq>
def Lan.rx.step source · line 306 · raw
@-R:Type -> @r:Pair(0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq, Maybe<&2, 0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Chain>) -> @+x:LanRx -> @rest:List<&2, LanRx> -> @used:Bool -> @k:(@_:Pair(0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq, Bool) -> 0xd0e7b290a9710a97d85853bd4c530f3f/src/vmm/abi.Op<R, LanRxOut>) -> 0xd0e7b290a9710a97d85853bd4c530f3f/src/vmm/abi.Op<R, LanRxOut>
def Lan.rx.go source · line 313 · raw
@items:List<&2, LanRx> -> @-R:Type -> @st:Pair(0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq, Bool) -> 0xd0e7b290a9710a97d85853bd4c530f3f/src/vmm/abi.Op<R, LanRxOut>
def Lan.rx source · line 327 · raw
@-R:Type -> @l:Lan -> @q:0xd0e7b290a9710a97d85853bd4c530f3f/src/virtio/queue.Vq -> 0xd0e7b290a9710a97d85853bd4c530f3f/src/vmm/abi.Op<R, LanRxOut>
Delivers what waits, in order, one item per available chain.
def Lan.with_rx source · line 332 · raw
@l:Lan -> @rx:List<&2, LanRx> -> Lan
def Lan.ready source · line 338 · raw
@l:Lan -> @+len:U32 -> Lan
The host holds a frame of len bytes for the guest.
def Lan.pending source · line 344 · raw
@l:Lan -> Bool
Whether anything waits for the guest.
def Lan.forget_held.go source · line 350 · 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 359 · raw
@l:Lan -> Lan
def Lan.rx_of source · line 364 · raw
@l:Lan -> List<&2, LanRx>