Skip to content

Commit

Permalink
Merge pull request #513 from arekm/master
Browse files Browse the repository at this point in the history
Handle EHOSTDOWN and refine error handling better granularity
  • Loading branch information
rewolff authored Aug 21, 2024
2 parents 49662a9 + 95d5f8b commit aad45da
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
10 changes: 7 additions & 3 deletions man/mtr-packet.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion packet/probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 4 additions & 2 deletions packet/probe_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions ui/cmdpipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 8 additions & 9 deletions ui/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit aad45da

Please sign in to comment.