From nobody@FreeBSD.ORG  Mon Jan 10 03:43:06 2000
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id 50CEF14C48; Mon, 10 Jan 2000 03:43:06 -0800 (PST)
Message-Id: <20000110114306.50CEF14C48@hub.freebsd.org>
Date: Mon, 10 Jan 2000 03:43:06 -0800 (PST)
From: pherman@piro.net
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@FreeBSD.org
Subject: Add an idletime counter for sppp, just like ppp has
X-Send-Pr-Version: www-1.0

>Number:         16023
>Category:       kern
>Synopsis:       Add an idletime counter for sppp, just like ppp has
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan 10 03:50:01 PST 2000
>Closed-Date:    Mon Aug 26 23:20:50 MEST 2002
>Last-Modified:  Mon Aug 26 23:20:50 MEST 2002
>Originator:     Paul Herman
>Release:        4.0 current
>Organization:
>Environment:
n/a
>Description:
Hi,

I'd like an idle time counter in sppp, just like ppp has.  The reason
for this is that i4b incorectly counts LCP control packets (like
LCP Echo-Request, and LCP Echo-Response) incorectly as "active" packets.

This can result in an idle PPP connection (no TCP/IP packets) which
stays indefinately open.

This is, of course, and i4b problem; However, to properly impliment a
fix for this, an idletime mechanism is required in the sppp stack.  I
stole the idea from ppp, and should be completely harmless -- I tested
them on 3.3-stable with no problems.  I'd be happy if the powers that be
could commit the patches below against 4.0-current.  :)

Thanks!
-Paul
>How-To-Repeat:
The i4b problem can be repeated by just connecting (via ISDN) to a PPP
Server which decides to send contiunous LCP Packets in the background,

...but again this is not an sppp problem, but i4b that should (will) be
fixed later with the help of this patch.

>Fix:
Patches (patched against 4.0-current):

******** CUT HERE ***********
--- src/sbin/spppcontrol/spppcontrol.c  Mon Jan 10 11:59:25 2000
+++ src/sbin/spppcontrol/spppcontrol.c.new      Mon Jan 10 12:06:13 2000
@@ -188,8 +188,10 @@

 void
 print_vals(const char *ifname, struct spppreq *sp)
 {
+       time_t send, recv;
+
        printf("%s:\tphase=%s\n", ifname, phase_name(sp->defs.pp_phase));
        if (sp->defs.myauth.proto) {
                printf("\tmyauthproto=%s myauthname=\"%.*s\"\n",
                       proto_name(sp->defs.myauth.proto),
@@ -200,8 +202,11 @@   
                       proto_name(sp->defs.hisauth.proto),
                       AUTHNAMELEN, sp->defs.hisauth.name,
                       authflags(sp->defs.hisauth.flags));
        }
+       send = time(NULL) - sp->defs.pp_last_sent;
+       recv = time(NULL) - sp->defs.pp_last_recv;
+       printf("\tidle_time=%ld\n", (send<recv)? send : recv);
 }

 const char *
 phase_name(enum ppp_phase phase)
--- src/sys/net/if_sppp.h       Mon Jan 10 11:57:57 2000
+++ src/sys/net/if_sppp.h.new   Mon Jan 10 12:11:16 2000
@@ -88,8 +88,10 @@
        u_short pp_alivecnt;    /* keepalive packets counter */
        u_short pp_loopcnt;     /* loopback detection counter */
        u_long  pp_seq;         /* local sequence number */
        u_long  pp_rseq;        /* remote sequence number */
+       time_t  pp_last_sent;   /* time() when the last packet was sent */
+       time_t  pp_last_recv;   /* time() when the last packet was received */
        enum ppp_phase pp_phase;        /* phase we're currently in */
        int     state[IDX_COUNT];       /* state machine */
        u_char  confid[IDX_COUNT];      /* id of last configuration request */
        int     rst_counter[IDX_COUNT]; /* restart counter */
--- src/sys/net/if_spppsubr.c   Mon Jan 10 11:58:08 2000
+++ src/sys/net/if_spppsubr.c.new       Mon Jan 10 12:16:38 2000
@@ -619,8 +619,9 @@
                                SPP_ARGS(ifp));
                goto drop;
        }
        IF_ENQUEUE(inq, m);
+       sp->pp_last_recv = time_second;
        splx(s);
 }
 
 /*
@@ -805,8 +806,9 @@
         * The packet length includes header, FCS and 1 flag,
         * according to RFC 1333.
         */
        ifp->if_obytes += m->m_pkthdr.len + 3;
+       sp->pp_last_sent = time_second;
        splx (s);
        return (0);
 }
 
@@ -838,8 +840,9 @@
        sp->pp_rseq = 0;
        sp->pp_phase = PHASE_DEAD;
        sp->pp_up = lcp.Up;
        sp->pp_down = lcp.Down;
+       sp->pp_last_recv = sp->pp_last_sent = time_second;
 
        sppp_lcp_init(sp);
        sppp_ipcp_init(sp);
        sppp_pap_init(sp);

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: joerg 
State-Changed-When: Mon Aug 26 23:02:39 MEST 2002 
State-Changed-Why:  
This is supposed to be fixed in -current and -stable's sppp, 
although a bit differently than your suggestion (mostly taken 
from the i4b line of fixes). 

Please verify that the problem you were describing is solved now, 
so we could close the PR.  Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=16023 
State-Changed-From-To: feedback->closed 
State-Changed-By: joerg 
State-Changed-When: Mon Aug 26 23:20:21 MEST 2002 
State-Changed-Why:  
Mail to originator bounces, so just assume the existing fix 
was appropriate anyway. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=16023 
>Unformatted:
