Skip to content

Commit

Permalink
use the Random device for IPv4 id
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesm committed Sep 16, 2018
1 parent c5e047e commit 813225d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/ipv4/ipv4_common.ml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
let adjust_output_header ~dmac ~tlen frame =
let adjust_output_header ~rng ~dmac ~tlen frame =
let open Ipv4_wire in
Ethif_wire.set_ethernet_dst dmac 0 frame;
let buf = Cstruct.sub frame Ethif_wire.sizeof_ethernet sizeof_ipv4 in
(* Set the mutable values in the ipv4 header *)
set_ipv4_len buf tlen;
set_ipv4_id buf (Random.int 65535); (* TODO *)
set_ipv4_id buf (Randomconv.int16 rng);
set_ipv4_csum buf 0;
let checksum = Tcpip_checksum.ones_complement buf in
set_ipv4_csum buf checksum
Expand Down
2 changes: 1 addition & 1 deletion src/ipv4/jbuild
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
((name tcpip_ipv4)
(public_name tcpip.ipv4)
(libraries (logs io-page mirage-protocols-lwt ipaddr cstruct rresult
tcpip tcpip.ethif tcpip.udp))
tcpip tcpip.ethif tcpip.udp mirage-random mirage-clock randomconv))
(preprocess (pps (ppx_cstruct)))
(wrapped false)))
6 changes: 3 additions & 3 deletions src/ipv4/static_ipv4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ open Lwt.Infix
let src = Logs.Src.create "ipv4" ~doc:"Mirage IPv4"
module Log = (val Logs.src_log src : Logs.LOG)

module Make(Ethif: Mirage_protocols_lwt.ETHIF) (Arpv4 : Mirage_protocols_lwt.ARP) = struct
module Make (R: Mirage_random.C) (C: Mirage_clock.MCLOCK) (Ethif: Mirage_protocols_lwt.ETHIF) (Arpv4 : Mirage_protocols_lwt.ARP) = struct
module Routing = Routing.Make(Log)(Arpv4)

(** IO operation errors *)
Expand All @@ -41,7 +41,7 @@ module Make(Ethif: Mirage_protocols_lwt.ETHIF) (Arpv4 : Mirage_protocols_lwt.ARP
mutable gateway: Ipaddr.V4.t option;
}

let adjust_output_header = Ipv4_common.adjust_output_header
let adjust_output_header = Ipv4_common.adjust_output_header ~rng:R.generate

let allocate_frame t ~(dst:ipaddr) ~(proto : [`ICMP | `TCP | `UDP]) : (buffer * int) =
Ipv4_common.allocate_frame ~src:t.ip ~source:(Ethif.mac t.ethif) ~dst ~proto
Expand Down Expand Up @@ -96,7 +96,7 @@ module Make(Ethif: Mirage_protocols_lwt.ETHIF) (Arpv4 : Mirage_protocols_lwt.ARP
let connect
?(ip=Ipaddr.V4.any)
?(network=Ipaddr.V4.Prefix.make 0 Ipaddr.V4.any)
?(gateway=None) ethif arp =
?(gateway=None) _clock ethif arp =
match Ipaddr.V4.Prefix.mem ip network with
| false ->
Log.warn (fun f -> f "IPv4: ip %a is not in the prefix %a" Ipaddr.V4.pp_hum ip Ipaddr.V4.Prefix.pp_hum network);
Expand Down
4 changes: 2 additions & 2 deletions src/ipv4/static_ipv4.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

module Make (E:Mirage_protocols_lwt.ETHIF) (A: Mirage_protocols_lwt.ARP) : sig
module Make (R: Mirage_random.C) (C: Mirage_clock.MCLOCK) (E: Mirage_protocols_lwt.ETHIF) (A: Mirage_protocols_lwt.ARP) : sig
include Mirage_protocols_lwt.IPV4
val connect :
?ip:Ipaddr.V4.t ->
?network:Ipaddr.V4.Prefix.t ->
?gateway:Ipaddr.V4.t option ->
E.t -> A.t -> t Lwt.t
C.t -> E.t -> A.t -> t Lwt.t
(** Connect to an ipv4 device.
Default ip is {!Ipaddr.V4.any}
Default network is {!Ipaddr.V4.any}/0
Expand Down

0 comments on commit 813225d

Please sign in to comment.