diff options
Diffstat (limited to 'flowtop.c')
-rw-r--r-- | flowtop.c | 42 |
1 files changed, 22 insertions, 20 deletions
@@ -48,8 +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 src_pkts, src_bytes; - uint64_t dst_pkts, dst_bytes; + uint64_t pkts_src, bytes_src; + uint64_t pkts_dst, bytes_dst; uint64_t timestamp_start, timestamp_stop; char country_src[128], country_dst[128]; char city_src[128], city_dst[128]; @@ -505,11 +505,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(src_pkts, ATTR_ORIG_COUNTER_PACKETS, 64); - CP_NFCT(src_bytes, ATTR_ORIG_COUNTER_BYTES, 64); + CP_NFCT(pkts_src, ATTR_ORIG_COUNTER_PACKETS, 64); + CP_NFCT(bytes_src, 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(pkts_dst, ATTR_REPL_COUNTER_PACKETS, 64); + CP_NFCT(bytes_dst, ATTR_REPL_COUNTER_BYTES, 64); CP_NFCT(timestamp_start, ATTR_TIMESTAMP_START, 64); CP_NFCT(timestamp_stop, ATTR_TIMESTAMP_STOP, 64); @@ -743,6 +743,18 @@ static char *bandw2str(double bytes, char *buf, size_t len) return buf; } +static void presenter_print_counters(uint64_t bytes, uint64_t pkts, int color) +{ + char bytes_str[64]; + + printw(" -> ("); + attron(COLOR_PAIR(color)); + printw("%"PRIu64" pkts, ", pkts); + printw("%s bytes", bandw2str(bytes, bytes_str, sizeof(bytes_str) - 1)); + attroff(COLOR_PAIR(color)); + printw(")"); +} + static void presenter_screen_do_line(WINDOW *screen, struct flow_entry *n, unsigned int *line) { @@ -826,13 +838,8 @@ 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)); - } + if (n->pkts_src > 0 && n->bytes_src > 0) + presenter_print_counters(n->bytes_src, n->pkts_src, 1); printw(" => "); } @@ -857,13 +864,8 @@ 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)); - } + if (n->pkts_dst > 0 && n->bytes_dst > 0) + presenter_print_counters(n->bytes_dst, n->pkts_dst, 2); } static inline bool presenter_flow_wrong_state(struct flow_entry *n) |