From b77716c43a9d08a19a12d0aaddd49c06f2653475 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Tue, 7 May 2024 15:24:27 +0200 Subject: [PATCH 1/8] remove mirage-profile dependency, also result update to recent tcpip (where V4-only stack is no longer available) --- .merlin | 7 ------- mirage-vnetif-stack.opam | 7 +++---- mirage-vnetif.opam | 5 ++--- src/vnetif-stack/dune | 6 +++--- src/vnetif-stack/vnetif_stack.ml | 24 ++++++++++++++---------- src/vnetif/dune | 2 +- src/vnetif/vnetif.ml | 2 +- 7 files changed, 24 insertions(+), 29 deletions(-) delete mode 100644 .merlin diff --git a/.merlin b/.merlin deleted file mode 100644 index ed14409..0000000 --- a/.merlin +++ /dev/null @@ -1,7 +0,0 @@ -PKG mirage-clock-unix mirage-console mirage-net-unix mirage-unix tcpip -PKG mirage-clock-lwt lwt io-page result ipaddr mirage-profile mirage-time-lwt -PKG mirage-net mirage-net-lwt duration logs -PKG mirage-stack mirage-random mirage-clock arp ethernet - -S src -B _build/** diff --git a/mirage-vnetif-stack.opam b/mirage-vnetif-stack.opam index f45cc50..024d1b4 100644 --- a/mirage-vnetif-stack.opam +++ b/mirage-vnetif-stack.opam @@ -15,21 +15,19 @@ build: [ ] depends: [ - "ocaml" {>= "4.06.0"} + "ocaml" {>= "4.08.0"} "dune" {>= "1.9"} - "result" {>= "1.5"} "lwt" "mirage-time" {>= "2.0.0"} "mirage-clock" {>= "3.0.0"} "mirage-net" {>= "3.0.0"} "mirage-random" "mirage-vnetif" {= version} - "tcpip" {>= "7.0.0"} + "tcpip" {>= "8.0.0"} "ethernet" "cstruct" {>="6.0.0"} "ipaddr" {>= "5.0.0"} "macaddr" - "mirage-profile" "arp" {>= "3.0.0"} "duration" "logs" @@ -39,6 +37,7 @@ depends: [ "alcotest" {>= "1.5.0" & with-test} "alcotest-lwt" {with-test} ] +conflicts: [ "result" {< "1.5"} ] tags: ["org:mirage"] synopsis: "Vnetif implementation of mirage-stack for Mirage TCP/IP" description: """ diff --git a/mirage-vnetif.opam b/mirage-vnetif.opam index e526fc9..b2d1feb 100644 --- a/mirage-vnetif.opam +++ b/mirage-vnetif.opam @@ -14,18 +14,17 @@ build: [ ] depends: [ - "ocaml" {>= "4.06.0"} + "ocaml" {>= "4.08.0"} "dune" {>= "1.9"} - "result" {>= "1.5"} "lwt" "mirage-net" {>= "3.0.0"} "cstruct" {>="6.0.0"} "ipaddr" {>= "3.0.0"} "macaddr" - "mirage-profile" "duration" "logs" ] +conflicts: [ "result" {< "1.5"} ] tags: ["org:mirage"] synopsis: "Virtual network interface and software switch for Mirage" description: """ diff --git a/src/vnetif-stack/dune b/src/vnetif-stack/dune index b06b6bf..caccb35 100644 --- a/src/vnetif-stack/dune +++ b/src/vnetif-stack/dune @@ -3,8 +3,8 @@ (public_name mirage-vnetif-stack) (modules vnetif_stack) (wrapped false) - (libraries cstruct lwt lwt.unix mirage-clock ipaddr macaddr mirage-profile - duration result mirage-time mirage-net mirage-random ethernet arp arp.mirage - logs tcpip.stack-direct tcpip.ipv4 tcpip.icmpv4 tcpip.tcp tcpip.udp + (libraries cstruct lwt lwt.unix mirage-clock ipaddr macaddr + duration mirage-time mirage-net mirage-random ethernet arp arp.mirage + logs tcpip.stack-direct tcpip.ipv4 tcpip.ipv6 tcpip.icmpv4 tcpip.tcp tcpip.udp tcpip mirage-vnetif )) diff --git a/src/vnetif-stack/vnetif_stack.ml b/src/vnetif-stack/vnetif_stack.ml index 8a9c4bb..2516cc9 100644 --- a/src/vnetif-stack/vnetif_stack.ml +++ b/src/vnetif-stack/vnetif_stack.ml @@ -14,7 +14,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -open Lwt +open Lwt.Infix module type Vnetif_stack = sig @@ -22,14 +22,14 @@ sig type buffer type 'a io type id - module V4 : Tcpip.Stack.V4 + module V4V6 : Tcpip.Stack.V4V6 module Backend : Vnetif.BACKEND (** Create a new IPv4 stack connected to an existing backend *) val create_stack_ipv4 : cidr:Ipaddr.V4.Prefix.t -> ?gateway:Ipaddr.V4.t -> ?mtu:int -> ?monitor_fn:(buffer -> unit io) -> ?unlock_on_listen:Lwt_mutex.t -> - backend -> V4.t Lwt.t + backend -> V4V6.t Lwt.t end module Vnetif_stack (B : Vnetif.BACKEND)(R : Mirage_random.S)(Time : Mirage_time.S)(Mclock : Mirage_clock.MCLOCK): @@ -44,21 +44,25 @@ struct module V = Vnetif.Make(Backend) module E = Ethernet.Make(V) module A = Arp.Make(E)(Time) - module Ip = Static_ipv4.Make(R)(Mclock)(E)(A) - module Icmp = Icmpv4.Make(Ip) + module Ip4 = Static_ipv4.Make(R)(Mclock)(E)(A) + module Icmp = Icmpv4.Make(Ip4) + module Ip6 = Ipv6.Make(V)(E)(R)(Time)(Mclock) + module Ip = Tcpip_stack_direct.IPV4V6(Ip4)(Ip6) module U = Udp.Make(Ip)(R) module T = Tcp.Flow.Make(Ip)(Time)(Mclock)(R) - module V4 = Tcpip_stack_direct.Make(Time)(R)(V)(E)(A)(Ip)(Icmp)(U)(T) + module V4V6 = Tcpip_stack_direct.MakeV4V6(Time)(R)(V)(E)(A)(Ip)(Icmp)(U)(T) let create_stack_ipv4 ~cidr ?gateway ?mtu ?monitor_fn ?unlock_on_listen backend = V.connect ?size_limit:mtu ?monitor_fn ?unlock_on_listen backend >>= fun netif -> E.connect netif >>= fun ethif -> A.connect ethif >>= fun arp -> - Ip.connect ~cidr ?gateway ethif arp >>= fun ipv4 -> + Ip4.connect ~cidr ?gateway ethif arp >>= fun ipv4 -> Icmp.connect ipv4 >>= fun icmp -> - U.connect ipv4 >>= fun udp -> - T.connect ipv4 >>= fun tcp -> - V4.connect netif ethif arp ipv4 icmp udp tcp + Ip6.connect ~no_init:true netif ethif >>= fun ipv6 -> + Ip.connect ~ipv4_only:true ~ipv6_only:false ipv4 ipv6 >>= fun ip -> + U.connect ip >>= fun udp -> + T.connect ip >>= fun tcp -> + V4V6.connect netif ethif arp ip icmp udp tcp end (*module Vnetif_stack_unix(B: Vnetif.BACKEND)(R : Mirage_random.S): diff --git a/src/vnetif/dune b/src/vnetif/dune index b2b0666..7af35f7 100644 --- a/src/vnetif/dune +++ b/src/vnetif/dune @@ -4,5 +4,5 @@ (modules basic_backend vnetif) (wrapped false) (libraries cstruct lwt lwt.unix ipaddr macaddr - duration result mirage-net logs mirage-profile + duration mirage-net logs )) diff --git a/src/vnetif/vnetif.ml b/src/vnetif/vnetif.ml index f1906e9..49ce2ce 100644 --- a/src/vnetif/vnetif.ml +++ b/src/vnetif/vnetif.ml @@ -111,7 +111,7 @@ module Make (B : BACKEND) = struct | Some l -> Lwt_mutex.unlock l); (* Block until woken up by disconnect *) - let task, waker = MProf.Trace.named_task "Netif.listen" in + let task, waker = Lwt.task () in t.wake_on_disconnect <- (Some waker); task >|= fun () -> Ok () From 258e80109f864957ceeb4c2ddf3a42661daee91e Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Tue, 7 May 2024 15:28:58 +0200 Subject: [PATCH 2/8] adapt tests to recent changes --- test/vnetif-stack/test.ml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/vnetif-stack/test.ml b/test/vnetif-stack/test.ml index 09bb71f..a4de4c1 100644 --- a/test/vnetif-stack/test.ml +++ b/test/vnetif-stack/test.ml @@ -30,12 +30,12 @@ let connect_test_lwt _ () = let or_error name fn t = fn t >>= function - | Error e -> Alcotest.failf "%s: %s" name (Format.asprintf "%a" Stack.V4.TCPV4.pp_error e) + | Error e -> Alcotest.failf "%s: %s" name (Format.asprintf "%a" Stack.V4V6.TCP.pp_error e) | Ok t -> Lwt.return t in let accept client_l flow expected = - or_error "read" Stack.V4.TCPV4.read flow >>= function + or_error "read" Stack.V4V6.TCP.read flow >>= function | `Eof -> Alcotest.failf "eof while reading from socket" | `Data data -> let recv_str = Cstruct.to_string data in @@ -62,19 +62,19 @@ let connect_test_lwt _ () = (* Server side *) (Stack.create_stack_ipv4 ~cidr:server_cidr ~unlock_on_listen:listen_l backend >>= fun s1 -> - Stack.V4.TCPV4.listen (Stack.V4.tcpv4 s1) ~port:80 (fun f -> accept accept_l f test_msg); - Stack.V4.listen s1 >>= fun () -> + Stack.V4V6.TCP.listen (Stack.V4V6.tcp s1) ~port:80 (fun f -> accept accept_l f test_msg); + Stack.V4V6.listen s1 >>= fun () -> Alcotest.failf "server: listen should never exit"); (* Client side *) Lwt_mutex.lock listen_l >>= fun () -> (* wait for server to unlock with call to listen *) Stack.create_stack_ipv4 ~cidr:client_cidr backend >>= fun s2 -> - or_error "connect" (Stack.V4.TCPV4.create_connection (Stack.V4.tcpv4 s2)) (Ipaddr.V4.Prefix.address server_cidr, 80) >>= fun flow -> - Stack.V4.TCPV4.write flow (Cstruct.of_string test_msg) >>= (function + or_error "connect" (Stack.V4V6.TCP.create_connection (Stack.V4V6.tcp s2)) Ipaddr.(V4 (V4.Prefix.address server_cidr), 80) >>= fun flow -> + Stack.V4V6.TCP.write flow (Cstruct.of_string test_msg) >>= (function | Ok () -> Lwt.return_unit - | Error e -> Alcotest.failf "write: %s" (Format.asprintf "%a" Stack.V4.TCPV4.pp_write_error e)) + | Error e -> Alcotest.failf "write: %s" (Format.asprintf "%a" Stack.V4V6.TCP.pp_write_error e)) >>= fun () -> - Stack.V4.TCPV4.close flow >>= fun () -> + Stack.V4V6.TCP.close flow >>= fun () -> Lwt_mutex.lock accept_l (* wait for accept to unlock *) ] ) From 2ee23194fc230e27f6a25dd8eea8c9402cd8d0c1 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Tue, 7 May 2024 15:36:45 +0200 Subject: [PATCH 3/8] mirage-vnetif-stack: adjust bounds --- mirage-vnetif-stack.opam | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mirage-vnetif-stack.opam b/mirage-vnetif-stack.opam index 024d1b4..c8334d6 100644 --- a/mirage-vnetif-stack.opam +++ b/mirage-vnetif-stack.opam @@ -18,8 +18,8 @@ depends: [ "ocaml" {>= "4.08.0"} "dune" {>= "1.9"} "lwt" - "mirage-time" {>= "2.0.0"} - "mirage-clock" {>= "3.0.0"} + "mirage-time" {>= "3.0.0"} + "mirage-clock" {>= "4.0.0"} "mirage-net" {>= "3.0.0"} "mirage-random" "mirage-vnetif" {= version} From a0d1bcb63ae5e978232ad4e6bbe6dcd0b84a08d8 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Tue, 7 May 2024 15:39:28 +0200 Subject: [PATCH 4/8] use mirage-crypto-rng instead of mirage-random-test --- mirage-vnetif-stack.opam | 2 +- test/vnetif-stack/dune | 2 +- test/vnetif-stack/test.ml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mirage-vnetif-stack.opam b/mirage-vnetif-stack.opam index c8334d6..046cd61 100644 --- a/mirage-vnetif-stack.opam +++ b/mirage-vnetif-stack.opam @@ -33,7 +33,7 @@ depends: [ "logs" "mirage-time-unix" {with-test} "mirage-clock-unix" {with-test} - "mirage-random-test" {with-test} + "mirage-crypto-rng" {with-test} "alcotest" {>= "1.5.0" & with-test} "alcotest-lwt" {with-test} ] diff --git a/test/vnetif-stack/dune b/test/vnetif-stack/dune index e052491..241ecf2 100644 --- a/test/vnetif-stack/dune +++ b/test/vnetif-stack/dune @@ -1,6 +1,6 @@ (test (name test) (package mirage-vnetif-stack) - (libraries lwt alcotest alcotest-lwt mirage-vnetif mirage-vnetif-stack mirage-random-test mirage-clock-unix mirage-time-unix) + (libraries lwt alcotest alcotest-lwt mirage-vnetif mirage-vnetif-stack mirage-crypto-rng mirage-crypto-rng.unix mirage-clock-unix mirage-time-unix) (action (run %{test} -v -e --color=always))) diff --git a/test/vnetif-stack/test.ml b/test/vnetif-stack/test.ml index a4de4c1..074218e 100644 --- a/test/vnetif-stack/test.ml +++ b/test/vnetif-stack/test.ml @@ -17,7 +17,7 @@ open Lwt.Infix module Stack(B: Vnetif.BACKEND) = struct - module V = Vnetif_stack.Vnetif_stack(B)(Mirage_random_test)(Time)(Mclock) + module V = Vnetif_stack.Vnetif_stack(B)(Mirage_crypto_rng)(Time)(Mclock) include V end @@ -86,7 +86,7 @@ let () = Random.init rand_seed; Printf.printf "Testing with rand_seed %d\n" rand_seed; - (*Mirage_random_test.initialize();*) + Mirage_crypto_rng_unix.initialize (module Mirage_crypto_rng.Fortuna); Lwt_main.run @@ Alcotest_lwt.run "mirage-vnetif" [ From 86ac897fa58d509b6dc0b7edb26940a3d44412f7 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Tue, 7 May 2024 15:47:15 +0200 Subject: [PATCH 5/8] require mirage-clock-unix 4.0.0 --- mirage-vnetif-stack.opam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mirage-vnetif-stack.opam b/mirage-vnetif-stack.opam index 046cd61..16434ec 100644 --- a/mirage-vnetif-stack.opam +++ b/mirage-vnetif-stack.opam @@ -32,7 +32,7 @@ depends: [ "duration" "logs" "mirage-time-unix" {with-test} - "mirage-clock-unix" {with-test} + "mirage-clock-unix" {with-test & >= "4.0.0"} "mirage-crypto-rng" {with-test} "alcotest" {>= "1.5.0" & with-test} "alcotest-lwt" {with-test} From 0e0a539554326155206c087e8f64f7cd97459245 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Wed, 8 May 2024 10:41:38 +0200 Subject: [PATCH 6/8] github action: split windows and macos to extend the windows opam repositories --- .github/workflows/{main.yml => macos.yml} | 1 - .github/workflows/windows.yml | 38 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) rename .github/workflows/{main.yml => macos.yml} (96%) create mode 100644 .github/workflows/windows.yml diff --git a/.github/workflows/main.yml b/.github/workflows/macos.yml similarity index 96% rename from .github/workflows/main.yml rename to .github/workflows/macos.yml index c623ef8..0378ac0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/macos.yml @@ -14,7 +14,6 @@ jobs: matrix: os: - macos-latest - - windows-latest ocaml-compiler: - 4.13.x diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 0000000..fc2348c --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,38 @@ +name: Main workflow + +on: + pull_request: + push: + schedule: + # Prime the caches every Monday + - cron: 0 1 * * MON + +jobs: + build: + strategy: + fail-fast: false + matrix: + os: + - windows-latest + ocaml-compiler: + - 4.13.x + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Use OCaml ${{ matrix.ocaml-compiler }} + uses: ocaml/setup-ocaml@v2 + with: + opam-repositories: | + opam-repository-mingw: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset + default: https://github.com/ocaml/opam-repository.git + ocaml-compiler: ${{ matrix.ocaml-compiler }} + + - run: opam install . --deps-only --with-test + + - run: opam exec -- dune build + + - run: opam exec -- dune runtest From 4a95f55782beff493bfed95d5afb96b0da5d44b9 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Wed, 8 May 2024 10:49:54 +0200 Subject: [PATCH 7/8] mirage-crypto-rng lower bound --- mirage-vnetif-stack.opam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mirage-vnetif-stack.opam b/mirage-vnetif-stack.opam index 16434ec..64d15cd 100644 --- a/mirage-vnetif-stack.opam +++ b/mirage-vnetif-stack.opam @@ -33,7 +33,7 @@ depends: [ "logs" "mirage-time-unix" {with-test} "mirage-clock-unix" {with-test & >= "4.0.0"} - "mirage-crypto-rng" {with-test} + "mirage-crypto-rng" {with-test & >= "0.11.0"} "alcotest" {>= "1.5.0" & with-test} "alcotest-lwt" {with-test} ] From 3c6d273b8830cab8076998c572c1b31e4a65ce8e Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Wed, 8 May 2024 10:58:43 +0200 Subject: [PATCH 8/8] require alcotest-lwt same as alcotest --- mirage-vnetif-stack.opam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mirage-vnetif-stack.opam b/mirage-vnetif-stack.opam index 64d15cd..4b4ab19 100644 --- a/mirage-vnetif-stack.opam +++ b/mirage-vnetif-stack.opam @@ -35,7 +35,7 @@ depends: [ "mirage-clock-unix" {with-test & >= "4.0.0"} "mirage-crypto-rng" {with-test & >= "0.11.0"} "alcotest" {>= "1.5.0" & with-test} - "alcotest-lwt" {with-test} + "alcotest-lwt" {>= "1.5.0" & with-test} ] conflicts: [ "result" {< "1.5"} ] tags: ["org:mirage"]