From 4f18a01466e58d65d83bb7ad7f6bc8a33fb38a00 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Wed, 28 Sep 2016 11:29:55 +0100 Subject: [PATCH 1/2] change of random --- _oasis | 4 ++-- _tags | 7 ++++++- lib/META | 6 +++--- lib/dhcp/dhcp_clientv4.ml | 4 ++-- lib/tcp/flow.ml | 2 +- lib/tcp/flow.mli | 2 +- lib/tcp/pcb.ml | 10 +++++----- lib/tcp/pcb.mli | 2 +- lib/tcpip_stack_direct.ml | 2 +- lib/tcpip_stack_direct.mli | 2 +- setup.ml | 13 ++++++++----- 11 files changed, 31 insertions(+), 23 deletions(-) diff --git a/_oasis b/_oasis index 774ee97c7..ad6b399ce 100644 --- a/_oasis +++ b/_oasis @@ -98,7 +98,7 @@ Library tcp Tcp_wire, Tcp_packet BuildDepends: logs,mirage-types,ipaddr,cstruct,cstruct.ppx,lwt,result,rresult,mirage-profile, io-page, - tcpip, duration + tcpip, duration, randomconv Library dhcpv4 CompiledObject: best @@ -107,7 +107,7 @@ Library dhcpv4 Findlibname: dhcpv4 Modules: Dhcpv4_option,Dhcp_clientv4 BuildDepends: logs,io-page,mirage-types,ipaddr,cstruct,cstruct.ppx,lwt, - tcpip.udp, duration + tcpip.udp, duration, randomconv Library "tcpip-stack-direct" CompiledObject: best diff --git a/_tags b/_tags index 927908538..e17e09063 100644 --- a/_tags +++ b/_tags @@ -1,5 +1,5 @@ # OASIS_START -# DO NOT EDIT (digest: 865c70bb000f8ddf7f1771b483047749) +# DO NOT EDIT (digest: bb445ce5e2101b5879bf9a10a8602530) # Ignore VCS directories, you can use the same kind of rule outside # OASIS_START/STOP if you want to exclude directories that contains # useless stuff for the build process @@ -128,6 +128,7 @@ true: annot, bin_annot : pkg_lwt : pkg_mirage-profile : pkg_mirage-types +: pkg_randomconv : pkg_result : pkg_rresult : use_tcpip @@ -142,6 +143,7 @@ true: annot, bin_annot : pkg_lwt : pkg_mirage-profile : pkg_mirage-types +: pkg_randomconv : pkg_result : pkg_rresult : use_tcpip @@ -157,6 +159,7 @@ true: annot, bin_annot : pkg_lwt : pkg_mirage-profile : pkg_mirage-types +: pkg_randomconv : pkg_result : pkg_rresult : use_dhcpv4 @@ -212,6 +215,7 @@ true: annot, bin_annot : pkg_mirage-vnetif : pkg_oUnit : pkg_pcap-format +: pkg_randomconv : pkg_result : pkg_rresult : use_arpv4 @@ -247,6 +251,7 @@ true: annot, bin_annot : pkg_mirage-vnetif : pkg_oUnit : pkg_pcap-format +: pkg_randomconv : pkg_result : pkg_rresult : use_arpv4 diff --git a/lib/META b/lib/META index f4252f31b..8d12e0ee5 100644 --- a/lib/META +++ b/lib/META @@ -1,5 +1,5 @@ # OASIS_START -# DO NOT EDIT (digest: 70283308f244bdf3d28fb6bd5d374881) +# DO NOT EDIT (digest: 6a8a6d795abb6ec056a6784efaf0d74f) version = "2.8.0" description = "Implementations for network-related module types from MirageOS." @@ -88,7 +88,7 @@ package "tcp" ( description = "Implementations for network-related module types from MirageOS." requires = - "logs mirage-types ipaddr cstruct cstruct.ppx lwt result rresult mirage-profile io-page tcpip duration" + "logs mirage-types ipaddr cstruct cstruct.ppx lwt result rresult mirage-profile io-page tcpip duration randomconv" archive(byte) = "tcp.cma" archive(byte, plugin) = "tcp.cma" archive(native) = "tcp.cmxa" @@ -189,7 +189,7 @@ package "dhcpv4" ( description = "Implementations for network-related module types from MirageOS." requires = - "logs io-page mirage-types ipaddr cstruct cstruct.ppx lwt tcpip.udp duration" + "logs io-page mirage-types ipaddr cstruct cstruct.ppx lwt tcpip.udp duration randomconv" archive(byte) = "dhcpv4.cma" archive(byte, plugin) = "dhcpv4.cma" archive(native) = "dhcpv4.cmxa" diff --git a/lib/dhcp/dhcp_clientv4.ml b/lib/dhcp/dhcp_clientv4.ml index 397fadf13..a57f30fe6 100644 --- a/lib/dhcp/dhcp_clientv4.ml +++ b/lib/dhcp/dhcp_clientv4.ml @@ -22,7 +22,7 @@ open Lwt.Infix module Make (Time : V1_LWT.TIME) - (Random : V1.RANDOM) + (Random : V1_LWT.RANDOM) (Udp : V1_LWT.UDPV4) = struct type offer = { @@ -193,7 +193,7 @@ module Make let start_discovery t = Time.sleep_ns (Duration.of_ms 200) >>= fun () -> - let xid = Random.int32 Int32.max_int in + let xid = Randomconv.int32 Random.generate in let yiaddr = Ipaddr.V4.any in let siaddr = Ipaddr.V4.any in let options = { Dhcpv4_option.Packet.op=`Discover; opts= [ diff --git a/lib/tcp/flow.ml b/lib/tcp/flow.ml index 3c42d4ffb..00476eb8f 100644 --- a/lib/tcp/flow.ml +++ b/lib/tcp/flow.ml @@ -23,7 +23,7 @@ exception Refused let src = Logs.Src.create "flow" ~doc:"Mirage TCP Flow module" module Log = (val Logs.src_log src : Logs.LOG) -module Make(IP:V1_LWT.IP)(TM:V1_LWT.TIME)(C:V1.MCLOCK)(R:V1.RANDOM) = struct +module Make(IP:V1_LWT.IP)(TM:V1_LWT.TIME)(C:V1.MCLOCK)(R:V1_LWT.RANDOM) = struct module Pcb = Pcb.Make(IP)(TM)(C)(R) diff --git a/lib/tcp/flow.mli b/lib/tcp/flow.mli index 8f9ba8876..3cfb9aed9 100644 --- a/lib/tcp/flow.mli +++ b/lib/tcp/flow.mli @@ -18,7 +18,7 @@ exception Refused (** {b NOTE}: to be removed in favor of a proper result type in V1.write_nodelay and V1.writev_nodelay.*) -module Make (IP:V1_LWT.IP)(TM:V1_LWT.TIME)(C:V1.MCLOCK)(R:V1.RANDOM) : sig +module Make (IP:V1_LWT.IP)(TM:V1_LWT.TIME)(C:V1.MCLOCK)(R:V1_LWT.RANDOM) : sig include V1_LWT.TCP with type ip = IP.t and type ipaddr = IP.ipaddr diff --git a/lib/tcp/pcb.ml b/lib/tcp/pcb.ml index d4149abd2..3b20d1485 100644 --- a/lib/tcp/pcb.ml +++ b/lib/tcp/pcb.ml @@ -20,7 +20,7 @@ open Lwt.Infix let src = Logs.Src.create "pcb" ~doc:"Mirage TCP PCB module" module Log = (val Logs.src_log src : Logs.LOG) -module Make(Ip:V1_LWT.IP)(Time:V1_LWT.TIME)(Clock:V1.MCLOCK)(Random:V1.RANDOM) = +module Make(Ip:V1_LWT.IP)(Time:V1_LWT.TIME)(Clock:V1.MCLOCK)(Random:V1_LWT.RANDOM) = struct module RXS = Segment.Rx(Time) @@ -416,7 +416,7 @@ struct Logs.(log_with_stats Debug "process-syn" t); match listeners @@ WIRE.src_port_of_id id with | Some pushf -> - let tx_isn = Sequence.of_int ((Random.int 65535) + 0x1AFE0000) in + let tx_isn = Sequence.of_int32 (Randomconv.int32 Random.generate) in (* TODO: make this configurable per listener *) let rx_wnd = 65535 in let rx_wnd_scaleoffer = wscale_default in @@ -581,7 +581,7 @@ struct let connect t ~dst ~dst_port = let id = getid t dst dst_port in - let tx_isn = Sequence.of_int ((Random.int 65535) + 0x1BCD0000) in + let tx_isn = Sequence.of_int32 (Randomconv.int32 Random.generate) in (* TODO: This is hardcoded for now - make it configurable *) let rx_wnd_scaleoffer = wscale_default in let options = @@ -602,8 +602,8 @@ struct (* Construct the main TCP thread *) let create ip clock = - Random.self_init (); - let localport = 10000 + (Random.int 10000) in + (* XXX: I've no clue why this is the way it is (10000 + Random ~bound:10000) -- hannes *) + let localport = 10000 + (Randomconv.int Random.generate ~bound:10000) in let listens = Hashtbl.create 1 in let connects = Hashtbl.create 1 in let channels = Hashtbl.create 7 in diff --git a/lib/tcp/pcb.mli b/lib/tcp/pcb.mli index 7fd02f2dc..14fa314c3 100644 --- a/lib/tcp/pcb.mli +++ b/lib/tcp/pcb.mli @@ -14,7 +14,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -module Make(Ip:V1_LWT.IP)(Time:V1_LWT.TIME)(Clock:V1.MCLOCK)(Random:V1.RANDOM) : sig +module Make(Ip:V1_LWT.IP)(Time:V1_LWT.TIME)(Clock:V1.MCLOCK)(Random:V1_LWT.RANDOM) : sig (** Overall state of the TCP stack *) type t diff --git a/lib/tcpip_stack_direct.ml b/lib/tcpip_stack_direct.ml index 773ea4e16..f411f78a7 100644 --- a/lib/tcpip_stack_direct.ml +++ b/lib/tcpip_stack_direct.ml @@ -28,7 +28,7 @@ module type TCPV4_DIRECT = V1_LWT.TCPV4 module Make (Time : V1_LWT.TIME) - (Random : V1.RANDOM) + (Random : V1_LWT.RANDOM) (Netif : V1_LWT.NETWORK) (Ethif : V1_LWT.ETHIF with type netif = Netif.t) (Arpv4 : V1_LWT.ARP) diff --git a/lib/tcpip_stack_direct.mli b/lib/tcpip_stack_direct.mli index c3129e850..e871f6335 100644 --- a/lib/tcpip_stack_direct.mli +++ b/lib/tcpip_stack_direct.mli @@ -23,7 +23,7 @@ module type TCPV4_DIRECT = V1_LWT.TCPV4 module Make (Time : V1_LWT.TIME) - (Random : V1.RANDOM) + (Random : V1_LWT.RANDOM) (Netif : V1_LWT.NETWORK) (Ethif : V1_LWT.ETHIF with type netif = Netif.t) (Arpv4 : V1_LWT.ARP) diff --git a/setup.ml b/setup.ml index 1ace4c530..47e68a30d 100644 --- a/setup.ml +++ b/setup.ml @@ -1,7 +1,7 @@ (* setup.ml generated for the first time by OASIS v0.4.5 *) (* OASIS_START *) -(* DO NOT EDIT (digest: c66b3ccd67691495732c021d86045b62) *) +(* DO NOT EDIT (digest: 97fdc978030881618fe6279b270b1427) *) (* Regenerated by OASIS v0.4.6 Visit http://oasis.forge.ocamlcore.org for more information and @@ -7302,7 +7302,8 @@ let setup_t = FindlibPackage ("mirage-profile", None); FindlibPackage ("io-page", None); InternalLibrary "tcpip"; - FindlibPackage ("duration", None) + FindlibPackage ("duration", None); + FindlibPackage ("randomconv", None) ]; bs_build_tools = [ExternalTool "ocamlbuild"]; bs_c_sources = []; @@ -7359,7 +7360,8 @@ let setup_t = FindlibPackage ("cstruct.ppx", None); FindlibPackage ("lwt", None); InternalLibrary "udp"; - FindlibPackage ("duration", None) + FindlibPackage ("duration", None); + FindlibPackage ("randomconv", None) ]; bs_build_tools = [ExternalTool "ocamlbuild"]; bs_c_sources = []; @@ -7728,7 +7730,8 @@ let setup_t = }; oasis_fn = Some "_oasis"; oasis_version = "0.4.6"; - oasis_digest = Some "\021<)K\251R\252\\K2\157\191!\2216\244"; + oasis_digest = + Some "\162h\220\1786\155\220\134\023V\176\159\002;\002\197"; oasis_exec = None; oasis_setup_args = []; setup_update = false @@ -7736,6 +7739,6 @@ let setup_t = let setup () = BaseSetup.setup setup_t;; -# 7740 "setup.ml" +# 7743 "setup.ml" (* OASIS_STOP *) let () = setup ();; From 5f44a2f36504701121811a2a6c65f331df9e240d Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Sun, 2 Oct 2016 12:39:27 +0100 Subject: [PATCH 2/2] need randomconv --- opam | 1 + 1 file changed, 1 insertion(+) diff --git a/opam b/opam index 5bba055bf..9212a056f 100644 --- a/opam +++ b/opam @@ -57,6 +57,7 @@ depends: [ "lwt" {>= "2.4.7"} "logs" {>= "0.6.0"} "duration" + "randomconv" ] depopts: [ "mirage-xen"