Skip to content
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ vpnkit.exe: src/bin/depends.ml

.PHONY: test
test:
jbuilder build --dev src/hostnet_test/main_uwt.exe
./_build/default/src/hostnet_test/main_uwt.exe
jbuilder build --dev src/hostnet_test/main.exe
./_build/default/src/hostnet_test/main.exe

.PHONY: OSS-LICENSES
OSS-LICENSES:
Expand Down
4 changes: 2 additions & 2 deletions src/bin/connect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let (/) = Filename.concat
let home = try Sys.getenv "HOME" with Not_found -> "/Users/root"
let vsock_port = 62373l

module Make_unix(Host: Sig.HOST) = struct
module Unix = struct

let vsock_path =
ref (home / "Library/Containers/com.docker.docker/Data/@connect")
Expand Down Expand Up @@ -41,7 +41,7 @@ module Make_unix(Host: Sig.HOST) = struct
Fmt.kstrf Lwt.fail_with "%a" pp_write_error e
end

module Make_hvsock(Host: Sig.HOST) = struct
module Hvsock = struct
(* Avoid using `detach` because we don't want to exhaust the
thread pool since this will block the main TCP/IP stack. *)
module F =
Expand Down
4 changes: 2 additions & 2 deletions src/bin/connect.mli
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Make_unix(Host: Sig.HOST): sig
module Unix: sig
include Sig.Connector

val vsock_path: string ref
end

module Make_hvsock(Host: Sig.HOST): sig
module Hvsock: sig
include Sig.Connector

val set_port_forward_addr: Hvsock.sockaddr -> unit
Expand Down
34 changes: 8 additions & 26 deletions src/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,16 @@ let hvsock_addr_of_uri ~default_serviceid uri =
in
{ Hvsock.vmid; serviceid }

module Main(Host: Sig.HOST) = struct

module Vnet = Basic_backend.Make
module Connect_unix = Connect.Make_unix(Host)
module Connect_hvsock = Connect.Make_hvsock(Host)
module Connect_unix = Connect.Unix
module Connect_hvsock = Connect.Hvsock
module Bind = Bind.Make(Host.Sockets)
module Dns_policy = Hostnet_dns.Policy(Host.Files)
module Config = Active_config.Make(Host.Time)(Host.Sockets.Stream.Unix)
module Forward_unix = Forward.Make(Mclock)(Connect_unix)(Bind)
module Forward_hvsock = Forward.Make(Mclock)(Connect_hvsock)(Bind)
module HV = Flow_lwt_hvsock.Make(Host.Time)(Host.Fn)
module Hosts = Hosts.Make(Host.Files)
module HostsFile = Hosts.Make(Host.Files)

let file_descr_of_int (x: int) : Unix.file_descr =
if Sys.os_type <> "Unix"
Expand Down Expand Up @@ -256,7 +254,7 @@ module Main(Host: Sig.HOST) = struct
~config:(`Upstream { servers; search = [];
assume_offline_after_drops = None }) );

let etc_hosts_watch = match Hosts.watch ~path:hosts () with
let etc_hosts_watch = match HostsFile.watch ~path:hosts () with
| Ok watch -> Some watch
| Error (`Msg m) ->
Log.err (fun f -> f "Failed to watch hosts file %s: %s" hosts m);
Expand Down Expand Up @@ -330,7 +328,7 @@ module Main(Host: Sig.HOST) = struct
| Some "hyperv-connect" ->
let module Slirp_stack =
Slirp.Make(Config)(Vmnet.Make(HV))(Dns_policy)
(Mclock)(Stdlibrandom)(Host)(Vnet)
(Mclock)(Stdlibrandom)(Vnet)
in
let sockaddr =
hvsock_addr_of_uri ~default_serviceid:ethernet_serviceid
Expand All @@ -352,7 +350,7 @@ module Main(Host: Sig.HOST) = struct
| _ ->
let module Slirp_stack =
Slirp.Make(Config)(Vmnet.Make(Host.Sockets.Stream.Unix))(Dns_policy)
(Mclock)(Stdlibrandom)(Host)(Vnet)
(Mclock)(Stdlibrandom)(Vnet)
in
unix_listen socket_url >>= fun server ->
( match config with
Expand All @@ -370,7 +368,7 @@ module Main(Host: Sig.HOST) = struct
let wait_forever, _ = Lwt.task () in
wait_forever >|= fun () ->
match etc_hosts_watch with
| Some watch -> Hosts.unwatch watch
| Some watch -> HostsFile.unwatch watch
| None -> ()

let main
Expand All @@ -382,18 +380,6 @@ module Main(Host: Sig.HOST) = struct
(main_t socket_url port_control_url introspection_url diagnostics_url
max_connections vsock_path db_path db_branch dns hosts host_names
listen_backlog debug)
end

let main
socket port_control introspection_url diagnostics_url max_connections
vsock_path db_path db_branch dns hosts host_names select listen_backlog
debug
=
let module Use_lwt_unix = Main(Host_lwt_unix) in
let module Use_uwt = Main(Host_uwt) in
(if select then Use_lwt_unix.main else Use_uwt.main)
socket port_control introspection_url diagnostics_url max_connections
vsock_path db_path db_branch dns hosts host_names listen_backlog debug

open Cmdliner

Expand Down Expand Up @@ -510,10 +496,6 @@ let host_names =
in
Arg.(value & opt string "vpnkit.host" doc)

let select =
let doc = "Use a select event loop rather than the default libuv-based one" in
Arg.(value & flag & info [ "select" ] ~doc)

let listen_backlog =
let doc = "Specify a maximum listen(2) backlog. If no override is specified \
then we will use SOMAXCONN." in
Expand All @@ -533,7 +515,7 @@ let command =
Term.(pure main
$ socket $ port_control_path $ introspection_path $ diagnostics_path
$ max_connections $ vsock_path $ db_path $ db_branch $ dns $ hosts
$ host_names $ select $ listen_backlog $ debug),
$ host_names $ listen_backlog $ debug),
Term.info (Filename.basename Sys.argv.(0)) ~version:Depends.version ~doc ~man

let () =
Expand Down
6 changes: 3 additions & 3 deletions src/hostnet/arp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ module Make (Ethif: Mirage_protocols_lwt.ETHIF) = struct
f "error while reading ARP packet: %a" Ethif.pp_error e);
end else Lwt.return_unit
|2 -> (* Reply *)
(* the requested address *)
(* the requested address *)
let spa = Ipaddr.V4.of_int32 (get_arp_tpa frame) in
Log.debug (fun f -> f "ARP ignoring reply %s" (Ipaddr.V4.to_string spa));
Lwt.return_unit
Expand All @@ -156,8 +156,8 @@ module Make (Ethif: Mirage_protocols_lwt.ETHIF) = struct
let connect ~table ethif =
let table =
List.fold_left (fun acc (ip, mac) ->
Table.add ip mac acc
) Table.empty table
Table.add ip mac acc
) Table.empty table
in
{ table; ethif }

Expand Down
38 changes: 19 additions & 19 deletions src/hostnet/host_uwt.ml → src/hostnet/host.ml
Original file line number Diff line number Diff line change
Expand Up @@ -409,30 +409,30 @@ module Sockets = struct
let connect ?(read_buffer_size = default_read_buffer_size) (ip, port) =
let description = Fmt.strf "tcp:%a:%d" Ipaddr.pp_hum ip port in
let label = match ip with
| Ipaddr.V4 _ -> "TCPv4"
| Ipaddr.V6 _ -> "TCPv6" in
| Ipaddr.V4 _ -> "TCPv4"
| Ipaddr.V6 _ -> "TCPv6" in
register_connection_noexn description
>>= function
| None ->
errorf "Socket.%s.connect %s: hit connection limit" label description
| Some idx ->
let fd =
try match ip with
| Ipaddr.V4 _ -> Uwt.Tcp.init_ipv4_exn ()
| Ipaddr.V6 _ -> Uwt.Tcp.init_ipv6_exn ()
with e -> deregister_connection idx; raise e in
Lwt.catch (fun () ->
let sockaddr = make_sockaddr (ip, port) in
Uwt.Tcp.connect fd ~addr:sockaddr >>= fun () ->
of_fd ~idx ~label ~read_buffer_size ~description fd
|> Lwt_result.return
) (fun e ->
deregister_connection idx;
log_exception_continue "Tcp.connect Uwt.Tcp.close_wait"
(fun () -> Uwt.Tcp.close_wait fd)
>>= fun () ->
errorf "Socket.%s.connect %s: caught %a" label description Fmt.exn e
)
let fd =
try match ip with
| Ipaddr.V4 _ -> Uwt.Tcp.init_ipv4_exn ()
| Ipaddr.V6 _ -> Uwt.Tcp.init_ipv6_exn ()
with e -> deregister_connection idx; raise e in
Lwt.catch (fun () ->
let sockaddr = make_sockaddr (ip, port) in
Uwt.Tcp.connect fd ~addr:sockaddr >>= fun () ->
of_fd ~idx ~label ~read_buffer_size ~description fd
|> Lwt_result.return
) (fun e ->
deregister_connection idx;
log_exception_continue "Tcp.connect Uwt.Tcp.close_wait"
(fun () -> Uwt.Tcp.close_wait fd)
>>= fun () ->
errorf "Socket.%s.connect %s: caught %a" label description Fmt.exn e
)

let shutdown_read _ =
Lwt.return ()
Expand Down
File renamed without changes.
Loading