From 123e243bb69eac9fb43470bb6cadf44c073912c4 Mon Sep 17 00:00:00 2001 From: Mindy Preston Date: Sat, 12 Mar 2016 11:39:15 +0000 Subject: [PATCH 1/4] improve error messages when no route can be found for a packet Signed-off-by: Mindy Preston --- lib/ipv4.ml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ipv4.ml b/lib/ipv4.ml index 429b61bf9..584698d76 100644 --- a/lib/ipv4.ml +++ b/lib/ipv4.ml @@ -78,16 +78,19 @@ module Make(Ethif: V1_LWT.ETHIF) (Arpv4 : V1_LWT.ARP) = struct |ip when Ipaddr.V4.is_multicast ip -> Lwt.return (mac_of_multicast ip) |ip -> begin (* Gateway *) + let out = Ipaddr.V4.to_string in match t.gateways with |hd::_ -> Arpv4.query t.arp hd >>= begin function | `Ok mac -> Lwt.return mac | `Timeout -> - printf "IP.output: arp timeout to gw %s\n%!" (Ipaddr.V4.to_string ip); + printf "IP.output: could not send to %s: failed to contact gateway %s\n%!" + (out ip) (out hd) ; Lwt.fail (No_route_to_destination_address ip) end |[] -> - printf "IP.output: no route to %s\n%!" (Ipaddr.V4.to_string ip); + printf "IP.output: no route to %s (no default gateway is configured)\n%!" + (out ip); Lwt.fail (No_route_to_destination_address ip) end end From 2663a0381171cb8ee4ddf19368c2549334bb964a Mon Sep 17 00:00:00 2001 From: Mindy Preston Date: Sat, 12 Mar 2016 11:40:02 +0000 Subject: [PATCH 2/4] slightly refactor error reporting for icmp Signed-off-by: Mindy Preston --- lib/ipv4.ml | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/lib/ipv4.ml b/lib/ipv4.ml index 584698d76..d055a410a 100644 --- a/lib/ipv4.ml +++ b/lib/ipv4.ml @@ -136,35 +136,33 @@ module Make(Ethif: V1_LWT.ETHIF) (Arpv4 : V1_LWT.ARP) = struct writev t frame [buf] let icmp_dst_unreachable buf = - let descr = - match Wire_structs.Ipv4_wire.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; - Lwt.return_unit + sprintf "ICMP Destination Unreachable: %s\n%!" @@ + match Wire_structs.Ipv4_wire.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 ICMP code: %d" code let icmp_input t src _hdr buf = MProf.Trace.label "icmp_input"; match Wire_structs.Ipv4_wire.get_icmpv4_ty buf with |0 -> (* echo reply *) - printf "ICMP: discarding echo reply\n%!"; + printf "ICMP: discarding echo reply from %s\n%!" (Ipaddr.V4.to_string src); Lwt.return_unit - |3 -> icmp_dst_unreachable buf + |3 -> printf "icmp_dst_unreachable buf"; Lwt.return_unit |8 -> (* echo request *) (* convert the echo request into an echo reply *) let csum = From a8eba64f04636b7e3fdf82f61f38759140de688f Mon Sep 17 00:00:00 2001 From: Mindy Preston Date: Sat, 12 Mar 2016 11:40:52 +0000 Subject: [PATCH 3/4] include more information in icmp error output --- lib/ipv4.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ipv4.ml b/lib/ipv4.ml index d055a410a..b447d8829 100644 --- a/lib/ipv4.ml +++ b/lib/ipv4.ml @@ -176,7 +176,7 @@ module Make(Ethif: V1_LWT.ETHIF) (Arpv4 : V1_LWT.ARP) = struct let frame = Cstruct.set_len frame header_len in write t frame buf |ty -> - printf "ICMP unknown ty %d\n" ty; + printf "ICMP unknown ty %d from %s\n" ty (Ipaddr.V4.to_string src); Lwt.return_unit let input t ~tcp ~udp ~default buf = From f273b086c3a69a5b51b62ebba89c565aaffc1e93 Mon Sep 17 00:00:00 2001 From: Mindy Preston Date: Sat, 12 Mar 2016 21:10:43 +0000 Subject: [PATCH 4/4] correct thinko for icmp error messages --- lib/ipv4.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ipv4.ml b/lib/ipv4.ml index b447d8829..5a76cfb2d 100644 --- a/lib/ipv4.ml +++ b/lib/ipv4.ml @@ -162,7 +162,7 @@ module Make(Ethif: V1_LWT.ETHIF) (Arpv4 : V1_LWT.ARP) = struct |0 -> (* echo reply *) printf "ICMP: discarding echo reply from %s\n%!" (Ipaddr.V4.to_string src); Lwt.return_unit - |3 -> printf "icmp_dst_unreachable buf"; Lwt.return_unit + |3 -> printf "%s\n%!" (icmp_dst_unreachable buf); Lwt.return_unit |8 -> (* echo request *) (* convert the echo request into an echo reply *) let csum =