Skip to content

Commit

Permalink
Merge pull request #98 from talex5/flow_errors
Browse files Browse the repository at this point in the history
Added 'error_message' functions
  • Loading branch information
talex5 committed Feb 3, 2015
2 parents e60c946 + 6779a3a commit 4abb290
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/ipv4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,35 @@ module Make(Ethif : V1_LWT.ETHIF) = struct
let write t frame buf =
writev t frame [buf]

let icmp_dst_unreachable buf =
let descr =
match Wire_structs.get_icmpv4_code buf with
| 0 -> "Destination network unreachable"
| 1 -> "Destination host unreachable"
| 2 -> "Destination protocol unreachable"
| 3 -> "Destination port unreachable"
| 4 -> "Fragmentation required, and DF flag set"
| 5 -> "Source route failed"
| 6 -> "Destination network unknown"
| 7 -> "Destination host unknown"
| 8 -> "Source host isolated"
| 9 -> "Network administratively prohibited"
| 10 -> "Host administratively prohibited"
| 11 -> "Network unreachable for TOS"
| 12 -> "Host unreachable for TOS"
| 13 -> "Communication administratively prohibited"
| 14 -> "Host Precedence Violation"
| 15 -> "Precedence cutoff in effect"
| code -> Printf.sprintf "Unknown code: %d" code in
printf "ICMP Destination Unreachable: %s\n%!" descr;
return ()

let icmp_input t src _hdr buf =
MProf.Trace.label "icmp_input";
match Wire_structs.get_icmpv4_ty buf with
|0 -> (* echo reply *)
return (printf "ICMP: discarding echo reply\n%!")
|3 -> icmp_dst_unreachable buf
|8 -> (* echo request *)
(* convert the echo request into an echo reply *)
let csum =
Expand Down
5 changes: 5 additions & 0 deletions tcp/flow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ module Make(IP:V1_LWT.IP)(TM:V1_LWT.TIME)(C:V1.CLOCK)(R:V1.RANDOM) = struct
| `Refused
]

let error_message = function
| `Unknown msg -> msg
| `Timeout -> "Timeout while attempting to connect"
| `Refused -> "Connection refused"

let id t = Pcb.ip t

let get_dest t = Pcb.get_dest t
Expand Down
5 changes: 5 additions & 0 deletions unix/tcpv4_socket.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ type error = [
| `Refused
]

let error_message = function
| `Unknown msg -> msg
| `Timeout -> "Timeout while attempting to connect"
| `Refused -> "Connection refused"

let connect id =
let t =
match id with
Expand Down
5 changes: 5 additions & 0 deletions unix/tcpv6_socket.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ type error = [
| `Refused
]

let error_message = function
| `Unknown msg -> msg
| `Timeout -> "Timeout while attempting to connect"
| `Refused -> "Connection refused"

let connect id =
let t =
match id with
Expand Down

0 comments on commit 4abb290

Please sign in to comment.