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

remove dependency on cstruct, use string and bytes instead #279

Merged
merged 17 commits into from
Sep 27, 2024
Merged

Conversation

hannesm
Copy link
Contributor

@hannesm hannesm commented Sep 24, 2024

re done of #223. compiles and test run fine. I'm sure there are potential optimizations, and we should take a look into what we did in #223 (which I tried and failed to rebase).

@hannesm
Copy link
Contributor Author

hannesm commented Sep 25, 2024

The CI failures for the unikernels are due to the fact that our cirrus jobs use the miragevpn#main opam file for discovering dependencies.

@hannesm
Copy link
Contributor Author

hannesm commented Sep 25, 2024

NOTE: we could improve with / review / reapply:

but I suggest to first get this PR reviewed and merged before we apply the enhancements.

mirage-router: avoid deprecated function get_ip
app/common.ml Outdated Show resolved Hide resolved
app/miragevpn_client_lwt.ml Outdated Show resolved Hide resolved
@@ -95,9 +92,11 @@ let send_ping ({ ip_config; seq_no; mtu = _; ping = _ } as ifconfig) =
~payload_len:(Cstruct.lenv [ icmpv4_hdr; payload ])
ipv4_hdr
in
(ifconfig, Cstruct.concat [ ipv4_hdr; icmpv4_hdr; payload ])
( ifconfig,
Cstruct.to_string (Cstruct.concat [ ipv4_hdr; icmpv4_hdr; payload ]) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be faster or better to do String.concat "" (List.map Cstruct.to_string [ ... ])
This may very well be premature optimization in unimportant code.

src/config.ml Outdated Show resolved Hide resolved
Comment on lines +572 to +573
| `SHA512 -> "SHA512"
| _ -> assert false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit annoying, but I didn't find a nicer way.

src/engine.ml Outdated Show resolved Hide resolved
src/engine.ml Outdated Show resolved Hide resolved
@@ -1248,7 +1269,7 @@ let outgoing s data =

let ping =
(* constant ping_string in OpenVPN: src/openvpn/ping.c *)
Cstruct.of_hex "2a 18 7b f3 64 1e b4 cb 07 ed 2d 0a 98 1f c7 48"
Ohex.decode "2a 18 7b f3 64 1e b4 cb 07 ed 2d 0a 98 1f c7 48"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make this a string literal now, but I like this.

let out = Cstruct.append out wkc in
Packet.set_protocol out session.protocol;
let out = out ^ wkc in
Packet.set_protocol (Bytes.unsafe_of_string out) session.protocol;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not ideal, but ok

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The let out = out ^ wkc in line above allocates a new string so it's local to us.

src/tls_crypt.ml Outdated Show resolved Hide resolved
hannesm and others added 11 commits September 27, 2024 13:47
Co-authored-by: Reynir Björnsson <[email protected]>
Co-authored-by: Reynir Björnsson <[email protected]>
Co-authored-by: Reynir Björnsson <[email protected]>
Co-authored-by: Reynir Björnsson <[email protected]>
Co-authored-by: Reynir Björnsson <[email protected]>
Co-authored-by: Reynir Björnsson <[email protected]>
Instead of doing unsafe casts to bytes and then calling Lwt_unix.write.
Copy link

  0.00 %      0/21     src/cc_message.ml
 80.42 %   1483/1844   src/config.ml
 60.59 %    123/203    src/config_ext.ml
 73.21 %   1003/1370   src/engine.ml
100.00 %      0/0      src/miragevpn.ml
 92.91 %    367/395    src/packet.ml
 20.00 %      1/5      src/result.ml
 82.72 %     67/81     src/state.ml
 62.93 %    146/232    src/tls_crypt.ml
 76.85 %   3190/4151   Project coverage

@reynir reynir merged commit 6099a4b into main Sep 27, 2024
2 of 5 checks passed
@reynir reynir deleted the nono-cstruct branch September 27, 2024 13:30
@reynir
Copy link
Contributor

reynir commented Sep 27, 2024

Hm, CI failed due to the unikernels pinning the main branch :/

@reynir
Copy link
Contributor

reynir commented Sep 27, 2024

Here are some numbers of iperf3 over openvpn with the server running in a local VM.

Before this branch was merged
reynir@solsort:~$ iperf3 -i 0 -c 10.8.1.1 -R
Connecting to host 10.8.1.1, port 5201
Reverse mode, remote host 10.8.1.1 is sending
[  5] local 10.8.1.2 port 55650 connected to 10.8.1.1 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-10.00  sec  1.09 GBytes   937 Mbits/sec                  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-10.00  sec  1.09 GBytes   938 Mbits/sec  7574             sender
[  5]   0.00-10.00  sec  1.09 GBytes   937 Mbits/sec                  receiver

iperf Done.
reynir@solsort:~$ iperf3 -i 0 -c 10.8.1.1
Connecting to host 10.8.1.1, port 5201
[  5] local 10.8.1.2 port 57320 connected to 10.8.1.1 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-10.00  sec   852 MBytes   715 Mbits/sec  385    223 KBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-10.00  sec   852 MBytes   715 Mbits/sec  385             sender
[  5]   0.00-10.00  sec   850 MBytes   713 Mbits/sec                  receiver

iperf Done.
With this branch merged
reynir@solsort:~$ iperf3 -i 0 -c 10.8.1.1 -R
Connecting to host 10.8.1.1, port 5201
Reverse mode, remote host 10.8.1.1 is sending
[  5] local 10.8.1.3 port 38948 connected to 10.8.1.1 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-10.00  sec  1.09 GBytes   935 Mbits/sec                  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-10.00  sec  1.09 GBytes   935 Mbits/sec  7084             sender
[  5]   0.00-10.00  sec  1.09 GBytes   935 Mbits/sec                  receiver

iperf Done.
reynir@solsort:~$ iperf3 -i 0 -c 10.8.1.1
Connecting to host 10.8.1.1, port 5201
[  5] local 10.8.1.3 port 53262 connected to 10.8.1.1 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-10.00  sec   987 MBytes   828 Mbits/sec  1375    685 KBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-10.00  sec   987 MBytes   828 Mbits/sec  1375             sender
[  5]   0.00-10.01  sec   985 MBytes   826 Mbits/sec                  receiver

iperf Done.

Download speed is roughly the same while upload speed is 15% faster and now closer to the download speed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants