Permalink
Browse files

Revert "Remove the mirage module for now: it's not clear this should …

…live in this repo, and it depends on a special mirage-net"

This reverts commit 2338b41.

Conflicts:
	lib/META
	setup.ml
  • Loading branch information...
1 parent d095a67 commit 5aaa7c1872c633498dc4070ecff91e6a37c2f450 David Scott committed Sep 20, 2012
Showing with 199 additions and 16 deletions.
  1. +2 −1 Makefile
  2. +13 −0 _oasis
  3. +9 −1 _tags
  4. +11 −1 lib/META
  5. +100 −0 mirage/pcap_mirage.ml
  6. +11 −10 myocamlbuild.ml
  7. +53 −3 setup.ml
View
@@ -4,13 +4,14 @@ NAME=pcap
J=4
UNIX ?= $(shell if ocamlfind query lwt.unix >/dev/null 2>&1; then echo --enable-unix; fi)
+MIRAGE ?= $(shell if ocamlfind query mirage-net >/dev/null 2>&1; then echo --enable-mirage; fi)
TESTS ?= $(shell if ocamlfind query oUnit >/dev/null 2>&1; then echo --enable-tests; fi)
setup.ml: _oasis
oasis setup
setup.data: setup.ml
- ocaml setup.ml -configure $(UNIX) $(TESTS)
+ ocaml setup.ml -configure $(UNIX) $(MIRAGE) $(TESTS)
build: setup.data setup.ml
ocaml setup.ml -build -j $(J)
View
13 _oasis
@@ -11,13 +11,26 @@ Flag unix
Description: build the Unix binary
Default: false
+Flag mirage
+ Description: build the mirage library
+ Default: false
+
Library pcap
CompiledObject: best
Path: lib
Findlibname: pcap
Modules: Pcap
BuildDepends: cstruct ( >= 0.5.0 ), cstruct.syntax
+Library mirage
+ Build$: flag(mirage)
+ CompiledObject: best
+ Path: mirage
+ Findlibname: mirage
+ Findlibparent: pcap
+ Modules: Pcap_mirage
+ BuildDepends: mirage-net, pcap, lwt, lwt.syntax
+
Executable print
Build$: flag(unix)
CompiledObject: best
View
10 _tags
@@ -1,5 +1,5 @@
# OASIS_START
-# DO NOT EDIT (digest: 7fec0955b1fdff1eda5184c0e07ab8ed)
+# DO NOT EDIT (digest: 7fe842995f4991c2b872623f87cbdd5e)
# 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
@@ -17,6 +17,14 @@
"lib/pcap.cmxs": use_pcap
<lib/*.ml{,i}>: pkg_cstruct
<lib/*.ml{,i}>: pkg_cstruct.syntax
+# Library mirage
+"mirage/mirage.cmxs": use_mirage
+<mirage/*.ml{,i}>: use_pcap
+<mirage/*.ml{,i}>: pkg_lwt
+<mirage/*.ml{,i}>: pkg_cstruct
+<mirage/*.ml{,i}>: pkg_mirage-net
+<mirage/*.ml{,i}>: pkg_lwt.syntax
+<mirage/*.ml{,i}>: pkg_cstruct.syntax
# Executable print
<print/print.{native,byte}>: use_pcap
<print/print.{native,byte}>: pkg_lwt
View
@@ -1,5 +1,5 @@
# OASIS_START
-# DO NOT EDIT (digest: 9185edc693fcbd2954e2117070209a81)
+# DO NOT EDIT (digest: f18cc1d0851cfce04d572e0451965e43)
version = "0.3.2"
description = "Pcap tools"
requires = "cstruct cstruct.syntax"
@@ -8,5 +8,15 @@ archive(byte, plugin) = "pcap.cma"
archive(native) = "pcap.cmxa"
archive(native, plugin) = "pcap.cmxs"
exists_if = "pcap.cma"
+package "mirage" (
+ version = "0.3.2"
+ description = "Pcap tools"
+ requires = "mirage-net pcap lwt lwt.syntax"
+ archive(byte) = "mirage.cma"
+ archive(byte, plugin) = "mirage.cma"
+ archive(native) = "mirage.cmxa"
+ archive(native, plugin) = "mirage.cmxs"
+ exists_if = "mirage.cma"
+)
# OASIS_STOP
View
@@ -0,0 +1,100 @@
+(*
+ * Copyright (c) 2012 Citrix Systems
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *)
+
+open Lwt
+open OS
+(*open Net.Ethif *)
+open Pcap
+open Pcap.LE (* write in little-endian format *)
+
+let capture_limit = 64
+(** Buffer this many packets before we start to drop *)
+
+(* We lack a decent file abstraction so we'll experiment with representing
+ open files as threads which read commands from an mvar. *)
+
+type fd = Cstruct.buf list option Lwt_mvar.t
+
+let open_blkif blkif : fd =
+ let m : fd = Lwt_mvar.create_empty () in
+ let page_offset = ref 0L in
+ let buf_offset = ref 0 in
+ let closed = ref false in
+ let buf = Io_page.get () in
+ let (_: unit Lwt.t) =
+ while_lwt not(!closed) do
+ Lwt_mvar.take m >>=
+ function
+ | None ->
+ closed := true;
+ return ()
+ | Some (frags: Cstruct.buf list) ->
+ let single_write frag =
+ let available_space = 4096 - !buf_offset in
+ let needed_space = Cstruct.len frag in
+ if needed_space >= available_space then begin
+ Cstruct.blit_buffer frag 0 buf !buf_offset available_space;
+ lwt () = blkif#write_page !page_offset buf in
+ page_offset := Int64.add !page_offset 4096L;
+ buf_offset := 0;
+ return available_space
+ end else begin
+ Cstruct.blit_buffer frag 0 buf !buf_offset needed_space;
+ buf_offset := !buf_offset + needed_space;
+ return needed_space
+ end in
+ let write frag =
+ let remaining = ref frag in
+ while_lwt Cstruct.len !remaining > 0 do
+ lwt written = single_write !remaining in
+ remaining := Cstruct.shift !remaining written;
+ return ()
+ done in
+ Lwt_list.iter_s write frags
+ done in
+ m
+
+let capture input fd =
+ let buf = OS.Io_page.get () in
+ set_pcap_header_magic_number buf magic_number;
+ set_pcap_header_version_major buf major_version;
+ set_pcap_header_version_minor buf minor_version;
+ set_pcap_header_thiszone buf 0l;
+ set_pcap_header_sigfigs buf 0l;
+ set_pcap_header_snaplen buf 4096l;
+ set_pcap_header_network buf (Network.(to_int32 Ethernet));
+ lwt () = Lwt_mvar.put fd (Some [Cstruct.sub buf 0 sizeof_pcap_header] ) in
+
+ set_capture_limit capture_limit input;
+ OS.Console.log (Printf.sprintf "pcap: set capture limit to %d" capture_limit);
+
+ let stream = get_captured_packets input in
+ try_lwt
+ while_lwt true do
+ lwt packets = Lwt_bounded_stream.nget 1 stream in
+ Lwt_list.iter_s
+ (fun (time, frags) ->
+ let len = List.fold_left (+) 0 (List.map Cstruct.len frags) in
+ let buf = OS.Io_page.get () in
+ set_pcap_packet_ts_sec buf (Int32.(of_float time));
+ set_pcap_packet_ts_usec buf (Int32.rem (Int32.of_float ( time *. 1000000.)) 1000000l);
+ set_pcap_packet_incl_len buf (Int32.of_int len);
+ set_pcap_packet_orig_len buf (Int32.of_int len);
+ Lwt_mvar.put fd (Some (Cstruct.sub buf 0 sizeof_pcap_packet :: frags))
+ ) packets
+ done
+ with Lwt_stream.Closed ->
+ return ()
View
@@ -1,7 +1,7 @@
(* OASIS_START *)
-(* DO NOT EDIT (digest: d97eb6a4a76575f43024877abb2426c4) *)
+(* DO NOT EDIT (digest: 5b1cec25a6d4341f2d4dc4b90846fd71) *)
module OASISGettext = struct
-# 21 "/home/djs/.opam/3.12.1/build/oasis.0.3.0/src/oasis/OASISGettext.ml"
+# 21 "/Users/avsm/.opam/3.12.1+mirage-unix-direct/build/oasis.0.3.0/src/oasis/OASISGettext.ml"
let ns_ str =
str
@@ -24,7 +24,7 @@ module OASISGettext = struct
end
module OASISExpr = struct
-# 21 "/home/djs/.opam/3.12.1/build/oasis.0.3.0/src/oasis/OASISExpr.ml"
+# 21 "/Users/avsm/.opam/3.12.1+mirage-unix-direct/build/oasis.0.3.0/src/oasis/OASISExpr.ml"
@@ -116,7 +116,7 @@ end
# 117 "myocamlbuild.ml"
module BaseEnvLight = struct
-# 21 "/home/djs/.opam/3.12.1/build/oasis.0.3.0/src/base/BaseEnvLight.ml"
+# 21 "/Users/avsm/.opam/3.12.1+mirage-unix-direct/build/oasis.0.3.0/src/base/BaseEnvLight.ml"
module MapString = Map.Make(String)
@@ -214,7 +214,7 @@ end
# 215 "myocamlbuild.ml"
module MyOCamlbuildFindlib = struct
-# 21 "/home/djs/.opam/3.12.1/build/oasis.0.3.0/src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml"
+# 21 "/Users/avsm/.opam/3.12.1+mirage-unix-direct/build/oasis.0.3.0/src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml"
(** OCamlbuild extension, copied from
* http://brion.inria.fr/gallium/index.php/Using_ocamlfind_with_ocamlbuild
@@ -323,7 +323,7 @@ module MyOCamlbuildFindlib = struct
end
module MyOCamlbuildBase = struct
-# 21 "/home/djs/.opam/3.12.1/build/oasis.0.3.0/src/plugins/ocamlbuild/MyOCamlbuildBase.ml"
+# 21 "/Users/avsm/.opam/3.12.1+mirage-unix-direct/build/oasis.0.3.0/src/plugins/ocamlbuild/MyOCamlbuildBase.ml"
(** Base functions for writing myocamlbuild.ml
@author Sylvain Le Gall
@@ -339,7 +339,7 @@ module MyOCamlbuildBase = struct
type name = string
type tag = string
-# 56 "/home/djs/.opam/3.12.1/build/oasis.0.3.0/src/plugins/ocamlbuild/MyOCamlbuildBase.ml"
+# 56 "/Users/avsm/.opam/3.12.1+mirage-unix-direct/build/oasis.0.3.0/src/plugins/ocamlbuild/MyOCamlbuildBase.ml"
type t =
{
@@ -477,15 +477,16 @@ end
open Ocamlbuild_plugin;;
let package_default =
{
- MyOCamlbuildBase.lib_ocaml = [("pcap", ["lib"])];
+ MyOCamlbuildBase.lib_ocaml = [("pcap", ["lib"]); ("mirage", ["mirage"])];
lib_c = [];
flags = [];
- includes = [("print", ["lib"]); ("lib_test", ["lib"])];
+ includes =
+ [("print", ["lib"]); ("mirage", ["lib"]); ("lib_test", ["lib"])];
}
;;
let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;;
-# 490 "myocamlbuild.ml"
+# 491 "myocamlbuild.ml"
(* OASIS_STOP *)
Ocamlbuild_plugin.dispatch dispatch_default;;
View
@@ -1,7 +1,7 @@
(* setup.ml generated for the first time by OASIS v0.3.0 *)
(* OASIS_START *)
-(* DO NOT EDIT (digest: fd12faa852fe3edb6cab0404d3d917eb) *)
+(* DO NOT EDIT (digest: 6250bb6899998910c3bfc46ffe502143) *)
(*
Regenerated by OASIS v0.3.0
Visit http://oasis.forge.ocamlcore.org for more information and
@@ -5641,6 +5641,16 @@ let setup_t =
flag_description = Some "build the Unix binary";
flag_default = [(OASISExpr.EBool true, false)];
});
+ Flag
+ ({
+ cs_name = "mirage";
+ cs_data = PropList.Data.create ();
+ cs_plugin_data = [];
+ },
+ {
+ flag_description = Some "build the mirage library";
+ flag_default = [(OASISExpr.EBool true, false)];
+ });
Library
({
cs_name = "pcap";
@@ -5677,6 +5687,46 @@ let setup_t =
lib_findlib_name = Some "pcap";
lib_findlib_containers = [];
});
+ Library
+ ({
+ cs_name = "mirage";
+ cs_data = PropList.Data.create ();
+ cs_plugin_data = [];
+ },
+ {
+ bs_build =
+ [
+ (OASISExpr.EBool true, false);
+ (OASISExpr.EFlag "mirage", true)
+ ];
+ bs_install = [(OASISExpr.EBool true, true)];
+ bs_path = "mirage";
+ bs_compiled_object = Best;
+ bs_build_depends =
+ [
+ FindlibPackage ("mirage-net", None);
+ InternalLibrary "pcap";
+ FindlibPackage ("lwt", None);
+ FindlibPackage ("lwt.syntax", None)
+ ];
+ bs_build_tools = [ExternalTool "ocamlbuild"];
+ bs_c_sources = [];
+ bs_data_files = [];
+ bs_ccopt = [(OASISExpr.EBool true, [])];
+ bs_cclib = [(OASISExpr.EBool true, [])];
+ bs_dlllib = [(OASISExpr.EBool true, [])];
+ bs_dllpath = [(OASISExpr.EBool true, [])];
+ bs_byteopt = [(OASISExpr.EBool true, [])];
+ bs_nativeopt = [(OASISExpr.EBool true, [])];
+ },
+ {
+ lib_modules = ["Pcap_mirage"; "Lwt_bounded_stream"];
+ lib_pack = false;
+ lib_internal_modules = [];
+ lib_findlib_parent = Some "pcap";
+ lib_findlib_name = Some "mirage";
+ lib_findlib_containers = [];
+ });
Executable
({
cs_name = "print";
@@ -5750,14 +5800,14 @@ let setup_t =
};
oasis_fn = Some "_oasis";
oasis_version = "0.3.0";
- oasis_digest = Some "\n\212\002:\030\185\174\135\134~\175d\187\018Q\222";
+ oasis_digest = Some "\205a\030\231S*\147vd\216j=\253i\224\202";
oasis_exec = None;
oasis_setup_args = [];
setup_update = false;
};;
let setup () = BaseSetup.setup setup_t;;
-# 5762 "setup.ml"
+# 5812 "setup.ml"
(* OASIS_STOP *)
let () = setup ();;

0 comments on commit 5aaa7c1

Please sign in to comment.