summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrian <brian@cvs.openbsd.org>1999-02-04 11:54:50 +0000
committerbrian <brian@cvs.openbsd.org>1999-02-04 11:54:50 +0000
commit42c1969c1d3f1318f3d471c2b50731c630c123cb (patch)
treef9d5d553daded4ec86cb30f656231d697d6920b0
parentba0a2a7598cec80429adbc8dd4d6598555d74c73 (diff)
Change the timer routines so that they interrupt when the next
item is scheduled rather than interrupting 10 times per second and finding that there's nothing to do most of the time. This change reduces interrupt overheads but will expose any (previously small) latency problems. Be more careful about building VJ compression requests - we can't htonl/ntohl the entire four bytes ! Also, when we get a NAK, try to get as close as possible to what the peer NAKs with when sending our next REQ. Similarily when we send a NAK, pick values as close as possible to what the peer REQd. Fix a couple of man page typos (compliments of billf@FreeBSD.org)
-rw-r--r--usr.sbin/ppp/ppp/bundle.c4
-rw-r--r--usr.sbin/ppp/ppp/ipcp.c55
-rw-r--r--usr.sbin/ppp/ppp/ppp.86
-rw-r--r--usr.sbin/ppp/ppp/timer.c87
-rw-r--r--usr.sbin/ppp/ppp/timer.h4
5 files changed, 90 insertions, 66 deletions
diff --git a/usr.sbin/ppp/ppp/bundle.c b/usr.sbin/ppp/ppp/bundle.c
index 1d33308b4a6..398aacf17af 100644
--- a/usr.sbin/ppp/ppp/bundle.c
+++ b/usr.sbin/ppp/ppp/bundle.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: bundle.c,v 1.6 1999/01/06 00:10:02 brian Exp $
+ * $Id: bundle.c,v 1.7 1999/02/04 11:54:47 brian Exp $
*/
#include <sys/param.h>
@@ -1660,7 +1660,7 @@ bundle_setsid(struct bundle *bundle, int holdsession)
log_Printf(LogPHASE, "%d -> %d: %s session control\n",
(int)orig, (int)getpid(),
holdsession ? "Passed" : "Dropped");
- timer_InitService();
+ timer_InitService(0); /* Start the Timer Service */
break;
default:
close(fds[1]);
diff --git a/usr.sbin/ppp/ppp/ipcp.c b/usr.sbin/ppp/ppp/ipcp.c
index 6113885c1a0..83f1090c4aa 100644
--- a/usr.sbin/ppp/ppp/ipcp.c
+++ b/usr.sbin/ppp/ppp/ipcp.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: ipcp.c,v 1.5 1998/10/29 02:21:45 brian Exp $
+ * $Id: ipcp.c,v 1.6 1999/02/04 11:54:47 brian Exp $
*
* TODO:
* o More RFC1772 backward compatibility
@@ -598,7 +598,12 @@ IpcpSendConfigReq(struct fsm *fp)
ua_htons(&proto, o->data);
INC_LCP_OPT(TY_COMPPROTO, 4, o);
} else {
- ua_htonl(&ipcp->my_compproto, o->data);
+ struct compreq req;
+
+ req.proto = htons(ipcp->my_compproto >> 16);
+ req.slots = (ipcp->my_compproto >> 8) & 255;
+ req.compcid = ipcp->my_compproto & 1;
+ memcpy(o->data, &req, 4);
INC_LCP_OPT(TY_COMPPROTO, 6, o);
}
}
@@ -890,7 +895,9 @@ IpcpDecodeConfig(struct fsm *fp, u_char * cp, int plen, int mode_type,
break;
case TY_COMPPROTO:
- memcpy(&compproto, cp + 2, 4);
+ pcomp = (struct compreq *)(cp + 2);
+ compproto = (ntohs(pcomp->proto) << 16) + (pcomp->slots << 8) +
+ pcomp->compcid;
log_Printf(LogIPCP, "%s %s\n", tbuff, vj2asc(compproto));
switch (mode_type) {
@@ -899,11 +906,11 @@ IpcpDecodeConfig(struct fsm *fp, u_char * cp, int plen, int mode_type,
memcpy(dec->rejend, cp, length);
dec->rejend += length;
} else {
- pcomp = (struct compreq *) (cp + 2);
switch (length) {
case 4: /* RFC1172 */
if (ntohs(pcomp->proto) == PROTO_VJCOMP) {
- log_Printf(LogWARN, "Peer is speaking RFC1172 compression protocol !\n");
+ log_Printf(LogWARN, "Peer is speaking RFC1172 compression "
+ "protocol !\n");
ipcp->heis1172 = 1;
ipcp->peer_compproto = compproto;
memcpy(dec->ackend, cp, length);
@@ -916,18 +923,29 @@ IpcpDecodeConfig(struct fsm *fp, u_char * cp, int plen, int mode_type,
}
break;
case 6: /* RFC1332 */
- if (ntohs(pcomp->proto) == PROTO_VJCOMP
- && pcomp->slots <= MAX_VJ_STATES
- && pcomp->slots >= MIN_VJ_STATES) {
- ipcp->peer_compproto = compproto;
- ipcp->heis1172 = 0;
- memcpy(dec->ackend, cp, length);
- dec->ackend += length;
+ if (ntohs(pcomp->proto) == PROTO_VJCOMP) {
+ if (pcomp->slots <= MAX_VJ_STATES
+ && pcomp->slots >= MIN_VJ_STATES) {
+ /* Ok, we can do that */
+ ipcp->peer_compproto = compproto;
+ ipcp->heis1172 = 0;
+ memcpy(dec->ackend, cp, length);
+ dec->ackend += length;
+ } else {
+ /* Get as close as we can to what he wants */
+ ipcp->heis1172 = 0;
+ memcpy(dec->nakend, cp, 2);
+ pcomp->slots = pcomp->slots < MIN_VJ_STATES ?
+ MIN_VJ_STATES : MAX_VJ_STATES;
+ memcpy(dec->nakend+2, &pcomp, sizeof pcomp);
+ dec->nakend += length;
+ }
} else {
+ /* What we really want */
memcpy(dec->nakend, cp, 2);
pcomp->proto = htons(PROTO_VJCOMP);
pcomp->slots = DEF_VJ_STATES;
- pcomp->compcid = 0;
+ pcomp->compcid = 1;
memcpy(dec->nakend+2, &pcomp, sizeof pcomp);
dec->nakend += length;
}
@@ -941,9 +959,18 @@ IpcpDecodeConfig(struct fsm *fp, u_char * cp, int plen, int mode_type,
break;
case MODE_NAK:
+ if (ntohs(pcomp->proto) == PROTO_VJCOMP) {
+ if (pcomp->slots > MAX_VJ_STATES)
+ pcomp->slots = MAX_VJ_STATES;
+ else if (pcomp->slots < MIN_VJ_STATES)
+ pcomp->slots = MIN_VJ_STATES;
+ compproto = (ntohs(pcomp->proto) << 16) + (pcomp->slots << 8) +
+ pcomp->compcid;
+ } else
+ compproto = 0;
log_Printf(LogIPCP, "%s changing compproto: %08x --> %08x\n",
tbuff, ipcp->my_compproto, compproto);
- ipcp->my_compproto = compproto;
+ ipcp->my_compproto = compproto;
break;
case MODE_REJ:
diff --git a/usr.sbin/ppp/ppp/ppp.8 b/usr.sbin/ppp/ppp/ppp.8
index a8b3a137ed2..74a50e042fa 100644
--- a/usr.sbin/ppp/ppp/ppp.8
+++ b/usr.sbin/ppp/ppp/ppp.8
@@ -1,4 +1,4 @@
-.\" $Id: ppp.8,v 1.14 1999/01/19 22:21:43 brian Exp $
+.\" $Id: ppp.8,v 1.15 1999/02/04 11:54:48 brian Exp $
.Dd 20 September 1995
.nr XX \w'\fC00'
.Os FreeBSD
@@ -7,7 +7,7 @@
.Nm ppp
.Nd Point to Point Protocol (a.k.a. user-ppp)
.Sh SYNOPSIS
-.Nm ppp
+.Nm
.Oo
.Fl auto |
.Fl background |
@@ -1299,7 +1299,7 @@ to flush all rules.
.El
.Pp
See
-.Pa /etc/ppp/ppp.conf.example .
+.Pa /etc/ppp/ppp.conf.sample .
.Sh SETTING THE IDLE TIMER
To check/set the idle timer, use the
.Dq show bundle
diff --git a/usr.sbin/ppp/ppp/timer.c b/usr.sbin/ppp/ppp/timer.c
index b3028aea232..371cf58b2c2 100644
--- a/usr.sbin/ppp/ppp/timer.c
+++ b/usr.sbin/ppp/ppp/timer.c
@@ -17,11 +17,12 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: timer.c,v 1.1 1998/08/31 00:22:29 brian Exp $
+ * $Id: timer.c,v 1.2 1999/02/04 11:54:48 brian Exp $
*
* TODO:
*/
+#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <sys/time.h>
@@ -96,8 +97,8 @@ timer_Start(struct pppTimer * tp)
if (pt) {
pt->next = tp;
} else {
- timer_InitService();
TimerList = tp;
+ timer_InitService(0); /* Start the Timer Service */
}
if (t)
t->rest -= tp->rest;
@@ -143,7 +144,7 @@ StopTimerNoBlock(struct pppTimer * tp)
static void
TimerService(void)
{
- struct pppTimer *tp, *exp, *wt;
+ struct pppTimer *tp, *exp, *next;
if (log_IsKept(LogTIMER)) {
static time_t t; /* Only show timers globally every second */
@@ -153,43 +154,34 @@ TimerService(void)
timer_Show(LogTIMER, NULL);
t = n;
}
+
tp = TimerList;
if (tp) {
- tp->rest--;
- if (tp->rest == 0) {
-
- /*
- * Multiple timers may expires at once. Create list of expired timers.
- */
- exp = NULL;
- do {
- tp->state = TIMER_EXPIRED;
- wt = tp->next;
- tp->enext = exp;
- exp = tp;
- tp = wt;
- } while (tp && (tp->rest == 0));
-
- TimerList = tp;
- if (TimerList == NULL) /* No timers ? */
- timer_TermService(); /* Terminate Timer Service */
-
- /*
- * Process all expired timers.
- */
- while (exp) {
-#ifdef notdef
- timer_Stop(exp);
-#endif
- if (exp->func)
- (*exp->func) (exp->arg);
-
- /*
- * Just Removing each item from expired list And exp->enext will be
- * intialized at next expire in this funtion.
- */
- exp = exp->enext;
- }
+ tp->rest = 0;
+
+ /* Multiple timers might expire at once. Create a list of expired timers */
+ exp = NULL;
+ do {
+ tp->state = TIMER_EXPIRED;
+ next = tp->next;
+ tp->enext = exp;
+ exp = tp;
+ tp = next;
+ } while (tp && tp->rest == 0);
+
+ TimerList = tp;
+ if (TimerList != NULL) /* Any timers remaining ? */
+ timer_InitService(1); /* Restart the Timer Service */
+ else
+ timer_TermService(); /* Stop the Timer Service */
+
+ /* Process all expired timers */
+ while (exp) {
+ next = exp->enext;
+ exp->enext = NULL;
+ if (exp->func)
+ (*exp->func)(exp->arg);
+ exp = next;
}
}
}
@@ -223,15 +215,20 @@ timer_Show(int LogLevel, struct prompt *prompt)
}
void
-timer_InitService()
+timer_InitService(int restart)
{
struct itimerval itimer;
- sig_signal(SIGALRM, (void (*) (int)) TimerService);
- itimer.it_interval.tv_sec = itimer.it_value.tv_sec = 0;
- itimer.it_interval.tv_usec = itimer.it_value.tv_usec = TICKUNIT;
- if (setitimer(ITIMER_REAL, &itimer, NULL) == -1)
- log_Printf(LogERROR, "Unable to set itimer.\n");
+ if (TimerList) {
+ if (!restart)
+ sig_signal(SIGALRM, (void (*)(int))TimerService);
+ itimer.it_interval.tv_sec = 0;
+ itimer.it_interval.tv_usec = 0;
+ itimer.it_value.tv_sec = TimerList->rest / SECTICKS;
+ itimer.it_value.tv_usec = (TimerList->rest % SECTICKS) * TICKUNIT;
+ if (setitimer(ITIMER_REAL, &itimer, NULL) == -1)
+ log_Printf(LogERROR, "Unable to set itimer (%s)\n", sys_errlist[errno]);
+ }
}
void
@@ -242,6 +239,6 @@ timer_TermService(void)
itimer.it_interval.tv_usec = itimer.it_interval.tv_sec = 0;
itimer.it_value.tv_usec = itimer.it_value.tv_sec = 0;
if (setitimer(ITIMER_REAL, &itimer, NULL) == -1)
- log_Printf(LogERROR, "Unable to set itimer.\n");
+ log_Printf(LogERROR, "Unable to set itimer (%s)\n", sys_errlist[errno]);
sig_signal(SIGALRM, SIG_IGN);
}
diff --git a/usr.sbin/ppp/ppp/timer.h b/usr.sbin/ppp/ppp/timer.h
index d64e388136a..9de9a00f1bc 100644
--- a/usr.sbin/ppp/ppp/timer.h
+++ b/usr.sbin/ppp/ppp/timer.h
@@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: timer.h,v 1.1 1998/08/31 00:22:29 brian Exp $
+ * $Id: timer.h,v 1.2 1999/02/04 11:54:49 brian Exp $
*
* TODO:
*/
@@ -42,6 +42,6 @@ struct prompt;
extern void timer_Start(struct pppTimer *);
extern void timer_Stop(struct pppTimer *);
-extern void timer_InitService(void);
+extern void timer_InitService(int);
extern void timer_TermService(void);
extern void timer_Show(int LogLevel, struct prompt *);