Add PPP autodetect, based on code from FreeBSD via OpenBSD.

This commit is contained in:
tsarna 1998-10-12 18:03:48 +00:00
parent b3edb8ba74
commit 13b21dc12c
4 changed files with 65 additions and 11 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: gettytab.5,v 1.19 1998/04/22 04:54:19 ross Exp $ .\" $NetBSD: gettytab.5,v 1.20 1998/10/12 18:03:48 tsarna Exp $
.\" .\"
.\" Copyright (c) 1983, 1991, 1993 .\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved. .\" The Regents of the University of California. All rights reserved.
@ -155,6 +155,7 @@ hangup line on last close
.It "pe bool false use printer (hard copy) erase algorithm" .It "pe bool false use printer (hard copy) erase algorithm"
.It "pf num 0 delay" .It "pf num 0 delay"
between first prompt and following flush (seconds) between first prompt and following flush (seconds)
.It "pp str unused PPP authentication program"
.It "ps bool false line connected to a" .It "ps bool false line connected to a"
.Tn MICOM .Tn MICOM
port selector port selector
@ -358,6 +359,12 @@ implementation.
does not check parity of input characters in does not check parity of input characters in
.Dv RAW .Dv RAW
mode. mode.
.Pp
If
.Em \&pp
string is specified and a PPP link bringup sequence is recognized,
getty will invoke the program referenced by the pp option. This
can be used to handle incoming PPP calls.
.Sh SEE ALSO .Sh SEE ALSO
.Xr login 1 , .Xr login 1 ,
.Xr gethostname 3 , .Xr gethostname 3 ,

View File

@ -1,4 +1,4 @@
/* $NetBSD: gettytab.h,v 1.8 1996/07/31 20:40:31 thorpej Exp $ */ /* $NetBSD: gettytab.h,v 1.9 1998/10/12 18:03:49 tsarna Exp $ */
/* /*
* Copyright (c) 1983, 1993, 1994 * Copyright (c) 1983, 1993, 1994
@ -86,6 +86,7 @@ struct gettyflags {
#define FL gettystrs[21].value #define FL gettystrs[21].value
#define WE gettystrs[22].value #define WE gettystrs[22].value
#define LN gettystrs[23].value #define LN gettystrs[23].value
#define PP gettystrs[24].value
/* /*
* Numeric definitions. * Numeric definitions.

View File

@ -1,4 +1,4 @@
/* $NetBSD: init.c,v 1.8 1997/08/06 07:22:24 mikel Exp $ */ /* $NetBSD: init.c,v 1.9 1998/10/12 18:03:49 tsarna Exp $ */
/* /*
* Copyright (c) 1983, 1993 * Copyright (c) 1983, 1993
@ -38,7 +38,7 @@
#if 0 #if 0
static char sccsid[] = "from: @(#)init.c 8.1 (Berkeley) 6/4/93"; static char sccsid[] = "from: @(#)init.c 8.1 (Berkeley) 6/4/93";
#else #else
__RCSID("$NetBSD: init.c,v 1.8 1997/08/06 07:22:24 mikel Exp $"); __RCSID("$NetBSD: init.c,v 1.9 1998/10/12 18:03:49 tsarna Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -81,6 +81,7 @@ struct gettystrs gettystrs[] = {
{ "fl", &tmode.c_cc[VDISCARD] },/* flush output */ { "fl", &tmode.c_cc[VDISCARD] },/* flush output */
{ "we", &tmode.c_cc[VWERASE] }, /* word erase */ { "we", &tmode.c_cc[VWERASE] }, /* word erase */
{ "ln", &tmode.c_cc[VLNEXT] }, /* literal next */ { "ln", &tmode.c_cc[VLNEXT] }, /* literal next */
{ "pp" }, /* ppp login program */
{ 0 } { 0 }
}; };

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.26 1998/07/06 06:48:19 mrg Exp $ */ /* $NetBSD: main.c,v 1.27 1998/10/12 18:03:49 tsarna Exp $ */
/*- /*-
* Copyright (c) 1980, 1993 * Copyright (c) 1980, 1993
@ -44,7 +44,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
#if 0 #if 0
static char sccsid[] = "from: @(#)main.c 8.1 (Berkeley) 6/20/93"; static char sccsid[] = "from: @(#)main.c 8.1 (Berkeley) 6/20/93";
#else #else
__RCSID("$NetBSD: main.c,v 1.26 1998/07/06 06:48:19 mrg Exp $"); __RCSID("$NetBSD: main.c,v 1.27 1998/10/12 18:03:49 tsarna Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -82,6 +82,16 @@ extern char *__progname;
*/ */
#define GETTY_TIMEOUT 60 /* seconds */ #define GETTY_TIMEOUT 60 /* seconds */
/* defines for auto detection of incoming PPP calls (->PAP/CHAP) */
#define PPP_FRAME 0x7e /* PPP Framing character */
#define PPP_STATION 0xff /* "All Station" character */
#define PPP_ESCAPE 0x7d /* Escape Character */
#define PPP_CONTROL 0x03 /* PPP Control Field */
#define PPP_CONTROL_ESCAPED 0x23 /* PPP Control Field, escaped */
#define PPP_LCP_HI 0xc0 /* LCP protocol - high byte */
#define PPP_LCP_LOW 0x21 /* LCP protocol - low byte */
struct termios tmode, omode; struct termios tmode, omode;
int crmod, digit, lower, upper; int crmod, digit, lower, upper;
@ -160,7 +170,7 @@ timeoverrun(signo)
int signo; int signo;
{ {
syslog(LOG_ERR, "getty exiting due to excessive running time\n"); syslog(LOG_ERR, "getty exiting due to excessive running time");
exit(1); exit(1);
} }
@ -183,6 +193,7 @@ main(argc, argv)
int repcnt = 0, failopenlogged = 0, uugetty = 0; int repcnt = 0, failopenlogged = 0, uugetty = 0;
struct rlimit limit; struct rlimit limit;
struct passwd *pw; struct passwd *pw;
int rval;
#ifdef __GNUC__ #ifdef __GNUC__
(void)&tname; /* XXX gcc -Wall */ (void)&tname; /* XXX gcc -Wall */
@ -335,7 +346,11 @@ main(argc, argv)
signal(SIGALRM, dingdong); signal(SIGALRM, dingdong);
alarm(TO); alarm(TO);
} }
if (getname()) { if ((rval = getname()) == 2) {
execle(PP, "ppplogin", ttyn, (char *) 0, env);
syslog(LOG_ERR, "%s: %m", PP);
exit(1);
} else if (rval) {
int i; int i;
oflush(); oflush();
@ -388,8 +403,9 @@ getname()
{ {
int c; int c;
char *np; char *np;
char cs; unsigned char cs;
int ppp_state, ppp_connection;
/* /*
* Interrupt may happen if we use CBREAK mode * Interrupt may happen if we use CBREAK mode
*/ */
@ -410,6 +426,7 @@ getname()
exit(1); exit(1);
} }
crmod = digit = lower = upper = 0; crmod = digit = lower = upper = 0;
ppp_state = ppp_connection = 0;
np = name; np = name;
for (;;) { for (;;) {
oflush(); oflush();
@ -417,6 +434,34 @@ getname()
exit(0); exit(0);
if ((c = cs&0177) == 0) if ((c = cs&0177) == 0)
return (0); return (0);
/*
* PPP detection state machine..
* Look for sequences:
* PPP_FRAME, PPP_STATION, PPP_ESCAPE, PPP_CONTROL_ESCAPED or
* PPP_FRAME, PPP_STATION, PPP_CONTROL (deviant from RFC)
* See RFC1662.
* Derived from code from Michael Hancock <michaelh@cet.co.jp>
* and Erik 'PPP' Olson <eriko@wrq.com>
*/
if (PP && cs == PPP_FRAME) {
ppp_state = 1;
} else if (ppp_state == 1 && cs == PPP_STATION) {
ppp_state = 2;
} else if (ppp_state == 2 && cs == PPP_ESCAPE) {
ppp_state = 3;
} else if ((ppp_state == 2 && cs == PPP_CONTROL) ||
(ppp_state == 3 && cs == PPP_CONTROL_ESCAPED)) {
ppp_state = 4;
} else if (ppp_state == 4 && cs == PPP_LCP_HI) {
ppp_state = 5;
} else if (ppp_state == 5 && cs == PPP_LCP_LOW) {
ppp_connection = 1;
break;
} else {
ppp_state = 0;
}
if (c == EOT) if (c == EOT)
exit(1); exit(1);
if (c == '\r' || c == '\n' || np >= &name[sizeof name]) { if (c == '\r' || c == '\n' || np >= &name[sizeof name]) {
@ -463,7 +508,7 @@ getname()
for (np = name; *np; np++) for (np = name; *np; np++)
if (isupper(*np)) if (isupper(*np))
*np = tolower(*np); *np = tolower(*np);
return (1); return (1 + ppp_connection);
} }
static void static void