package mirage-types
An IPv4 stack that parses Ethernet frames into IPv4 packets
type error = [
| `Unknown of string
(*an undiagnosed error
*)| `Unimplemented
(*operation not yet implemented in the code
*)
]
IO operation errors
An input continuation used by the parsing functions to pass on an input packet down the stack. callback ~src ~dst buf
will be called with src
and dst
containing the source and destination IPv4 address respectively, and buf
will be a buffer pointing at the start of the IPv4 payload.
val input :
tcp:callback ->
udp:callback ->
default:(proto:int -> callback) ->
t ->
buffer ->
unit io
input ~tcp ~udp ~default ip buf
demultiplexes an incoming buffer
that contains an IPv4 frame. It examines the protocol header and passes the result onto either the tcp
or udp
function, or the default
function for unknown IP protocols.
allocate_frame ~proto ~dest_ip
will an output buffer for the proto
IP protocol for the dest_ip
IPv4 destination. It returns a tuple of the buffer of the full Ethernet frame (pointing at the start of the frame) and the total length of the Ethernet and IPv4 header that was written. The caller can create a sub-view into the payload using this information if it needs to, or combine it with write
to do a scatter-gather output with an existing payload.
write t frame buffer
concatenates a header frame
(possibly allocated with allocate_frame
with the buffer
and outputs it as a single frame.
writev t frame buffers
concatenates a header frame
(possibly allocated with allocate_frame
with the buffer
list and outputs it all as a single frame. Uses the underlying scatter-gather interface if available for efficiency.
Set the IPv4 address associated with this interface. Currently only supports a single IPv4 address, and aliases will be added in a future revision.
Get the IPv4 address associated with this interface. If none has been previously bound via set_ipv4
, it defaults to Ipaddr.V4.any
.
Set the IPv4 netmask associated with this interface. Currently only supports a single IPv4 netmask, and aliases will be added in a future revision.
Get the IPv4 netmask associated with this interface. If none has been previously bound via set_ipv4_netmask
, it defaults to Ipaddr.V4.any
.
Set the IPv4 gateways associated with this interface.
Get the IPv4 gateways associated with this interface. If none has been previously bound via set_ipv4_netmask
, it defaults to an empty list.