package mnet
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=154c3b18bbb019535a4f37d1fefa3c6131b636e53316a63b395d030b186f2a59
sha512=894d12ff3140b294de1129f76893b295e73093101edec137ba2b2106059081f94385e3e3420c48cde14df6aefbef333bec12f5772c1b85c7ecc73dcde9e5bb8c
doc/mnet.ipv6/IPv6/index.html
Module IPv6Source
IPv6 protocol layer.
This module handles IPv6 packet encoding, decoding, fragmentation, and reassembly. It integrates with the Neighbor Discovery Protocol (NDP) for address resolution and router/prefix discovery.
Address modes.
IPv6 addresses can be configured in three ways via mode:
Random: a random Interface Identifier is generated.EUI64: the Interface Identifier is derived from the device's MAC address using the EUI-64 algorithm (the default).Static: a user-specified IPv6 prefix is used directly.
Regardless of the mode, the stack always has a Link-Local address (fe80::/10) for communicating with direct neighbors. A Global address (2000::/3) is obtained via Router Advertisements (NDP).
Path MTU discovery.
IPv6 does not allow routers to fragment packets. The sender must discover the Path MTU and fragment at the source if needed. This module caches PMTU values discovered via ICMPv6 "Packet Too Big" messages. When the PMTU is unknown, fragmentation defaults to 1280 bytes (the IPv6 minimum MTU).
Types
The IPv6 protocol state. Maintains NDP state (neighbors, routers, prefixes), address configuration, fragmentation reassembly cache, and PMTU cache.
The background NDP daemon that sends Router Solicitations, processes advertisements, and manages neighbor reachability. Must be terminated with kill.
type payload = | Slice of SBstr.t| String of string(*The payload of a received IPv6 packet. Like
IPv4.payload:Slice: non-fragmented, zero-copy from the Ethernet frame.String: reassembled from fragments (involves copying).
The type of a function that processes received IPv6 packets.
~protocol: the upper-layer protocol number (6 = TCP, 58 = ICMPv6).- The two
Ipaddr.V6.targuments are source and destination respectively.
type mode = | Random| EUI64| Static of Ipaddr.V6.Prefix.t(*How to configure the IPv6 Interface Identifier.
Random: generate a random identifier (changes on each boot).EUI64: derive the identifier from the MAC address. This is deterministic and is the default mode.Static prefix: use the given IPv6 prefix directly. The address is the prefix combined with the Interface Identifier derived from the prefix.
Initialization
val create :
?handler:handler ->
Ethernet.t ->
mode ->
(t * daemon, [> `MTU_too_small ]) resultcreate ?handler eth mode creates a new IPv6 stack and starts the NDP background daemon. The daemon immediately sends a Router Solicitation to discover routers and obtain a Global address prefix.
?handler: the function called when a complete IPv6 packet is received (and reassembled if fragmented). If not provided, received packets are silently dropped. Typically set later viaset_handleronce the upper layers (TCP, UDP) are initialized.eth: theEthernetlayer.mode: the address configuration mode (seemode).
Returns `MTU_too_small if the Ethernet MTU is insufficient for IPv6.
set_handler t handler installs handler as the function called for incoming IPv6 packets. Replaces any previously installed handler.
Addressing
src ipv6 ~dst returns the correct IPv6 source address for communicating with the given destination. In the case of a direct neighbor (a Link-Local destination), the Link-Local address is used (fe80::). Otherwise, the global IPv6 address (2000::/3) is used.
addresses t returns the addresses on which the given state t is mounted.
With regard to IPv6, an IPv6 stack generally has two addresses:
- a Link-Local address (
fe80::) for communicating (and discovering) with its direct neighbors - a global address (
2000::/3) for communicating with the Internet
Sending packets
val write_directly :
t ->
?src:Ipaddr.V6.t ->
Ipaddr.V6.t ->
protocol:int ->
len:int ->
(Bstr.t -> unit) ->
(unit, [> `Packet_too_big | `Destination_unreachable of int ]) resultwrite_directly ipv6 ?src dst ~protocol ~len fn sends an IPv6 packet by calling fn buf, where buf is a buffer of size len that fn should fill with the packet payload.
The function handles fragmentation automatically based on the discovered PMTU. If the PMTU is unknown, fragmentation defaults to 1280 bytes.
This function has no interruptions (no Miou effects). If a route to dst is already known, the packet is sent immediately. If not, it is queued until NDP resolves the next-hop's link-layer address.
?srcoverrides the source IPv6 address.dstis the destination IPv6 address.~protocolis the upper-layer protocol number (6 = TCP, 17 = UDP).~lenis the exact payload size in bytes.
Returns `Packet_too_big if the payload cannot be sent even with fragmentation. Returns `Destination_unreachable code if an ICMPv6 Destination Unreachable was received for dst.
Receiving packets
input ipv6 pkt is the function to install as an IPv6 handler for an Ethernet daemon. It analyzes incoming IPv6 packets and updates the given state ipv6. NDP messages (Router Advertisements, Neighbor Solicitations, etc.) are processed internally; upper-layer packets are forwarded to the installed handler.