This is an updated submitted patch originally written by Jim Rees

and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.
This commit is contained in:
jrf 2003-07-19 01:36:47 +00:00
parent ec2c169839
commit ce22377a7e
5 changed files with 20 additions and 11 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: keywords.c,v 1.4 2001/01/27 04:51:25 itojun Exp $ */
/* $NetBSD: keywords.c,v 1.5 2003/07/19 01:36:47 jrf Exp $ */
/* WARNING! This file was generated by keywords.sh */
@ -54,6 +54,7 @@ struct keytab keywords[] = {
{"x25", K_X25},
{"xns", K_XNS},
{"xresolve", K_XRESOLVE},
{"flushall", K_FLUSHALL},
{0, 0}
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: keywords.h,v 1.6 2001/01/27 04:51:25 itojun Exp $ */
/* $NetBSD: keywords.h,v 1.7 2003/07/19 01:36:47 jrf Exp $ */
/* WARNING! This file was generated by keywords.sh */
@ -56,3 +56,4 @@ extern struct keytab {
#define K_X25 46
#define K_XNS 47
#define K_XRESOLVE 48
#define K_FLUSHALL 49

View File

@ -1,5 +1,5 @@
#!/bin/sh
# $NetBSD: keywords.sh,v 1.6 2001/01/27 04:51:17 itojun Exp $
# $NetBSD: keywords.sh,v 1.7 2003/07/19 01:36:47 jrf Exp $
# @(#)keywords 8.2 (Berkeley) 3/19/94
#
# WARNING! If you change this file, re-run it!
@ -56,6 +56,7 @@ static
x25
xns
xresolve
flushall
_EOF_

View File

@ -1,4 +1,4 @@
.\" $NetBSD: route.8,v 1.32 2003/06/03 04:41:42 itojun Exp $
.\" $NetBSD: route.8,v 1.33 2003/07/19 01:36:48 jrf Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -110,6 +110,8 @@ utility provides several commands:
Add a route.
.It Cm flush
Remove all routes.
.It Cm flushall
Remove all routes including the default gateway.
.It Cm delete
Delete a specific route.
.It Cm change

View File

@ -1,4 +1,4 @@
/* $NetBSD: route.c,v 1.66 2003/06/11 15:45:20 christos Exp $ */
/* $NetBSD: route.c,v 1.67 2003/07/19 01:36:47 jrf Exp $ */
/*
* Copyright (c) 1983, 1989, 1991, 1993
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1989, 1991, 1993\n\
#if 0
static char sccsid[] = "@(#)route.c 8.6 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: route.c,v 1.66 2003/06/11 15:45:20 christos Exp $");
__RCSID("$NetBSD: route.c,v 1.67 2003/07/19 01:36:47 jrf Exp $");
#endif
#endif /* not lint */
@ -90,7 +90,7 @@ static void inet_makenetandmask __P((u_int32_t, struct sockaddr_in *));
static int inet6_makenetandmask __P((struct sockaddr_in6 *));
#endif
static int getaddr __P((int, char *, struct hostent **));
static int flushroutes __P((int, char *[]));
static int flushroutes __P((int, char *[], int));
#ifndef SMALL
static int prefixlen __P((char *));
static int x25_makemask __P((void));
@ -218,7 +218,7 @@ main(argc, argv)
case K_ADD:
case K_DELETE:
if (doflush)
(void)flushroutes(1, argv);
(void)flushroutes(1, argv, 0);
return newroute(argc, argv);
case K_SHOW:
@ -232,8 +232,10 @@ main(argc, argv)
#endif /* SMALL */
case K_FLUSH:
return flushroutes(argc, argv);
return flushroutes(argc, argv, 0);
case K_FLUSHALL:
return flushroutes(argc, argv, 1);
no_cmd:
default:
usage(*argv);
@ -246,9 +248,10 @@ main(argc, argv)
* associated with network interfaces.
*/
static int
flushroutes(argc, argv)
flushroutes(argc, argv, doall)
int argc;
char *argv[];
int doall;
{
size_t needed;
int mib[6], rlen, seqno;
@ -317,7 +320,8 @@ bad: usage(*argv);
rtm = (struct rt_msghdr *)next;
if (verbose)
print_rtmsg(rtm, rtm->rtm_msglen);
if ((rtm->rtm_flags & RTF_GATEWAY) == 0)
if (!(rtm->rtm_flags & (RTF_GATEWAY | RTF_STATIC |
RTF_LLINFO)) && !doall)
continue;
if (af) {
struct sockaddr *sa = (struct sockaddr *)(rtm + 1);