Hi,

this adds a -priority argument to route show to filter on routes of a
certain priority.

With this you can see all ospf routes

  route -n show -priority 32

or any other priority. You can also name some common priorities:

  route -n show -priority bgp

This is useful on a router with a full view routing table where

  route show | grep foo

takes a little bit long.

any oks or other feedback?

diff --git sbin/route/keywords.h sbin/route/keywords.h
index 6174989..2d322ac 100644
--- sbin/route/keywords.h
+++ sbin/route/keywords.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: keywords.h,v 1.29 2015/02/06 03:22:00 reyk Exp $ */
+/* $OpenBSD$ */
 
 /* WARNING!  This file was generated by keywords.sh  */
 
@@ -10,6 +10,7 @@ struct keytab {
 enum {
        K_NULL,
        K_ADD,
+       K_BGP,
        K_BLACKHOLE,
        K_CHANGE,
        K_CLONING,
@@ -33,6 +34,7 @@ enum {
        K_LABEL,
        K_LINK,
        K_LLINFO,
+       K_LOCAL,
        K_LOCK,
        K_LOCKREST,
        K_MONITOR,
@@ -44,6 +46,7 @@ enum {
        K_NETMASK,
        K_NOJUMBO,
        K_NOSTATIC,
+       K_OSPF,
        K_OUT,
        K_POP,
        K_PREFIXLEN,
@@ -53,6 +56,7 @@ enum {
        K_PUSH,
        K_RECVPIPE,
        K_REJECT,
+       K_RIP,
        K_RTT,
        K_RTTVAR,
        K_SA,
@@ -66,6 +70,7 @@ enum {
 
 struct keytab keywords[] = {
        { "add",        K_ADD },
+       { "bgp",        K_BGP },
        { "blackhole",  K_BLACKHOLE },
        { "change",     K_CHANGE },
        { "cloning",    K_CLONING },
@@ -89,6 +94,7 @@ struct keytab keywords[] = {
        { "label",      K_LABEL },
        { "link",       K_LINK },
        { "llinfo",     K_LLINFO },
+       { "local",      K_LOCAL },
        { "lock",       K_LOCK },
        { "lockrest",   K_LOCKREST },
        { "monitor",    K_MONITOR },
@@ -100,6 +106,7 @@ struct keytab keywords[] = {
        { "netmask",    K_NETMASK },
        { "nojumbo",    K_NOJUMBO },
        { "nostatic",   K_NOSTATIC },
+       { "ospf",       K_OSPF },
        { "out",        K_OUT },
        { "pop",        K_POP },
        { "prefixlen",  K_PREFIXLEN },
@@ -109,6 +116,7 @@ struct keytab keywords[] = {
        { "push",       K_PUSH },
        { "recvpipe",   K_RECVPIPE },
        { "reject",     K_REJECT },
+       { "rip",        K_RIP },
        { "rtt",        K_RTT },
        { "rttvar",     K_RTTVAR },
        { "sa", K_SA },
diff --git sbin/route/keywords.sh sbin/route/keywords.sh
index db99593..d4844e2 100644
--- sbin/route/keywords.sh
+++ sbin/route/keywords.sh
@@ -12,6 +12,7 @@ awk=${AWK:-awk}
 cat << _EOF_ | sort > _keywords.t1
 add
 blackhole
+bgp
 change
 cloning
 delete
@@ -34,6 +35,7 @@ jumbo
 label
 link
 llinfo
+local
 lock
 lockrest
 monitor
@@ -45,6 +47,7 @@ net
 netmask
 nojumbo
 nostatic
+ospf
 out
 pop
 prefixlen
@@ -54,6 +57,7 @@ proto2
 push
 recvpipe
 reject
+rip
 rtt
 rttvar
 sa
diff --git sbin/route/route.8 sbin/route/route.8
index d867e87..efe1c77 100644
--- sbin/route/route.8
+++ sbin/route/route.8
@@ -165,6 +165,7 @@ are shown.
 .Op Ar family
 .Op Fl gateway
 .Op Fl label Ar label
+.Op Fl priority Ar priority
 .Xc
 Print out the route table similar to "netstat -r" (see
 .Xr netstat 1 ) .
@@ -177,6 +178,11 @@ same address family as the destination are shown.
 If
 .Fl label
 is specified, only routes with the specified label are shown.
+.Pp
+If
+.Fl priority
+is specified, only routes with the specified (numeric) priority are shown.
+Some well known priorities can be given by name.
 .El
 .Pp
 The other commands relating to adding, changing, or deleting routes
diff --git sbin/route/route.c sbin/route/route.c
index c1445db..de37b6f 100644
--- sbin/route/route.c
+++ sbin/route/route.c
@@ -662,7 +662,10 @@ newroute(int argc, char **argv)
 void
 show(int argc, char *argv[])
 {
-       int     af = 0;
+       int              af = 0;
+       u_char           prio = 0;
+       char            *priostr;
+       const char      *errstr;
 
        while (--argc > 0) {
                if (**(++argv)== '-')
@@ -687,6 +690,34 @@ show(int argc, char *argv[])
                                        usage(1+*argv);
                                getlabel(*++argv);
                                break;
+                       case K_PRIORITY:
+                               if (!--argc)
+                                       usage(1+*argv);
+                               priostr = *++argv;
+                               switch (keyword(priostr)) {
+                                       case K_LOCAL:
+                                           prio = RTP_LOCAL;
+                                           break;
+                                       case K_STATIC:
+                                           prio = RTP_STATIC;
+                                           break;
+                                       case K_OSPF:
+                                           prio = RTP_OSPF;
+                                           break;
+                                       case K_RIP:
+                                           prio = RTP_RIP;
+                                           break;
+                                       case K_BGP:
+                                           prio = RTP_BGP;
+                                           break;
+                                       default:
+                                           prio = strtonum(priostr, 0, RTP_MAX,
+                                               &errstr);
+                                           if (errstr)
+                                               errx(1, "priority is %s: %s",
+                                                   errstr, *argv);
+                               }
+                               break;
                        default:
                                usage(*argv);
                                /* NOTREACHED */
@@ -695,7 +726,7 @@ show(int argc, char *argv[])
                        usage(*argv);
        }
 
-       p_rttables(af, tableid, Tflag);
+       p_rttables(af, tableid, Tflag, prio);
 }
 
 void
diff --git sbin/route/show.c sbin/route/show.c
index c297105..b25be89 100644
--- sbin/route/show.c
+++ sbin/route/show.c
@@ -110,7 +110,7 @@ char        *netname6(struct sockaddr_in6 *, struct 
sockaddr_in6 *);
  * Print routing tables.
  */
 void
-p_rttables(int af, u_int tableid, int hastable)
+p_rttables(int af, u_int tableid, int hastable, u_char prio)
 {
        struct rt_msghdr *rtm;
        char *buf = NULL, *next, *lim = NULL;
@@ -156,6 +156,8 @@ p_rttables(int af, u_int tableid, int hastable)
                        sa = (struct sockaddr *)(next + rtm->rtm_hdrlen);
                        if (af != AF_UNSPEC && sa->sa_family != af)
                                continue;
+                       if (prio && rtm->rtm_priority != prio)
+                               continue;
                        p_rtentry(rtm);
                }
                free(buf);
diff --git sbin/route/show.h sbin/route/show.h
index ab5977a..3c9b892 100644
--- sbin/route/show.h
+++ sbin/route/show.h
@@ -28,7 +28,7 @@ union sockunion {
        struct sockaddr_mpls    smpls;
 };
 
-void    p_rttables(int, u_int, int);
+void    p_rttables(int, u_int, int, u_char);
 char   *routename(struct sockaddr *);
 char   *netname(struct sockaddr *, struct sockaddr *);
 char   *mpls_op(u_int32_t);

Reply via email to