Skip to content

Commit

Permalink
Merge pull request #10 from yomimono/irminify
Browse files Browse the repository at this point in the history
Irminify
  • Loading branch information
yomimono committed Aug 10, 2015
2 parents 1198b48 + 6367642 commit c99e75f
Show file tree
Hide file tree
Showing 19 changed files with 852 additions and 378 deletions.
4 changes: 4 additions & 0 deletions .merlin
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ PKG mirage-types
PKG tcpip
PKG ipaddr
PKG oUnit
PKG irmin-network-datastores
PKG sexplib
PKG type_conv
PKG sexplib.syntax
S lib
S lib_test
B _build/lib
Expand Down
29 changes: 22 additions & 7 deletions _oasis
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
OASISFormat: 0.4
Name: mirage-nat
Version: 0.3.0
Version: 0.5.0
Synopsis: an embryonic NAT module
Authors: Mindy Preston (meetup@yomimono.org)
License: ISC
Expand All @@ -15,36 +15,51 @@ Flag randomized

Library "mirage-nat"
Path: lib
Modules: Nat_lookup, Nat_rewrite, Nat_translations
InternalModules: Nat_decompose, Nat_shims
BuildDepends: ipaddr, tcpip, cstruct
Modules: Nat_lookup, Nat_rewrite, Nat_translations, Nat_decompose
InternalModules: Nat_shims, Nat_table
BuildDepends: ipaddr, tcpip, cstruct, sexplib, sexplib.syntax, tc, irmin-network-datastores, irmin, irmin.mem, lwt, git

Executable randomized_tests
Build$: flag(randomized) && flag(tests)
Path: lib_test
MainIs: test_randomized.ml
ByteOpt: -g
BuildDepends: oUnit, quickcheck, mirage-nat, arbitrary-network
BuildDepends: oUnit, alcotest, quickcheck, mirage-nat, arbitrary-network

Test randomized_tests
Run$: flag(randomized) && flag(tests)
Command: $randomized_tests

Executable test_decompose
Build$: flag(tests)
Install: false
Path: lib_test
Custom: true
MainIs: test_decompose.ml
ByteOpt: -g
BuildDepends: oUnit, alcotest, mirage-nat, tcpip

Executable test_lookup
Build$: flag(tests)
Install: false
Path: lib_test
Custom: true
MainIs: test_lookup.ml
ByteOpt: -g
BuildDepends: oUnit, mirage-nat
BuildDepends: oUnit, alcotest, mirage-nat, lwt.unix

Executable test_rewrite
Build$: flag(tests)
Install: false
Path: lib_test
Custom: true
MainIs: test_rewrite.ml
ByteOpt: -g
BuildDepends: oUnit, tcpip, mirage-nat
BuildDepends: oUnit, tcpip, alcotest, mirage-nat, lwt.unix

Test test_decompose
Run$: flag(tests)
Command: $test_decompose

Test test_lookup
Run$: flag(tests)
Expand Down
69 changes: 68 additions & 1 deletion _tags
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# OASIS_START
# DO NOT EDIT (digest: 50504a8cc575b0a7edc720cddbe311b0)
# DO NOT EDIT (digest: 820564c6bf23ced60e2c72fb5d562d7c)
# 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
Expand All @@ -17,39 +17,106 @@ true: annot, bin_annot
# Library mirage-nat
"lib/mirage-nat.cmxs": use_mirage-nat
<lib/*.ml{,i,y}>: pkg_cstruct
<lib/*.ml{,i,y}>: pkg_git
<lib/*.ml{,i,y}>: pkg_ipaddr
<lib/*.ml{,i,y}>: pkg_irmin
<lib/*.ml{,i,y}>: pkg_irmin-network-datastores
<lib/*.ml{,i,y}>: pkg_irmin.mem
<lib/*.ml{,i,y}>: pkg_lwt
<lib/*.ml{,i,y}>: pkg_sexplib
<lib/*.ml{,i,y}>: pkg_sexplib.syntax
<lib/*.ml{,i,y}>: pkg_tc
<lib/*.ml{,i,y}>: pkg_tcpip
# Executable randomized_tests
"lib_test/test_randomized.byte": oasis_executable_randomized_tests_byte
<lib_test/*.ml{,i,y}>: oasis_executable_randomized_tests_byte
"lib_test/test_randomized.byte": pkg_alcotest
"lib_test/test_randomized.byte": pkg_arbitrary-network
"lib_test/test_randomized.byte": pkg_cstruct
"lib_test/test_randomized.byte": pkg_git
"lib_test/test_randomized.byte": pkg_ipaddr
"lib_test/test_randomized.byte": pkg_irmin
"lib_test/test_randomized.byte": pkg_irmin-network-datastores
"lib_test/test_randomized.byte": pkg_irmin.mem
"lib_test/test_randomized.byte": pkg_lwt
"lib_test/test_randomized.byte": pkg_oUnit
"lib_test/test_randomized.byte": pkg_quickcheck
"lib_test/test_randomized.byte": pkg_sexplib
"lib_test/test_randomized.byte": pkg_sexplib.syntax
"lib_test/test_randomized.byte": pkg_tc
"lib_test/test_randomized.byte": pkg_tcpip
"lib_test/test_randomized.byte": use_mirage-nat
<lib_test/*.ml{,i,y}>: pkg_arbitrary-network
<lib_test/*.ml{,i,y}>: pkg_quickcheck
# Executable test_decompose
"lib_test/test_decompose.byte": oasis_executable_test_decompose_byte
<lib_test/*.ml{,i,y}>: oasis_executable_test_decompose_byte
"lib_test/test_decompose.byte": pkg_alcotest
"lib_test/test_decompose.byte": pkg_cstruct
"lib_test/test_decompose.byte": pkg_git
"lib_test/test_decompose.byte": pkg_ipaddr
"lib_test/test_decompose.byte": pkg_irmin
"lib_test/test_decompose.byte": pkg_irmin-network-datastores
"lib_test/test_decompose.byte": pkg_irmin.mem
"lib_test/test_decompose.byte": pkg_lwt
"lib_test/test_decompose.byte": pkg_oUnit
"lib_test/test_decompose.byte": pkg_sexplib
"lib_test/test_decompose.byte": pkg_sexplib.syntax
"lib_test/test_decompose.byte": pkg_tc
"lib_test/test_decompose.byte": pkg_tcpip
"lib_test/test_decompose.byte": use_mirage-nat
"lib_test/test_decompose.byte": custom
# Executable test_lookup
"lib_test/test_lookup.byte": oasis_executable_test_lookup_byte
<lib_test/*.ml{,i,y}>: oasis_executable_test_lookup_byte
"lib_test/test_lookup.byte": pkg_alcotest
"lib_test/test_lookup.byte": pkg_cstruct
"lib_test/test_lookup.byte": pkg_git
"lib_test/test_lookup.byte": pkg_ipaddr
"lib_test/test_lookup.byte": pkg_irmin
"lib_test/test_lookup.byte": pkg_irmin-network-datastores
"lib_test/test_lookup.byte": pkg_irmin.mem
"lib_test/test_lookup.byte": pkg_lwt
"lib_test/test_lookup.byte": pkg_lwt.unix
"lib_test/test_lookup.byte": pkg_oUnit
"lib_test/test_lookup.byte": pkg_sexplib
"lib_test/test_lookup.byte": pkg_sexplib.syntax
"lib_test/test_lookup.byte": pkg_tc
"lib_test/test_lookup.byte": pkg_tcpip
"lib_test/test_lookup.byte": use_mirage-nat
"lib_test/test_lookup.byte": custom
# Executable test_rewrite
"lib_test/test_rewrite.byte": oasis_executable_test_rewrite_byte
<lib_test/*.ml{,i,y}>: oasis_executable_test_rewrite_byte
"lib_test/test_rewrite.byte": pkg_alcotest
"lib_test/test_rewrite.byte": pkg_cstruct
"lib_test/test_rewrite.byte": pkg_git
"lib_test/test_rewrite.byte": pkg_ipaddr
"lib_test/test_rewrite.byte": pkg_irmin
"lib_test/test_rewrite.byte": pkg_irmin-network-datastores
"lib_test/test_rewrite.byte": pkg_irmin.mem
"lib_test/test_rewrite.byte": pkg_lwt
"lib_test/test_rewrite.byte": pkg_lwt.unix
"lib_test/test_rewrite.byte": pkg_oUnit
"lib_test/test_rewrite.byte": pkg_sexplib
"lib_test/test_rewrite.byte": pkg_sexplib.syntax
"lib_test/test_rewrite.byte": pkg_tc
"lib_test/test_rewrite.byte": pkg_tcpip
"lib_test/test_rewrite.byte": use_mirage-nat
<lib_test/*.ml{,i,y}>: pkg_alcotest
<lib_test/*.ml{,i,y}>: pkg_cstruct
<lib_test/*.ml{,i,y}>: pkg_git
<lib_test/*.ml{,i,y}>: pkg_ipaddr
<lib_test/*.ml{,i,y}>: pkg_irmin
<lib_test/*.ml{,i,y}>: pkg_irmin-network-datastores
<lib_test/*.ml{,i,y}>: pkg_irmin.mem
<lib_test/*.ml{,i,y}>: pkg_lwt
<lib_test/*.ml{,i,y}>: pkg_lwt.unix
<lib_test/*.ml{,i,y}>: pkg_oUnit
<lib_test/*.ml{,i,y}>: pkg_sexplib
<lib_test/*.ml{,i,y}>: pkg_sexplib.syntax
<lib_test/*.ml{,i,y}>: pkg_tc
<lib_test/*.ml{,i,y}>: pkg_tcpip
<lib_test/*.ml{,i,y}>: use_mirage-nat
"lib_test/test_rewrite.byte": custom
# OASIS_STOP
7 changes: 4 additions & 3 deletions lib/META
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# OASIS_START
# DO NOT EDIT (digest: cd99d3673a291a9b290fd5f61d9993c2)
version = "0.2.4"
# DO NOT EDIT (digest: 8e4d1b6cdfc1d810351b4567f125a9c6)
version = "0.4.0"
description = "an embryonic NAT module"
requires = "ipaddr tcpip cstruct"
requires =
"ipaddr tcpip cstruct sexplib sexplib.syntax tc irmin-network-datastores irmin irmin.mem lwt git"
archive(byte) = "mirage-nat.cma"
archive(byte, plugin) = "mirage-nat.cma"
archive(native) = "mirage-nat.cmxa"
Expand Down
3 changes: 2 additions & 1 deletion lib/mirage-nat.mldylib
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# OASIS_START
# DO NOT EDIT (digest: c452be258f77fbe9bd56b7a4881b1954)
# DO NOT EDIT (digest: a6693be375f0205415e3565338d736df)
Nat_lookup
Nat_rewrite
Nat_translations
Nat_decompose
Nat_shims
Nat_table
# OASIS_STOP
3 changes: 2 additions & 1 deletion lib/mirage-nat.mllib
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# OASIS_START
# DO NOT EDIT (digest: c452be258f77fbe9bd56b7a4881b1954)
# DO NOT EDIT (digest: a6693be375f0205415e3565338d736df)
Nat_lookup
Nat_rewrite
Nat_translations
Nat_decompose
Nat_shims
Nat_table
# OASIS_STOP
4 changes: 3 additions & 1 deletion lib/nat_decompose.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let addresses_of_ip ip_packet =
| 6 -> (* ipv6 *)
(Ipaddr.V6 (V6.of_cstruct_exn (Wire_structs.Ipv6_wire.get_ipv6_src ip_packet)),
Ipaddr.V6 (V6.of_cstruct_exn (Wire_structs.Ipv6_wire.get_ipv6_dst ip_packet)))
| _ -> failwith "invalid ip type in packet"

let retrieve_ports tx_layer =
(* Cstruct.uint16, Cstruct.uint16 *)
Expand All @@ -45,6 +46,7 @@ let proto_of_ip ip_layer =
match ((hlen_version land 0xf0) lsr 4) with
| 4 -> Wire_structs.Ipv4_wire.get_ipv4_proto ip_layer
| 6 -> Wire_structs.Ipv6_wire.get_ipv6_nhdr ip_layer
| _ -> failwith "invalid ip type in packet"

let ip_header_length hlen_version =
match ((hlen_version land 0xf0) lsr 4) with
Expand Down Expand Up @@ -76,7 +78,7 @@ let payload_of_transport proto tx =
match proto with
| 6 ->
if (Cstruct.len tx < Wire_structs.Tcp_wire.sizeof_tcp) then None else begin
let word_offset = Wire_structs.Tcp_wire.get_tcp_dataoff tx in
let word_offset = (Wire_structs.Tcp_wire.get_tcp_dataoff tx) lsr 4 in
let byte_offset = word_offset * 4 in
if (Cstruct.len tx < byte_offset) then None
else Some (Cstruct.shift tx byte_offset)
Expand Down
Loading

0 comments on commit c99e75f

Please sign in to comment.