Index: pf.c
===================================================================
RCS file: /cvs/src/sys/net/pf.c,v
retrieving revision 1.1095
diff -u -p -r1.1095 pf.c
--- pf.c	7 Dec 2020 08:29:41 -0000	1.1095
+++ pf.c	17 Dec 2020 19:39:28 -0000
@@ -4267,6 +4267,37 @@ pf_translate(struct pf_pdesc *pd, struct
 	return (rewrite);
 }
 
+
+void
+pf_lantecy_tcptrackfull( struct pf_state *state, struct tcphdr *th) {
+	struct pf_rule_item *mrm;
+	struct timeval lpexpire, deltatime;
+	
+	if (th->th_flags & TH_ACK && timerisset(&(state->lexpire)) )
+	{
+		getmicrouptime(&lpexpire);
+		timersub(&lpexpire, &(state->lexpire), &deltatime);
+		timerclear(&(state->lexpire));
+		if (deltatime.tv_usec != 0 || deltatime.tv_sec != 0 )
+			printf("PF LAG ACK: %lld : %lld . %ld LAG\n", state->id, deltatime.tv_sec, deltatime.tv_usec );
+
+		if ( timercmp(&(state->lsum), &deltatime, < ) )
+			state->lmax = deltatime;
+		timeradd(&(state->lsum), &deltatime, &(state->lsum));
+		state->lcount++;
+	} else {
+		if (state->rule.ptr != NULL && 0 == strcmp(state->rule.ptr->label,"WELP") ) {
+			getmicrouptime(&(state->lexpire));
+			return;
+		} 
+		SLIST_FOREACH(mrm,&((state)->match_rules), entry) 
+			if ( 0 == strcmp(mrm->r->label,"HELLO") ) {
+				getmicrouptime(&(state->lexpire));
+				return;
+			}
+	}
+}
+
 int
 pf_tcp_track_full(struct pf_pdesc *pd, struct pf_state **state, u_short *reason,
     int *copyback, int reverse)
@@ -4297,6 +4328,7 @@ pf_tcp_track_full(struct pf_pdesc *pd, s
 	} else
 		sws = dws = 0;
 
+	pf_lantecy_tcptrackfull(*state, th);
 	/*
 	 * Sequence tracking algorithm from Guido van Rooij's paper:
 	 *   http://www.madison-gurkha.com/publications/tcp_filtering/
Index: pfvar.h
===================================================================
RCS file: /cvs/src/sys/net/pfvar.h,v
retrieving revision 1.497
diff -u -p -r1.497 pfvar.h
--- pfvar.h	14 Oct 2020 19:22:14 -0000	1.497
+++ pfvar.h	17 Dec 2020 19:39:28 -0000
@@ -797,6 +797,11 @@ struct pf_state {
 	u_int16_t		 if_index_out;
 	pf_refcnt_t		 refcnt;
 	u_int16_t		 delay;
+//#if LATENCY_STATE
+	struct timeval		 lexpire; /* last non ack packet time */
+	struct timeval		 lmax;
+	struct timeval	 	 lsum;
+	u_int8_t		 lcount;
 };
 
 /*
