From 95d5f8b833b51ed5ae8f92c3e0a5ec3f08002f79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20Mi=C5=9Bkiewicz?= Date: Wed, 21 Aug 2024 09:42:14 +0200 Subject: [PATCH] Handle EHOSTDOWN and refine error handling better granularity --- man/mtr-packet.8.in | 10 +++++++--- packet/probe.c | 3 ++- packet/probe_unix.c | 6 ++++-- ui/cmdpipe.c | 8 ++++++-- ui/display.c | 17 ++++++++--------- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/man/mtr-packet.8.in b/man/mtr-packet.8.in index 090c3adb..120362c9 100644 --- a/man/mtr-packet.8.in +++ b/man/mtr-packet.8.in @@ -317,14 +317,18 @@ label, and so on. The values are provided in this order: .IR ttl . .HP 7 .TP -.B no-route -There was no route to the host used in a +.B no-route-network +.B no-route-host +There was no route to the network or the host itself for the .B send-probe -request. +request used to reach the host. .TP .B network-down A probe could not be sent because the network is down. .TP +.B host-down +A probe could not be sent because the host is down. +.TP .B probes-exhausted A probe could not be sent because there are already too many unresolved probes in flight. diff --git a/packet/probe.c b/packet/probe.c index 6581015d..4b265af4 100644 --- a/packet/probe.c +++ b/packet/probe.c @@ -264,7 +264,8 @@ void respond_to_probe( if (icmp_type == ICMP_TIME_EXCEEDED) { result = "ttl-expired"; } else if (icmp_type == ICMP_DEST_UNREACH) { - result = "no-route"; + /* XXX icmphdr->code is not known here, so assume that host is unreachable */ + result = "no-route-host"; } else { assert(icmp_type == ICMP_ECHOREPLY); result = "reply"; diff --git a/packet/probe_unix.c b/packet/probe_unix.c index 0c885a58..00ec7a25 100644 --- a/packet/probe_unix.c +++ b/packet/probe_unix.c @@ -534,10 +534,12 @@ void report_packet_error( printf("%d invalid-argument\n", command_token); } else if (errno == ENETDOWN) { printf("%d network-down\n", command_token); + } else if (errno == EHOSTDOWN) { + printf("%d host-down\n", command_token); } else if (errno == ENETUNREACH) { - printf("%d no-route\n", command_token); + printf("%d no-route-network\n", command_token); } else if (errno == EHOSTUNREACH) { - printf("%d no-route\n", command_token); + printf("%d no-route-host\n", command_token); } else if (errno == EPERM) { printf("%d permission-denied\n", command_token); } else if (errno == EADDRINUSE) { diff --git a/ui/cmdpipe.c b/ui/cmdpipe.c index 8017cc0f..81acb9c8 100644 --- a/ui/cmdpipe.c +++ b/ui/cmdpipe.c @@ -715,10 +715,14 @@ void handle_command_reply( if (!strcmp(reply_name, "reply") || !strcmp(reply_name, "ttl-expired")) { err = 0; - } else if (!strcmp(reply_name, "no-route")) { - err = ENETUNREACH; } else if (!strcmp(reply_name, "network-down")) { err = ENETDOWN; + } else if (!strcmp(reply_name, "host-down")) { + err = EHOSTDOWN; + } else if (!strcmp(reply_name, "no-route-network")) { + err = ENETUNREACH; + } else if (!strcmp(reply_name, "no-route-host")) { + err = EHOSTUNREACH; } else { /* If the reply type is unknown, ignore it */ return; diff --git a/ui/display.c b/ui/display.c index e457b59c..6761b190 100644 --- a/ui/display.c +++ b/ui/display.c @@ -266,17 +266,16 @@ void display_clear( char *host_error_to_string( int err) { - if (err == ENETUNREACH) { + if (err == ENETDOWN) + return "network is down"; + else if (err == EHOSTDOWN) + return "host is down"; + else if (err == ENETUNREACH) + return "no route to network"; + else if (err == EHOSTUNREACH) return "no route to host"; - } - - if (err == ENETDOWN) { - return "network down"; - } - - if (err == 0) { + else if (err == 0) return "waiting for reply"; - } return strerror(err); }