package mirage-types

  1. Overview
  2. Docs
include IP with type +'a io = 'a io with type ipaddr = ipv4addr with type buffer = buffer with type t = ipv4
type buffer = buffer

The type for memory buffers.

type ethif

The type for ethernet devices.

type ipaddr = ipv4addr

The type for IP addresses.

type prefix

The type for IP prefixes.

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

    an undiagnosed error

    *)
  2. | `Unimplemented
    (*

    operation not yet implemented in the code

    *)
]

The type for 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

The type for potentially blocking I/O operation

type t = ipv4

The type representing the internal state of the device

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:ipaddr -> dst:ipaddr -> 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 IP address respectively, and buf will be a buffer pointing at the start of the IP payload.

val input : t -> tcp:callback -> udp:callback -> default:(proto:int -> callback) -> buffer -> unit io

input ~tcp ~udp ~default ip buf demultiplexes an incoming buffer that contains an IP 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 : t -> dst:ipaddr -> proto:[ `ICMP | `TCP | `UDP ] -> buffer * int

allocate_frame t ~dst ~proto retrurns a pair (pkt, len) such that Cstruct.sub pkt 0 len is the IP header (including the link layer part) of a packet going to dst for protocol proto. The space in pkt after the first len bytes can be used by the client.

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

write t frame buf writes the packet frame :: buf :: [] to the address dst.

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

writev t frame bufs writes the packet frame :: bufs.

val checksum : buffer -> buffer list -> int

checksum frame bufs computes the IP checksum of bufs computing the pseudo-header from the actual header frame. It assumes that frame is of the form returned by allocate_frame, i.e., that it contains the link-layer part.

val get_source : t -> dst:ipaddr -> ipaddr

get_source ip ~dst is the source address to be used to send a packet to dst.

val set_ip : t -> ipaddr -> unit io

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

val get_ip : t -> ipaddr list

Get the IP addresses associated with this interface.

val set_ip_netmask : t -> prefix -> unit io

Set an IP netmask associated with this interface. For IPv4, currently only supports a single IPv4 netmask, and aliases will be added in a future revision.

val get_ip_netmasks : t -> prefix list

Get the IP netmasks associated with this interface.

val set_ip_gateways : t -> ipaddr list -> unit io

Set an IP gateways associated with this interface.

val get_ip_gateways : t -> ipaddr list

Get the IP gateways associated with this interface.

type uipaddr

The type for universal IP addresses. It supports all the possible versions.

val to_uipaddr : ipaddr -> uipaddr

Convert an IP address with a specific version (eg. V4) into a universal IP address.

val of_uipaddr : uipaddr -> ipaddr option

Project a universal IP address into the version supported by the current implementation. Return None if there is a version mismatch.

OCaml

Innovation. Community. Security.