Skip to content

Commit 24caf7a

Browse files
committed
Update Mirage packages
This also allows VPNkit to be build with OCaml 5+ Signed-off-by: Patrick Ferris <[email protected]>
1 parent 604ab7f commit 24caf7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+357
-309
lines changed

dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
(rule
2525
(target vpnkit.tgz)
26+
(enabled_if (= %{os_type} "macOS"))
2627
(deps vpnkit.exe (:gen ./scripts/mac_package.exe))
2728
(action (run %{gen} -out %{target} -in %{deps})))
2829

src/bin/config/discover.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let os_type () =
1111
let flags () =
1212
match os_type () with
1313
| "Linux" ->
14-
[ "-ccopt"; "-static" ]
14+
[ "-ccopt"; "-static" ]
1515
| _ ->
1616
[]
1717

src/bin/config/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
(executable
22
(name discover)
3-
(libraries sexplib))
3+
(libraries unix sexplib))

src/bin/connect.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ module Hvsock = struct
8383
let read t = F.read t.flow
8484
let write t = F.write t.flow
8585
let writev t = F.writev t.flow
86-
let shutdown_read t = F.shutdown_read t.flow
87-
let shutdown_write t = F.shutdown_write t.flow
86+
let shutdown t = F.shutdown t.flow
8887
let pp_error = F.pp_error
8988
let pp_write_error = F.pp_write_error
9089
type error = F.error

src/bin/main.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -863,21 +863,21 @@ let gc_compact =
863863
in
864864
Arg.(value & opt (some int) None doc)
865865

866-
let command =
866+
let term, info =
867867
let doc = "proxy TCP/IP connections from an ethernet link via sockets" in
868868
let man =
869869
[`S "DESCRIPTION";
870870
`P "Terminates TCP/IP and UDP/IP connections from a client and proxy the\
871871
flows via userspace sockets"]
872872
in
873-
Term.(pure main
873+
Term.(const main
874874
$ socket $ port_control_urls $ introspection_urls $ diagnostics_urls $ pcap_urls $ pcap_snaplen
875875
$ max_connections $ port_forwards $ dns $ http $ http_intercept_api_path $ hosts
876876
$ host_names $ gateway_names $ vm_names $ listen_backlog $ port_max_idle_time $ debug
877877
$ server_macaddr $ domain $ allowed_bind_addresses $ gateway_ip $ host_ip
878878
$ lowest_ip $ highest_ip $ dhcp_json_path $ mtu $ udpv4_forwards $ tcpv4_forwards
879879
$ gateway_forwards_path $ forwards_path $ gc_compact),
880-
Term.info (Filename.basename Sys.argv.(0)) ~version:Version.git ~doc ~man
880+
Cmd.info (Filename.basename Sys.argv.(0)) ~version:Version.git ~doc ~man
881881

882882
let () =
883883
Printexc.record_backtrace true;
@@ -886,4 +886,5 @@ let () =
886886
Log.err (fun f ->
887887
f "Lwt.async failure %a: %s" Fmt.exn exn (Printexc.get_backtrace ()))
888888
);
889-
Term.exit @@ Term.eval command
889+
let command = Cmd.v info term in
890+
exit (Cmd.eval command)

src/dns_forward/dns_forward.mli

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module Flow: sig
3737
on a well-known address (see Server) *)
3838

3939
module type Client = sig
40-
include Mirage_flow_combinators.SHUTDOWNABLE
40+
include Mirage_flow.S
4141

4242
type address
4343
(** Identifies an endpoint for [connect] *)
@@ -64,7 +64,7 @@ module Flow: sig
6464
(** Accept connections forever, calling the callback with each one.
6565
Connections are closed automatically when the callback finishes. *)
6666

67-
val shutdown: server -> unit Lwt.t
67+
val stop: server -> unit Lwt.t
6868
(** Stop accepting connections on the given server *)
6969
end
7070
end
@@ -253,7 +253,7 @@ module Rpc: sig
253253
(** Listen and accept incoming connections, use the provided callback to
254254
answer requests. *)
255255

256-
val shutdown: server -> unit Lwt.t
256+
val stop: server -> unit Lwt.t
257257
(** Shutdown the server and free any allocated resources. *)
258258
end
259259

src/dns_forward/dns_forward_rpc.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ module Server = struct
370370
);
371371
Lwt_result.return ()
372372
373-
let shutdown server =
374-
Sockets.shutdown server.server
373+
let stop server =
374+
Sockets.stop server.server
375375
376376
end
377377
end

src/dns_forward/dns_forward_s.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module type Comparable = sig
2222
end
2323

2424
module type FLOW_CLIENT = sig
25-
include Mirage_flow_combinators.SHUTDOWNABLE
25+
include Mirage_flow.S
2626
type address
2727
val connect: ?read_buffer_size:int -> address
2828
-> (flow, [ `Msg of string ]) Lwt_result.t
@@ -35,7 +35,7 @@ module type FLOW_SERVER = sig
3535
val getsockname: server -> address
3636
type flow
3737
val listen: server -> (flow -> unit Lwt.t) -> unit
38-
val shutdown: server -> unit Lwt.t
38+
val stop: server -> unit Lwt.t
3939
end
4040

4141
module type RPC_CLIENT = sig
@@ -57,7 +57,7 @@ module type RPC_SERVER = sig
5757
type server
5858
val bind: address -> (server, [ `Msg of string ]) Lwt_result.t
5959
val listen: server -> (request -> (response, [ `Msg of string ]) Lwt_result.t) -> (unit, [ `Msg of string ]) Lwt_result.t
60-
val shutdown: server -> unit Lwt.t
60+
val stop: server -> unit Lwt.t
6161
end
6262

6363
module type RESOLVER = sig

src/dns_forward/dns_forward_server.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ module Make(Server: Dns_forward_s.RPC_SERVER)(Resolver: Dns_forward_s.RESOLVER)
5252
>>= fun () ->
5353
match server with
5454
| None -> Lwt.return_unit
55-
| Some server -> Server.shutdown server
55+
| Some server -> Server.stop server
5656
end

src/dns_forward_lwt_unix/dns_forward_lwt_unix.ml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ module Tcp = struct
193193
Lwt.return_unit
194194
)
195195

196+
let shutdown t = function
197+
| `read -> shutdown_read t
198+
| `write -> shutdown_write t
199+
| `read_write ->
200+
shutdown_read t >>= fun () ->
201+
shutdown_write t
202+
196203
type server = {
197204
mutable server_fd: Lwt_unix.file_descr option;
198205
read_buffer_size: int;
@@ -221,7 +228,7 @@ module Tcp = struct
221228

222229
let getsockname server = getsockname "Tcp.getsockname" server.server_fd
223230

224-
let shutdown server = match server.server_fd with
231+
let stop server = match server.server_fd with
225232
| None -> Lwt.return_unit
226233
| Some fd ->
227234
server.server_fd <- None;
@@ -279,7 +286,7 @@ module Tcp = struct
279286
Lwt_unix.listen fd 32;
280287
loop fd
281288
) (fun () ->
282-
shutdown server
289+
stop server
283290
)
284291
) (fun e ->
285292
Log.info (fun f -> f "%s: caught %s so shutting down server"
@@ -373,8 +380,7 @@ module Udp = struct
373380
Log.debug (fun f -> f "%s: close" (string_of_flow t));
374381
Lwt_unix.close fd
375382

376-
let shutdown_read _t = Lwt.return_unit
377-
let shutdown_write _t = Lwt.return_unit
383+
let shutdown _t _ = Lwt.return_unit
378384

379385
type server = {
380386
mutable server_fd: Lwt_unix.file_descr option;
@@ -396,7 +402,7 @@ module Udp = struct
396402
| e -> errorf "udp:%s: bind caught %s"
397403
(string_of_address address) (Printexc.to_string e)
398404

399-
let shutdown t = match t.server_fd with
405+
let stop t = match t.server_fd with
400406
| None -> Lwt.return_unit
401407
| Some fd ->
402408
t.server_fd <- None;

src/dns_forward_test/flow.ml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ let shutdown_write flow =
8484
Lwt_condition.signal flow.l2r_c ();
8585
Lwt.return_unit
8686

87+
let shutdown flow = function
88+
| `read -> shutdown_read flow
89+
| `write -> shutdown_write flow
90+
| `read_write ->
91+
let open Lwt.Infix in
92+
shutdown_read flow >>= fun () ->
93+
shutdown_write flow
94+
8795
let writev flow bufs =
8896
if flow.l2r_closed then Lwt.return (Error `Closed) else (
8997
List.iter (fun buf -> ignore @@ Lwt_dllist.add_l buf flow.l2r) bufs;
@@ -145,7 +153,8 @@ let listen server (cb: flow -> unit Lwt.t) =
145153
);
146154
Lwt.return (Result.Ok flow) in
147155
server.listen_cb <- listen_cb
148-
let shutdown server =
156+
157+
let stop server =
149158
server.listen_cb <- (fun _ -> Lwt.return (Result.Error (`Msg "shutdown")));
150159
Hashtbl.remove bound server.address;
151160
Lwt.return_unit

src/dns_forward_test/rpc.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ let bind address =
8585
let listen server cb =
8686
server.listen_cb <- cb;
8787
Lwt.return (Result.Ok ())
88-
let shutdown server =
88+
let stop server =
8989
server.listen_cb <- (fun _ -> Lwt.return (Result.Error (`Msg "shutdown")));
9090
Hashtbl.remove bound server.address;
9191
Lwt.return_unit

src/dns_forward_test/server.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ module Make(Server: Rpc.Server.S) = struct
8787
>>= fun () ->
8888
Lwt.return (Ok server)
8989

90-
let shutdown = Server.shutdown
90+
let stop = Server.stop
9191

9292
end

src/dns_forward_test/server.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module Make(Server: Rpc.Server.S): sig
3232
val serve: address: Config.Address.t -> t -> server Error.t
3333
(** Serve requests on the given IP and port forever *)
3434

35-
val shutdown: server -> unit Lwt.t
35+
val stop: server -> unit Lwt.t
3636
(** Shutdown the running server *)
3737

3838
val get_nr_queries: t -> int

src/dns_forward_test/test.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ let test_cache () =
579579
>>= function
580580
| Error _ -> failwith "failed initial lookup"
581581
| Ok _ ->
582-
S.shutdown server
582+
S.stop server
583583
>>= fun () ->
584584
R.answer request r
585585
>>= function

src/dns_mirage/dns_resolver_mirage.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ open Dns_resolver
2020

2121
module DP = Packet
2222

23-
let default_ns = Ipaddr.V4.of_string_exn "8.8.8.8"
23+
let default_ns = Ipaddr.of_string_exn "8.8.8.8"
2424
let default_port = 53
2525

2626
module type S = sig
@@ -31,20 +31,20 @@ module type S = sig
3131

3232
val resolve :
3333
(module Protocol.CLIENT) ->
34-
t -> Ipaddr.V4.t -> int ->
34+
t -> Ipaddr.t -> int ->
3535
Packet.q_class ->
3636
Packet.q_type ->
3737
Name.t ->
3838
Packet.t Lwt.t
3939

4040
val gethostbyname : t ->
41-
?server:Ipaddr.V4.t -> ?dns_port:int ->
41+
?server:Ipaddr.t -> ?dns_port:int ->
4242
?q_class:Dns.Packet.q_class ->
4343
?q_type:Dns.Packet.q_type ->
4444
string -> Ipaddr.t list Lwt.t
4545

4646
val gethostbyaddr : t ->
47-
?server:Ipaddr.V4.t -> ?dns_port:int ->
47+
?server:Ipaddr.t -> ?dns_port:int ->
4848
?q_class:Dns.Packet.q_class ->
4949
?q_type:Dns.Packet.q_type ->
5050
Ipaddr.V4.t -> string list Lwt.t
@@ -80,10 +80,10 @@ module Static = struct
8080
return (Hashtbl.find_all s.rev addr)
8181
end
8282

83-
module Make(Time:Mirage_time.S)(S:Tcpip.Stack.V4) = struct
83+
module Make(Time:Mirage_time.S)(S:Tcpip.Stack.V4V6) = struct
8484

8585
type stack = S.t
86-
type endp = Ipaddr.V4.t * int
86+
type endp = Ipaddr.t * int
8787

8888
type t = {
8989
s: S.t;
@@ -95,7 +95,7 @@ module Make(Time:Mirage_time.S)(S:Tcpip.Stack.V4) = struct
9595
{ s; res }
9696

9797
let connect_to_resolver {s; res} ((dst,dst_port) as endp) =
98-
let udp = S.udpv4 s in
98+
let udp = S.udp s in
9999
try
100100
Hashtbl.find res endp
101101
with Not_found ->
@@ -105,13 +105,13 @@ module Make(Time:Mirage_time.S)(S:Tcpip.Stack.V4) = struct
105105
let src_port = (Random.int 64511) + 1024 in
106106
let callback ~src:_ ~dst:_ ~src_port:_ buf = Lwt_mvar.put mvar buf in
107107
let cleanfn () = return () in
108-
S.UDPV4.listen (S.udpv4 s) ~port:src_port callback;
108+
S.UDP.listen (S.udp s) ~port:src_port callback;
109109
let txfn buf =
110-
S.UDPV4.write ~src_port ~dst ~dst_port udp buf >>= function
110+
S.UDP.write ~src_port ~dst ~dst_port udp buf >>= function
111111
| Error e ->
112112
Fmt.kstr fail_with
113113
"Attempting to communicate with remote resolver: %a"
114-
S.UDPV4.pp_error e
114+
S.UDP.pp_error e
115115
| Ok () -> Lwt.return_unit
116116
in
117117
let rec rxfn f =

src/dns_mirage/dns_resolver_mirage.mli

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515
*)
1616

17-
val default_ns : Ipaddr.V4.t
17+
val default_ns : Ipaddr.t
1818
val default_port : int
1919

2020
module type S = sig
@@ -25,20 +25,20 @@ module type S = sig
2525

2626
val resolve :
2727
(module Dns.Protocol.CLIENT) ->
28-
t -> Ipaddr.V4.t -> int ->
28+
t -> Ipaddr.t -> int ->
2929
Dns.Packet.q_class ->
3030
Dns.Packet.q_type ->
3131
Dns.Name.t ->
3232
Dns.Packet.t Lwt.t
3333

3434
val gethostbyname : t ->
35-
?server:Ipaddr.V4.t -> ?dns_port:int ->
35+
?server:Ipaddr.t -> ?dns_port:int ->
3636
?q_class:Dns.Packet.q_class ->
3737
?q_type:Dns.Packet.q_type ->
3838
string -> Ipaddr.t list Lwt.t
3939

4040
val gethostbyaddr : t ->
41-
?server:Ipaddr.V4.t -> ?dns_port:int ->
41+
?server:Ipaddr.t -> ?dns_port:int ->
4242
?q_class:Dns.Packet.q_class ->
4343
?q_type:Dns.Packet.q_type ->
4444
Ipaddr.V4.t -> string list Lwt.t
@@ -52,4 +52,4 @@ type static_dns =
5252

5353
module Static : S with type stack = static_dns
5454

55-
module Make(Time:Mirage_time.S)(S:Tcpip.Stack.V4) : S with type stack = S.t
55+
module Make(Time:Mirage_time.S)(S:Tcpip.Stack.V4V6) : S with type stack = S.t

src/dns_mirage/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
(library
22
(name mirage_dns)
3-
(libraries dns_lwt duration mirage-time mirage-stack mirage-kv)
3+
(libraries dns_lwt duration mirage-time tcpip mirage-kv)
44
(wrapped false))

src/forwarder/multiplexer.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ module Make (Flow : Mirage_flow.S) = struct
261261
(* boilerplate: *)
262262
let shutdown_read _chanel = Lwt.return_unit
263263

264+
let shutdown channel = function
265+
| `write -> shutdown_write channel
266+
| `read -> shutdown_read channel
267+
| `read_write -> shutdown_read channel >>= fun () -> shutdown_write channel
268+
264269
let write channel buf = writev channel [buf]
265270

266271
type flow = channel

src/forwarder/multiplexer.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Make (Flow : Mirage_flow.S) : sig
66

77
val connect : flow -> Frame.Destination.t -> channel Lwt.t
88

9-
include Mirage_flow_combinators.SHUTDOWNABLE with type flow = channel
9+
include Mirage_flow.S with type flow = channel
1010

1111
val read_into: channel -> Cstruct.t -> (unit Mirage_flow.or_eof, error) result Lwt.t
1212
end

0 commit comments

Comments
 (0)