summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp/main.c
diff options
context:
space:
mode:
authoramurai <amurai@FreeBSD.org>1995-02-26 12:18:08 +0000
committeramurai <amurai@FreeBSD.org>1995-02-26 12:18:08 +0000
commiteeb422fed8735188e4e141578d0383ae57ba8343 (patch)
treed05da3a88d3d54962fad8582d501f1b7ad9500b9 /usr.sbin/ppp/main.c
parent7c16fe40ea66e6edc77ed310b654360adf11b9f9 (diff)
downloadFreeBSD-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/main.c')
-rw-r--r--usr.sbin/ppp/main.c104
1 files changed, 82 insertions, 22 deletions
diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c
index 0054716..58a4438 100644
--- a/usr.sbin/ppp/main.c
+++ b/usr.sbin/ppp/main.c
@@ -18,7 +18,7 @@
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id:$
- *
+ *
* TODO:
* o Add commands for traffic summary, version display, etc.
* o Add signal handler for misc controls.
@@ -27,7 +27,6 @@
#include <fcntl.h>
#include <sys/time.h>
#include <termios.h>
-#include <sys/ioctl.h>
#include <signal.h>
#include <sys/wait.h>
#include <errno.h>
@@ -40,6 +39,13 @@
#include "lcp.h"
#include "ipcp.h"
#include "vars.h"
+#include "auth.h"
+
+#ifndef O_NONBLOCK
+#ifdef O_NDELAY
+#define O_NONBLOCK O_NDELAY
+#endif
+#endif
extern void VjInit(), AsyncInit();
extern void AsyncInput(), IpOutput();
@@ -74,7 +80,7 @@ TtyInit()
newtio.c_cc[VMIN] = 1;
newtio.c_cc[VTIME] = 0;
newtio.c_cflag |= CS8;
- ioctl(0, TIOCSETA, &newtio);
+ tcsetattr(0, TCSADRAIN, &newtio);
comtio = newtio;
}
@@ -89,11 +95,11 @@ TtyCommandMode()
if (!(mode & MODE_INTER))
return;
- ioctl(0, TIOCGETA, &newtio);
+ tcgetattr(0, &newtio);
newtio.c_lflag |= (ECHO|ICANON);
newtio.c_iflag = oldtio.c_iflag;
newtio.c_oflag |= OPOST;
- ioctl(0, TIOCSETA, &newtio);
+ tcsetattr(0, TCSADRAIN, &newtio);
stat = fcntl(0, F_GETFL, 0);
stat |= O_NONBLOCK;
fcntl(0, F_SETFL, stat);
@@ -109,7 +115,7 @@ TtyTermMode()
{
int stat;
- ioctl(0, TIOCSETA, &comtio);
+ tcsetattr(0, TCSADRAIN, &comtio);
stat = fcntl(0, F_GETFL, 0);
stat &= ~O_NONBLOCK;
fcntl(0, F_SETFL, stat);
@@ -123,10 +129,12 @@ int excode;
int stat;
OsLinkdown();
+#ifdef notdef
stat = fcntl(0, F_GETFL, 0);
stat &= ~O_NONBLOCK;
fcntl(0, F_SETFL, stat);
- ioctl(0, TIOCSETA, &oldtio);
+ tcsetattr(0, TCSANOW, &oldtio);
+#endif
OsCloseLink(1);
sleep(1);
if (mode & MODE_AUTO)
@@ -136,6 +144,12 @@ int excode;
LogClose();
if (server > 0)
close(server);
+#ifndef notdef
+ stat = fcntl(0, F_GETFL, 0);
+ stat &= ~O_NONBLOCK;
+ fcntl(0, F_SETFL, stat);
+ tcsetattr(0, TCSANOW, &oldtio);
+#endif
exit(excode);
}
@@ -226,6 +240,16 @@ char **argv;
if (LogOpen())
exit(EX_START);
+ switch ( LocalAuthInit() ) {
+ case NOT_FOUND:
+ fprintf(stderr, "Warning: No password entry in secret file\n");
+ fprintf(stderr, "Warning: Anyone is allowd manipulating!!!\n");
+ VarLocalAuth = LOCAL_AUTH;
+ break;
+ default:
+ break;
+ }
+
if (OpenTunnel(&tunno) < 0) {
perror("open_tun");
exit(EX_START);
@@ -244,12 +268,20 @@ char **argv;
}
}
- ioctl(0, TIOCGETA, &oldtio); /* Save original tty mode */
+ tcgetattr(0, &oldtio); /* Save original tty mode */
signal(SIGHUP, Hangup);
signal(SIGTERM, CloseSession);
signal(SIGINT, CloseSession);
+#ifdef SIGSEGV
signal(SIGSEGV, Hangup);
+#endif
+#ifdef SIGPIPE
+ signal(SIGPIPE, Hangup);
+#endif
+#ifdef SIGALRM
+ signal(SIGALRM, SIG_IGN);
+#endif
if (dstsystem) {
if (SelectSystem(dstsystem, CONFFILE) < 0) {
@@ -298,7 +330,7 @@ char **argv;
}
LogPrintf(LOG_PHASE, "Listening at %d.\n", port);
#ifdef DOTTYINIT
- if (mode & (MODE_DIRECT|MODE_DEDICATED)) {
+ if (mode & (MODE_DIRECT|MODE_DEDICATED)) { /* } */
#else
if (mode & MODE_DIRECT) {
#endif
@@ -371,12 +403,13 @@ ReadTty()
#endif
if (!TermMode) {
n = read(netfd, linebuff, sizeof(linebuff)-1);
- if (n > 0)
+ if (n > 0) {
DecodeCommand(linebuff, n, 1);
- else {
+ } else {
#ifdef DEBUG
logprintf("connection closed.\n");
#endif
+ VarLocalAuth = LOCAL_NO_AUTH;
close(netfd);
netfd = -1;
mode &= ~MODE_INTER;
@@ -455,10 +488,11 @@ ReadTty()
*/
static char *FrameHeaders[] = {
- "\176\177\175\043",
- "\176\377\175\043",
- "\176\175\137\175\043",
- "\176\175\337\175\043",
+ "\176\377\003\300\041",
+ "\176\377\175\043\300\041",
+ "\176\177\175\043\100\041",
+ "\176\175\337\175\043\300\041",
+ "\176\175\137\175\043\100\041",
NULL,
};
@@ -467,12 +501,15 @@ HdlcDetect(cp, n)
u_char *cp;
int n;
{
- char *ptr, **hp;
+ char *ptr, *fp, **hp;
cp[n] = '\0'; /* be sure to null terminated */
ptr = NULL;
for (hp = FrameHeaders; *hp; hp++) {
- if (ptr = strstr((char *)cp, *hp))
+ fp = *hp;
+ if (DEV_IS_SYNC)
+ fp++;
+ if (ptr = strstr((char *)cp, fp))
break;
}
return((u_char *)ptr);
@@ -509,6 +546,7 @@ DoLoop()
int ssize = sizeof(hisaddr);
u_char *cp;
u_char rbuff[MAX_MRU];
+ struct itimerval itimer;
if (mode & MODE_DIRECT) {
modem = OpenModem(mode);
@@ -522,7 +560,14 @@ 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);
+#else
timeout.tv_usec = 0;
+#endif
for (;;) {
IpStartOutput();
@@ -537,18 +582,23 @@ DoLoop()
* too big, it results loss of characters from modem and poor responce.
* If this values is too small, ppp process eats many CPU time.
*/
+#ifndef SIGALRM
usleep(TICKUNIT);
TimerService();
+#endif
if (modem) {
FD_SET(modem, &rfds);
FD_SET(modem, &efds);
- FD_SET(modem, &wfds);
+ if (ModemQlen() > 0) {
+ FD_SET(modem, &wfds);
+ }
}
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.
@@ -556,10 +606,16 @@ DoLoop()
*/
tp = (RedialTimer.state == TIMER_RUNNING)? &timeout : NULL;
i = select(tun_in+10, &rfds, &wfds, &efds, tp);
+#else
+ i = select(tun_in+10, &rfds, &wfds, &efds, NULL);
+#endif
if (i == 0) {
continue;
}
+
if (i < 0) {
+ if (errno == EINTR)
+ continue;
perror("select");
break;
}
@@ -596,6 +652,8 @@ DoLoop()
ModemStartOutput(modem);
}
if (FD_ISSET(modem, &rfds)) { /* something to read from modem */
+ if (LcpFsm.state <= ST_CLOSED)
+ usleep(10000);
n = read(modem, rbuff, sizeof(rbuff));
if ((mode & MODE_DIRECT) && n <= 0) {
DownConnection();
@@ -668,12 +726,9 @@ DoLoop()
if (DialModem()) {
sleep(1); /* little pause to allow peer starts */
- ModemTimeout();
+ ModemTimeout();
PacketMode();
} else {
-#ifdef notdef
- Cleanup(EX_DIAL);
-#endif
CloseModem();
/* Dial failed. Keep quite during redial wait period. */
/* XXX: We shoud implement re-dial */
@@ -689,5 +744,10 @@ DoLoop()
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");
}
OpenPOWER on IntegriCloud