diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2009-05-30 19:50:29 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2009-05-30 19:50:29 +0000 |
commit | 40b9dd74e2c8558eba1354572add51fd6d999450 (patch) | |
tree | 4c5d9e43fde5ce3873f8aee9126771c9214d2705 | |
parent | 2d313f2f59f73c038f8e076d908028d249c1aa2f (diff) |
Make route flush more powerful by allowing -iface/-interface or -priority
to be specified. So only routes matching these conditions will be flushed.
This will help making dhclient less dumb when fiddeling with routes.
OK henning@
-rw-r--r-- | sbin/route/route.8 | 12 | ||||
-rw-r--r-- | sbin/route/route.c | 30 |
2 files changed, 35 insertions, 7 deletions
diff --git a/sbin/route/route.8 b/sbin/route/route.8 index 7c9aa20c3f8..8849c509cb2 100644 --- a/sbin/route/route.8 +++ b/sbin/route/route.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: route.8,v 1.56 2008/05/07 06:29:48 claudio Exp $ +.\" $OpenBSD: route.8,v 1.57 2009/05/30 19:50:28 claudio Exp $ .\" $NetBSD: route.8,v 1.6 1995/03/18 15:00:13 cgd Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)route.8 8.3 (Berkeley) 3/19/94 .\" -.Dd $Mdocdate: May 7 2008 $ +.Dd $Mdocdate: May 30 2009 $ .Dt ROUTE 8 .Os .Sh NAME @@ -134,7 +134,7 @@ command has the syntax: .Bd -filled -offset indent .Nm route Op Fl dnqtv .Cm flush -.Op Ar family +.Op Ar modifiers .Ed .Pp If the @@ -149,6 +149,12 @@ When the address family is specified by any one of the modifiers (listed below), only routes having destinations with addresses in the delineated family will be deleted. +Also, only routes matching a specific interface or priority can be flushed +by using the +.Fl iface +or +.Fl priority +modifiers. .Pp The .Cm monitor diff --git a/sbin/route/route.c b/sbin/route/route.c index 0c267553a69..3bdc528e6d8 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.128 2009/04/28 12:09:35 michele Exp $ */ +/* $OpenBSD: route.c,v 1.129 2009/05/30 19:50:28 claudio Exp $ */ /* $NetBSD: route.c,v 1.16 1996/04/15 18:27:05 cgd Exp $ */ /* @@ -210,18 +210,20 @@ main(int argc, char **argv) void flushroutes(int argc, char **argv) { + const char *errstr; size_t needed; int mib[7], rlen, seqno; char *buf = NULL, *next, *lim = NULL; struct rt_msghdr *rtm; struct sockaddr *sa; + u_short prio = 0; + unsigned int ifindex; if (uid) errx(1, "must be root to alter routing table"); shutdown(s, 0); /* Don't want to read back our messages */ - if (argc > 1) { - argv++; - if (argc == 2 && **argv == '-') + while (--argc > 0) { + if (**(++argv) == '-') switch (keyword(*argv + 1)) { case K_INET: af = AF_INET; @@ -235,6 +237,22 @@ flushroutes(int argc, char **argv) case K_MPLS: af = AF_MPLS; break; + case K_IFACE: + case K_INTERFACE: + if (!--argc) + usage(1+*argv); + ifindex = if_nametoindex(*++argv); + if (ifindex == 0) + errx(1, "no such interface %s", *argv); + break; + case K_PRIORITY: + if (!--argc) + usage(1+*argv); + prio = strtonum(*++argv, 0, RTP_MAX, &errstr); + if (errstr) + errx(1, "priority is %s: %s", errstr, + *argv); + break; default: usage(*argv); /* NOTREACHED */ @@ -278,6 +296,10 @@ flushroutes(int argc, char **argv) sa = (struct sockaddr *)(next + rtm->rtm_hdrlen); if (af && sa->sa_family != af) continue; + if (ifindex && rtm->rtm_index != ifindex) + continue; + if (prio && rtm->rtm_priority != prio) + continue; if (sa->sa_family == AF_KEY) continue; /* Don't flush SPD */ if (debugonly) |