package mnet

  1. Overview
  2. Docs
An implementation of TCP (Transmission Control Protocol) in OCaml for Miou & Solo5

Install

dune-project
 Dependency

Authors

Maintainers

Sources

mnet-0.0.5.tbz
sha256=ebc621ad01b33a7f96fd049e71bbd06ef95c1a6b36d4072fd15fd35c1a93dc17
sha512=8d47f9434bc6472703f55f819bea21a7deb12095d925f0f8fbb8b96b799473b62a8b302966f579792354aa256b9109dcc16851f5cf951002d35a7d70bca59135

doc/src/mnet.ipv4/routing.ml.html

Source file routing.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
type r = Mac of Macaddr.t | Arp of Ipaddr.V4.t

let routing network gateway ~src ~dst =
  if Ipaddr.V4.Prefix.(mem dst loopback) || Ipaddr.V4.Prefix.(mem src loopback)
  then
    (* avoid packets to or from 127.0.0.0/8 *)
    Error `Loopback
  else if
    Ipaddr.V4.(compare broadcast) dst == 0
    || Ipaddr.V4.(compare (Prefix.broadcast network)) dst == 0
  then
    (* use broadcast mac *)
    Ok (Mac Macaddr.broadcast)
  else if Ipaddr.V4.is_multicast dst then
    (* filter multicast *)
    Ok (Mac (Ipaddr.V4.multicast_to_mac dst))
  else if Ipaddr.V4.Prefix.mem dst network then
    (* direct to this network *)
    Ok (Arp dst)
  else
    (* send to gateway *)
    match gateway with
    | None -> Error `Gateway
    | Some gateway -> Ok (Arp gateway)

let ( let* ) = Result.bind

let destination_macaddr network gateway arp ~src ~dst =
  let* it = routing network gateway ~src ~dst in
  match it with Mac x -> Ok x | Arp ip -> ARPv4.query arp ip

let destination_macaddr_without_interruption network gateway arp ~src ~dst =
  match routing network gateway ~src ~dst with
  | Error _ -> None
  | Ok (Mac x) -> Some x
  | Ok (Arp ip) -> ARPv4.ask arp ip