src/net/wire.bend checks
raw source on the hub · import 0xd0e7b290a9710a97d85853bd4c530f3f/src/net/wire.bend as Wire
3 imports
import Base import ../lib/u64.bend as U import ../lib/bytes.bend as B
Types
type Eth source · line 108 · raw
Data
Ethernet II: dst MAC, src MAC, ethertype (2048 IPv4, 2054 ARP), payload.
Eth@dst:List<&2, U32> -> @src:List<&2, U32> -> @ethertype:U32 -> @payload:List<&2, U32> -> Eth
type Arp source · line 123 · raw
Data
ARP for IPv4 over Ethernet (htype 1, ptype 2048, hlen 6, plen 4); op 1 request, 2 reply.
Arp@op:U32 -> @sha:List<&2, U32> -> @spa:U32 -> @tha:List<&2, U32> -> @tpa:U32 -> Arp
type Ipv4 source · line 145 · raw
Data
IPv4 without options on build (IHL 5, TOS 0, flags DF, fragment offset 0); parse skips any options and drops bytes past total length. proto: 1 ICMP, 6 TCP, 17 UDP.
Ipv4@src:U32 -> @dst:U32 -> @proto:U32 -> @ttl:U32 -> @id:U32 -> @payload:List<&2, U32> -> Ipv4
type Icmp source · line 176 · raw
Data
ICMP: kind is the ICMP type (0 echo reply, 8 echo request), code, and the rest of the message after the checksum (for echo: id, sequence, data).
Icmp@kind:U32 -> @code:U32 -> @rest:List<&2, U32> -> Icmp
type Udp source · line 191 · raw
Data
Udp@sport:U32 -> @dport:U32 -> @payload:List<&2, U32> -> Udp
type Tcp source · line 220 · raw
Data
TCP flags: FIN 1, SYN 2, RST 4, PSH 8, ACK 16. mss is the MSS option: on parse, the value of an MSS option if present else 0; on build, an MSS option is emitted when mss != 0 (data offset 6), else none (data offset 5).
Tcp@sport:U32 -> @dport:U32 -> @seq:U32 -> @ack:U32 -> @flags:U32 -> @window:U32 -> @mss:U32 -> @payload:List<&2, U32> -> Tcp
type TcpOpt source · line 224 · raw
Data
The first option of an option list.
OptEndTcpOpt
OptBadTcpOpt
OptSkip@size:Nat -> TcpOpt
OptMss@value:U32 -> TcpOpt
Definitions
def Csum.fold1 source · line 16 · raw
@+x:U32 -> U32
One end-around-carry step: the high half added back into the low half.
def Csum.fold source · line 21 · raw
@x:U32 -> U32
Folds a 32-bit sum of 16-bit words to 16 bits (end-around carry). Two steps suffice: the first leaves at most 0x1_fffe, the second at most 0xffff.
def Csum.add source · line 25 · raw
@a:U32 -> @b:U32 -> U32
One's-complement addition of two 16-bit values.
def Csum.seq source · line 29 · raw
@bs:List<&2, U32> -> U32
The folded sum, word by word.
def Csum.leaf source · line 39 · raw
Nat
Buffers up to this many bytes are summed sequentially.
def Csum.small source · line 42 · raw
@+n:Nat -> Bool
def Csum.par source · line 48 · raw
@d:Nat -> @small:Bool -> @+n:Nat -> @+bs:List<&2, U32> -> U32
The folded sum of bs (n bytes), as a balanced parallel fold: the halves split at an even offset, so each half's words are words of bs, and one's-complement addition is associative and commutative. d bounds the depth.
def Csum.sum source · line 66 · raw
@bs:List<&2, U32> -> U32
The 16-bit one's-complement sum of bs (an odd final byte is padded with a zero), folded, not complemented: Csum.fold(Csum.sum(bs)).
def Csum.of source · line 72 · raw
@bs:List<&2, U32> -> U32
The Internet checksum of bs: the complement of the folded sum, in 0..65535.
def Wire.when source · line 76 · raw
@-A:Data -> @ok:Bool -> @x:A -> Maybe<&2, A>
Some{x} when ok, else None.
def Wire.u8 source · line 84 · raw
@bs:List<&2, U32> -> @off:Nat -> U32
The byte at off (0 past the end).
def Wire.u16 source · line 88 · raw
@bs:List<&2, U32> -> @off:Nat -> U32
The big-endian 16-bit field at off.
def Wire.u32 source · line 91 · raw
@bs:List<&2, U32> -> @off:Nat -> U32
def Wire.be16 source · line 94 · raw
@x:U32 -> List<&2, U32>
def Wire.len source · line 97 · raw
@bs:List<&2, U32> -> Nat
def Wire.cat source · line 100 · raw
@a:List<&2, U32> -> @b:List<&2, U32> -> List<&2, U32>
def Wire.pseudo source · line 104 · raw
@src:U32 -> @dst:U32 -> @proto:U32 -> @len:U32 -> List<&2, U32>
The IPv4 pseudo-header of a TCP or UDP checksum.
def Eth.parse source · line 111 · raw
@frame:List<&2, U32> -> Maybe<&2, Eth>
def Eth.build source · line 116 · raw
@e:Eth -> List<&2, U32>
def Arp.prefix source · line 128 · raw
List<&2, U32>
The fixed prefix: htype 1, ptype 0x0800, hlen 6, plen 4 (read as 0x0001_0800 = 67584 and 0x0604 = 1540).
def Arp.parse source · line 131 · raw
@bs:List<&2, U32> -> Maybe<&2, Arp>
def Arp.build source · line 137 · raw
@a:Arp -> List<&2, U32>
def Ipv4.parse source · line 148 · raw
@bs:List<&2, U32> -> Maybe<&2, Ipv4>
def Ipv4.header source · line 158 · raw
@+p:Ipv4 -> @csum:U32 -> List<&2, U32>
The 20-byte header with the given checksum field.
def Ipv4.payload source · line 165 · raw
@p:Ipv4 -> List<&2, U32>
def Ipv4.build source · line 170 · raw
@p:Ipv4 -> List<&2, U32>
def Icmp.parse source · line 179 · raw
@bs:List<&2, U32> -> Maybe<&2, Icmp>
def Icmp.build source · line 184 · raw
@m:Icmp -> List<&2, U32>
def Udp.parse source · line 195 · raw
@bs:List<&2, U32> -> Maybe<&2, Udp>
Parse drops bytes past the length field.
def Udp.nonzero source · line 203 · raw
@+c:U32 -> U32
0 is sent as 65535: a UDP checksum of 0 means none.
def Udp.build source · line 208 · raw
@src:U32 -> @dst:U32 -> @u:Udp -> List<&2, U32>
The UDP datagram with its checksum over the IPv4 pseudo-header of src, dst (a computed checksum of 0 is sent as 65535).
def Tcp.opt.sized source · line 231 · raw
@ok:Bool -> @mss:Bool -> @+l:U32 -> @value:U32 -> TcpOpt
A kind with a length byte l: bad when l < 2 or past the options.
def Tcp.opt source · line 238 · raw
@+opts:List<&2, U32> -> TcpOpt
def Tcp.opts source · line 248 · raw
@fuel:Nat -> @o:TcpOpt -> @+opts:List<&2, U32> -> @mss:U32 -> Maybe<&2, U32>
Walks the options from o, the first of opts; mss is the last MSS seen. Each step consumes at least one byte, so the fuel is the options' length.
def Tcp.mss source · line 265 · raw
@+opts:List<&2, U32> -> Maybe<&2, U32>
def Tcp.make source · line 268 · raw
@+bs:List<&2, U32> -> @hl:Nat -> @mss:U32 -> Maybe<&2, Tcp>
def Tcp.parse source · line 273 · raw
@bs:List<&2, U32> -> Maybe<&2, Tcp>
Parse answers None for a bad data offset or a malformed option (a length byte below 2 or past the header).
def Tcp.options source · line 283 · raw
@+mss:U32 -> List<&2, U32>
The MSS option, if any.
def Tcp.header source · line 287 · raw
@+t:Tcp -> @csum:U32 -> List<&2, U32>
The header with the given checksum field.
def Tcp.payload source · line 295 · raw
@t:Tcp -> List<&2, U32>
def Tcp.build source · line 301 · raw
@src:U32 -> @dst:U32 -> @t:Tcp -> List<&2, U32>
The TCP segment with its checksum over the IPv4 pseudo-header of src, dst.
def Wire.host_tag source · line 314 · raw
U32
A frame whose payload stays on the host: [256, conn, off, len] then its headers. 256 is no byte, so such a frame is never a plain one. The device writes the headers and has the host move the len bytes at offset off of what it holds for TCP connection conn right after them (V.VmNetToRam): the payload never passes through Bend.
def Wire.host_frame source · line 317 · raw
@conn:U32 -> @off:U32 -> @len:U32 -> @head:List<&2, U32> -> List<&2, U32>
def Wire.host_tag_of source · line 322 · raw
@+size:U32 -> U32
A host frame the guest cuts into TCP segments of size bytes (its GSO size): the tag carries size in its top 16 bits, 256 alone meaning 1460.
def Wire.host_frame_of source · line 325 · raw
@+size:U32 -> @conn:U32 -> @off:U32 -> @len:U32 -> @head:List<&2, U32> -> List<&2, U32>
def Wire.host_seg source · line 329 · raw
@+tag:U32 -> U32
The segment size of a host frame's tag.
def Wire.is_host_frame source · line 333 · raw
@f:List<&2, U32> -> Bool
def Ipv4.head source · line 342 · raw
@+src:U32 -> @+dst:U32 -> @+proto:U32 -> @+len:U32 -> List<&2, U32>
The 20-byte IPv4 header (IHL 5, flags DF, id 0, TTL 64) of a packet with len bytes after the header, with its checksum.
def Wire.staged_tag source · line 351 · raw
U32
A frame whose TCP payload waits on the host in a staged slot (V.VmStage): [257, slot, len] then its Ethernet, IPv4 and TCP headers as the guest sent them (the IPv4 total length still counting the payload).
def Wire.staged_frame source · line 354 · raw
@slot:U32 -> @len:U32 -> @head:List<&2, U32> -> List<&2, U32>
def Wire.is_staged source · line 357 · raw
@f:List<&2, U32> -> Bool
def Tcp.wscale.go source · line 367 · raw
@fuel:Nat -> @+opts:List<&2, U32> -> U32
The window scale option (kind 3, length 3) of a TCP segment's header bs: its shift (at most 14), or 4294967295 when there is none. Each step of the walk consumes at least one byte of the options.
def Tcp.wscale source · line 379 · raw
@+bs:List<&2, U32> -> U32
def Tcp.build_opts source · line 386 · raw
@src:U32 -> @dst:U32 -> @t:Tcp -> @+opts:List<&2, U32> -> List<&2, U32>
The TCP segment with the given option bytes (padded with NOPs to whole words; t's own mss is not used) and its checksum.