Re: top: filter by routing table

2020-08-23 Thread Remi Locherer
On Sun, Aug 23, 2020 at 10:45:14PM +0200, Klemens Nanni wrote:
> On Sun, Aug 23, 2020 at 10:39:21PM +0200, Remi Locherer wrote:
> > I like the feature and it works as advertised.
> > 
> > It would be nice to have a column that displays the rtable id of
> > each process when T is used. When I type "T-0" I see a list of procs
> > not in rtable 0.  But I still do not know in which one they are.
> That's certainly possible, but we need to pick a column which is not
> only suitable to omit but also wide enough to fit "RTABLE" as
> description, I'd say.
> 
> Are you OK with the diff as is?  We can take care of the rest as a
> separate diff.

sure! ok remi@



Re: top: filter by routing table

2020-08-23 Thread Klemens Nanni
On Sun, Aug 23, 2020 at 10:39:21PM +0200, Remi Locherer wrote:
> I like the feature and it works as advertised.
> 
> It would be nice to have a column that displays the rtable id of
> each process when T is used. When I type "T-0" I see a list of procs
> not in rtable 0.  But I still do not know in which one they are.
That's certainly possible, but we need to pick a column which is not
only suitable to omit but also wide enough to fit "RTABLE" as
description, I'd say.

Are you OK with the diff as is?  We can take care of the rest as a
separate diff.



Re: top: filter by routing table

2020-08-23 Thread Remi Locherer
On Sat, Aug 22, 2020 at 05:20:56PM -0600, Todd C. Miller wrote:
> This looks good to me but I've refrained from commenting simply
> because I don't use rtables at all myself.  Can we get some feedback
> from people who actually use rtables?
> 
>  - todd
> 

I like the feature and it works as advertised.

It would be nice to have a column that displays the rtable id of
each process when T is used. When I type "T-0" I see a list of procs
not in rtable 0.  But I still do not know in which one they are.

Remi



Re: top: filter by routing table

2020-08-22 Thread Todd C . Miller
This looks good to me but I've refrained from commenting simply
because I don't use rtables at all myself.  Can we get some feedback
from people who actually use rtables?

 - todd



Re: top: filter by routing table

2020-08-22 Thread Klemens Nanni
On Sun, Aug 09, 2020 at 09:02:14PM +0200, Klemens Nanni wrote:
> Sometimes I want to see processes outside the default routing table with
> `-T -0', sometimes those in in a specific one with `-T 3' (for testing).
> 
> Since others have poked around with routing tables and/or domains as of
> late, perhaps this deemed useful enough?
> 
> Semantically, filtering is identical to that of users: pick or hide one;
> this makes the code pretty much copy/paste within top(1), manual wording
> and command line flag is taken from pgrep(1).
> 
> pgrep is currently the only way to identify processes by routing table.
> After netstat(1)'s relatively recent addition of `-R', filtering in top
> makes for a quite handy set of tooling around rtable(4).
> 
> Feedback? OK?
Anyone?

One thing is that routing tables are now the only values you can filter
for which are never visible in top - I thought about adding another
RTABLE column, replacing one as `H' does with USERNAME -> TID or so,
but did not deem it necessary/worthwile in the end.

What do you think?

Same diff below.


Index: display.c
===
RCS file: /cvs/src/usr.bin/top/display.c,v
retrieving revision 1.63
diff -u -p -r1.63 display.c
--- display.c   26 Jul 2020 21:59:16 -  1.63
+++ display.c   9 Aug 2020 17:55:56 -
@@ -824,6 +824,8 @@ show_help(void)
"r count pid  - renice process `pid' to nice value `count'\n"
"S- toggle the display of system processes\n"
"s time   - change delay between displays to `time' seconds\n"
+   "T [-]rtable  - show processes associated with routing table 
`rtable'\n"
+   "   (T+ shows all, T -rtable hides rtable)\n"
"u [-]user- show processes for `user' (u+ shows all, u -user 
hides user)\n"
"\n");
 
Index: machine.c
===
RCS file: /cvs/src/usr.bin/top/machine.c,v
retrieving revision 1.107
diff -u -p -r1.107 machine.c
--- machine.c   6 Jul 2020 16:27:59 -   1.107
+++ machine.c   9 Aug 2020 18:06:36 -
@@ -414,7 +414,7 @@ get_process_info(struct system_info *si,
 int (*compare) (const void *, const void *))
 {
int show_idle, show_system, show_threads, show_uid, show_pid, show_cmd;
-   int hide_uid;
+   int show_rtable, hide_rtable, hide_uid;
int total_procs, active_procs;
struct kinfo_proc **prefp, *pp;
int what = KERN_PROC_ALL;
@@ -446,6 +446,8 @@ get_process_info(struct system_info *si,
show_uid = sel->uid != (uid_t)-1;
hide_uid = sel->huid != (uid_t)-1;
show_pid = sel->pid != (pid_t)-1;
+   show_rtable = sel->rtableid != -1;
+   hide_rtable = sel->hrtableid != -1;
show_cmd = sel->command != NULL;
 
/* count up process states and get pointers to interesting procs */
@@ -474,6 +476,8 @@ get_process_info(struct system_info *si,
(!hide_uid || pp->p_ruid != sel->huid) &&
(!show_uid || pp->p_ruid == sel->uid) &&
(!show_pid || pp->p_pid == sel->pid) &&
+   (!hide_rtable || pp->p_rtableid != sel->hrtableid) 
&&
+   (!show_rtable || pp->p_rtableid == sel->rtableid) &&
(!show_cmd || cmd_matches(pp, sel->command))) {
*prefp++ = pp;
active_procs++;
Index: machine.h
===
RCS file: /cvs/src/usr.bin/top/machine.h,v
retrieving revision 1.29
diff -u -p -r1.29 machine.h
--- machine.h   25 Jun 2020 20:38:41 -  1.29
+++ machine.h   9 Aug 2020 17:50:14 -
@@ -77,6 +77,8 @@ struct process_select {
uid_t   uid;/* only this uid (unless uid == -1) */
uid_t   huid;   /* hide this uid (unless huid == -1) */
pid_t   pid;/* only this pid (unless pid == -1) */
+   int rtableid;   /* only this rtable (unless rtableid == 
-1) */
+   int hrtableid;  /* hide this rtable (unless hrtableid 
== -1) */
char   *command;/* only this command (unless == NULL) */
 };
 
Index: top.1
===
RCS file: /cvs/src/usr.bin/top/top.1,v
retrieving revision 1.75
diff -u -p -r1.75 top.1
--- top.1   26 Jul 2020 21:59:16 -  1.75
+++ top.1   9 Aug 2020 18:16:12 -
@@ -38,6 +38,7 @@
 .Op Fl o Oo - Oc Ns Ar field
 .Op Fl p Ar pid
 .Op Fl s Ar time
+.Op Fl T Oo - Oc Ns Ar rtable
 .Op Fl U Oo - Oc Ns Ar user
 .Op Ar number
 .Ek
@@ -179,6 +180,14 @@ Set the delay between screen updates to
 seconds.
 The value may be fractional, to permit delays of less than 1 second.
 The default delay between updates is 5 seconds.
+.It Fl T Oo - Oc Ns Ar rtable
+Display only processes associat

top: filter by routing table

2020-08-09 Thread Klemens Nanni
Sometimes I want to see processes outside the default routing table with
`-T -0', sometimes those in in a specific one with `-T 3' (for testing).

Since others have poked around with routing tables and/or domains as of
late, perhaps this deemed useful enough?

Semantically, filtering is identical to that of users: pick or hide one;
this makes the code pretty much copy/paste within top(1), manual wording
and command line flag is taken from pgrep(1).

pgrep is currently the only way to identify processes by routing table.
After netstat(1)'s relatively recent addition of `-R', filtering in top
makes for a quite handy set of tooling around rtable(4).

Feedback? OK?


Index: display.c
===
RCS file: /cvs/src/usr.bin/top/display.c,v
retrieving revision 1.63
diff -u -p -r1.63 display.c
--- display.c   26 Jul 2020 21:59:16 -  1.63
+++ display.c   9 Aug 2020 17:55:56 -
@@ -824,6 +824,8 @@ show_help(void)
"r count pid  - renice process `pid' to nice value `count'\n"
"S- toggle the display of system processes\n"
"s time   - change delay between displays to `time' seconds\n"
+   "T [-]rtable  - show processes associated with routing table 
`rtable'\n"
+   "   (T+ shows all, T -rtable hides rtable)\n"
"u [-]user- show processes for `user' (u+ shows all, u -user 
hides user)\n"
"\n");
 
Index: machine.c
===
RCS file: /cvs/src/usr.bin/top/machine.c,v
retrieving revision 1.107
diff -u -p -r1.107 machine.c
--- machine.c   6 Jul 2020 16:27:59 -   1.107
+++ machine.c   9 Aug 2020 18:06:36 -
@@ -414,7 +414,7 @@ get_process_info(struct system_info *si,
 int (*compare) (const void *, const void *))
 {
int show_idle, show_system, show_threads, show_uid, show_pid, show_cmd;
-   int hide_uid;
+   int show_rtable, hide_rtable, hide_uid;
int total_procs, active_procs;
struct kinfo_proc **prefp, *pp;
int what = KERN_PROC_ALL;
@@ -446,6 +446,8 @@ get_process_info(struct system_info *si,
show_uid = sel->uid != (uid_t)-1;
hide_uid = sel->huid != (uid_t)-1;
show_pid = sel->pid != (pid_t)-1;
+   show_rtable = sel->rtableid != -1;
+   hide_rtable = sel->hrtableid != -1;
show_cmd = sel->command != NULL;
 
/* count up process states and get pointers to interesting procs */
@@ -474,6 +476,8 @@ get_process_info(struct system_info *si,
(!hide_uid || pp->p_ruid != sel->huid) &&
(!show_uid || pp->p_ruid == sel->uid) &&
(!show_pid || pp->p_pid == sel->pid) &&
+   (!hide_rtable || pp->p_rtableid != sel->hrtableid) 
&&
+   (!show_rtable || pp->p_rtableid == sel->rtableid) &&
(!show_cmd || cmd_matches(pp, sel->command))) {
*prefp++ = pp;
active_procs++;
Index: machine.h
===
RCS file: /cvs/src/usr.bin/top/machine.h,v
retrieving revision 1.29
diff -u -p -r1.29 machine.h
--- machine.h   25 Jun 2020 20:38:41 -  1.29
+++ machine.h   9 Aug 2020 17:50:14 -
@@ -77,6 +77,8 @@ struct process_select {
uid_t   uid;/* only this uid (unless uid == -1) */
uid_t   huid;   /* hide this uid (unless huid == -1) */
pid_t   pid;/* only this pid (unless pid == -1) */
+   int rtableid;   /* only this rtable (unless rtableid == 
-1) */
+   int hrtableid;  /* hide this rtable (unless hrtableid 
== -1) */
char   *command;/* only this command (unless == NULL) */
 };
 
Index: top.1
===
RCS file: /cvs/src/usr.bin/top/top.1,v
retrieving revision 1.75
diff -u -p -r1.75 top.1
--- top.1   26 Jul 2020 21:59:16 -  1.75
+++ top.1   9 Aug 2020 18:16:12 -
@@ -38,6 +38,7 @@
 .Op Fl o Oo - Oc Ns Ar field
 .Op Fl p Ar pid
 .Op Fl s Ar time
+.Op Fl T Oo - Oc Ns Ar rtable
 .Op Fl U Oo - Oc Ns Ar user
 .Op Ar number
 .Ek
@@ -179,6 +180,14 @@ Set the delay between screen updates to
 seconds.
 The value may be fractional, to permit delays of less than 1 second.
 The default delay between updates is 5 seconds.
+.It Fl T Oo - Oc Ns Ar rtable
+Display only processes associated with the specified routing table
+.Ar rtable .
+.Sq T+
+shows processes associated with all routing tables.
+The
+.Sq -
+prefix hides proccesses associated with a single routing table.
 .It Fl U Oo - Oc Ns Ar user
 Show only those processes owned by username or UID
 .Ar user .
@@ -371,6 +380,14 @@ Toggle the display of system processes.
 Set the delay between screen updates to
 .Ar time
 seconds