Vitezslav Samel (3): othptab.c: fix window size calculation ipmon(): show packet captured count only when needed all: show dropped packet count
src/deskman.c | 6 ++++++ src/deskman.h | 1 + src/detstats.c | 5 +++++ src/hostmon.c | 6 +++++- src/ifstats.c | 7 ++++--- src/itrafmon.c | 7 ++++++- src/othptab.c | 2 +- src/packet.c | 13 +++++++++++++ src/packet.h | 1 + src/pktsize.c | 4 ++++ src/serv.c | 4 ++++ 11 files changed, 50 insertions(+), 6 deletions(-)
Fix window size miscalculation caused by integer rounding.
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/othptab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/othptab.c b/src/othptab.c index e23f39e..26de2a9 100644 --- a/src/othptab.c +++ b/src/othptab.c @@ -92,8 +92,8 @@ void init_othp_table(struct othptable *table) unsigned int wintop; unsigned int obmaxx __unused;
- winht = LINES - (LINES * 0.6) - 2; wintop = (LINES * 0.6) + 1; + winht = LINES - wintop - 2;
table->count = 0; table->lastpos = 0;
Don't print captured packet count after each packet receive, but only if screen update is needed.
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/itrafmon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/itrafmon.c b/src/itrafmon.c index 20c6f6c..56c181b 100644 --- a/src/itrafmon.c +++ b/src/itrafmon.c @@ -727,6 +727,7 @@ void ipmon(time_t facilitytime, char *ifptr) */
if (screen_update_needed(&tv, &updtime)) { + show_stats(statwin, total_pkts); update_panels(); doupdate();
@@ -948,7 +949,6 @@ void ipmon(time_t facilitytime, char *ifptr) continue;
total_pkts++; - show_stats(statwin, total_pkts);
pkt_result = packet_process(&pkt, &br, &sport, &dport,
Dropped packets are packets which were handled by an interface, but were not handled by our packet capturing interface. These drops are caused by e.g. packet bursts which overflow socket buffers or by excessive packet count which iptraf-ng cannot handle on given hardware.
Show this counter on each screen.
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/deskman.c | 6 ++++++ src/deskman.h | 1 + src/detstats.c | 5 +++++ src/hostmon.c | 6 +++++- src/ifstats.c | 7 ++++--- src/itrafmon.c | 5 +++++ src/packet.c | 13 +++++++++++++ src/packet.h | 1 + src/pktsize.c | 4 ++++ src/serv.c | 4 ++++ 10 files changed, 48 insertions(+), 4 deletions(-)
diff --git a/src/deskman.c b/src/deskman.c index ba73796..58c3c8d 100644 --- a/src/deskman.c +++ b/src/deskman.c @@ -190,6 +190,12 @@ void printlargenum(unsigned long long i, WINDOW * win) wprintw(win, "%8lluT", i / 1000000000000ULL); }
+void print_packet_drops(unsigned long count, WINDOW *win, int y, int x) +{ + wattrset(win, BOXATTR); + mvwprintw(win, y, x, " Dropped packets: %lu ", count); +} + int screen_update_needed(const struct timeval *now, const struct timeval *last) { unsigned long msecs = timeval_diff_msec(now, last); diff --git a/src/deskman.h b/src/deskman.h index 7536459..7f6a72f 100644 --- a/src/deskman.h +++ b/src/deskman.h @@ -17,6 +17,7 @@ void scrollkeyhelp(void); void stdexitkeyhelp(void); void indicate(char *message); void printlargenum(unsigned long long i, WINDOW * win); +void print_packet_drops(unsigned long count, WINDOW *win, int y, int x); int screen_update_needed(const struct timeval *now, const struct timeval *last); void infobox(char *text, char *prompt); void standardcolors(int color); diff --git a/src/detstats.c b/src/detstats.c index 646893f..d42f7ff 100644 --- a/src/detstats.c +++ b/src/detstats.c @@ -290,6 +290,8 @@ void detstats(char *iface, time_t facilitytime)
int fd;
+ unsigned long dropped = 0UL; + if (!dev_up(iface)) { err_iface_down(); return; @@ -399,6 +401,9 @@ void detstats(char *iface, time_t facilitytime) wattrset(statwin, BOXATTR); printelapsedtime(statbegin, now, LINES - 3, 1, statwin);
+ dropped += packet_get_dropped(fd); + print_packet_drops(dropped, statwin, LINES - 3, 49); + msecs = timeval_diff_msec(&tv, &start_tv);
rate_add_rate(&rate, span.proto_total.pc_bytes, msecs); diff --git a/src/hostmon.c b/src/hostmon.c index 44dcf40..5416ba9 100644 --- a/src/hostmon.c +++ b/src/hostmon.c @@ -173,7 +173,7 @@ static void initethtab(struct ethtab *table) mvwprintw(table->borderwin, 0, 70 * COLS / 80, " OutRate ");
mvwprintw(table->borderwin, LINES - 3, 40, - " InRate and OutRate are in %s ", dispmode(options.actmode)); + " Rates are in %s ", dispmode(options.actmode));
wattrset(table->tabwin, STDATTR); tx_colorwin(table->tabwin); @@ -758,6 +758,8 @@ void hostmon(time_t facilitytime, char *ifptr)
int fd;
+ unsigned long dropped = 0UL; + if (ifptr && !dev_up(ifptr)) { err_iface_down(); return; @@ -832,6 +834,8 @@ void hostmon(time_t facilitytime, char *ifptr) printelapsedtime(statbegin, now, LINES - 3, 15, table.borderwin); updateethrates(&table, msecs, idx); + dropped += packet_get_dropped(fd); + print_packet_drops(dropped, table.borderwin, LINES - 3, 62); tv_rate = tv; } if (logging) { diff --git a/src/ifstats.c b/src/ifstats.c index 2a5bba4..93529ac 100644 --- a/src/ifstats.c +++ b/src/ifstats.c @@ -363,9 +363,6 @@ static void initiftab(struct iftab *table) wtimeout(table->statwin, -1); wattrset(table->statwin, STDATTR); tx_colorwin(table->statwin); - wattrset(table->statwin, BOXATTR); - mvwprintw(table->borderwin, LINES - 3, 32 * COLS / 80, - " Total, IP, NonIP, and BadIP are packet counts "); }
/* @@ -427,6 +424,8 @@ void ifstats(time_t facilitytime)
int fd;
+ unsigned long dropped = 0UL; + struct timeval tv; time_t starttime = 0; time_t statbegin = 0; @@ -505,6 +504,8 @@ void ifstats(time_t facilitytime) showrates(&table); printelapsedtime(statbegin, now, LINES - 3, 1, table.borderwin); + dropped += packet_get_dropped(fd); + print_packet_drops(dropped, table.borderwin, LINES - 3, 49); starttime = now; start_tv = tv; } diff --git a/src/itrafmon.c b/src/itrafmon.c index 56c181b..5bb24ab 100644 --- a/src/itrafmon.c +++ b/src/itrafmon.c @@ -588,6 +588,8 @@ void ipmon(time_t facilitytime, char *ifptr)
int fd;
+ unsigned long dropped = 0UL; + int ch; int keymode = 0; char msgstring[80]; @@ -749,6 +751,9 @@ void ipmon(time_t facilitytime, char *ifptr) "No TCP entries "); } tv_rate = tv; + + dropped += packet_get_dropped(fd); + print_packet_drops(dropped, othptbl.borderwin, othptbl.obmaxy - 1, 49); }
/* diff --git a/src/packet.c b/src/packet.c index 4556516..ff4515c 100644 --- a/src/packet.c +++ b/src/packet.c @@ -329,6 +329,19 @@ again: return PACKET_OK; }
+unsigned int packet_get_dropped(int fd) +{ + struct tpacket_stats stats; + socklen_t len = sizeof(stats); + + memset(&stats, 0, len); + int err = getsockopt(fd, SOL_PACKET, PACKET_STATISTICS, &stats, &len); + if (err < 0) + die_errno("%s(): getsockopt(PACKET_STATISTICS)", __func__); + + return stats.tp_drops; +} + void pkt_cleanup(void) { destroyfraglist(); diff --git a/src/packet.h b/src/packet.h index 895d63b..2d7c98b 100644 --- a/src/packet.h +++ b/src/packet.h @@ -80,6 +80,7 @@ int packet_get(int fd, struct pkt_hdr *pkt, int *ch, WINDOW *win); int packet_process(struct pkt_hdr *pkt, unsigned int *total_br, in_port_t *sport, in_port_t *dport, int match_opposite, int v6inv4asv6); +unsigned int packet_get_dropped(int fd); void pkt_cleanup(void);
#endif /* IPTRAF_NG_PACKET_H */ diff --git a/src/pktsize.c b/src/pktsize.c index 54fb680..a99dd9f 100644 --- a/src/pktsize.c +++ b/src/pktsize.c @@ -164,6 +164,8 @@ void packet_size_breakdown(char *ifname, time_t facilitytime)
int fd;
+ unsigned long dropped = 0UL; + if (!dev_up(ifname)) { err_iface_down(); goto err_unmark; @@ -266,6 +268,8 @@ void packet_size_breakdown(char *ifname, time_t facilitytime) if (now - timeint >= 5) { printelapsedtime(starttime, now, LINES - 3, 1, borderwin); + dropped += packet_get_dropped(fd); + print_packet_drops(dropped, borderwin, LINES - 3, 49); timeint = now; } if (logging) { diff --git a/src/serv.c b/src/serv.c index c82bd3a..0481a1f 100644 --- a/src/serv.c +++ b/src/serv.c @@ -767,6 +767,8 @@ void servmon(char *ifname, time_t facilitytime)
int fd;
+ unsigned long dropped = 0UL; + struct porttab *ports;
if (!dev_up(ifname)) { @@ -871,6 +873,8 @@ void servmon(char *ifname, time_t facilitytime) if (list.barptr != NULL) print_serv_rates(list.barptr, statwin);
+ dropped += packet_get_dropped(fd); + print_packet_drops(dropped, list.borderwin, LINES - 4, 49); tv_rate = tv; }
iptraf-ng@lists.fedorahosted.org