2015-12-30 04:52:24 -05:00
|
|
|
(* Copyright (C) 2015, Thomas Leonard <thomas.leonard@unikernel.com>
|
|
|
|
See the README file for details. *)
|
|
|
|
|
|
|
|
(** Routing packets to the right network interface. *)
|
|
|
|
|
|
|
|
open Utils
|
|
|
|
|
2015-12-30 11:07:16 -05:00
|
|
|
type t = private {
|
|
|
|
client_eth : Client_eth.t;
|
2016-01-02 10:50:05 -05:00
|
|
|
mutable nat : Nat_lookup.t;
|
2016-01-01 06:32:57 -05:00
|
|
|
uplink : interface;
|
2015-12-30 11:07:16 -05:00
|
|
|
}
|
2015-12-30 04:52:24 -05:00
|
|
|
(** A routing table. *)
|
|
|
|
|
|
|
|
val create :
|
2015-12-30 08:48:13 -05:00
|
|
|
client_eth:Client_eth.t ->
|
2016-01-01 06:32:57 -05:00
|
|
|
uplink:interface ->
|
2015-12-30 04:52:24 -05:00
|
|
|
t
|
2016-01-01 06:32:57 -05:00
|
|
|
(** [create ~client_eth ~uplink] is a new routing table
|
|
|
|
that routes packets outside of [client_eth] via [uplink]. *)
|
2015-12-30 04:52:24 -05:00
|
|
|
|
|
|
|
val target : t -> Cstruct.t -> interface option
|
|
|
|
(** [target t packet] is the interface to which [packet] (an IP packet) should be routed. *)
|
|
|
|
|
|
|
|
val add_client : t -> client_link -> unit
|
|
|
|
(** [add_client t iface] adds a rule for routing packets addressed to [iface].
|
2015-12-30 08:48:13 -05:00
|
|
|
The client's IP address must be within the [client_eth] passed to [create]. *)
|
2015-12-30 04:52:24 -05:00
|
|
|
|
|
|
|
val remove_client : t -> client_link -> unit
|
2015-12-30 08:48:13 -05:00
|
|
|
|
2015-12-30 11:07:16 -05:00
|
|
|
val classify : t -> Ipaddr.t -> Packet.host
|
2016-01-01 06:32:57 -05:00
|
|
|
val resolve : t -> Packet.host -> Ipaddr.t
|
2016-01-02 10:50:05 -05:00
|
|
|
|
|
|
|
val reset : t -> unit
|
|
|
|
(** Clear the NAT table (to free memory). *)
|