Skip to content

Commit

Permalink
apply suggestion from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Reynir Björnsson <[email protected]>
Co-authored-by: Romain Calascibetta <[email protected]>
  • Loading branch information
3 people committed Jun 19, 2024
1 parent 8d143db commit 07dd67a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
5 changes: 3 additions & 2 deletions config.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(* mirage >= 4.5.0 & < 4.6.0 *)
open Mirage

(* xenstore id 51712 is the root volume *)
let block = block_of_xenstore_id "51712"
let config = tar_kv_ro block
let ethernet = etif default_network
Expand All @@ -11,10 +12,10 @@ let ipv4_only = Runtime_arg.ipv4_only ~group:"sys-net" ()
let ipv6_only = Runtime_arg.ipv4_only ~group:"sys-net" ()
let stack = direct_stackv4v6 ~ipv4_only ~ipv6_only default_network ethernet arp ipv4 ipv6

let config_fn = runtime_arg ~pos:__POS__ "Unikernel.config_fn"
let config_key = runtime_arg ~pos:__POS__ "Unikernel.config_key"

let main =
main ~runtime_args:[ config_fn ]
main ~runtime_args:[ config_key ]
~packages:
[
package "vchan" ~min:"4.0.2";
Expand Down
16 changes: 7 additions & 9 deletions unikernel.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
let ( let* ) = Lwt.bind
let ( % ) f g = fun x -> f (g x)

let config_fn =
let doc = Cmdliner.Arg.info ~doc:"OpenVPN config filename." [ "config_fn" ] in
let config_key =
let doc = Cmdliner.Arg.info ~doc:"OpenVPN config filename." [ "config_key" ] in
Cmdliner.Arg.(value & opt string "/config.ovpn" doc)

module Main
Expand Down Expand Up @@ -271,21 +271,19 @@ struct
(* TODO(dinosaure): should report ICMP error message to src. *)
ingest_private t end

let openvpn_configuration disk config_fn =
let* contents = KV.get disk (Mirage_kv.Key.v config_fn) in
let openvpn_configuration disk config_key =
let* contents = KV.get disk (Mirage_kv.Key.v config_key) in
match contents with
| Error _ ->
Logs.err(fun m -> m "Expected configuration file '%s' is absent in the root volume" config_fn);
Logs.err(fun m -> m "Try to run in dom0: qvm-volume import mirage-vpn:root vpn.tar");
Logs.err(fun m -> m " with the tarball conatining the requested configuration file");
Logs.err(fun m -> m "Expected configuration file '%s' is absent in the root volume.\nTry to run in dom0:\n qvm-volume import mirage-vpn:root vpn.tar\nwith the tarball containing the requested configuration file." config_key);
Fmt.failwith "No OpenVPN configuration found"
| Ok contents -> (
let string_of_file _ = Error (`Msg "Impossible to load extra files") in
match Miragevpn.Config.parse_client ~string_of_file contents with
| Ok cfg -> Lwt.return cfg
| Error _ -> Fmt.failwith "Invalid OpenVPN configuration")

let start _random _mclock _pclock _time qubesDB vif0 disk config_fn =
let start _random _mclock _pclock _time qubesDB vif0 disk config_key =
Logs.debug (fun m -> m "Start the unikernel");
let shutdown =
let* value = Xen_os.Lifecycle.await_shutdown_request () in
Expand All @@ -297,7 +295,7 @@ struct
Ipaddr.V4.pp (fst cfg.Dao.dns)
Ipaddr.V4.pp (snd cfg.Dao.dns));
let clients = Clients.create cfg in
let* config = openvpn_configuration disk config_fn in
let* config = openvpn_configuration disk config_key in
Logs.debug (fun m -> m "OpenVPN configuration loaded");
let* ovpn = O.connect config vif0 in
match ovpn with
Expand Down

0 comments on commit 07dd67a

Please sign in to comment.