diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2015-08-01 17:42:51 +0300 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2015-08-03 09:56:40 +0200 |
commit | 3fa0a5bab6049a269c535a75ed8b10d7dc3e1edc (patch) | |
tree | a3acc7b8204de93a1460ed0f40d6ebdeaebdf51e /flowtop.c | |
parent | e23a0ad4457fc8a0dc07c6c9c14764033a0b644a (diff) |
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 <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'flowtop.c')
-rw-r--r-- | flowtop.c | 40 |
1 files changed, 25 insertions, 15 deletions
@@ -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) |