Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to mirage 4.8 #284

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ freebsd_instance:
freebsd_client_task:
pkg_install_script: pkg install -y ocaml-opam gmake bash
ocaml_script: opam init -a --comp=4.14.2
mirage_script: eval `opam env` && opam install --confirm-level=unsafe-yes "mirage>=4.7.0"
mirage_script: eval `opam env` && opam install --confirm-level=unsafe-yes "mirage>=4.8.0"
configure_script: eval `opam env` && cd mirage-client && mirage configure -t hvt
depend_script: eval `opam env` && cd mirage-client && gmake depend
copy_script: rm -rf mirage-client/duniverse/miragevpn/* && cp -R dune-project miragevpn.opam src mirage mirage-client/duniverse/miragevpn/
Expand All @@ -15,7 +15,7 @@ freebsd_client_task:
freebsd_router_task:
pkg_install_script: pkg install -y ocaml-opam gmake bash
ocaml_script: opam init -a --comp=4.14.2
mirage_script: eval `opam env` && opam install --confirm-level=unsafe-yes "mirage>=4.7.0"
mirage_script: eval `opam env` && opam install --confirm-level=unsafe-yes "mirage>=4.8.0"
configure_script: eval `opam env` && cd mirage-router && mirage configure -t hvt --enable-monitoring
depend_script: eval `opam env` && cd mirage-router && gmake depend
copy_script: rm -rf mirage-router/duniverse/miragevpn/* && cp -R dune-project miragevpn.opam src mirage mirage-router/duniverse/miragevpn/
Expand All @@ -26,7 +26,7 @@ freebsd_router_task:
freebsd_server_task:
pkg_install_script: pkg install -y ocaml-opam gmake bash
ocaml_script: opam init -a --comp=4.14.2
mirage_script: eval `opam env` && opam install --confirm-level=unsafe-yes "mirage>=4.7.0"
mirage_script: eval `opam env` && opam install --confirm-level=unsafe-yes "mirage>=4.8.0"
configure_script: eval `opam env` && cd mirage-server && mirage configure -t hvt
depend_script: eval `opam env` && cd mirage-server && gmake depend
copy_script: rm -rf mirage-server/duniverse/miragevpn/* && cp -R dune-project miragevpn.opam src mirage mirage-server/duniverse/miragevpn/
Expand Down
2 changes: 1 addition & 1 deletion mirage-client/config.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* mirage >= 4.7.0 & < 4.8.0 *)
(* mirage >= 4.7.0 & < 4.9.0 *)

open Mirage

Expand Down
10 changes: 2 additions & 8 deletions mirage-router/config.ml
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
(* mirage >= 4.7.0 & < 4.8.0 *)
(* mirage >= 4.8.0 & < 4.9.0 *)

open Mirage

let private_netif = netif ~group:"private" "private"
let private_ethernet = ethif private_netif
let private_arp = arp private_ethernet
(* this is temporary until we find a better way *)
let ip = Runtime_arg.V4.network ~group:"private" (Ipaddr.V4.Prefix.of_string_exn "10.0.0.2/24")
let private_ipv4 = create_ipv4 ~group:"private" private_ethernet private_arp

let nat = runtime_arg ~pos:__POS__ "Unikernel.K.nat"
let nat_table_size = runtime_arg ~pos:__POS__ "Unikernel.K.nat_table_size"

let miragevpn_handler =
let packages =
let pin = "git+https://github.com/robur-coop/miragevpn.git" in
Expand All @@ -21,9 +16,8 @@ let miragevpn_handler =
package "mirage-kv";
package ~min:"3.0.0" "mirage-nat";
]
and runtime_args = [ Runtime_arg.v ip ; nat ; nat_table_size ]
in
main ~runtime_args ~packages "Unikernel.Main"
main ~packages "Unikernel.Main"
(random @-> mclock @-> pclock @-> time @-> stackv4v6 @-> network
@-> ethernet @-> arpv4 @-> ipv4 @-> block @-> job)

Expand Down
13 changes: 7 additions & 6 deletions mirage-router/unikernel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ module K = struct
let doc = Arg.info ~doc:"Use network address translation (NAT) on local traffic before sending over the tunnel."
["nat"]
in
Arg.(value & flag doc)
Mirage_runtime.register_arg Arg.(value & flag doc)

let nat_table_size =
let doc = Arg.info ~doc:"The size of the NAT table (n/100 -> ICMP, n/2 -> TCP, n/2 -> UDP)." ["nat-table-size"] in
Arg.(value & opt int 2048 doc)
Mirage_runtime.register_arg Arg.(value & opt int 2048 doc)
end

module Main
Expand Down Expand Up @@ -484,14 +484,14 @@ struct
t.ovpn_fragments <- frags;
ovpn_recv t private_ip

let start _ _ _ _ s net eth arp ip block private_ip nat nat_table_size =
let start _ _ _ _ s net eth arp ip block =
(* TODO maybe rename private to local? *)
(let open Lwt_result.Infix in
read_config block >>= fun config ->
let nat =
if nat then
let icmp_size = nat_table_size / 100 in
let tcp_size = (nat_table_size - icmp_size) / 2 in
if K.nat () then
let icmp_size = K.nat_table_size () / 100 in
let tcp_size = (K.nat_table_size () - icmp_size) / 2 in
Logs.info (fun m -> m "Using NAT with %u ICMP, %u TCP, and %u UDP entries"
icmp_size tcp_size tcp_size);
Some (Mirage_nat_lru.empty ~tcp_size ~udp_size:tcp_size ~icmp_size)
Expand All @@ -510,6 +510,7 @@ struct
private_fragments = Fragments.Cache.empty (256 * 1024);
}
in
let private_ip = List.hd (I.configured_ips ip) in
Lwt_result.ok (Lwt.join
[ ovpn_recv t private_ip;
private_recv t private_ip net eth arp ]))
Expand Down
13 changes: 3 additions & 10 deletions mirage-server/config.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* mirage >= 4.7.0 & < 4.8.0 *)
(* mirage >= 4.8.0 & < 4.9.0 *)

open Mirage

Expand All @@ -14,15 +14,8 @@ let miragevpn_handler =
package "mirage-nat";
package "tcpip" ~sublibs:[ "stack-direct" ];
]
and runtime_args = [
runtime_arg ~pos:__POS__ "Unikernel.K.ipv4";
runtime_arg ~pos:__POS__ "Unikernel.K.ipv4_gateway";
runtime_arg ~pos:__POS__ "Unikernel.K.ipv4_only";
runtime_arg ~pos:__POS__ "Unikernel.K.ipv6_only";
runtime_arg ~pos:__POS__ "Unikernel.K.nat_table_size";
runtime_arg ~pos:__POS__ "Unikernel.K.really_no_authentication";
] in
main ~runtime_args ~packages "Unikernel.Main"
in
main ~packages "Unikernel.Main"
(random @-> mclock @-> pclock @-> time @-> network @-> ethernet @-> arpv4 @-> ipv6 @-> block @-> job)

let block =
Expand Down
27 changes: 15 additions & 12 deletions mirage-server/unikernel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@ module K = struct
open Cmdliner

let ipv4 =
Mirage_runtime_network.V4.network (Ipaddr.V4.Prefix.of_string_exn "10.0.0.2/24")
Mirage_runtime.register_arg
(Mirage_runtime_network.V4.network (Ipaddr.V4.Prefix.of_string_exn "10.0.0.2/24"))

let ipv4_gateway =
Mirage_runtime_network.V4.gateway None
Mirage_runtime.register_arg (Mirage_runtime_network.V4.gateway None)

let ipv4_only = Mirage_runtime_network.ipv4_only ()
let ipv4_only =
Mirage_runtime.register_arg (Mirage_runtime_network.ipv4_only ())

let ipv6_only = Mirage_runtime_network.ipv6_only ()
let ipv6_only =
Mirage_runtime.register_arg (Mirage_runtime_network.ipv6_only ())

let nat_table_size =
let doc = Arg.info ~doc:"The size of the NAT table (n/100 -> ICMP, n/2 -> TCP, n/2 -> UDP)." ["nat-table-size"] in
Arg.(value & opt int 2048 doc)
Mirage_runtime.register_arg Arg.(value & opt int 2048 doc)

let really_no_authentication =
let doc = Arg.info ~doc:"Allow to not do any authentication. This will allow any client to connect."
["really-no-authentication"]
in
Arg.(value & flag doc)
Mirage_runtime.register_arg Arg.(value & flag doc)
end

module Main
Expand Down Expand Up @@ -304,27 +307,27 @@ begin
| Error e -> Logs.warn (fun m -> m "error %a when sending data received over tunnel"
S.IP.pp_error e)

let start _ _ _ _ net eth arp ipv6 block ipv4 ipv4_gateway ipv4_only ipv6_only nat_table_size really_no_authentication =
let start _ _ _ _ net eth arp ipv6 block =
read_config block >>= function
| Error (`Msg msg) ->
Logs.err (fun m -> m "error while reading config %s" msg);
failwith "config file error"
| Ok config ->
let table =
let icmp_size = nat_table_size / 100 in
let tcp_size = (nat_table_size - icmp_size) / 2 in
let icmp_size = K.nat_table_size () / 100 in
let tcp_size = (K.nat_table_size () - icmp_size) / 2 in
Logs.info (fun m -> m "Using NAT with %u ICMP, %u TCP, and %u UDP entries"
icmp_size tcp_size tcp_size);
Mirage_nat_lru.empty ~tcp_size ~udp_size:tcp_size ~icmp_size
in
Ipv4.connect ~no_init:ipv6_only ~cidr:ipv4 ?gateway:ipv4_gateway eth arp table config >>= fun ipv4 ->
IPV4V6.connect ~ipv4_only ~ipv6_only ipv4 ipv6 >>= fun ip ->
Ipv4.connect ~no_init:(K.ipv6_only ()) ~cidr:(K.ipv4 ()) ?gateway:(K.ipv4_gateway ()) eth arp table config >>= fun ipv4 ->
IPV4V6.connect ~ipv4_only:(K.ipv4_only ()) ~ipv6_only:(K.ipv6_only ()) ipv4 ipv6 >>= fun ip ->
ICMP.connect ipv4 >>= fun icmp ->
UDP.connect ip >>= fun udp ->
TCP.connect ip >>= fun tcp ->
S.connect net eth arp ip icmp udp tcp >>= fun stack ->
let payloadv4_from_tunnel = payloadv4_from_tunnel config table stack in
let t = O.connect ~really_no_authentication ~payloadv4_from_tunnel config stack in
let t = O.connect ~really_no_authentication:(K.really_no_authentication ()) ~payloadv4_from_tunnel config stack in
Ipv4.inject_write (O.write t);
let task, _u = Lwt.task () in
task
Expand Down
Loading