Mnet_dhcpSourceA DHCP-enabled TCP/IP stack.
This is a thin assembly on top of Mnet: it starts a normal stack without an IPv4 address, runs a DHCP client on the link, and keeps the stack's IPv4 configuration in sync with the leases it obtains.
A DHCP lease (the accepted DHCPACK), seen as a typed bag of network configuration.
cidr lease is the address and prefix to configure (the leased address combined with the subnet mask; defaults to a /32 if the server omitted the mask).
gateway lease is the first router advertised by the server, if any.
dns_servers lease is the list of DNS resolvers advertised by the server.
domain_name lease is the domain name advertised by the server, if any.
lease_time lease is the lease duration in seconds, if advertised.
options lease is the full list of DHCP options of the lease (escape hatch).
type config = {requests : Dhcp_wire.option_code list;the options to ask the server for (e.g. SUBNET_MASK, ROUTERS, DNS_SERVERS, or a private code carrying a certificate). An empty list lets charrua pick a sensible default set.
options : Dhcp_wire.dhcp_option list;the DHCP options to ask the server for (e.g. Sip_servers, Irc_servers, etc.). An empty list lets charrua pick a sensible default set.
on_lease : previous:lease option -> lease -> decision;called for every obtained or renewed lease, with the previously accepted lease (if any). The return value decides whether the lease is applied.
*)}accept_all requests the default set of options and accepts every lease.
with_requests requests config is config with its config.requests replaced. Convenient to start from accept_all and only add the option codes you care about.
A running DHCP-enabled stack (all protocol layers together with their background daemons and the DHCP client driving the IPv4 configuration).
val stack :
?timeout:int ->
name:string ->
?max:int option ->
?ipv6:Mnet.IPv6.mode ->
config ->
(t * Mnet.TCP.state * Mnet.UDP.state * lease) Mkernel.argstack ~name ?ipv6 config is like Mnet.stack but obtains its IPv4 configuration from DHCP according to config. The stack starts configured with the given lease. If, after a certain period of time, no DHCP server has configured the stack, an Unconfigured exception is raised (by default, this is after 5 minutes; see timeout).
name and ipv6 have the same meaning as in Mnet.stack.
addresses t returns all IP addresses (IPv4 and IPv6) currently configured on the stack — including the IPv4 address obtained via DHCP, once a lease has been accepted.
current_lease t is the most recently accepted lease, if any. Use it to read configuration the stack does not consume (DNS servers, domain name, or a TLS certificate carried in a private option).
kill t terminates the DHCP daemon and all the stack's background daemons (Ethernet reader, ARP responder, IPv6 NDP daemon, TCP timer, and ICMP handler). After calling kill, the stack must not be used.
This function should be called when the unikernel is shutting down.
/