package mirage-types

  1. Overview
  2. Docs

An IPv4 stack that parses Ethernet frames into IPv4 packets

type buffer = buffer

Abstract type for a memory buffer that may not be page aligned

type ethif

Abstract type for an Ethernet device.

type ipv4addr = ipv4addr

Abstract type for an IPv4 address.

type error = [
  1. | `Unknown of string
    (*

    an undiagnosed error

    *)
  2. | `Unimplemented
    (*

    operation not yet implemented in the code

    *)
]

IO operation errors

include DEVICE with type error := error and type id := ethif with type +'a io = 'a io with type t = ipv4
type +'a io = 'a io

A potentially blocking I/O operation

type t = ipv4

The type representing the internal state of the device

val id : t -> ethif

Return the identifier that was used to construct this device

val connect : ethif -> [ `Error of error | `Ok of t ] io

Connect to the device identified by id

val disconnect : t -> unit io

Disconnect from the device. While this might take some time to complete, it can never result in an error.

type callback = src:ipv4addr -> dst:ipv4addr -> buffer -> unit io

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.

val allocate_frame : proto:[< `ICMP | `TCP | `UDP ] -> dest_ip:ipv4addr -> t -> (buffer * int) io

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.

val write : t -> buffer -> buffer -> unit io

write t frame buffer concatenates a header frame (possibly allocated with allocate_frame with the buffer and outputs it as a single frame.

val writev : t -> buffer -> buffer list -> unit io

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.

val set_ipv4 : t -> ipv4addr -> unit io

Set the IPv4 address associated with this interface. Currently only supports a single IPv4 address, and aliases will be added in a future revision.

val get_ipv4 : t -> ipv4addr

Get the IPv4 address associated with this interface. If none has been previously bound via set_ipv4, it defaults to Ipaddr.V4.any.

val set_ipv4_netmask : t -> ipv4addr -> unit io

Set the IPv4 netmask associated with this interface. Currently only supports a single IPv4 netmask, and aliases will be added in a future revision.

val get_ipv4_netmask : t -> ipv4addr

Get the IPv4 netmask associated with this interface. If none has been previously bound via set_ipv4_netmask, it defaults to Ipaddr.V4.any.

val set_ipv4_gateways : t -> ipv4addr list -> unit io

Set the IPv4 gateways associated with this interface.

val get_ipv4_gateways : t -> ipv4addr list

Get the IPv4 gateways associated with this interface. If none has been previously bound via set_ipv4_netmask, it defaults to an empty list.

OCaml

Innovation. Community. Security.