$NetBSD: patch-ag,v 1.2 2010/09/18 20:48:23 wiz Exp $

--- pftop.c.orig	2007-11-07 07:36:46 +0100
+++ pftop.c	2009-11-16 23:37:03 +0100
@@ -40,21 +40,41 @@
 #include <netinet/in.h>
 #define TCPSTATES
 #include <netinet/tcp_fsm.h>
+#ifdef __DragonFly__
+#include <net/pf/pfvar.h>
+#else
 #include <net/pfvar.h>
+#endif /* !__DragonFly__ */
 #include <arpa/inet.h>
 
 #ifdef HAVE_ALTQ
+#ifdef __DragonFly__
+#include <net/altq/altq.h>
+#include <net/altq/altq_cbq.h>
+#include <net/altq/altq_priq.h>
+#include <net/altq/altq_hfsc.h>
+#else
 #include <altq/altq.h>
 #include <altq/altq_cbq.h>
 #include <altq/altq_priq.h>
 #include <altq/altq_hfsc.h>
 #endif
 
+#ifdef ALTQT_FAIRQ
+#ifdef __DragonFly__
+#include <net/altq/altq_fairq.h>
+#else
+#include <altq/altq_fairq.h>
+#endif
+#endif
+#endif
+
 #include <ctype.h>
 #include <curses.h>
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <limits.h>
 #include <netdb.h>
 #include <signal.h>
 #include <stdio.h>
@@ -371,6 +391,9 @@
 	class_stats_t		cbq_stats;
 	struct priq_classstats	priq_stats;
 	struct hfsc_classstats	hfsc_stats;
+#ifdef ALTQT_FAIRQ
+	struct fairq_classstats fairq_stats;
+#endif
 };
 
 struct queue_stats {
@@ -736,7 +759,7 @@
 	} else {
 		num_states = 0;
 		for (n = 0; n<num_states_all; n++)
-			if (bpf_filter(filter_prog.bf_insns, (char *)(&state_buf[n]),
+			if (bpf_filter(filter_prog.bf_insns, (u_char *)(&state_buf[n]),
 			    sizeof(pf_state_t), sizeof(pf_state_t)) > 0)
 				state_ord[num_states++] = n;
 	}
@@ -828,7 +851,7 @@
 		tbprintf(" PAUSED");
 
 	if (rawmode)
-		printf("\n\n%s\n", tmp_buf);
+		printf("\n%s", tmp_buf);
 	else
 		mvprintw(0, 0, "%s", tmp_buf);
 
@@ -843,7 +866,10 @@
 		len = columns - strlen(tmp_buf);
 		if (len < 0)
 			len = 0;
-		mvprintw(0, len, "%s", tmp_buf);
+		if (rawmode)
+			printf(" %s\n", tmp_buf);
+		else
+			mvprintw(0, len, "%s", tmp_buf);
 	}
 
 	tb_end();
@@ -1244,7 +1270,6 @@
 		FLD_ANCHOR->max_width = mx;
 		FLD_ANCHOR->norm_width = nx;
 		field_setup();
-		need_update = 1;
 	}
 }
 #endif
@@ -1279,7 +1304,6 @@
 			FLD_LABEL->norm_width = nw;
 			FLD_LABEL->max_width = mw;
 			field_setup();
-			need_update = 1;
 		}
 	}
 #endif
@@ -1924,6 +1948,10 @@
 	    node->altq.scheduler == ALTQT_HFSC
 		)
 		print_fld_bw(FLD_BANDW, (double)node->altq.bandwidth);
+#ifdef ALTQT_FAIRQ
+	if (node->altq.scheduler == ALTQT_FAIRQ)
+		print_fld_bw(FLD_BANDW, (double)node->altq.bandwidth);
+#endif
 	
 	if (node->altq.priority != DEFAULT_PRIORITY)
 		print_fld_uint(FLD_PRIO,
@@ -1992,6 +2020,26 @@
 					node->qstats_last.data.hfsc_stats.xmit_cnt.bytes, interval);
 		}
 		break;
+#ifdef ALTQT_FAIRQ
+	case ALTQT_FAIRQ:
+		print_fld_str(FLD_SCHED, "fairq");
+		print_fld_size(FLD_PKTS,
+				node->qstats.data.fairq_stats.xmit_cnt.packets);
+		print_fld_size(FLD_BYTES,
+				node->qstats.data.fairq_stats.xmit_cnt.bytes);
+		print_fld_size(FLD_DROPP,
+				node->qstats.data.fairq_stats.drop_cnt.packets);
+		print_fld_size(FLD_DROPB,
+				node->qstats.data.fairq_stats.drop_cnt.bytes);
+		print_fld_size(FLD_QLEN, node->qstats.data.fairq_stats.qlength);
+		if (interval > 0) {
+			pps = calc_pps(node->qstats.data.fairq_stats.xmit_cnt.packets,
+					node->qstats_last.data.fairq_stats.xmit_cnt.packets, interval);
+			bps = calc_rate(node->qstats.data.fairq_stats.xmit_cnt.bytes,
+					node->qstats_last.data.fairq_stats.xmit_cnt.bytes, interval);
+		}
+		break;
+#endif
 	}
 
 	/* if (node->altq.scheduler != ALTQT_HFSC && interval > 0) { */
@@ -2041,11 +2089,9 @@
 	if (cachestates) {
 		show_field(FLD_SI);
 		show_field(FLD_SP);
-		gotsig_alarm = 1;
 	} else {
 		hide_field(FLD_SI);
 		hide_field(FLD_SP);
-		need_update = 1;
 	}
 	field_setup();
 }
@@ -2105,8 +2151,10 @@
 	line++;
 	mvprintw(line++, 6, "press any key to continue ...");
 
-	while (getch() == ERR);
-
+	timeout(-1);
+	while (getch() == ERR)
+		continue;
+	timeout(0);
 }
 
 
@@ -2142,7 +2190,6 @@
 	del = atoi(cmdbuf);
 	if (del > 0) {
 		delay = del;
-		gotsig_alarm = 1;
 	}
 }
 
@@ -2175,7 +2222,6 @@
 		/* FALLTHROUGH */
 	case 'h':
 		show_help();
-		need_update = 1;
 		break;
 	case 'n':
 		command_set(&cm_count, NULL);
@@ -2349,8 +2395,6 @@
 	if (rawmode && countmax == 0)
 		countmax = 1;
 
-	gotsig_alarm = 1;
-
 	engine_loop(countmax);
 
 	close(pf_dev);
