commit 726548d572a41307b43e1288ed24f82b51350c1d from: Stefan Sperling date: Fri Nov 01 13:49:37 2024 UTC Hide informative output of flush routes/arp behind a verbose flag Suggested by Tom commit - 6ee01971ba6608ecc75f4604494d732471fe2c77 commit + 726548d572a41307b43e1288ed24f82b51350c1d blob - 323d14763a6873206162aeb3cc27a2a996d719f3 blob + 1977c63808962ebce1ad375adb0b3c52da224000 --- commands.c +++ commands.c @@ -1046,9 +1046,17 @@ sysctlhelp(int unused1, char **unused2, ...) * Data structures and routines for the "flush" command. */ +struct ghs flushtab[] = { + { "", "Type Enter to run command", CMPL0 NULL, 0 }, + { "verbose", "Show verbose diagnostics", CMPL0 NULL, 0 }, + { NULL, NULL, NULL, NULL, 0 } +}; + Menu flushlist[] = { - { "routes", "IP routes", CMPL0 0, 0, 0, 0, flush_ip_routes }, - { "arp", "ARP cache", CMPL0 0, 0, 0, 0, flush_arp_cache }, + { "routes", "IP routes", CMPL(h) (char **)flushtab, + sizeof(struct ghs), 0, 1, flush_ip_routes }, + { "arp", "ARP cache", CMPL(h) (char **)flushtab, + sizeof(struct ghs), 0, 1, flush_arp_cache }, { "ndp", "NDP cache", CMPL0 0, 0, 0, 0, flush_ndp_cache }, { "line", "Active user", CMPL0 0, 0, 1, 1, flush_line }, { "bridge-dyn", "Dynamically learned bridge addresses", CMPL0 0, 0, 1, 1, flush_bridgedyn }, @@ -3457,15 +3465,29 @@ powerdown(int argc, char **argv, ...) static int flush_ip_routes(int argc, char **argv, ...) { - flushroutes(AF_INET, AF_INET); + va_list ap; + char *verbose_arg; + + va_start(ap, argv); + verbose_arg = va_arg(ap, char *); + va_end(ap); + flushroutes(AF_INET, AF_INET, verbose_arg != NULL); + return(0); } static int flush_arp_cache(int argc, char **argv, ...) { - flushroutes(AF_INET, AF_LINK); + va_list ap; + char *verbose_arg; + + va_start(ap, argv); + verbose_arg = va_arg(ap, char *); + va_end(ap); + + flushroutes(AF_INET, AF_INET, verbose_arg != NULL); return(0); } blob - c5a8966d0b3506a015dd105fb55b3044ddbe1d10 blob + aa5c777725bcff637d09e989a07d3fe6bfb3c51f --- externs.h +++ externs.h @@ -146,7 +146,7 @@ struct rtdump *getrtdump(int, int, int); void freertdump(struct rtdump *); int monitor(int, char **, ...); int rtmsg(int, int, int, int, int); -void flushroutes(int, int); +void flushroutes(int, int, int); void bprintf(FILE *, int, u_char *); #ifdef _NET_IF_DL_H_ char *mylink_ntoa(const struct sockaddr_dl *); blob - 98febbd027c112d6992682db6bc022d91f222334 blob + c00c9bda0ced41a4cf7372e81357d2e33ad273a7 --- kroute.c +++ kroute.c @@ -69,7 +69,6 @@ u_long rtm_inits; char *mylink_ntoa(const struct sockaddr_dl *); -void flushroutes(int, int); void print_rtmsg(struct rt_msghdr *); void print_getmsg(struct rt_msghdr *, int); void pmsg_common(struct rt_msghdr *); @@ -147,7 +146,7 @@ freertdump(struct rtdump *rtdump) * sockaddrs match requested address families */ void -flushroutes(int af, int af2) +flushroutes(int af, int af2, int flush_verbose) { int rlen, seqno, s; char *next; @@ -203,12 +202,13 @@ flushroutes(int af, int af2) 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); - + if (flush_verbose) { + printf("%% No such route to delete:"); + print_addrs((char *)rtm + + rtm->rtm_hdrlen, rtm->rtm_addrs); + putchar('\n'); + fflush(stdout); + } seqno++; continue; } @@ -220,7 +220,7 @@ flushroutes(int af, int af2) if (verbose) { printf("\n%% Wrote message:\n"); print_rtmsg(rtm); - } else { + } else if (flush_verbose) { printf("%% %-20.20s ", routename(sa)); printf("%-20.20s flushed\n", routename(sa2)); } @@ -229,6 +229,9 @@ flushroutes(int af, int af2) printf("\n"); if (!seqno) printf("%% No entires found to flush\n"); + else + printf("%% %d routing table entr%s flushed\n", seqno, + seqno == 1 ? "y" : "ies"); freertdump(rtdump); close(s); return; blob - 9a7ff7a37a3389046cca788ad7e2fe1d714f16dc blob + 71bd08fc0636cebbeda9302565037432bc6fc429 --- nsh.8 +++ nsh.8 @@ -3695,14 +3695,20 @@ nsh(p)/flush ? .Ed .Pp .Tg route -.Ic flush routes +.Ic flush routes Oo Ic verbose Oc .Pp Clear the system routing table. +If the +.Ic verbose +flag is used then show which routes were deleted. .Pp .Tg arp -.Ic flush arp +.Ic flush arp Oo Ic verbose Oc .Pp Clear the system arp cache and static arp table. +If the +.Ic verbose +flag is used then show which ARP entries were deleted. .Pp .Tg ndp .Ic flush ndp