add the network_config to the router

This commit is contained in:
palainp 2023-06-30 15:33:41 +02:00
parent 5a0711bb2d
commit de9a1dbd1c
3 changed files with 13 additions and 9 deletions

View File

@ -6,13 +6,14 @@ open Fw_utils
(* The routing table *)
type t = {
config : Dao.network_config;
clients : Client_eth.t;
nat : My_nat.t;
uplink : interface;
}
let create ~clients ~uplink ~nat =
{ clients; nat; uplink }
let create ~config ~clients ~uplink ~nat =
{ config; clients; nat; uplink }
let target t buf =
let dst_ip = buf.Ipv4_packet.dst in
@ -24,11 +25,11 @@ let add_client t = Client_eth.add_client t.clients
let remove_client t = Client_eth.remove_client t.clients
let classify t ip =
if ip = Ipaddr.V4 t.uplink#my_ip then `Firewall
else if ip = Ipaddr.V4 t.uplink#other_ip then `NetVM
if ip = Ipaddr.V4 t.config.our_ip then `Firewall
else if ip = Ipaddr.V4 t.config.netvm_ip then `NetVM
else (Client_eth.classify t.clients ip :> Packet.host)
let resolve t = function
| `Firewall -> Ipaddr.V4 t.uplink#my_ip
| `NetVM -> Ipaddr.V4 t.uplink#other_ip
| `Firewall -> Ipaddr.V4 t.config.our_ip
| `NetVM -> Ipaddr.V4 t.config.netvm_ip
| #Client_eth.host as host -> Client_eth.resolve t.clients host

View File

@ -6,15 +6,17 @@
open Fw_utils
type t = private {
config : Dao.network_config;
clients : Client_eth.t;
nat : My_nat.t;
uplink : interface;
}
val create :
clients:Client_eth.t ->
uplink:interface ->
nat:My_nat.t ->
config : Dao.network_config ->
clients : Client_eth.t ->
uplink : interface ->
nat : My_nat.t ->
t
(** [create ~client_eth ~uplink ~nat] is a new routing table
that routes packets outside of [client_eth] via [uplink]. *)

View File

@ -55,6 +55,7 @@ module Main (R : Mirage_random.S)(Clock : Mirage_clock.MCLOCK)(Time : Mirage_tim
Client_eth.create config >>= fun clients ->
(* Set up routing between networks and hosts *)
let router = Router.create
~config
~clients
~uplink:(Uplink.interface uplink)
~nat