Add command 'a' to show only active flows with rate > 0 (dst or src).
Now 'n->is_visible' means which flow to show by presenter.

Signed-off-by: Vadim Kochan <vadi...@gmail.com>
---
 flowtop.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/flowtop.c b/flowtop.c
index a70899a..e84d7e1 100644
--- a/flowtop.c
+++ b/flowtop.c
@@ -127,6 +127,7 @@ static bool show_src = false;
 static bool resolve_dns = true;
 static bool resolve_geoip = true;
 static enum rate_units rate_type = RATE_BYTES;
+static bool show_active_only = false;
 
 static const char *short_options = "vhTUsDIS46ut:nGb";
 static const struct option long_options[] = {
@@ -374,6 +375,8 @@ static void flow_list_new_entry(struct flow_list *fl, const 
struct nf_conntrack
 
        rcu_assign_pointer(n->next, fl->head);
        rcu_assign_pointer(fl->head, n);
+
+       n->is_visible = true;
 }
 
 static struct flow_entry *flow_list_find_id(struct flow_list *fl,
@@ -1103,11 +1106,12 @@ static void draw_flows(WINDOW *screen, struct flow_list 
*fl,
 
        n = rcu_dereference(fl->head);
        if (!n)
-               mvwprintw(screen, line, 2, "(No active sessions! "
+               mvwprintw(screen, line, 2, "(No sessions! "
                          "Is netfilter running?)");
 
        for (; n; n = rcu_dereference(n->next)) {
-               n->is_visible = false;
+               if (!n->is_visible)
+                       continue;
 
                if (presenter_flow_wrong_state(n))
                        continue;
@@ -1123,8 +1127,6 @@ static void draw_flows(WINDOW *screen, struct flow_list 
*fl,
                        continue;
                }
 
-               n->is_visible = true;
-
                draw_flow_entry(screen, n, &line);
 
                line++;
@@ -1186,6 +1188,7 @@ static void draw_help(WINDOW *screen)
        attroff(A_BOLD | A_UNDERLINE);
 
        mvaddnstr(row + 12, col + 3, "b             Change rate units 
(bits/bytes)", -1);
+       mvaddnstr(row + 13, col + 3, "a             Enable/disable only active 
flows (rate > 0)", -1);
 }
 
 static void draw_footer(WINDOW *screen)
@@ -1251,6 +1254,9 @@ static void presenter(void)
                        else
                                rate_type = RATE_BYTES;
                        break;
+               case 'a':
+                       show_active_only = !show_active_only;
+                       break;
                case '?':
                        if (show_help)
                                show_help = false;
@@ -1382,6 +1388,14 @@ static void conntrack_tstamp_enable(void)
        }
 }
 
+static void flow_entry_filter(struct flow_entry *n)
+{
+       if (show_active_only && !n->rate_bytes_src && !n->rate_bytes_dst)
+               n->is_visible = false;
+       else
+               n->is_visible = true;
+}
+
 static int flow_update_cb(enum nf_conntrack_msg_type type,
                          struct nf_conntrack *ct, void *data __maybe_unused)
 {
@@ -1400,6 +1414,7 @@ static int flow_update_cb(enum nf_conntrack_msg_type type,
        flow_entry_calc_rate(n, ct);
        flow_entry_update_time(n);
        flow_entry_from_ct(n, ct);
+       flow_entry_filter(n);
 
        return NFCT_CB_CONTINUE;
 }
@@ -1409,12 +1424,8 @@ static void collector_refresh_flows(struct nfct_handle 
*handle)
        struct flow_entry *n;
 
        n = rcu_dereference(flow_list.head);
-       for (; n; n = rcu_dereference(n->next)) {
-               if (!n->is_visible)
-                       continue;
-
+       for (; n; n = rcu_dereference(n->next))
                nfct_query(handle, NFCT_Q_GET, n->ct);
-       }
 }
 
 static void collector_create_filter(struct nfct_handle *nfct)
-- 
2.6.1

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to