Skip to content

Commit

Permalink
fix error when flush arp/route run into deleted routing table entries
Browse files Browse the repository at this point in the history
It is possible to get "no such process" (ESRCH) errors during flush
arp or flush route commands due to concurrent deletion of routing
table entries by another process.

This is no reason to stop trying to delete more routes, so do not
abort the loop in this case.

Also, make nsh print a more informative error message in this case,
rather than "no such process". Example of the new error message:

% No such route to delete: 100.64.1.2 fe:e1:ba:d0:8e:45 255.255.255.255 fe:e1:bb:d1:c4:b8 100.64.1.3

Testing + OK Tom
  • Loading branch information
stspdotname committed Nov 1, 2024
1 parent d4510bc commit 6ee0197
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions kroute.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void print_rtmsg(struct rt_msghdr *);
void print_getmsg(struct rt_msghdr *, int);
void pmsg_common(struct rt_msghdr *);
void pmsg_addrs(char *, int);
void print_addrs(char *, int);
void bprintf(FILE *, int, u_char *);

/*
Expand Down Expand Up @@ -201,6 +202,16 @@ flushroutes(int af, int af2)
rtm->rtm_seq = seqno;
rlen = write(s, next, rtm->rtm_msglen);
if (rlen < (int)rtm->rtm_msglen) {
if (errno == ESRCH) {
printf("%% No such route to delete:");
print_addrs((char *)rtm + rtm->rtm_hdrlen,
rtm->rtm_addrs);
putchar('\n');
fflush(stdout);

seqno++;
continue;
}
printf("%% Unable to write to routing socket: %s\n",
strerror(errno));
break;
Expand Down Expand Up @@ -517,22 +528,31 @@ pmsg_common(struct rt_msghdr *rtm)
void
pmsg_addrs(char *cp, int addrs)
{
struct sockaddr *sa;
int i;

if (addrs == 0)
return;
(void) printf("%% sockaddrs: ");
bprintf(stdout, addrs, addrnames);
(void) putchar('\n');
print_addrs(cp, addrs);
(void) putchar('\n');
(void) fflush(stdout);
}

void
print_addrs(char *cp, int addrs)
{
struct sockaddr *sa;
int i;

if (addrs == 0)
return;

for (i = 1; i; i <<= 1)
if (i & addrs) {
sa = (struct sockaddr *)cp;
(void) printf(" %s", routename(sa));
ADVANCE(cp, sa);
}
(void) putchar('\n');
(void) fflush(stdout);
}

void
Expand Down

0 comments on commit 6ee0197

Please sign in to comment.