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 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..4b4ab19 100644 --- a/mirage-vnetif-stack.opam +++ b/mirage-vnetif-stack.opam @@ -15,30 +15,29 @@ 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-time" {>= "3.0.0"} + "mirage-clock" {>= "4.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" "mirage-time-unix" {with-test} - "mirage-clock-unix" {with-test} - "mirage-random-test" {with-test} + "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"] 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 () 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 09bb71f..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 @@ -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 *) ] ) @@ -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" [