From 3fa0a5bab6049a269c535a75ed8b10d7dc3e1edc Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Sat, 1 Aug 2015 17:42:51 +0300 Subject: flowtop: Show counters by direction Show bytes/pkts counters per src/dst direction. By default counters originated from dst are showed. Src counters are showed only if '-s' is specified. Signed-off-by: Vadim Kochan Signed-off-by: Tobias Klauser --- flowtop.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/flowtop.c b/flowtop.c index 16c8b68..492d77a 100644 --- a/flowtop.c +++ b/flowtop.c @@ -48,7 +48,8 @@ struct flow_entry { uint32_t ip6_src_addr[4], ip6_dst_addr[4]; uint16_t port_src, port_dst; uint8_t tcp_state, tcp_flags, sctp_state, dccp_state; - uint64_t counter_pkts, counter_bytes; + uint64_t src_pkts, src_bytes; + uint64_t dst_pkts, dst_bytes; uint64_t timestamp_start, timestamp_stop; char country_src[128], country_dst[128]; char city_src[128], city_dst[128]; @@ -494,8 +495,11 @@ static void flow_entry_from_ct(struct flow_entry *n, struct nf_conntrack *ct) CP_NFCT(sctp_state, ATTR_SCTP_STATE, 8); CP_NFCT(dccp_state, ATTR_DCCP_STATE, 8); - CP_NFCT(counter_pkts, ATTR_ORIG_COUNTER_PACKETS, 64); - CP_NFCT(counter_bytes, ATTR_ORIG_COUNTER_BYTES, 64); + CP_NFCT(src_pkts, ATTR_ORIG_COUNTER_PACKETS, 64); + CP_NFCT(src_bytes, ATTR_ORIG_COUNTER_BYTES, 64); + + CP_NFCT(dst_pkts, ATTR_REPL_COUNTER_PACKETS, 64); + CP_NFCT(dst_bytes, ATTR_REPL_COUNTER_BYTES, 64); CP_NFCT(timestamp_start, ATTR_TIMESTAMP_START, 64); CP_NFCT(timestamp_stop, ATTR_TIMESTAMP_STOP, 64); @@ -785,18 +789,8 @@ static void presenter_screen_do_line(WINDOW *screen, struct flow_entry *n, printw(":%s", pname); attroff(A_BOLD); } - printw(" ->"); - - /* Number packets, bytes */ - if (n->counter_pkts > 0 && n->counter_bytes > 0) { - char bytes_str[64]; - - printw(" (%"PRIu64" pkts, %s bytes) ->", n->counter_pkts, - bandw2str(n->counter_bytes, bytes_str, - sizeof(bytes_str) - 1)); - } - /* Show source information: reverse DNS, port, country, city */ + /* Show source information: reverse DNS, port, country, city, counters */ if (show_src) { attron(COLOR_PAIR(1)); mvwprintw(screen, ++(*line), 8, "src: %s", n->rev_dns_src); @@ -817,10 +811,18 @@ static void presenter_screen_do_line(WINDOW *screen, struct flow_entry *n, printw(")"); } + if (n->src_pkts > 0 && n->src_bytes > 0) { + char bytes_str[64]; + + printw(" -> (%"PRIu64" pkts, %s bytes)", n->src_pkts, + bandw2str(n->src_bytes, bytes_str, + sizeof(bytes_str) - 1)); + } + printw(" => "); } - /* Show dest information: reverse DNS, port, country, city */ + /* Show dest information: reverse DNS, port, country, city, counters */ attron(COLOR_PAIR(2)); mvwprintw(screen, ++(*line), 8, "dst: %s", n->rev_dns_dst); attroff(COLOR_PAIR(2)); @@ -839,6 +841,14 @@ static void presenter_screen_do_line(WINDOW *screen, struct flow_entry *n, printw(")"); } + + if (n->dst_pkts > 0 && n->dst_bytes > 0) { + char bytes_str[64]; + + printw(" -> (%"PRIu64" pkts, %s bytes)", n->dst_pkts, + bandw2str(n->dst_bytes, bytes_str, + sizeof(bytes_str) - 1)); + } } static inline bool presenter_flow_wrong_state(struct flow_entry *n) -- cgit v1.2.3-54-g00ecf