Skip to content

Commit

Permalink
test mode: wait for 3 pings
Browse files Browse the repository at this point in the history
this allows the rekeying / reneg code being tested
  • Loading branch information
hannesm committed Jun 26, 2024
1 parent e292e3c commit 668154c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app/miragevpn_client_notun.ml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ let pong { ip_config; _ } buf =
m "Received ICMPv4 payload %d bytes" (Cstruct.length buf));
(id, seq_no)

let _received_pong = ref 0

let rec established_action test proto fd incoming ifconfig tick client actions =
let action, actions =
match actions with
Expand Down Expand Up @@ -193,7 +195,8 @@ let rec established_action test proto fd incoming ifconfig tick client actions =
(match pong ifconfig data with
| Ok (_id, seq_no) ->
Logs.app (fun m -> m "Received pong icmp_seq=%d" seq_no);
if test then exit 0
incr _received_pong;
if test && !_received_pong > 2 then exit 0
| Error msg -> Logs.app (fun m -> m "Received unexpected data: %s" msg));
established_action test proto fd incoming ifconfig tick client actions
| `Exit -> Lwt_result.fail (`Msg "Exiting due to Miragevpn engine exit")
Expand Down
5 changes: 4 additions & 1 deletion app/miragevpn_server_notun.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ let write t dst cs =
Hashtbl.remove t.connections dst
| Ok () -> ()))

let _received_ping = ref 0

let handle_payload t dst source_ip data =
match Ipv4_packet.Unmarshal.of_cstruct data with
| Error e ->
Expand Down Expand Up @@ -60,6 +62,7 @@ let handle_payload t dst source_ip data =
match Icmpv4_packet.Unmarshal.of_cstruct payload with
| Ok (({ ty = Icmpv4_wire.Echo_request; _ } as icmp), payload) ->
(* XXX(reynir): also check code = 0?! *)
incr _received_ping;
let* () =
let reply = { icmp with Icmpv4_packet.ty = Icmpv4_wire.Echo_reply }
and ip' = { ip with src = ip.dst; dst = ip.src } in
Expand All @@ -74,7 +77,7 @@ let handle_payload t dst source_ip data =
in
write t ip.src (Cstruct.append hdr data)
in
if t.test then (
if t.test && !_received_ping > 2 then (
Logs.app (fun m ->
m "Received echo request from %a" Ipaddr.V4.pp source_ip);
let client_fd, client = Hashtbl.find t.connections source_ip in
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/client-up.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

ping -c1 10.8.0.1 &
ping -c3 10.8.0.1 &
1 change: 1 addition & 0 deletions test/e2e/tls-crypt-v2/client.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ pkcs12 client-nopass.p12
cipher AES-256-CBC
verb 7
tls-crypt-v2 tls-crypt-v2-client-timestamp.key
reneg-bytes 1
1 change: 1 addition & 0 deletions test/e2e/tls-crypt-v2/server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ server 10.8.0.0 255.255.255.0
keepalive 10 30
verb 4
tls-crypt-v2 tls-crypt-v2-server.key allow-noncookie
reneg-sec 1

0 comments on commit 668154c

Please sign in to comment.