Skip to content

Commit aad45da

Browse files
authored
Merge pull request #513 from arekm/master
Handle EHOSTDOWN and refine error handling better granularity
2 parents 49662a9 + 95d5f8b commit aad45da

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

man/mtr-packet.8.in

+7-3
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,18 @@ label, and so on. The values are provided in this order:
317317
.IR ttl .
318318
.HP 7
319319
.TP
320-
.B no-route
321-
There was no route to the host used in a
320+
.B no-route-network
321+
.B no-route-host
322+
There was no route to the network or the host itself for the
322323
.B send-probe
323-
request.
324+
request used to reach the host.
324325
.TP
325326
.B network-down
326327
A probe could not be sent because the network is down.
327328
.TP
329+
.B host-down
330+
A probe could not be sent because the host is down.
331+
.TP
328332
.B probes-exhausted
329333
A probe could not be sent because there are already too many unresolved
330334
probes in flight.

packet/probe.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ void respond_to_probe(
264264
if (icmp_type == ICMP_TIME_EXCEEDED) {
265265
result = "ttl-expired";
266266
} else if (icmp_type == ICMP_DEST_UNREACH) {
267-
result = "no-route";
267+
/* XXX icmphdr->code is not known here, so assume that host is unreachable */
268+
result = "no-route-host";
268269
} else {
269270
assert(icmp_type == ICMP_ECHOREPLY);
270271
result = "reply";

packet/probe_unix.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,12 @@ void report_packet_error(
534534
printf("%d invalid-argument\n", command_token);
535535
} else if (errno == ENETDOWN) {
536536
printf("%d network-down\n", command_token);
537+
} else if (errno == EHOSTDOWN) {
538+
printf("%d host-down\n", command_token);
537539
} else if (errno == ENETUNREACH) {
538-
printf("%d no-route\n", command_token);
540+
printf("%d no-route-network\n", command_token);
539541
} else if (errno == EHOSTUNREACH) {
540-
printf("%d no-route\n", command_token);
542+
printf("%d no-route-host\n", command_token);
541543
} else if (errno == EPERM) {
542544
printf("%d permission-denied\n", command_token);
543545
} else if (errno == EADDRINUSE) {

ui/cmdpipe.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -715,10 +715,14 @@ void handle_command_reply(
715715
if (!strcmp(reply_name, "reply")
716716
|| !strcmp(reply_name, "ttl-expired")) {
717717
err = 0;
718-
} else if (!strcmp(reply_name, "no-route")) {
719-
err = ENETUNREACH;
720718
} else if (!strcmp(reply_name, "network-down")) {
721719
err = ENETDOWN;
720+
} else if (!strcmp(reply_name, "host-down")) {
721+
err = EHOSTDOWN;
722+
} else if (!strcmp(reply_name, "no-route-network")) {
723+
err = ENETUNREACH;
724+
} else if (!strcmp(reply_name, "no-route-host")) {
725+
err = EHOSTUNREACH;
722726
} else {
723727
/* If the reply type is unknown, ignore it */
724728
return;

ui/display.c

+8-9
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,16 @@ void display_clear(
266266
char *host_error_to_string(
267267
int err)
268268
{
269-
if (err == ENETUNREACH) {
269+
if (err == ENETDOWN)
270+
return "network is down";
271+
else if (err == EHOSTDOWN)
272+
return "host is down";
273+
else if (err == ENETUNREACH)
274+
return "no route to network";
275+
else if (err == EHOSTUNREACH)
270276
return "no route to host";
271-
}
272-
273-
if (err == ENETDOWN) {
274-
return "network down";
275-
}
276-
277-
if (err == 0) {
277+
else if (err == 0)
278278
return "waiting for reply";
279-
}
280279

281280
return strerror(err);
282281
}

0 commit comments

Comments
 (0)