]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
Handle EHOSTDOWN and refine error handling better granularity 513/head
authorArkadiusz Miśkiewicz <arekm@maven.pl>
Wed, 21 Aug 2024 07:42:14 +0000 (09:42 +0200)
committerArkadiusz Miśkiewicz <arekm@maven.pl>
Wed, 21 Aug 2024 08:03:55 +0000 (10:03 +0200)
man/mtr-packet.8.in
packet/probe.c
packet/probe_unix.c
ui/cmdpipe.c
ui/display.c

index 090c3adb166410f325a43bd2fa4dc69a8e7ae4ea..120362c96454ae7314d1371c8dcb2a964b3b72ba 100644 (file)
@@ -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.
index 6581015df398054ab2d2c715821eeac075c74713..4b265af47cc82918feab22a5720d0e2b4875bc65 100644 (file)
@@ -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";
index 0c885a5844db2efc6e1defed094c4479d6d6ba1e..00ec7a25906b81bc586b9b7e56e2400543693daf 100644 (file)
@@ -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) {
index 8017cc0fc298104b486adce5d823fa69f270dea2..81acb9c8b68f2d580f16231e94ce492fa56788cc 100644 (file)
@@ -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;
index e457b59cf01136e4ac02eb876c7122cf36c8fdfc..6761b19072fa468dcb5d6bd5de87162deef0cfb1 100644 (file)
@@ -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);
 }