diff options
author | amurai <amurai@FreeBSD.org> | 1995-02-26 12:18:08 +0000 |
---|---|---|
committer | amurai <amurai@FreeBSD.org> | 1995-02-26 12:18:08 +0000 |
commit | eeb422fed8735188e4e141578d0383ae57ba8343 (patch) | |
tree | d05da3a88d3d54962fad8582d501f1b7ad9500b9 /usr.sbin/ppp/timer.c | |
parent | 7c16fe40ea66e6edc77ed310b654360adf11b9f9 (diff) | |
download | FreeBSD-src-eeb422fed8735188e4e141578d0383ae57ba8343.zip FreeBSD-src-eeb422fed8735188e4e141578d0383ae57ba8343.tar.gz |
New user Process PPP based on iij-ppp0.94beta2.
o Supporting SYNC SIO device (But need a device driver)
- add "set speed sync"
o Fixing bug for Predictor-1 function.
o Add new parameter that re-sent interval for set timeout commands.
o Improving RTT (Round Trip Time) and reducing processor time.
- Previous Timer service was using polling, and now using
SIGALRM ;-)
- A 0.94beta2 will not work correctly....
-- Follows are additinal feature not including 0.94beta2
o Support Proxy ARP
- add "enable/disable proxy" commands
o Marging common routine in CHAP/PAP.
o Enhancing LCP/IPCP log information.
o Support local Authfication connection on port 300x and tty.
- You can set up pair of your "hostname -s" and
password in ppp.secret. if either ppp.secret file nor
your hostname line don't exist, It will notify a message
and working as same as previous version.(Backword compatibility)
- If you did set up them, It's allow connection but nothing to do
except help and passwd command.
- add "passwd yourpasswd" commands
o Support afilter - keep Alive filter that a packet can send/receiving
according to ifilter/ofilter but doesn't count it as preventing idle
timer expires.
- Same syntax of other filters.
o Fixing bugs reported by current user for previous one. Thanks !!
Reviewed by: Atsushi Murai (amurai@spec.co.jp)
Diffstat (limited to 'usr.sbin/ppp/timer.c')
-rw-r--r-- | usr.sbin/ppp/timer.c | 140 |
1 files changed, 126 insertions, 14 deletions
diff --git a/usr.sbin/ppp/timer.c b/usr.sbin/ppp/timer.c index 2c665da..3792103 100644 --- a/usr.sbin/ppp/timer.c +++ b/usr.sbin/ppp/timer.c @@ -18,34 +18,57 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * $Id:$ - * + * * TODO: */ #include "defs.h" #include <sys/time.h> #include <signal.h> #include "timeout.h" +#ifdef SIGALRM +#include <errno.h> +#endif +void StopTimerNoBlock( struct pppTimer *); +void ShowTimers(void); void +StopTimer( struct pppTimer *tp ) +{ +#ifdef SIGALRM + int omask; + omask = sigblock(sigmask(SIGALRM)); +#endif + StopTimerNoBlock(tp); +#ifdef SIGALRM + sigsetmask(omask); +#endif +} +void StartTimer(tp) struct pppTimer *tp; { struct pppTimer *t, *pt; u_long ticks = 0; - if (tp->state == TIMER_RUNNING) { - StopTimer(tp); +#ifdef SIGALRM + int omask; + omask = sigblock(sigmask(SIGALRM)); +#endif + + if (tp->state != TIMER_STOPPED) { + StopTimerNoBlock(tp); } if (tp->load == 0) { #ifdef DEBUG logprintf("timer %x has 0 load!\n", tp); #endif + sigsetmask(omask); return; } pt = NULL; for (t = TimerList; t; t = t->next) { #ifdef DEBUG - logprintf("%x(%d): ticks: %d, rest: %d\n", t, t->state, ticks, t->rest); + logprintf("StartTimer: %x(%d): ticks: %d, rest: %d\n", t, t->state, ticks, t->rest); #endif if (ticks + t->rest >= tp->load) break; @@ -66,24 +89,35 @@ struct pppTimer *tp; TimerList = tp; if (t) t->rest -= tp->rest; + +#ifdef SIGALRM + sigsetmask(omask); +#endif } void -StopTimer(tp) +StopTimerNoBlock(tp) struct pppTimer *tp; { struct pppTimer *t, *pt; + /* + * A Running Timer should be removing TimerList, + * But STOPPED/EXPIRED is already removing TimerList. + * So just marked as TIMER_STOPPED. + * Do not change tp->enext!! (Might be Called by expired proc) + */ +#ifdef DEBUG + logprintf("StopTimer: %x, next = %x state=%x\n", tp, tp->next, tp->state); +#endif if (tp->state != TIMER_RUNNING) { - tp->next = NULL; + tp->next = NULL; + tp->state = TIMER_STOPPED; return; } -#ifdef DEBUG - logprintf("StopTimer: %x, next = %x\n", tp, tp->next); -#endif pt = NULL; - for (t = TimerList; t != tp; t = t->next) + for (t = TimerList; t != tp && t !=NULL ; t = t->next) pt = t; if (t) { if (pt) @@ -92,8 +126,9 @@ struct pppTimer *tp; TimerList = t->next; if (t->next) t->next->rest += tp->rest; - } else - fprintf(stderr, "Oops, timer not found!!\n"); + } else { + logprintf("Oops, timer not found!!\n"); + } tp->next = NULL; tp->state = TIMER_STOPPED; } @@ -103,6 +138,9 @@ TimerService() { struct pppTimer *tp, *exp, *wt; +#ifdef DEBUG + ShowTimers(); +#endif if (tp = TimerList) { tp->rest--; if (tp->rest == 0) { @@ -135,7 +173,12 @@ TimerService() #endif if (exp->func) (*exp->func)(exp->arg); - exp = exp->enext; + /* + * Just Removing each item from expired list + * And exp->enext will be intialized at next expire + * in this funtion. + */ + exp = exp->enext; } } } @@ -146,6 +189,75 @@ ShowTimers() { struct pppTimer *pt; + logprintf("---- Begin of Timer Service List---\n"); for (pt = TimerList; pt; pt = pt->next) - fprintf(stderr, "%x: load = %d, rest = %d\r\n", pt, pt->load, pt->rest); + logprintf("%x: load = %d, rest = %d, state =%x\n", + pt, pt->load, pt->rest, pt->state); + logprintf("---- End of Timer Service List ---\n"); } + +#ifdef SIGALRM +u_int sleep( u_int sec ) +{ + struct timeval to,st,et; + long sld, nwd, std; + + gettimeofday( &st, NULL ); + to.tv_sec = sec; + to.tv_usec = 0; + std = st.tv_sec * 1000000 + st.tv_usec; + for (;;) { + if ( select ( 0, NULL, NULL, NULL, &to) == 0 || + errno != EINTR ) { + break; + } else { + gettimeofday( &et, NULL ); + sld = to.tv_sec * 1000000 + to.tv_sec; + nwd = et.tv_sec * 1000000 + et.tv_usec - std; + if ( sld > nwd ) + sld -= nwd; + else + sld = 1; /* Avoid both tv_sec/usec is 0 */ + + /* Calculate timeout value for select */ + to.tv_sec = sld / 1000000; + to.tv_usec = sld % 1000000; + + /* Forwarding signal as normal */ + kill(getpid(), SIGALRM); + } + } +} + +void usleep( u_int usec) +{ + struct timeval to,st,et; + long sld, nwd, std; + + gettimeofday( &st, NULL ); + to.tv_sec = 0; + to.tv_usec = usec; + std = st.tv_sec * 1000000 + st.tv_usec; + for (;;) { + if ( select ( 0, NULL, NULL, NULL, &to) == 0 || + errno != EINTR ) { + break; + } else { + gettimeofday( &et, NULL ); + sld = to.tv_sec * 1000000 + to.tv_sec; + nwd = et.tv_sec * 1000000 + et.tv_usec - std; + if ( sld > nwd ) + sld -= nwd; + else + sld = 1; /* Avoid both tv_sec/usec is 0 */ + + /* Calculate timeout value for select */ + to.tv_sec = sld / 1000000; + to.tv_usec = sld % 1000000; + + /* Forwarding signal as normal */ + kill(getpid(), SIGALRM); + } + } +} +#endif |