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/chat.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/chat.c')
-rw-r--r-- | usr.sbin/ppp/chat.c | 173 |
1 files changed, 145 insertions, 28 deletions
diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c index ad1378e..5a79a0e 100644 --- a/usr.sbin/ppp/chat.c +++ b/usr.sbin/ppp/chat.c @@ -17,9 +17,9 @@ * 1760 Zollinger Road * Columbus, OH 43221 * (614)451-1883 - * + * * $Id:$ - * + * * TODO: * o Support more UUCP compatible control sequences. * o Dialing shoud not block monitor process. @@ -32,13 +32,19 @@ #endif #include <sys/time.h> #include <fcntl.h> +#include <errno.h> +#include <signal.h> +#include <sys/wait.h> #include "timeout.h" #include "vars.h" +#define IBSIZE 200 + static int TimeoutSec; static int abort_next, timeout_next; static int numaborts; char *AbortStrings[50]; +char inbuff[IBSIZE]; extern int ChangeParity(char *); @@ -177,15 +183,17 @@ int WaitforString(estr) char *estr; { -#define IBSIZE 200 struct timeval timeout; char *s, *str, ch; char *inp; fd_set rfds; - int i, nfds; + int i, nfds, nb; char buff[200]; - char inbuff[IBSIZE]; +#ifdef SIGALRM + int omask; + omask = sigblock(sigmask(SIGALRM)); +#endif (void) ExpandString(estr, buff, 0); LogPrintf(LOG_CHAT, "Wait for (%d): %s --> %s\n", TimeoutSec, estr, buff); str = buff; @@ -202,52 +210,150 @@ char *estr; */ timeout.tv_sec = TimeoutSec; timeout.tv_usec = 0; - i = select(nfds, &rfds, NULL, NULL, &timeout); #ifdef notdef TimerService(); #endif if (i < 0) { +#ifdef SIGALRM + if (errno == EINTR) + continue; + sigsetmask(omask); +#endif perror("select"); + *inp = 0; return(NOMATCH); } else if (i == 0) { /* Timeout reached! */ + *inp = 0; + if (inp != inbuff) + LogPrintf(LOG_CHAT, "got: %s\n", inbuff); LogPrintf(LOG_CHAT, "can't get (%d).\n", timeout.tv_sec); +#ifdef SIGALRM + sigsetmask(omask); +#endif return(NOMATCH); } if (FD_ISSET(modem, &rfds)) { /* got something */ - read(modem, &ch, 1); - *inp++ = ch; - if (ch == *s) { - s++; - if (*s == '\0') { + if (DEV_IS_SYNC) { + nb = read(modem, inbuff, IBSIZE-1); + inbuff[nb] = 0; + if (strstr(inbuff, str)) { +#ifdef SIGALRM + sigsetmask(omask); +#endif return(MATCH); } - } else { - s = str; - if (inp == inbuff+ IBSIZE) { - bcopy(inp - 100, inbuff, 100); - inp = inbuff + 100; - } - for (i = 0; i < numaborts; i++) { /* Look for Abort strings */ - int len; - char *s1; - - s1 = AbortStrings[i]; - len = strlen(s1); - if ((len <= inp - inbuff) && (strncmp(inp - len, s1, len) == 0)) { - LogPrintf(LOG_CHAT, "Abort: %s\n", s1); + for (i = 0; i < numaborts; i++) { + if (strstr(inbuff, AbortStrings[i])) { + LogPrintf(LOG_CHAT, "Abort: %s\n", AbortStrings[i]); +#ifdef SIGALRM + sigsetmask(omask); +#endif return(ABORT); } } + } else { + read(modem, &ch, 1); + *inp++ = ch; + if (ch == *s) { + s++; + if (*s == '\0') { +#ifdef SIGALRM + sigsetmask(omask); +#endif + *inp = 0; + return(MATCH); + } + } else { + s = str; + if (inp == inbuff+ IBSIZE) { + bcopy(inp - 100, inbuff, 100); + inp = inbuff + 100; + } + for (i = 0; i < numaborts; i++) { /* Look for Abort strings */ + int len; + char *s1; + + s1 = AbortStrings[i]; + len = strlen(s1); + if ((len <= inp - inbuff) && (strncmp(inp - len, s1, len) == 0)) { + LogPrintf(LOG_CHAT, "Abort: %s\n", s1); + *inp = 0; +#ifdef SIGALRM + sigsetmask(omask); +#endif + return(ABORT); + } + } + } } } } +#ifdef SIGALRM + sigsetmask(omask); +#endif +} + +void +ExecStr(command, out) +char *command, *out; +{ + int pid; + int fids[2]; + char *vector[20]; + int stat, nb; + char *cp; + char tmp[300]; + extern int errno; + + cp = inbuff + strlen(inbuff) - 1; + while (cp > inbuff) { + if (*cp < ' ' && *cp != '\t') { + cp++; + break; + } + cp--; + } + sprintf(tmp, "%s %s", command, cp); + (void) MakeArgs(tmp, &vector); + + pipe(fids); + pid = fork(); + if (pid == 0) { + signal(SIGINT, SIG_DFL); + signal(SIGQUIT, SIG_DFL); + signal(SIGTERM, SIG_DFL); + signal(SIGHUP, SIG_DFL); + close(fids[0]); + dup2(fids[1], 1); + close(fids[1]); + nb = open("/dev/tty", O_RDWR); + dup2(nb, 0); +LogPrintf(LOG_CHAT, "exec: %s\n", command); + pid = execvp(command, vector); + LogPrintf(LOG_CHAT, "execvp failed for (%d/%d): %s\n", pid, errno, command); + exit(127); + } else { + close(fids[1]); + for (;;) { + nb = read(fids[0], out, 1); + if (nb <= 0) + break; + out++; + } + *out = '\0'; + close(fids[0]); + close(fids[1]); + waitpid(pid, &stat, WNOHANG); + } } void SendString(str) char *str; { + char *cp; + int nb, on; char buff[200]; if (abort_next) { @@ -260,9 +366,20 @@ char *str; if (TimeoutSec <= 0) TimeoutSec = 30; } else { - (void) ExpandString(str, buff, 1); - LogPrintf(LOG_CHAT, "sending: %s\n", buff); - write(modem, buff, strlen(buff)); + if (*str == '!') { + (void) ExpandString(str+1, buff+2, 0); + ExecStr(buff + 2, buff + 2); + } else { + (void) ExpandString(str, buff+2, 1); + } + LogPrintf(LOG_CHAT, "sending: %s\n", buff+2); + cp = buff; + if (DEV_IS_SYNC) + bcopy("\377\003", buff, 2); /* Prepend HDLC header */ + else + cp += 2; + on = strlen(cp); + nb = write(modem, cp, on); } } |