changeset 899:a1065c17429c

rvinterf: implement TCH hiding mode and -v option for verbose
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 12 Dec 2022 22:15:25 +0000
parents 203c025e71ab
children 8171c5c0d804
files rvinterf/lowlevel/Makefile rvinterf/lowlevel/logsent.c rvinterf/lowlevel/output.c rvinterf/lowlevel/rvifmain.c rvinterf/lowlevel/tchhide.c
diffstat 5 files changed, 77 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/lowlevel/Makefile	Sun Apr 03 19:09:21 2022 +0000
+++ b/rvinterf/lowlevel/Makefile	Mon Dec 12 22:15:25 2022 +0000
@@ -12,7 +12,7 @@
 
 RVINTERF_OBJS=	clientcmd.o format.o format_fc.o localsock.o logsent.o \
 		output.o packetrx.o packettx.o pktfwd.o rviflcd.o \
-		rvifmain.o
+		rvifmain.o tchhide.o
 
 TFC139_OBJS=	format.o output.o packetrx.o packettx.o tfc139.o
 
--- a/rvinterf/lowlevel/logsent.c	Sun Apr 03 19:09:21 2022 +0000
+++ b/rvinterf/lowlevel/logsent.c	Mon Dec 12 22:15:25 2022 +0000
@@ -9,6 +9,9 @@
 #include "../include/pktmux.h"
 #include "../include/limits.h"
 
+extern int no_output, verbose;
+extern FILE *logF;
+
 static void
 log_sent_ati(pkt, pktlen)
 	u_char *pkt;
@@ -72,6 +75,8 @@
 log_sent_packet(pkt, pktlen)
 	u_char *pkt;
 {
+	if (no_output && !logF)
+		return;
 	switch (pkt[0]) {
 	case RVT_L23_HEADER:
 		log_sent_gpf(pkt, pktlen);
@@ -79,7 +84,13 @@
 	case RVT_AT_HEADER:
 		log_sent_ati(pkt, pktlen);
 		return;
+	case RVT_TCH_HEADER:
+		if (verbose)
+			goto generic;
+		tch_inc_count_tx();
+		return;
 	default:
+	generic:
 		log_sent_other(pkt, pktlen);
 	}
 }
--- a/rvinterf/lowlevel/output.c	Sun Apr 03 19:09:21 2022 +0000
+++ b/rvinterf/lowlevel/output.c	Mon Dec 12 22:15:25 2022 +0000
@@ -14,6 +14,8 @@
 extern FILE *logF;
 extern time_t logtime;
 
+void (*output_hook)();
+
 static struct tm last_tm;
 
 void
@@ -22,6 +24,8 @@
 {
 	struct tm *curtm;
 
+	if (output_hook)
+		output_hook();
 	if (!no_output)
 		printf("%s\n", item);
 	if (!logF)
--- a/rvinterf/lowlevel/rvifmain.c	Sun Apr 03 19:09:21 2022 +0000
+++ b/rvinterf/lowlevel/rvifmain.c	Mon Dec 12 22:15:25 2022 +0000
@@ -27,7 +27,7 @@
 char *logfname;
 FILE *logF;
 time_t logtime;
-int background, no_output;
+int background, no_output, verbose;
 int max_fd;
 
 char *socket_pathname = "/tmp/rvinterf_socket";
@@ -64,7 +64,7 @@
 	fd_set fds;
 	struct client *cli, **clip;
 
-	while ((c = getopt(argc, argv, "bB:d:l:nP:s:S:w:X:")) != EOF)
+	while ((c = getopt(argc, argv, "bB:d:l:nP:s:S:vw:X:")) != EOF)
 		switch (c) {
 		case 'b':
 			background++;
@@ -91,6 +91,9 @@
 		case 'S':
 			socketpair_fd = atoi(optarg);
 			continue;
+		case 'v':
+			verbose++;
+			continue;
 		case 'w':
 			wakeup_after_sec = strtoul(optarg, 0, 0);
 			continue;
@@ -221,8 +224,12 @@
 			report_extui_packet();
 		return;
 	case RVT_TCH_HEADER:
-		if (!no_output || logF)
-			print_tch_output_raw();
+		if (!no_output || logF) {
+			if (verbose)
+				print_tch_output_raw();
+			else
+				tch_inc_count_rx();
+		}
 		if (client_head)
 			forward_nonrvt_pkt();
 		return;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/lowlevel/tchhide.c	Mon Dec 12 22:15:25 2022 +0000
@@ -0,0 +1,50 @@
+/*
+ * One of several FreeCalypso extensions to RVTMUX is TCH bit access
+ * logical channel, and we would like to handle it specially in rvinterf
+ * because it's extremely chatty, sending a frame every 20 ms.  If we
+ * were to output every TCH frame in our regular log, that log output
+ * becomes useless as everything else is drowned out.  Therefore, we
+ * implement a hiding mode by default: we only count how many TCH packets
+ * were exchanged in between other messages of interest, and report these
+ * counts.
+ */
+
+#include <stdio.h>
+
+extern void (*output_hook)();
+
+unsigned tch_rx_count, tch_tx_count;
+
+static void
+tch_report_hook()
+{
+	char msgbuf[80];
+
+	output_hook = 0;
+	if (tch_rx_count) {
+		sprintf(msgbuf, "TCH: received %u packet%s", tch_rx_count,
+			tch_rx_count != 1 ? "s" : "");
+		output_line(msgbuf);
+		tch_rx_count = 0;
+	}
+	if (tch_tx_count) {
+		sprintf(msgbuf, "TCH: sent %u packet%s", tch_tx_count,
+			tch_tx_count != 1 ? "s" : "");
+		output_line(msgbuf);
+		tch_tx_count = 0;
+	}
+}
+
+void
+tch_inc_count_rx()
+{
+	tch_rx_count++;
+	output_hook = tch_report_hook;
+}
+
+void
+tch_inc_count_tx()
+{
+	tch_tx_count++;
+	output_hook = tch_report_hook;
+}