summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoramurai <amurai@FreeBSD.org>1995-03-11 15:18:55 +0000
committeramurai <amurai@FreeBSD.org>1995-03-11 15:18:55 +0000
commit4e41b74b9d21768a96f51254ed346d04bb4405af (patch)
tree37ea926bbfbf0a7fb4adb214f5262d8872ba5a52
parent9b4b6386ecfab11f456999cadd482f36e97e6938 (diff)
downloadFreeBSD-src-4e41b74b9d21768a96f51254ed346d04bb4405af.zip
FreeBSD-src-4e41b74b9d21768a96f51254ed346d04bb4405af.tar.gz
1.Reducing cpu usage at off connection.
2.Implment Redail function as working correctly. 3.Clean up a code as I notice. 4.Now, RTT getting close to 50ms with ISDN/TA 38400bps !! Reviewed by: amurai@spec.co.jp Submitted by: amurai@spec.co.jp
-rw-r--r--usr.sbin/ppp/chat.c3
-rw-r--r--usr.sbin/ppp/filter.h6
-rw-r--r--usr.sbin/ppp/ip.c23
-rw-r--r--usr.sbin/ppp/ipcp.c4
-rw-r--r--usr.sbin/ppp/lcp.c4
-rw-r--r--usr.sbin/ppp/main.c126
-rw-r--r--usr.sbin/ppp/modem.c6
-rw-r--r--usr.sbin/ppp/timeout.h4
-rw-r--r--usr.sbin/ppp/timer.c42
-rw-r--r--usr.sbin/ppp/uucplock.c2
-rw-r--r--usr.sbin/ppp/vars.h4
11 files changed, 138 insertions, 86 deletions
diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c
index 5a79a0e..0fba4cf 100644
--- a/usr.sbin/ppp/chat.c
+++ b/usr.sbin/ppp/chat.c
@@ -18,11 +18,12 @@
* Columbus, OH 43221
* (614)451-1883
*
- * $Id:$
+ * $Id: chat.c,v 1.2 1995/02/26 12:17:20 amurai Exp $
*
* TODO:
* o Support more UUCP compatible control sequences.
* o Dialing shoud not block monitor process.
+ * o Reading modem by select should be unified into main.c
*/
#include "defs.h"
#include <ctype.h>
diff --git a/usr.sbin/ppp/filter.h b/usr.sbin/ppp/filter.h
index 848555d..9a5132b 100644
--- a/usr.sbin/ppp/filter.h
+++ b/usr.sbin/ppp/filter.h
@@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id:$
+ * $Id: filter.h,v 1.2 1995/02/26 12:17:26 amurai Exp $
*
* TODO:
*/
@@ -70,6 +70,10 @@ struct filterent {
#define MAXFILTERS 20
+#define FL_IN 0
+#define FL_OUT 1
+#define FL_DIAL 2
+#define FL_KEEP 3
struct filterent ifilters[MAXFILTERS];
struct filterent ofilters[MAXFILTERS];
struct filterent dfilters[MAXFILTERS];
diff --git a/usr.sbin/ppp/ip.c b/usr.sbin/ppp/ip.c
index 9e2ad62..c0dd7e8 100644
--- a/usr.sbin/ppp/ip.c
+++ b/usr.sbin/ppp/ip.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id:$
+ * $Id: ip.c,v 1.2 1995/02/26 12:17:33 amurai Exp $
*
* TODO:
* o Return ICMP message for filterd packet
@@ -75,7 +75,6 @@ static void
RestartIdleTimer()
{
if (!(mode & MODE_DEDICATED) && ipKeepAlive ) {
-/* StopTimer(&IdleTimer); */
StartTimer(&IdleTimer);
ipIdleSecs = 0;
}
@@ -301,7 +300,7 @@ int direction;
if (direction == 0) IcmpError(pip, pri);
return(-1);
} else {
- if ( FilterCheck(pip, 3) & A_DENY ) { /* Check Keep Alive filter */
+ if ( FilterCheck(pip, FL_KEEP ) & A_DENY ) { /* Check Keep Alive filter */
ipKeepAlive = FALSE;
} else {
ipKeepAlive = TRUE;
@@ -327,7 +326,7 @@ struct mbuf *bp; /* IN: Pointer to IP pakcet */
nb += wp->cnt;
}
- if (PacketCheck(tunbuff, nb, 0) < 0) {
+ if ( PacketCheck(tunbuff, nb, FL_IN ) < 0) {
pfree(bp);
return;
}
@@ -355,7 +354,7 @@ int cnt; /* IN: Length of packet */
if (IpcpFsm.state != ST_OPENED)
return;
- pri = PacketCheck(ptr, cnt, 1);
+ pri = PacketCheck(ptr, cnt, FL_OUT);
if (pri >= 0) {
bp = mballoc(cnt, MB_IPIN);
bcopy(ptr, MBUF_CTOP(bp), cnt);
@@ -380,6 +379,20 @@ int count;
Enqueue(&IpOutputQueues[pri], bp);
}
+int
+IsIpEnqueued()
+{
+ struct mqueue *queue;
+ int exist = FALSE;
+ for (queue = &IpOutputQueues[PRI_URGENT]; queue >= IpOutputQueues; queue--) {
+ if ( queue->qlen > 0 ) {
+ exist = TRUE;
+ break;
+ }
+ }
+ return( exist );
+}
+
void
IpStartOutput()
{
diff --git a/usr.sbin/ppp/ipcp.c b/usr.sbin/ppp/ipcp.c
index e13fa20..c8cb6ae 100644
--- a/usr.sbin/ppp/ipcp.c
+++ b/usr.sbin/ppp/ipcp.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id:$
+ * $Id: ipcp.c,v 1.2 1995/02/26 12:17:33 amurai Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@@ -53,7 +53,7 @@ static void IpcpLayerUp __P((struct fsm *));
static void IpcpLayerDown __P((struct fsm *));
static void IpcpInitRestartCounter __P((struct fsm *));
-static struct pppTimer IpcpReportTimer;
+struct pppTimer IpcpReportTimer;
static int lastInOctets, lastOutOctets;
diff --git a/usr.sbin/ppp/lcp.c b/usr.sbin/ppp/lcp.c
index e8ffa7f..0f7d9b1 100644
--- a/usr.sbin/ppp/lcp.c
+++ b/usr.sbin/ppp/lcp.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id:$
+ * $Id: lcp.c,v 1.2 1995/02/26 12:17:35 amurai Exp $
*
* TODO:
* o Validate magic number received from peer.
@@ -44,6 +44,7 @@ extern void Prompt();
extern void StopIdleTimer();
extern void OsLinkdown();
extern void Cleanup();
+extern struct pppTimer IpcpReportTimer;
struct lcpstate LcpInfo;
@@ -322,6 +323,7 @@ static void
StopAllTimers()
{
StopTimer(&LcpReportTimer);
+ StopTimer(&IpcpReportTimer);
StopIdleTimer();
StopTimer(&AuthPapInfo.authtimer);
StopTimer(&AuthChapInfo.authtimer);
diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c
index e30ab40..3f8126f 100644
--- a/usr.sbin/ppp/main.c
+++ b/usr.sbin/ppp/main.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: main.c,v 1.2 1995/02/26 12:17:41 amurai Exp $
+ * $Id: main.c,v 1.3 1995/02/27 10:57:50 amurai Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@@ -40,6 +40,7 @@
#include "ipcp.h"
#include "vars.h"
#include "auth.h"
+#include "filter.h"
#define LAUTH_M1 "Warning: No password entry for this host in ppp.secret\n"
#define LAUTH_M2 "Warning: All manipulation is allowed by anyone in a world\n"
@@ -551,7 +552,7 @@ DoLoop()
int ssize = sizeof(hisaddr);
u_char *cp;
u_char rbuff[MAX_MRU];
- struct itimerval itimer;
+ int dial_up;
if (mode & MODE_DIRECT) {
modem = OpenModem(mode);
@@ -564,20 +565,50 @@ DoLoop()
fflush(stdout);
- timeout.tv_sec = 0;;
#ifdef SIGALRM
- 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;
- setitimer(ITIMER_REAL, &itimer, NULL);
+ timeout.tv_sec = 0;
#else
timeout.tv_usec = 0;
#endif
+ dial_up = FALSE; /* XXXX */
for (;;) {
- IpStartOutput();
+ if ( modem )
+ IpStartOutput();
FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&efds);
- FD_SET(tun_in, &rfds);
+
+ /*
+ * If Ip packet for output is enqueued and require dial up,
+ * Just do it!
+ */
+ if ( dial_up && RedialTimer.state != TIMER_RUNNING ) { /* XXX */
+#ifdef DEBUG
+ logprintf("going to dial: modem = %d\n", modem);
+#endif
+ modem = OpenModem(mode);
+ if (modem < 0) {
+ modem = 0; /* Set intial value for next OpenModem */
+ StartRedialTimer();
+ } else {
+ if (DialModem()) {
+ sleep(1); /* little pause to allow peer starts */
+ ModemTimeout();
+ PacketMode();
+ dial_up = FALSE;
+ } else {
+ CloseModem();
+ /* Dial failed. Keep quite during redial wait period. */
+ StartRedialTimer();
+ }
+ }
+ }
+ if (modem) {
+ FD_SET(modem, &rfds);
+ FD_SET(modem, &efds);
+ if (ModemQlen() > 0) {
+ FD_SET(modem, &wfds);
+ }
+ }
if (server > 0) FD_SET(server, &rfds);
/* *** IMPORTANT ***
@@ -592,38 +623,40 @@ DoLoop()
TimerService();
#endif
- if (modem) {
- FD_SET(modem, &rfds);
- FD_SET(modem, &efds);
- if (ModemQlen() > 0) {
- FD_SET(modem, &wfds);
- }
- }
+ FD_SET(tun_in, &rfds);
if (netfd > -1) {
FD_SET(netfd, &rfds);
FD_SET(netfd, &efds);
}
+
+
#ifndef SIGALRM
/*
- * Normally, slect() will not block because modem is writable.
- * In AUTO mode, select will block until we find packet from tun.
- * However, we have to run ourselves while we are in redial wait state.
+ * Normally, select() will not block because modem is writable.
+ * In AUTO mode, select will block until we find packet from tun
*/
tp = (RedialTimer.state == TIMER_RUNNING)? &timeout : NULL;
i = select(tun_in+10, &rfds, &wfds, &efds, tp);
#else
+ /*
+ * When SIGALRM timer is running, a select function will be
+ * return -1 and EINTR after a Time Service signal hundler
+ * is done.
+ */
i = select(tun_in+10, &rfds, &wfds, &efds, NULL);
#endif
- if (i == 0) {
- continue;
+ if ( i == 0 ) {
+ continue;
}
- if (i < 0) {
- if (errno == EINTR)
- continue;
- perror("select");
- break;
- }
+ if ( i < 0 ) {
+ if ( errno == EINTR ) {
+ continue; /* Got SIGALRM, Do check a queue for dailing */
+ }
+ perror("select");
+ break;
+ }
+
if ((netfd > 0 && FD_ISSET(netfd, &efds)) || FD_ISSET(modem, &efds)) {
logprintf("Exception detected.\n");
break;
@@ -707,13 +740,14 @@ DoLoop()
}
}
}
+
if (FD_ISSET(tun_in, &rfds)) { /* something to read from tun */
/*
* If there are many packets queued, wait until they are drained.
*/
if (ModemQlen() > 5)
continue;
-
+
n = read(tun_in, rbuff, sizeof(rbuff));
if (n < 0) {
perror("read from tun");
@@ -724,47 +758,17 @@ DoLoop()
* device until IPCP is opened.
*/
if (LcpFsm.state <= ST_CLOSED && (mode & MODE_AUTO)) {
- pri = PacketCheck(rbuff, n, 2);
+ pri = PacketCheck(rbuff, n, FL_DIAL);
if (pri >= 0) {
- if (RedialTimer.state == TIMER_RUNNING) {
- /*
- * We are in redial wait state. Ignore packet.
- */
- continue;
- }
- modem = OpenModem(mode);
-#ifdef DEBUG
- logprintf("going to dial: modem = %d\n", modem);
-#endif
- if (modem < 0) {
- printf("failed to open modem.\n");
- Cleanup(EX_MODEM);
- }
-
- if (DialModem()) {
- sleep(1); /* little pause to allow peer starts */
- ModemTimeout();
- PacketMode();
- } else {
- CloseModem();
- /* Dial failed. Keep quite during redial wait period. */
- /* XXX: We shoud implement re-dial */
- StartRedialTimer();
- continue;
- }
IpEnqueue(pri, rbuff, n);
+ dial_up = TRUE; /* XXX */
}
continue;
}
- pri = PacketCheck(rbuff, n, 1);
+ pri = PacketCheck(rbuff, n, FL_OUT);
if (pri >= 0)
IpEnqueue(pri, rbuff, n);
}
}
-#ifdef SIGALRM
- itimer.it_value.tv_usec = itimer.it_value.tv_sec = 0;
- setitimer(ITIMER_REAL, &itimer, NULL);
- signal(SIGALRM, SIG_DFL);
-#endif
logprintf("job done.\n");
}
diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c
index 56a73ba..b056a83 100644
--- a/usr.sbin/ppp/modem.c
+++ b/usr.sbin/ppp/modem.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: modem.c,v 1.2 1995/02/26 12:17:45 amurai Exp $
+ * $Id: modem.c,v 1.3 1995/02/27 10:57:54 amurai Exp $
*
* TODO:
*/
@@ -375,12 +375,12 @@ int mode;
if (strncmp(VarDevice, "/dev", 4) == 0) {
strcpy(uucplock, rindex(VarDevice, '/')+1);
if (uu_lock(uucplock) < 0) {
- fprintf(stderr, "modem is in use.\n");
+ LogPrintf(LOG_PHASE, "Modem %s is in use\n", VarDevice);
return(-1);
}
modem = open(VarDevice, O_RDWR|O_NONBLOCK);
if (modem < 0) {
- perror("open modem");
+ LogPrintf(LOG_PHASE, "Open Failed %s\n", VarDevice);
return(modem);
}
} else {
diff --git a/usr.sbin/ppp/timeout.h b/usr.sbin/ppp/timeout.h
index 2fe9d28..cc7285d 100644
--- a/usr.sbin/ppp/timeout.h
+++ b/usr.sbin/ppp/timeout.h
@@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: timeout.h,v 1.2 1995/02/26 12:18:00 amurai Exp $
+ * $Id: timeout.h,v 1.4 1995/02/27 03:18:28 amurai Exp $
*
* TODO:
*/
@@ -46,5 +46,7 @@ struct pppTimer *TimerList;
extern void StartTimer __P((struct pppTimer *));
extern void StopTimer __P((struct pppTimer *));
extern void TimerService __P((void));
+extern void InitTimerService __P((void));
+extern void TermTimerService __P((void));
extern void StartIdleTimer __P((void));
#endif /* _TIMEOUT_H_ */
diff --git a/usr.sbin/ppp/timer.c b/usr.sbin/ppp/timer.c
index 3792103..b91fbcd 100644
--- a/usr.sbin/ppp/timer.c
+++ b/usr.sbin/ppp/timer.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id:$
+ * $Id: timer.c,v 1.2 1995/02/26 12:18:01 amurai Exp $
*
* TODO:
*/
@@ -85,8 +85,10 @@ struct pppTimer *tp;
tp->next = t;
if (pt) {
pt->next = tp;
- } else
+ } else {
+ InitTimerService();
TimerList = tp;
+ }
if (t)
t->rest -= tp->rest;
@@ -120,10 +122,13 @@ struct pppTimer *tp;
for (t = TimerList; t != tp && t !=NULL ; t = t->next)
pt = t;
if (t) {
- if (pt)
+ if (pt) {
pt->next = t->next;
- else
+ } else {
TimerList = t->next;
+ if ( TimerList == NULL ) /* Last one ? */
+ TermTimerService(); /* Terminate Timer Service */
+ }
if (t->next)
t->next->rest += tp->rest;
} else {
@@ -160,6 +165,8 @@ TimerService()
} while (tp && (tp->rest == 0));
TimerList = tp;
+ if ( TimerList == NULL ) /* No timers ? */
+ TermTimerService(); /* Terminate Timer Service */
#ifdef DEBUG
logprintf("TimerService: next is %x(%d)\n",
TimerList, TimerList? TimerList->rest : 0);
@@ -222,9 +229,6 @@ u_int sleep( u_int sec )
/* Calculate timeout value for select */
to.tv_sec = sld / 1000000;
to.tv_usec = sld % 1000000;
-
- /* Forwarding signal as normal */
- kill(getpid(), SIGALRM);
}
}
}
@@ -255,9 +259,29 @@ void usleep( u_int usec)
to.tv_sec = sld / 1000000;
to.tv_usec = sld % 1000000;
- /* Forwarding signal as normal */
- kill(getpid(), SIGALRM);
}
}
}
+
+void InitTimerService( void ) {
+ struct itimerval itimer;
+
+ 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;
+ setitimer(ITIMER_REAL, &itimer, NULL);
+}
+
+void TermTimerService( void ) {
+ struct itimerval itimer;
+
+ itimer.it_interval.tv_sec = itimer.it_value.tv_sec = 0;
+ itimer.it_value.tv_usec = itimer.it_value.tv_sec = 0;
+ setitimer(ITIMER_REAL, &itimer, NULL);
+ /*
+ * Notes: after disabling timer here, we will get one
+ * SIGALRM will be got.
+ */
+ signal(SIGALRM, SIG_IGN);
+}
#endif
diff --git a/usr.sbin/ppp/uucplock.c b/usr.sbin/ppp/uucplock.c
index c066ca72..455c8c4 100644
--- a/usr.sbin/ppp/uucplock.c
+++ b/usr.sbin/ppp/uucplock.c
@@ -87,7 +87,7 @@ uu_lock(ttyname)
* The process that locked the file isn't running, so
* we'll lock it ourselves
*/
- if (lseek(fd, 0L, L_SET) < 0) {
+ if (lseek(fd, (off_t) 0, L_SET) < 0) {
(void)close(fd);
perror("lock lseek");
return(-1);
diff --git a/usr.sbin/ppp/vars.h b/usr.sbin/ppp/vars.h
index a0e0d57..9794d8a 100644
--- a/usr.sbin/ppp/vars.h
+++ b/usr.sbin/ppp/vars.h
@@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: vars.h,v 1.1.1.1 1995/01/31 06:29:55 amurai Exp $
+ * $Id: vars.h,v 1.2 1995/02/26 12:18:06 amurai Exp $
*
* TODO:
*/
@@ -64,6 +64,8 @@ struct pppvars {
#define LOCAL_AUTH 0x01
#define LOCAL_NO_AUTH 0x02
u_char lauth; /* Local Authorized status */
+ #define DIALUP_REQ 0x01
+ #define DIALUP_DONE 0x02
char dial_script[200]; /* Dial script */
char login_script[200]; /* Login script */
char auth_key[50]; /* PAP/CHAP key */
OpenPOWER on IntegriCloud