Re: netstat -R: list rdomains with associated ifs and tables

2020-06-14 Thread Stuart Henderson
On 2020/06/13 23:29, Sebastian Benoit wrote:
> Of course that makes parsing the output more difficult.

not really..

netstat -R|awk -F : '/Routing table/ {print $2}'



Re: netstat -R: list rdomains with associated ifs and tables

2020-06-13 Thread Sebastian Benoit
Remi Locherer(remi.loche...@relo.ch) on 2020.06.11 21:46:45 +0200:
> > This would be clearer if it used table/tables as appropriate e.g.
> > 
> >   Routing table: 0
> >   Routing table: 100
> >   Routing tables: 0 6 7 77
> > 
> > the code to handle this gets messy though, maybe someone can think
> > of alternative wording that gets around this another way..
> > 
> 
> It's not too messy I think.
> 
> twister ..in/netstat$ obj/netstat -R 
> Rdomain 0
>   Interfaces: lo0 iwm0 re0 enc0 pflog0
>   Routing tables: 0 5
> 
> Rdomain 255
>   Interface: lo255
>   Routing table: 255

Of course that makes parsing the output more difficult.
Maybe we can change this in tree when we fins a better solution?

/B.



Re: netstat -R: list rdomains with associated ifs and tables

2020-06-11 Thread Remi Locherer
On Wed, Jun 10, 2020 at 11:47:49PM +0200, Sebastian Benoit wrote:
> Remi Locherer(remi.loche...@relo.ch) on 2020.06.10 22:16:36 +0200:
> > On Tue, Jun 09, 2020 at 10:02:06AM +0200, Remi Locherer wrote:
> > > On Tue, Jun 09, 2020 at 09:17:31AM +0200, Claudio Jeker wrote:
> > > > On Tue, Jun 09, 2020 at 08:44:42AM +0200, Remi Locherer wrote:
> > > > > On Mon, Jun 08, 2020 at 10:10:17PM +0200, Remi Locherer wrote:
> > > > > > Hi,
> > > > > > 
> > > > > > to my knowledge there is no easy way to list all active rdomains or
> > > > > > routing tables. Other platforms have "show vrf" or similar commands
> > > > > > for an overview.
> > > > > > 
> > > > > > Here is my attempt at such a view for OpenBSD:
> > > > > 
> > > > > Updated diff with small changes:
> > > > > - Print inet instead of Internet (input deraadt)
> > > > > - Removed padding before rdomain id.
> > > > > - Changed man page wording.
> > > > > 
> > > > > twister ..in/netstat$ obj/netstat -R
> > > > > Rdomain 0
> > > > >   Interfaces: lo0 iwm0 re0 enc0 pflog0 mpe0
> > > > >   Routing tables:
> > > > >   0: inet   8, inet6  45, mpls   1
> > > > >   3: inet   1, inet6   0, mpls   0
> > > > >   7: inet  130309, inet6   1, mpls   0
> > > > > 
> > > > > Rdomain 77
> > > > >   Interfaces: vether77 lo77
> > > > >   Routing tables:
> > > > >  77: inet   0, inet6   0, mpls   0
> > > > > 
> > > > > Rdomain 122
> > > > >   Interfaces: vether122 lo122 pair122 vether1122 vether1123 
> > > > > vether1124 vether1125 vether1126 vether1127
> > > > >   Routing tables:
> > > > > 122: inet  24, inet6   0, mpls   0
> > > > > 
> > > > > Rdomain 255
> > > > >   Interfaces: vether255 lo255
> > > > >   Routing tables:
> > > > > 255: inet   3, inet6   0, mpls   0
> > > > > 
> > > > > twister ..in/netstat$
> > > > > 
> > > > > OK?
> > > > 
> > > > Why do you think the route counts are needed? You fetch all routing 
> > > > tables
> > > > to count them in userland. The sysctl for doing that is expensive and
> > > > especially on systems with full tables will make this command slow.
> > > > If this is something we really want then the kernel should track and
> > > > provide the count.
> > > 
> > > These counters are of interest for operators. But I agree that counting
> > > the routes in userland is unfortunate. But I don't know how bad it is.
> > > Is a lock involved in the kernel when dumping the full table?
> > 
> > I did some homework and figured out, that dumping a routing table takes the
> > NET_LOCK. So it's not just inefficient counting all routes in userland it
> > might have a negative impact on the system.
> > 
> > Below my new proposal without the counters. I still think it would be good
> > to have those counters. Maybe I'll try to find a solution for that.
> 
> Maybe sysctl NET_RT_STATS and struct rtstat could be expanded to cover this?

I also looked at that. If I understand sysctl_rtable_rstat() correct then it
is not per table but for all of them. I guess I can change that. ;-)



Re: netstat -R: list rdomains with associated ifs and tables

2020-06-11 Thread Remi Locherer
On Wed, Jun 10, 2020 at 11:44:17PM +0100, Stuart Henderson wrote:
> It's useful information, I like it. (I preferred it with the route
> count, but I agree, it's hard on the system if there's a full DFZ
> table).
> 
> One thing though -
> 
> > twister ..in/netstat$ obj/netstat -R 
> > Rdomain 0
> >   Interfaces: lo0 iwm0 re0 enc0 pflog0
> >   Routing tables: 0 6 7 77
> 
> When there are multiple tables it's clear that this is a list of
> table numbers, but when there's only one the output text is confusing:
> 
> Rdomain 0
>   Interfaces: lo0 em1 enc0 tun2 vlan1 pflog0
>   Routing tables: 0
> 
> "there are zero routing tables?"
> 
> Rdomain 100
>   Interfaces: vether100 lo100 vether101 [...]
>   Routing tables: 100
> 
> "there are 100 tables?"
> 
> This would be clearer if it used table/tables as appropriate e.g.
> 
>   Routing table: 0
>   Routing table: 100
>   Routing tables: 0 6 7 77
> 
> the code to handle this gets messy though, maybe someone can think
> of alternative wording that gets around this another way..
> 

It's not too messy I think.

twister ..in/netstat$ obj/netstat -R 
Rdomain 0
  Interfaces: lo0 iwm0 re0 enc0 pflog0
  Routing tables: 0 5

Rdomain 255
  Interface: lo255
  Routing table: 255

twister ..in/netstat$



Index: main.c
===
RCS file: /cvs/src/usr.bin/netstat/main.c,v
retrieving revision 1.116
diff -u -p -r1.116 main.c
--- main.c  28 Apr 2019 17:59:51 -  1.116
+++ main.c  30 May 2020 17:59:33 -
@@ -127,7 +127,7 @@ main(int argc, char *argv[])
tableid = getrtable();
 
while ((ch = getopt(argc, argv,
-   "AaBbc:deFf:ghI:iLlM:mN:np:P:qrsT:tuvW:w:")) != -1)
+   "AaBbc:deFf:ghI:iLlM:mN:np:P:qRrsT:tuvW:w:")) != -1)
switch (ch) {
case 'A':
Aflag = 1;
@@ -225,6 +225,9 @@ main(int argc, char *argv[])
case 'q':
qflag = 1;
break;
+   case 'R':
+   Rflag = 1;
+   break;
case 'r':
rflag = 1;
break;
@@ -318,6 +321,11 @@ main(int argc, char *argv[])
mroutepr();
if (af == AF_INET6 || af == AF_UNSPEC)
mroute6pr();
+   exit(0);
+   }
+
+   if (Rflag) {
+   rdomainpr();
exit(0);
}
 
Index: netstat.1
===
RCS file: /cvs/src/usr.bin/netstat/netstat.1,v
retrieving revision 1.86
diff -u -p -r1.86 netstat.1
--- netstat.1   17 Apr 2019 20:34:21 -  1.86
+++ netstat.1   8 Jun 2020 20:42:46 -
@@ -74,6 +74,8 @@
 .Op Fl i | I Ar interface
 .Nm
 .Op Fl W Ar interface
+.Nm
+.Op Fl R
 .Sh DESCRIPTION
 The
 .Nm
@@ -267,6 +269,8 @@ Otherwise the states of the matching soc
 Only show interfaces that have seen packets (or bytes if
 .Fl b
 is specified).
+.It Fl R
+List all rdomains with associated interfaces and routing tables.
 .It Fl r
 Show the routing tables.
 The output is explained in more detail below.
Index: netstat.h
===
RCS file: /cvs/src/usr.bin/netstat/netstat.h,v
retrieving revision 1.74
diff -u -p -r1.74 netstat.h
--- netstat.h   28 Apr 2019 17:59:51 -  1.74
+++ netstat.h   10 Jun 2020 20:08:28 -
@@ -57,6 +57,7 @@ int   pflag;  /* show given protocol */
 intPflag;  /* show given PCB */
 intqflag;  /* only display non-zero values for output */
 intrflag;  /* show routing tables (or routing stats) */
+intRflag;  /* show rdomain and rtable summary */
 intsflag;  /* show protocol statistics */
 inttflag;  /* show i/f watchdog timers */
 intvflag;  /* be verbose */
@@ -112,6 +113,8 @@ voidrt_stats(void);
 void   pr_rthdr(int, int);
 void   pr_encaphdr(void);
 void   pr_family(int);
+
+void   rdomainpr(void);
 
 void   ip6_stats(char *);
 void   icmp6_stats(char *);
Index: route.c
===
RCS file: /cvs/src/usr.bin/netstat/route.c,v
retrieving revision 1.104
diff -u -p -r1.104 route.c
--- route.c 28 Jun 2019 13:35:02 -  1.104
+++ route.c 11 Jun 2020 19:39:38 -
@@ -51,6 +51,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "netstat.h"
 
@@ -346,4 +347,75 @@ rt_stats(void)
rtstat.rts_unreach, plural(rtstat.rts_unreach));
printf("\t%u use%s of a wildcard route\n",
rtstat.rts_wildcard, plural(rtstat.rts_wildcard));
+}
+
+/*
+ * Print rdomain and rtable summary
+ */
+
+void
+rdomainpr(void)
+{
+   struct if_data   *ifd;
+   struct ifaddrs   *ifap, *ifa;
+   struct rt_tableinfo   info;
+
+   int  rtt_dom[RT_TABLEID_MAX+1];
+   int  rdom_

Re: netstat -R: list rdomains with associated ifs and tables

2020-06-10 Thread Stuart Henderson
It's useful information, I like it. (I preferred it with the route
count, but I agree, it's hard on the system if there's a full DFZ
table).

One thing though -

> twister ..in/netstat$ obj/netstat -R 
> Rdomain 0
>   Interfaces: lo0 iwm0 re0 enc0 pflog0
>   Routing tables: 0 6 7 77

When there are multiple tables it's clear that this is a list of
table numbers, but when there's only one the output text is confusing:

Rdomain 0
  Interfaces: lo0 em1 enc0 tun2 vlan1 pflog0
  Routing tables: 0

"there are zero routing tables?"

Rdomain 100
  Interfaces: vether100 lo100 vether101 [...]
  Routing tables: 100

"there are 100 tables?"

This would be clearer if it used table/tables as appropriate e.g.

  Routing table: 0
  Routing table: 100
  Routing tables: 0 6 7 77

the code to handle this gets messy though, maybe someone can think
of alternative wording that gets around this another way..



Re: netstat -R: list rdomains with associated ifs and tables

2020-06-10 Thread Sebastian Benoit
Remi Locherer(remi.loche...@relo.ch) on 2020.06.10 22:16:36 +0200:
> On Tue, Jun 09, 2020 at 10:02:06AM +0200, Remi Locherer wrote:
> > On Tue, Jun 09, 2020 at 09:17:31AM +0200, Claudio Jeker wrote:
> > > On Tue, Jun 09, 2020 at 08:44:42AM +0200, Remi Locherer wrote:
> > > > On Mon, Jun 08, 2020 at 10:10:17PM +0200, Remi Locherer wrote:
> > > > > Hi,
> > > > > 
> > > > > to my knowledge there is no easy way to list all active rdomains or
> > > > > routing tables. Other platforms have "show vrf" or similar commands
> > > > > for an overview.
> > > > > 
> > > > > Here is my attempt at such a view for OpenBSD:
> > > > 
> > > > Updated diff with small changes:
> > > > - Print inet instead of Internet (input deraadt)
> > > > - Removed padding before rdomain id.
> > > > - Changed man page wording.
> > > > 
> > > > twister ..in/netstat$ obj/netstat -R
> > > > Rdomain 0
> > > >   Interfaces: lo0 iwm0 re0 enc0 pflog0 mpe0
> > > >   Routing tables:
> > > >   0: inet   8, inet6  45, mpls   1
> > > >   3: inet   1, inet6   0, mpls   0
> > > >   7: inet  130309, inet6   1, mpls   0
> > > > 
> > > > Rdomain 77
> > > >   Interfaces: vether77 lo77
> > > >   Routing tables:
> > > >  77: inet   0, inet6   0, mpls   0
> > > > 
> > > > Rdomain 122
> > > >   Interfaces: vether122 lo122 pair122 vether1122 vether1123 vether1124 
> > > > vether1125 vether1126 vether1127
> > > >   Routing tables:
> > > > 122: inet  24, inet6   0, mpls   0
> > > > 
> > > > Rdomain 255
> > > >   Interfaces: vether255 lo255
> > > >   Routing tables:
> > > > 255: inet   3, inet6   0, mpls   0
> > > > 
> > > > twister ..in/netstat$
> > > > 
> > > > OK?
> > > 
> > > Why do you think the route counts are needed? You fetch all routing tables
> > > to count them in userland. The sysctl for doing that is expensive and
> > > especially on systems with full tables will make this command slow.
> > > If this is something we really want then the kernel should track and
> > > provide the count.
> > 
> > These counters are of interest for operators. But I agree that counting
> > the routes in userland is unfortunate. But I don't know how bad it is.
> > Is a lock involved in the kernel when dumping the full table?
> 
> I did some homework and figured out, that dumping a routing table takes the
> NET_LOCK. So it's not just inefficient counting all routes in userland it
> might have a negative impact on the system.
> 
> Below my new proposal without the counters. I still think it would be good
> to have those counters. Maybe I'll try to find a solution for that.

Maybe sysctl NET_RT_STATS and struct rtstat could be expanded to cover this?

As for the diff, ok benno@. The number of routes is interesting but can be
added later.

/B.



 
> twister ..in/netstat$ obj/netstat -R 
> Rdomain 0
>   Interfaces: lo0 iwm0 re0 enc0 pflog0
>   Routing tables: 0 6 7 77
> 
> Rdomain 100
>   Interfaces: vether100 lo100 vether101 vether102 vether103 vether104 
> vether105 vether106 vether107 vether108 vether109
>   Routing tables: 100
> 
> Rdomain 255
>   Interfaces: vether255 lo255
>   Routing tables: 255
> 
> twister ..in/netstat$
> 
> 
> 
> Index: main.c
> ===
> RCS file: /cvs/src/usr.bin/netstat/main.c,v
> retrieving revision 1.116
> diff -u -p -r1.116 main.c
> --- main.c28 Apr 2019 17:59:51 -  1.116
> +++ main.c30 May 2020 17:59:33 -
> @@ -127,7 +127,7 @@ main(int argc, char *argv[])
>   tableid = getrtable();
>  
>   while ((ch = getopt(argc, argv,
> - "AaBbc:deFf:ghI:iLlM:mN:np:P:qrsT:tuvW:w:")) != -1)
> + "AaBbc:deFf:ghI:iLlM:mN:np:P:qRrsT:tuvW:w:")) != -1)
>   switch (ch) {
>   case 'A':
>   Aflag = 1;
> @@ -225,6 +225,9 @@ main(int argc, char *argv[])
>   case 'q':
>   qflag = 1;
>   break;
> + case 'R':
> + Rflag = 1;
> + break;
>   case 'r':
>   rflag = 1;
>   break;
> @@ -318,6 +321,11 @@ main(int argc, char *argv[])
>   mroutepr();
>   if (af == AF_INET6 || af == AF_UNSPEC)
>   mroute6pr();
> + exit(0);
> + }
> +
> + if (Rflag) {
> + rdomainpr();
>   exit(0);
>   }
>  
> Index: netstat.1
> ===
> RCS file: /cvs/src/usr.bin/netstat/netstat.1,v
> retrieving revision 1.86
> diff -u -p -r1.86 netstat.1
> --- netstat.1 17 Apr 2019 20:34:21 -  1.86
> +++ netstat.1 8 Jun 2020 20:42:46 -
> @@ -74,6 +74,8 @@
>  .Op Fl i | I Ar interface
>  .Nm
>  .Op Fl W Ar interface
> +.Nm
> +.Op Fl R
>  .Sh DESCRIPTION
>  The
>  .Nm
> @@ -267,6 +269,8 @@ Otherwise the states of the matching soc
>  Only show interfaces that have 

Re: netstat -R: list rdomains with associated ifs and tables

2020-06-10 Thread Remi Locherer
On Tue, Jun 09, 2020 at 10:02:06AM +0200, Remi Locherer wrote:
> On Tue, Jun 09, 2020 at 09:17:31AM +0200, Claudio Jeker wrote:
> > On Tue, Jun 09, 2020 at 08:44:42AM +0200, Remi Locherer wrote:
> > > On Mon, Jun 08, 2020 at 10:10:17PM +0200, Remi Locherer wrote:
> > > > Hi,
> > > > 
> > > > to my knowledge there is no easy way to list all active rdomains or
> > > > routing tables. Other platforms have "show vrf" or similar commands
> > > > for an overview.
> > > > 
> > > > Here is my attempt at such a view for OpenBSD:
> > > 
> > > Updated diff with small changes:
> > > - Print inet instead of Internet (input deraadt)
> > > - Removed padding before rdomain id.
> > > - Changed man page wording.
> > > 
> > > twister ..in/netstat$ obj/netstat -R
> > > Rdomain 0
> > >   Interfaces: lo0 iwm0 re0 enc0 pflog0 mpe0
> > >   Routing tables:
> > >   0: inet   8, inet6  45, mpls   1
> > >   3: inet   1, inet6   0, mpls   0
> > >   7: inet  130309, inet6   1, mpls   0
> > > 
> > > Rdomain 77
> > >   Interfaces: vether77 lo77
> > >   Routing tables:
> > >  77: inet   0, inet6   0, mpls   0
> > > 
> > > Rdomain 122
> > >   Interfaces: vether122 lo122 pair122 vether1122 vether1123 vether1124 
> > > vether1125 vether1126 vether1127
> > >   Routing tables:
> > > 122: inet  24, inet6   0, mpls   0
> > > 
> > > Rdomain 255
> > >   Interfaces: vether255 lo255
> > >   Routing tables:
> > > 255: inet   3, inet6   0, mpls   0
> > > 
> > > twister ..in/netstat$
> > > 
> > > OK?
> > 
> > Why do you think the route counts are needed? You fetch all routing tables
> > to count them in userland. The sysctl for doing that is expensive and
> > especially on systems with full tables will make this command slow.
> > If this is something we really want then the kernel should track and
> > provide the count.
> 
> These counters are of interest for operators. But I agree that counting
> the routes in userland is unfortunate. But I don't know how bad it is.
> Is a lock involved in the kernel when dumping the full table?

I did some homework and figured out, that dumping a routing table takes the
NET_LOCK. So it's not just inefficient counting all routes in userland it
might have a negative impact on the system.

Below my new proposal without the counters. I still think it would be good
to have those counters. Maybe I'll try to find a solution for that.

twister ..in/netstat$ obj/netstat -R 
Rdomain 0
  Interfaces: lo0 iwm0 re0 enc0 pflog0
  Routing tables: 0 6 7 77

Rdomain 100
  Interfaces: vether100 lo100 vether101 vether102 vether103 vether104 vether105 
vether106 vether107 vether108 vether109
  Routing tables: 100

Rdomain 255
  Interfaces: vether255 lo255
  Routing tables: 255

twister ..in/netstat$



Index: main.c
===
RCS file: /cvs/src/usr.bin/netstat/main.c,v
retrieving revision 1.116
diff -u -p -r1.116 main.c
--- main.c  28 Apr 2019 17:59:51 -  1.116
+++ main.c  30 May 2020 17:59:33 -
@@ -127,7 +127,7 @@ main(int argc, char *argv[])
tableid = getrtable();
 
while ((ch = getopt(argc, argv,
-   "AaBbc:deFf:ghI:iLlM:mN:np:P:qrsT:tuvW:w:")) != -1)
+   "AaBbc:deFf:ghI:iLlM:mN:np:P:qRrsT:tuvW:w:")) != -1)
switch (ch) {
case 'A':
Aflag = 1;
@@ -225,6 +225,9 @@ main(int argc, char *argv[])
case 'q':
qflag = 1;
break;
+   case 'R':
+   Rflag = 1;
+   break;
case 'r':
rflag = 1;
break;
@@ -318,6 +321,11 @@ main(int argc, char *argv[])
mroutepr();
if (af == AF_INET6 || af == AF_UNSPEC)
mroute6pr();
+   exit(0);
+   }
+
+   if (Rflag) {
+   rdomainpr();
exit(0);
}
 
Index: netstat.1
===
RCS file: /cvs/src/usr.bin/netstat/netstat.1,v
retrieving revision 1.86
diff -u -p -r1.86 netstat.1
--- netstat.1   17 Apr 2019 20:34:21 -  1.86
+++ netstat.1   8 Jun 2020 20:42:46 -
@@ -74,6 +74,8 @@
 .Op Fl i | I Ar interface
 .Nm
 .Op Fl W Ar interface
+.Nm
+.Op Fl R
 .Sh DESCRIPTION
 The
 .Nm
@@ -267,6 +269,8 @@ Otherwise the states of the matching soc
 Only show interfaces that have seen packets (or bytes if
 .Fl b
 is specified).
+.It Fl R
+List all rdomains with associated interfaces and routing tables.
 .It Fl r
 Show the routing tables.
 The output is explained in more detail below.
Index: netstat.h
===
RCS file: /cvs/src/usr.bin/netstat/netstat.h,v
retrieving revision 1.74
diff -u -p -r1.74 netstat.h
--- netstat.h   28 Apr 2019 17:59:51 -  1.74
+++ netst

Re: netstat -R: list rdomains with associated ifs and tables

2020-06-09 Thread Remi Locherer
On Tue, Jun 09, 2020 at 09:17:31AM +0200, Claudio Jeker wrote:
> On Tue, Jun 09, 2020 at 08:44:42AM +0200, Remi Locherer wrote:
> > On Mon, Jun 08, 2020 at 10:10:17PM +0200, Remi Locherer wrote:
> > > Hi,
> > > 
> > > to my knowledge there is no easy way to list all active rdomains or
> > > routing tables. Other platforms have "show vrf" or similar commands
> > > for an overview.
> > > 
> > > Here is my attempt at such a view for OpenBSD:
> > 
> > Updated diff with small changes:
> > - Print inet instead of Internet (input deraadt)
> > - Removed padding before rdomain id.
> > - Changed man page wording.
> > 
> > twister ..in/netstat$ obj/netstat -R
> > Rdomain 0
> >   Interfaces: lo0 iwm0 re0 enc0 pflog0 mpe0
> >   Routing tables:
> >   0: inet   8, inet6  45, mpls   1
> >   3: inet   1, inet6   0, mpls   0
> >   7: inet  130309, inet6   1, mpls   0
> > 
> > Rdomain 77
> >   Interfaces: vether77 lo77
> >   Routing tables:
> >  77: inet   0, inet6   0, mpls   0
> > 
> > Rdomain 122
> >   Interfaces: vether122 lo122 pair122 vether1122 vether1123 vether1124 
> > vether1125 vether1126 vether1127
> >   Routing tables:
> > 122: inet  24, inet6   0, mpls   0
> > 
> > Rdomain 255
> >   Interfaces: vether255 lo255
> >   Routing tables:
> > 255: inet   3, inet6   0, mpls   0
> > 
> > twister ..in/netstat$
> > 
> > OK?
> 
> Why do you think the route counts are needed? You fetch all routing tables
> to count them in userland. The sysctl for doing that is expensive and
> especially on systems with full tables will make this command slow.
> If this is something we really want then the kernel should track and
> provide the count.

These counters are of interest for operators. But I agree that counting
the routes in userland is unfortunate. But I don't know how bad it is.
Is a lock involved in the kernel when dumping the full table?

I see in art.h that struct art_table has a counter. What would be a good
way to export this to userland?

> 
> Apart from that I think this is a good addition.
>  
> > Index: main.c
> > ===
> > RCS file: /cvs/src/usr.bin/netstat/main.c,v
> > retrieving revision 1.116
> > diff -u -p -r1.116 main.c
> > --- main.c  28 Apr 2019 17:59:51 -  1.116
> > +++ main.c  30 May 2020 17:59:33 -
> > @@ -127,7 +127,7 @@ main(int argc, char *argv[])
> > tableid = getrtable();
> >  
> > while ((ch = getopt(argc, argv,
> > -   "AaBbc:deFf:ghI:iLlM:mN:np:P:qrsT:tuvW:w:")) != -1)
> > +   "AaBbc:deFf:ghI:iLlM:mN:np:P:qRrsT:tuvW:w:")) != -1)
> > switch (ch) {
> > case 'A':
> > Aflag = 1;
> > @@ -225,6 +225,9 @@ main(int argc, char *argv[])
> > case 'q':
> > qflag = 1;
> > break;
> > +   case 'R':
> > +   Rflag = 1;
> > +   break;
> > case 'r':
> > rflag = 1;
> > break;
> > @@ -318,6 +321,11 @@ main(int argc, char *argv[])
> > mroutepr();
> > if (af == AF_INET6 || af == AF_UNSPEC)
> > mroute6pr();
> > +   exit(0);
> > +   }
> > +
> > +   if (Rflag) {
> > +   rdomainpr();
> > exit(0);
> > }
> >  
> > Index: netstat.1
> > ===
> > RCS file: /cvs/src/usr.bin/netstat/netstat.1,v
> > retrieving revision 1.86
> > diff -u -p -r1.86 netstat.1
> > --- netstat.1   17 Apr 2019 20:34:21 -  1.86
> > +++ netstat.1   8 Jun 2020 20:42:46 -
> > @@ -74,6 +74,8 @@
> >  .Op Fl i | I Ar interface
> >  .Nm
> >  .Op Fl W Ar interface
> > +.Nm
> > +.Op Fl R
> >  .Sh DESCRIPTION
> >  The
> >  .Nm
> > @@ -267,6 +269,8 @@ Otherwise the states of the matching soc
> >  Only show interfaces that have seen packets (or bytes if
> >  .Fl b
> >  is specified).
> > +.It Fl R
> > +List all rdomains with associated interfaces and routing tables.
> >  .It Fl r
> >  Show the routing tables.
> >  The output is explained in more detail below.
> > Index: netstat.h
> > ===
> > RCS file: /cvs/src/usr.bin/netstat/netstat.h,v
> > retrieving revision 1.74
> > diff -u -p -r1.74 netstat.h
> > --- netstat.h   28 Apr 2019 17:59:51 -  1.74
> > +++ netstat.h   7 Jun 2020 22:03:10 -
> > @@ -57,6 +57,7 @@ int   pflag;  /* show given protocol */
> >  intPflag;  /* show given PCB */
> >  intqflag;  /* only display non-zero values for output */
> >  intrflag;  /* show routing tables (or routing stats) */
> > +intRflag;  /* show rdomain and rtable summary */
> >  intsflag;  /* show protocol statistics */
> >  inttflag;  /* show i/f watchdog timers */
> >  i

Re: netstat -R: list rdomains with associated ifs and tables

2020-06-09 Thread Claudio Jeker
On Tue, Jun 09, 2020 at 08:44:42AM +0200, Remi Locherer wrote:
> On Mon, Jun 08, 2020 at 10:10:17PM +0200, Remi Locherer wrote:
> > Hi,
> > 
> > to my knowledge there is no easy way to list all active rdomains or
> > routing tables. Other platforms have "show vrf" or similar commands
> > for an overview.
> > 
> > Here is my attempt at such a view for OpenBSD:
> 
> Updated diff with small changes:
> - Print inet instead of Internet (input deraadt)
> - Removed padding before rdomain id.
> - Changed man page wording.
> 
> twister ..in/netstat$ obj/netstat -R
> Rdomain 0
>   Interfaces: lo0 iwm0 re0 enc0 pflog0 mpe0
>   Routing tables:
>   0: inet   8, inet6  45, mpls   1
>   3: inet   1, inet6   0, mpls   0
>   7: inet  130309, inet6   1, mpls   0
> 
> Rdomain 77
>   Interfaces: vether77 lo77
>   Routing tables:
>  77: inet   0, inet6   0, mpls   0
> 
> Rdomain 122
>   Interfaces: vether122 lo122 pair122 vether1122 vether1123 vether1124 
> vether1125 vether1126 vether1127
>   Routing tables:
> 122: inet  24, inet6   0, mpls   0
> 
> Rdomain 255
>   Interfaces: vether255 lo255
>   Routing tables:
> 255: inet   3, inet6   0, mpls   0
> 
> twister ..in/netstat$
> 
> OK?

Why do you think the route counts are needed? You fetch all routing tables
to count them in userland. The sysctl for doing that is expensive and
especially on systems with full tables will make this command slow.
If this is something we really want then the kernel should track and
provide the count.

Apart from that I think this is a good addition.
 
> Index: main.c
> ===
> RCS file: /cvs/src/usr.bin/netstat/main.c,v
> retrieving revision 1.116
> diff -u -p -r1.116 main.c
> --- main.c28 Apr 2019 17:59:51 -  1.116
> +++ main.c30 May 2020 17:59:33 -
> @@ -127,7 +127,7 @@ main(int argc, char *argv[])
>   tableid = getrtable();
>  
>   while ((ch = getopt(argc, argv,
> - "AaBbc:deFf:ghI:iLlM:mN:np:P:qrsT:tuvW:w:")) != -1)
> + "AaBbc:deFf:ghI:iLlM:mN:np:P:qRrsT:tuvW:w:")) != -1)
>   switch (ch) {
>   case 'A':
>   Aflag = 1;
> @@ -225,6 +225,9 @@ main(int argc, char *argv[])
>   case 'q':
>   qflag = 1;
>   break;
> + case 'R':
> + Rflag = 1;
> + break;
>   case 'r':
>   rflag = 1;
>   break;
> @@ -318,6 +321,11 @@ main(int argc, char *argv[])
>   mroutepr();
>   if (af == AF_INET6 || af == AF_UNSPEC)
>   mroute6pr();
> + exit(0);
> + }
> +
> + if (Rflag) {
> + rdomainpr();
>   exit(0);
>   }
>  
> Index: netstat.1
> ===
> RCS file: /cvs/src/usr.bin/netstat/netstat.1,v
> retrieving revision 1.86
> diff -u -p -r1.86 netstat.1
> --- netstat.1 17 Apr 2019 20:34:21 -  1.86
> +++ netstat.1 8 Jun 2020 20:42:46 -
> @@ -74,6 +74,8 @@
>  .Op Fl i | I Ar interface
>  .Nm
>  .Op Fl W Ar interface
> +.Nm
> +.Op Fl R
>  .Sh DESCRIPTION
>  The
>  .Nm
> @@ -267,6 +269,8 @@ Otherwise the states of the matching soc
>  Only show interfaces that have seen packets (or bytes if
>  .Fl b
>  is specified).
> +.It Fl R
> +List all rdomains with associated interfaces and routing tables.
>  .It Fl r
>  Show the routing tables.
>  The output is explained in more detail below.
> Index: netstat.h
> ===
> RCS file: /cvs/src/usr.bin/netstat/netstat.h,v
> retrieving revision 1.74
> diff -u -p -r1.74 netstat.h
> --- netstat.h 28 Apr 2019 17:59:51 -  1.74
> +++ netstat.h 7 Jun 2020 22:03:10 -
> @@ -57,6 +57,7 @@ int pflag;  /* show given protocol */
>  int  Pflag;  /* show given PCB */
>  int  qflag;  /* only display non-zero values for output */
>  int  rflag;  /* show routing tables (or routing stats) */
> +int  Rflag;  /* show rdomain and rtable summary */
>  int  sflag;  /* show protocol statistics */
>  int  tflag;  /* show i/f watchdog timers */
>  int  vflag;  /* be verbose */
> @@ -112,6 +113,9 @@ void  rt_stats(void);
>  void pr_rthdr(int, int);
>  void pr_encaphdr(void);
>  void pr_family(int);
> +
> +void rdomainpr(void);
> +void rttsummarypr(int);
>  
>  void ip6_stats(char *);
>  void icmp6_stats(char *);
> Index: route.c
> ===
> RCS file: /cvs/src/usr.bin/netstat/route.c,v
> retrieving revision 1.104
> diff -u -p -r1.104 route.c
> --- route.c   28 Jun 2019 13:35:02 -  1.104
> +++ route.c   9 Jun 2020 06:36:29 -
> @@ -51,6 +51,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  

Re: netstat -R: list rdomains with associated ifs and tables

2020-06-08 Thread Remi Locherer
On Mon, Jun 08, 2020 at 10:10:17PM +0200, Remi Locherer wrote:
> Hi,
> 
> to my knowledge there is no easy way to list all active rdomains or
> routing tables. Other platforms have "show vrf" or similar commands
> for an overview.
> 
> Here is my attempt at such a view for OpenBSD:

Updated diff with small changes:
- Print inet instead of Internet (input deraadt)
- Removed padding before rdomain id.
- Changed man page wording.

twister ..in/netstat$ obj/netstat -R
Rdomain 0
  Interfaces: lo0 iwm0 re0 enc0 pflog0 mpe0
  Routing tables:
  0: inet   8, inet6  45, mpls   1
  3: inet   1, inet6   0, mpls   0
  7: inet  130309, inet6   1, mpls   0

Rdomain 77
  Interfaces: vether77 lo77
  Routing tables:
 77: inet   0, inet6   0, mpls   0

Rdomain 122
  Interfaces: vether122 lo122 pair122 vether1122 vether1123 vether1124 
vether1125 vether1126 vether1127
  Routing tables:
122: inet  24, inet6   0, mpls   0

Rdomain 255
  Interfaces: vether255 lo255
  Routing tables:
255: inet   3, inet6   0, mpls   0

twister ..in/netstat$

OK?


Index: main.c
===
RCS file: /cvs/src/usr.bin/netstat/main.c,v
retrieving revision 1.116
diff -u -p -r1.116 main.c
--- main.c  28 Apr 2019 17:59:51 -  1.116
+++ main.c  30 May 2020 17:59:33 -
@@ -127,7 +127,7 @@ main(int argc, char *argv[])
tableid = getrtable();
 
while ((ch = getopt(argc, argv,
-   "AaBbc:deFf:ghI:iLlM:mN:np:P:qrsT:tuvW:w:")) != -1)
+   "AaBbc:deFf:ghI:iLlM:mN:np:P:qRrsT:tuvW:w:")) != -1)
switch (ch) {
case 'A':
Aflag = 1;
@@ -225,6 +225,9 @@ main(int argc, char *argv[])
case 'q':
qflag = 1;
break;
+   case 'R':
+   Rflag = 1;
+   break;
case 'r':
rflag = 1;
break;
@@ -318,6 +321,11 @@ main(int argc, char *argv[])
mroutepr();
if (af == AF_INET6 || af == AF_UNSPEC)
mroute6pr();
+   exit(0);
+   }
+
+   if (Rflag) {
+   rdomainpr();
exit(0);
}
 
Index: netstat.1
===
RCS file: /cvs/src/usr.bin/netstat/netstat.1,v
retrieving revision 1.86
diff -u -p -r1.86 netstat.1
--- netstat.1   17 Apr 2019 20:34:21 -  1.86
+++ netstat.1   8 Jun 2020 20:42:46 -
@@ -74,6 +74,8 @@
 .Op Fl i | I Ar interface
 .Nm
 .Op Fl W Ar interface
+.Nm
+.Op Fl R
 .Sh DESCRIPTION
 The
 .Nm
@@ -267,6 +269,8 @@ Otherwise the states of the matching soc
 Only show interfaces that have seen packets (or bytes if
 .Fl b
 is specified).
+.It Fl R
+List all rdomains with associated interfaces and routing tables.
 .It Fl r
 Show the routing tables.
 The output is explained in more detail below.
Index: netstat.h
===
RCS file: /cvs/src/usr.bin/netstat/netstat.h,v
retrieving revision 1.74
diff -u -p -r1.74 netstat.h
--- netstat.h   28 Apr 2019 17:59:51 -  1.74
+++ netstat.h   7 Jun 2020 22:03:10 -
@@ -57,6 +57,7 @@ int   pflag;  /* show given protocol */
 intPflag;  /* show given PCB */
 intqflag;  /* only display non-zero values for output */
 intrflag;  /* show routing tables (or routing stats) */
+intRflag;  /* show rdomain and rtable summary */
 intsflag;  /* show protocol statistics */
 inttflag;  /* show i/f watchdog timers */
 intvflag;  /* be verbose */
@@ -112,6 +113,9 @@ voidrt_stats(void);
 void   pr_rthdr(int, int);
 void   pr_encaphdr(void);
 void   pr_family(int);
+
+void   rdomainpr(void);
+void   rttsummarypr(int);
 
 void   ip6_stats(char *);
 void   icmp6_stats(char *);
Index: route.c
===
RCS file: /cvs/src/usr.bin/netstat/route.c,v
retrieving revision 1.104
diff -u -p -r1.104 route.c
--- route.c 28 Jun 2019 13:35:02 -  1.104
+++ route.c 9 Jun 2020 06:36:29 -
@@ -51,6 +51,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "netstat.h"
 
@@ -346,4 +347,117 @@ rt_stats(void)
rtstat.rts_unreach, plural(rtstat.rts_unreach));
printf("\t%u use%s of a wildcard route\n",
rtstat.rts_wildcard, plural(rtstat.rts_wildcard));
+}
+
+/*
+ * Print rdomain and rtable summary
+ */
+
+void
+rdomainpr(void)
+{
+   struct if_data   *ifd;
+   struct ifaddrs   *ifap, *ifa;
+   struct rt_tableinfo   info;
+
+   int  rtt_dom[RT_TABLEID_MAX+1];
+   int  mib[6], rdom, rtt;
+   size_t   len;
+   char*old, *rdom_if[RT_TABLEID_MAX+1] = { };
+
+ 

netstat -R: list rdomains with associated ifs and tables

2020-06-08 Thread Remi Locherer
Hi,

to my knowledge there is no easy way to list all active rdomains or
routing tables. Other platforms have "show vrf" or similar commands
for an overview.

Here is my attempt at such a view for OpenBSD:

twister ..in/netstat$ obj/netstat -R
Rdomain   0
  Interfaces: lo0 iwm0 re0 enc0 pflog0
  Routing tables:
  0: Internet   8, Internet6  43, MPLS   0
  3: Internet   1, Internet6   0, MPLS   0
  7: Internet  130309, Internet6   1, MPLS   0

Rdomain  77
  Interfaces: vether77 lo77
  Routing tables:
 77: Internet   0, Internet6   0, MPLS   0

Rdomain 122
  Interfaces: vether122 lo122 pair122 vether1122 vether1123 vether1124 
vether1125 vether1126 vether1127
  Routing tables:
122: Internet  24, Internet6   0, MPLS   0

Rdomain 255
  Interfaces: vether255 lo255
  Routing tables:
255: Internet   3, Internet6   0, MPLS   0

twister ..in/netstat$

Comments? OKs?

Remi


Index: main.c
===
RCS file: /cvs/src/usr.bin/netstat/main.c,v
retrieving revision 1.116
diff -u -p -r1.116 main.c
--- main.c  28 Apr 2019 17:59:51 -  1.116
+++ main.c  30 May 2020 17:59:33 -
@@ -127,7 +127,7 @@ main(int argc, char *argv[])
tableid = getrtable();
 
while ((ch = getopt(argc, argv,
-   "AaBbc:deFf:ghI:iLlM:mN:np:P:qrsT:tuvW:w:")) != -1)
+   "AaBbc:deFf:ghI:iLlM:mN:np:P:qRrsT:tuvW:w:")) != -1)
switch (ch) {
case 'A':
Aflag = 1;
@@ -225,6 +225,9 @@ main(int argc, char *argv[])
case 'q':
qflag = 1;
break;
+   case 'R':
+   Rflag = 1;
+   break;
case 'r':
rflag = 1;
break;
@@ -318,6 +321,11 @@ main(int argc, char *argv[])
mroutepr();
if (af == AF_INET6 || af == AF_UNSPEC)
mroute6pr();
+   exit(0);
+   }
+
+   if (Rflag) {
+   rdomainpr();
exit(0);
}
 
Index: netstat.1
===
RCS file: /cvs/src/usr.bin/netstat/netstat.1,v
retrieving revision 1.86
diff -u -p -r1.86 netstat.1
--- netstat.1   17 Apr 2019 20:34:21 -  1.86
+++ netstat.1   8 Jun 2020 19:21:26 -
@@ -74,6 +74,8 @@
 .Op Fl i | I Ar interface
 .Nm
 .Op Fl W Ar interface
+.Nm
+.Op Fl R
 .Sh DESCRIPTION
 The
 .Nm
@@ -267,6 +269,9 @@ Otherwise the states of the matching soc
 Only show interfaces that have seen packets (or bytes if
 .Fl b
 is specified).
+.It Fl R
+Show all rdomains and list associated interfaces and routing tables
+with number of entries.
 .It Fl r
 Show the routing tables.
 The output is explained in more detail below.
Index: netstat.h
===
RCS file: /cvs/src/usr.bin/netstat/netstat.h,v
retrieving revision 1.74
diff -u -p -r1.74 netstat.h
--- netstat.h   28 Apr 2019 17:59:51 -  1.74
+++ netstat.h   7 Jun 2020 22:03:10 -
@@ -57,6 +57,7 @@ int   pflag;  /* show given protocol */
 intPflag;  /* show given PCB */
 intqflag;  /* only display non-zero values for output */
 intrflag;  /* show routing tables (or routing stats) */
+intRflag;  /* show rdomain and rtable summary */
 intsflag;  /* show protocol statistics */
 inttflag;  /* show i/f watchdog timers */
 intvflag;  /* be verbose */
@@ -112,6 +113,9 @@ voidrt_stats(void);
 void   pr_rthdr(int, int);
 void   pr_encaphdr(void);
 void   pr_family(int);
+
+void   rdomainpr(void);
+void   rttsummarypr(int);
 
 void   ip6_stats(char *);
 void   icmp6_stats(char *);
Index: route.c
===
RCS file: /cvs/src/usr.bin/netstat/route.c,v
retrieving revision 1.104
diff -u -p -r1.104 route.c
--- route.c 28 Jun 2019 13:35:02 -  1.104
+++ route.c 8 Jun 2020 19:29:58 -
@@ -51,6 +51,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "netstat.h"
 
@@ -346,4 +347,117 @@ rt_stats(void)
rtstat.rts_unreach, plural(rtstat.rts_unreach));
printf("\t%u use%s of a wildcard route\n",
rtstat.rts_wildcard, plural(rtstat.rts_wildcard));
+}
+
+/*
+ * Print rdomain and rtable summary
+ */
+
+void
+rdomainpr(void)
+{
+   struct if_data   *ifd;
+   struct ifaddrs   *ifap, *ifa;
+   struct rt_tableinfo   info;
+
+   int  rtt_dom[RT_TABLEID_MAX+1];
+   int  mib[6], rdom, rtt;
+   size_t   len;
+   char*old, *rdom_if[RT_TABLEID_MAX+1] = { };
+
+   getifaddrs(&ifap);
+   for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+   if (ifa->ifa_addr->sa_family != AF_LINK)