Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Release 1.1.6 #61

Merged
merged 7 commits into from
This page is out of date. Refresh to see the latest.
View
8 .travis-ci.sh
@@ -1,6 +1,3 @@
-# OPAM packages needed to build tests.
-OPAM_PACKAGES="cstruct mirage-types mirage-unix mirage-console-unix mirage-clock-unix mirage-net-unix ipaddr"
-
case "$OCAML_VERSION,$OPAM_VERSION" in
3.12.1,1.0.0) ppa=avsm/ocaml312+opam10 ;;
3.12.1,1.1.0) ppa=avsm/ocaml312+opam11 ;;
@@ -23,7 +20,8 @@ opam --version
opam --git-version
opam init
-opam install ${OPAM_PACKAGES}
eval `opam config env`
-make
+opam pin tcpip .
+opam install tcpip
+opam install mirage-www
View
5 CHANGES
@@ -1,5 +1,8 @@
-1.1.6 (trunk):
+1.1.6 (20-July-2014):
* Quieten down the stack logging rate by not announcing IPv6 packet discards.
+* Raise exception `Bad_option` for unparseable or invalid TCPv4 options (#57).
+* Fix linking error with module `Tcp_checksum` by lifting it into top library (#60).
+* Add `opam` file to permit easier local pinning, and fix Travis to use this.
1.1.5 (18-June-2014):
* Ensure that DHCP completes before the application is started, so that
View
20 opam
@@ -0,0 +1,20 @@
+opam-version: "1"
+maintainer: "anil@recoil.org"
+build: [
+ [make]
+ [make "install"]
+]
+remove: [
+ ["ocamlfind" "remove" "tcpip"]
+]
+depends: [
+ "ocamlfind"
+ "cstruct" {>= "1.0.1"}
+ "mirage-types" {>= "1.1.2"}
+ "mirage-unix" {>= "1.1.0"}
+ "mirage-console-unix"
+ "mirage-clock-unix" {>= "1.0.0"}
+ "mirage-net-unix" {>= "1.1.0"}
+ "ipaddr" {>= "2.2.0"}
+]
+ocaml-version: [>= "4.00.0"]
View
62 tcp/options.ml
@@ -16,6 +16,8 @@
(* TCP options parsing *)
+exception Bad_option of string
+
type t =
|Noop
|MSS of int (* RFC793 *)
@@ -27,32 +29,60 @@ type t =
type ts = t list
-let unmarshal buf =
+let report_error n =
+ let error = Printf.sprintf "Invalid option %d presented" n in
+ raise (Bad_option error)
+
+let check_mss buf =
+ let min_mss_size = 88 in
+ let mss_size = Cstruct.BE.get_uint16 buf 2 in
+ if mss_size < min_mss_size then
+ let err = (Printf.sprintf "Invalid MSS %d received" mss_size) in
+ raise (Bad_option err)
+ else
+ MSS mss_size
+
+let unmarshal buf =
let open Cstruct in
let i = iter
(fun buf ->
match get_uint8 buf 0 with
|0 -> None (* EOF *)
|1 -> Some 1 (* NOP *)
- |n -> Some (get_uint8 buf 1)
+ |n ->
+ try Some (get_uint8 buf 1)
+ with Invalid_argument _ -> report_error n
)
(fun buf ->
- match get_uint8 buf 0 with
+ let option_number = (get_uint8 buf 0) in
+ match option_number with
|0 -> assert false
|1 -> Noop
- |2 -> MSS (BE.get_uint16 buf 2)
- |3 -> Window_size_shift (get_uint8 buf 2)
- |4 -> SACK_ok
- |5 ->
- let num = ((get_uint8 buf 1) - 2) / 8 in
- let rec to_int32_list off acc = function
- |0 -> acc
- |n ->
- let x = (BE.get_uint32 buf off), (BE.get_uint32 buf (off+4)) in
- to_int32_list (off+8) (x::acc) (n-1)
- in SACK (to_int32_list 2 [] num)
- |8 -> Timestamp ((BE.get_uint32 buf 2), (BE.get_uint32 buf 6))
- |n -> Unknown (n, (copy buf 2 (len buf - 2)))
+ |_ ->
+ let option_length = (get_uint8 buf 1) in
+ try
+ match option_number, option_length with
+ (* error out for lengths that are always nonsensible when option
+ * number >1 *)
+ | _, 0 | _, 1 -> report_error option_number
+ | 2, 4 -> check_mss buf
+ | 3, 3 -> Window_size_shift (get_uint8 buf 2)
+ | 4, 2 -> SACK_ok
+ | 5, _ ->
+ let num = (option_length - 2) / 8 in
+ let rec to_int32_list off acc = function
+ |0 -> acc
+ |n ->
+ let x = (BE.get_uint32 buf off), (BE.get_uint32 buf (off+4)) in
+ to_int32_list (off+8) (x::acc) (n-1)
+ in SACK (to_int32_list 2 [] num)
+ | 8, 10 -> Timestamp ((BE.get_uint32 buf 2), (BE.get_uint32 buf 6))
+ (* error out for lengths that don't match the spec's fixed length
+ * for a given, recognized option number *)
+ | 2, _ | 3, _ | 4, _ | 8, _ -> report_error option_number
+ (* Parse apparently well-formed but unrecognized options *)
+ | n, _ -> Unknown (n, (copy buf 2 (len buf - 2)))
+ with Invalid_argument _ -> report_error option_number
) buf in
fold (fun a b -> b :: a) i []
View
2  tcp/options.mli
@@ -14,6 +14,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)
+exception Bad_option of string
+
type t =
|Noop
|MSS of int (* RFC793 *)
Something went wrong with that request. Please try again.