diff --git a/opam b/opam index eb6c1a79f..91559e15f 100644 --- a/opam +++ b/opam @@ -33,7 +33,7 @@ depends: [ "result" "tar-format" {= "0.6.1"} "ipaddr" - "lwt" { < "3.0.0" } + "lwt" { >= "2.7.0" } "uwt" { >= "0.0.4" } "tcpip" { >= "2.8.0" & < "3.0.0" } "pcap-format" diff --git a/repo/darwin/packages/local/slirp.local/opam b/repo/darwin/packages/local/slirp.local/opam index 95c96e461..b8f4febce 100644 --- a/repo/darwin/packages/local/slirp.local/opam +++ b/repo/darwin/packages/local/slirp.local/opam @@ -8,7 +8,7 @@ depends: [ "result" "tar-format" {= "0.6.1"} "ipaddr" - "lwt" { < "3.0.0" } + "lwt" { >= "2.7.0" } "uwt" {>= "0.0.4"} "tcpip" { = "999" } "pcap-format" diff --git a/src/bin/connect.ml b/src/bin/connect.ml index 1af904e56..8e0c1f507 100644 --- a/src/bin/connect.ml +++ b/src/bin/connect.ml @@ -76,7 +76,6 @@ module Make_hvsock(Host: Sig.HOST) = struct let flow = F.connect fd in Lwt.return { idx; flow } - let getclientname _ = failwith "Hyper-V socket implementation lacks getsockname" let read_into t = F.read_into t.flow let read t = F.read t.flow let write t = F.write t.flow diff --git a/src/bin/jbuild b/src/bin/jbuild index 8c557d71c..b1812870e 100644 --- a/src/bin/jbuild +++ b/src/bin/jbuild @@ -5,4 +5,5 @@ datakit-server.fs9p win-eventlog asl fd-send-recv )) (preprocess no_preprocessing) + (flags (:standard -warn-error "+1..49-3" -w "A-4-41-42-44")) )) diff --git a/src/bin/main.ml b/src/bin/main.ml index 1df073341..7a318cf83 100644 --- a/src/bin/main.ml +++ b/src/bin/main.ml @@ -19,7 +19,7 @@ module Log = (val Logs.src_log src : Logs.LOG) let _ = Printexc.register_printer (function | Unix.Unix_error(e, _, _) -> Some (Unix.error_message e) - | e -> None + | _ -> None ) let log_exception_continue description f = @@ -30,8 +30,6 @@ let log_exception_continue description f = Lwt.return () ) -let default d = function None -> d | Some x -> x - let ethernet_serviceid = "30D48B34-7D27-4B0B-AAAF-BBBED334DD59" let ports_serviceid = "0B95756A-9985-48AD-9470-78E060895BE7" @@ -194,7 +192,7 @@ let start_port_forwarding port_control_url max_connections vsock_path = ); Lwt.return_unit -let main_t socket_url port_control_url introspection_url diagnostics_url max_connections vsock_path db_path db_branch dns hosts pcap host_names debug = +let main_t socket_url port_control_url introspection_url diagnostics_url max_connections vsock_path db_path db_branch dns hosts host_names debug = (* Write to stdout if expicitly requested [debug = true] or if the environment variable DEBUG is set *) let env_debug = try ignore @@ Unix.getenv "DEBUG"; true with Not_found -> false in @@ -262,17 +260,15 @@ let main_t socket_url port_control_url introspection_url diagnostics_url max_con let host_names = List.map Dns.Name.of_string @@ Astring.String.cuts ~sep:"," host_names in let hardcoded_configuration = - let never, _ = Lwt.task () in - let pcap = match pcap with None -> None | Some filename -> Some (filename, None) in let server_macaddr = Slirp.default_server_macaddr in let peer_ip = Ipaddr.V4.of_string_exn "192.168.65.2" in let local_ip = Ipaddr.V4.of_string_exn "192.168.65.1" in let client_uuids : Slirp.uuid_table = { - mutex = Lwt_mutex.create (); + Slirp.mutex = Lwt_mutex.create (); table = Hashtbl.create 50; } in let global_arp_table : Slirp.arp_table = { - mutex = Lwt_mutex.create (); + Slirp.mutex = Lwt_mutex.create (); table = [(local_ip, server_macaddr)]; } in { @@ -353,16 +349,16 @@ let main_t socket_url port_control_url introspection_url diagnostics_url max_con | None -> () ); Lwt.return_unit -let main socket_url port_control_url introspection_url diagnostics_url max_connections vsock_path db_path db_branch dns hosts pcap host_names debug = +let main socket_url port_control_url introspection_url diagnostics_url max_connections vsock_path db_path db_branch dns hosts host_names debug = Host.Main.run - (main_t socket_url port_control_url introspection_url diagnostics_url max_connections vsock_path db_path db_branch dns hosts pcap host_names debug) + (main_t socket_url port_control_url introspection_url diagnostics_url max_connections vsock_path db_path db_branch dns hosts host_names debug) end -let main socket port_control introspection_url diagnostics_url max_connections vsock_path db_path db_branch dns hosts pcap host_names select debug = +let main socket port_control introspection_url diagnostics_url max_connections vsock_path db_path db_branch dns hosts host_names select 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 pcap host_names debug + socket port_control introspection_url diagnostics_url max_connections vsock_path db_path db_branch dns hosts host_names debug open Cmdliner @@ -465,13 +461,6 @@ let hosts = in Arg.(value & opt string Hosts.default_etc_hosts_path doc) -let pcap= - let doc = - Arg.info ~doc: - "Filename to write packet capture data to" ["pcap"] - in - Arg.(value & opt (some string) None doc) - let host_names = let doc = Arg.info ~doc: @@ -495,7 +484,7 @@ let command = `P "Terminates TCP/IP and UDP/IP connections from a client and proxy the\ flows via userspace sockets"] in - Term.(pure main $ socket $ port_control_path $ introspection_path $ diagnostics_path $ max_connections $ vsock_path $ db_path $ db_branch $ dns $ hosts $ pcap $ host_names $ select $ debug), + Term.(pure main $ socket $ port_control_path $ introspection_path $ diagnostics_path $ max_connections $ vsock_path $ db_path $ db_branch $ dns $ hosts $ host_names $ select $ debug), Term.info (Filename.basename Sys.argv.(0)) ~version:Depends.version ~doc ~man let () = diff --git a/src/hostnet/capture.ml b/src/hostnet/capture.ml index 68becd49a..472bf82de 100644 --- a/src/hostnet/capture.ml +++ b/src/hostnet/capture.ml @@ -175,7 +175,7 @@ module Make(Input: Sig.VMNET) = struct let record t bufs = try Hashtbl.iter - (fun name rule -> + (fun _ rule -> match Frame.parse bufs with | Result.Ok f -> if rule.predicate f then push rule bufs | Result.Error (`Msg m) -> failwith m @@ -232,9 +232,9 @@ module Make(Input: Sig.VMNET) = struct let stop_capture _ = failwith "Capture.stop_capture unimplemented" - let get_client_uuid t = + let get_client_uuid _ = failwith "Capture.get_client_uuid unimplemented" - let get_client_macaddr t = + let get_client_macaddr _ = failwith "Capture.get_client_macaddr unimplemented" end diff --git a/src/hostnet/cstructs.ml b/src/hostnet/cstructs.ml index 0e3b36ab5..7296624c8 100644 --- a/src/hostnet/cstructs.ml +++ b/src/hostnet/cstructs.ml @@ -33,7 +33,7 @@ let sub t off len = (* trim the length *) let rec trim acc ts remaining = match remaining, ts with | 0, _ -> List.rev acc - | n, [] -> err "invalid bounds in Cstructs.sub %a off=%d len=%d" pp_t t off len + | _, [] -> err "invalid bounds in Cstructs.sub %a off=%d len=%d" pp_t t off len | n, t :: ts -> let to_take = min (Cstruct.len t) n in (* either t is consumed and we only need ts, or t has data remaining in which diff --git a/src/hostnet/dhcp.ml b/src/hostnet/dhcp.ml index 110c71500..ab85940f2 100644 --- a/src/hostnet/dhcp.ml +++ b/src/hostnet/dhcp.ml @@ -30,7 +30,7 @@ module Make(Netif: V1_LWT.NETWORK) = struct | hd::tl -> List.fold_left (fun acc x -> if compare acc x > 0 then acc else x) hd tl (* given some MACs and IPs, construct a usable DHCP configuration *) - let make ~client_macaddr ~server_macaddr ~peer_ip ~highest_peer_ip ~local_ip ~extra_dns_ip + let make ~server_macaddr ~peer_ip ~highest_peer_ip ~local_ip ~extra_dns_ip ~get_domain_search ~get_domain_name netif = let open Dhcp_server.Config in (* FIXME: We need a DHCP range to make the DHCP server happy, even though we diff --git a/src/hostnet/dhcp.mli b/src/hostnet/dhcp.mli index b1bf1fd3e..ccbf604e9 100644 --- a/src/hostnet/dhcp.mli +++ b/src/hostnet/dhcp.mli @@ -4,7 +4,7 @@ module Make(Netif: V1_LWT.NETWORK): sig type t - val make: client_macaddr:Macaddr.t -> server_macaddr:Macaddr.t + val make: server_macaddr:Macaddr.t -> peer_ip: Ipaddr.V4.t -> highest_peer_ip: Ipaddr.V4.t option -> local_ip:Ipaddr.V4.t -> extra_dns_ip:Ipaddr.V4.t list -> get_domain_search:(unit -> string list) -> get_domain_name:(unit -> string) diff --git a/src/hostnet/error.ml b/src/hostnet/error.ml index 001630b99..231acbbce 100644 --- a/src/hostnet/error.ml +++ b/src/hostnet/error.ml @@ -1,14 +1,3 @@ -open Lwt.Infix - type 'a t = ('a, [ `Msg of string ]) Hostnet_lwt_result.t -module FromFlowError(Flow: V1_LWT.FLOW) = struct - let (>>=) m f = m >>= function - | `Eof -> Lwt.return (Result.Error (`Msg "Unexpected end of file")) - | `Error e -> Lwt.return (Result.Error (`Msg (Flow.error_message e))) - | `Ok x -> f x -end - -let errorf fmt = Printf.ksprintf (fun s -> Lwt.return (Result.Error (`Msg s))) fmt - module Infix = Hostnet_lwt_result.Infix diff --git a/src/hostnet/filter.ml b/src/hostnet/filter.ml index dc8868f1e..739b4c9f1 100644 --- a/src/hostnet/filter.ml +++ b/src/hostnet/filter.ml @@ -107,10 +107,10 @@ module Make(Input: Sig.VMNET) = struct let of_fd ~client_macaddr_of_uuid:_ ~server_macaddr:_ ~mtu:_ = failwith "Filter.of_fd unimplemented" - let get_client_uuid t = + let get_client_uuid _ = failwith "Filter.get_client_uuid unimplemented" - let get_client_macaddr t = + let get_client_macaddr _ = failwith "Filter.get_client_macaddr unimplemented" let start_capture _ ?size_limit:_ _ = diff --git a/src/hostnet/forward.ml b/src/hostnet/forward.ml index 5dd5a0307..79f2b6994 100644 --- a/src/hostnet/forward.ml +++ b/src/hostnet/forward.ml @@ -31,26 +31,14 @@ module Result = struct end module Int16 = struct - module M = struct - type t = int - let compare (a: t) (b: t) = Pervasives.compare a b - end - include M - module Map = Map.Make(M) - module Set = Set.Make(M) + type t = int end module Port = struct - module M = struct - type t = [ - | `Tcp of Ipaddr.t * Int16.t - | `Udp of Ipaddr.t * Int16.t - ] - let compare = compare - end - include M - module Map = Map.Make(M) - module Set = Set.Make(M) + type t = [ + | `Tcp of Ipaddr.t * Int16.t + | `Udp of Ipaddr.t * Int16.t + ] let to_string = function | `Tcp (addr, port) -> Printf.sprintf "tcp:%s:%d" (Ipaddr.to_string addr) port @@ -85,8 +73,6 @@ type key = Port.t let get_key t = t.local -module Map = Port.Map - type context = string let to_string t = Printf.sprintf "%s:%s" (Port.to_string t.local) (Port.to_string t.remote_port) diff --git a/src/hostnet/host_lwt_unix.ml b/src/hostnet/host_lwt_unix.ml index 5941f229b..89126f530 100644 --- a/src/hostnet/host_lwt_unix.ml +++ b/src/hostnet/host_lwt_unix.ml @@ -37,7 +37,7 @@ exception Too_many_connections let connection_table = Hashtbl.create 511 let connections () = let xs = Hashtbl.fold (fun _ c acc -> c :: acc) connection_table [] in - Vfs.File.ro_of_string @@ String.concat "\n" xs + Vfs.File.ro_of_string (String.concat "\n" xs) let register_connection_no_limit description = let idx = next_connection_idx () in Hashtbl.replace connection_table idx description; @@ -87,7 +87,8 @@ let unix_bind_one ?(description="") pf ty ip port = Lwt.catch (fun () -> Lwt_unix.setsockopt fd Lwt_unix.SO_REUSEADDR true; - Lwt_unix.bind fd addr; + Lwt_unix.Versioned.bind_2 fd addr + >>= fun () -> Lwt.return (idx, fd) ) (fun e -> Lwt_unix.close fd @@ -168,7 +169,8 @@ module Datagram = struct | Ipaddr.V6 _ -> Lwt_unix.PF_INET6, Unix.inet6_addr_any in let fd = Lwt_unix.socket pf Lwt_unix.SOCK_DGRAM 0 in (* Win32 requires all sockets to be bound however macOS and Linux don't *) - (try Lwt_unix.bind fd (Lwt_unix.ADDR_INET(addr, 0)) with _ -> ()); + Lwt.catch (fun () -> Lwt_unix.Versioned.bind_2 fd (Lwt_unix.ADDR_INET(addr, 0))) (fun _ -> Lwt.return_unit) + >>= fun () -> let sockaddr = sockaddr_of_address address in Lwt.return (Result.Ok (of_fd ~idx ~description ?read_buffer_size sockaddr address fd)) @@ -629,7 +631,8 @@ module Stream = struct let s = Lwt_unix.socket Lwt_unix.PF_UNIX Lwt_unix.SOCK_STREAM 0 in Lwt.catch (fun () -> - Lwt_unix.bind s (Lwt_unix.ADDR_UNIX path); + Lwt_unix.Versioned.bind_2 s (Lwt_unix.ADDR_UNIX path) + >>= fun () -> Lwt.return (make ~path [ idx, s ]) ) (fun e -> Lwt_unix.close s diff --git a/src/hostnet/host_uwt.ml b/src/hostnet/host_uwt.ml index b31b1838a..6937baf0a 100644 --- a/src/hostnet/host_uwt.ml +++ b/src/hostnet/host_uwt.ml @@ -71,7 +71,7 @@ module Sockets = struct let connection_table = Hashtbl.create 511 let connections () = let xs = Hashtbl.fold (fun _ c acc -> c :: acc) connection_table [] in - Vfs.File.ro_of_string @@ String.concat "\n" xs + Vfs.File.ro_of_string (String.concat "\n" xs) let register_connection_no_limit description = let idx = next_connection_idx () in Hashtbl.replace connection_table idx description; diff --git a/src/hostnet/hostnet_dns.ml b/src/hostnet/hostnet_dns.ml index daed52b9c..8dc86a7d2 100644 --- a/src/hostnet/hostnet_dns.ml +++ b/src/hostnet/hostnet_dns.ml @@ -31,7 +31,7 @@ module Policy(Files: Sig.FILES) = struct let config_of_ips ips = let open Dns_forward.Config in let servers = Server.Set.of_list ( - List.map (fun (ip, port) -> + List.map (fun (ip, _) -> { Server.address = { Address.ip; port = 53 }; zones = Domain.Set.empty; timeout_ms = Some 2000; order = 0 } ) ips) in @@ -162,11 +162,11 @@ module Make(Ip: V1_LWT.IPV4) (Udp:V1_LWT.UDPV4) (Tcp:V1_LWT.TCPV4) (Socket: Sig. let set_recorder r = recorder := Some r let destroy = function - | { resolver = Upstream { dns_tcp_resolver; dns_udp_resolver } } -> + | { resolver = Upstream { dns_tcp_resolver; dns_udp_resolver; _ }; _ } -> Dns_tcp_resolver.destroy dns_tcp_resolver >>= fun () -> Dns_udp_resolver.destroy dns_udp_resolver - | { resolver = Host } -> + | { resolver = Host; _ } -> Lwt.return_unit let record_udp ~source_ip ~source_port ~dest_ip ~dest_port bufs = @@ -212,12 +212,6 @@ module Make(Ip: V1_LWT.IPV4) (Udp:V1_LWT.UDPV4) (Tcp:V1_LWT.TCPV4) (Socket: Sig. | None -> () (* nowhere to log packet *) - let try_host_resolver question = - D.resolve question - >>= function - | [] -> Lwt.return None - | x -> Lwt.return (Some x) - let create ~local_address ~host_names = let local_ip = local_address.Dns_forward.Config.Address.ip in Log.info (fun f -> f "DNS names %s will map to local IP %s" (String.concat ", " @@ List.map Dns.Name.to_string host_names) (Ipaddr.to_string local_ip)); @@ -247,6 +241,7 @@ module Make(Ip: V1_LWT.IPV4) (Udp:V1_LWT.UDPV4) (Tcp:V1_LWT.TCPV4) (Socket: Sig. Lwt.return { local_ip; host_names; resolver = Host } let answer t is_tcp buffer = + let open Dns.Packet in let len = Cstruct.len buffer in let buf = Dns.Buf.of_cstruct buffer in match Dns.Protocol.Server.parse (Dns.Buf.sub buf 0 len) with @@ -303,7 +298,7 @@ module Make(Ip: V1_LWT.IPV4) (Udp:V1_LWT.UDPV4) (Tcp:V1_LWT.TCPV4) (Socket: Sig. | None -> Printf.sprintf "Unparsable DNS packet length %d" len | Some request -> Dns.Packet.to_string request - let handle_udp ~t ~udp ~src ~dst ~src_port buf = + let handle_udp ~t ~udp ~src ~dst:_ ~src_port buf = answer t false buf >>= function | Result.Error (`Msg m) -> @@ -314,7 +309,7 @@ module Make(Ip: V1_LWT.IPV4) (Udp:V1_LWT.UDPV4) (Tcp:V1_LWT.TCPV4) (Socket: Sig. let handle_tcp ~t = (* FIXME: need to record the upstream request *) - let listeners port = + let listeners _ = Log.debug (fun f -> f "DNS TCP handshake complete"); Some (fun flow -> let packets = Dns_tcp_framing.connect flow in diff --git a/src/hostnet/hosts.ml b/src/hostnet/hosts.ml index fb681c930..7425a90ee 100644 --- a/src/hostnet/hosts.ml +++ b/src/hostnet/hosts.ml @@ -24,7 +24,7 @@ let of_string txt = if line = "" then acc else begin let line = match String.cut ~sep:"#" line with | None -> line - | Some (important, comment) -> important in + | Some (important, _) -> important in let whitespace = function | ' ' | '\n' | '\011' | '\012' | '\r' | '\t' -> true | _ -> false in diff --git a/src/hostnet/jbuild b/src/hostnet/jbuild index 583d0391d..448e93190 100644 --- a/src/hostnet/jbuild +++ b/src/hostnet/jbuild @@ -11,4 +11,5 @@ )) (c_names (stubs_utils)) (wrapped false) + (flags (:standard -warn-error "+1..49-3" -w "A-4-41-42-44")) )) diff --git a/src/hostnet/mux.ml b/src/hostnet/mux.ml index 4b71594eb..678ebc341 100644 --- a/src/hostnet/mux.ml +++ b/src/hostnet/mux.ml @@ -67,7 +67,7 @@ module Make(Netif: V1_LWT.NETWORK) = struct (fun ip t acc -> Printf.sprintf "%s last_active_time = %.1f" (Ipaddr.V4.to_string ip) t.last_active_time :: acc ) t.rules [] in - Vfs.File.ro_of_string @@ String.concat "\n" xs + Vfs.File.ro_of_string (String.concat "\n" xs) let remove t rule = Log.debug (fun f -> f "removing switch port for %s" (Ipaddr.V4.to_string rule)); @@ -77,7 +77,7 @@ module Make(Netif: V1_LWT.NETWORK) = struct (* Does the packet match any of our rules? *) let open Frame in match parse [ buf ] with - | Ok (Ethernet { payload = Ipv4 { dst } }) -> + | Ok (Ethernet { payload = Ipv4 { dst; _ }; _ }) -> if RuleMap.mem dst t.rules then begin let port = RuleMap.find dst t.rules in port.last_active_time <- Unix.gettimeofday (); diff --git a/src/hostnet/slirp.ml b/src/hostnet/slirp.ml index 6eb61dafc..eb6ea3194 100644 --- a/src/hostnet/slirp.ml +++ b/src/hostnet/slirp.ml @@ -196,7 +196,7 @@ module Make(Config: Active_config.S)(Vmnet: Sig.VMNET)(Dns_policy: Sig.DNS_POLIC let filesystem () = let flows = Id.Map.fold (fun _ t acc -> to_string t :: acc) !all [] in - Vfs.File.ro_of_string @@ String.concat "\n" flows + Vfs.File.ro_of_string (String.concat "\n" flows) let create id socket = let socket = Some socket in @@ -526,7 +526,7 @@ module Make(Config: Active_config.S)(Vmnet: Sig.VMNET)(Dns_policy: Sig.DNS_POLIC (fun ip t acc -> Printf.sprintf "%s last_active_time = %.1f" (Ipaddr.V4.to_string ip) t.Endpoint.last_active_time :: acc ) t.endpoints [] in - Vfs.File.ro_of_string @@ String.concat "\n" xs in + Vfs.File.ro_of_string (String.concat "\n" xs) in Vfs.Dir.of_list (fun () -> Vfs.ok [ @@ -669,7 +669,7 @@ module Make(Config: Active_config.S)(Vmnet: Sig.VMNET)(Dns_policy: Sig.DNS_POLIC None (* just set smallest available prefix *) end in - let dhcp = Dhcp.make ~client_macaddr ~server_macaddr ~peer_ip ~highest_peer_ip ~local_ip + let dhcp = Dhcp.make ~server_macaddr ~peer_ip ~highest_peer_ip ~local_ip ~extra_dns_ip ~get_domain_search ~get_domain_name switch in let endpoints = IPMap.empty in @@ -741,7 +741,7 @@ module Make(Config: Active_config.S)(Vmnet: Sig.VMNET)(Dns_policy: Sig.DNS_POLIC (fun buf -> let open Frame in match parse [ buf ] with - | Ok (Ethernet { src = eth_src ; dst = eth_dst ; payload }) when + | Ok (Ethernet { src = eth_src ; dst = eth_dst ; _ }) when (not (Macaddr.compare eth_dst client_macaddr = 0 || Macaddr.compare eth_dst server_macaddr = 0 || Macaddr.compare eth_dst Macaddr.broadcast = 0)) -> (* not to server, client or broadcast.. *) @@ -1048,7 +1048,7 @@ module Make(Config: Active_config.S)(Vmnet: Sig.VMNET)(Dns_policy: Sig.DNS_POLIC let client_macaddr = (Vnet.mac l2_switch l2_client_id) in let used_ips = - Hashtbl.fold (fun k v l -> + Hashtbl.fold (fun _ v l -> let ip, _ = v in l @ [ip]) t.client_uuids.table [] in @@ -1072,7 +1072,7 @@ module Make(Config: Active_config.S)(Vmnet: Sig.VMNET)(Dns_policy: Sig.DNS_POLIC if not (List.mem preferred_ip used_ips) then begin Some preferred_ip end else begin - failwith "Preferred IP address %s not available" (Ipaddr.V4.to_string preferred_ip) + failwith (Printf.sprintf "Preferred IP address %s not available" (Ipaddr.V4.to_string preferred_ip)) end end else begin None diff --git a/src/hostnet/vmnet.ml b/src/hostnet/vmnet.ml index 6096da2ab..6e03fac0c 100644 --- a/src/hostnet/vmnet.ml +++ b/src/hostnet/vmnet.ml @@ -1,7 +1,6 @@ module Lwt_result = Hostnet_lwt_result (* remove when new Lwt is released *) open Lwt -open Sexplib.Std let src = let src = Logs.Src.create "vmnet" ~doc:"vmnet" in @@ -10,14 +9,6 @@ let src = module Log = (val Logs.src_log src : Logs.LOG) -let log_exception_continue description f = - Lwt.catch - (fun () -> f ()) - (fun e -> - Log.err (fun f -> f "%s: caught %s" description (Printexc.to_string e)); - Lwt.return () - ) - let ethernet_header_length = 14 (* no VLAN *) module Init = struct @@ -215,10 +206,10 @@ let server_negotiate ~fd ~client_macaddr_of_uuid ~mtu = >>= fun (command, _) -> Log.info (fun f -> f "PPP.negotiate: received %s" (Command.to_string command)); match command with - | Ethernet uuid -> begin + | Command.Ethernet uuid -> begin let open Lwt.Infix in client_macaddr_of_uuid uuid - >>= fun client_macaddr -> + >>= fun client_macaddr -> let vif = Vif.create client_macaddr mtu () in let buf = Cstruct.create Vif.sizeof in let (_: Cstruct.t) = Vif.marshal vif buf in @@ -229,7 +220,7 @@ let server_negotiate ~fd ~client_macaddr_of_uuid ~mtu = >>= fun () -> Lwt_result.return (uuid, client_macaddr) end - | Bind_ipv4 _ -> (raise (Failure "PPP.negotiate: unsupported command Bind_ipv4")) + | Command.Bind_ipv4 _ -> (raise (Failure "PPP.negotiate: unsupported command Bind_ipv4")) ) let client_negotiate ~uuid ~fd = @@ -341,9 +332,9 @@ let of_fd ~client_macaddr_of_uuid ~server_macaddr ~mtu flow = let client_of_fd ~uuid ~server_macaddr flow = let open Lwt_result.Infix in let channel = Channel.create flow in - client_negotiate ~uuid ~fd:channel + client_negotiate ~uuid ~fd:channel >>= fun vif -> - let t = make vif.client_macaddr server_macaddr vif.mtu uuid channel in + let t = make ~client_macaddr:vif.Vif.client_macaddr ~server_macaddr:server_macaddr ~mtu:vif.Vif.mtu ~client_uuid:uuid channel in Lwt_result.return t let disconnect t = match t.fd with @@ -540,5 +531,4 @@ let reset_stats_counters t = t.stats.rx_pkts <- 0l; t.stats.tx_pkts <- 0l -let get_id _ = () end diff --git a/src/hostnet_test/forwarding.ml b/src/hostnet_test/forwarding.ml index e84bdeaee..93ac20196 100644 --- a/src/hostnet_test/forwarding.ml +++ b/src/hostnet_test/forwarding.ml @@ -67,8 +67,6 @@ module ForwardServer = struct end module Forward = Forward.Make(struct - type port = Forward.Port.t - include Host.Sockets.Stream.Tcp open Lwt.Infix @@ -226,7 +224,7 @@ module ForwardControl = struct Lwt.return { t; fid; ip; port } | _ -> failwith ("failed to parse response: " ^ line) end else failwith response - let destroy { t; fid } = + let destroy { t; fid; _ } = Client.LowLevel.clunk t.ninep fid >>*= fun _clunk -> Lwt.return () diff --git a/src/hostnet_test/jbuild b/src/hostnet_test/jbuild index ec5f5813e..201d5b7b2 100644 --- a/src/hostnet_test/jbuild +++ b/src/hostnet_test/jbuild @@ -5,4 +5,5 @@ dns.mirage lwt.preemptive uwt.preemptive )) (preprocess no_preprocessing) + (flags (:standard -warn-error "+1..49-3" -w "A-4-41-42-44")) )) diff --git a/src/hostnet_test/main_lwt.ml b/src/hostnet_test/main_lwt.ml index 33863f622..04a4d52ad 100644 --- a/src/hostnet_test/main_lwt.ml +++ b/src/hostnet_test/main_lwt.ml @@ -1,5 +1,3 @@ -open Lwt.Infix - let src = let src = Logs.Src.create "test" ~doc:"Test the slirp stack" in Logs.Src.set_level src (Some Logs.Debug); diff --git a/src/hostnet_test/main_uwt.ml b/src/hostnet_test/main_uwt.ml index df86f9b99..0c240a649 100644 --- a/src/hostnet_test/main_uwt.ml +++ b/src/hostnet_test/main_uwt.ml @@ -1,5 +1,3 @@ -open Lwt.Infix - let src = let src = Logs.Src.create "test" ~doc:"Test the slirp stack" in Logs.Src.set_level src (Some Logs.Debug); diff --git a/src/hostnet_test/slirp_stack.ml b/src/hostnet_test/slirp_stack.ml index 3e2a52a87..fab638b06 100644 --- a/src/hostnet_test/slirp_stack.ml +++ b/src/hostnet_test/slirp_stack.ml @@ -11,7 +11,7 @@ module Dns_policy = struct let config_of_ips ips = let open Dns_forward.Config in let servers = Server.Set.of_list ( - List.map (fun (ip, port) -> + List.map (fun (ip, _) -> { Server.address = { Address.ip; port = 53 }; zones = Domain.Set.empty; timeout_ms = Some 2000; order = 0; @@ -113,18 +113,17 @@ let peer_ip = Ipaddr.V4.of_string_exn "192.168.65.2" let local_ip = Ipaddr.V4.of_string_exn "192.168.65.1" let server_macaddr = Slirp.default_server_macaddr -let global_arp_table : Slirp.arp_table = - { mutex = Lwt_mutex.create (); - table = [(local_ip, Slirp.default_server_macaddr)] +let global_arp_table : Slirp.arp_table = + { Slirp.mutex = Lwt_mutex.create (); + table = [(local_ip, Slirp.default_server_macaddr)] } -let client_uuids : Slirp.uuid_table = - { mutex = Lwt_mutex.create (); +let client_uuids : Slirp.uuid_table = + { Slirp.mutex = Lwt_mutex.create (); table = Hashtbl.create 50; } let config_without_bridge = - let never, _ = Lwt.task () in { Slirp.peer_ip; local_ip; @@ -182,7 +181,6 @@ let with_stack f = | Result.Ok flow -> Log.info (fun f -> f "Made a loopback connection"); let client_macaddr = Slirp.default_client_macaddr in - let server_macaddr = Slirp.default_server_macaddr in let uuid = (match Uuidm.of_string "d1d9cd61-d0dc-4715-9bb3-4c11da7ad7a5" with | Some x -> x | None -> failwith "unable to parse test uuid") in diff --git a/src/hostnet_test/suite.ml b/src/hostnet_test/suite.ml index 700f92d00..5fdd2120f 100644 --- a/src/hostnet_test/suite.ml +++ b/src/hostnet_test/suite.ml @@ -77,11 +77,11 @@ let test_localhost_local_query server use_host () = (fun _ stack -> let resolver = DNS.create stack in Lwt_list.iter_s - (fun name -> + (fun _ -> let request = DNS.gethostbyname ~server resolver "localhost.local" >>= function - | (_ :: _) as ips -> + | _ :: _ -> Log.err (fun f -> f "successfully resolved localhost.local: this shouldn't happen"); failwith "Successfully resolved localhost.local" | _ -> @@ -139,7 +139,7 @@ let test_max_connections () = Host.Sockets.set_max_connections (Some 0); begin Client.TCPV4.create_connection (Client.tcpv4 stack) (ip, 80) >>= function - | `Ok flow -> + | `Ok _ -> Log.err (fun f -> f "Connected to www.google.com, max_connections exceeded"); failwith "too many connections" | `Error _ -> @@ -264,7 +264,7 @@ let rec count = function 0 -> [] | n -> () :: (count (n - 1)) let test_stream_data connections length () = let t = DevNullServer.with_server - (fun { DevNullServer.local_port } -> + (fun { DevNullServer.local_port; _ } -> with_stack (fun _ stack -> Lwt_list.iter_p diff --git a/src/hostnet_test/test_nat.ml b/src/hostnet_test/test_nat.ml index 1ac8df475..0922d3040 100644 --- a/src/hostnet_test/test_nat.ml +++ b/src/hostnet_test/test_nat.ml @@ -80,7 +80,7 @@ module Make(Host: Sig.HOST) = struct let seen_source_ports = PortSet.empty in let t = { port; highest; seen_source_ports; c } in Client.listen_udpv4 stack ~port - (fun ~src ~dst ~src_port buffer -> + (fun ~src:_ ~dst:_ ~src_port buffer -> t.highest <- max t.highest (Cstruct.get_uint8 buffer 0); t.seen_source_ports <- PortSet.add src_port t.seen_source_ports; Log.debug (fun f -> f "Received UDP %d -> %d highest %d" src_port port t.highest); @@ -88,13 +88,13 @@ module Make(Host: Sig.HOST) = struct Lwt.return_unit ); t - let rec wait_for_data ~timeout ~highest t = + let wait_for_data ~highest t = if t.highest < highest then begin Lwt.pick [ Lwt_condition.wait t.c; Host.Time.sleep 1. ] >>= fun () -> Lwt.return (t.highest >= highest) end else Lwt.return true - let rec wait_for_ports ~timeout ~num t = + let wait_for_ports ~num t = if PortSet.cardinal t.seen_source_ports < num then begin Lwt.pick [ Lwt_condition.wait t.c; Host.Time.sleep 1. ] >>= fun () -> @@ -106,7 +106,7 @@ module Make(Host: Sig.HOST) = struct let test_udp () = let t = EchoServer.with_server - (fun { EchoServer.local_port } -> + (fun { EchoServer.local_port; _ } -> with_stack (fun _ stack -> let buffer = Cstruct.create 1024 in @@ -121,7 +121,7 @@ module Make(Host: Sig.HOST) = struct Log.debug (fun f -> f "Sending %d -> %d value %d" virtual_port local_port (Cstruct.get_uint8 buffer 0)); Client.UDPV4.write ~source_port:virtual_port ~dest_ip:Ipaddr.V4.localhost ~dest_port:local_port udpv4 buffer >>= fun () -> - UdpServer.wait_for_data ~timeout:1. ~highest:1 server + UdpServer.wait_for_data ~highest:1 server >>= function | true -> Lwt.return_unit | false -> loop (remaining - 1) in @@ -136,7 +136,7 @@ module Make(Host: Sig.HOST) = struct let test_udp_2 () = let t = EchoServer.with_server - (fun { EchoServer.local_port } -> + (fun { EchoServer.local_port; _ } -> with_stack (fun _ stack -> let buffer = Cstruct.create 1024 in @@ -153,7 +153,7 @@ module Make(Host: Sig.HOST) = struct Log.debug (fun f -> f "Sending %d -> %d value %d" virtual_port1 local_port (Cstruct.get_uint8 buffer 0)); Client.UDPV4.write ~source_port:virtual_port1 ~dest_ip:Ipaddr.V4.localhost ~dest_port:local_port udpv4 buffer >>= fun () -> - UdpServer.wait_for_data ~timeout:1. ~highest:1 server1 + UdpServer.wait_for_data ~highest:1 server1 >>= function | true -> Lwt.return_unit | false -> loop (remaining - 1) in @@ -169,10 +169,10 @@ module Make(Host: Sig.HOST) = struct Log.debug (fun f -> f "Sending %d -> %d value %d" virtual_port2 local_port (Cstruct.get_uint8 buffer 0)); Client.UDPV4.write ~source_port:virtual_port2 ~dest_ip:Ipaddr.V4.localhost ~dest_port:local_port udpv4 buffer >>= fun () -> - UdpServer.wait_for_data ~timeout:1. ~highest:2 server2 + UdpServer.wait_for_data ~highest:2 server2 >>= fun ok2 -> (* The server should "multicast" the packet to the original "connection" *) - UdpServer.wait_for_data ~timeout:1. ~highest:2 server1 + UdpServer.wait_for_data ~highest:2 server1 >>= fun ok1 -> if ok1 && ok2 then Lwt.return_unit else loop (remaining - 1) in loop 5 @@ -204,7 +204,7 @@ module Make(Host: Sig.HOST) = struct Log.debug (fun f -> f "Sending %d -> %d value %d" virtual_port1 dest_port (Cstruct.get_uint8 buffer 0)); Client.UDPV4.write ~source_port:virtual_port1 ~dest_ip:Ipaddr.V4.localhost ~dest_port udpv4 buffer >>= fun () -> - UdpServer.wait_for_data ~timeout:1. ~highest:1 server1 + UdpServer.wait_for_data ~highest:1 server1 >>= function | true -> Lwt.return_unit | false -> loop (remaining - 1) in @@ -225,7 +225,7 @@ module Make(Host: Sig.HOST) = struct Log.debug (fun f -> f "Sending %d -> %d value %d" source_port dest_port (Cstruct.get_uint8 buffer 0)); Host.Sockets.Datagram.Udp.sendto client address buffer >>= fun () -> - UdpServer.wait_for_data ~timeout:1. ~highest:2 server1 + UdpServer.wait_for_data ~highest:2 server1 >>= function | true -> Lwt.return_unit | false -> loop (remaining - 1) in @@ -240,7 +240,7 @@ module Make(Host: Sig.HOST) = struct let test_shared_nat_rule () = let t = EchoServer.with_server - (fun { EchoServer.local_port } -> + (fun { EchoServer.local_port; _ } -> with_stack (fun slirp_server stack -> let buffer = Cstruct.create 1024 in @@ -256,7 +256,7 @@ module Make(Host: Sig.HOST) = struct Log.debug (fun f -> f "Sending %d -> %d value %d" virtual_port local_port (Cstruct.get_uint8 buffer 0)); Client.UDPV4.write ~source_port:virtual_port ~dest_ip:Ipaddr.V4.localhost ~dest_port:local_port udpv4 buffer >>= fun () -> - UdpServer.wait_for_data ~timeout:1. ~highest:1 server + UdpServer.wait_for_data ~highest:1 server >>= function | true -> Lwt.return_unit | false -> loop (remaining - 1) in @@ -268,13 +268,13 @@ module Make(Host: Sig.HOST) = struct (* Create another physical server and send traffic from the same virtual address *) EchoServer.with_server - (fun { EchoServer.local_port } -> + (fun { EchoServer.local_port; _ } -> let rec loop remaining = if remaining = 0 then failwith "Timed-out before UDP response arrived"; Log.debug (fun f -> f "Sending %d -> %d value %d" virtual_port local_port (Cstruct.get_uint8 buffer 0)); Client.UDPV4.write ~source_port:virtual_port ~dest_ip:Ipaddr.V4.localhost ~dest_port:local_port udpv4 buffer >>= fun () -> - UdpServer.wait_for_data ~timeout:1. ~highest:2 server + UdpServer.wait_for_data ~highest:2 server >>= function | true -> Lwt.return_unit | false -> loop (remaining - 1) in @@ -292,9 +292,9 @@ module Make(Host: Sig.HOST) = struct let test_source_ports () = let t = EchoServer.with_server - (fun { EchoServer.local_port = local_port1 } -> + (fun { EchoServer.local_port = local_port1; _ } -> EchoServer.with_server - (fun { EchoServer.local_port = local_port2 } -> + (fun { EchoServer.local_port = local_port2; _ } -> with_stack (fun _ stack -> let buffer = Cstruct.create 1024 in @@ -311,7 +311,7 @@ module Make(Host: Sig.HOST) = struct Log.debug (fun f -> f "Sending %d -> %d value %d" virtual_port local_port2 (Cstruct.get_uint8 buffer 0)); Client.UDPV4.write ~source_port:virtual_port ~dest_ip:Ipaddr.V4.localhost ~dest_port:local_port2 udpv4 buffer >>= fun () -> - UdpServer.wait_for_ports ~timeout:1. ~num:2 server + UdpServer.wait_for_ports ~num:2 server >>= function | true -> Lwt.return_unit | false -> loop (remaining - 1) in diff --git a/src/ofs/active_list.ml b/src/ofs/active_list.ml index 699d76e00..d44920b4f 100644 --- a/src/ofs/active_list.ml +++ b/src/ofs/active_list.ml @@ -151,6 +151,8 @@ The directory will be deleted and replaced with a file of the same name. connection.fids := Types.Fid.Map.add fid Root !(connection.fids); return { Response.Attach.qid = root_qid } + exception Enoent + let walk connection ~cancel:_ { Request.Walk.fid; newfid; wnames } = try let from = Types.Fid.Map.find fid !(connection.fids) in @@ -168,19 +170,18 @@ The directory will be deleted and replaced with a file of the same name. | Some _ -> [] ) in (Entry entry, qid), qid :: qids - end else failwith "ENOENT" + end else raise Enoent | "ctl", Entry entry -> let qid = next_qid [] in (ControlFile entry, qid), qid :: qids - | _, _ -> failwith "ENOENT" + | _, _ -> raise Enoent ) ((from, next_qid []), []) wnames in connection.fids := Types.Fid.Map.add newfid (fst from) !(connection.fids); let wqids = List.rev wqids in return { Response.Walk.wqids } with | Not_found -> Error.badfid - | Failure "ENOENT" -> Error.enoent - | Failure "BADWALK" -> Error.badwalk + | Enoent -> Error.enoent let free_resource = function | ControlFile entry -> diff --git a/src/ofs/jbuild b/src/ofs/jbuild index eec317b76..70f955203 100644 --- a/src/ofs/jbuild +++ b/src/ofs/jbuild @@ -6,5 +6,6 @@ mirage-types.lwt astring named-pipe.lwt )) (wrapped false) + (flags (:standard -warn-error "+1..49-3" -w "A-4-41-42-44")) ))