diff --git a/.travis.yml b/.travis.yml index 91bc7b04d..d912b4487 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ env: - POST_INSTALL_HOOK="sh ./.travis-ci.sh" - PACKAGE=tcpip matrix: - - DISTRO=alpine OCAML_VERSION=4.06 EXTRA_ENV="MIRAGE_MODE=xen" - - DISTRO=alpine OCAML_VERSION=4.07 EXTRA_ENV="MIRAGE_MODE=unix" - - DISTRO=alpine OCAML_VERSION=4.08 EXTRA_ENV="MIRAGE_MODE=qubes" - - DISTRO=alpine OCAML_VERSION=4.09 EXTRA_ENV="MIRAGE_MODE=virtio" + - DISTRO=alpine OCAML_VERSION=4.08 EXTRA_ENV="MIRAGE_MODE=xen" + - DISTRO=alpine OCAML_VERSION=4.09 EXTRA_ENV="MIRAGE_MODE=unix" + - DISTRO=alpine OCAML_VERSION=4.10 EXTRA_ENV="MIRAGE_MODE=qubes" + - DISTRO=alpine OCAML_VERSION=4.10 EXTRA_ENV="MIRAGE_MODE=virtio" diff --git a/src/ipv4/static_ipv4.ml b/src/ipv4/static_ipv4.ml index aef0e2ea9..60512d426 100644 --- a/src/ipv4/static_ipv4.ml +++ b/src/ipv4/static_ipv4.ml @@ -36,14 +36,13 @@ module Make (R: Mirage_random.S) (C: Mirage_clock.MCLOCK) (Ethernet: Mirage_prot type t = { ethif : Ethernet.t; arp : Arpv4.t; - mutable ip: Ipaddr.V4.t; - network: Ipaddr.V4.Prefix.t; - mutable gateway: Ipaddr.V4.t option; + cidr: Ipaddr.V4.Prefix.t; + gateway: Ipaddr.V4.t option; mutable cache: Fragments.Cache.t; } let write t ?(fragment = true) ?(ttl = 38) ?src dst proto ?(size = 0) headerf bufs = - Routing.destination_mac t.network t.gateway t.arp dst >>= function + Routing.destination_mac t.cidr t.gateway t.arp dst >>= function | Error `Local -> Log.warn (fun f -> f "Could not find %a on the local network" Ipaddr.V4.pp dst); Lwt.return @@ Error (`No_route "no response for IP on local network") @@ -73,7 +72,7 @@ module Make (R: Mirage_random.S) (C: Mirage_clock.MCLOCK) (Ethernet: Mirage_prot | false, true -> assert false (* handled by conditional above *) in let hdr = - let src = match src with None -> t.ip | Some x -> x in + let src = match src with None -> Ipaddr.V4.Prefix.address t.cidr | Some x -> x in let id = if multiple then Randomconv.int16 R.generate else 0 in Ipv4_packet.{ options = Cstruct.empty ; @@ -134,9 +133,9 @@ module Make (R: Mirage_random.S) (C: Mirage_clock.MCLOCK) (Ethernet: Mirage_prot Lwt.return_unit | Ok (packet, payload) -> let of_interest ip = - Ipaddr.V4.(compare ip t.ip = 0 + Ipaddr.V4.(compare ip (Prefix.address t.cidr) = 0 || compare ip broadcast = 0 - || compare ip (Prefix.broadcast t.network) = 0) + || compare ip (Prefix.broadcast t.cidr) = 0) in if not (of_interest packet.dst) then begin Log.debug (fun m -> m "dropping IP fragment not for us or broadcast %a" @@ -159,22 +158,20 @@ module Make (R: Mirage_random.S) (C: Mirage_clock.MCLOCK) (Ethernet: Mirage_prot | Some `ICMP | None -> default ~proto:packet.proto ~src ~dst payload let connect - ~ip:(network, ip) ?gateway ?(fragment_cache_size = 1024 * 256) ethif arp = - Arpv4.set_ips arp [ip] >>= fun () -> - (* TODO currently hardcoded to 256KB, should be configurable - and maybe limited per-src/dst-ip as well? *) + ~cidr ?gateway ?(fragment_cache_size = 1024 * 256) ethif arp = + Arpv4.set_ips arp [Ipaddr.V4.Prefix.address cidr] >>= fun () -> let cache = Fragments.Cache.empty fragment_cache_size in - Lwt.return { ethif; arp; ip; network; gateway ; cache } + Lwt.return { ethif; arp; cidr; gateway; cache } let disconnect _ = Lwt.return_unit - let get_ip t = [t.ip] + let get_ip t = [Ipaddr.V4.Prefix.address t.cidr] let pseudoheader t ?src dst proto len = - let src = match src with None -> t.ip | Some x -> x in + let src = match src with None -> Ipaddr.V4.Prefix.address t.cidr | Some x -> x in Ipv4_packet.Marshal.pseudoheader ~src ~dst ~proto len - let src t ~dst:_ = t.ip + let src t ~dst:_ = Ipaddr.V4.Prefix.address t.cidr let mtu t = Ethernet.mtu t.ethif - Ipv4_wire.sizeof_ipv4 diff --git a/src/ipv4/static_ipv4.mli b/src/ipv4/static_ipv4.mli index dc614c849..84f643d0b 100644 --- a/src/ipv4/static_ipv4.mli +++ b/src/ipv4/static_ipv4.mli @@ -17,10 +17,10 @@ module Make (R: Mirage_random.S) (C: Mirage_clock.MCLOCK) (E: Mirage_protocols.ETHERNET) (A: Mirage_protocols.ARP) : sig include Mirage_protocols.IP with type ipaddr = Ipaddr.V4.t - val connect : ip:(Ipaddr.V4.Prefix.t * Ipaddr.V4.t) -> ?gateway:Ipaddr.V4.t -> + val connect : cidr:Ipaddr.V4.Prefix.t -> ?gateway:Ipaddr.V4.t -> ?fragment_cache_size:int -> E.t -> A.t -> t Lwt.t - (** [connect ~ip ~gateway ~fragment_cache_size eth arp] connects the ipv4 - device using [ip] and [gateway] for network communication. The size of + (** [connect ~cidr ~gateway ~fragment_cache_size eth arp] connects the ipv4 + device using [cidr] and [gateway] for network communication. The size of the IPv4 fragment cache (for reassembly) can be provided in byte-size of fragments (defaults to 256kB). *) end diff --git a/tcpip.opam b/tcpip.opam index fdd2a5daa..c7e9c3721 100644 --- a/tcpip.opam +++ b/tcpip.opam @@ -32,7 +32,7 @@ depends: [ "mirage-stack" {>= "2.0.0"} "mirage-protocols" {>= "4.0.0"} "mirage-time" {>= "2.0.0"} - "ipaddr" {>= "4.0.0"} + "ipaddr" {>= "5.0.0"} "macaddr" {>="4.0.0"} "macaddr-cstruct" "mirage-profile" {>= "0.5"} diff --git a/test/test_connect.ml b/test/test_connect.ml index bb9e2f7c4..c78c2069b 100644 --- a/test/test_connect.ml +++ b/test/test_connect.ml @@ -26,9 +26,8 @@ module Test_connect (B : Vnetif_backends.Backend) = struct module V = VNETIF_STACK (B) let gateway = Ipaddr.V4.of_string_exn "10.0.0.1" - let client_ip = Ipaddr.V4.of_string_exn "10.0.0.101" - let server_ip = Ipaddr.V4.of_string_exn "10.0.0.100" - let network = Ipaddr.V4.Prefix.make 24 client_ip + let client_cidr = Ipaddr.V4.Prefix.of_string_exn "10.0.0.101/24" + let server_cidr = Ipaddr.V4.Prefix.of_string_exn "10.0.0.100/24" let test_string = "Hello world from Mirage 123456789...." let backend = V.create_backend () @@ -62,16 +61,16 @@ module Test_connect (B : Vnetif_backends.Backend) = struct (Lwt_unix.sleep timeout >>= fun () -> failf "connect test timedout after %f seconds" timeout) ; - (V.create_stack ~ip:(network, server_ip) ~gateway backend >>= fun s1 -> + (V.create_stack ~cidr:server_cidr ~gateway backend >>= fun s1 -> V.Stackv4.listen_tcpv4 s1 ~port:80 (fun f -> accept f test_string); V.Stackv4.listen s1) ; (Lwt_unix.sleep 0.1 >>= fun () -> - V.create_stack ~ip:(network, client_ip) ~gateway backend >>= fun s2 -> + V.create_stack ~cidr:client_cidr ~gateway backend >>= fun s2 -> Lwt.pick [ 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 -> + or_error "connect" conn (Ipaddr.V4.Prefix.address server_cidr, 80) >>= fun flow -> Log.debug (fun f -> f "Connected to other end..."); V.Stackv4.TCPV4.write flow (Cstruct.of_string test_string) >>= function diff --git a/test/test_deadlock.ml b/test/test_deadlock.ml index 3437ad514..74a4b7a18 100644 --- a/test/test_deadlock.ml +++ b/test/test_deadlock.ml @@ -37,13 +37,14 @@ struct type stack = TCPIP.t let server_ip = Ipaddr.V4.of_string_exn "192.168.10.10" + let server_cidr = Ipaddr.V4.Prefix.make 24 server_ip let client_ip = Ipaddr.V4.of_string_exn "192.168.10.20" - let network = Ipaddr.V4.Prefix.make 24 server_ip + let client_cidr = Ipaddr.V4.Prefix.make 24 client_ip - let make ~ip ?gateway netif = + let make ~cidr ?gateway netif = ETHIF.connect netif >>= fun ethif -> ARPV4.connect ethif >>= fun arpv4 -> - IPV4.connect ~ip:(network, ip) ?gateway ethif arpv4 >>= fun ipv4 -> + IPV4.connect ~cidr ?gateway ethif arpv4 >>= fun ipv4 -> ICMPV4.connect ipv4 >>= fun icmpv4 -> UDPV4.connect ipv4 >>= fun udpv4 -> TCPV4.connect ipv4 >>= fun tcpv4 -> @@ -55,8 +56,8 @@ struct let tcpip t = t let make role netif = match role with - | `Server -> make ~ip:server_ip netif - | `Client -> make ~ip:client_ip netif + | `Server -> make ~cidr:server_cidr netif + | `Client -> make ~cidr:client_cidr netif type conn = M.NETIF.t diff --git a/test/test_icmpv4.ml b/test/test_icmpv4.ml index ebad83011..1dc151beb 100644 --- a/test/test_icmpv4.ml +++ b/test/test_icmpv4.ml @@ -48,11 +48,11 @@ let header_size = Ethernet_wire.sizeof_ethernet let get_stack ?(backend = B.create ~use_async_readers:true ~yield:(fun() -> Lwt_main.yield ()) ()) ip = - let network = Ipaddr.V4.Prefix.make 24 listener_address in + let cidr = Ipaddr.V4.Prefix.make 24 ip in V.connect backend >>= fun netif -> E.connect netif >>= fun ethif -> Static_arp.connect ethif >>= fun arp -> - Ip.connect ~ip:(network, ip) ethif arp >>= fun ip -> + Ip.connect ~cidr ethif arp >>= fun ip -> Icmp.connect ip >>= fun icmp -> Udp.connect ip >>= fun udp -> Lwt.return { backend; netif; ethif; arp; ip; icmp; udp } diff --git a/test/test_iperf.ml b/test/test_iperf.ml index 5cb76fbf5..6fa29472e 100644 --- a/test/test_iperf.ml +++ b/test/test_iperf.ml @@ -25,8 +25,8 @@ module Test_iperf (B : Vnetif_backends.Backend) = struct module V = VNETIF_STACK (B) let gateway = Ipaddr.V4.of_string_exn "10.0.0.1" - let client_ip = Ipaddr.V4.Prefix.of_address_string_exn "10.0.0.101/24" - let server_ip = Ipaddr.V4.Prefix.of_address_string_exn "10.0.0.100/24" + let client_cidr = Ipaddr.V4.Prefix.of_string_exn "10.0.0.101/24" + let server_cidr = Ipaddr.V4.Prefix.of_string_exn "10.0.0.100/24" type stats = { mutable bytes: int64; @@ -44,8 +44,8 @@ module Test_iperf (B : Vnetif_backends.Backend) = struct } let default_network ?(backend = B.create ()) () = - V.create_stack ~ip:client_ip ~gateway backend >>= fun client -> - V.create_stack ~ip:server_ip ~gateway backend >>= fun server -> + V.create_stack ~cidr:client_cidr ~gateway backend >>= fun client -> + V.create_stack ~cidr:server_cidr ~gateway backend >>= fun server -> Lwt.return {backend; server; client} let msg = diff --git a/test/test_keepalive.ml b/test/test_keepalive.ml index 834ed4c29..d529b6668 100644 --- a/test/test_keepalive.ml +++ b/test/test_keepalive.ml @@ -75,9 +75,8 @@ module Test_connect = struct module V = VNETIF_STACK (Vnetif_backends.On_off_switch) let gateway = Ipaddr.V4.of_string_exn "10.0.0.1" - let client_ip = Ipaddr.V4.of_string_exn "10.0.0.101" - let server_ip = Ipaddr.V4.of_string_exn "10.0.0.100" - let network = Ipaddr.V4.Prefix.make 24 client_ip + let client_cidr = Ipaddr.V4.Prefix.of_string_exn "10.0.0.101/24" + let server_cidr = Ipaddr.V4.Prefix.of_string_exn "10.0.0.100/24" let backend = V.create_backend () let err_read_eof () = failf "accept got EOF while reading" @@ -101,17 +100,17 @@ module Test_connect = struct (Lwt_unix.sleep timeout >>= fun () -> failf "connect test timedout after %f seconds" timeout) ; - (V.create_stack ~ip:(network, server_ip) ~gateway backend >>= fun s1 -> + (V.create_stack ~cidr:server_cidr ~gateway backend >>= fun s1 -> V.Stackv4.listen_tcpv4 s1 ~port:80 (fun f -> accept f); V.Stackv4.listen s1) ; (Lwt_unix.sleep 0.1 >>= fun () -> - V.create_stack ~ip:(network, client_ip) ~gateway backend >>= fun s2 -> + V.create_stack ~cidr:client_cidr ~gateway backend >>= fun s2 -> Lwt.pick [ V.Stackv4.listen s2; let keepalive = { Mirage_protocols.Keepalive.after = 0L; interval = Duration.of_sec 1; probes = 3 } in (let conn = V.Stackv4.TCPV4.create_connection ~keepalive (V.Stackv4.tcpv4 s2) in - or_error "connect" conn (server_ip, 80) >>= fun flow -> + or_error "connect" conn (Ipaddr.V4.Prefix.address server_cidr, 80) >>= fun flow -> Logs.debug (fun f -> f "Connected to other end..."); Vnetif_backends.On_off_switch.send_packets := false; V.Stackv4.TCPV4.read flow >>= function diff --git a/test/test_mtus.ml b/test/test_mtus.ml index fef469ee5..18f8211ee 100644 --- a/test/test_mtus.ml +++ b/test/test_mtus.ml @@ -1,8 +1,7 @@ open Lwt.Infix -let server_ip = Ipaddr.V4.of_string_exn "192.168.1.254" -let client_ip = Ipaddr.V4.of_string_exn "192.168.1.10" -let network = Ipaddr.V4.Prefix.make 24 server_ip +let server_cidr = Ipaddr.V4.Prefix.of_string_exn "192.168.1.254/24" +let client_cidr = Ipaddr.V4.Prefix.of_string_exn "192.168.1.10/24" let server_port = 7 @@ -34,8 +33,8 @@ let read_one flow = let get_stacks ?client_mtu ?server_mtu backend = let or_default = function | None -> default_mtu | Some n -> n in let client_mtu, server_mtu = or_default client_mtu, or_default server_mtu in - Stack.create_stack ~ip:(network, client_ip) ~mtu:client_mtu backend >>= fun client -> - Stack.create_stack ~ip:(network, server_ip) ~mtu:server_mtu backend >>= fun server -> + Stack.create_stack ~cidr:client_cidr ~mtu:client_mtu backend >>= fun client -> + Stack.create_stack ~cidr:server_cidr ~mtu:server_mtu backend >>= fun server -> let max_mtu = max client_mtu server_mtu in Backend.set_mtu max_mtu; Lwt.return (server, client) @@ -45,7 +44,7 @@ let start_server ~f server = Stack.Stackv4.listen server let start_client client = - Stack.Stackv4.TCPV4.create_connection (Stack.Stackv4.tcpv4 client) (server_ip, server_port) >>= function + Stack.Stackv4.TCPV4.create_connection (Stack.Stackv4.tcpv4 client) (Ipaddr.V4.Prefix.address server_cidr, server_port) >>= function | Ok connection -> Lwt.return connection | Error e -> err_fail e diff --git a/test/test_rfc5961.ml b/test/test_rfc5961.ml index cc41e9378..73b9e7b04 100644 --- a/test/test_rfc5961.ml +++ b/test/test_rfc5961.ml @@ -35,9 +35,9 @@ module Tcp_wire = Tcp.Tcp_wire module Tcp_unmarshal = Tcp.Tcp_packet.Unmarshal module Sequence = Tcp.Sequence -let sut_ip = Ipaddr.V4.of_string_exn "10.0.0.101" +let sut_cidr = Ipaddr.V4.Prefix.of_string_exn "10.0.0.101/24" let server_ip = Ipaddr.V4.of_string_exn "10.0.0.100" -let network = Ipaddr.V4.Prefix.make 24 server_ip +let server_cidr = Ipaddr.V4.Prefix.make 24 server_ip let gateway = Ipaddr.V4.of_string_exn "10.0.0.1" let header_size = Ethernet_wire.sizeof_ethernet @@ -47,13 +47,13 @@ let options = [] let window = 5120 let create_sut_stack backend = - VNETIF_STACK.create_stack ~ip:(network, sut_ip) ~gateway backend + VNETIF_STACK.create_stack ~cidr:sut_cidr ~gateway backend -let create_raw_stack ip backend = +let create_raw_stack backend = V.connect backend >>= fun netif -> E.connect netif >>= fun ethif -> A.connect ethif >>= fun arpv4 -> - I.connect ~ip:(network, ip) ~gateway ethif arpv4 >>= fun ip -> + I.connect ~cidr:server_cidr ~gateway ethif arpv4 >>= fun ip -> Lwt.return (netif, ethif, arpv4, ip) type 'state fsm_result = @@ -67,7 +67,7 @@ type 'state fsm_result = let run backend fsm sut () = let initial_state, fsm_handler = fsm in create_sut_stack backend >>= fun stackv4 -> - create_raw_stack server_ip backend >>= fun (netif, ethif, arp, rawip) -> + create_raw_stack backend >>= fun (netif, ethif, arp, rawip) -> let error_mbox = Lwt_mvar.create_empty () in let stream, pushf = Lwt_stream.create () in Lwt.pick [ diff --git a/test/test_udp.ml b/test/test_udp.ml index 1760a6b7a..f9c7c9092 100644 --- a/test/test_udp.ml +++ b/test/test_udp.ml @@ -20,11 +20,11 @@ type stack = { let get_stack ?(backend = B.create ~use_async_readers:true ~yield:(fun() -> Lwt_main.yield ()) ()) ip = let open Lwt.Infix in - let network = Ipaddr.V4.Prefix.make 24 ip in + let cidr = Ipaddr.V4.Prefix.make 24 ip in V.connect backend >>= fun netif -> E.connect netif >>= fun ethif -> Static_arp.connect ethif >>= fun arp -> - Ip.connect ~ip:(network, ip) ethif arp >>= fun ip -> + Ip.connect ~cidr ethif arp >>= fun ip -> Udp.connect ip >>= fun udp -> Lwt.return { backend; netif; ethif; arp; ip; udp } diff --git a/test/vnetif_common.ml b/test/vnetif_common.ml index 50dc78efe..6985701e6 100644 --- a/test/vnetif_common.ml +++ b/test/vnetif_common.ml @@ -39,7 +39,7 @@ sig val create_backend : unit -> backend (** Create a new stack connected to an existing backend *) - val create_stack : ?mtu:int -> ip:(Ipaddr.V4.Prefix.t * Ipaddr.V4.t) -> + val create_stack : ?mtu:int -> cidr:Ipaddr.V4.Prefix.t -> ?gateway:Ipaddr.V4.t -> backend -> Stackv4.t Lwt.t (** [create_stack backend ?mtu ip netmask gateway] adds a listener @@ -75,12 +75,12 @@ struct let create_backend () = B.create () - let create_stack ?mtu ~ip ?gateway backend = + let create_stack ?mtu ~cidr ?gateway backend = let size_limit = match mtu with None -> None | Some x -> Some x in V.connect ?size_limit backend >>= fun netif -> E.connect netif >>= fun ethif -> A.connect ethif >>= fun arpv4 -> - Ip.connect ~ip ?gateway ethif arpv4 >>= fun ipv4 -> + Ip.connect ~cidr ?gateway ethif arpv4 >>= fun ipv4 -> Icmp.connect ipv4 >>= fun icmpv4 -> U.connect ipv4 >>= fun udpv4 -> T.connect ipv4 >>= fun tcpv4 ->