commit f2e98605612da20b0aea1d6c1de978f2a1456c06 from: Stefan Sperling date: Thu Oct 31 18:05:52 2024 UTC fix error when flush arp/route run into deleted routing table entries 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 commit - 8c49d18a44147af1ab39ce950b96914db1bde50f commit + f2e98605612da20b0aea1d6c1de978f2a1456c06 blob - 00017bf8a8f2051af1d1393e820c5bfc9a69e7d3 blob + 98febbd027c112d6992682db6bc022d91f222334 --- kroute.c +++ kroute.c @@ -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 *); /* @@ -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; @@ -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