Skip to content

Commit

Permalink
Merge pull request #4 from palainp/add-config
Browse files Browse the repository at this point in the history
Add config file argument
  • Loading branch information
dinosaure authored Jun 20, 2024
2 parents 283750d + 3f622ea commit 8342b25
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
6 changes: 5 additions & 1 deletion config.ml
Original file line number Diff line number Diff line change
@@ -1,5 +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 @@ -10,8 +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_key = runtime_arg ~pos:__POS__ "Unikernel.config_key"

let main =
main ~runtime_args:[]
main ~runtime_args:[ config_key ]
~packages:
[
package "vchan" ~min:"4.0.2";
Expand Down
2 changes: 1 addition & 1 deletion qubes-miragevpn.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c38251c9c0e72e891b0bffeba3ab4a14244360df3eaea4b87af778e299f1d2b7 ./dist/qubes-miragevpn.xen
2959804554bc7bca62d391355086abe80ffe37c35ce3c016eba0320a3077d0e0 ./dist/qubes-miragevpn.xen
16 changes: 11 additions & 5 deletions unikernel.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
let ( let* ) = Lwt.bind
let ( % ) f g = fun x -> f (g x)

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
(R : Mirage_random.S)
(M : Mirage_clock.MCLOCK)
Expand Down Expand Up @@ -267,17 +271,19 @@ struct
(* TODO(dinosaure): should report ICMP error message to src. *)
ingest_private t end

let openvpn_configuration disk =
let* contents = KV.get disk (Mirage_kv.Key.v "/config.ovpn") in
let openvpn_configuration disk config_key =
let* contents = KV.get disk (Mirage_kv.Key.v config_key) in
match contents with
| Error _ -> Fmt.failwith "No OpenVPN configuration found"
| Error _ ->
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 =
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 @@ -289,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 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 8342b25

Please sign in to comment.