Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some semantics-preserving changes #381

Merged
merged 2 commits into from
Dec 6, 2018
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 src/arpv4/arpv4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module Make (Ethif : Mirage_protocols_lwt.ETHIF)
}

let report_ethif_error s e =
Logs.debug (fun f ->
Log.err (fun f ->
f "error on underlying ethernet interface when attempting to %s : %a"
s Ethif.pp_error e)

Expand Down Expand Up @@ -159,7 +159,7 @@ module Make (Ethif : Mirage_protocols_lwt.ETHIF)
let spa = match t.bound_ips with
| hd::_ -> hd | [] -> Ipaddr.V4.any in
let arp = Arpv4_packet.({ op=Arpv4_wire.Request; tha; sha; tpa; spa }) in
Logs.debug (fun f -> f "ARP: transmitting probe: %a" Arpv4_packet.pp arp);
Log.debug (fun f -> f "ARP: transmitting probe: %a" Arpv4_packet.pp arp);
output t ~source:sha ~destination:tha arp

let get_ips t = t.bound_ips
Expand Down
6 changes: 3 additions & 3 deletions src/ipv4/fragments.ml
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ let process cache ts (packet : Ipv4_packet.t) payload =
Ipv4_packet.pp packet
Fmt.(list ~sep:(unit "; ") (pair ~sep:(unit ", ") int int))
(List.map (fun (s, d) -> (s, Cstruct.len d)) all_frags)) ;
Logs.debug (fun m -> m "full fragments: %a"
Fmt.(list ~sep:(unit "@.") Cstruct.hexdump_pp)
(List.map snd all_frags)) ;
Log.debug (fun m -> m "full fragments: %a"
Fmt.(list ~sep:(unit "@.") Cstruct.hexdump_pp)
(List.map snd all_frags)) ;

Cache.remove key cache', None
| Error Hole -> maybe_add_to_cache cache', None
Expand Down
2 changes: 1 addition & 1 deletion src/stack-direct/tcpip_stack_direct.ml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module Make
with Not_found -> None

let listen t =
Logs.debug (fun f -> f "Establishing or updating listener for stack %a" pp t);
Log.debug (fun f -> f "Establishing or updating listener for stack %a" pp t);
let ethif_listener = Ethif.input
~arpv4:(Arpv4.input t.arpv4)
~ipv4:(
Expand Down
3 changes: 1 addition & 2 deletions src/stack-unix/icmpv4_socket.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ let input t ~src ~dst:_ buf =
(* some default logic -- respond to echo requests with echo replies *)
match Icmpv4_packet.Unmarshal.of_cstruct buf with
| Error s ->
let s = "Error decomposing an ICMP packet: " ^ s in
Logs.debug (fun f -> f "%s" s);
Log.debug (fun f -> f "Error decomposing an ICMP packet: %s" s);
Lwt.return_unit
| Ok (icmp, payload) ->
let open Icmpv4_packet in
Expand Down
6 changes: 1 addition & 5 deletions src/stack-unix/tcpip_stack_socket.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ type ipv4 = Ipaddr.V4.t option
type t = {
udpv4 : Udpv4.t;
tcpv4 : Tcpv4.t;
udpv4_listeners: (int, Udpv4.callback) Hashtbl.t;
tcpv4_listeners: (int, (Tcpv4.flow -> unit Lwt.t)) Hashtbl.t;
}

let udpv4 { udpv4; _ } = udpv4
Expand Down Expand Up @@ -132,9 +130,7 @@ let listen _t =

let connect ips udpv4 tcpv4 =
Log.info (fun f -> f "Manager: connect");
let udpv4_listeners = Hashtbl.create 7 in
let tcpv4_listeners = Hashtbl.create 7 in
let t = { tcpv4; udpv4; udpv4_listeners; tcpv4_listeners } in
let t = { tcpv4; udpv4 } in
Log.info (fun f -> f "Manager: configuring");
configure t ips >|= fun () ->
t
Expand Down
16 changes: 8 additions & 8 deletions src/tcp/flow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct
(Hashtbl.length t.listens)
(Hashtbl.length t.connects)

let log_with_stats level name t = Log.msg level (fun fmt -> fmt "%s: %a" name pp_stats t)
let log_with_stats name t = Log.debug (fun fmt -> fmt "%s: %a" name pp_stats t)

let wscale_default = 2

Expand Down Expand Up @@ -240,7 +240,7 @@ struct
try Some (Hashtbl.find h k) with Not_found -> None

let clearpcb t id tx_isn =
Logs.(log_with_stats Debug "removing pcb from connection tables" t);
log_with_stats "removing pcb from connection tables" t;
match hashtbl_find t.channels id with
| Some _ ->
Hashtbl.remove t.channels id;
Expand Down Expand Up @@ -399,7 +399,7 @@ struct
Lwt.return (pcb, th, opts)

let new_server_connection t params id pushf keepalive =
Logs.(log_with_stats Debug "new-server-connection" t);
log_with_stats "new-server-connection" t;
new_pcb t params id keepalive >>= fun (pcb, th, opts) ->
STATE.tick pcb.state State.Passive_open;
STATE.tick pcb.state (State.Send_synack params.tx_isn);
Expand All @@ -418,7 +418,7 @@ struct
Lwt.return (pcb, th)

let new_client_connection t params id ack_number keepalive =
Logs.(log_with_stats Debug "new-client-connection" t);
log_with_stats "new-client-connection" t;
let tx_isn = params.tx_isn in
let params = { params with tx_isn = Sequence.succ tx_isn } in
new_pcb t params id keepalive >>= fun (pcb, th, _) ->
Expand All @@ -436,7 +436,7 @@ struct
(Sequence.compare (Sequence.succ tx_isn) ack_number) = 0

let process_reset t id ~ack ~ack_number =
Logs.(log_with_stats Debug "process-reset" t);
log_with_stats "process-reset" t;
if ack then
match hashtbl_find t.connects id with
| Some (wakener, tx_isn, _) ->
Expand Down Expand Up @@ -464,7 +464,7 @@ struct
Lwt.return_unit

let process_synack t id ~tx_wnd ~ack_number ~sequence ~options ~syn ~fin =
Logs.(log_with_stats Debug "process-synack" t);
log_with_stats "process-synack" t;
match hashtbl_find t.connects id with
| Some (wakener, tx_isn, keepalive) ->
if is_correct_ack ~tx_isn ~ack_number then (
Expand Down Expand Up @@ -492,7 +492,7 @@ struct
>>= fun _ -> Lwt.return_unit (* discard errors; we won't retry *)

let process_syn t id ~listeners ~tx_wnd ~ack_number ~sequence ~options ~syn ~fin =
Logs.(log_with_stats Debug "process-syn" t);
log_with_stats "process-syn" t;
match listeners @@ WIRE.src_port id with
| Some { process; keepalive } ->
let tx_isn = Sequence.of_int32 (Randomconv.int32 Random.generate) in
Expand All @@ -510,7 +510,7 @@ struct

let process_ack t id ~pkt =
let open RXS in
Logs.(log_with_stats Debug "process-ack" t);
log_with_stats "process-ack" t;
match hashtbl_find t.listens id with
| Some (tx_isn, (pushf, newconn)) ->
if Tcp_packet.(is_correct_ack ~tx_isn ~ack_number:pkt.header.ack_number) then begin
Expand Down
8 changes: 4 additions & 4 deletions test/test_arp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ let query_or_die arp ip expected_mac =
| Error `Timeout ->
let pp_ip = Ipaddr.V4.pp_hum in
A.to_repr arp >>= fun repr ->
Logs.warn (fun f -> f "Timeout querying %a. Table contents: %a" pp_ip ip A.pp repr);
Log.warn (fun f -> f "Timeout querying %a. Table contents: %a" pp_ip ip A.pp repr);
fail "ARP query failed when success was mandatory";
| Ok mac ->
Alcotest.(check macaddr) "mismatch for expected query value" expected_mac mac;
Expand All @@ -183,8 +183,8 @@ let set_and_check ~listener ~claimant ip =

let start_arp_listener stack () =
let noop = (fun _ -> Lwt.return_unit) in
Logs.debug (fun f -> f "starting arp listener for %s" (Macaddr.to_string (V.mac stack.netif)));
E.input ~arpv4:(fun frame -> Logs.debug (fun f -> f "frame received for arpv4"); A.input stack.arp frame) ~ipv4:noop ~ipv6:noop stack.ethif
Log.debug (fun f -> f "starting arp listener for %s" (Macaddr.to_string (V.mac stack.netif)));
E.input ~arpv4:(fun frame -> Log.debug (fun f -> f "frame received for arpv4"); A.input stack.arp frame) ~ipv4:noop ~ipv6:noop stack.ethif

let output_then_disconnect ~speak:speak_netif ~disconnect:listen_netif bufs =
Lwt.join (List.map (fun b -> V.write speak_netif b >|= fun _ -> ()) bufs) >>= fun () ->
Expand Down Expand Up @@ -312,7 +312,7 @@ let unreachable_times_out () =
let input_replaces_old () =
three_arp () >>= fun (listen, claimant_1, claimant_2) ->
let listener = start_arp_listener listen () in
Lwt.async ( fun () -> Logs.debug (fun f -> f "arp listener started"); V.listen listen.netif (fun buf -> Logs.debug (fun f -> f "packet received: %a" Cstruct.hexdump_pp buf); listener buf));
Lwt.async ( fun () -> Log.debug (fun f -> f "arp listener started"); V.listen listen.netif (fun buf -> Log.debug (fun f -> f "packet received: %a" Cstruct.hexdump_pp buf); listener buf));
timeout ~time:2000 (
Time.sleep_ns (Duration.of_ms 100) >>= fun () ->
set_and_check ~listener:listen.arp ~claimant:claimant_1 first_ip >>= fun () ->
Expand Down
10 changes: 5 additions & 5 deletions test/test_connect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ module Test_connect (B : Vnetif_backends.Backend) = struct

let accept flow expected =
let ip, port = V.Stackv4.TCPV4.dst flow in
Logs.debug (fun f -> f "Accepted connection from %s:%d" (Ipaddr.V4.to_string ip) port);
Log.debug (fun f -> f "Accepted connection from %s:%d" (Ipaddr.V4.to_string ip) port);
V.Stackv4.TCPV4.read flow >>= function
| Error e -> err_read e
| Ok `Eof -> err_read_eof ()
| Ok (`Data b) ->
Lwt_unix.sleep 0.1 >>= fun () ->
(* sleep first to capture data in pcap *)
Alcotest.(check string) "accept" expected (Cstruct.to_string b);
Logs.debug (fun f -> f "Connection closed");
Log.debug (fun f -> f "Connection closed");
Lwt.return_unit

let test_tcp_connect_two_stacks () =
Expand All @@ -72,12 +72,12 @@ module Test_connect (B : Vnetif_backends.Backend) = struct
V.Stackv4.listen s2;
(let conn = V.Stackv4.TCPV4.create_connection (V.Stackv4.tcpv4 s2) in
or_error "connect" conn (server_ip, 80) >>= fun flow ->
Logs.debug (fun f -> f "Connected to other end...");
Log.debug (fun f -> f "Connected to other end...");
V.Stackv4.TCPV4.write flow (Cstruct.of_string test_string) >>= function
| Error `Closed -> err_write_eof ()
| Error e -> err_write e
| Ok () ->
Logs.debug (fun f -> f "wrote hello world");
Log.debug (fun f -> f "wrote hello world");
V.Stackv4.TCPV4.close flow >>= fun () ->
Lwt_unix.sleep 1.0 >>= fun () -> (* record some traffic after close *)
Lwt.return_unit)]) ] >>= fun () ->
Expand All @@ -98,7 +98,7 @@ let test_tcp_connect_two_stacks_basic () =
let test_tcp_connect_two_stacks_x100_uniform_no_payload_packet_loss () =
let rec loop = function
| 0 -> Lwt.return_unit
| n -> Logs.info (fun f -> f "%d/100" (101-n));
| n -> Log.info (fun f -> f "%d/100" (101-n));
let module Test = Test_connect(Vnetif_backends.Uniform_no_payload_packet_loss) in
Test.record_pcap
(Printf.sprintf
Expand Down