Remove if_ppp(4) and if_sl(4).
Not only did these two drivers depend on IFF_NEEDSGIANT, they were broken 7 months ago during the MPSAFE TTY import. if_ppp(4) has been replaced by ppp(8). There is no replacement for if_sl(4). If we see regressions in for example the ports tree, we should just use __FreeBSD_version 800045 to check whether if_ppp(4) and if_sl(4) are present. Version 800045 is used to denote the import of MPSAFE TTY. Discussed with: rwatson, but also rwatson's IFF_NEEDSGIANT emails on the lists.
This commit is contained in:
parent
18eefdb2b2
commit
36d960175a
@ -14,6 +14,26 @@
|
||||
# The file is partitioned: OLD_FILES first, then OLD_LIBS and OLD_DIRS last.
|
||||
#
|
||||
|
||||
# 20090405: removal of if_ppp(4) and if_sl(4)
|
||||
OLD_FILES+=sbin/slattach
|
||||
OLD_FILES+=sbin/startslip
|
||||
OLD_FILES+=usr/include/net/if_ppp.h
|
||||
OLD_FILES+=usr/include/net/if_pppvar.h
|
||||
OLD_FILES+=usr/include/net/if_slvar.h
|
||||
OLD_FILES+=usr/include/net/ppp_comp.h
|
||||
OLD_FILES+=usr/include/net/slip.h
|
||||
OLD_FILES+=usr/sbin/sliplogin
|
||||
OLD_FILES+=usr/sbin/pppd
|
||||
OLD_FILES+=usr/sbin/pppstats
|
||||
OLD_FILES+=usr/share/man/man1/startslip.1.gz
|
||||
OLD_FILES+=usr/share/man/man4/if_ppp.4.gz
|
||||
OLD_FILES+=usr/share/man/man4/if_sl.4.gz
|
||||
OLD_FILES+=usr/share/man/man4/ppp.4.gz
|
||||
OLD_FILES+=usr/share/man/man4/sl.4.gz
|
||||
OLD_FILES+=usr/share/man/man8/pppd.8.gz
|
||||
OLD_FILES+=usr/share/man/man8/pppstats.8.gz
|
||||
OLD_FILES+=usr/share/man/man8/slattach.8.gz
|
||||
OLD_FILES+=usr/share/man/man8/sliplogin.8.gz
|
||||
# 20090319: uscanner(4) has been removed
|
||||
OLD_FILES+=usr/share/man/man4/uscanner.4.gz
|
||||
# 20090313: k8temp(4) renamed to amdtemp(4)
|
||||
|
@ -118,7 +118,7 @@ CRUNCH_PROGS_sbin= atacontrol badsect \
|
||||
mount_udf mount_unionfs newfs \
|
||||
newfs_msdos nos-tun ping reboot \
|
||||
restore rcorder route routed rtquery rtsol savecore \
|
||||
slattach spppcontrol startslip swapon sysctl tunefs umount
|
||||
spppcontrol swapon sysctl tunefs umount
|
||||
|
||||
.if ${MK_ATM} != "no"
|
||||
CRUNCH_PROGS_sbin+= atmconfig
|
||||
|
@ -82,9 +82,7 @@ SUBDIR= adjkerntz \
|
||||
${_sconfig} \
|
||||
setkey \
|
||||
shutdown \
|
||||
slattach \
|
||||
spppcontrol \
|
||||
${_startslip} \
|
||||
${_sunlabel} \
|
||||
swapon \
|
||||
sysctl \
|
||||
@ -130,10 +128,6 @@ _quotacheck= quotacheck
|
||||
_routed= routed
|
||||
.endif
|
||||
|
||||
.if ${MK_SLIP} != "no"
|
||||
_startslip= startslip
|
||||
.endif
|
||||
|
||||
.if ${MACHINE_ARCH} == "i386"
|
||||
.if ${MACHINE} == "i386"
|
||||
_fdisk= fdisk
|
||||
|
@ -1,12 +0,0 @@
|
||||
# @(#)Makefile 5.4 (Berkeley) 5/11/90
|
||||
#
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= slattach
|
||||
WARNS?= 0
|
||||
MAN= slattach.8
|
||||
MLINKS= slattach.8 slip.8
|
||||
LDADD= -lutil
|
||||
DPADD= ${LIBUTIL}
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,271 +0,0 @@
|
||||
.\" Copyright (c) 1986, 1991 The Regents of the University of California.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)slattach.8 6.4 (Berkeley) 3/16/91
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd April 4, 1993
|
||||
.Dt SLATTACH 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm slattach
|
||||
.Nd attach serial lines as network interfaces
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl acfhLlnz
|
||||
.Op Fl e Ar exit-command
|
||||
.Op Fl K Ar keepalive
|
||||
.Op Fl O Ar outfill
|
||||
.Op Fl r Ar redial-command
|
||||
.Op Fl S Ar unit
|
||||
.Op Fl s Ar baudrate
|
||||
.Op Fl u Ar unit-command
|
||||
.Ar ttyname
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility is used to assign a tty line to a network interface,
|
||||
and to define the network source and destination addresses.
|
||||
.Pp
|
||||
The following options are available:
|
||||
.Bl -tag -width indent
|
||||
.It Fl a
|
||||
Autoenable the VJ header compression option, if the other end of the link
|
||||
is capable of VJ header compression then it will be used otherwise normal
|
||||
headers will be used.
|
||||
.It Fl c
|
||||
Enable the VJ header compression option.
|
||||
Note that both ends of the link
|
||||
must be able to use VJ header compression for this to work.
|
||||
.It Fl e Ar exit-command
|
||||
Specify a command to be invoked within a shell
|
||||
.Ql sh \-c Ar exit-command
|
||||
before
|
||||
.Nm
|
||||
exits.
|
||||
.It Fl f
|
||||
Disable the invocation of daemon() to run
|
||||
.Nm
|
||||
in the background.
|
||||
.It Fl h
|
||||
Turn on cts/rts style flow control on the slip port, by default no flow
|
||||
control is done.
|
||||
.It Fl l
|
||||
Disable modem control (CLOCAL) and ignore carrier detect on the slip
|
||||
port.
|
||||
By default the
|
||||
.Ar redial-command
|
||||
is invoked upon carrier drop and
|
||||
.Nm
|
||||
aborts if no
|
||||
.Ar redial-command
|
||||
is specified.
|
||||
.It Fl n
|
||||
Throw away ICMP packets.
|
||||
The slip interface will ignore ICMP packets
|
||||
to prevent slow lines being saturated by ICMP responses.
|
||||
.It Fl r Ar redial-command
|
||||
Specify a command to be invoked within a shell
|
||||
.Ql sh \-c Ar redial-command
|
||||
whenever carrier is lost on the modem line.
|
||||
Empty
|
||||
.Ar redial-command
|
||||
(i.e.\&
|
||||
.Fl r Qq "" )
|
||||
cause connection reestablishing on leased line
|
||||
without any external command invoked.
|
||||
.It Fl s Ar baudrate
|
||||
Specify the speed of the connection.
|
||||
If not specified, the
|
||||
default of 9600 is used.
|
||||
.It Fl u Ar unit-command
|
||||
When the line is switched to slip discipline, run
|
||||
.Dq Nm "sh -c" Ar unit-command old new
|
||||
where
|
||||
.Ar old
|
||||
and
|
||||
.Ar new
|
||||
are the slip unit numbers when the line was
|
||||
last opened and the unit number of the current slip connection
|
||||
respectively.
|
||||
The unit number can change after redialing if you are
|
||||
using more than one slip line.
|
||||
When
|
||||
.Nm
|
||||
is connected for the first time,
|
||||
.Dq Nm "sh -c" Ar unit-command \-1 new
|
||||
is run.
|
||||
When
|
||||
.Nm
|
||||
is disconnected,
|
||||
.Dq Nm "sh -c" Ar unit-command old \-1
|
||||
is run.
|
||||
The
|
||||
.Nm
|
||||
utility will abort if the unit number
|
||||
changes and
|
||||
.Dq Fl u Ar \%unit-command
|
||||
was not specified.
|
||||
.It Fl z
|
||||
Force redial
|
||||
.Ar redial-command
|
||||
upon startup irrespective of carrier.
|
||||
.It Fl L
|
||||
Use uucp-style device locking.
|
||||
You need it unless you start
|
||||
.Nm
|
||||
from external program which already does uucp locking.
|
||||
Default case is no uucp locking to satisfy such programs.
|
||||
.It Fl K Ar keepalive
|
||||
Set SLIP "keep alive" timeout in seconds.
|
||||
If FRAME_END is not received in
|
||||
this amount of time, re-connect occurs.
|
||||
The default value is no timeout.
|
||||
.It Fl O Ar outfill
|
||||
Set SLIP "out fill" timeout in seconds.
|
||||
It forces at least one FRAME_END
|
||||
to be sent during this time period, which is necessary for the "keep alive"
|
||||
timeout on the remote side.
|
||||
The default value is no timeout.
|
||||
.It Fl S Ar unit
|
||||
Set the SLIP unit number directly.
|
||||
Use with caution, because no check is made
|
||||
for two interfaces with same number.
|
||||
By default sliplogin dynamically assigns the unit number.
|
||||
.It Ar ttyname
|
||||
Specify the name of the tty device.
|
||||
.Ar Ttyname
|
||||
should be a string of the form
|
||||
.Ql ttyXX
|
||||
or
|
||||
.Ql /dev/ttyXX .
|
||||
.El
|
||||
.Pp
|
||||
Only the super-user may attach a network interface.
|
||||
.Pp
|
||||
To detach the interface, use
|
||||
.Dq Li ifconfig interface-name down
|
||||
after killing off the
|
||||
.Nm
|
||||
process using
|
||||
.Ql kill -INT .
|
||||
.Ar Interface-name
|
||||
is the name that is shown by
|
||||
.Xr netstat 1 .
|
||||
.Pp
|
||||
To setup
|
||||
.Nm
|
||||
to redial the phone when carrier is lost, use the
|
||||
.Fl r Ar redial-command
|
||||
option to specify a script or executable that will reconnect the
|
||||
serial line to the slip server.
|
||||
For example, the script could redial
|
||||
the server and log in, etc.
|
||||
.Pp
|
||||
To reconfigure the network interface in case the slip unit number
|
||||
changes, use the
|
||||
.Fl u Ar unit-command
|
||||
option to specify a script or executable that will be invoked as
|
||||
.Ql sh \-c Ar unit-command old new
|
||||
where
|
||||
.Ar old
|
||||
and
|
||||
.Ar new
|
||||
are the slip unit numbers before and after
|
||||
reconnecting the line.
|
||||
The unit number can change if you have more
|
||||
than one line disconnect at the same time.
|
||||
The first to succeed in
|
||||
reconnecting will get the lowest unit number.
|
||||
.Pp
|
||||
To kill
|
||||
.Nm
|
||||
use
|
||||
.Ql kill -INT
|
||||
(SIGINT) which causes it to close the tty and exit.
|
||||
.Pp
|
||||
To force a redial, use
|
||||
.Ql kill -HUP
|
||||
(SIGHUP) which causes
|
||||
.Nm
|
||||
to think carrier was lost and thus invoke
|
||||
.Ql sh \-c Ar redial-command
|
||||
to reconnect to the server.
|
||||
.Pp
|
||||
If you use a hard-wired connection rather than a modem, invoke
|
||||
.Nm
|
||||
with the
|
||||
.Fl l
|
||||
option in order to ignore carrier on the slip line.
|
||||
.Sh FILES
|
||||
.Bl -tag -width /usr/share/examples/slattach/* -compact
|
||||
.It Pa /var/run/slattach.<tty>.pid
|
||||
with
|
||||
.Ar tty
|
||||
replaced by the terminal path name component of
|
||||
.Ar ttyname .
|
||||
This file contains the numerical process ID of the
|
||||
.Nm
|
||||
process and can be examined by scripts in order to send a signal to
|
||||
.Nm
|
||||
.It Pa /usr/share/examples/slattach/*
|
||||
.El
|
||||
.Sh EXAMPLES
|
||||
.Bd -literal -offset indent -compact
|
||||
slattach ttyd8
|
||||
slattach \-s 4800 /dev/ttyd1
|
||||
slattach \-c \-s 38400 /dev/cuad1
|
||||
slattach \-r 'kermit -y dial.script >kermit.log 2>&1'
|
||||
.Ed
|
||||
.Sh DIAGNOSTICS
|
||||
Look for error messages in
|
||||
.Pa /var/log/messages
|
||||
.No ( Nm
|
||||
is a daemon).
|
||||
Messages indicating the specified interface does not exit, the
|
||||
requested address is unknown, the user is not privileged and tried to
|
||||
alter an interface's configuration are logged there.
|
||||
The
|
||||
.Nm
|
||||
utility
|
||||
also logs failure to set the controlling terminal or failure to install
|
||||
signal handlers.
|
||||
Upon connection and redial the ttyname and baud rate
|
||||
are logged and on shutdown the ttyname is logged.
|
||||
.Sh SEE ALSO
|
||||
.Xr netstat 1 ,
|
||||
.Xr startslip 1 ,
|
||||
.Xr netintro 4 ,
|
||||
.Xr ifconfig 8 ,
|
||||
.Xr rc 8 ,
|
||||
.Xr sliplogin 8
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
utility appeared in
|
||||
.Bx 4.3 .
|
@ -1,599 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1988 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Rick Adams.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1988 Regents of the University of California.\n\
|
||||
All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "from: @(#)slattach.c 4.6 (Berkeley) 6/1/90";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <libutil.h>
|
||||
#include <paths.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/slip.h>
|
||||
|
||||
#define DEFAULT_BAUD 9600
|
||||
|
||||
void sighup_handler(); /* SIGHUP handler */
|
||||
void sigint_handler(); /* SIGINT handler */
|
||||
void sigterm_handler(); /* SIGTERM handler */
|
||||
void sigurg_handler(); /* SIGURG handler */
|
||||
void exit_handler(int ret); /* run exit_cmd iff specified upon exit. */
|
||||
void setup_line(int cflag); /* configure terminal settings */
|
||||
void slip_discipline(); /* switch to slip line discipline */
|
||||
void configure_network(); /* configure slip interface */
|
||||
void acquire_line(); /* get tty device as controlling terminal */
|
||||
static void usage(void);
|
||||
|
||||
int fd = -1;
|
||||
char *dev = (char *)0; /* path name of the tty (e.g. /dev/tty01) */
|
||||
char *dvname; /* basename of dev */
|
||||
int locked = 0; /* uucp lock active */
|
||||
int flow_control = 0; /* non-zero to enable hardware flow control. */
|
||||
int modem_control = HUPCL; /* !CLOCAL+HUPCL iff we watch carrier. */
|
||||
int comstate; /* TIOCMGET current state of serial driver */
|
||||
int redial_on_startup = 0; /* iff non-zero execute redial_cmd on startup */
|
||||
speed_t speed = DEFAULT_BAUD; /* baud rate of tty */
|
||||
int slflags = 0; /* compression flags */
|
||||
int unit = -1; /* slip device unit number */
|
||||
int foreground = 0; /* act as daemon if zero, else don't fork. */
|
||||
int keepal = 0; /* keepalive timeout */
|
||||
int outfill = 0; /* outfill timeout */
|
||||
int sl_unit = -1; /* unit number */
|
||||
int uucp_lock = 0; /* do uucp locking */
|
||||
int exiting = 0; /* already running exit_handler */
|
||||
|
||||
struct termios tty; /* tty configuration/state */
|
||||
|
||||
char tty_path[32]; /* path name of the tty (e.g. /dev/tty01) */
|
||||
char pidfilename[40]; /* e.g. /var/run/slattach.tty01.pid */
|
||||
char *redial_cmd = 0; /* command to exec upon shutdown. */
|
||||
char *config_cmd = 0; /* command to exec if slip unit changes. */
|
||||
char *exit_cmd = 0; /* command to exec before exiting. */
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr, "%s\n%s\n%s\n",
|
||||
"usage: slattach [-acfhLlnz] [-e exit-command] [-K keepalive] [-O outfill]",
|
||||
" [-r redial-command] [-S unit] [-s baudrate] [-u unit-command]",
|
||||
" ttyname");
|
||||
/* do not exit here */
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int option;
|
||||
|
||||
while ((option = getopt(argc, argv, "ace:fhlnr:s:u:zLK:O:S:")) != -1) {
|
||||
switch (option) {
|
||||
case 'a':
|
||||
slflags |= IFF_LINK2;
|
||||
slflags &= ~IFF_LINK0;
|
||||
break;
|
||||
case 'c':
|
||||
slflags |= IFF_LINK0;
|
||||
slflags &= ~IFF_LINK2;
|
||||
break;
|
||||
case 'e':
|
||||
exit_cmd = strdup (optarg);
|
||||
break;
|
||||
case 'f':
|
||||
foreground = 1;
|
||||
break;
|
||||
case 'h':
|
||||
flow_control |= CRTSCTS;
|
||||
break;
|
||||
case 'l':
|
||||
modem_control = CLOCAL; /* clear HUPCL too */
|
||||
break;
|
||||
case 'n':
|
||||
slflags |= IFF_LINK1;
|
||||
break;
|
||||
case 'r':
|
||||
redial_cmd = strdup (optarg);
|
||||
break;
|
||||
case 's':
|
||||
speed = atoi(optarg);
|
||||
break;
|
||||
case 'u':
|
||||
config_cmd = strdup (optarg);
|
||||
break;
|
||||
case 'z':
|
||||
redial_on_startup = 1;
|
||||
break;
|
||||
case 'L':
|
||||
uucp_lock = 1;
|
||||
break;
|
||||
case 'K':
|
||||
keepal = atoi(optarg);
|
||||
break;
|
||||
case 'O':
|
||||
outfill = atoi(optarg);
|
||||
break;
|
||||
case 'S':
|
||||
sl_unit = atoi(optarg);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
exit_handler(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind == argc - 1)
|
||||
dev = argv[optind];
|
||||
|
||||
if (optind < (argc - 1))
|
||||
warnx("too many args, first='%s'", argv[optind]);
|
||||
if (optind > (argc - 1))
|
||||
warnx("not enough args");
|
||||
if (dev == (char *)0) {
|
||||
usage();
|
||||
exit_handler(2);
|
||||
}
|
||||
if (strncmp(_PATH_DEV, dev, sizeof(_PATH_DEV) - 1)) {
|
||||
strcpy(tty_path, _PATH_DEV);
|
||||
strcat(tty_path, "/");
|
||||
strncat(tty_path, dev, 10);
|
||||
dev = tty_path;
|
||||
}
|
||||
dvname = strrchr(dev, '/'); /* always succeeds */
|
||||
dvname++; /* trailing tty pathname component */
|
||||
snprintf(pidfilename, sizeof(pidfilename),
|
||||
"%sslattach.%s.pid", _PATH_VARRUN, dvname);
|
||||
printf("%s\n",pidfilename);
|
||||
|
||||
if (!foreground)
|
||||
daemon(0,0); /* fork, setsid, chdir /, and close std*. */
|
||||
/* daemon() closed stderr, so log errors from here on. */
|
||||
openlog("slattach",LOG_CONS|LOG_PID,LOG_DAEMON);
|
||||
|
||||
acquire_line(); /* get tty device as controlling terminal */
|
||||
setup_line(0); /* configure for slip line discipline */
|
||||
slip_discipline(); /* switch to slip line discipline */
|
||||
|
||||
/* upon INT log a timestamp and exit. */
|
||||
if (signal(SIGINT,sigint_handler) == SIG_ERR)
|
||||
syslog(LOG_NOTICE,"cannot install SIGINT handler: %m");
|
||||
/* upon TERM log a timestamp and exit. */
|
||||
if (signal(SIGTERM,sigterm_handler) == SIG_ERR)
|
||||
syslog(LOG_NOTICE,"cannot install SIGTERM handler: %m");
|
||||
/* upon HUP redial and reconnect. */
|
||||
if (signal(SIGHUP,sighup_handler) == SIG_ERR)
|
||||
syslog(LOG_NOTICE,"cannot install SIGHUP handler: %m");
|
||||
|
||||
if (redial_on_startup)
|
||||
sighup_handler();
|
||||
else if (!(modem_control & CLOCAL)) {
|
||||
if (ioctl(fd, TIOCMGET, &comstate) < 0)
|
||||
syslog(LOG_NOTICE,"cannot get carrier state: %m");
|
||||
if (!(comstate & TIOCM_CD)) { /* check for carrier */
|
||||
/* force a redial if no carrier */
|
||||
kill (getpid(), SIGHUP);
|
||||
} else
|
||||
configure_network();
|
||||
} else
|
||||
configure_network(); /* configure the network if needed. */
|
||||
|
||||
for (;;) {
|
||||
sigset_t mask;
|
||||
sigemptyset(&mask);
|
||||
sigsuspend(&mask);
|
||||
}
|
||||
}
|
||||
|
||||
/* Close all FDs, fork, reopen tty port as 0-2, and make it the
|
||||
controlling terminal for our process group. */
|
||||
void acquire_line()
|
||||
{
|
||||
int ttydisc = TTYDISC;
|
||||
int oflags;
|
||||
FILE *pidfile;
|
||||
|
||||
/* reset to tty discipline */
|
||||
if (fd >= 0 && ioctl(fd, TIOCSETD, &ttydisc) < 0) {
|
||||
syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
|
||||
(void)close(STDIN_FILENO); /* close FDs before forking. */
|
||||
(void)close(STDOUT_FILENO);
|
||||
(void)close(STDERR_FILENO);
|
||||
if (fd > 2)
|
||||
(void)close(fd);
|
||||
|
||||
signal(SIGHUP, SIG_IGN); /* ignore HUP signal when parent dies. */
|
||||
if (daemon(0,0)) { /* fork, setsid, chdir /, and close std*. */
|
||||
syslog(LOG_ERR, "daemon(0,0): %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
|
||||
while (getppid () != 1)
|
||||
sleep (1); /* Wait for parent to die. */
|
||||
|
||||
/* create PID file */
|
||||
if((pidfile = fopen(pidfilename, "w"))) {
|
||||
fprintf(pidfile, "%ld\n", (long)getpid());
|
||||
fclose(pidfile);
|
||||
}
|
||||
|
||||
if (signal(SIGHUP,sighup_handler) == SIG_ERR) /* Re-enable HUP signal */
|
||||
syslog(LOG_NOTICE,"cannot install SIGHUP handler: %m");
|
||||
|
||||
if (uucp_lock) {
|
||||
/* unlock not needed here, always re-lock with new pid */
|
||||
int res;
|
||||
if ((res = uu_lock(dvname)) != UU_LOCK_OK) {
|
||||
if (res != UU_LOCK_INUSE)
|
||||
syslog(LOG_ERR, "uu_lock: %s", uu_lockerr(res));
|
||||
syslog(LOG_ERR, "can't lock %s", dev);
|
||||
exit_handler(1);
|
||||
}
|
||||
locked = 1;
|
||||
}
|
||||
|
||||
if ((fd = open(dev, O_RDWR | O_NONBLOCK, 0)) < 0) {
|
||||
syslog(LOG_ERR, "open(%s) %m", dev);
|
||||
exit_handler(1);
|
||||
}
|
||||
/* Turn off O_NONBLOCK for dumb redialers, if any. */
|
||||
if ((oflags = fcntl(fd, F_GETFL)) == -1) {
|
||||
syslog(LOG_ERR, "fcntl(F_GETFL) failed: %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
if (fcntl(fd, F_SETFL, oflags & ~O_NONBLOCK) == -1) {
|
||||
syslog(LOG_ERR, "fcntl(F_SETFL) failed: %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
(void)dup2(fd, STDIN_FILENO);
|
||||
(void)dup2(fd, STDOUT_FILENO);
|
||||
(void)dup2(fd, STDERR_FILENO);
|
||||
if (fd > 2)
|
||||
(void)close (fd);
|
||||
fd = STDIN_FILENO;
|
||||
|
||||
/* acquire the serial line as a controlling terminal. */
|
||||
if (ioctl(fd, TIOCSCTTY, 0) < 0) {
|
||||
syslog(LOG_ERR,"ioctl(TIOCSCTTY): %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
/* Make us the foreground process group associated with the
|
||||
slip line which is our controlling terminal. */
|
||||
if (tcsetpgrp(fd, getpid()) < 0)
|
||||
syslog(LOG_NOTICE,"tcsetpgrp failed: %m");
|
||||
}
|
||||
|
||||
/* Set the tty flags and set DTR. */
|
||||
/* Call as setup_line(CLOCAL) to force clocal assertion. */
|
||||
void setup_line(int cflag)
|
||||
{
|
||||
tty.c_lflag = tty.c_iflag = tty.c_oflag = 0;
|
||||
tty.c_cflag = CREAD | CS8 | flow_control | modem_control | cflag;
|
||||
cfsetispeed(&tty, speed);
|
||||
cfsetospeed(&tty, speed);
|
||||
/* set the line speed and flow control */
|
||||
if (tcsetattr(fd, TCSAFLUSH, &tty) < 0) {
|
||||
syslog(LOG_ERR, "tcsetattr(TCSAFLUSH): %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
/* set data terminal ready */
|
||||
if (ioctl(fd, TIOCSDTR) < 0) {
|
||||
syslog(LOG_ERR, "ioctl(TIOCSDTR): %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Put the line in slip discipline. */
|
||||
void slip_discipline()
|
||||
{
|
||||
struct ifreq ifr;
|
||||
int slipdisc = SLIPDISC;
|
||||
int s, tmp_unit = -1;
|
||||
|
||||
/* Switch to slip line discipline. */
|
||||
if (ioctl(fd, TIOCSETD, &slipdisc) < 0) {
|
||||
syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
|
||||
if (sl_unit >= 0 && ioctl(fd, SLIOCSUNIT, &sl_unit) < 0) {
|
||||
syslog(LOG_ERR, "ioctl(SLIOCSUNIT): %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
|
||||
/* find out what unit number we were assigned */
|
||||
if (ioctl(fd, SLIOCGUNIT, (caddr_t)&tmp_unit) < 0) {
|
||||
syslog(LOG_ERR, "ioctl(SLIOCGUNIT): %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
|
||||
if (tmp_unit < 0) {
|
||||
syslog(LOG_ERR, "bad unit (%d) from ioctl(SLIOCGUNIT)",tmp_unit);
|
||||
exit_handler(1);
|
||||
}
|
||||
|
||||
if (keepal > 0) {
|
||||
signal(SIGURG, sigurg_handler);
|
||||
if (ioctl(fd, SLIOCSKEEPAL, &keepal) < 0) {
|
||||
syslog(LOG_ERR, "ioctl(SLIOCSKEEPAL): %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
}
|
||||
if (outfill > 0 && ioctl(fd, SLIOCSOUTFILL, &outfill) < 0) {
|
||||
syslog(LOG_ERR, "ioctl(SLIOCSOUTFILL): %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
|
||||
/* open a socket as the handle to the interface */
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
syslog(LOG_ERR, "socket: %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
sprintf(ifr.ifr_name, "sl%d", tmp_unit);
|
||||
|
||||
/* get the flags for the interface */
|
||||
if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
|
||||
syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
|
||||
/* Assert any compression or no-icmp flags. */
|
||||
#define SLMASK (~(IFF_LINK0 | IFF_LINK1 | IFF_LINK2))
|
||||
ifr.ifr_flags &= SLMASK;
|
||||
ifr.ifr_flags |= slflags;
|
||||
if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&ifr) < 0) {
|
||||
syslog(LOG_ERR, "ioctl (SIOCSIFFLAGS): %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
close(s);
|
||||
}
|
||||
|
||||
/* configure the interface, e.g. by passing the unit number to a script. */
|
||||
void configure_network()
|
||||
{
|
||||
int new_unit;
|
||||
|
||||
/* find out what unit number we were assigned */
|
||||
if (ioctl(fd, SLIOCGUNIT, (caddr_t)&new_unit) < 0) {
|
||||
syslog(LOG_ERR, "ioctl(SLIOCGUNIT): %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
/* iff the unit number changes either invoke config_cmd or punt. */
|
||||
if (config_cmd) {
|
||||
char *s;
|
||||
s = (char*) malloc(strlen(config_cmd) + 32);
|
||||
if (s == NULL) {
|
||||
syslog(LOG_ERR, "malloc failed");
|
||||
exit(1);
|
||||
}
|
||||
sprintf (s, "%s %d %d", config_cmd, unit, new_unit);
|
||||
syslog(LOG_NOTICE, "configuring %s (sl%d):", dev, unit);
|
||||
syslog(LOG_NOTICE, " '%s'", s);
|
||||
system(s);
|
||||
free (s);
|
||||
unit = new_unit;
|
||||
} else {
|
||||
/* don't compare unit numbers if this is the first time to attach. */
|
||||
if (unit < 0)
|
||||
unit = new_unit;
|
||||
if (new_unit != unit) {
|
||||
syslog(LOG_ERR,
|
||||
"slip unit changed from sl%d to sl%d, but no -u CMD was specified!",
|
||||
unit, new_unit);
|
||||
exit_handler(1);
|
||||
}
|
||||
syslog(LOG_NOTICE,"sl%d connected to %s at %d baud",unit,dev,speed);
|
||||
}
|
||||
}
|
||||
|
||||
/* sighup_handler() is invoked when carrier drops, eg. before redial. */
|
||||
void sighup_handler()
|
||||
{
|
||||
if(exiting) return;
|
||||
|
||||
if (redial_cmd == NULL) {
|
||||
syslog(LOG_NOTICE,"SIGHUP on %s (sl%d); exiting", dev, unit);
|
||||
exit_handler(1);
|
||||
}
|
||||
again:
|
||||
/* invoke a shell for redial_cmd or punt. */
|
||||
if (*redial_cmd) { /* Non-empty redial command */
|
||||
syslog(LOG_NOTICE,"SIGHUP on %s (sl%d); running '%s'",
|
||||
dev, unit, redial_cmd);
|
||||
acquire_line(); /* reopen dead line */
|
||||
setup_line(CLOCAL);
|
||||
if (locked) {
|
||||
if (uucp_lock)
|
||||
uu_unlock(dvname); /* for redial */
|
||||
locked = 0;
|
||||
}
|
||||
if (system(redial_cmd))
|
||||
goto again;
|
||||
if (uucp_lock) {
|
||||
int res;
|
||||
if ((res = uu_lock(dvname)) != UU_LOCK_OK) {
|
||||
if (res != UU_LOCK_INUSE)
|
||||
syslog(LOG_ERR, "uu_lock: %s", uu_lockerr(res));
|
||||
syslog(LOG_ERR, "can't relock %s after %s, aborting",
|
||||
dev, redial_cmd);
|
||||
exit_handler(1);
|
||||
}
|
||||
locked = 1;
|
||||
}
|
||||
/* Now check again for carrier (dial command is done): */
|
||||
if (!(modem_control & CLOCAL)) {
|
||||
tty.c_cflag &= ~CLOCAL;
|
||||
if (tcsetattr(fd, TCSAFLUSH, &tty) < 0) {
|
||||
syslog(LOG_ERR, "tcsetattr(TCSAFLUSH): %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
ioctl(fd, TIOCMGET, &comstate);
|
||||
if (!(comstate & TIOCM_CD)) { /* check for carrier */
|
||||
/* force a redial if no carrier */
|
||||
goto again;
|
||||
}
|
||||
} else
|
||||
setup_line(0);
|
||||
} else { /* Empty redial command */
|
||||
syslog(LOG_NOTICE,"SIGHUP on %s (sl%d); reestablish connection",
|
||||
dev, unit);
|
||||
acquire_line(); /* reopen dead line */
|
||||
setup_line(0); /* restore ospeed from hangup (B0) */
|
||||
/* If modem control, just wait for carrier before attaching.
|
||||
If no modem control, just fall through immediately. */
|
||||
if (!(modem_control & CLOCAL)) {
|
||||
int carrier = 0;
|
||||
|
||||
syslog(LOG_NOTICE, "waiting for carrier on %s (sl%d)",
|
||||
dev, unit);
|
||||
/* Now wait for carrier before attaching line. */
|
||||
/* We must poll since CLOCAL prevents signal. */
|
||||
while (! carrier) {
|
||||
sleep(2);
|
||||
ioctl(fd, TIOCMGET, &comstate);
|
||||
if (comstate & TIOCM_CD)
|
||||
carrier = 1;
|
||||
}
|
||||
syslog(LOG_NOTICE, "carrier now present on %s (sl%d)",
|
||||
dev, unit);
|
||||
}
|
||||
}
|
||||
slip_discipline();
|
||||
configure_network();
|
||||
}
|
||||
/* Signal handler for SIGINT. We just log and exit. */
|
||||
void sigint_handler()
|
||||
{
|
||||
if(exiting) return;
|
||||
syslog(LOG_NOTICE,"SIGINT on %s (sl%d); exiting",dev,unit);
|
||||
exit_handler(0);
|
||||
}
|
||||
/* Signal handler for SIGURG. */
|
||||
void sigurg_handler()
|
||||
{
|
||||
int ttydisc = TTYDISC;
|
||||
|
||||
signal(SIGURG, SIG_IGN);
|
||||
if(exiting) return;
|
||||
syslog(LOG_NOTICE,"SIGURG on %s (sl%d); hangup",dev,unit);
|
||||
if (ioctl(fd, TIOCSETD, &ttydisc) < 0) {
|
||||
syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
cfsetospeed(&tty, B0);
|
||||
if (tcsetattr(fd, TCSANOW, &tty) < 0) {
|
||||
syslog(LOG_ERR, "tcsetattr(TCSANOW): %m");
|
||||
exit_handler(1);
|
||||
}
|
||||
/* Need to go to sighup handler in any case */
|
||||
if (modem_control & CLOCAL)
|
||||
kill (getpid(), SIGHUP);
|
||||
|
||||
}
|
||||
/* Signal handler for SIGTERM. We just log and exit. */
|
||||
void sigterm_handler()
|
||||
{
|
||||
if(exiting) return;
|
||||
syslog(LOG_NOTICE,"SIGTERM on %s (sl%d); exiting",dev,unit);
|
||||
exit_handler(0);
|
||||
}
|
||||
/* Run config_cmd if specified before exiting. */
|
||||
void exit_handler(int ret)
|
||||
{
|
||||
if(exiting) return;
|
||||
exiting = 1;
|
||||
/*
|
||||
* First close the slip line in case exit_cmd wants it (like to hang
|
||||
* up a modem or something).
|
||||
*/
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
if (uucp_lock && locked)
|
||||
uu_unlock(dvname);
|
||||
|
||||
/* Remove the PID file */
|
||||
(void)unlink(pidfilename);
|
||||
|
||||
if (config_cmd) {
|
||||
char *s;
|
||||
s = (char*) malloc(strlen(config_cmd) + 32);
|
||||
if (s == NULL) {
|
||||
syslog(LOG_ERR, "malloc failed");
|
||||
exit(1);
|
||||
}
|
||||
sprintf (s, "%s %d -1", config_cmd, unit);
|
||||
syslog(LOG_NOTICE, "deconfiguring %s (sl%d):", dev, unit);
|
||||
syslog(LOG_NOTICE, " '%s'", s);
|
||||
system(s);
|
||||
free (s);
|
||||
}
|
||||
/* invoke a shell for exit_cmd. */
|
||||
if (exit_cmd) {
|
||||
syslog(LOG_NOTICE,"exiting after running %s", exit_cmd);
|
||||
system(exit_cmd);
|
||||
}
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
/* local variables: */
|
||||
/* c-indent-level: 8 */
|
||||
/* c-argdecl-indent: 0 */
|
||||
/* c-label-offset: -8 */
|
||||
/* c-continued-statement-offset: 8 */
|
||||
/* c-brace-offset: 0 */
|
||||
/* comment-column: 32 */
|
||||
/* end: */
|
@ -1,9 +0,0 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/5/93
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= startslip
|
||||
WARNS?= 3
|
||||
DPADD= ${LIBUTIL}
|
||||
LDADD= -lutil
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,213 +0,0 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)startslip.1 8.1 (Berkeley) 6/5/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd June 5, 1993
|
||||
.Dt STARTSLIP 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm startslip
|
||||
.Nd dial up and login to a slip server
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl d
|
||||
.Op Fl b Ar speed
|
||||
.Oo
|
||||
.Fl s Ar string1
|
||||
.Op Fl s Ar string2 Op Ar ...\&
|
||||
.Oc
|
||||
.Op Fl h
|
||||
.Op Fl l
|
||||
.Op Fl L
|
||||
.Op Fl A Ar annexname
|
||||
.Op Fl U Ar upscript
|
||||
.Op Fl D Ar downscript
|
||||
.Op Fl t Ar script_timeout
|
||||
.Op Fl W Ar maxtries
|
||||
.Op Fl w Ar retry_pause
|
||||
.Op Fl K Ar keepalive
|
||||
.Op Fl O Ar outfill
|
||||
.Op Fl S Ar unit
|
||||
.Ar device user password
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility opens the specified
|
||||
.Ar device .
|
||||
Once carrier is asserted (if modem control is enabled)
|
||||
.Nm
|
||||
attempts to login as the specified
|
||||
.Ar user
|
||||
with the given
|
||||
.Ar password .
|
||||
Standard login: & Password: scheme assumed unless Annex option
|
||||
specified (see
|
||||
.Fl A ) .
|
||||
If successful, it puts the device into the slip line discipline,
|
||||
calls
|
||||
.Ar upscript
|
||||
and goes to wait mode.
|
||||
If carrier drops (modem control enabled) or a
|
||||
.Dv SIGHUP
|
||||
is sent to
|
||||
.Nm ,
|
||||
it closes the device, calls
|
||||
.Ar downscript
|
||||
and attempts to repeat the dialup and login sequence.
|
||||
If a
|
||||
.Dv SIGTERM
|
||||
is send to
|
||||
.Nm ,
|
||||
it closes the device, calls
|
||||
.Ar downscript
|
||||
and exits.
|
||||
When
|
||||
.Nm
|
||||
called twice on the same device, previous copy killed by a
|
||||
.Dv SIGTERM
|
||||
before any operation.
|
||||
.Pp
|
||||
The following options are available:
|
||||
.Bl -tag -width indent
|
||||
.It Fl d
|
||||
Print out debugging information.
|
||||
.It Fl b Ar speed
|
||||
Determine the baud rate used for
|
||||
.Ar device ,
|
||||
default value is 9600.
|
||||
.It Fl t Ar script_timeout
|
||||
Set login script timeout in seconds, default value is 90.
|
||||
.It Fl w Ar retry_pause
|
||||
Set connecting retry pause in seconds (increased from one retry to another),
|
||||
default value is 60.
|
||||
.It Fl W Ar maxtries
|
||||
Set maximum number of connection retries for one session,
|
||||
default value is 6.
|
||||
Value 0 means infinite count.
|
||||
.It Fl s Ar stringN
|
||||
The optional
|
||||
.Ar stringN
|
||||
is written to
|
||||
.Ar device .
|
||||
Return character is added automatically.
|
||||
For a dialup modem,
|
||||
the string is used to specify a dial sequence.
|
||||
No string written by default.
|
||||
You can specify several
|
||||
.Fl s Ar stringN
|
||||
arguments to use with each try, f.e.
|
||||
several host phone numbers.
|
||||
.It Fl A Ar annexname
|
||||
The
|
||||
.Nm
|
||||
utility assumes it is connecting to a Xylogics Annex box and engages in an
|
||||
appropriate dialog using the
|
||||
.Ar user
|
||||
and
|
||||
.Ar password
|
||||
arguments.
|
||||
The
|
||||
.Ar annexname
|
||||
argument is a string that is used to match against the Annex prompt
|
||||
to determine when a connection has been established.
|
||||
.It Fl h
|
||||
Use hardware (CTS/RTS) flow control for
|
||||
.Ar device .
|
||||
Default value is no flow control.
|
||||
.It Fl l
|
||||
Disable modem control (waiting for carrier and carrier drop sense) for
|
||||
.Ar device .
|
||||
Modem control is enabled by default.
|
||||
.It Fl U Ar upscript
|
||||
Specify a script to run when a SLIP interface becomes connected.
|
||||
This may
|
||||
contain
|
||||
.Xr ifconfig 8 ,
|
||||
.Xr route 8 ,
|
||||
and other appropriate commands.
|
||||
The arguments that
|
||||
are passed to the script are "slX up".
|
||||
Default value is
|
||||
.Pa /sbin/ifconfig .
|
||||
Dial sequence number (see
|
||||
.Fl s )
|
||||
passed via
|
||||
.Ev LINE
|
||||
environment variable.
|
||||
.It Fl D Ar downscript
|
||||
Specify a script to run when a SLIP connection goes away.
|
||||
The arguments that
|
||||
are passed to the script are "slX down".
|
||||
Default value is
|
||||
.Pa /sbin/ifconfig .
|
||||
Dial sequence number (see
|
||||
.Fl s )
|
||||
passed via
|
||||
.Ev LINE
|
||||
environment variable.
|
||||
.It Fl K Ar keepalive
|
||||
Set SLIP "keep alive" timeout in seconds.
|
||||
If FRAME_END not received during this
|
||||
time period, a reconnect will occur.
|
||||
Active "out fill" timeout expected from other
|
||||
side.
|
||||
Default value is no timeout.
|
||||
.It Fl O Ar outfill
|
||||
Set SLIP "out fill" timeout in seconds.
|
||||
It causes at least one FRAME_END
|
||||
to be sent during this timeout.
|
||||
Needed for "keep alive" timeout on other side.
|
||||
Default value is no timeout.
|
||||
.It Fl S Ar unit
|
||||
Set SLIP unit number directly.
|
||||
Use with caution, no check for two
|
||||
interfaces with same number made.
|
||||
Default is dynamic assignment.
|
||||
.It Fl L
|
||||
Use uucp-style device locking.
|
||||
You need it unless you start
|
||||
.Nm
|
||||
from external program which already does uucp locking.
|
||||
Default case is no uucp locking to satisfy such programs.
|
||||
.El
|
||||
.Sh FILES
|
||||
.Bl -tag -width /var/run/startslip.<device>.pid -compact
|
||||
.It Pa /var/run/startslip.<device>.pid
|
||||
pid stored here
|
||||
.It Pa /usr/share/examples/startslip/*
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr uustat 1 Pq Pa ports/net/freebsd-uucp ,
|
||||
.Xr slattach 8 ,
|
||||
.Xr sliplogin 8
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
appeared in
|
||||
.Bx 4.4 .
|
@ -1,595 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1990, 1991, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)startslip.c 8.1 (Berkeley) 6/5/93";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <libutil.h>
|
||||
#include <paths.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <net/slip.h>
|
||||
|
||||
#define DEFAULT_BAUD B9600
|
||||
int speed = DEFAULT_BAUD;
|
||||
#define FC_NONE 0 /* flow control: none */
|
||||
#define FC_HW 1 /* flow control: hardware (RTS/CTS) */
|
||||
int flowcontrol = FC_NONE;
|
||||
int modem_control = 1; /* !CLOCAL+HUPCL iff we watch carrier. */
|
||||
int sl_unit = -1;
|
||||
int uucp_lock = 0; /* uucp locking */
|
||||
char *annex;
|
||||
char *username;
|
||||
int hup;
|
||||
int terminate;
|
||||
int locked = 0; /* uucp lock active */
|
||||
int logged_in = 0;
|
||||
int wait_time = 60; /* then back off */
|
||||
int script_timeout = 90; /* connect script default timeout */
|
||||
time_t conn_time, start_time;
|
||||
int MAXTRIES = 6; /* w/60 sec and doubling, takes an hour */
|
||||
#define PIDFILE "%sstartslip.%s.pid"
|
||||
|
||||
#define MAXDIALS 20
|
||||
char *dials[MAXDIALS];
|
||||
int diali, dialc;
|
||||
|
||||
int fd = -1;
|
||||
FILE *pfd;
|
||||
char *dvname, *devicename;
|
||||
char pidfile[80];
|
||||
|
||||
#ifdef DEBUG
|
||||
int debug = 1;
|
||||
#undef LOG_ERR
|
||||
#undef LOG_INFO
|
||||
#define syslog fprintf
|
||||
#define LOG_ERR stderr
|
||||
#define LOG_INFO stderr
|
||||
#else
|
||||
int debug = 0;
|
||||
#endif
|
||||
#define printd if (debug) printf
|
||||
|
||||
int carrier(void);
|
||||
void down(int);
|
||||
int getline(char *, int, int, time_t);
|
||||
void sighup(int);
|
||||
void sigterm(int);
|
||||
void sigurg(int);
|
||||
static void usage(void);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char *cp, **ap;
|
||||
int ch, disc;
|
||||
FILE *wfd = NULL;
|
||||
char *dialerstring = 0, buf[BUFSIZ];
|
||||
int unitnum, keepal = 0, outfill = 0;
|
||||
char unitname[32];
|
||||
char *password;
|
||||
char *upscript = NULL, *downscript = NULL;
|
||||
int first = 1, tries = 0;
|
||||
time_t fintimeout;
|
||||
long lpid;
|
||||
pid_t pid;
|
||||
struct termios t;
|
||||
|
||||
while ((ch = getopt(argc, argv, "dhlb:s:t:w:A:U:D:W:K:O:S:L")) != -1)
|
||||
switch (ch) {
|
||||
case 'd':
|
||||
debug = 1;
|
||||
break;
|
||||
case 'b':
|
||||
speed = atoi(optarg);
|
||||
break;
|
||||
case 's':
|
||||
if (diali >= MAXDIALS)
|
||||
errx(1, "max dial strings number (%d) exceeded", MAXDIALS);
|
||||
dials[diali++] = strdup(optarg);
|
||||
break;
|
||||
case 't':
|
||||
script_timeout = atoi(optarg);
|
||||
break;
|
||||
case 'w':
|
||||
wait_time = atoi(optarg);
|
||||
break;
|
||||
case 'W':
|
||||
MAXTRIES = atoi(optarg);
|
||||
break;
|
||||
case 'A':
|
||||
annex = strdup(optarg);
|
||||
break;
|
||||
case 'U':
|
||||
upscript = strdup(optarg);
|
||||
break;
|
||||
case 'D':
|
||||
downscript = strdup(optarg);
|
||||
break;
|
||||
case 'L':
|
||||
uucp_lock = 1;
|
||||
break;
|
||||
case 'l':
|
||||
modem_control = 0;
|
||||
break;
|
||||
case 'h':
|
||||
flowcontrol = FC_HW;
|
||||
break;
|
||||
case 'K':
|
||||
keepal = atoi(optarg);
|
||||
break;
|
||||
case 'O':
|
||||
outfill = atoi(optarg);
|
||||
break;
|
||||
case 'S':
|
||||
sl_unit = atoi(optarg);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc != 3)
|
||||
usage();
|
||||
|
||||
/*
|
||||
* Copy these so they exist after we clobber them.
|
||||
*/
|
||||
devicename = strdup(argv[0]);
|
||||
username = strdup(argv[1]);
|
||||
password = strdup(argv[2]);
|
||||
|
||||
/*
|
||||
* Security hack. Do not want private information such as the
|
||||
* password and possible phone number to be left around.
|
||||
* So we clobber the arguments.
|
||||
*/
|
||||
for (ap = argv - optind + 1; ap < argv + 3; ap++)
|
||||
for (cp = *ap; *cp != 0; cp++)
|
||||
*cp = '\0';
|
||||
|
||||
openlog("startslip", LOG_PID|LOG_PERROR, LOG_DAEMON);
|
||||
|
||||
if (debug)
|
||||
setbuf(stdout, NULL);
|
||||
|
||||
signal(SIGTERM, sigterm);
|
||||
if ((dvname = strrchr(devicename, '/')) == NULL)
|
||||
dvname = devicename;
|
||||
else
|
||||
dvname++;
|
||||
if (snprintf(pidfile, sizeof(pidfile), PIDFILE, _PATH_VARRUN, dvname)
|
||||
>= (int)sizeof(pidfile))
|
||||
usage();
|
||||
|
||||
if ((pfd = fopen(pidfile, "r")) != NULL) {
|
||||
if (fscanf(pfd, "%ld\n", &lpid) == 1) {
|
||||
pid = lpid;
|
||||
if (pid == lpid && pid > 0)
|
||||
kill(pid, SIGTERM);
|
||||
}
|
||||
fclose(pfd);
|
||||
pfd = NULL; /* not remove pidfile yet */
|
||||
sleep(5); /* allow down script to be completed */
|
||||
} else
|
||||
restart:
|
||||
signal(SIGHUP, SIG_IGN);
|
||||
signal(SIGURG, SIG_IGN);
|
||||
hup = 0;
|
||||
if (wfd) {
|
||||
printd("fclose, ");
|
||||
fclose(wfd);
|
||||
conn_time = time(NULL) - start_time;
|
||||
if (uucp_lock)
|
||||
uu_unlock(dvname);
|
||||
locked = 0;
|
||||
wfd = NULL;
|
||||
fd = -1;
|
||||
sleep(5);
|
||||
} else if (fd >= 0) {
|
||||
printd("close, ");
|
||||
close(fd);
|
||||
conn_time = time(NULL) - start_time;
|
||||
if (uucp_lock)
|
||||
uu_unlock(dvname);
|
||||
locked = 0;
|
||||
fd = -1;
|
||||
sleep(5);
|
||||
}
|
||||
if (logged_in) {
|
||||
syslog(LOG_INFO, "%s: connection time elapsed: %ld secs",
|
||||
username, (long)conn_time);
|
||||
sprintf(buf, "LINE=%d %s %s down",
|
||||
diali ? (dialc - 1) % diali : 0,
|
||||
downscript ? downscript : _PATH_IFCONFIG , unitname);
|
||||
(void) system(buf);
|
||||
logged_in = 0;
|
||||
}
|
||||
if (terminate)
|
||||
down(0);
|
||||
tries++;
|
||||
if (MAXTRIES > 0 && tries > MAXTRIES) {
|
||||
syslog(LOG_ERR, "%s: exiting login after %d tries", username, tries);
|
||||
/* ???
|
||||
if (first)
|
||||
*/
|
||||
down(3);
|
||||
}
|
||||
if (tries > 1) {
|
||||
syslog(LOG_INFO, "%s: sleeping %d seconds (%d tries)",
|
||||
username, wait_time * (tries - 1), tries);
|
||||
sleep(wait_time * (tries - 1));
|
||||
if (terminate)
|
||||
goto restart;
|
||||
}
|
||||
|
||||
if (daemon(1, debug) < 0) {
|
||||
syslog(LOG_ERR, "%s: daemon: %m", username);
|
||||
down(2);
|
||||
}
|
||||
|
||||
pid = getpid();
|
||||
printd("restart: pid %ld: ", (long)pid);
|
||||
if ((pfd = fopen(pidfile, "w")) != NULL) {
|
||||
fprintf(pfd, "%ld\n", (long)pid);
|
||||
fclose(pfd);
|
||||
}
|
||||
printd("open");
|
||||
if (uucp_lock) {
|
||||
int res;
|
||||
if ((res = uu_lock(dvname)) != UU_LOCK_OK) {
|
||||
if (res != UU_LOCK_INUSE)
|
||||
syslog(LOG_ERR, "uu_lock: %s", uu_lockerr(res));
|
||||
syslog(LOG_ERR, "%s: can't lock %s", username, devicename);
|
||||
goto restart;
|
||||
}
|
||||
locked = 1;
|
||||
}
|
||||
if ((fd = open(devicename, O_RDWR | O_NONBLOCK)) < 0) {
|
||||
syslog(LOG_ERR, "%s: open %s: %m", username, devicename);
|
||||
if (first)
|
||||
down(1);
|
||||
else {
|
||||
if (uucp_lock)
|
||||
uu_unlock(dvname);
|
||||
locked = 0;
|
||||
goto restart;
|
||||
}
|
||||
}
|
||||
printd(" %d", fd);
|
||||
signal(SIGHUP, sighup);
|
||||
if (ioctl(fd, TIOCSCTTY, 0) < 0) {
|
||||
syslog(LOG_ERR, "%s: ioctl (TIOCSCTTY): %m", username);
|
||||
down(2);
|
||||
}
|
||||
if (tcsetpgrp(fd, getpid()) < 0) {
|
||||
syslog(LOG_ERR, "%s: tcsetpgrp failed: %m", username);
|
||||
down(2);
|
||||
}
|
||||
printd(", ioctl\n");
|
||||
if (tcgetattr(fd, &t) < 0) {
|
||||
syslog(LOG_ERR, "%s: tcgetattr(%s): %m", username, devicename);
|
||||
down(2);
|
||||
}
|
||||
cfmakeraw(&t);
|
||||
switch (flowcontrol) {
|
||||
case FC_HW:
|
||||
t.c_cflag |= (CRTS_IFLOW|CCTS_OFLOW);
|
||||
break;
|
||||
case FC_NONE:
|
||||
t.c_cflag &= ~(CRTS_IFLOW|CCTS_OFLOW);
|
||||
break;
|
||||
}
|
||||
if (modem_control)
|
||||
t.c_cflag |= HUPCL;
|
||||
else
|
||||
t.c_cflag &= ~(HUPCL);
|
||||
t.c_cflag |= CLOCAL; /* until modem commands passes */
|
||||
cfsetispeed(&t, speed);
|
||||
cfsetospeed(&t, speed);
|
||||
if (tcsetattr(fd, TCSAFLUSH, &t) < 0) {
|
||||
syslog(LOG_ERR, "%s: tcsetattr(%s): %m", username, devicename);
|
||||
down(2);
|
||||
}
|
||||
sleep(2); /* wait for flakey line to settle */
|
||||
if (hup || terminate)
|
||||
goto restart;
|
||||
|
||||
wfd = fdopen(fd, "w+");
|
||||
if (wfd == NULL) {
|
||||
syslog(LOG_ERR, "%s: can't fdopen %s: %m", username, devicename);
|
||||
down(2);
|
||||
}
|
||||
setbuf(wfd, NULL);
|
||||
|
||||
if (diali > 0)
|
||||
dialerstring = dials[dialc++ % diali];
|
||||
if (dialerstring) {
|
||||
syslog(LOG_INFO, "%s: dialer string: %s\\r", username, dialerstring);
|
||||
fprintf(wfd, "%s\r", dialerstring);
|
||||
}
|
||||
printd("\n");
|
||||
|
||||
fintimeout = time(NULL) + script_timeout;
|
||||
if (modem_control) {
|
||||
printd("waiting for carrier\n");
|
||||
while (time(NULL) < fintimeout && !carrier()) {
|
||||
sleep(1);
|
||||
if (hup || terminate)
|
||||
goto restart;
|
||||
}
|
||||
if (!carrier())
|
||||
goto restart;
|
||||
t.c_cflag &= ~(CLOCAL);
|
||||
if (tcsetattr(fd, TCSANOW, &t) < 0) {
|
||||
syslog(LOG_ERR, "%s: tcsetattr(%s): %m", username, devicename);
|
||||
down(2);
|
||||
}
|
||||
/* Only now we able to receive HUP on carrier drop! */
|
||||
}
|
||||
|
||||
/*
|
||||
* Log in
|
||||
*/
|
||||
printd("look for login: ");
|
||||
for (;;) {
|
||||
if (getline(buf, BUFSIZ, fd, fintimeout) == 0 || hup || terminate)
|
||||
goto restart;
|
||||
if (annex) {
|
||||
if (bcmp(buf, annex, strlen(annex)) == 0) {
|
||||
fprintf(wfd, "slip\r");
|
||||
printd("Sent \"slip\"\n");
|
||||
continue;
|
||||
}
|
||||
if (bcmp(&buf[1], "sername:", 8) == 0) {
|
||||
fprintf(wfd, "%s\r", username);
|
||||
printd("Sent login: %s\n", username);
|
||||
continue;
|
||||
}
|
||||
if (bcmp(&buf[1], "assword:", 8) == 0) {
|
||||
fprintf(wfd, "%s\r", password);
|
||||
printd("Sent password: %s\n", password);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (strstr(&buf[1], "ogin:") != NULL) {
|
||||
fprintf(wfd, "%s\r", username);
|
||||
printd("Sent login: %s\n", username);
|
||||
continue;
|
||||
}
|
||||
if (strstr(&buf[1], "assword:") != NULL) {
|
||||
fprintf(wfd, "%s\r", password);
|
||||
printd("Sent password: %s\n", password);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sleep(5); /* Wait until login completed */
|
||||
if (hup || terminate)
|
||||
goto restart;
|
||||
start_time = time(NULL);
|
||||
/*
|
||||
* Attach
|
||||
*/
|
||||
printd("setd");
|
||||
disc = SLIPDISC;
|
||||
if (ioctl(fd, TIOCSETD, &disc) < 0) {
|
||||
syslog(LOG_ERR, "%s: ioctl (%s, TIOCSETD): %m",
|
||||
username, devicename);
|
||||
down(2);
|
||||
}
|
||||
if (sl_unit >= 0 && ioctl(fd, SLIOCSUNIT, &sl_unit) < 0) {
|
||||
syslog(LOG_ERR, "%s: ioctl(SLIOCSUNIT): %m", username);
|
||||
down(2);
|
||||
}
|
||||
if (ioctl(fd, SLIOCGUNIT, &unitnum) < 0) {
|
||||
syslog(LOG_ERR, "%s: ioctl(SLIOCGUNIT): %m", username);
|
||||
down(2);
|
||||
}
|
||||
sprintf(unitname, "sl%d", unitnum);
|
||||
|
||||
if (keepal > 0) {
|
||||
signal(SIGURG, sigurg);
|
||||
if (ioctl(fd, SLIOCSKEEPAL, &keepal) < 0) {
|
||||
syslog(LOG_ERR, "%s: ioctl(SLIOCSKEEPAL): %m", username);
|
||||
down(2);
|
||||
}
|
||||
}
|
||||
if (outfill > 0 && ioctl(fd, SLIOCSOUTFILL, &outfill) < 0) {
|
||||
syslog(LOG_ERR, "%s: ioctl(SLIOCSOUTFILL): %m", username);
|
||||
down(2);
|
||||
}
|
||||
|
||||
sprintf(buf, "LINE=%d %s %s up",
|
||||
diali ? (dialc - 1) % diali : 0,
|
||||
upscript ? upscript : _PATH_IFCONFIG , unitname);
|
||||
(void) system(buf);
|
||||
|
||||
printd(", ready\n");
|
||||
if (!first)
|
||||
syslog(LOG_INFO, "%s: reconnected on %s (%d tries)", username, unitname, tries);
|
||||
else
|
||||
syslog(LOG_INFO, "%s: connected on %s", username, unitname);
|
||||
first = 0;
|
||||
tries = 0;
|
||||
logged_in = 1;
|
||||
while (hup == 0 && terminate == 0) {
|
||||
sigpause(0L);
|
||||
printd("sigpause return\n");
|
||||
}
|
||||
goto restart;
|
||||
return(0); /* not reached */
|
||||
}
|
||||
|
||||
void
|
||||
sighup(int sig __unused)
|
||||
{
|
||||
|
||||
printd("hup\n");
|
||||
if (hup == 0 && logged_in)
|
||||
syslog(LOG_INFO, "%s: got hangup signal", username);
|
||||
hup = 1;
|
||||
}
|
||||
|
||||
void
|
||||
sigurg(int sig __unused)
|
||||
{
|
||||
|
||||
printd("urg\n");
|
||||
if (hup == 0 && logged_in)
|
||||
syslog(LOG_INFO, "%s: got dead line signal", username);
|
||||
hup = 1;
|
||||
}
|
||||
|
||||
void
|
||||
sigterm(int sig __unused)
|
||||
{
|
||||
|
||||
printd("terminate\n");
|
||||
if (terminate == 0 && logged_in)
|
||||
syslog(LOG_INFO, "%s: got terminate signal", username);
|
||||
terminate = 1;
|
||||
}
|
||||
|
||||
int
|
||||
getline(char *buf, int size, int fd, time_t fintimeout)
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
fd_set readfds;
|
||||
struct timeval tv;
|
||||
time_t timeout;
|
||||
|
||||
size--;
|
||||
for (i = 0; i < size; i++) {
|
||||
if (hup || terminate)
|
||||
return (0);
|
||||
if ((timeout = fintimeout - time(NULL)) <= 0)
|
||||
goto tout;
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(fd, &readfds);
|
||||
tv.tv_sec = timeout;
|
||||
tv.tv_usec = 0;
|
||||
if ((ret = select(fd + 1, &readfds, NULL, NULL, &tv)) < 0) {
|
||||
if (errno != EINTR)
|
||||
syslog(LOG_ERR, "%s: getline: select: %m", username);
|
||||
} else {
|
||||
if (! ret) {
|
||||
tout:
|
||||
printd("getline: timed out\n");
|
||||
return (0);
|
||||
}
|
||||
if ((ret = read(fd, &buf[i], 1)) == 1) {
|
||||
buf[i] &= 0177;
|
||||
if (buf[i] == '\r' || buf[i] == '\0') {
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
if (buf[i] != '\n' && buf[i] != ':')
|
||||
continue;
|
||||
buf[i + 1] = '\0';
|
||||
printd("Got %d: %s", i + 1, buf);
|
||||
return (i+1);
|
||||
}
|
||||
if (ret <= 0) {
|
||||
if (ret < 0) {
|
||||
syslog(LOG_ERR, "%s: getline: read: %m", username);
|
||||
} else
|
||||
syslog(LOG_ERR, "%s: read returned 0", username);
|
||||
buf[i] = '\0';
|
||||
printd("returning %d after %d: %s\n", ret, i, buf);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
carrier(void)
|
||||
{
|
||||
int comstate;
|
||||
|
||||
if (ioctl(fd, TIOCMGET, &comstate) < 0) {
|
||||
syslog(LOG_ERR, "%s: ioctl (%s, TIOCMGET): %m",
|
||||
username, devicename);
|
||||
down(2);
|
||||
}
|
||||
return !!(comstate & TIOCM_CD);
|
||||
}
|
||||
|
||||
void
|
||||
down(int code)
|
||||
{
|
||||
if (fd > -1)
|
||||
close(fd);
|
||||
if (pfd)
|
||||
unlink(pidfile);
|
||||
if (uucp_lock && locked)
|
||||
uu_unlock(dvname);
|
||||
exit(code);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
|
||||
"usage: startslip [-d] [-b speed] [-s string1 [-s string2 [...]]] [-h] [-l]",
|
||||
" [-L] [-A annexname] [-U upscript] [-D downscript]",
|
||||
" [-t script_timeout] [-W maxtries] [-w retry_pause]",
|
||||
" [-K keepalive] [-O outfill] [-S unit] device user password");
|
||||
exit(1);
|
||||
}
|
@ -289,7 +289,6 @@ MAN= aac.4 \
|
||||
ppbus.4 \
|
||||
ppc.4 \
|
||||
ppi.4 \
|
||||
ppp.4 \
|
||||
psm.4 \
|
||||
pst.4 \
|
||||
pt.4 \
|
||||
@ -324,7 +323,6 @@ MAN= aac.4 \
|
||||
sio.4 \
|
||||
sis.4 \
|
||||
sk.4 \
|
||||
sl.4 \
|
||||
smb.4 \
|
||||
smbus.4 \
|
||||
smp.4 \
|
||||
@ -531,7 +529,6 @@ MLINKS+=pccbb.4 cbb.4
|
||||
MLINKS+=pcm.4 snd.4 \
|
||||
pcm.4 sound.4
|
||||
MLINKS+=pcn.4 if_pcn.4
|
||||
MLINKS+=ppp.4 if_ppp.4
|
||||
MLINKS+=ral.4 if_ral.4
|
||||
MLINKS+=re.4 if_re.4
|
||||
MLINKS+=rl.4 if_rl.4
|
||||
@ -544,7 +541,6 @@ MLINKS+=scsi.4 CAM.4 \
|
||||
MLINKS+=sf.4 if_sf.4
|
||||
MLINKS+=sis.4 if_sis.4
|
||||
MLINKS+=sk.4 if_sk.4
|
||||
MLINKS+=sl.4 if_sl.4
|
||||
MLINKS+=smp.4 SMP.4
|
||||
MLINKS+=sn.4 if_sn.4
|
||||
MLINKS+=snd_envy24.4 snd_ak452x.4
|
||||
|
@ -1,84 +0,0 @@
|
||||
.\" $NetBSD: ppp.4,v 1.1 1996/08/10 21:26:12 explorer Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1983, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" From: @(#)lo.4 8.1 (Berkeley) 6/5/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd August 10, 1996
|
||||
.Dt PPP 4
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm ppp
|
||||
.Nd point to point protocol network interface
|
||||
.Sh SYNOPSIS
|
||||
.Cd "device ppp"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
interface allows serial lines to be used as network interfaces using the
|
||||
.Em point-to-point
|
||||
protocol.
|
||||
The
|
||||
.Nm
|
||||
interface can use various types of compression and has many features over
|
||||
the
|
||||
.Xr sl 4
|
||||
protocol.
|
||||
.Pp
|
||||
Each
|
||||
.Nm
|
||||
interface is created at runtime using interface cloning.
|
||||
This is most easily done with the
|
||||
.Xr ifconfig 8
|
||||
.Cm create
|
||||
command or using the
|
||||
.Va cloned_interfaces
|
||||
variable in
|
||||
.Xr rc.conf 5 .
|
||||
.Sh DIAGNOSTICS
|
||||
.Bl -diag
|
||||
.It ppp%d: af%d not supported.
|
||||
The interface was handed
|
||||
a message with addresses formatted in an unsuitable address
|
||||
family; the packet was dropped.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr inet 4 ,
|
||||
.Xr intro 4 ,
|
||||
.Xr sl 4 ,
|
||||
.Xr pppd 8 ,
|
||||
.Xr pppstats 8
|
||||
.Sh BUGS
|
||||
Currently, only the
|
||||
.Xr ip 4
|
||||
protocol is supported.
|
@ -1,82 +0,0 @@
|
||||
.\" $NetBSD: sl.4,v 1.1 1996/08/10 21:26:14 explorer Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1983, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" From: @(#)lo.4 8.1 (Berkeley) 6/5/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd August 10, 1996
|
||||
.Dt SL 4
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm sl
|
||||
.Nd slip network interface
|
||||
.Sh SYNOPSIS
|
||||
.Cd "device sl" Op Ar count
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
interface allows serial lines to be used as network interfaces using the
|
||||
.Em slip
|
||||
protocol.
|
||||
The
|
||||
.Nm
|
||||
interface can use Van Jacobson TCP header compression and ICMP filtering.
|
||||
This is arranged by using the various link-level flags to the
|
||||
.Xr ifconfig 8
|
||||
command:
|
||||
.Pp
|
||||
.Bl -tag -width LINK0X -compact
|
||||
.It Em link0
|
||||
Enable VJ header compression.
|
||||
.It Em link1
|
||||
Suppress ICMP traffic.
|
||||
.It Em link2
|
||||
Enable VJ header compression autodetection.
|
||||
This will turn on the
|
||||
.Em link0
|
||||
flag as soon as the first VJ-compressed packet has been seen by
|
||||
the driver.
|
||||
.El
|
||||
.Sh DIAGNOSTICS
|
||||
.Bl -diag
|
||||
.It sl%d: af%d not supported.
|
||||
The interface was handed
|
||||
a message with addresses formatted in an unsuitable address
|
||||
family; the packet was dropped.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr inet 4 ,
|
||||
.Xr intro 4 ,
|
||||
.Xr slattach 8 ,
|
||||
.Xr sliplogin 8 ,
|
||||
.Xr slstat 8
|
@ -372,7 +372,6 @@ WITH_IDEA=
|
||||
SENDMAIL \
|
||||
SETUID_LOGIN \
|
||||
SHAREDOCS \
|
||||
SLIP \
|
||||
SSP \
|
||||
SYSINSTALL \
|
||||
SYMVER \
|
||||
|
1117
sys/net/bsd_comp.c
1117
sys/net/bsd_comp.c
File diff suppressed because it is too large
Load Diff
1733
sys/net/if_ppp.c
1733
sys/net/if_ppp.c
File diff suppressed because it is too large
Load Diff
139
sys/net/if_ppp.h
139
sys/net/if_ppp.h
@ -1,139 +0,0 @@
|
||||
/*
|
||||
* if_ppp.h - Point-to-Point Protocol definitions.
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1989 Carnegie Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Carnegie Mellon University. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _IF_PPP_H_
|
||||
#define _IF_PPP_H_
|
||||
|
||||
/* XXX this used to be self-contained. */
|
||||
#include <net/ppp_defs.h>
|
||||
#include <net/if.h>
|
||||
|
||||
/*
|
||||
* Packet sizes
|
||||
*/
|
||||
#define PPP_MTU 1500 /* Default MTU (size of Info field) */
|
||||
#define PPP_MAXMRU 65000 /* Largest MRU we allow */
|
||||
#define PPP_MAXMTU 16384 /* Largest MTU we allow */
|
||||
|
||||
/*
|
||||
* Bit definitions for flags.
|
||||
*/
|
||||
#define SC_COMP_PROT 0x00000001 /* protocol compression (output) */
|
||||
#define SC_COMP_AC 0x00000002 /* header compression (output) */
|
||||
#define SC_COMP_TCP 0x00000004 /* TCP (VJ) compression (output) */
|
||||
#define SC_NO_TCP_CCID 0x00000008 /* disable VJ connection-id comp. */
|
||||
#define SC_REJ_COMP_AC 0x00000010 /* reject adrs/ctrl comp. on input */
|
||||
#define SC_REJ_COMP_TCP 0x00000020 /* reject TCP (VJ) comp. on input */
|
||||
#define SC_CCP_OPEN 0x00000040 /* Look at CCP packets */
|
||||
#define SC_CCP_UP 0x00000080 /* May send/recv compressed packets */
|
||||
#define SC_DEBUG 0x00010000 /* enable debug messages */
|
||||
#define SC_LOG_INPKT 0x00020000 /* log contents of good pkts recvd */
|
||||
#define SC_LOG_OUTPKT 0x00040000 /* log contents of pkts sent */
|
||||
#define SC_LOG_RAWIN 0x00080000 /* log all chars received */
|
||||
#define SC_LOG_FLUSH 0x00100000 /* log all chars flushed */
|
||||
#define SC_RCV_B7_0 0x01000000 /* have rcvd char with bit 7 = 0 */
|
||||
#define SC_RCV_B7_1 0x02000000 /* have rcvd char with bit 7 = 1 */
|
||||
#define SC_RCV_EVNP 0x04000000 /* have rcvd char with even parity */
|
||||
#define SC_RCV_ODDP 0x08000000 /* have rcvd char with odd parity */
|
||||
#define SC_MASK 0x0fff00ff /* bits that user can change */
|
||||
|
||||
/*
|
||||
* State bits in sc_flags, not changeable by user.
|
||||
*/
|
||||
#define SC_TIMEOUT 0x00000400 /* timeout is currently pending */
|
||||
#define SC_VJ_RESET 0x00000800 /* need to reset VJ decomp */
|
||||
#define SC_COMP_RUN 0x00001000 /* compressor has been initiated */
|
||||
#define SC_DECOMP_RUN 0x00002000 /* decompressor has been initiated */
|
||||
#define SC_DC_ERROR 0x00004000 /* non-fatal decomp error detected */
|
||||
#define SC_DC_FERROR 0x00008000 /* fatal decomp error detected */
|
||||
#define SC_TBUSY 0x10000000 /* xmitter doesn't need a packet yet */
|
||||
#define SC_PKTLOST 0x20000000 /* have lost or dropped a packet */
|
||||
#define SC_FLUSH 0x40000000 /* flush input until next PPP_FLAG */
|
||||
#define SC_ESCAPED 0x80000000 /* saw a PPP_ESCAPE */
|
||||
|
||||
/*
|
||||
* Ioctl definitions.
|
||||
*/
|
||||
|
||||
struct npioctl {
|
||||
int protocol; /* PPP procotol, e.g. PPP_IP */
|
||||
enum NPmode mode;
|
||||
};
|
||||
|
||||
/* Structure describing a CCP configuration option, for PPPIOCSCOMPRESS */
|
||||
struct ppp_option_data {
|
||||
u_char *ptr;
|
||||
u_int length;
|
||||
int transmit;
|
||||
};
|
||||
|
||||
struct ifpppstatsreq {
|
||||
char ifr_name[IFNAMSIZ];
|
||||
struct ppp_stats stats;
|
||||
};
|
||||
|
||||
struct ifpppcstatsreq {
|
||||
char ifr_name[IFNAMSIZ];
|
||||
struct ppp_comp_stats stats;
|
||||
};
|
||||
|
||||
/*
|
||||
* Ioctl definitions.
|
||||
*/
|
||||
|
||||
#define PPPIOCGFLAGS _IOR('t', 90, int) /* get configuration flags */
|
||||
#define PPPIOCSFLAGS _IOW('t', 89, int) /* set configuration flags */
|
||||
#define PPPIOCGASYNCMAP _IOR('t', 88, int) /* get async map */
|
||||
#define PPPIOCSASYNCMAP _IOW('t', 87, int) /* set async map */
|
||||
#define PPPIOCGUNIT _IOR('t', 86, int) /* get ppp unit number */
|
||||
#define PPPIOCGRASYNCMAP _IOR('t', 85, int) /* get receive async map */
|
||||
#define PPPIOCSRASYNCMAP _IOW('t', 84, int) /* set receive async map */
|
||||
#define PPPIOCGMRU _IOR('t', 83, int) /* get max receive unit */
|
||||
#define PPPIOCSMRU _IOW('t', 82, int) /* set max receive unit */
|
||||
#define PPPIOCSMAXCID _IOW('t', 81, int) /* set VJ max slot ID */
|
||||
#define PPPIOCGXASYNCMAP _IOR('t', 80, ext_accm) /* get extended ACCM */
|
||||
#define PPPIOCSXASYNCMAP _IOW('t', 79, ext_accm) /* set extended ACCM */
|
||||
#define PPPIOCXFERUNIT _IO('t', 78) /* transfer PPP unit */
|
||||
#define PPPIOCSCOMPRESS _IOW('t', 77, struct ppp_option_data)
|
||||
#define PPPIOCGNPMODE _IOWR('t', 76, struct npioctl) /* get NP mode */
|
||||
#define PPPIOCSNPMODE _IOW('t', 75, struct npioctl) /* set NP mode */
|
||||
#define PPPIOCGIDLE _IOR('t', 74, struct ppp_idle) /* get idle time */
|
||||
#define PPPIOCSPASS _IOW('t', 71, struct bpf_program) /* set pass filter */
|
||||
#define PPPIOCSACTIVE _IOW('t', 70, struct bpf_program) /* set active filt */
|
||||
|
||||
/* PPPIOC[GS]MTU are alternatives to SIOC[GS]IFMTU, used under Ultrix */
|
||||
#define PPPIOCGMTU _IOR('t', 73, int) /* get interface MTU */
|
||||
#define PPPIOCSMTU _IOW('t', 72, int) /* set interface MTU */
|
||||
|
||||
/*
|
||||
* These two are interface ioctls so that pppstats can do them on
|
||||
* a socket without having to open the serial device.
|
||||
*/
|
||||
#define SIOCGPPPSTATS _IOWR('i', 123, struct ifpppstatsreq)
|
||||
#define SIOCGPPPCSTATS _IOWR('i', 122, struct ifpppcstatsreq)
|
||||
|
||||
#if !defined(ifr_mtu)
|
||||
#define ifr_mtu ifr_ifru.ifru_metric
|
||||
#endif
|
||||
|
||||
#endif /* _IF_PPP_H_ */
|
@ -1,113 +0,0 @@
|
||||
/*
|
||||
* if_pppvar.h - private structures and declarations for PPP.
|
||||
*/
|
||||
/*-
|
||||
* Copyright (c) 1994 The Australian National University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, provided that the above copyright
|
||||
* notice appears in all copies. This software is provided without any
|
||||
* warranty, express or implied. The Australian National University
|
||||
* makes no representations about the suitability of this software for
|
||||
* any purpose.
|
||||
*
|
||||
* IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
|
||||
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
|
||||
* THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
* ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
|
||||
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
||||
* OR MODIFICATIONS.
|
||||
*
|
||||
* Copyright (c) 1989 Carnegie Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Carnegie Mellon University. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Supported network protocols. These values are used for
|
||||
* indexing sc_npmode.
|
||||
*/
|
||||
#define NP_IP 0 /* Internet Protocol */
|
||||
#define NP_IPV6 1 /* Internet Protocol version 6 */
|
||||
#define NUM_NP 2 /* Number of NPs. */
|
||||
|
||||
/*
|
||||
* Structure describing each ppp unit.
|
||||
*/
|
||||
struct ppp_softc {
|
||||
struct ifnet *sc_ifp; /* network-visible interface */
|
||||
/*hi*/ u_int sc_flags; /* control/status bits; see if_ppp.h */
|
||||
struct callout sc_timo_ch; /* Used for scheduling timeouts */
|
||||
void *sc_devp; /* pointer to device-dep structure */
|
||||
void (*sc_start)(struct ppp_softc *); /* start output proc */
|
||||
void (*sc_ctlp)(struct ppp_softc *); /* rcvd control pkt */
|
||||
void (*sc_relinq)(struct ppp_softc *); /* relinquish ifunit */
|
||||
void (*sc_setmtu)(struct ppp_softc *); /* set mtu */
|
||||
short sc_mru; /* max receive unit */
|
||||
pid_t sc_xfer; /* used in transferring unit */
|
||||
/*hi*/ struct ifqueue sc_rawq; /* received packets */
|
||||
/*net*/ struct ifqueue sc_inq; /* queue of input packets for daemon */
|
||||
/*net*/ struct ifqueue sc_fastq; /* interactive output packet q */
|
||||
struct mbuf *sc_npqueue; /* output packets not to be sent yet */
|
||||
struct mbuf **sc_npqtail; /* ptr to last next ptr in npqueue */
|
||||
struct pppstat sc_stats; /* count of bytes/pkts sent/rcvd */
|
||||
enum NPmode sc_npmode[NUM_NP]; /* what to do with each NP */
|
||||
struct compressor *sc_xcomp; /* transmit compressor */
|
||||
void *sc_xc_state; /* transmit compressor state */
|
||||
struct compressor *sc_rcomp; /* receive decompressor */
|
||||
void *sc_rc_state; /* receive decompressor state */
|
||||
time_t sc_last_sent; /* time (secs) last NP pkt sent */
|
||||
time_t sc_last_recv; /* time (secs) last NP pkt rcvd */
|
||||
#ifdef PPP_FILTER
|
||||
struct bpf_program sc_pass_filt; /* filter for packets to pass */
|
||||
struct bpf_program sc_active_filt; /* filter for "non-idle" packets */
|
||||
#endif /* PPP_FILTER */
|
||||
#ifdef VJC
|
||||
struct slcompress *sc_comp; /* vjc control buffer */
|
||||
#endif
|
||||
|
||||
/* Device-dependent part for async lines. */
|
||||
ext_accm sc_asyncmap; /* async control character map */
|
||||
u_long sc_rasyncmap; /* receive async control char map */
|
||||
struct mbuf *sc_outm; /* mbuf chain currently being output */
|
||||
struct mbuf *sc_m; /* pointer to input mbuf chain */
|
||||
struct mbuf *sc_mc; /* pointer to current input mbuf */
|
||||
char *sc_mp; /* ptr to next char in input mbuf */
|
||||
short sc_ilen; /* length of input packet so far */
|
||||
u_short sc_fcs; /* FCS so far (input) */
|
||||
u_short sc_outfcs; /* FCS so far for output packet */
|
||||
u_char sc_rawin[16]; /* chars as received */
|
||||
int sc_rawin_count; /* # in sc_rawin */
|
||||
LIST_ENTRY(ppp_softc) sc_list;
|
||||
};
|
||||
#define PPP2IFP(sc) ((sc)->sc_ifp)
|
||||
|
||||
struct ppp_softc *pppalloc(pid_t pid);
|
||||
void pppdealloc(struct ppp_softc *sc);
|
||||
int pppioctl(struct ppp_softc *sc, u_long cmd, caddr_t data, int flag,
|
||||
struct thread *td);
|
||||
int pppoutput(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst,
|
||||
struct rtentry *rtp);
|
||||
void ppp_restart(struct ppp_softc *sc);
|
||||
void ppppktin(struct ppp_softc *sc, struct mbuf *m, int lost);
|
||||
struct mbuf *ppp_dequeue(struct ppp_softc *sc);
|
1110
sys/net/if_sl.c
1110
sys/net/if_sl.c
File diff suppressed because it is too large
Load Diff
@ -1,83 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)if_slvar.h 8.3 (Berkeley) 2/1/94
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NET_IF_SLVAR_H_
|
||||
#define _NET_IF_SLVAR_H_
|
||||
|
||||
#include <sys/callout.h>
|
||||
|
||||
/*
|
||||
* Definitions for SLIP interface data structures
|
||||
*
|
||||
* (This exists so programs like slstats can get at the definition
|
||||
* of sl_softc.)
|
||||
*/
|
||||
struct sl_softc {
|
||||
struct ifnet *sc_ifp; /* network-visible interface */
|
||||
struct ifqueue sc_fastq; /* interactive output queue */
|
||||
struct tty *sc_ttyp; /* pointer to tty structure */
|
||||
struct mbuf *sc_mbuf; /* pointer to mbuf containing buffer */
|
||||
u_char *sc_mp; /* pointer to next available buf char */
|
||||
u_char *sc_ep; /* pointer to last available buf char */
|
||||
u_char *sc_buf; /* input buffer */
|
||||
u_int sc_flags; /* see below */
|
||||
u_int sc_escape; /* =1 if last char input was FRAME_ESCAPE */
|
||||
time_t sc_lasttime; /* last time a char arrived */
|
||||
long sc_abortcount; /* number of abort escape chars */
|
||||
time_t sc_starttime; /* time of first abort in window */
|
||||
u_int sc_keepalive; /* time to decide link hang */
|
||||
u_int sc_outfill; /* time to send FRAME_END when output idle */
|
||||
/*
|
||||
* Handles for scheduling outfill and
|
||||
* keepalive timeouts.
|
||||
*/
|
||||
struct callout_handle sc_ofhandle;
|
||||
struct callout_handle sc_kahandle;
|
||||
struct slcompress sc_comp; /* tcp compression data */
|
||||
LIST_ENTRY(sl_softc) sl_next;
|
||||
u_char *bpfbuf; /* hang buffer for bpf here */
|
||||
};
|
||||
#define SL2IFP(sc) ((sc)->sc_ifp)
|
||||
|
||||
/* internal flags */
|
||||
#define SC_ERROR 0x0001 /* had an input error */
|
||||
#define SC_OUTWAIT 0x0002 /* waiting for output fill */
|
||||
#define SC_KEEPALIVE 0x0004 /* input keepalive */
|
||||
|
||||
/* visible flags */
|
||||
#define SC_COMPRESS IFF_LINK0 /* compress TCP traffic */
|
||||
#define SC_NOICMP IFF_LINK1 /* suppress ICMP traffic */
|
||||
#define SC_AUTOCOMP IFF_LINK2 /* auto-enable TCP compression */
|
||||
|
||||
|
||||
#endif
|
@ -1,153 +0,0 @@
|
||||
/*
|
||||
* ppp_comp.h - Definitions for doing PPP packet compression.
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1994 The Australian National University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, provided that the above copyright
|
||||
* notice appears in all copies. This software is provided without any
|
||||
* warranty, express or implied. The Australian National University
|
||||
* makes no representations about the suitability of this software for
|
||||
* any purpose.
|
||||
*
|
||||
* IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
|
||||
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
|
||||
* THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
* ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
|
||||
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
||||
* OR MODIFICATIONS.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NET_PPP_COMP_H
|
||||
#define _NET_PPP_COMP_H
|
||||
|
||||
/*
|
||||
* Structure giving methods for compression/decompression.
|
||||
*/
|
||||
#ifdef PACKETPTR
|
||||
struct compressor {
|
||||
int compress_proto; /* CCP compression protocol number */
|
||||
|
||||
/* Allocate space for a compressor (transmit side) */
|
||||
void *(*comp_alloc)(u_char *options, int opt_len);
|
||||
/* Free space used by a compressor */
|
||||
void (*comp_free)(void *state);
|
||||
/* Initialize a compressor */
|
||||
int (*comp_init)(void *state, u_char *options, int opt_len,
|
||||
int unit, int hdrlen, int debug);
|
||||
/* Reset a compressor */
|
||||
void (*comp_reset)(void *state);
|
||||
/* Compress a packet */
|
||||
int (*compress)(void *state, PACKETPTR *mret, PACKETPTR mp,
|
||||
int orig_len, int max_len);
|
||||
/* Return compression statistics */
|
||||
void (*comp_stat)(void *state, struct compstat *stats);
|
||||
|
||||
/* Allocate space for a decompressor (receive side) */
|
||||
void *(*decomp_alloc)(u_char *options, int opt_len);
|
||||
/* Free space used by a decompressor */
|
||||
void (*decomp_free)(void *state);
|
||||
/* Initialize a decompressor */
|
||||
int (*decomp_init)(void *state, u_char *options, int opt_len,
|
||||
int unit, int hdrlen, int mru, int debug);
|
||||
/* Reset a decompressor */
|
||||
void (*decomp_reset)(void *state);
|
||||
/* Decompress a packet. */
|
||||
int (*decompress)(void *state, PACKETPTR mp, PACKETPTR *dmpp);
|
||||
/* Update state for an incompressible packet received */
|
||||
void (*incomp)(void *state, PACKETPTR mp);
|
||||
/* Return decompression statistics */
|
||||
void (*decomp_stat)(void *state, struct compstat *stats);
|
||||
};
|
||||
#endif /* PACKETPTR */
|
||||
|
||||
/*
|
||||
* Return values for decompress routine.
|
||||
* We need to make these distinctions so that we can disable certain
|
||||
* useful functionality, namely sending a CCP reset-request as a result
|
||||
* of an error detected after decompression. This is to avoid infringing
|
||||
* a patent held by Motorola.
|
||||
* Don't you just lurve software patents.
|
||||
*/
|
||||
#define DECOMP_OK 0 /* everything went OK */
|
||||
#define DECOMP_ERROR 1 /* error detected before decomp. */
|
||||
#define DECOMP_FATALERROR 2 /* error detected after decomp. */
|
||||
|
||||
/*
|
||||
* CCP codes.
|
||||
*/
|
||||
#define CCP_CONFREQ 1
|
||||
#define CCP_CONFACK 2
|
||||
#define CCP_TERMREQ 5
|
||||
#define CCP_TERMACK 6
|
||||
#define CCP_RESETREQ 14
|
||||
#define CCP_RESETACK 15
|
||||
|
||||
/*
|
||||
* Max # bytes for a CCP option
|
||||
*/
|
||||
#define CCP_MAX_OPTION_LENGTH 32
|
||||
|
||||
/*
|
||||
* Parts of a CCP packet.
|
||||
*/
|
||||
#define CCP_CODE(dp) ((dp)[0])
|
||||
#define CCP_ID(dp) ((dp)[1])
|
||||
#define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
|
||||
#define CCP_HDRLEN 4
|
||||
|
||||
#define CCP_OPT_CODE(dp) ((dp)[0])
|
||||
#define CCP_OPT_LENGTH(dp) ((dp)[1])
|
||||
#define CCP_OPT_MINLEN 2
|
||||
|
||||
/*
|
||||
* Definitions for BSD-Compress.
|
||||
*/
|
||||
#define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
|
||||
#define CILEN_BSD_COMPRESS 3 /* length of config. option */
|
||||
|
||||
/* Macros for handling the 3rd byte of the BSD-Compress config option. */
|
||||
#define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */
|
||||
#define BSD_VERSION(x) ((x) >> 5) /* version of option format */
|
||||
#define BSD_CURRENT_VERSION 1 /* current version number */
|
||||
#define BSD_MAKE_OPT(v, n) (((v) << 5) | (n))
|
||||
|
||||
#define BSD_MIN_BITS 9 /* smallest code size supported */
|
||||
#define BSD_MAX_BITS 15 /* largest code size supported */
|
||||
|
||||
/*
|
||||
* Definitions for Deflate.
|
||||
*/
|
||||
#define CI_DEFLATE 26 /* config option for Deflate */
|
||||
#define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */
|
||||
#define CILEN_DEFLATE 4 /* length of its config option */
|
||||
|
||||
#define DEFLATE_MIN_SIZE 8
|
||||
#define DEFLATE_MAX_SIZE 15
|
||||
#define DEFLATE_METHOD_VAL 8
|
||||
#define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE)
|
||||
#define DEFLATE_METHOD(x) ((x) & 0x0F)
|
||||
#define DEFLATE_MAKE_OPT(w) ((((w) - DEFLATE_MIN_SIZE) << 4) \
|
||||
+ DEFLATE_METHOD_VAL)
|
||||
#define DEFLATE_CHK_SEQUENCE 0
|
||||
|
||||
/*
|
||||
* Definitions for other, as yet unsupported, compression methods.
|
||||
*/
|
||||
#define CI_PREDICTOR_1 1 /* config option for Predictor-1 */
|
||||
#define CILEN_PREDICTOR_1 2 /* length of its config option */
|
||||
#define CI_PREDICTOR_2 2 /* config option for Predictor-2 */
|
||||
#define CILEN_PREDICTOR_2 2 /* length of its config option */
|
||||
|
||||
#endif /* _NET_PPP_COMP_H */
|
@ -1,680 +0,0 @@
|
||||
/* $FreeBSD$ */
|
||||
|
||||
/*-
|
||||
* ppp_deflate.c - interface the zlib procedures for Deflate compression
|
||||
* and decompression (as used by gzip) to the PPP code.
|
||||
* This version is for use with mbufs on BSD-derived systems.
|
||||
*
|
||||
* Copyright (c) 1994 The Australian National University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, provided that the above copyright
|
||||
* notice appears in all copies. This software is provided without any
|
||||
* warranty, express or implied. The Australian National University
|
||||
* makes no representations about the suitability of this software for
|
||||
* any purpose.
|
||||
*
|
||||
* IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
|
||||
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
|
||||
* THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
* ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
|
||||
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
||||
* OR MODIFICATIONS.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/mutex.h>
|
||||
|
||||
#include <net/ppp_defs.h>
|
||||
#include <net/zlib.h>
|
||||
|
||||
#define PACKETPTR struct mbuf *
|
||||
#include <net/ppp_comp.h>
|
||||
|
||||
#define DEFLATE_DEBUG 1
|
||||
|
||||
/*
|
||||
* State for a Deflate (de)compressor.
|
||||
*/
|
||||
struct deflate_state {
|
||||
int seqno;
|
||||
int w_size;
|
||||
int unit;
|
||||
int hdrlen;
|
||||
int mru;
|
||||
int debug;
|
||||
z_stream strm;
|
||||
struct compstat stats;
|
||||
};
|
||||
|
||||
#define DEFLATE_OVHD 2 /* Deflate overhead/packet */
|
||||
|
||||
static void *z_alloc(void *, u_int items, u_int size);
|
||||
static void z_free(void *, void *ptr);
|
||||
static void *z_comp_alloc(u_char *options, int opt_len);
|
||||
static void *z_decomp_alloc(u_char *options, int opt_len);
|
||||
static void z_comp_free(void *state);
|
||||
static void z_decomp_free(void *state);
|
||||
static int z_comp_init(void *state, u_char *options, int opt_len,
|
||||
int unit, int hdrlen, int debug);
|
||||
static int z_decomp_init(void *state, u_char *options, int opt_len,
|
||||
int unit, int hdrlen, int mru, int debug);
|
||||
static int z_compress(void *state, struct mbuf **mret, struct mbuf *mp,
|
||||
int slen, int maxolen);
|
||||
static void z_incomp(void *state, struct mbuf *dmsg);
|
||||
static int z_decompress(void *state, struct mbuf *cmp, struct mbuf **dmpp);
|
||||
static void z_comp_reset(void *state);
|
||||
static void z_decomp_reset(void *state);
|
||||
static void z_comp_stats(void *state, struct compstat *stats);
|
||||
|
||||
/*
|
||||
* Procedures exported to if_ppp.c.
|
||||
*/
|
||||
struct compressor ppp_deflate = {
|
||||
CI_DEFLATE, /* compress_proto */
|
||||
z_comp_alloc, /* comp_alloc */
|
||||
z_comp_free, /* comp_free */
|
||||
z_comp_init, /* comp_init */
|
||||
z_comp_reset, /* comp_reset */
|
||||
z_compress, /* compress */
|
||||
z_comp_stats, /* comp_stat */
|
||||
z_decomp_alloc, /* decomp_alloc */
|
||||
z_decomp_free, /* decomp_free */
|
||||
z_decomp_init, /* decomp_init */
|
||||
z_decomp_reset, /* decomp_reset */
|
||||
z_decompress, /* decompress */
|
||||
z_incomp, /* incomp */
|
||||
z_comp_stats, /* decomp_stat */
|
||||
};
|
||||
|
||||
struct compressor ppp_deflate_draft = {
|
||||
CI_DEFLATE_DRAFT, /* compress_proto */
|
||||
z_comp_alloc, /* comp_alloc */
|
||||
z_comp_free, /* comp_free */
|
||||
z_comp_init, /* comp_init */
|
||||
z_comp_reset, /* comp_reset */
|
||||
z_compress, /* compress */
|
||||
z_comp_stats, /* comp_stat */
|
||||
z_decomp_alloc, /* decomp_alloc */
|
||||
z_decomp_free, /* decomp_free */
|
||||
z_decomp_init, /* decomp_init */
|
||||
z_decomp_reset, /* decomp_reset */
|
||||
z_decompress, /* decompress */
|
||||
z_incomp, /* incomp */
|
||||
z_comp_stats, /* decomp_stat */
|
||||
};
|
||||
|
||||
/*
|
||||
* Space allocation and freeing routines for use by zlib routines.
|
||||
*/
|
||||
static void *
|
||||
z_alloc(notused, items, size)
|
||||
void *notused;
|
||||
u_int items, size;
|
||||
{
|
||||
void *ptr;
|
||||
|
||||
ptr = malloc(items * size, M_DEVBUF, M_NOWAIT);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void
|
||||
z_free(notused, ptr)
|
||||
void *notused;
|
||||
void *ptr;
|
||||
{
|
||||
free(ptr, M_DEVBUF);
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate space for a compressor.
|
||||
*/
|
||||
static void *
|
||||
z_comp_alloc(options, opt_len)
|
||||
u_char *options;
|
||||
int opt_len;
|
||||
{
|
||||
struct deflate_state *state;
|
||||
int w_size;
|
||||
|
||||
if (opt_len != CILEN_DEFLATE
|
||||
|| (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
|
||||
|| options[1] != CILEN_DEFLATE
|
||||
|| DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
|
||||
|| options[3] != DEFLATE_CHK_SEQUENCE)
|
||||
return NULL;
|
||||
w_size = DEFLATE_SIZE(options[2]);
|
||||
if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
|
||||
return NULL;
|
||||
|
||||
state = malloc(sizeof(struct deflate_state),
|
||||
M_DEVBUF, M_NOWAIT);
|
||||
if (state == NULL)
|
||||
return NULL;
|
||||
|
||||
state->strm.next_in = NULL;
|
||||
state->strm.zalloc = z_alloc;
|
||||
state->strm.zfree = z_free;
|
||||
if (deflateInit2(&state->strm, Z_DEFAULT_COMPRESSION, DEFLATE_METHOD_VAL,
|
||||
-w_size, 8, Z_DEFAULT_STRATEGY) != Z_OK) {
|
||||
free(state, M_DEVBUF);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
state->w_size = w_size;
|
||||
bzero(&state->stats, sizeof(state->stats));
|
||||
return (void *) state;
|
||||
}
|
||||
|
||||
static void
|
||||
z_comp_free(arg)
|
||||
void *arg;
|
||||
{
|
||||
struct deflate_state *state = (struct deflate_state *) arg;
|
||||
|
||||
deflateEnd(&state->strm);
|
||||
free(state, M_DEVBUF);
|
||||
}
|
||||
|
||||
static int
|
||||
z_comp_init(arg, options, opt_len, unit, hdrlen, debug)
|
||||
void *arg;
|
||||
u_char *options;
|
||||
int opt_len, unit, hdrlen, debug;
|
||||
{
|
||||
struct deflate_state *state = (struct deflate_state *) arg;
|
||||
|
||||
if (opt_len < CILEN_DEFLATE
|
||||
|| (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
|
||||
|| options[1] != CILEN_DEFLATE
|
||||
|| DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
|
||||
|| DEFLATE_SIZE(options[2]) != state->w_size
|
||||
|| options[3] != DEFLATE_CHK_SEQUENCE)
|
||||
return 0;
|
||||
|
||||
state->seqno = 0;
|
||||
state->unit = unit;
|
||||
state->hdrlen = hdrlen;
|
||||
state->debug = debug;
|
||||
|
||||
deflateReset(&state->strm);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
z_comp_reset(arg)
|
||||
void *arg;
|
||||
{
|
||||
struct deflate_state *state = (struct deflate_state *) arg;
|
||||
|
||||
state->seqno = 0;
|
||||
deflateReset(&state->strm);
|
||||
}
|
||||
|
||||
static int
|
||||
z_compress(arg, mret, mp, orig_len, maxolen)
|
||||
void *arg;
|
||||
struct mbuf **mret; /* compressed packet (out) */
|
||||
struct mbuf *mp; /* uncompressed packet (in) */
|
||||
int orig_len, maxolen;
|
||||
{
|
||||
struct deflate_state *state = (struct deflate_state *) arg;
|
||||
u_char *rptr, *wptr;
|
||||
int proto, olen, wspace, r, flush;
|
||||
struct mbuf *m;
|
||||
|
||||
/*
|
||||
* Check that the protocol is in the range we handle.
|
||||
*/
|
||||
rptr = mtod(mp, u_char *);
|
||||
proto = PPP_PROTOCOL(rptr);
|
||||
if (proto > 0x3fff || proto == 0xfd || proto == 0xfb) {
|
||||
*mret = NULL;
|
||||
return orig_len;
|
||||
}
|
||||
|
||||
/* Allocate one mbuf initially. */
|
||||
if (maxolen > orig_len)
|
||||
maxolen = orig_len;
|
||||
MGET(m, M_DONTWAIT, MT_DATA);
|
||||
*mret = m;
|
||||
if (m != NULL) {
|
||||
m->m_len = 0;
|
||||
if (maxolen + state->hdrlen > MLEN)
|
||||
MCLGET(m, M_DONTWAIT);
|
||||
wspace = M_TRAILINGSPACE(m);
|
||||
if (state->hdrlen + PPP_HDRLEN + 2 < wspace) {
|
||||
m->m_data += state->hdrlen;
|
||||
wspace -= state->hdrlen;
|
||||
}
|
||||
wptr = mtod(m, u_char *);
|
||||
|
||||
/*
|
||||
* Copy over the PPP header and store the 2-byte sequence number.
|
||||
*/
|
||||
wptr[0] = PPP_ADDRESS(rptr);
|
||||
wptr[1] = PPP_CONTROL(rptr);
|
||||
wptr[2] = PPP_COMP >> 8;
|
||||
wptr[3] = PPP_COMP;
|
||||
wptr += PPP_HDRLEN;
|
||||
wptr[0] = state->seqno >> 8;
|
||||
wptr[1] = state->seqno;
|
||||
wptr += 2;
|
||||
state->strm.next_out = wptr;
|
||||
state->strm.avail_out = wspace - (PPP_HDRLEN + 2);
|
||||
} else {
|
||||
state->strm.next_out = NULL;
|
||||
state->strm.avail_out = 1000000;
|
||||
wptr = NULL;
|
||||
wspace = 0;
|
||||
}
|
||||
++state->seqno;
|
||||
|
||||
rptr += (proto > 0xff)? 2: 3; /* skip 1st proto byte if 0 */
|
||||
state->strm.next_in = rptr;
|
||||
state->strm.avail_in = mtod(mp, u_char *) + mp->m_len - rptr;
|
||||
mp = mp->m_next;
|
||||
flush = (mp == NULL)? Z_PACKET_FLUSH: Z_NO_FLUSH;
|
||||
olen = 0;
|
||||
for (;;) {
|
||||
r = deflate(&state->strm, flush);
|
||||
if (r != Z_OK) {
|
||||
printf("z_compress: deflate returned %d (%s)\n",
|
||||
r, (state->strm.msg? state->strm.msg: ""));
|
||||
break;
|
||||
}
|
||||
if (flush != Z_NO_FLUSH && state->strm.avail_out != 0)
|
||||
break; /* all done */
|
||||
if (state->strm.avail_in == 0 && mp != NULL) {
|
||||
state->strm.next_in = mtod(mp, u_char *);
|
||||
state->strm.avail_in = mp->m_len;
|
||||
mp = mp->m_next;
|
||||
if (mp == NULL)
|
||||
flush = Z_PACKET_FLUSH;
|
||||
}
|
||||
if (state->strm.avail_out == 0) {
|
||||
if (m != NULL) {
|
||||
m->m_len = wspace;
|
||||
olen += wspace;
|
||||
MGET(m->m_next, M_DONTWAIT, MT_DATA);
|
||||
m = m->m_next;
|
||||
if (m != NULL) {
|
||||
m->m_len = 0;
|
||||
if (maxolen - olen > MLEN)
|
||||
MCLGET(m, M_DONTWAIT);
|
||||
state->strm.next_out = mtod(m, u_char *);
|
||||
state->strm.avail_out = wspace = M_TRAILINGSPACE(m);
|
||||
}
|
||||
}
|
||||
if (m == NULL) {
|
||||
state->strm.next_out = NULL;
|
||||
state->strm.avail_out = 1000000;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m != NULL)
|
||||
olen += (m->m_len = wspace - state->strm.avail_out);
|
||||
|
||||
/*
|
||||
* See if we managed to reduce the size of the packet.
|
||||
*/
|
||||
if (m != NULL && olen < orig_len) {
|
||||
state->stats.comp_bytes += olen;
|
||||
state->stats.comp_packets++;
|
||||
} else {
|
||||
if (*mret != NULL) {
|
||||
m_freem(*mret);
|
||||
*mret = NULL;
|
||||
}
|
||||
state->stats.inc_bytes += orig_len;
|
||||
state->stats.inc_packets++;
|
||||
olen = orig_len;
|
||||
}
|
||||
state->stats.unc_bytes += orig_len;
|
||||
state->stats.unc_packets++;
|
||||
|
||||
return olen;
|
||||
}
|
||||
|
||||
static void
|
||||
z_comp_stats(arg, stats)
|
||||
void *arg;
|
||||
struct compstat *stats;
|
||||
{
|
||||
struct deflate_state *state = (struct deflate_state *) arg;
|
||||
u_int out;
|
||||
|
||||
*stats = state->stats;
|
||||
stats->ratio = stats->unc_bytes;
|
||||
out = stats->comp_bytes + stats->inc_bytes;
|
||||
if (stats->ratio <= 0x7ffffff)
|
||||
stats->ratio <<= 8;
|
||||
else
|
||||
out >>= 8;
|
||||
if (out != 0)
|
||||
stats->ratio /= out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate space for a decompressor.
|
||||
*/
|
||||
static void *
|
||||
z_decomp_alloc(options, opt_len)
|
||||
u_char *options;
|
||||
int opt_len;
|
||||
{
|
||||
struct deflate_state *state;
|
||||
int w_size;
|
||||
|
||||
if (opt_len != CILEN_DEFLATE
|
||||
|| (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
|
||||
|| options[1] != CILEN_DEFLATE
|
||||
|| DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
|
||||
|| options[3] != DEFLATE_CHK_SEQUENCE)
|
||||
return NULL;
|
||||
w_size = DEFLATE_SIZE(options[2]);
|
||||
if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
|
||||
return NULL;
|
||||
|
||||
state = malloc(sizeof(struct deflate_state),
|
||||
M_DEVBUF, M_NOWAIT);
|
||||
if (state == NULL)
|
||||
return NULL;
|
||||
|
||||
state->strm.next_out = NULL;
|
||||
state->strm.zalloc = z_alloc;
|
||||
state->strm.zfree = z_free;
|
||||
if (inflateInit2(&state->strm, -w_size) != Z_OK) {
|
||||
free(state, M_DEVBUF);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
state->w_size = w_size;
|
||||
bzero(&state->stats, sizeof(state->stats));
|
||||
return (void *) state;
|
||||
}
|
||||
|
||||
static void
|
||||
z_decomp_free(arg)
|
||||
void *arg;
|
||||
{
|
||||
struct deflate_state *state = (struct deflate_state *) arg;
|
||||
|
||||
inflateEnd(&state->strm);
|
||||
free(state, M_DEVBUF);
|
||||
}
|
||||
|
||||
static int
|
||||
z_decomp_init(arg, options, opt_len, unit, hdrlen, mru, debug)
|
||||
void *arg;
|
||||
u_char *options;
|
||||
int opt_len, unit, hdrlen, mru, debug;
|
||||
{
|
||||
struct deflate_state *state = (struct deflate_state *) arg;
|
||||
|
||||
if (opt_len < CILEN_DEFLATE
|
||||
|| (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
|
||||
|| options[1] != CILEN_DEFLATE
|
||||
|| DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
|
||||
|| DEFLATE_SIZE(options[2]) != state->w_size
|
||||
|| options[3] != DEFLATE_CHK_SEQUENCE)
|
||||
return 0;
|
||||
|
||||
state->seqno = 0;
|
||||
state->unit = unit;
|
||||
state->hdrlen = hdrlen;
|
||||
state->debug = debug;
|
||||
state->mru = mru;
|
||||
|
||||
inflateReset(&state->strm);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
z_decomp_reset(arg)
|
||||
void *arg;
|
||||
{
|
||||
struct deflate_state *state = (struct deflate_state *) arg;
|
||||
|
||||
state->seqno = 0;
|
||||
inflateReset(&state->strm);
|
||||
}
|
||||
|
||||
/*
|
||||
* Decompress a Deflate-compressed packet.
|
||||
*
|
||||
* Because of patent problems, we return DECOMP_ERROR for errors
|
||||
* found by inspecting the input data and for system problems, but
|
||||
* DECOMP_FATALERROR for any errors which could possibly be said to
|
||||
* be being detected "after" decompression. For DECOMP_ERROR,
|
||||
* we can issue a CCP reset-request; for DECOMP_FATALERROR, we may be
|
||||
* infringing a patent of Motorola's if we do, so we take CCP down
|
||||
* instead.
|
||||
*
|
||||
* Given that the frame has the correct sequence number and a good FCS,
|
||||
* errors such as invalid codes in the input most likely indicate a
|
||||
* bug, so we return DECOMP_FATALERROR for them in order to turn off
|
||||
* compression, even though they are detected by inspecting the input.
|
||||
*/
|
||||
static int
|
||||
z_decompress(arg, mi, mop)
|
||||
void *arg;
|
||||
struct mbuf *mi, **mop;
|
||||
{
|
||||
struct deflate_state *state = (struct deflate_state *) arg;
|
||||
struct mbuf *mo, *mo_head;
|
||||
u_char *rptr, *wptr;
|
||||
int rlen, olen, ospace;
|
||||
int seq, i, flush, r, decode_proto;
|
||||
u_char hdr[PPP_HDRLEN + DEFLATE_OVHD];
|
||||
|
||||
*mop = NULL;
|
||||
rptr = mtod(mi, u_char *);
|
||||
rlen = mi->m_len;
|
||||
for (i = 0; i < PPP_HDRLEN + DEFLATE_OVHD; ++i) {
|
||||
while (rlen <= 0) {
|
||||
mi = mi->m_next;
|
||||
if (mi == NULL)
|
||||
return DECOMP_ERROR;
|
||||
rptr = mtod(mi, u_char *);
|
||||
rlen = mi->m_len;
|
||||
}
|
||||
hdr[i] = *rptr++;
|
||||
--rlen;
|
||||
}
|
||||
|
||||
/* Check the sequence number. */
|
||||
seq = (hdr[PPP_HDRLEN] << 8) + hdr[PPP_HDRLEN+1];
|
||||
if (seq != state->seqno) {
|
||||
if (state->debug)
|
||||
printf("z_decompress%d: bad seq # %d, expected %d\n",
|
||||
state->unit, seq, state->seqno);
|
||||
return DECOMP_ERROR;
|
||||
}
|
||||
++state->seqno;
|
||||
|
||||
/* Allocate an output mbuf. */
|
||||
MGETHDR(mo, M_DONTWAIT, MT_DATA);
|
||||
if (mo == NULL)
|
||||
return DECOMP_ERROR;
|
||||
mo_head = mo;
|
||||
mo->m_len = 0;
|
||||
mo->m_next = NULL;
|
||||
MCLGET(mo, M_DONTWAIT);
|
||||
ospace = M_TRAILINGSPACE(mo);
|
||||
if (state->hdrlen + PPP_HDRLEN < ospace) {
|
||||
mo->m_data += state->hdrlen;
|
||||
ospace -= state->hdrlen;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fill in the first part of the PPP header. The protocol field
|
||||
* comes from the decompressed data.
|
||||
*/
|
||||
wptr = mtod(mo, u_char *);
|
||||
wptr[0] = PPP_ADDRESS(hdr);
|
||||
wptr[1] = PPP_CONTROL(hdr);
|
||||
wptr[2] = 0;
|
||||
|
||||
/*
|
||||
* Set up to call inflate. We set avail_out to 1 initially so we can
|
||||
* look at the first byte of the output and decide whether we have
|
||||
* a 1-byte or 2-byte protocol field.
|
||||
*/
|
||||
state->strm.next_in = rptr;
|
||||
state->strm.avail_in = rlen;
|
||||
mi = mi->m_next;
|
||||
flush = (mi == NULL)? Z_PACKET_FLUSH: Z_NO_FLUSH;
|
||||
rlen += PPP_HDRLEN + DEFLATE_OVHD;
|
||||
state->strm.next_out = wptr + 3;
|
||||
state->strm.avail_out = 1;
|
||||
decode_proto = 1;
|
||||
olen = PPP_HDRLEN;
|
||||
|
||||
/*
|
||||
* Call inflate, supplying more input or output as needed.
|
||||
*/
|
||||
for (;;) {
|
||||
r = inflate(&state->strm, flush);
|
||||
if (r != Z_OK) {
|
||||
#if !DEFLATE_DEBUG
|
||||
if (state->debug)
|
||||
#endif
|
||||
printf("z_decompress%d: inflate returned %d (%s)\n",
|
||||
state->unit, r, (state->strm.msg? state->strm.msg: ""));
|
||||
m_freem(mo_head);
|
||||
return DECOMP_FATALERROR;
|
||||
}
|
||||
if (flush != Z_NO_FLUSH && state->strm.avail_out != 0)
|
||||
break; /* all done */
|
||||
if (state->strm.avail_in == 0 && mi != NULL) {
|
||||
state->strm.next_in = mtod(mi, u_char *);
|
||||
state->strm.avail_in = mi->m_len;
|
||||
rlen += mi->m_len;
|
||||
mi = mi->m_next;
|
||||
if (mi == NULL)
|
||||
flush = Z_PACKET_FLUSH;
|
||||
}
|
||||
if (state->strm.avail_out == 0) {
|
||||
if (decode_proto) {
|
||||
state->strm.avail_out = ospace - PPP_HDRLEN;
|
||||
if ((wptr[3] & 1) == 0) {
|
||||
/* 2-byte protocol field */
|
||||
wptr[2] = wptr[3];
|
||||
--state->strm.next_out;
|
||||
++state->strm.avail_out;
|
||||
--olen;
|
||||
}
|
||||
decode_proto = 0;
|
||||
} else {
|
||||
mo->m_len = ospace;
|
||||
olen += ospace;
|
||||
MGET(mo->m_next, M_DONTWAIT, MT_DATA);
|
||||
mo = mo->m_next;
|
||||
if (mo == NULL) {
|
||||
m_freem(mo_head);
|
||||
return DECOMP_ERROR;
|
||||
}
|
||||
MCLGET(mo, M_DONTWAIT);
|
||||
state->strm.next_out = mtod(mo, u_char *);
|
||||
state->strm.avail_out = ospace = M_TRAILINGSPACE(mo);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (decode_proto) {
|
||||
m_freem(mo_head);
|
||||
return DECOMP_ERROR;
|
||||
}
|
||||
olen += (mo->m_len = ospace - state->strm.avail_out);
|
||||
#if DEFLATE_DEBUG
|
||||
if (state->debug && olen > state->mru + PPP_HDRLEN)
|
||||
printf("ppp_deflate%d: exceeded mru (%d > %d)\n",
|
||||
state->unit, olen, state->mru + PPP_HDRLEN);
|
||||
#endif
|
||||
|
||||
state->stats.unc_bytes += olen;
|
||||
state->stats.unc_packets++;
|
||||
state->stats.comp_bytes += rlen;
|
||||
state->stats.comp_packets++;
|
||||
|
||||
*mop = mo_head;
|
||||
return DECOMP_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Incompressible data has arrived - add it to the history.
|
||||
*/
|
||||
static void
|
||||
z_incomp(arg, mi)
|
||||
void *arg;
|
||||
struct mbuf *mi;
|
||||
{
|
||||
struct deflate_state *state = (struct deflate_state *) arg;
|
||||
u_char *rptr;
|
||||
int rlen, proto, r;
|
||||
|
||||
/*
|
||||
* Check that the protocol is one we handle.
|
||||
*/
|
||||
rptr = mtod(mi, u_char *);
|
||||
proto = PPP_PROTOCOL(rptr);
|
||||
if (proto > 0x3fff || proto == 0xfd || proto == 0xfb)
|
||||
return;
|
||||
|
||||
++state->seqno;
|
||||
|
||||
/*
|
||||
* Iterate through the mbufs, adding the characters in them
|
||||
* to the decompressor's history. For the first mbuf, we start
|
||||
* at the either the 1st or 2nd byte of the protocol field,
|
||||
* depending on whether the protocol value is compressible.
|
||||
*/
|
||||
rlen = mi->m_len;
|
||||
state->strm.next_in = rptr + 3;
|
||||
state->strm.avail_in = rlen - 3;
|
||||
if (proto > 0xff) {
|
||||
--state->strm.next_in;
|
||||
++state->strm.avail_in;
|
||||
}
|
||||
for (;;) {
|
||||
r = inflateIncomp(&state->strm);
|
||||
if (r != Z_OK) {
|
||||
/* gak! */
|
||||
#if !DEFLATE_DEBUG
|
||||
if (state->debug)
|
||||
#endif
|
||||
printf("z_incomp%d: inflateIncomp returned %d (%s)\n",
|
||||
state->unit, r, (state->strm.msg? state->strm.msg: ""));
|
||||
return;
|
||||
}
|
||||
mi = mi->m_next;
|
||||
if (mi == NULL)
|
||||
break;
|
||||
state->strm.next_in = mtod(mi, u_char *);
|
||||
state->strm.avail_in = mi->m_len;
|
||||
rlen += mi->m_len;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update stats.
|
||||
*/
|
||||
state->stats.inc_bytes += rlen;
|
||||
state->stats.inc_packets++;
|
||||
state->stats.unc_bytes += rlen;
|
||||
state->stats.unc_packets++;
|
||||
}
|
||||
MODULE_DEPEND(ppp_deflate, zlib, 1, 1, 1);
|
1076
sys/net/ppp_tty.c
1076
sys/net/ppp_tty.c
File diff suppressed because it is too large
Load Diff
@ -1,58 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)slip.h 8.1 (Berkeley) 2/12/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NET_SLIP_H_
|
||||
#define _NET_SLIP_H_
|
||||
|
||||
/* Ioctls operating on SLIP ttys. */
|
||||
#define SLIOCGUNIT _IOR('t', 88, int) /* get slip unit number */
|
||||
#define SLIOCSKEEPAL _IOW('t', 84, int) /* set keepalive */
|
||||
#define SLIOCSOUTFILL _IOW('t', 83, int) /* set out fill time */
|
||||
#define SLIOCGKEEPAL _IOR('t', 82, int) /* get keepalive time */
|
||||
#define SLIOCGOUTFILL _IOR('t', 81, int) /* get out fill time */
|
||||
#define SLIOCSUNIT _IOW('t', 80, int) /* set slip unit number */
|
||||
|
||||
/*
|
||||
* Definitions of the pseudo-link-level header attached to slip
|
||||
* packets grabbed by the packet filter (bpf) traffic monitor.
|
||||
*/
|
||||
#define SLIP_HDRLEN 16 /* BPF SLIP header length */
|
||||
|
||||
/* Offsets into BPF SLIP header. */
|
||||
#define SLX_DIR 0 /* direction; see below */
|
||||
#define SLX_CHDR 1 /* compressed header data */
|
||||
#define CHDR_LEN 15 /* length of compressed header data */
|
||||
|
||||
#define SLIPDIR_IN 0 /* incoming */
|
||||
#define SLIPDIR_OUT 1 /* outgoing */
|
||||
|
||||
#endif /* !_NET_SLIP_H */
|
@ -1,4 +0,0 @@
|
||||
.\" $FreeBSD$
|
||||
Set to not build
|
||||
.Xr sliplogin 8
|
||||
and related programs.
|
@ -129,8 +129,6 @@ SUBDIR= ${_ac} \
|
||||
powerd \
|
||||
${_ppp} \
|
||||
${_pppctl} \
|
||||
${_pppd} \
|
||||
${_pppstats} \
|
||||
${_praliases} \
|
||||
${_praudit} \
|
||||
procctl \
|
||||
@ -166,7 +164,6 @@ SUBDIR= ${_ac} \
|
||||
setfmac \
|
||||
setpmac \
|
||||
${_sicontrol} \
|
||||
${_sliplogin} \
|
||||
${_slstat} \
|
||||
smbmsg \
|
||||
snapinfo \
|
||||
@ -363,8 +360,6 @@ _portsnap= portsnap
|
||||
.if ${MK_PPP} != "no"
|
||||
_ppp= ppp
|
||||
#_pppctl handled below
|
||||
_pppd= pppd
|
||||
_pppstats= pppstats
|
||||
.endif
|
||||
|
||||
.if ${MK_QUOTAS} != "no"
|
||||
@ -385,11 +380,6 @@ _praliases= praliases
|
||||
_sendmail= sendmail
|
||||
.endif
|
||||
|
||||
.if ${MK_SLIP} != "no"
|
||||
_sliplogin= sliplogin
|
||||
_slstat= slstat
|
||||
.endif
|
||||
|
||||
.if ${MK_SYSINSTALL} != "no"
|
||||
.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386" || \
|
||||
${MACHINE_ARCH} == "sparc64"
|
||||
|
@ -1,56 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
# I once used this extensively, but no longer have a modem. Feel free
|
||||
# to ask me questions about it, but I disclaim ownership now. -Peter
|
||||
|
||||
PROG= pppd
|
||||
MAN= pppd.8
|
||||
SRCS= main.c magic.c fsm.c lcp.c ipcp.c ipxcp.c upap.c chap.c ccp.c \
|
||||
demand.c auth.c options.c sys-bsd.c
|
||||
BINMODE=4550
|
||||
BINOWN= root
|
||||
BINGRP= dialer
|
||||
|
||||
CFLAGS+= -DHAVE_PATHS_H
|
||||
|
||||
DPADD= ${LIBCRYPT} ${LIBUTIL} ${LIBMD}
|
||||
LDADD= -lcrypt -lutil -lmd
|
||||
|
||||
# Support SPX/IPX - not quite ready
|
||||
#CFLAGS+= -DIPX_CHANGE
|
||||
#SRCS+= ipxcp.c
|
||||
|
||||
# Callback Control Protocol
|
||||
CFLAGS+= -DCBCP_SUPPORT
|
||||
SRCS+= cbcp.c
|
||||
|
||||
# Filter support
|
||||
CFLAGS+= -DPPP_FILTER
|
||||
DPADD+= ${LIBPCAP}
|
||||
LDADD+= -lpcap
|
||||
|
||||
# MS-CHAP support. Requires the DES library.
|
||||
.if ${MK_OPENSSL} != "no" && !defined(RELEASE_CRUNCH)
|
||||
CFLAGS+= -DCHAPMS
|
||||
SRCS+= chap_ms.c
|
||||
LDADD+= -lcrypto
|
||||
DPADD+= ${LIBCRYPTO}
|
||||
.endif
|
||||
|
||||
.if ${MK_INET6_SUPPORT} != "no"
|
||||
CFLAGS+=-DINET6
|
||||
SRCS+= eui64.c ipv6cp.c
|
||||
.endif
|
||||
|
||||
.if defined(RELEASE_CRUNCH)
|
||||
# We must create these objects because crunchgen will link them,
|
||||
# and we don't want any unused symbols to spoil the final link.
|
||||
SRCS+= chap_ms.c
|
||||
chap_ms.o:
|
||||
>null_${.PREFIX}.c
|
||||
cc -c -o ${.TARGET} null_${.PREFIX}.c
|
||||
.endif
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,726 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
This is the README file for ppp-2.3, a package which implements the
|
||||
Point-to-Point Protocol (PPP) to provide Internet connections over
|
||||
serial lines.
|
||||
|
||||
|
||||
Introduction.
|
||||
*************
|
||||
|
||||
The Point-to-Point Protocol (PPP) provides a standard way to establish
|
||||
a network connection over a serial link. At present, this package
|
||||
supports IP and the protocols layered above IP, such as TCP and UDP.
|
||||
The Linux port of this package also has support for IPX.
|
||||
|
||||
This software consists of two parts:
|
||||
|
||||
- Kernel code, which establishes a network interface and passes
|
||||
packets between the serial port, the kernel networking code and the
|
||||
PPP daemon (pppd). This code is implemented using STREAMS modules on
|
||||
SunOS 4.x, Solaris 2.x, System V Release 4, and OSF/1, and as a
|
||||
line discipline under Ultrix, NextStep, NetBSD, FreeBSD, and Linux.
|
||||
|
||||
- The PPP daemon (pppd), which negotiates with the peer to establish
|
||||
the link and sets up the ppp network interface. Pppd includes support
|
||||
for authentication, so you can control which other systems may make a
|
||||
PPP connection and what IP addresses they may use.
|
||||
|
||||
|
||||
Installation.
|
||||
*************
|
||||
|
||||
The file SETUP contains general information about setting up your
|
||||
system for using PPP. There is also a README file for each supported
|
||||
system, which contains more specific details for installing PPP on
|
||||
that system. The supported systems, and the corresponding README
|
||||
files, are:
|
||||
|
||||
Digital Unix (OSF/1) README.osf
|
||||
Linux README.linux
|
||||
NetBSD, FreeBSD README.bsd
|
||||
NeXTStep README.next
|
||||
Solaris 2 README.sol2
|
||||
SunOS 4.x README.sunos4
|
||||
System V Release 4 README.svr4
|
||||
Ultrix 4.x README.ultrix
|
||||
|
||||
Unfortunately, AIX 4 is no longer supported, since I don't have a
|
||||
maintainer for the AIX 4 port. If you want to volunteer, contact me.
|
||||
The Ultrix port is untested, as I no longer have access to an Ultrix
|
||||
box.
|
||||
|
||||
In each case you start by running the ./configure script. This works
|
||||
out which operating system you are using and creates symbolic links to
|
||||
the appropriate makefiles. You then run `make' to compile the
|
||||
user-level code, and (as root) `make install' to install the
|
||||
user-level programs pppd, chat and pppstats.
|
||||
|
||||
The procedures for installing the kernel code vary from system to
|
||||
system. On some systems, the kernel code can be loaded into a running
|
||||
kernel using a `modload' facility. On others, the kernel image has to
|
||||
be recompiled and the system rebooted. See the README.* files for
|
||||
details.
|
||||
|
||||
N.B. Since 2.3.0, leaving the permitted IP addresses column of the
|
||||
pap-secrets or chap-secrets file empty means that no addresses are
|
||||
permitted. You need to put a "*" in that column to allow the peer to
|
||||
use any IP address. (This only applies where the peer is
|
||||
authenticating itself to you, of course.)
|
||||
|
||||
|
||||
What's new in ppp-2.3.5.
|
||||
************************
|
||||
|
||||
* Minor corrections to the Digital UNIX and NetBSD ports.
|
||||
|
||||
* A workaround to avoid tickling a bug in the `se' serial port driver
|
||||
on Sun PCI Ultra machines running Solaris.
|
||||
|
||||
* Fixed a bug in the negotiation of the Microsoft WINS server address
|
||||
option.
|
||||
|
||||
* Fixed a bug in the Linux port where it would fail for kernel
|
||||
versions above 2.1.99.
|
||||
|
||||
|
||||
What was new in ppp-2.3.4.
|
||||
**************************
|
||||
|
||||
* The NeXT port has been updated, thanks to Steve Perkins.
|
||||
|
||||
* ppp-2.3.4 compiles and works under Solaris 2.6, using either gcc or
|
||||
cc.
|
||||
|
||||
* With the Solaris, SVR4 and SunOS ports, you can control the choice
|
||||
of C compiler, C compiler options, and installation directories by
|
||||
editing the svr4/Makedefs or sunos4/Makedefs file.
|
||||
|
||||
* Until now, we have been using the number 24 to identify Deflate
|
||||
compression in the CCP negotiations, which was the number in the draft
|
||||
RFC describing Deflate. The number actually assigned to Deflate is
|
||||
26. The code has been changed to use 26, but to allow the use of 24
|
||||
for now for backwards compatibility. (This can be disabled with the
|
||||
`nodeflatedraft' option to pppd.)
|
||||
|
||||
* Fixed some bugs in the linux driver and deflate compressor which
|
||||
were causing compression problems, including corrupting long
|
||||
incompressible packets sometimes.
|
||||
|
||||
* Fixes to the PAM and shadow password support in pppd, from Al
|
||||
Longyear and others.
|
||||
|
||||
* Pppd now sets some environment variables for scripts it invokes
|
||||
(ip-up/down, auth-ip/down), giving information about the connection.
|
||||
The variables it sets are PEERNAME, IPLOCAL, IPREMOTE, UID, DEVICE,
|
||||
SPEED, and IFNAME.
|
||||
|
||||
* Pppd now has an `updetach' option, which will cause it to detach
|
||||
from its controlling terminal once the link has come up (i.e. once it
|
||||
is available for IP traffic).
|
||||
|
||||
|
||||
What was new in ppp-2.3.3.
|
||||
**************************
|
||||
|
||||
* Fixed compilation problems under SunOS.
|
||||
|
||||
* Fixed a bug introduced into chat in 2.3.2, and compilation problems
|
||||
introduced into the MS-CHAP implementation in 2.3.2.
|
||||
|
||||
* The linux kernel driver has been updated for recent 2.1-series
|
||||
kernel changes, and it now will ask kerneld to load compression
|
||||
modules when required, if the kernel is configured to support kerneld.
|
||||
|
||||
* Pppd should now compile correctly under linux on systems with glibc.
|
||||
|
||||
|
||||
What was new in ppp-2.3.2.
|
||||
**************************
|
||||
|
||||
* In 2.3.1, I made a change which was intended to make pppd able to
|
||||
detect loss of CD during or immediately after the connection script
|
||||
runs. Unfortunately, this had the side-effect that the connection
|
||||
script wouldn't work at all on some systems. This change has been
|
||||
reversed.
|
||||
|
||||
* Fix compilation problems in the Linux kernel driver.
|
||||
|
||||
|
||||
What was new in ppp-2.3.1.
|
||||
**************************
|
||||
|
||||
* Enhancements to chat, thanks to Francis Demierre. Chat can now
|
||||
accept comments in the chat script file, and has new SAY, HANGUP,
|
||||
CLR_ABORT and CLR_REPORT keywords.
|
||||
|
||||
* Fixed a bug which causes 2.3.0 to crash Solaris systems.
|
||||
|
||||
* Bug-fixes and restructuring of the Linux kernel driver.
|
||||
|
||||
* The holdoff behaviour of pppd has been changed slightly: now, if
|
||||
the link comes up for IP (or other network protocol) traffic, we
|
||||
consider that the link has been successfully established, and don't
|
||||
enforce the holdoff period after the link goes down.
|
||||
|
||||
* Pppd should now correctly wait for CD (carrier detect) from the
|
||||
modem, even when the serial port initially had CLOCAL set, and it
|
||||
should also detect loss of CD during or immediately after the
|
||||
connection script runs.
|
||||
|
||||
* Under linux, pppd will work with older 2.2.0* version kernel
|
||||
drivers, although demand-dialling is not supported with them.
|
||||
|
||||
* Minor bugfixes for pppd.
|
||||
|
||||
|
||||
What was new in ppp-2.3.
|
||||
************************
|
||||
|
||||
* Demand-dialling. Pppd now has a mode where it will establish the
|
||||
network interface immediately when it starts, but not actually bring
|
||||
the link up until it sees some data to be sent. Look for the demand
|
||||
option description in the pppd man page. Demand-dialling is not
|
||||
supported under Ultrix or NeXTStep.
|
||||
|
||||
* Idle timeout. Pppd will optionally terminate the link if no data
|
||||
packets are sent or received within a certain time interval.
|
||||
|
||||
* Pppd now runs the /etc/ppp/auth-up script, if it exists, when the
|
||||
peer successfully authenticates itself, and /etc/ppp/auth-down when
|
||||
the connection is subsequently terminated. This can be useful for
|
||||
accounting purposes.
|
||||
|
||||
* A new packet compression scheme, Deflate, has been implemented.
|
||||
This uses the same compression method as `gzip'. This method is free
|
||||
of patent or copyright restrictions, and it achieves better
|
||||
compression than BSD-Compress. It does consume more CPU cycles for
|
||||
compression than BSD-Compress, but this shouldn't be a problem for
|
||||
links running at 100kbit/s or less.
|
||||
|
||||
* There is no code in this distribution which is covered by Brad
|
||||
Clements' restrictive copyright notice. The STREAMS modules for SunOS
|
||||
and OSF/1 have been rewritten, based on the Solaris 2 modules, which
|
||||
were written from scratch without any Clements code.
|
||||
|
||||
* Pppstats has been reworked to clean up the output format somewhat.
|
||||
It also has a new -d option which displays data rate in kbyte/s for
|
||||
those columns which would normally display bytes.
|
||||
|
||||
* Pppd options beginning with - or + have been renamed, e.g. -ip
|
||||
became noip, +chap became require-chap, etc. The old options are
|
||||
still accepted for compatibility but may be removed in future.
|
||||
|
||||
* Pppd now has some options (such as the new `noauth' option) which
|
||||
can only be specified if it is being run by root, or in an
|
||||
"privileged" options file: /etc/ppp/options or an options file in the
|
||||
/etc/ppp/peers directory. There is a new "call" option to read
|
||||
options from a file in /etc/ppp/peers, making it possible for non-root
|
||||
users to make unauthenticated connections, but only to certain trusted
|
||||
peers. My intention is to make the `auth' option the default in a
|
||||
future release.
|
||||
|
||||
* Several minor new features have been added to pppd, including the
|
||||
maxconnect and welcome options. Pppd will now terminate the
|
||||
connection when there are no network control protocols running. The
|
||||
allowed IP address(es) field in the secrets files can now specify
|
||||
subnets (with a notation like 123.45.67.89/24) and addresses which are
|
||||
not acceptable (put a ! on the front).
|
||||
|
||||
* Numerous bugs have been fixed (no doubt some have been introduced :-)
|
||||
Thanks to those who reported bugs in ppp-2.2.
|
||||
|
||||
|
||||
Patents.
|
||||
********
|
||||
|
||||
The BSD-Compress algorithm used for packet compression is the same as
|
||||
that used in the Unix "compress" command. It is apparently covered by
|
||||
U.S. patents 4,814,746 (owned by IBM) and 4,558,302 (owned by Unisys),
|
||||
and corresponding patents in various other countries (but not
|
||||
Australia). If this is of concern, you can build the package without
|
||||
including BSD-Compress. To do this, edit net/ppp-comp.h to change the
|
||||
definition of DO_BSD_COMPRESS to 0. The bsd-comp.c files are then no
|
||||
longer needed, so the references to bsd-comp.o may optionally be
|
||||
removed from the Makefiles.
|
||||
|
||||
|
||||
Contacts.
|
||||
*********
|
||||
|
||||
The comp.protocols.ppp newsgroup is a useful place to get help if you
|
||||
have trouble getting your ppp connections to work. Please do not send
|
||||
me questions of the form "please help me get connected to my ISP" -
|
||||
I'm sorry, but I simply do not have the time to answer all the
|
||||
questions like this that I get.
|
||||
|
||||
If you find bugs in this package, please report them to the maintainer
|
||||
for the port for the operating system you are using:
|
||||
|
||||
Digital Unix (OSF/1) Farrell Woods <ftw@zk3.dec.com>
|
||||
Linux Al Longyear <longyear@pobox.com>
|
||||
NetBSD Matthew Green <mrg@eterna.com.au
|
||||
FreeBSD Peter Wemm <peter@haywire.DIALix.COM>
|
||||
NeXTStep Steve Perkins <perkins@cps.msu.edu>
|
||||
Solaris 2 Paul Mackerras <Paul.Mackerras@cs.anu.edu.au>
|
||||
SunOS 4.x Paul Mackerras <Paul.Mackerras@cs.anu.edu.au>
|
||||
System V Release 4 Matthias Apitz <Matthias.Apitz@SOFTCON.de>
|
||||
Ultrix 4.x Paul Mackerras (for want of anybody better :-)
|
||||
|
||||
|
||||
Copyrights:
|
||||
***********
|
||||
|
||||
All of the code can be freely used and redistributed.
|
||||
|
||||
|
||||
Distribution:
|
||||
*************
|
||||
|
||||
The primary site for releases of this software is:
|
||||
|
||||
ftp://cs.anu.edu.au/pub/software/ppp/
|
||||
|
||||
-------------------------
|
||||
This is the README file for ppp-2.2, a package which implements the
|
||||
Point-to-Point Protocol (PPP) to provide Internet connections over
|
||||
serial lines.
|
||||
|
||||
|
||||
Introduction.
|
||||
*************
|
||||
|
||||
The Point-to-Point Protocol (PPP) provides a standard way to transmit
|
||||
datagrams over a serial link, as well as a standard way for the
|
||||
machines at either end of the link (the `peers') to negotiate various
|
||||
optional characteristics of the link. Using PPP, a serial link can be
|
||||
used to transmit Internet Protocol (IP) datagrams, allowing TCP/IP
|
||||
connections between the peers. PPP is defined in several RFC (Request
|
||||
For Comments) documents, in particular RFCs 1661, 1662, 1332 and 1334.
|
||||
Other RFCs describe standard ways to transmit datagrams from other
|
||||
network protocols (e.g., DECnet, OSI, Appletalk), but this package
|
||||
only supports IP.
|
||||
|
||||
This software consists of two parts:
|
||||
|
||||
- Kernel code, which establishes a network interface and passes
|
||||
packets between the serial port, the kernel networking code and the
|
||||
PPP daemon (pppd). This code is implemented using STREAMS modules on
|
||||
SunOS 4.x, AIX 4.1 and OSF/1, and as a line discipline under Ultrix,
|
||||
NextStep, NetBSD, FreeBSD, and Linux.
|
||||
|
||||
- The PPP daemon (pppd), which negotiates with the peer to establish
|
||||
the link and sets up the ppp network interface. Pppd includes support
|
||||
for authentication, so you can control which other systems may make a
|
||||
PPP connection and what IP addresses they may use.
|
||||
|
||||
|
||||
What is new in ppp-2.2.
|
||||
***********************
|
||||
|
||||
* More systems are now supported:
|
||||
|
||||
AIX 4, thanks to Charlie Wick,
|
||||
OSF/1 on DEC Alpha, thanks to Steve Tate (srt@zaphod.csci.unt.edu),
|
||||
NextStep 3.2 and 3.3, thanks to Philip-Andrew Prindeville
|
||||
(philipp@res.enst.fr) and Steve Perkins (perkins@cps.msu.edu),
|
||||
Solaris 2,
|
||||
|
||||
in addition to NetBSD 1.0, SunOS 4.x, Ultrix 4.x, FreeBSD 2.0, and
|
||||
Linux.
|
||||
|
||||
* Packet compression has been implemented. This version implements
|
||||
CCP (Compression Control Protocol) and the BSD-Compress compression
|
||||
scheme according to the current draft RFCs. This means that incoming
|
||||
and outgoing packets can be compressed with the LZW scheme (same as
|
||||
the `compress' command) using a code size of up to 15 bits.
|
||||
|
||||
* Some bug fixes to the LCP protocol code. In particular, pppd now
|
||||
correctly replies with a Configure-NAK (instead of a Configure-Reject)
|
||||
if the peer asks for CHAP and pppd is willing to do PAP but not CHAP.
|
||||
|
||||
* The ip-up and ip-down scripts are now run with the real user ID set
|
||||
to root, and with an empty environment. Clearing the environment
|
||||
fixes a security hole.
|
||||
|
||||
* The kernel code on NetBSD, FreeBSD, NextStep and Ultrix has been
|
||||
restructured to make it easier to implement PPP over devices other
|
||||
than asynchronous tty ports (for example, synchronous serial ports).
|
||||
|
||||
* pppd now looks at the list of interfaces in the system to determine
|
||||
what the netmask should be. In most cases, this should eliminate the
|
||||
need to use the `netmask' option.
|
||||
|
||||
* There is a new `papcrypt' option to pppd, which specifies that
|
||||
secrets in /etc/ppp/pap-secrets used for authenticating the peer are
|
||||
encrypted, so pppd always encrypts the peer's password before
|
||||
comparing it with the secret from /etc/ppp/pap-secrets. This gives
|
||||
better security.
|
||||
|
||||
|
||||
Patents.
|
||||
********
|
||||
|
||||
The BSD-Compress algorithm used for packet compression is the same as
|
||||
that used in the Unix "compress" command. It is apparently covered by
|
||||
U.S. patents 4,814,746 (owned by IBM) and 4,558,302 (owned by Unisys),
|
||||
and corresponding patents in various other countries (but not
|
||||
Australia). If this is of concern, you can build the package without
|
||||
including BSD-Compress. To do this, edit net/ppp-comp.h to change the
|
||||
definition of DO_BSD_COMPRESS to 0. The bsd-comp.c files are then no
|
||||
longer needed, so the references to bsd-comp.o may optionally be
|
||||
removed from the Makefiles.
|
||||
|
||||
|
||||
Contacts.
|
||||
*********
|
||||
|
||||
Bugs in the the SunOS, NetBSD and Ultrix ports and bugs in pppd, chat
|
||||
or pppstats should be reported to:
|
||||
|
||||
paulus@cs.anu.edu.au
|
||||
Paul Mackerras
|
||||
Dept. of Computer Science
|
||||
Australian National University
|
||||
Canberra ACT 0200
|
||||
AUSTRALIA
|
||||
|
||||
Bugs in other ports should be reported to the maintainer for that port
|
||||
(see the appropriate README.* file) or to the above. Unfortunately,
|
||||
Charlie Wick is not in a position to provide support for the AIX 4
|
||||
port, so if you find bugs in it, send them to me.
|
||||
|
||||
Thanks to:
|
||||
|
||||
Brad Parker (brad@fcr.com)
|
||||
Greg Christy (gmc@quotron.com)
|
||||
Drew D. Perkins (ddp@andrew.cmu.edu)
|
||||
Rick Adams (rick@seismo.ARPA)
|
||||
Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris).
|
||||
|
||||
|
||||
Copyrights:
|
||||
|
||||
Most of the code can be freely used and redistributed. The STREAMS
|
||||
code for SunOS 4.x, OSF/1 and AIX 4 is under a more restrictive
|
||||
copyright:
|
||||
|
||||
This code is Copyright (C) 1989, 1990 By Brad K. Clements,
|
||||
All Rights Reserved.
|
||||
|
||||
You may use this code for your personal use, to provide a non-profit
|
||||
service to others, or to use as a test platform for a commercial
|
||||
implementation.
|
||||
|
||||
You may NOT use this code in a commercial product, nor to provide a
|
||||
commercial service, nor may you sell this code without express
|
||||
written permission of the author.
|
||||
|
||||
Otherwise, Enjoy!
|
||||
|
||||
This copyright applies to (parts of) the following files:
|
||||
|
||||
sunos/ppp_async.c
|
||||
sunos/ppp_if.c
|
||||
aix4/ppp_async.c
|
||||
aix4/ppp_if.c
|
||||
net/ppp_str.h
|
||||
pppd/sys-str.c
|
||||
pppd/sys-osf.c
|
||||
pppd/sys-aix4.c
|
||||
-------------------------
|
||||
pppd-2.1.1 release notes
|
||||
Paul Mackerras 27 May 1994
|
||||
|
||||
This file details the new and changed features in pppd since version 1.3.
|
||||
Briefly:
|
||||
- the protocol code has been updated to conform with
|
||||
RFCs 1548, 1549, 1332 and 1334
|
||||
- security has been improved
|
||||
- functionality has been improved in various ways.
|
||||
|
||||
|
||||
NEW FEATURES
|
||||
|
||||
* The option negotiation automaton has been updated to RFC1548. LCP
|
||||
now rejects the Quality Protocol option, since LQR is not implemented
|
||||
yet. IPCP now uses the IP-Address option, and falls back to the old
|
||||
IP-Addresses option if the IP-Address option is rejected. IPCP also
|
||||
uses the new form of the VJ-Compression option.
|
||||
|
||||
RFC1548 defines the "passive" option to mean that the automaton
|
||||
outputs configure-request packets initially, but does not close down
|
||||
if no answer is received. A valid configure-request received will
|
||||
restart the negotiation. The "silent" option has been added with the
|
||||
old meaning of "passive", i.e. the automaton will not output
|
||||
configure-requests until it receives a valid one from the peer.
|
||||
|
||||
* More systems are supported: in addition to SunOS 4.x and BSD/Net-2
|
||||
derived systems, Ultrix and Linux are supported, thanks to Robert
|
||||
Olsson, Per Sundstrom, Michael Callahan and Al Longyear.
|
||||
|
||||
* Options can be taken from files as well as the command line. pppd
|
||||
reads options from the files /etc/ppp/options and ~/.ppprc before
|
||||
looking at the command line, and /etc/ppp/options.<ttyname> after
|
||||
interpreting the options on the command line. An options file is
|
||||
parsed into a series of words, delimited by whitespace. Whitespace
|
||||
can be included in a word by enclosing the word in quotes (").
|
||||
Backslash (\) quotes the following character. A hash (#) starts a
|
||||
comment, which continues until the end of the line. In addition, the
|
||||
`file' option causes pppd to read options from a file. pppd will
|
||||
report and error and exit if ~/.ppprc or the file given as the
|
||||
argument to the `file' option cannot be read by the user who invoked
|
||||
pppd.
|
||||
|
||||
* On those systems, such as NetBSD, where the serial line speed is
|
||||
stored in the termios structure in bits per second (i.e. B9600 ==
|
||||
9600), it is possible to set any speed.
|
||||
|
||||
* If desired, pppd will output LCP echo-request frames periodically
|
||||
while the link is up, and take the link down if no replies are
|
||||
received to a user-configurable number of echo-requests. This can be
|
||||
used to detect that the serial connection has been broken on those
|
||||
systems which don't have hardware modem control lines.
|
||||
|
||||
AUTHENTICATION
|
||||
|
||||
Previous versions of pppd have provided no control over which IP
|
||||
addresses the peer can use. Thus it is possible for the peer to
|
||||
impersonate another host on the local network, leading to various
|
||||
security holes. In addition, the authentication mechanisms were quite
|
||||
weak: if the peer refused to agree to authenticate, pppd would print a
|
||||
warning message but still allow the link to come up. The CHAP
|
||||
implementation also appeared to be quite broken (has anybody actually
|
||||
used it?).
|
||||
|
||||
This new version of pppd addresses these problems. My aim has been to
|
||||
provide system administrators with sufficient access control that PPP
|
||||
access to a server machine can be provided to legitimate users without
|
||||
fear of compromising the security of the server or the network it's
|
||||
on. In part this is provided by the /etc/ppp/options file, where the
|
||||
administrator can place options to require authentication which cannot
|
||||
be disabled by users. Thus the new pppd can made setuid-root and run
|
||||
by users.
|
||||
|
||||
The behaviour where pppd refuses to run unless the /etc/ppp/options
|
||||
file is present and readable by pppd is now the default behaviour. If
|
||||
you really want pppd to run without the presence of the
|
||||
/etc/ppp/options file, you will have to include -DREQ_SYSOPTIONS=0 on
|
||||
the compilation command line.
|
||||
|
||||
The options related to authentication are:
|
||||
|
||||
auth Require authentication from the peer. If neither
|
||||
+chap or +pap is also given, either CHAP or PAP
|
||||
authentication will be accepted.
|
||||
+chap Require CHAP authentication from the peer.
|
||||
+pap Require PAP authentication from the peer.
|
||||
-chap Don't agree to authenticate ourselves with the peer
|
||||
using CHAP.
|
||||
-pap Don't agree to authenticate ourselves using PAP.
|
||||
+ua <f> Get username and password for authenticating ourselves
|
||||
with the peer using PAP from file <f>.
|
||||
name <n> Use <n> as the local name for authentication.
|
||||
usehostname Use this machine's hostname as the local name for
|
||||
authentication.
|
||||
remotename <n> Use <n> as the name of the peer for authentication.
|
||||
login If the peer authenticates using PAP, check the
|
||||
supplied username and password against the system
|
||||
password database, and make a wtmp entry.
|
||||
user <n> Use <n> as the username for authenticating ourselves
|
||||
using PAP.
|
||||
|
||||
The defaults are to agree to authenticate if requested, and to not
|
||||
require authentication from the peer. However, pppd will not agree to
|
||||
authenticate itself with a particular protocol if it has no secrets
|
||||
which could be used to do so.
|
||||
|
||||
Authentication is based on secrets, which are selected from secrets
|
||||
files (/etc/ppp/pap-secrets for PAP, /etc/ppp/chap-secrets for CHAP).
|
||||
Both secrets files have the same format, and both can store secrets
|
||||
for several combinations of server (authenticating peer) and client
|
||||
(peer being authenticated). Note that each end can be both a server
|
||||
and client, and that different protocols can be used in the two
|
||||
directions if desired.
|
||||
|
||||
A secrets file is parsed into words as for an options file. A secret
|
||||
is specified by a line containing at least 3 words, in the order
|
||||
client, server, secret. Any following words on the same line are
|
||||
taken to be a list of acceptable IP addresses for that client. If
|
||||
there are only 3 words on the line, it is assumed that any IP address
|
||||
is OK; to disallow all IP addresses, use "-". If the secret starts
|
||||
with an `@', what follows is assumed to be the name of a file from
|
||||
which to read the secret. A "*" as the client or server name matches
|
||||
any name. When selecting a secret, pppd takes the best match, i.e.
|
||||
the match with the fewest wildcards.
|
||||
|
||||
Thus a secrets file contains both secrets for use in authenticating
|
||||
other hosts, plus secrets which we use for authenticating ourselves to
|
||||
others. Which secret to use is chosen based on the names of the host
|
||||
(the `local name') and its peer (the `remote name'). The local name
|
||||
is set as follows:
|
||||
|
||||
if the `usehostname' option is given,
|
||||
then the local name is the hostname of this machine
|
||||
(with the domain appended, if given)
|
||||
|
||||
else if the `name' option is given,
|
||||
then use the argument of the first `name' option seen
|
||||
|
||||
else if the local IP address is specified with a
|
||||
host name (e.g. `sirius:')
|
||||
then use that host name
|
||||
|
||||
else use the hostname of this machine
|
||||
(with the domain appended, if given)
|
||||
|
||||
When authenticating ourselves using PAP, there is also a `username'
|
||||
which is the local name by default, but can be set with the `user'
|
||||
option or the `+ua' option.
|
||||
|
||||
The remote name is set as follows:
|
||||
|
||||
if the `remotename' option is given,
|
||||
then use the argument of the last `remotename' option seen
|
||||
|
||||
else if the remote IP address is specified with a
|
||||
host name (e.g. `avago:')
|
||||
then use that host name
|
||||
|
||||
else the remote name is the null string "".
|
||||
|
||||
Secrets are selected from the PAP secrets file as follows:
|
||||
|
||||
- For authenticating the peer, look for a secret with client ==
|
||||
username specified in the PAP authenticate-request, and server ==
|
||||
local name.
|
||||
|
||||
- For authenticating ourselves to the peer, look for a secret with
|
||||
client == our username, server == remote name.
|
||||
|
||||
When authenticating the peer with PAP, a secret of "" matches any
|
||||
password supplied by the peer. If the password doesn't match the
|
||||
secret, the password is encrypted using crypt() and checked against
|
||||
the secret again; thus secrets for authenticating the peer can be
|
||||
stored in encrypted form. If the `login' option was specified, the
|
||||
username and password are also checked against the system password
|
||||
database. Thus, the system administrator can set up the pap-secrets
|
||||
file to allow PPP access only to certain users, and to restrict the
|
||||
set of IP addresses that each user can use.
|
||||
|
||||
Secrets are selected from the CHAP secrets file as follows:
|
||||
|
||||
- For authenticating the peer, look for a secret with client == name
|
||||
specified in the CHAP-Response message, and server == local name.
|
||||
|
||||
- For authenticating ourselves to the peer, look for a secret with
|
||||
client == local name, and server == name specified in the
|
||||
CHAP-Challenge message.
|
||||
|
||||
Authentication must be satisfactorily completed before IPCP (or any
|
||||
other Network Control Protocol) can be started. If authentication
|
||||
fails, pppd will terminated the link (by closing LCP). If IPCP
|
||||
negotiates an unacceptable IP address for the remote host, IPCP will
|
||||
be closed. IP packets cannot be sent or received until IPCP is
|
||||
successfully opened.
|
||||
|
||||
(some examples needed here perhaps)
|
||||
|
||||
|
||||
ROUTING
|
||||
|
||||
Setting the addresses on a ppp interface is sufficient to create a
|
||||
host route to the remote end of the link. Sometimes it is desirable
|
||||
to add a default route through the remote host, as in the case of a
|
||||
machine whose only connection to the Internet is through the ppp
|
||||
interface. The `defaultroute' option causes pppd to create such a
|
||||
default route when IPCP comes up, and delete it when the link is
|
||||
terminated.
|
||||
|
||||
In some cases it is desirable to use proxy ARP, for example on a
|
||||
server machine connected to a LAN, in order to allow other hosts to
|
||||
communicate with the remote host. The `proxyarp' option causes pppd
|
||||
to look for a network interface (an interface supporting broadcast and
|
||||
ARP, which is up and not a point-to-point or loopback interface) on
|
||||
the same subnet as the remote host. If found, pppd creates a
|
||||
permanent, published ARP entry with the IP address of the remote host
|
||||
and the hardware address of the network interface found.
|
||||
|
||||
|
||||
OTHER NEW AND CHANGED OPTIONS
|
||||
|
||||
modem Use modem control lines (not fully implemented
|
||||
yet)
|
||||
local Don't use modem control lines
|
||||
persist Keep reopening connection (not fully
|
||||
implemented yet)
|
||||
|
||||
lcp-restart <n> Set timeout for LCP retransmissions to <n>
|
||||
seconds (default 3 seconds)
|
||||
lcp-max-terminate <n> Set maximum number of LCP terminate-request
|
||||
transmissions (default 2)
|
||||
lcp-max-configure <n> Set maximum number of LCP configure-request
|
||||
transmissions (default 10)
|
||||
lcp-max-failure <n> Set maximum number of LCP configure-Naks sent
|
||||
before converting to configure-rejects
|
||||
(default 10)
|
||||
|
||||
ipcp-restart <n> Set timeout for IPCP retransmissions to <n>
|
||||
seconds (default 3 seconds)
|
||||
ipcp-max-terminate <n> Set maximum number of IPCP
|
||||
terminate-request transmissions (default 2)
|
||||
ipcp-max-configure <n> Set maximum number of IPCP
|
||||
configure-request transmissions (default 10)
|
||||
ipcp-max-failure <n> Set maximum number of IPCP configure-Naks
|
||||
sent before converting to configure-rejects
|
||||
(default 10)
|
||||
|
||||
upap-restart <n> Set timeout for PAP retransmissions to
|
||||
<n> seconds (default 3 seconds)
|
||||
upap-max-authreq <n> Set maximum number of Authenticate-request
|
||||
retransmissions (default 10)
|
||||
|
||||
chap-restart <n> Set timeout for CHAP retransmissions to
|
||||
<n> seconds (default 3 seconds)
|
||||
chap-max-challenge <n> Set maximum number of CHAP Challenge
|
||||
retransmissions (default 10)
|
||||
chap-interval <n> Set the interval between CHAP rechallenges
|
||||
(default 0, meaning infinity)
|
||||
|
||||
The -ua option no longer exists.
|
||||
|
||||
|
||||
SOFTWARE RESTRUCTURING
|
||||
|
||||
Many of the source files for pppd have changed significantly from
|
||||
ppp-1.3, upon which it is based. In particular:
|
||||
|
||||
- the macros for system-dependent operations in pppd.h have mostly
|
||||
been removed. Instead these operations are performed by procedures in
|
||||
sys-bsd.c (for BSD-4.4ish systems like NetBSD, 386BSD, etc.) or
|
||||
sys-str.c (for SunOS-based systems using STREAMS). (I got sick of
|
||||
having to recompile everything every time I wanted to change one of
|
||||
those horrible macros.)
|
||||
|
||||
- most of the system-dependent code in main.c has also been removed to
|
||||
sys-bsd.c and sys-str.c.
|
||||
|
||||
- the option processing code in main.c has been removed to options.c.
|
||||
|
||||
- the authentication code in main.c has been removed to auth.c, which
|
||||
also contains substantial amounts of new code.
|
||||
|
||||
- fsm.c has changed significantly, and lcp.c, ipcp.c, and upap.c have
|
||||
changed somewhat. chap.c has also changed significantly.
|
||||
|
||||
|
||||
STILL TO DO
|
||||
|
||||
* sort out appropriate modem control and implement the persist option
|
||||
properly; add an `answer' option for auto-answering a modem.
|
||||
|
||||
* add an inactivity timeout and demand dialing.
|
||||
|
||||
* implement link quality monitoring.
|
||||
|
||||
* implement other network control protocols.
|
1637
usr.sbin/pppd/auth.c
1637
usr.sbin/pppd/auth.c
File diff suppressed because it is too large
Load Diff
@ -1,411 +0,0 @@
|
||||
/*
|
||||
* cbcp - Call Back Configuration Protocol.
|
||||
*
|
||||
* Copyright (c) 1995 Pedro Roque Marques
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Pedro Roque Marques. The name of the author may not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] = "$FreeBSD$";
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "pppd.h"
|
||||
#include "cbcp.h"
|
||||
#include "fsm.h"
|
||||
#include "lcp.h"
|
||||
#include "ipcp.h"
|
||||
|
||||
/*
|
||||
* Protocol entry points.
|
||||
*/
|
||||
static void cbcp_init(int unit);
|
||||
static void cbcp_open(int unit);
|
||||
static void cbcp_lowerup(int unit);
|
||||
static void cbcp_input(int unit, u_char *pkt, int len);
|
||||
static void cbcp_protrej(int unit);
|
||||
static int cbcp_printpkt(u_char *pkt, int len,
|
||||
void (*printer)(void *, char *, ...),
|
||||
void *arg);
|
||||
|
||||
struct protent cbcp_protent = {
|
||||
PPP_CBCP,
|
||||
cbcp_init,
|
||||
cbcp_input,
|
||||
cbcp_protrej,
|
||||
cbcp_lowerup,
|
||||
NULL,
|
||||
cbcp_open,
|
||||
NULL,
|
||||
cbcp_printpkt,
|
||||
NULL,
|
||||
0,
|
||||
"CBCP",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
cbcp_state cbcp[NUM_PPP];
|
||||
|
||||
/* internal prototypes */
|
||||
|
||||
static void cbcp_recvreq(cbcp_state *us, char *pckt, int len);
|
||||
static void cbcp_resp(cbcp_state *us);
|
||||
static void cbcp_up(cbcp_state *us);
|
||||
static void cbcp_recvack(cbcp_state *us, char *pckt, int len);
|
||||
static void cbcp_send(cbcp_state *us, u_char code, u_char *buf, int len);
|
||||
|
||||
/* init state */
|
||||
static void
|
||||
cbcp_init(int iface)
|
||||
{
|
||||
cbcp_state *us;
|
||||
|
||||
us = &cbcp[iface];
|
||||
memset(us, 0, sizeof(cbcp_state));
|
||||
us->us_unit = iface;
|
||||
us->us_type |= (1 << CB_CONF_NO);
|
||||
}
|
||||
|
||||
/* lower layer is up */
|
||||
static void
|
||||
cbcp_lowerup(int iface)
|
||||
{
|
||||
cbcp_state *us = &cbcp[iface];
|
||||
|
||||
syslog(LOG_DEBUG, "cbcp_lowerup");
|
||||
syslog(LOG_DEBUG, "want: %d", us->us_type);
|
||||
|
||||
if (us->us_type == CB_CONF_USER)
|
||||
syslog(LOG_DEBUG, "phone no: %s", us->us_number);
|
||||
}
|
||||
|
||||
static void
|
||||
cbcp_open(int unit)
|
||||
{
|
||||
syslog(LOG_DEBUG, "cbcp_open");
|
||||
}
|
||||
|
||||
/* process an incomming packet */
|
||||
static void
|
||||
cbcp_input(int unit, u_char *inpacket, int pktlen)
|
||||
{
|
||||
u_char *inp;
|
||||
u_char code, id;
|
||||
u_short len;
|
||||
|
||||
cbcp_state *us = &cbcp[unit];
|
||||
|
||||
inp = inpacket;
|
||||
|
||||
if (pktlen < CBCP_MINLEN) {
|
||||
syslog(LOG_ERR, "CBCP packet is too small");
|
||||
return;
|
||||
}
|
||||
|
||||
GETCHAR(code, inp);
|
||||
GETCHAR(id, inp);
|
||||
GETSHORT(len, inp);
|
||||
|
||||
if (len < CBCP_MINLEN || len > pktlen) {
|
||||
syslog(LOG_ERR, "CBCP packet: invalid length");
|
||||
return;
|
||||
}
|
||||
|
||||
len -= CBCP_MINLEN;
|
||||
|
||||
switch(code) {
|
||||
case CBCP_REQ:
|
||||
us->us_id = id;
|
||||
cbcp_recvreq(us, inp, len);
|
||||
break;
|
||||
|
||||
case CBCP_RESP:
|
||||
syslog(LOG_DEBUG, "CBCP_RESP received");
|
||||
break;
|
||||
|
||||
case CBCP_ACK:
|
||||
if (id != us->us_id)
|
||||
syslog(LOG_DEBUG, "id doesn't match: expected %d recv %d",
|
||||
us->us_id, id);
|
||||
|
||||
cbcp_recvack(us, inp, len);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* protocol was rejected by foe */
|
||||
void cbcp_protrej(int iface)
|
||||
{
|
||||
}
|
||||
|
||||
char *cbcp_codenames[] = {
|
||||
"Request", "Response", "Ack"
|
||||
};
|
||||
|
||||
char *cbcp_optionnames[] = {
|
||||
"NoCallback",
|
||||
"UserDefined",
|
||||
"AdminDefined",
|
||||
"List"
|
||||
};
|
||||
|
||||
/* pretty print a packet */
|
||||
static int
|
||||
cbcp_printpkt(u_char *p, int plen, void (*printer)(void *, char *, ...),
|
||||
void *arg)
|
||||
{
|
||||
int code, opt, id, len, olen, delay;
|
||||
u_char *pstart;
|
||||
|
||||
if (plen < HEADERLEN)
|
||||
return 0;
|
||||
pstart = p;
|
||||
GETCHAR(code, p);
|
||||
GETCHAR(id, p);
|
||||
GETSHORT(len, p);
|
||||
if (len < HEADERLEN || len > plen)
|
||||
return 0;
|
||||
|
||||
if (code >= 1 && code <= sizeof(cbcp_codenames) / sizeof(char *))
|
||||
printer(arg, " %s", cbcp_codenames[code-1]);
|
||||
else
|
||||
printer(arg, " code=0x%x", code);
|
||||
|
||||
printer(arg, " id=0x%x", id);
|
||||
len -= HEADERLEN;
|
||||
|
||||
switch (code) {
|
||||
case CBCP_REQ:
|
||||
case CBCP_RESP:
|
||||
case CBCP_ACK:
|
||||
while(len >= 2) {
|
||||
GETCHAR(opt, p);
|
||||
GETCHAR(olen, p);
|
||||
|
||||
if (olen < 2 || olen > len) {
|
||||
break;
|
||||
}
|
||||
|
||||
printer(arg, " <");
|
||||
len -= olen;
|
||||
|
||||
if (opt >= 1 && opt <= sizeof(cbcp_optionnames) / sizeof(char *))
|
||||
printer(arg, " %s", cbcp_optionnames[opt-1]);
|
||||
else
|
||||
printer(arg, " option=0x%x", opt);
|
||||
|
||||
if (olen > 2) {
|
||||
GETCHAR(delay, p);
|
||||
printer(arg, " delay = %d", delay);
|
||||
}
|
||||
|
||||
if (olen > 3) {
|
||||
int addrt;
|
||||
char str[256];
|
||||
|
||||
GETCHAR(addrt, p);
|
||||
memcpy(str, p, olen - 4);
|
||||
str[olen - 4] = 0;
|
||||
printer(arg, " number = %s", str);
|
||||
}
|
||||
printer(arg, ">");
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (; len > 0; --len) {
|
||||
GETCHAR(code, p);
|
||||
printer(arg, " %.2x", code);
|
||||
}
|
||||
|
||||
return p - pstart;
|
||||
}
|
||||
|
||||
/* received CBCP request */
|
||||
static void
|
||||
cbcp_recvreq(cbcp_state *us, char *pckt, int pcktlen)
|
||||
{
|
||||
u_char type, opt_len, delay, addr_type;
|
||||
char address[256];
|
||||
int len = pcktlen;
|
||||
|
||||
address[0] = 0;
|
||||
|
||||
while (len > 1) {
|
||||
syslog(LOG_DEBUG, "length: %d", len);
|
||||
|
||||
GETCHAR(type, pckt);
|
||||
GETCHAR(opt_len, pckt);
|
||||
|
||||
if (len < opt_len)
|
||||
break;
|
||||
len -= opt_len;
|
||||
|
||||
if (opt_len > 2)
|
||||
GETCHAR(delay, pckt);
|
||||
|
||||
us->us_allowed |= (1 << type);
|
||||
|
||||
switch(type) {
|
||||
case CB_CONF_NO:
|
||||
syslog(LOG_DEBUG, "no callback allowed");
|
||||
break;
|
||||
|
||||
case CB_CONF_USER:
|
||||
syslog(LOG_DEBUG, "user callback allowed");
|
||||
if (opt_len > 4) {
|
||||
GETCHAR(addr_type, pckt);
|
||||
memcpy(address, pckt, opt_len - 4);
|
||||
address[opt_len - 4] = 0;
|
||||
if (address[0])
|
||||
syslog(LOG_DEBUG, "address: %s", address);
|
||||
}
|
||||
break;
|
||||
|
||||
case CB_CONF_ADMIN:
|
||||
syslog(LOG_DEBUG, "user admin defined allowed");
|
||||
break;
|
||||
|
||||
case CB_CONF_LIST:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cbcp_resp(us);
|
||||
}
|
||||
|
||||
static void
|
||||
cbcp_resp(cbcp_state *us)
|
||||
{
|
||||
u_char cb_type;
|
||||
u_char buf[256];
|
||||
u_char *bufp = buf;
|
||||
int len = 0;
|
||||
|
||||
cb_type = us->us_allowed & us->us_type;
|
||||
syslog(LOG_DEBUG, "cbcp_resp cb_type=%d", cb_type);
|
||||
|
||||
#if 0
|
||||
if (!cb_type)
|
||||
lcp_down(us->us_unit);
|
||||
#endif
|
||||
|
||||
if (cb_type & ( 1 << CB_CONF_USER ) ) {
|
||||
syslog(LOG_DEBUG, "cbcp_resp CONF_USER");
|
||||
PUTCHAR(CB_CONF_USER, bufp);
|
||||
len = 3 + 1 + strlen(us->us_number) + 1;
|
||||
PUTCHAR(len , bufp);
|
||||
PUTCHAR(5, bufp); /* delay */
|
||||
PUTCHAR(1, bufp);
|
||||
BCOPY(us->us_number, bufp, strlen(us->us_number) + 1);
|
||||
cbcp_send(us, CBCP_RESP, buf, len);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cb_type & ( 1 << CB_CONF_ADMIN ) ) {
|
||||
syslog(LOG_DEBUG, "cbcp_resp CONF_ADMIN");
|
||||
PUTCHAR(CB_CONF_ADMIN, bufp);
|
||||
len = 3;
|
||||
PUTCHAR(len, bufp);
|
||||
PUTCHAR(5, bufp); /* delay */
|
||||
cbcp_send(us, CBCP_RESP, buf, len);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cb_type & ( 1 << CB_CONF_NO ) ) {
|
||||
syslog(LOG_DEBUG, "cbcp_resp CONF_NO");
|
||||
PUTCHAR(CB_CONF_NO, bufp);
|
||||
len = 2;
|
||||
PUTCHAR(len , bufp);
|
||||
cbcp_send(us, CBCP_RESP, buf, len);
|
||||
(*ipcp_protent.open)(us->us_unit);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
cbcp_send(cbcp_state *us, u_char code, u_char *buf, int len)
|
||||
{
|
||||
u_char *outp;
|
||||
int outlen;
|
||||
|
||||
outp = outpacket_buf;
|
||||
|
||||
outlen = 4 + len;
|
||||
|
||||
MAKEHEADER(outp, PPP_CBCP);
|
||||
|
||||
PUTCHAR(code, outp);
|
||||
PUTCHAR(us->us_id, outp);
|
||||
PUTSHORT(outlen, outp);
|
||||
|
||||
if (len)
|
||||
BCOPY(buf, outp, len);
|
||||
|
||||
output(us->us_unit, outpacket_buf, outlen + PPP_HDRLEN);
|
||||
}
|
||||
|
||||
static void
|
||||
cbcp_recvack(cbcp_state *us, char *pckt, int len)
|
||||
{
|
||||
u_char type, delay, addr_type;
|
||||
int opt_len;
|
||||
char address[256];
|
||||
|
||||
if (len > 1) {
|
||||
GETCHAR(type, pckt);
|
||||
GETCHAR(opt_len, pckt);
|
||||
|
||||
if (opt_len > len)
|
||||
return;
|
||||
|
||||
if (opt_len > 2)
|
||||
GETCHAR(delay, pckt);
|
||||
|
||||
if (opt_len > 4) {
|
||||
GETCHAR(addr_type, pckt);
|
||||
memcpy(address, pckt, opt_len - 4);
|
||||
address[opt_len - 4] = 0;
|
||||
if (address[0])
|
||||
syslog(LOG_DEBUG, "peer will call: %s", address);
|
||||
}
|
||||
}
|
||||
|
||||
cbcp_up(us);
|
||||
}
|
||||
|
||||
extern int persist;
|
||||
|
||||
/* ok peer will do callback */
|
||||
static void
|
||||
cbcp_up(cbcp_state *us)
|
||||
{
|
||||
persist = 0;
|
||||
lcp_close(0, "Call me back, please");
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
#ifndef CBCP_H
|
||||
#define CBCP_H
|
||||
|
||||
typedef struct cbcp_state {
|
||||
int us_unit; /* Interface unit number */
|
||||
u_char us_id; /* Current id */
|
||||
u_char us_allowed;
|
||||
int us_type;
|
||||
char *us_number; /* Telefone Number */
|
||||
} cbcp_state;
|
||||
|
||||
extern cbcp_state cbcp[];
|
||||
|
||||
extern struct protent cbcp_protent;
|
||||
|
||||
#define CBCP_MINLEN 4
|
||||
|
||||
#define CBCP_REQ 1
|
||||
#define CBCP_RESP 2
|
||||
#define CBCP_ACK 3
|
||||
|
||||
#define CB_CONF_NO 1
|
||||
#define CB_CONF_USER 2
|
||||
#define CB_CONF_ADMIN 3
|
||||
#define CB_CONF_LIST 4
|
||||
#endif
|
1113
usr.sbin/pppd/ccp.c
1113
usr.sbin/pppd/ccp.c
File diff suppressed because it is too large
Load Diff
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* ccp.h - Definitions for PPP Compression Control Protocol.
|
||||
*
|
||||
* Copyright (c) 1994 The Australian National University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, provided that the above copyright
|
||||
* notice appears in all copies. This software is provided without any
|
||||
* warranty, express or implied. The Australian National University
|
||||
* makes no representations about the suitability of this software for
|
||||
* any purpose.
|
||||
*
|
||||
* IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
|
||||
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
|
||||
* THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
* ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
|
||||
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
||||
* OR MODIFICATIONS.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
typedef struct ccp_options {
|
||||
u_int bsd_compress: 1; /* do BSD Compress? */
|
||||
u_int deflate: 1; /* do Deflate? (RFC code) */
|
||||
u_int baddeflate: 1; /* do Deflate? (Magnalink!) */
|
||||
u_int predictor_1: 1; /* do Predictor-1? */
|
||||
u_int predictor_2: 1; /* do Predictor-2? */
|
||||
u_int deflate_correct: 1; /* use correct code for deflate? */
|
||||
u_int deflate_draft: 1; /* use draft RFC code for deflate? */
|
||||
u_short bsd_bits; /* # bits/code for BSD Compress */
|
||||
u_short deflate_size; /* lg(window size) for Deflate */
|
||||
u_short baddeflate_size; /* lg(window size) for Deflate */
|
||||
short method; /* code for chosen compression method */
|
||||
} ccp_options;
|
||||
|
||||
extern fsm ccp_fsm[];
|
||||
extern ccp_options ccp_wantoptions[];
|
||||
extern ccp_options ccp_gotoptions[];
|
||||
extern ccp_options ccp_allowoptions[];
|
||||
extern ccp_options ccp_hisoptions[];
|
||||
|
||||
extern struct protent ccp_protent;
|
@ -1,870 +0,0 @@
|
||||
/*
|
||||
* chap.c - Challenge Handshake Authentication Protocol.
|
||||
*
|
||||
* Copyright (c) 1993 The Australian National University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the Australian National University. The name of the University
|
||||
* may not be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* Copyright (c) 1991 Gregory M. Christy.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Gregory M. Christy. The name of the author may not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] = "$FreeBSD$";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <syslog.h>
|
||||
#include <md5.h>
|
||||
|
||||
#include "pppd.h"
|
||||
#include "chap.h"
|
||||
#include "md5.h"
|
||||
#ifdef CHAPMS
|
||||
#include "chap_ms.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Protocol entry points.
|
||||
*/
|
||||
static void ChapInit(int);
|
||||
static void ChapLowerUp(int);
|
||||
static void ChapLowerDown(int);
|
||||
static void ChapInput(int, u_char *, int);
|
||||
static void ChapProtocolReject(int);
|
||||
static int ChapPrintPkt(u_char *, int,
|
||||
void (*)(void *, char *, ...), void *);
|
||||
|
||||
struct protent chap_protent = {
|
||||
PPP_CHAP,
|
||||
ChapInit,
|
||||
ChapInput,
|
||||
ChapProtocolReject,
|
||||
ChapLowerUp,
|
||||
ChapLowerDown,
|
||||
NULL,
|
||||
NULL,
|
||||
ChapPrintPkt,
|
||||
NULL,
|
||||
1,
|
||||
"CHAP",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
chap_state chap[NUM_PPP]; /* CHAP state; one for each unit */
|
||||
|
||||
static void ChapChallengeTimeout(void *);
|
||||
static void ChapResponseTimeout(void *);
|
||||
static void ChapReceiveChallenge(chap_state *, u_char *, int, int);
|
||||
static void ChapRechallenge(void *);
|
||||
static void ChapReceiveResponse(chap_state *, u_char *, int, int);
|
||||
static void ChapReceiveSuccess(chap_state *, u_char *, int, int);
|
||||
static void ChapReceiveFailure(chap_state *, u_char *, int, int);
|
||||
static void ChapSendStatus(chap_state *, int);
|
||||
static void ChapSendChallenge(chap_state *);
|
||||
static void ChapSendResponse(chap_state *);
|
||||
static void ChapGenChallenge(chap_state *);
|
||||
|
||||
extern double drand48(void);
|
||||
extern void srand48(long);
|
||||
|
||||
/*
|
||||
* ChapInit - Initialize a CHAP unit.
|
||||
*/
|
||||
static void
|
||||
ChapInit(unit)
|
||||
int unit;
|
||||
{
|
||||
chap_state *cstate = &chap[unit];
|
||||
|
||||
BZERO(cstate, sizeof(*cstate));
|
||||
cstate->unit = unit;
|
||||
cstate->clientstate = CHAPCS_INITIAL;
|
||||
cstate->serverstate = CHAPSS_INITIAL;
|
||||
cstate->timeouttime = CHAP_DEFTIMEOUT;
|
||||
cstate->max_transmits = CHAP_DEFTRANSMITS;
|
||||
/* random number generator is initialized in magic_init */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ChapAuthWithPeer - Authenticate us with our peer (start client).
|
||||
*
|
||||
*/
|
||||
void
|
||||
ChapAuthWithPeer(unit, our_name, digest)
|
||||
int unit;
|
||||
char *our_name;
|
||||
int digest;
|
||||
{
|
||||
chap_state *cstate = &chap[unit];
|
||||
|
||||
cstate->resp_name = our_name;
|
||||
cstate->resp_type = digest;
|
||||
|
||||
if (cstate->clientstate == CHAPCS_INITIAL ||
|
||||
cstate->clientstate == CHAPCS_PENDING) {
|
||||
/* lower layer isn't up - wait until later */
|
||||
cstate->clientstate = CHAPCS_PENDING;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* We get here as a result of LCP coming up.
|
||||
* So even if CHAP was open before, we will
|
||||
* have to re-authenticate ourselves.
|
||||
*/
|
||||
cstate->clientstate = CHAPCS_LISTEN;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ChapAuthPeer - Authenticate our peer (start server).
|
||||
*/
|
||||
void
|
||||
ChapAuthPeer(unit, our_name, digest)
|
||||
int unit;
|
||||
char *our_name;
|
||||
int digest;
|
||||
{
|
||||
chap_state *cstate = &chap[unit];
|
||||
|
||||
cstate->chal_name = our_name;
|
||||
cstate->chal_type = digest;
|
||||
|
||||
if (cstate->serverstate == CHAPSS_INITIAL ||
|
||||
cstate->serverstate == CHAPSS_PENDING) {
|
||||
/* lower layer isn't up - wait until later */
|
||||
cstate->serverstate = CHAPSS_PENDING;
|
||||
return;
|
||||
}
|
||||
|
||||
ChapGenChallenge(cstate);
|
||||
ChapSendChallenge(cstate); /* crank it up dude! */
|
||||
cstate->serverstate = CHAPSS_INITIAL_CHAL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ChapChallengeTimeout - Timeout expired on sending challenge.
|
||||
*/
|
||||
static void
|
||||
ChapChallengeTimeout(arg)
|
||||
void *arg;
|
||||
{
|
||||
chap_state *cstate = (chap_state *) arg;
|
||||
|
||||
/* if we aren't sending challenges, don't worry. then again we */
|
||||
/* probably shouldn't be here either */
|
||||
if (cstate->serverstate != CHAPSS_INITIAL_CHAL &&
|
||||
cstate->serverstate != CHAPSS_RECHALLENGE)
|
||||
return;
|
||||
|
||||
if (cstate->chal_transmits >= cstate->max_transmits) {
|
||||
/* give up on peer */
|
||||
syslog(LOG_ERR, "Peer failed to respond to CHAP challenge");
|
||||
cstate->serverstate = CHAPSS_BADAUTH;
|
||||
auth_peer_fail(cstate->unit, PPP_CHAP);
|
||||
return;
|
||||
}
|
||||
|
||||
ChapSendChallenge(cstate); /* Re-send challenge */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ChapResponseTimeout - Timeout expired on sending response.
|
||||
*/
|
||||
static void
|
||||
ChapResponseTimeout(arg)
|
||||
void *arg;
|
||||
{
|
||||
chap_state *cstate = (chap_state *) arg;
|
||||
|
||||
/* if we aren't sending a response, don't worry. */
|
||||
if (cstate->clientstate != CHAPCS_RESPONSE)
|
||||
return;
|
||||
|
||||
ChapSendResponse(cstate); /* re-send response */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ChapRechallenge - Time to challenge the peer again.
|
||||
*/
|
||||
static void
|
||||
ChapRechallenge(arg)
|
||||
void *arg;
|
||||
{
|
||||
chap_state *cstate = (chap_state *) arg;
|
||||
|
||||
/* if we aren't sending a response, don't worry. */
|
||||
if (cstate->serverstate != CHAPSS_OPEN)
|
||||
return;
|
||||
|
||||
ChapGenChallenge(cstate);
|
||||
ChapSendChallenge(cstate);
|
||||
cstate->serverstate = CHAPSS_RECHALLENGE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ChapLowerUp - The lower layer is up.
|
||||
*
|
||||
* Start up if we have pending requests.
|
||||
*/
|
||||
static void
|
||||
ChapLowerUp(unit)
|
||||
int unit;
|
||||
{
|
||||
chap_state *cstate = &chap[unit];
|
||||
|
||||
if (cstate->clientstate == CHAPCS_INITIAL)
|
||||
cstate->clientstate = CHAPCS_CLOSED;
|
||||
else if (cstate->clientstate == CHAPCS_PENDING)
|
||||
cstate->clientstate = CHAPCS_LISTEN;
|
||||
|
||||
if (cstate->serverstate == CHAPSS_INITIAL)
|
||||
cstate->serverstate = CHAPSS_CLOSED;
|
||||
else if (cstate->serverstate == CHAPSS_PENDING) {
|
||||
ChapGenChallenge(cstate);
|
||||
ChapSendChallenge(cstate);
|
||||
cstate->serverstate = CHAPSS_INITIAL_CHAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ChapLowerDown - The lower layer is down.
|
||||
*
|
||||
* Cancel all timeouts.
|
||||
*/
|
||||
static void
|
||||
ChapLowerDown(unit)
|
||||
int unit;
|
||||
{
|
||||
chap_state *cstate = &chap[unit];
|
||||
|
||||
/* Timeout(s) pending? Cancel if so. */
|
||||
if (cstate->serverstate == CHAPSS_INITIAL_CHAL ||
|
||||
cstate->serverstate == CHAPSS_RECHALLENGE)
|
||||
UNTIMEOUT(ChapChallengeTimeout, cstate);
|
||||
else if (cstate->serverstate == CHAPSS_OPEN
|
||||
&& cstate->chal_interval != 0)
|
||||
UNTIMEOUT(ChapRechallenge, cstate);
|
||||
if (cstate->clientstate == CHAPCS_RESPONSE)
|
||||
UNTIMEOUT(ChapResponseTimeout, cstate);
|
||||
|
||||
cstate->clientstate = CHAPCS_INITIAL;
|
||||
cstate->serverstate = CHAPSS_INITIAL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ChapProtocolReject - Peer doesn't grok CHAP.
|
||||
*/
|
||||
static void
|
||||
ChapProtocolReject(unit)
|
||||
int unit;
|
||||
{
|
||||
chap_state *cstate = &chap[unit];
|
||||
|
||||
if (cstate->serverstate != CHAPSS_INITIAL &&
|
||||
cstate->serverstate != CHAPSS_CLOSED)
|
||||
auth_peer_fail(unit, PPP_CHAP);
|
||||
if (cstate->clientstate != CHAPCS_INITIAL &&
|
||||
cstate->clientstate != CHAPCS_CLOSED)
|
||||
auth_withpeer_fail(unit, PPP_CHAP);
|
||||
ChapLowerDown(unit); /* shutdown chap */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ChapInput - Input CHAP packet.
|
||||
*/
|
||||
static void
|
||||
ChapInput(unit, inpacket, packet_len)
|
||||
int unit;
|
||||
u_char *inpacket;
|
||||
int packet_len;
|
||||
{
|
||||
chap_state *cstate = &chap[unit];
|
||||
u_char *inp;
|
||||
u_char code, id;
|
||||
int len;
|
||||
|
||||
/*
|
||||
* Parse header (code, id and length).
|
||||
* If packet too short, drop it.
|
||||
*/
|
||||
inp = inpacket;
|
||||
if (packet_len < CHAP_HEADERLEN) {
|
||||
CHAPDEBUG((LOG_INFO, "ChapInput: rcvd short header."));
|
||||
return;
|
||||
}
|
||||
GETCHAR(code, inp);
|
||||
GETCHAR(id, inp);
|
||||
GETSHORT(len, inp);
|
||||
if (len < CHAP_HEADERLEN) {
|
||||
CHAPDEBUG((LOG_INFO, "ChapInput: rcvd illegal length."));
|
||||
return;
|
||||
}
|
||||
if (len > packet_len) {
|
||||
CHAPDEBUG((LOG_INFO, "ChapInput: rcvd short packet."));
|
||||
return;
|
||||
}
|
||||
len -= CHAP_HEADERLEN;
|
||||
|
||||
/*
|
||||
* Action depends on code (as in fact it usually does :-).
|
||||
*/
|
||||
switch (code) {
|
||||
case CHAP_CHALLENGE:
|
||||
ChapReceiveChallenge(cstate, inp, id, len);
|
||||
break;
|
||||
|
||||
case CHAP_RESPONSE:
|
||||
ChapReceiveResponse(cstate, inp, id, len);
|
||||
break;
|
||||
|
||||
case CHAP_FAILURE:
|
||||
ChapReceiveFailure(cstate, inp, id, len);
|
||||
break;
|
||||
|
||||
case CHAP_SUCCESS:
|
||||
ChapReceiveSuccess(cstate, inp, id, len);
|
||||
break;
|
||||
|
||||
default: /* Need code reject? */
|
||||
syslog(LOG_WARNING, "Unknown CHAP code (%d) received.", code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ChapReceiveChallenge - Receive Challenge and send Response.
|
||||
*/
|
||||
static void
|
||||
ChapReceiveChallenge(cstate, inp, id, len)
|
||||
chap_state *cstate;
|
||||
u_char *inp;
|
||||
int id;
|
||||
int len;
|
||||
{
|
||||
int rchallenge_len;
|
||||
u_char *rchallenge;
|
||||
int secret_len;
|
||||
char secret[MAXSECRETLEN];
|
||||
char rhostname[256];
|
||||
MD5_CTX mdContext;
|
||||
u_char hash[MD5_SIGNATURE_SIZE];
|
||||
|
||||
CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: Rcvd id %d.", id));
|
||||
if (cstate->clientstate == CHAPCS_CLOSED ||
|
||||
cstate->clientstate == CHAPCS_PENDING) {
|
||||
CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: in state %d",
|
||||
cstate->clientstate));
|
||||
return;
|
||||
}
|
||||
|
||||
if (len < 2) {
|
||||
CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: rcvd short packet."));
|
||||
return;
|
||||
}
|
||||
|
||||
GETCHAR(rchallenge_len, inp);
|
||||
len -= sizeof (u_char) + rchallenge_len; /* now name field length */
|
||||
if (len < 0) {
|
||||
CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: rcvd short packet."));
|
||||
return;
|
||||
}
|
||||
rchallenge = inp;
|
||||
INCPTR(rchallenge_len, inp);
|
||||
|
||||
if (len >= sizeof(rhostname))
|
||||
len = sizeof(rhostname) - 1;
|
||||
BCOPY(inp, rhostname, len);
|
||||
rhostname[len] = '\000';
|
||||
|
||||
CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: received name field '%s'",
|
||||
rhostname));
|
||||
|
||||
/* Microsoft doesn't send their name back in the PPP packet */
|
||||
if (remote_name[0] != 0 && (explicit_remote || rhostname[0] == 0)) {
|
||||
strncpy(rhostname, remote_name, sizeof(rhostname));
|
||||
rhostname[sizeof(rhostname) - 1] = 0;
|
||||
CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: using '%s' as remote name",
|
||||
rhostname));
|
||||
}
|
||||
|
||||
/* get secret for authenticating ourselves with the specified host */
|
||||
if (!get_secret(cstate->unit, cstate->resp_name, rhostname,
|
||||
secret, &secret_len, 0)) {
|
||||
secret_len = 0; /* assume null secret if can't find one */
|
||||
syslog(LOG_WARNING, "No CHAP secret found for authenticating us to %s",
|
||||
rhostname);
|
||||
}
|
||||
|
||||
/* cancel response send timeout if necessary */
|
||||
if (cstate->clientstate == CHAPCS_RESPONSE)
|
||||
UNTIMEOUT(ChapResponseTimeout, cstate);
|
||||
|
||||
cstate->resp_id = id;
|
||||
cstate->resp_transmits = 0;
|
||||
|
||||
/* generate MD based on negotiated type */
|
||||
switch (cstate->resp_type) {
|
||||
|
||||
case CHAP_DIGEST_MD5:
|
||||
MD5Init(&mdContext);
|
||||
MD5Update(&mdContext, &cstate->resp_id, 1);
|
||||
MD5Update(&mdContext, secret, secret_len);
|
||||
MD5Update(&mdContext, rchallenge, rchallenge_len);
|
||||
MD5Final(hash, &mdContext);
|
||||
BCOPY(hash, cstate->response, MD5_SIGNATURE_SIZE);
|
||||
cstate->resp_length = MD5_SIGNATURE_SIZE;
|
||||
break;
|
||||
|
||||
#ifdef CHAPMS
|
||||
case CHAP_MICROSOFT:
|
||||
ChapMS(cstate, rchallenge, rchallenge_len, secret, secret_len);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
CHAPDEBUG((LOG_INFO, "unknown digest type %d", cstate->resp_type));
|
||||
return;
|
||||
}
|
||||
|
||||
BZERO(secret, sizeof(secret));
|
||||
ChapSendResponse(cstate);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ChapReceiveResponse - Receive and process response.
|
||||
*/
|
||||
static void
|
||||
ChapReceiveResponse(cstate, inp, id, len)
|
||||
chap_state *cstate;
|
||||
u_char *inp;
|
||||
int id;
|
||||
int len;
|
||||
{
|
||||
u_char *remmd, remmd_len;
|
||||
int secret_len, old_state;
|
||||
int code;
|
||||
char rhostname[256];
|
||||
MD5_CTX mdContext;
|
||||
char secret[MAXSECRETLEN];
|
||||
u_char hash[MD5_SIGNATURE_SIZE];
|
||||
|
||||
CHAPDEBUG((LOG_INFO, "ChapReceiveResponse: Rcvd id %d.", id));
|
||||
|
||||
if (cstate->serverstate == CHAPSS_CLOSED ||
|
||||
cstate->serverstate == CHAPSS_PENDING) {
|
||||
CHAPDEBUG((LOG_INFO, "ChapReceiveResponse: in state %d",
|
||||
cstate->serverstate));
|
||||
return;
|
||||
}
|
||||
|
||||
if (id != cstate->chal_id)
|
||||
return; /* doesn't match ID of last challenge */
|
||||
|
||||
/*
|
||||
* If we have received a duplicate or bogus Response,
|
||||
* we have to send the same answer (Success/Failure)
|
||||
* as we did for the first Response we saw.
|
||||
*/
|
||||
if (cstate->serverstate == CHAPSS_OPEN) {
|
||||
ChapSendStatus(cstate, CHAP_SUCCESS);
|
||||
return;
|
||||
}
|
||||
if (cstate->serverstate == CHAPSS_BADAUTH) {
|
||||
ChapSendStatus(cstate, CHAP_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (len < 2) {
|
||||
CHAPDEBUG((LOG_INFO, "ChapReceiveResponse: rcvd short packet."));
|
||||
return;
|
||||
}
|
||||
GETCHAR(remmd_len, inp); /* get length of MD */
|
||||
remmd = inp; /* get pointer to MD */
|
||||
INCPTR(remmd_len, inp);
|
||||
|
||||
len -= sizeof (u_char) + remmd_len;
|
||||
if (len < 0) {
|
||||
CHAPDEBUG((LOG_INFO, "ChapReceiveResponse: rcvd short packet."));
|
||||
return;
|
||||
}
|
||||
|
||||
UNTIMEOUT(ChapChallengeTimeout, cstate);
|
||||
|
||||
if (len >= sizeof(rhostname))
|
||||
len = sizeof(rhostname) - 1;
|
||||
BCOPY(inp, rhostname, len);
|
||||
rhostname[len] = '\000';
|
||||
|
||||
CHAPDEBUG((LOG_INFO, "ChapReceiveResponse: received name field: %s",
|
||||
rhostname));
|
||||
|
||||
/*
|
||||
* Get secret for authenticating them with us,
|
||||
* do the hash ourselves, and compare the result.
|
||||
*/
|
||||
code = CHAP_FAILURE;
|
||||
if (!get_secret(cstate->unit, rhostname, cstate->chal_name,
|
||||
secret, &secret_len, 1)) {
|
||||
syslog(LOG_WARNING, "No CHAP secret found for authenticating %s",
|
||||
rhostname);
|
||||
} else {
|
||||
|
||||
/* generate MD based on negotiated type */
|
||||
switch (cstate->chal_type) {
|
||||
|
||||
case CHAP_DIGEST_MD5: /* only MD5 is defined for now */
|
||||
if (remmd_len != MD5_SIGNATURE_SIZE)
|
||||
break; /* it's not even the right length */
|
||||
MD5Init(&mdContext);
|
||||
MD5Update(&mdContext, &cstate->chal_id, 1);
|
||||
MD5Update(&mdContext, secret, secret_len);
|
||||
MD5Update(&mdContext, cstate->challenge, cstate->chal_len);
|
||||
MD5Final(hash, &mdContext);
|
||||
|
||||
/* compare local and remote MDs and send the appropriate status */
|
||||
if (memcmp (hash, remmd, MD5_SIGNATURE_SIZE) == 0)
|
||||
code = CHAP_SUCCESS; /* they are the same! */
|
||||
break;
|
||||
|
||||
default:
|
||||
CHAPDEBUG((LOG_INFO, "unknown digest type %d", cstate->chal_type));
|
||||
}
|
||||
}
|
||||
|
||||
BZERO(secret, sizeof(secret));
|
||||
ChapSendStatus(cstate, code);
|
||||
|
||||
if (code == CHAP_SUCCESS) {
|
||||
old_state = cstate->serverstate;
|
||||
cstate->serverstate = CHAPSS_OPEN;
|
||||
if (old_state == CHAPSS_INITIAL_CHAL) {
|
||||
auth_peer_success(cstate->unit, PPP_CHAP, rhostname, len);
|
||||
}
|
||||
if (cstate->chal_interval != 0)
|
||||
TIMEOUT(ChapRechallenge, cstate, cstate->chal_interval);
|
||||
syslog(LOG_NOTICE, "CHAP peer authentication succeeded for %s",
|
||||
rhostname);
|
||||
|
||||
} else {
|
||||
syslog(LOG_ERR, "CHAP peer authentication failed for remote host %s",
|
||||
rhostname);
|
||||
cstate->serverstate = CHAPSS_BADAUTH;
|
||||
auth_peer_fail(cstate->unit, PPP_CHAP);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ChapReceiveSuccess - Receive Success
|
||||
*/
|
||||
static void
|
||||
ChapReceiveSuccess(cstate, inp, id, len)
|
||||
chap_state *cstate;
|
||||
u_char *inp;
|
||||
u_char id;
|
||||
int len;
|
||||
{
|
||||
|
||||
CHAPDEBUG((LOG_INFO, "ChapReceiveSuccess: Rcvd id %d.", id));
|
||||
|
||||
if (cstate->clientstate == CHAPCS_OPEN)
|
||||
/* presumably an answer to a duplicate response */
|
||||
return;
|
||||
|
||||
if (cstate->clientstate != CHAPCS_RESPONSE) {
|
||||
/* don't know what this is */
|
||||
CHAPDEBUG((LOG_INFO, "ChapReceiveSuccess: in state %d\n",
|
||||
cstate->clientstate));
|
||||
return;
|
||||
}
|
||||
|
||||
UNTIMEOUT(ChapResponseTimeout, cstate);
|
||||
|
||||
/*
|
||||
* Print message.
|
||||
*/
|
||||
if (len > 0)
|
||||
PRINTMSG(inp, len);
|
||||
|
||||
cstate->clientstate = CHAPCS_OPEN;
|
||||
|
||||
auth_withpeer_success(cstate->unit, PPP_CHAP);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ChapReceiveFailure - Receive failure.
|
||||
*/
|
||||
static void
|
||||
ChapReceiveFailure(cstate, inp, id, len)
|
||||
chap_state *cstate;
|
||||
u_char *inp;
|
||||
u_char id;
|
||||
int len;
|
||||
{
|
||||
CHAPDEBUG((LOG_INFO, "ChapReceiveFailure: Rcvd id %d.", id));
|
||||
|
||||
if (cstate->clientstate != CHAPCS_RESPONSE) {
|
||||
/* don't know what this is */
|
||||
CHAPDEBUG((LOG_INFO, "ChapReceiveFailure: in state %d\n",
|
||||
cstate->clientstate));
|
||||
return;
|
||||
}
|
||||
|
||||
UNTIMEOUT(ChapResponseTimeout, cstate);
|
||||
|
||||
/*
|
||||
* Print message.
|
||||
*/
|
||||
if (len > 0)
|
||||
PRINTMSG(inp, len);
|
||||
|
||||
syslog(LOG_ERR, "CHAP authentication failed");
|
||||
auth_withpeer_fail(cstate->unit, PPP_CHAP);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ChapSendChallenge - Send an Authenticate challenge.
|
||||
*/
|
||||
static void
|
||||
ChapSendChallenge(cstate)
|
||||
chap_state *cstate;
|
||||
{
|
||||
u_char *outp;
|
||||
int chal_len, name_len;
|
||||
int outlen;
|
||||
|
||||
chal_len = cstate->chal_len;
|
||||
name_len = strlen(cstate->chal_name);
|
||||
outlen = CHAP_HEADERLEN + sizeof (u_char) + chal_len + name_len;
|
||||
outp = outpacket_buf;
|
||||
|
||||
MAKEHEADER(outp, PPP_CHAP); /* paste in a CHAP header */
|
||||
|
||||
PUTCHAR(CHAP_CHALLENGE, outp);
|
||||
PUTCHAR(cstate->chal_id, outp);
|
||||
PUTSHORT(outlen, outp);
|
||||
|
||||
PUTCHAR(chal_len, outp); /* put length of challenge */
|
||||
BCOPY(cstate->challenge, outp, chal_len);
|
||||
INCPTR(chal_len, outp);
|
||||
|
||||
BCOPY(cstate->chal_name, outp, name_len); /* append hostname */
|
||||
|
||||
output(cstate->unit, outpacket_buf, outlen + PPP_HDRLEN);
|
||||
|
||||
CHAPDEBUG((LOG_INFO, "ChapSendChallenge: Sent id %d.", cstate->chal_id));
|
||||
|
||||
TIMEOUT(ChapChallengeTimeout, cstate, cstate->timeouttime);
|
||||
++cstate->chal_transmits;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ChapSendStatus - Send a status response (ack or nak).
|
||||
*/
|
||||
static void
|
||||
ChapSendStatus(cstate, code)
|
||||
chap_state *cstate;
|
||||
int code;
|
||||
{
|
||||
u_char *outp;
|
||||
int outlen, msglen;
|
||||
char msg[256];
|
||||
|
||||
if (code == CHAP_SUCCESS)
|
||||
sprintf(msg, "Welcome to %s.", hostname);
|
||||
else
|
||||
sprintf(msg, "I don't like you. Go 'way.");
|
||||
msglen = strlen(msg);
|
||||
|
||||
outlen = CHAP_HEADERLEN + msglen;
|
||||
outp = outpacket_buf;
|
||||
|
||||
MAKEHEADER(outp, PPP_CHAP); /* paste in a header */
|
||||
|
||||
PUTCHAR(code, outp);
|
||||
PUTCHAR(cstate->chal_id, outp);
|
||||
PUTSHORT(outlen, outp);
|
||||
BCOPY(msg, outp, msglen);
|
||||
output(cstate->unit, outpacket_buf, outlen + PPP_HDRLEN);
|
||||
|
||||
CHAPDEBUG((LOG_INFO, "ChapSendStatus: Sent code %d, id %d.", code,
|
||||
cstate->chal_id));
|
||||
}
|
||||
|
||||
/*
|
||||
* ChapGenChallenge is used to generate a pseudo-random challenge string of
|
||||
* a pseudo-random length between min_len and max_len. The challenge
|
||||
* string and its length are stored in *cstate, and various other fields of
|
||||
* *cstate are initialized.
|
||||
*/
|
||||
|
||||
static void
|
||||
ChapGenChallenge(cstate)
|
||||
chap_state *cstate;
|
||||
{
|
||||
int chal_len;
|
||||
u_char *ptr = cstate->challenge;
|
||||
unsigned int i;
|
||||
|
||||
/* pick a random challenge length between MIN_CHALLENGE_LENGTH and
|
||||
MAX_CHALLENGE_LENGTH */
|
||||
chal_len = (unsigned) ((drand48() *
|
||||
(MAX_CHALLENGE_LENGTH - MIN_CHALLENGE_LENGTH)) +
|
||||
MIN_CHALLENGE_LENGTH);
|
||||
cstate->chal_len = chal_len;
|
||||
cstate->chal_id = ++cstate->id;
|
||||
cstate->chal_transmits = 0;
|
||||
|
||||
/* generate a random string */
|
||||
for (i = 0; i < chal_len; i++ )
|
||||
*ptr++ = (char) (drand48() * 0xff);
|
||||
}
|
||||
|
||||
/*
|
||||
* ChapSendResponse - send a response packet with values as specified
|
||||
* in *cstate.
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
static void
|
||||
ChapSendResponse(cstate)
|
||||
chap_state *cstate;
|
||||
{
|
||||
u_char *outp;
|
||||
int outlen, md_len, name_len;
|
||||
|
||||
md_len = cstate->resp_length;
|
||||
name_len = strlen(cstate->resp_name);
|
||||
outlen = CHAP_HEADERLEN + sizeof (u_char) + md_len + name_len;
|
||||
outp = outpacket_buf;
|
||||
|
||||
MAKEHEADER(outp, PPP_CHAP);
|
||||
|
||||
PUTCHAR(CHAP_RESPONSE, outp); /* we are a response */
|
||||
PUTCHAR(cstate->resp_id, outp); /* copy id from challenge packet */
|
||||
PUTSHORT(outlen, outp); /* packet length */
|
||||
|
||||
PUTCHAR(md_len, outp); /* length of MD */
|
||||
BCOPY(cstate->response, outp, md_len); /* copy MD to buffer */
|
||||
INCPTR(md_len, outp);
|
||||
|
||||
BCOPY(cstate->resp_name, outp, name_len); /* append our name */
|
||||
|
||||
/* send the packet */
|
||||
output(cstate->unit, outpacket_buf, outlen + PPP_HDRLEN);
|
||||
|
||||
cstate->clientstate = CHAPCS_RESPONSE;
|
||||
TIMEOUT(ChapResponseTimeout, cstate, cstate->timeouttime);
|
||||
++cstate->resp_transmits;
|
||||
}
|
||||
|
||||
/*
|
||||
* ChapPrintPkt - print the contents of a CHAP packet.
|
||||
*/
|
||||
static char *ChapCodenames[] = {
|
||||
"Challenge", "Response", "Success", "Failure"
|
||||
};
|
||||
|
||||
static int
|
||||
ChapPrintPkt(p, plen, printer, arg)
|
||||
u_char *p;
|
||||
int plen;
|
||||
void (*printer)(void *, char *, ...);
|
||||
void *arg;
|
||||
{
|
||||
int code, id, len;
|
||||
int clen, nlen;
|
||||
u_char x;
|
||||
|
||||
if (plen < CHAP_HEADERLEN)
|
||||
return 0;
|
||||
GETCHAR(code, p);
|
||||
GETCHAR(id, p);
|
||||
GETSHORT(len, p);
|
||||
if (len < CHAP_HEADERLEN || len > plen)
|
||||
return 0;
|
||||
|
||||
if (code >= 1 && code <= sizeof(ChapCodenames) / sizeof(char *))
|
||||
printer(arg, " %s", ChapCodenames[code-1]);
|
||||
else
|
||||
printer(arg, " code=0x%x", code);
|
||||
printer(arg, " id=0x%x", id);
|
||||
len -= CHAP_HEADERLEN;
|
||||
switch (code) {
|
||||
case CHAP_CHALLENGE:
|
||||
case CHAP_RESPONSE:
|
||||
if (len < 1)
|
||||
break;
|
||||
clen = p[0];
|
||||
if (len < clen + 1)
|
||||
break;
|
||||
++p;
|
||||
nlen = len - clen - 1;
|
||||
printer(arg, " <");
|
||||
for (; clen > 0; --clen) {
|
||||
GETCHAR(x, p);
|
||||
printer(arg, "%.2x", x);
|
||||
}
|
||||
printer(arg, ">, name = ");
|
||||
print_string((char *)p, nlen, printer, arg);
|
||||
break;
|
||||
case CHAP_FAILURE:
|
||||
case CHAP_SUCCESS:
|
||||
printer(arg, " ");
|
||||
print_string((char *)p, len, printer, arg);
|
||||
break;
|
||||
default:
|
||||
for (clen = len; clen > 0; --clen) {
|
||||
GETCHAR(x, p);
|
||||
printer(arg, " %.2x", x);
|
||||
}
|
||||
}
|
||||
|
||||
return len + CHAP_HEADERLEN;
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
/*
|
||||
* chap.h - Challenge Handshake Authentication Protocol definitions.
|
||||
*
|
||||
* Copyright (c) 1993 The Australian National University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the Australian National University. The name of the University
|
||||
* may not be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* Copyright (c) 1991 Gregory M. Christy
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the author.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef __CHAP_INCLUDE__
|
||||
|
||||
/* Code + ID + length */
|
||||
#define CHAP_HEADERLEN 4
|
||||
|
||||
/*
|
||||
* CHAP codes.
|
||||
*/
|
||||
|
||||
#define CHAP_DIGEST_MD5 5 /* use MD5 algorithm */
|
||||
#define MD5_SIGNATURE_SIZE 16 /* 16 bytes in a MD5 message digest */
|
||||
#define CHAP_MICROSOFT 0x80 /* use Microsoft-compatible alg. */
|
||||
#define MS_CHAP_RESPONSE_LEN 49 /* Response length for MS-CHAP */
|
||||
|
||||
#define CHAP_CHALLENGE 1
|
||||
#define CHAP_RESPONSE 2
|
||||
#define CHAP_SUCCESS 3
|
||||
#define CHAP_FAILURE 4
|
||||
|
||||
/*
|
||||
* Challenge lengths (for challenges we send) and other limits.
|
||||
*/
|
||||
#define MIN_CHALLENGE_LENGTH 32
|
||||
#define MAX_CHALLENGE_LENGTH 64
|
||||
#define MAX_RESPONSE_LENGTH 64 /* sufficient for MD5 or MS-CHAP */
|
||||
|
||||
/*
|
||||
* Each interface is described by a chap structure.
|
||||
*/
|
||||
|
||||
typedef struct chap_state {
|
||||
int unit; /* Interface unit number */
|
||||
int clientstate; /* Client state */
|
||||
int serverstate; /* Server state */
|
||||
u_char challenge[MAX_CHALLENGE_LENGTH]; /* last challenge string sent */
|
||||
u_char chal_len; /* challenge length */
|
||||
u_char chal_id; /* ID of last challenge */
|
||||
u_char chal_type; /* hash algorithm for challenges */
|
||||
u_char id; /* Current id */
|
||||
char *chal_name; /* Our name to use with challenge */
|
||||
int chal_interval; /* Time until we challenge peer again */
|
||||
int timeouttime; /* Timeout time in seconds */
|
||||
int max_transmits; /* Maximum # of challenge transmissions */
|
||||
int chal_transmits; /* Number of transmissions of challenge */
|
||||
int resp_transmits; /* Number of transmissions of response */
|
||||
u_char response[MAX_RESPONSE_LENGTH]; /* Response to send */
|
||||
u_char resp_length; /* length of response */
|
||||
u_char resp_id; /* ID for response messages */
|
||||
u_char resp_type; /* hash algorithm for responses */
|
||||
char *resp_name; /* Our name to send with response */
|
||||
} chap_state;
|
||||
|
||||
|
||||
/*
|
||||
* Client (peer) states.
|
||||
*/
|
||||
#define CHAPCS_INITIAL 0 /* Lower layer down, not opened */
|
||||
#define CHAPCS_CLOSED 1 /* Lower layer up, not opened */
|
||||
#define CHAPCS_PENDING 2 /* Auth us to peer when lower up */
|
||||
#define CHAPCS_LISTEN 3 /* Listening for a challenge */
|
||||
#define CHAPCS_RESPONSE 4 /* Sent response, waiting for status */
|
||||
#define CHAPCS_OPEN 5 /* We've received Success */
|
||||
|
||||
/*
|
||||
* Server (authenticator) states.
|
||||
*/
|
||||
#define CHAPSS_INITIAL 0 /* Lower layer down, not opened */
|
||||
#define CHAPSS_CLOSED 1 /* Lower layer up, not opened */
|
||||
#define CHAPSS_PENDING 2 /* Auth peer when lower up */
|
||||
#define CHAPSS_INITIAL_CHAL 3 /* We've sent the first challenge */
|
||||
#define CHAPSS_OPEN 4 /* We've sent a Success msg */
|
||||
#define CHAPSS_RECHALLENGE 5 /* We've sent another challenge */
|
||||
#define CHAPSS_BADAUTH 6 /* We've sent a Failure msg */
|
||||
|
||||
/*
|
||||
* Timeouts.
|
||||
*/
|
||||
#define CHAP_DEFTIMEOUT 3 /* Timeout time in seconds */
|
||||
#define CHAP_DEFTRANSMITS 10 /* max # times to send challenge */
|
||||
|
||||
extern chap_state chap[];
|
||||
|
||||
void ChapAuthWithPeer(int, char *, int);
|
||||
void ChapAuthPeer(int, char *, int);
|
||||
|
||||
extern struct protent chap_protent;
|
||||
|
||||
#define __CHAP_INCLUDE__
|
||||
#endif /* __CHAP_INCLUDE__ */
|
@ -1,335 +0,0 @@
|
||||
/*
|
||||
* chap_ms.c - Microsoft MS-CHAP compatible implementation.
|
||||
*
|
||||
* Copyright (c) 1995 Eric Rosenquist, Strata Software Limited.
|
||||
* http://www.strataware.com/
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Eric Rosenquist. The name of the author may not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modifications by Lauri Pesonen / lpesonen@clinet.fi, april 1997
|
||||
*
|
||||
* Implemented LANManager type password response to MS-CHAP challenges.
|
||||
* Now pppd provides both NT style and LANMan style blocks, and the
|
||||
* prefered is set by option "ms-lanman". Default is to use NT.
|
||||
* The hash text (StdText) was taken from Win95 RASAPI32.DLL.
|
||||
*
|
||||
* You should also use DOMAIN\\USERNAME as described in README.MSCHAP80
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] = "$FreeBSD$";
|
||||
#endif
|
||||
|
||||
#ifdef CHAPMS
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_CRYPT_H
|
||||
#include <crypt.h>
|
||||
#endif
|
||||
|
||||
#include "pppd.h"
|
||||
#include "chap.h"
|
||||
#include "chap_ms.h"
|
||||
#include "md4.h"
|
||||
|
||||
#ifndef USE_CRYPT
|
||||
#include <openssl/des.h>
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
u_char LANManResp[24];
|
||||
u_char NTResp[24];
|
||||
u_char UseNT; /* If 1, ignore the LANMan response field */
|
||||
} MS_ChapResponse;
|
||||
/* We use MS_CHAP_RESPONSE_LEN, rather than sizeof(MS_ChapResponse),
|
||||
in case this struct gets padded. */
|
||||
|
||||
|
||||
static void ChallengeResponse(u_char *, u_char *, u_char *);
|
||||
static void DesEncrypt(u_char *, u_char *, u_char *);
|
||||
static void MakeKey(u_char *, u_char *);
|
||||
static u_char Get7Bits(u_char *, int);
|
||||
static void ChapMS_NT(char *, int, char *, int, MS_ChapResponse *);
|
||||
#ifdef MSLANMAN
|
||||
static void ChapMS_LANMan(char *, int, char *, int, MS_ChapResponse *);
|
||||
#endif
|
||||
|
||||
#ifdef USE_CRYPT
|
||||
static void Expand(u_char *, u_char *);
|
||||
static void Collapse(u_char *, u_char *);
|
||||
#endif
|
||||
|
||||
static void
|
||||
ChallengeResponse(challenge, pwHash, response)
|
||||
u_char *challenge; /* IN 8 octets */
|
||||
u_char *pwHash; /* IN 16 octets */
|
||||
u_char *response; /* OUT 24 octets */
|
||||
{
|
||||
char ZPasswordHash[21];
|
||||
|
||||
BZERO(ZPasswordHash, sizeof(ZPasswordHash));
|
||||
BCOPY(pwHash, ZPasswordHash, MD4_SIGNATURE_SIZE);
|
||||
|
||||
#if 0
|
||||
log_packet(ZPasswordHash, sizeof(ZPasswordHash), "ChallengeResponse - ZPasswordHash", LOG_DEBUG);
|
||||
#endif
|
||||
|
||||
DesEncrypt(challenge, ZPasswordHash + 0, response + 0);
|
||||
DesEncrypt(challenge, ZPasswordHash + 7, response + 8);
|
||||
DesEncrypt(challenge, ZPasswordHash + 14, response + 16);
|
||||
|
||||
#if 0
|
||||
log_packet(response, 24, "ChallengeResponse - response", LOG_DEBUG);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_CRYPT
|
||||
static void
|
||||
DesEncrypt(clear, key, cipher)
|
||||
u_char *clear; /* IN 8 octets */
|
||||
u_char *key; /* IN 7 octets */
|
||||
u_char *cipher; /* OUT 8 octets */
|
||||
{
|
||||
u_char des_key[8];
|
||||
u_char crypt_key[66];
|
||||
u_char des_input[66];
|
||||
|
||||
MakeKey(key, des_key);
|
||||
|
||||
Expand(des_key, crypt_key);
|
||||
setkey(crypt_key);
|
||||
|
||||
#if 0
|
||||
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X",
|
||||
clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
|
||||
#endif
|
||||
|
||||
Expand(clear, des_input);
|
||||
encrypt(des_input, 0);
|
||||
Collapse(des_input, cipher);
|
||||
|
||||
#if 0
|
||||
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X",
|
||||
cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
|
||||
#endif
|
||||
}
|
||||
|
||||
#else /* USE_CRYPT */
|
||||
|
||||
static void
|
||||
DesEncrypt(clear, key, cipher)
|
||||
u_char *clear; /* IN 8 octets */
|
||||
u_char *key; /* IN 7 octets */
|
||||
u_char *cipher; /* OUT 8 octets */
|
||||
{
|
||||
des_cblock des_key;
|
||||
des_key_schedule key_schedule;
|
||||
|
||||
MakeKey(key, des_key);
|
||||
|
||||
des_set_key(&des_key, key_schedule);
|
||||
|
||||
#if 0
|
||||
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X",
|
||||
clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
|
||||
#endif
|
||||
|
||||
des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher, key_schedule, 1);
|
||||
|
||||
#if 0
|
||||
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X",
|
||||
cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* USE_CRYPT */
|
||||
|
||||
|
||||
static u_char Get7Bits(input, startBit)
|
||||
u_char *input;
|
||||
int startBit;
|
||||
{
|
||||
register unsigned int word;
|
||||
|
||||
word = (unsigned)input[startBit / 8] << 8;
|
||||
word |= (unsigned)input[startBit / 8 + 1];
|
||||
|
||||
word >>= 15 - (startBit % 8 + 7);
|
||||
|
||||
return word & 0xFE;
|
||||
}
|
||||
|
||||
#ifdef USE_CRYPT
|
||||
|
||||
/* in == 8-byte string (expanded version of the 56-bit key)
|
||||
* out == 64-byte string where each byte is either 1 or 0
|
||||
* Note that the low-order "bit" is always ignored by by setkey()
|
||||
*/
|
||||
static void Expand(in, out)
|
||||
u_char *in;
|
||||
u_char *out;
|
||||
{
|
||||
int j, c;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 64; in++){
|
||||
c = *in;
|
||||
for(j = 7; j >= 0; j--)
|
||||
*out++ = (c >> j) & 01;
|
||||
i += 8;
|
||||
}
|
||||
}
|
||||
|
||||
/* The inverse of Expand
|
||||
*/
|
||||
static void Collapse(in, out)
|
||||
u_char *in;
|
||||
u_char *out;
|
||||
{
|
||||
int j;
|
||||
int i;
|
||||
unsigned int c;
|
||||
|
||||
for (i = 0; i < 64; i += 8, out++) {
|
||||
c = 0;
|
||||
for (j = 7; j >= 0; j--, in++)
|
||||
c |= *in << j;
|
||||
*out = c & 0xff;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void MakeKey(key, des_key)
|
||||
u_char *key; /* IN 56 bit DES key missing parity bits */
|
||||
u_char *des_key; /* OUT 64 bit DES key with parity bits added */
|
||||
{
|
||||
des_key[0] = Get7Bits(key, 0);
|
||||
des_key[1] = Get7Bits(key, 7);
|
||||
des_key[2] = Get7Bits(key, 14);
|
||||
des_key[3] = Get7Bits(key, 21);
|
||||
des_key[4] = Get7Bits(key, 28);
|
||||
des_key[5] = Get7Bits(key, 35);
|
||||
des_key[6] = Get7Bits(key, 42);
|
||||
des_key[7] = Get7Bits(key, 49);
|
||||
|
||||
#ifndef USE_CRYPT
|
||||
des_set_odd_parity((des_cblock *)des_key);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
CHAPDEBUG((LOG_INFO, "MakeKey: 56-bit input : %02X%02X%02X%02X%02X%02X%02X",
|
||||
key[0], key[1], key[2], key[3], key[4], key[5], key[6]));
|
||||
CHAPDEBUG((LOG_INFO, "MakeKey: 64-bit output: %02X%02X%02X%02X%02X%02X%02X%02X",
|
||||
des_key[0], des_key[1], des_key[2], des_key[3], des_key[4], des_key[5], des_key[6], des_key[7]));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
ChapMS_NT(rchallenge, rchallenge_len, secret, secret_len, response)
|
||||
char *rchallenge;
|
||||
int rchallenge_len;
|
||||
char *secret;
|
||||
int secret_len;
|
||||
MS_ChapResponse *response;
|
||||
{
|
||||
int i;
|
||||
MD4_CTX md4Context;
|
||||
u_char hash[MD4_SIGNATURE_SIZE];
|
||||
u_char unicodePassword[MAX_NT_PASSWORD * 2];
|
||||
|
||||
/* Initialize the Unicode version of the secret (== password). */
|
||||
/* This implicitly supports 8-bit ISO8859/1 characters. */
|
||||
BZERO(unicodePassword, sizeof(unicodePassword));
|
||||
for (i = 0; i < secret_len; i++)
|
||||
unicodePassword[i * 2] = (u_char)secret[i];
|
||||
|
||||
MD4Init(&md4Context);
|
||||
MD4Update(&md4Context, unicodePassword, secret_len * 2); /* Unicode is 2 bytes/char */
|
||||
|
||||
MD4Final(hash, &md4Context); /* Tell MD4 we're done */
|
||||
|
||||
ChallengeResponse(rchallenge, hash, response->NTResp);
|
||||
}
|
||||
|
||||
#ifdef MSLANMAN
|
||||
static u_char *StdText = (u_char *)"KGS!@#$%"; /* key from rasapi32.dll */
|
||||
|
||||
static void
|
||||
ChapMS_LANMan(rchallenge, rchallenge_len, secret, secret_len, response)
|
||||
char *rchallenge;
|
||||
int rchallenge_len;
|
||||
char *secret;
|
||||
int secret_len;
|
||||
MS_ChapResponse *response;
|
||||
{
|
||||
int i;
|
||||
u_char UcasePassword[MAX_NT_PASSWORD]; /* max is actually 14 */
|
||||
u_char PasswordHash[MD4_SIGNATURE_SIZE];
|
||||
|
||||
/* LANMan password is case insensitive */
|
||||
BZERO(UcasePassword, sizeof(UcasePassword));
|
||||
for (i = 0; i < secret_len; i++)
|
||||
UcasePassword[i] = (u_char)toupper(secret[i]);
|
||||
DesEncrypt( StdText, UcasePassword + 0, PasswordHash + 0 );
|
||||
DesEncrypt( StdText, UcasePassword + 7, PasswordHash + 8 );
|
||||
ChallengeResponse(rchallenge, PasswordHash, response->LANManResp);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
ChapMS(cstate, rchallenge, rchallenge_len, secret, secret_len)
|
||||
chap_state *cstate;
|
||||
char *rchallenge;
|
||||
int rchallenge_len;
|
||||
char *secret;
|
||||
int secret_len;
|
||||
{
|
||||
MS_ChapResponse response;
|
||||
#ifdef MSLANMAN
|
||||
extern int ms_lanman;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
CHAPDEBUG((LOG_INFO, "ChapMS: secret is '%.*s'", secret_len, secret));
|
||||
#endif
|
||||
BZERO(&response, sizeof(response));
|
||||
|
||||
/* Calculate both always */
|
||||
ChapMS_NT(rchallenge, rchallenge_len, secret, secret_len, &response);
|
||||
|
||||
#ifdef MSLANMAN
|
||||
ChapMS_LANMan(rchallenge, rchallenge_len, secret, secret_len, &response);
|
||||
|
||||
/* prefered method is set by option */
|
||||
response.UseNT = !ms_lanman;
|
||||
#else
|
||||
response.UseNT = 1;
|
||||
#endif
|
||||
|
||||
BCOPY(&response, cstate->response, MS_CHAP_RESPONSE_LEN);
|
||||
cstate->resp_length = MS_CHAP_RESPONSE_LEN;
|
||||
}
|
||||
|
||||
#endif /* CHAPMS */
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* chap.h - Challenge Handshake Authentication Protocol definitions.
|
||||
*
|
||||
* Copyright (c) 1995 Eric Rosenquist, Strata Software Limited.
|
||||
* http://www.strataware.com/
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Eric Rosenquist. The name of the author may not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef __CHAPMS_INCLUDE__
|
||||
|
||||
#define MD4_SIGNATURE_SIZE 16 /* 16 bytes in a MD4 message digest */
|
||||
#define MAX_NT_PASSWORD 256 /* Maximum number of (Unicode) chars in an NT password */
|
||||
|
||||
void ChapMS(chap_state *, char *, int, char *, int);
|
||||
|
||||
#define __CHAPMS_INCLUDE__
|
||||
#endif /* __CHAPMS_INCLUDE__ */
|
@ -1,348 +0,0 @@
|
||||
/*
|
||||
* demand.c - Support routines for demand-dialling.
|
||||
*
|
||||
* Copyright (c) 1993 The Australian National University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the Australian National University. The name of the University
|
||||
* may not be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] = "$FreeBSD$";
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <syslog.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef PPP_FILTER
|
||||
#include <net/if.h>
|
||||
#include <net/bpf.h>
|
||||
#include <pcap.h>
|
||||
#endif
|
||||
|
||||
#include "pppd.h"
|
||||
#include "fsm.h"
|
||||
#include "ipcp.h"
|
||||
#include "lcp.h"
|
||||
|
||||
char *frame;
|
||||
int framelen;
|
||||
int framemax;
|
||||
int escape_flag;
|
||||
int flush_flag;
|
||||
int fcs;
|
||||
|
||||
struct packet {
|
||||
int length;
|
||||
struct packet *next;
|
||||
unsigned char data[1];
|
||||
};
|
||||
|
||||
struct packet *pend_q;
|
||||
struct packet *pend_qtail;
|
||||
|
||||
static int active_packet(unsigned char *, int);
|
||||
|
||||
/*
|
||||
* demand_conf - configure the interface for doing dial-on-demand.
|
||||
*/
|
||||
void
|
||||
demand_conf()
|
||||
{
|
||||
int i;
|
||||
struct protent *protp;
|
||||
|
||||
/* framemax = lcp_allowoptions[0].mru;
|
||||
if (framemax < PPP_MRU) */
|
||||
framemax = PPP_MRU;
|
||||
framemax += PPP_HDRLEN + PPP_FCSLEN;
|
||||
frame = malloc(framemax);
|
||||
if (frame == NULL)
|
||||
novm("demand frame");
|
||||
framelen = 0;
|
||||
pend_q = NULL;
|
||||
escape_flag = 0;
|
||||
flush_flag = 0;
|
||||
fcs = PPP_INITFCS;
|
||||
|
||||
ppp_send_config(0, PPP_MRU, (u_int32_t) 0, 0, 0);
|
||||
ppp_recv_config(0, PPP_MRU, (u_int32_t) 0, 0, 0);
|
||||
|
||||
#ifdef PPP_FILTER
|
||||
set_filters(&pass_filter, &active_filter);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Call the demand_conf procedure for each protocol that's got one.
|
||||
*/
|
||||
for (i = 0; (protp = protocols[i]) != NULL; ++i)
|
||||
if (protp->enabled_flag && protp->demand_conf != NULL)
|
||||
if (!((*protp->demand_conf)(0)))
|
||||
die(1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* demand_block - set each network protocol to block further packets.
|
||||
*/
|
||||
void
|
||||
demand_block()
|
||||
{
|
||||
int i;
|
||||
struct protent *protp;
|
||||
|
||||
for (i = 0; (protp = protocols[i]) != NULL; ++i)
|
||||
if (protp->enabled_flag && protp->demand_conf != NULL)
|
||||
sifnpmode(0, protp->protocol & ~0x8000, NPMODE_QUEUE);
|
||||
get_loop_output();
|
||||
}
|
||||
|
||||
/*
|
||||
* demand_discard - set each network protocol to discard packets
|
||||
* with an error.
|
||||
*/
|
||||
void
|
||||
demand_discard()
|
||||
{
|
||||
struct packet *pkt, *nextpkt;
|
||||
int i;
|
||||
struct protent *protp;
|
||||
|
||||
for (i = 0; (protp = protocols[i]) != NULL; ++i)
|
||||
if (protp->enabled_flag && protp->demand_conf != NULL)
|
||||
sifnpmode(0, protp->protocol & ~0x8000, NPMODE_ERROR);
|
||||
get_loop_output();
|
||||
|
||||
/* discard all saved packets */
|
||||
for (pkt = pend_q; pkt != NULL; pkt = nextpkt) {
|
||||
nextpkt = pkt->next;
|
||||
free(pkt);
|
||||
}
|
||||
pend_q = NULL;
|
||||
framelen = 0;
|
||||
flush_flag = 0;
|
||||
escape_flag = 0;
|
||||
fcs = PPP_INITFCS;
|
||||
}
|
||||
|
||||
/*
|
||||
* demand_unblock - set each enabled network protocol to pass packets.
|
||||
*/
|
||||
void
|
||||
demand_unblock()
|
||||
{
|
||||
int i;
|
||||
struct protent *protp;
|
||||
|
||||
for (i = 0; (protp = protocols[i]) != NULL; ++i)
|
||||
if (protp->enabled_flag && protp->demand_conf != NULL)
|
||||
sifnpmode(0, protp->protocol & ~0x8000, NPMODE_PASS);
|
||||
}
|
||||
|
||||
/*
|
||||
* FCS lookup table as calculated by genfcstab.
|
||||
*/
|
||||
static u_short fcstab[256] = {
|
||||
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
|
||||
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
|
||||
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
|
||||
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
|
||||
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
|
||||
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
|
||||
0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
|
||||
0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
|
||||
0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
|
||||
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
|
||||
0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
|
||||
0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
|
||||
0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
|
||||
0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
|
||||
0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
|
||||
0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
|
||||
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
|
||||
0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
|
||||
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
|
||||
0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
|
||||
0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
|
||||
0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
|
||||
0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
|
||||
0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
|
||||
0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
|
||||
0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
|
||||
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
|
||||
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
|
||||
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
|
||||
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
|
||||
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
|
||||
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
|
||||
};
|
||||
|
||||
/*
|
||||
* loop_chars - process characters received from the loopback.
|
||||
* Calls loop_frame when a complete frame has been accumulated.
|
||||
* Return value is 1 if we need to bring up the link, 0 otherwise.
|
||||
*/
|
||||
int
|
||||
loop_chars(p, n)
|
||||
unsigned char *p;
|
||||
int n;
|
||||
{
|
||||
int c, rv;
|
||||
|
||||
rv = 0;
|
||||
for (; n > 0; --n) {
|
||||
c = *p++;
|
||||
if (c == PPP_FLAG) {
|
||||
if (!escape_flag && !flush_flag
|
||||
&& framelen > 2 && fcs == PPP_GOODFCS) {
|
||||
framelen -= 2;
|
||||
if (loop_frame(frame, framelen))
|
||||
rv = 1;
|
||||
}
|
||||
framelen = 0;
|
||||
flush_flag = 0;
|
||||
escape_flag = 0;
|
||||
fcs = PPP_INITFCS;
|
||||
continue;
|
||||
}
|
||||
if (flush_flag)
|
||||
continue;
|
||||
if (escape_flag) {
|
||||
c ^= PPP_TRANS;
|
||||
escape_flag = 0;
|
||||
} else if (c == PPP_ESCAPE) {
|
||||
escape_flag = 1;
|
||||
continue;
|
||||
}
|
||||
if (framelen >= framemax) {
|
||||
flush_flag = 1;
|
||||
continue;
|
||||
}
|
||||
frame[framelen++] = c;
|
||||
fcs = PPP_FCS(fcs, c);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* loop_frame - given a frame obtained from the loopback,
|
||||
* decide whether to bring up the link or not, and, if we want
|
||||
* to transmit this frame later, put it on the pending queue.
|
||||
* Return value is 1 if we need to bring up the link, 0 otherwise.
|
||||
* We assume that the kernel driver has already applied the
|
||||
* pass_filter, so we won't get packets it rejected.
|
||||
* We apply the active_filter to see if we want this packet to
|
||||
* bring up the link.
|
||||
*/
|
||||
int
|
||||
loop_frame(frame, len)
|
||||
unsigned char *frame;
|
||||
int len;
|
||||
{
|
||||
struct packet *pkt;
|
||||
|
||||
/* log_packet(frame, len, "from loop: ", LOG_DEBUG); */
|
||||
if (len < PPP_HDRLEN)
|
||||
return 0;
|
||||
if ((PPP_PROTOCOL(frame) & 0x8000) != 0)
|
||||
return 0; /* shouldn't get any of these anyway */
|
||||
if (!active_packet(frame, len))
|
||||
return 0;
|
||||
|
||||
pkt = (struct packet *) malloc(sizeof(struct packet) + len);
|
||||
if (pkt != NULL) {
|
||||
pkt->length = len;
|
||||
pkt->next = NULL;
|
||||
memcpy(pkt->data, frame, len);
|
||||
if (pend_q == NULL)
|
||||
pend_q = pkt;
|
||||
else
|
||||
pend_qtail->next = pkt;
|
||||
pend_qtail = pkt;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* demand_rexmit - Resend all those frames which we got via the
|
||||
* loopback, now that the real serial link is up.
|
||||
*/
|
||||
void
|
||||
demand_rexmit(proto)
|
||||
int proto;
|
||||
{
|
||||
struct packet *pkt, *prev, *nextpkt;
|
||||
|
||||
prev = NULL;
|
||||
pkt = pend_q;
|
||||
pend_q = NULL;
|
||||
for (; pkt != NULL; pkt = nextpkt) {
|
||||
nextpkt = pkt->next;
|
||||
if (PPP_PROTOCOL(pkt->data) == proto) {
|
||||
output(0, pkt->data, pkt->length);
|
||||
free(pkt);
|
||||
} else {
|
||||
if (prev == NULL)
|
||||
pend_q = pkt;
|
||||
else
|
||||
prev->next = pkt;
|
||||
prev = pkt;
|
||||
}
|
||||
}
|
||||
pend_qtail = prev;
|
||||
if (prev != NULL)
|
||||
prev->next = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Scan a packet to decide whether it is an "active" packet,
|
||||
* that is, whether it is worth bringing up the link for.
|
||||
*/
|
||||
static int
|
||||
active_packet(p, len)
|
||||
unsigned char *p;
|
||||
int len;
|
||||
{
|
||||
int proto, i;
|
||||
struct protent *protp;
|
||||
|
||||
if (len < PPP_HDRLEN)
|
||||
return 0;
|
||||
proto = PPP_PROTOCOL(p);
|
||||
#ifdef PPP_FILTER
|
||||
if (active_filter.bf_len != 0
|
||||
&& bpf_filter(active_filter.bf_insns, frame, len, len) == 0)
|
||||
return 0;
|
||||
#endif
|
||||
for (i = 0; (protp = protocols[i]) != NULL; ++i) {
|
||||
if (protp->protocol < 0xC000 && (protp->protocol & ~0x8000) == proto) {
|
||||
if (!protp->enabled_flag)
|
||||
return 0;
|
||||
if (protp->active_pkt == NULL)
|
||||
return 1;
|
||||
return (*protp->active_pkt)(p, len);
|
||||
}
|
||||
}
|
||||
return 0; /* not a supported protocol !!?? */
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
eui64.c - EUI64 routines for IPv6CP.
|
||||
Copyright (C) 1999 Tommi Komulainen <Tommi.Komulainen@iki.fi>
|
||||
|
||||
Redistribution and use in source and binary forms are permitted
|
||||
provided that the above copyright notice and this paragraph are
|
||||
duplicated in all such forms and that any documentation,
|
||||
advertising materials, and other materials related to such
|
||||
distribution and use acknowledge that the software was developed
|
||||
by Tommi Komulainen. The name of the author may not be used
|
||||
to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
|
||||
$Id: eui64.c,v 1.3 1999/08/25 04:15:51 paulus Exp $
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#define RCSID "$Id: eui64.c,v 1.3 1999/08/25 04:15:51 paulus Exp $"
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "pppd.h"
|
||||
|
||||
#ifdef RCSID
|
||||
static const char rcsid[] = RCSID;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* eui64_ntoa - Make an ascii representation of an interface identifier
|
||||
*/
|
||||
char *
|
||||
eui64_ntoa(e)
|
||||
eui64_t e;
|
||||
{
|
||||
static char buf[32];
|
||||
|
||||
snprintf(buf, 32, "%02x%02x:%02x%02x:%02x%02x:%02x%02x",
|
||||
e.e8[0], e.e8[1], e.e8[2], e.e8[3],
|
||||
e.e8[4], e.e8[5], e.e8[6], e.e8[7]);
|
||||
return buf;
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
/* $FreeBSD$ */
|
||||
/*
|
||||
eui64.h - EUI64 routines for IPv6CP.
|
||||
Copyright (C) 1999 Tommi Komulainen <Tommi.Komulainen@iki.fi>
|
||||
|
||||
Redistribution and use in source and binary forms are permitted
|
||||
provided that the above copyright notice and this paragraph are
|
||||
duplicated in all such forms and that any documentation,
|
||||
advertising materials, and other materials related to such
|
||||
distribution and use acknowledge that the software was developed
|
||||
by Tommi Komulainen. The name of the author may not be used
|
||||
to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
|
||||
$Id: eui64.h,v 1.3 1999/09/30 19:56:37 masputra Exp $
|
||||
*/
|
||||
|
||||
#ifndef __EUI64_H__
|
||||
#define __EUI64_H__
|
||||
|
||||
#if !defined(INET6)
|
||||
#error "this file should only be included when INET6 is defined"
|
||||
#endif /* not defined(INET6) */
|
||||
|
||||
#if defined(SOL2)
|
||||
#include <netinet/in.h>
|
||||
|
||||
typedef union {
|
||||
uint8_t e8[8]; /* lower 64-bit IPv6 address */
|
||||
uint32_t e32[2]; /* lower 64-bit IPv6 address */
|
||||
} eui64_t;
|
||||
|
||||
/*
|
||||
* Declare the two below, since in.h only defines them when _KERNEL
|
||||
* is declared - which shouldn't be true when dealing with user-land programs
|
||||
*/
|
||||
#define s6_addr8 _S6_un._S6_u8
|
||||
#define s6_addr32 _S6_un._S6_u32
|
||||
|
||||
#else /* else if not defined(SOL2) */
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
*
|
||||
* Maybe this should be done by processing struct in6_addr directly...
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
u_int8_t e8[8];
|
||||
u_int16_t e16[4];
|
||||
u_int32_t e32[2];
|
||||
} eui64_t;
|
||||
|
||||
#endif /* defined(SOL2) */
|
||||
|
||||
#define eui64_iszero(e) (((e).e32[0] | (e).e32[1]) == 0)
|
||||
#define eui64_equals(e, o) (((e).e32[0] == (o).e32[0]) && \
|
||||
((e).e32[1] == (o).e32[1]))
|
||||
#define eui64_zero(e) (e).e32[0] = (e).e32[1] = 0;
|
||||
|
||||
#define eui64_copy(s, d) memcpy(&(d), &(s), sizeof(eui64_t))
|
||||
|
||||
#define eui64_magic(e) do { \
|
||||
(e).e32[0] = magic(); \
|
||||
(e).e32[1] = magic(); \
|
||||
(e).e8[0] &= ~2; \
|
||||
} while (0)
|
||||
#define eui64_magic_nz(x) do { \
|
||||
eui64_magic(x); \
|
||||
} while (eui64_iszero(x))
|
||||
#define eui64_magic_ne(x, y) do { \
|
||||
eui64_magic(x); \
|
||||
} while (eui64_equals(x, y))
|
||||
|
||||
#define eui64_get(ll, cp) do { \
|
||||
eui64_copy((*cp), (ll)); \
|
||||
(cp) += sizeof(eui64_t); \
|
||||
} while (0)
|
||||
|
||||
#define eui64_put(ll, cp) do { \
|
||||
eui64_copy((ll), (*cp)); \
|
||||
(cp) += sizeof(eui64_t); \
|
||||
} while (0)
|
||||
|
||||
#define eui64_set32(e, l) do { \
|
||||
(e).e32[0] = 0; \
|
||||
(e).e32[1] = htonl(l); \
|
||||
} while (0)
|
||||
#define eui64_setlo32(e, l) eui64_set32(e, l)
|
||||
|
||||
char *eui64_ntoa(eui64_t); /* Returns ascii representation of id */
|
||||
|
||||
#endif /* __EUI64_H__ */
|
||||
|
@ -1,798 +0,0 @@
|
||||
/*
|
||||
* fsm.c - {Link, IP} Control Protocol Finite State Machine.
|
||||
*
|
||||
* Copyright (c) 1989 Carnegie Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Carnegie Mellon University. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] = "$FreeBSD$";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* Randomize fsm id on link/init.
|
||||
* Deal with variable outgoing MTU.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "pppd.h"
|
||||
#include "fsm.h"
|
||||
|
||||
static void fsm_timeout(void *);
|
||||
static void fsm_rconfreq(fsm *, int, u_char *, int);
|
||||
static void fsm_rconfack(fsm *, int, u_char *, int);
|
||||
static void fsm_rconfnakrej(fsm *, int, int, u_char *, int);
|
||||
static void fsm_rtermreq(fsm *, int, u_char *, int);
|
||||
static void fsm_rtermack(fsm *);
|
||||
static void fsm_rcoderej(fsm *, u_char *, int);
|
||||
static void fsm_sconfreq(fsm *, int);
|
||||
|
||||
#define PROTO_NAME(f) ((f)->callbacks->proto_name)
|
||||
|
||||
int peer_mru[NUM_PPP];
|
||||
|
||||
|
||||
/*
|
||||
* fsm_init - Initialize fsm.
|
||||
*
|
||||
* Initialize fsm state.
|
||||
*/
|
||||
void
|
||||
fsm_init(f)
|
||||
fsm *f;
|
||||
{
|
||||
f->state = INITIAL;
|
||||
f->flags = 0;
|
||||
f->id = 0; /* XXX Start with random id? */
|
||||
f->timeouttime = DEFTIMEOUT;
|
||||
f->maxconfreqtransmits = DEFMAXCONFREQS;
|
||||
f->maxtermtransmits = DEFMAXTERMREQS;
|
||||
f->maxnakloops = DEFMAXNAKLOOPS;
|
||||
f->term_reason_len = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fsm_lowerup - The lower layer is up.
|
||||
*/
|
||||
void
|
||||
fsm_lowerup(f)
|
||||
fsm *f;
|
||||
{
|
||||
switch( f->state ){
|
||||
case INITIAL:
|
||||
f->state = CLOSED;
|
||||
break;
|
||||
|
||||
case STARTING:
|
||||
if( f->flags & OPT_SILENT )
|
||||
f->state = STOPPED;
|
||||
else {
|
||||
/* Send an initial configure-request */
|
||||
fsm_sconfreq(f, 0);
|
||||
f->state = REQSENT;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
FSMDEBUG((LOG_INFO, "%s: Up event in state %d!",
|
||||
PROTO_NAME(f), f->state));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fsm_lowerdown - The lower layer is down.
|
||||
*
|
||||
* Cancel all timeouts and inform upper layers.
|
||||
*/
|
||||
void
|
||||
fsm_lowerdown(f)
|
||||
fsm *f;
|
||||
{
|
||||
switch( f->state ){
|
||||
case CLOSED:
|
||||
f->state = INITIAL;
|
||||
break;
|
||||
|
||||
case STOPPED:
|
||||
f->state = STARTING;
|
||||
if( f->callbacks->starting )
|
||||
(*f->callbacks->starting)(f);
|
||||
break;
|
||||
|
||||
case CLOSING:
|
||||
f->state = INITIAL;
|
||||
UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
|
||||
break;
|
||||
|
||||
case STOPPING:
|
||||
case REQSENT:
|
||||
case ACKRCVD:
|
||||
case ACKSENT:
|
||||
f->state = STARTING;
|
||||
UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
|
||||
break;
|
||||
|
||||
case OPENED:
|
||||
if( f->callbacks->down )
|
||||
(*f->callbacks->down)(f);
|
||||
f->state = STARTING;
|
||||
break;
|
||||
|
||||
default:
|
||||
FSMDEBUG((LOG_INFO, "%s: Down event in state %d!",
|
||||
PROTO_NAME(f), f->state));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fsm_open - Link is allowed to come up.
|
||||
*/
|
||||
void
|
||||
fsm_open(f)
|
||||
fsm *f;
|
||||
{
|
||||
switch( f->state ){
|
||||
case INITIAL:
|
||||
f->state = STARTING;
|
||||
if( f->callbacks->starting )
|
||||
(*f->callbacks->starting)(f);
|
||||
break;
|
||||
|
||||
case CLOSED:
|
||||
if( f->flags & OPT_SILENT )
|
||||
f->state = STOPPED;
|
||||
else {
|
||||
/* Send an initial configure-request */
|
||||
fsm_sconfreq(f, 0);
|
||||
f->state = REQSENT;
|
||||
}
|
||||
break;
|
||||
|
||||
case CLOSING:
|
||||
f->state = STOPPING;
|
||||
/* FALLTHROUGH */
|
||||
case STOPPED:
|
||||
case OPENED:
|
||||
if( f->flags & OPT_RESTART ){
|
||||
fsm_lowerdown(f);
|
||||
fsm_lowerup(f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fsm_close - Start closing connection.
|
||||
*
|
||||
* Cancel timeouts and either initiate close or possibly go directly to
|
||||
* the CLOSED state.
|
||||
*/
|
||||
void
|
||||
fsm_close(f, reason)
|
||||
fsm *f;
|
||||
char *reason;
|
||||
{
|
||||
f->term_reason = reason;
|
||||
f->term_reason_len = (reason == NULL? 0: strlen(reason));
|
||||
switch( f->state ){
|
||||
case STARTING:
|
||||
f->state = INITIAL;
|
||||
break;
|
||||
case STOPPED:
|
||||
f->state = CLOSED;
|
||||
break;
|
||||
case STOPPING:
|
||||
f->state = CLOSING;
|
||||
break;
|
||||
|
||||
case REQSENT:
|
||||
case ACKRCVD:
|
||||
case ACKSENT:
|
||||
case OPENED:
|
||||
if( f->state != OPENED )
|
||||
UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
|
||||
else if( f->callbacks->down )
|
||||
(*f->callbacks->down)(f); /* Inform upper layers we're down */
|
||||
|
||||
/* Init restart counter, send Terminate-Request */
|
||||
f->retransmits = f->maxtermtransmits;
|
||||
fsm_sdata(f, TERMREQ, f->reqid = ++f->id,
|
||||
(u_char *) f->term_reason, f->term_reason_len);
|
||||
TIMEOUT(fsm_timeout, f, f->timeouttime);
|
||||
--f->retransmits;
|
||||
|
||||
f->state = CLOSING;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fsm_timeout - Timeout expired.
|
||||
*/
|
||||
static void
|
||||
fsm_timeout(arg)
|
||||
void *arg;
|
||||
{
|
||||
fsm *f = (fsm *) arg;
|
||||
|
||||
switch (f->state) {
|
||||
case CLOSING:
|
||||
case STOPPING:
|
||||
if( f->retransmits <= 0 ){
|
||||
/*
|
||||
* We've waited for an ack long enough. Peer probably heard us.
|
||||
*/
|
||||
f->state = (f->state == CLOSING)? CLOSED: STOPPED;
|
||||
if( f->callbacks->finished )
|
||||
(*f->callbacks->finished)(f);
|
||||
} else {
|
||||
/* Send Terminate-Request */
|
||||
fsm_sdata(f, TERMREQ, f->reqid = ++f->id,
|
||||
(u_char *) f->term_reason, f->term_reason_len);
|
||||
TIMEOUT(fsm_timeout, f, f->timeouttime);
|
||||
--f->retransmits;
|
||||
}
|
||||
break;
|
||||
|
||||
case REQSENT:
|
||||
case ACKRCVD:
|
||||
case ACKSENT:
|
||||
if (f->retransmits <= 0) {
|
||||
syslog(LOG_WARNING, "%s: timeout sending Config-Requests",
|
||||
PROTO_NAME(f));
|
||||
f->state = STOPPED;
|
||||
if( (f->flags & OPT_PASSIVE) == 0 && f->callbacks->finished )
|
||||
(*f->callbacks->finished)(f);
|
||||
|
||||
} else {
|
||||
/* Retransmit the configure-request */
|
||||
if (f->callbacks->retransmit)
|
||||
(*f->callbacks->retransmit)(f);
|
||||
fsm_sconfreq(f, 1); /* Re-send Configure-Request */
|
||||
if( f->state == ACKRCVD )
|
||||
f->state = REQSENT;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
FSMDEBUG((LOG_INFO, "%s: Timeout event in state %d!",
|
||||
PROTO_NAME(f), f->state));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fsm_input - Input packet.
|
||||
*/
|
||||
void
|
||||
fsm_input(f, inpacket, l)
|
||||
fsm *f;
|
||||
u_char *inpacket;
|
||||
int l;
|
||||
{
|
||||
u_char *inp;
|
||||
u_char code, id;
|
||||
int len;
|
||||
|
||||
/*
|
||||
* Parse header (code, id and length).
|
||||
* If packet too short, drop it.
|
||||
*/
|
||||
inp = inpacket;
|
||||
if (l < HEADERLEN) {
|
||||
FSMDEBUG((LOG_WARNING, "fsm_input(%x): Rcvd short header.",
|
||||
f->protocol));
|
||||
return;
|
||||
}
|
||||
GETCHAR(code, inp);
|
||||
GETCHAR(id, inp);
|
||||
GETSHORT(len, inp);
|
||||
if (len < HEADERLEN) {
|
||||
FSMDEBUG((LOG_INFO, "fsm_input(%x): Rcvd illegal length.",
|
||||
f->protocol));
|
||||
return;
|
||||
}
|
||||
if (len > l) {
|
||||
FSMDEBUG((LOG_INFO, "fsm_input(%x): Rcvd short packet.",
|
||||
f->protocol));
|
||||
return;
|
||||
}
|
||||
len -= HEADERLEN; /* subtract header length */
|
||||
|
||||
if( f->state == INITIAL || f->state == STARTING ){
|
||||
FSMDEBUG((LOG_INFO, "fsm_input(%x): Rcvd packet in state %d.",
|
||||
f->protocol, f->state));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Action depends on code.
|
||||
*/
|
||||
switch (code) {
|
||||
case CONFREQ:
|
||||
fsm_rconfreq(f, id, inp, len);
|
||||
break;
|
||||
|
||||
case CONFACK:
|
||||
fsm_rconfack(f, id, inp, len);
|
||||
break;
|
||||
|
||||
case CONFNAK:
|
||||
case CONFREJ:
|
||||
fsm_rconfnakrej(f, code, id, inp, len);
|
||||
break;
|
||||
|
||||
case TERMREQ:
|
||||
fsm_rtermreq(f, id, inp, len);
|
||||
break;
|
||||
|
||||
case TERMACK:
|
||||
fsm_rtermack(f);
|
||||
break;
|
||||
|
||||
case CODEREJ:
|
||||
fsm_rcoderej(f, inp, len);
|
||||
break;
|
||||
|
||||
default:
|
||||
if( !f->callbacks->extcode
|
||||
|| !(*f->callbacks->extcode)(f, code, id, inp, len) )
|
||||
fsm_sdata(f, CODEREJ, ++f->id, inpacket, len + HEADERLEN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fsm_rconfreq - Receive Configure-Request.
|
||||
*/
|
||||
static void
|
||||
fsm_rconfreq(f, id, inp, len)
|
||||
fsm *f;
|
||||
u_char id;
|
||||
u_char *inp;
|
||||
int len;
|
||||
{
|
||||
int code, reject_if_disagree;
|
||||
|
||||
FSMDEBUG((LOG_INFO, "fsm_rconfreq(%s): Rcvd id %d.", PROTO_NAME(f), id));
|
||||
switch( f->state ){
|
||||
case CLOSED:
|
||||
/* Go away, we're closed */
|
||||
fsm_sdata(f, TERMACK, id, NULL, 0);
|
||||
return;
|
||||
case CLOSING:
|
||||
case STOPPING:
|
||||
return;
|
||||
|
||||
case OPENED:
|
||||
/* Go down and restart negotiation */
|
||||
if( f->callbacks->down )
|
||||
(*f->callbacks->down)(f); /* Inform upper layers */
|
||||
fsm_sconfreq(f, 0); /* Send initial Configure-Request */
|
||||
break;
|
||||
|
||||
case STOPPED:
|
||||
/* Negotiation started by our peer */
|
||||
fsm_sconfreq(f, 0); /* Send initial Configure-Request */
|
||||
f->state = REQSENT;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Pass the requested configuration options
|
||||
* to protocol-specific code for checking.
|
||||
*/
|
||||
if (f->callbacks->reqci){ /* Check CI */
|
||||
reject_if_disagree = (f->nakloops >= f->maxnakloops);
|
||||
code = (*f->callbacks->reqci)(f, inp, &len, reject_if_disagree);
|
||||
} else if (len)
|
||||
code = CONFREJ; /* Reject all CI */
|
||||
else
|
||||
code = CONFACK;
|
||||
|
||||
/* send the Ack, Nak or Rej to the peer */
|
||||
fsm_sdata(f, code, id, inp, len);
|
||||
|
||||
if (code == CONFACK) {
|
||||
if (f->state == ACKRCVD) {
|
||||
UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
|
||||
f->state = OPENED;
|
||||
if (f->callbacks->up)
|
||||
(*f->callbacks->up)(f); /* Inform upper layers */
|
||||
} else
|
||||
f->state = ACKSENT;
|
||||
f->nakloops = 0;
|
||||
|
||||
} else {
|
||||
/* we sent CONFACK or CONFREJ */
|
||||
if (f->state != ACKRCVD)
|
||||
f->state = REQSENT;
|
||||
if( code == CONFNAK )
|
||||
++f->nakloops;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fsm_rconfack - Receive Configure-Ack.
|
||||
*/
|
||||
static void
|
||||
fsm_rconfack(f, id, inp, len)
|
||||
fsm *f;
|
||||
int id;
|
||||
u_char *inp;
|
||||
int len;
|
||||
{
|
||||
FSMDEBUG((LOG_INFO, "fsm_rconfack(%s): Rcvd id %d.",
|
||||
PROTO_NAME(f), id));
|
||||
|
||||
if (id != f->reqid || f->seen_ack) /* Expected id? */
|
||||
return; /* Nope, toss... */
|
||||
if( !(f->callbacks->ackci? (*f->callbacks->ackci)(f, inp, len):
|
||||
(len == 0)) ){
|
||||
/* Ack is bad - ignore it */
|
||||
log_packet(inp, len, "Received bad configure-ack: ", LOG_ERR);
|
||||
FSMDEBUG((LOG_INFO, "%s: received bad Ack (length %d)",
|
||||
PROTO_NAME(f), len));
|
||||
return;
|
||||
}
|
||||
f->seen_ack = 1;
|
||||
|
||||
switch (f->state) {
|
||||
case CLOSED:
|
||||
case STOPPED:
|
||||
fsm_sdata(f, TERMACK, id, NULL, 0);
|
||||
break;
|
||||
|
||||
case REQSENT:
|
||||
f->state = ACKRCVD;
|
||||
f->retransmits = f->maxconfreqtransmits;
|
||||
break;
|
||||
|
||||
case ACKRCVD:
|
||||
/* Huh? an extra valid Ack? oh well... */
|
||||
UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
|
||||
fsm_sconfreq(f, 0);
|
||||
f->state = REQSENT;
|
||||
break;
|
||||
|
||||
case ACKSENT:
|
||||
UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
|
||||
f->state = OPENED;
|
||||
f->retransmits = f->maxconfreqtransmits;
|
||||
if (f->callbacks->up)
|
||||
(*f->callbacks->up)(f); /* Inform upper layers */
|
||||
break;
|
||||
|
||||
case OPENED:
|
||||
/* Go down and restart negotiation */
|
||||
if (f->callbacks->down)
|
||||
(*f->callbacks->down)(f); /* Inform upper layers */
|
||||
fsm_sconfreq(f, 0); /* Send initial Configure-Request */
|
||||
f->state = REQSENT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fsm_rconfnakrej - Receive Configure-Nak or Configure-Reject.
|
||||
*/
|
||||
static void
|
||||
fsm_rconfnakrej(f, code, id, inp, len)
|
||||
fsm *f;
|
||||
int code, id;
|
||||
u_char *inp;
|
||||
int len;
|
||||
{
|
||||
int (*proc)(fsm *, u_char *, int);
|
||||
int ret;
|
||||
|
||||
FSMDEBUG((LOG_INFO, "fsm_rconfnakrej(%s): Rcvd id %d.",
|
||||
PROTO_NAME(f), id));
|
||||
|
||||
if (id != f->reqid || f->seen_ack) /* Expected id? */
|
||||
return; /* Nope, toss... */
|
||||
proc = (code == CONFNAK)? f->callbacks->nakci: f->callbacks->rejci;
|
||||
if (!proc || !(ret = proc(f, inp, len))) {
|
||||
/* Nak/reject is bad - ignore it */
|
||||
log_packet(inp, len, "Received bad configure-nak/rej: ", LOG_ERR);
|
||||
FSMDEBUG((LOG_INFO, "%s: received bad %s (length %d)",
|
||||
PROTO_NAME(f), (code==CONFNAK? "Nak": "reject"), len));
|
||||
return;
|
||||
}
|
||||
f->seen_ack = 1;
|
||||
|
||||
switch (f->state) {
|
||||
case CLOSED:
|
||||
case STOPPED:
|
||||
fsm_sdata(f, TERMACK, id, NULL, 0);
|
||||
break;
|
||||
|
||||
case REQSENT:
|
||||
case ACKSENT:
|
||||
/* They didn't agree to what we wanted - try another request */
|
||||
UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
|
||||
if (ret < 0)
|
||||
f->state = STOPPED; /* kludge for stopping CCP */
|
||||
else
|
||||
fsm_sconfreq(f, 0); /* Send Configure-Request */
|
||||
break;
|
||||
|
||||
case ACKRCVD:
|
||||
/* Got a Nak/reject when we had already had an Ack?? oh well... */
|
||||
UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
|
||||
fsm_sconfreq(f, 0);
|
||||
f->state = REQSENT;
|
||||
break;
|
||||
|
||||
case OPENED:
|
||||
/* Go down and restart negotiation */
|
||||
if (f->callbacks->down)
|
||||
(*f->callbacks->down)(f); /* Inform upper layers */
|
||||
fsm_sconfreq(f, 0); /* Send initial Configure-Request */
|
||||
f->state = REQSENT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fsm_rtermreq - Receive Terminate-Req.
|
||||
*/
|
||||
static void
|
||||
fsm_rtermreq(f, id, p, len)
|
||||
fsm *f;
|
||||
int id;
|
||||
u_char *p;
|
||||
int len;
|
||||
{
|
||||
char str[80];
|
||||
|
||||
FSMDEBUG((LOG_INFO, "fsm_rtermreq(%s): Rcvd id %d.",
|
||||
PROTO_NAME(f), id));
|
||||
|
||||
switch (f->state) {
|
||||
case ACKRCVD:
|
||||
case ACKSENT:
|
||||
f->state = REQSENT; /* Start over but keep trying */
|
||||
break;
|
||||
|
||||
case OPENED:
|
||||
if (len > 0) {
|
||||
fmtmsg(str, sizeof(str), "%0.*v", len, p);
|
||||
syslog(LOG_INFO, "%s terminated by peer (%s)", PROTO_NAME(f), str);
|
||||
} else
|
||||
syslog(LOG_INFO, "%s terminated by peer", PROTO_NAME(f));
|
||||
if (f->callbacks->down)
|
||||
(*f->callbacks->down)(f); /* Inform upper layers */
|
||||
f->retransmits = 0;
|
||||
f->state = STOPPING;
|
||||
TIMEOUT(fsm_timeout, f, f->timeouttime);
|
||||
break;
|
||||
}
|
||||
|
||||
fsm_sdata(f, TERMACK, id, NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fsm_rtermack - Receive Terminate-Ack.
|
||||
*/
|
||||
static void
|
||||
fsm_rtermack(f)
|
||||
fsm *f;
|
||||
{
|
||||
FSMDEBUG((LOG_INFO, "fsm_rtermack(%s).", PROTO_NAME(f)));
|
||||
|
||||
switch (f->state) {
|
||||
case CLOSING:
|
||||
UNTIMEOUT(fsm_timeout, f);
|
||||
f->state = CLOSED;
|
||||
if( f->callbacks->finished )
|
||||
(*f->callbacks->finished)(f);
|
||||
break;
|
||||
case STOPPING:
|
||||
UNTIMEOUT(fsm_timeout, f);
|
||||
f->state = STOPPED;
|
||||
if( f->callbacks->finished )
|
||||
(*f->callbacks->finished)(f);
|
||||
break;
|
||||
|
||||
case ACKRCVD:
|
||||
f->state = REQSENT;
|
||||
break;
|
||||
|
||||
case OPENED:
|
||||
if (f->callbacks->down)
|
||||
(*f->callbacks->down)(f); /* Inform upper layers */
|
||||
fsm_sconfreq(f, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fsm_rcoderej - Receive a Code-Reject.
|
||||
*/
|
||||
static void
|
||||
fsm_rcoderej(f, inp, len)
|
||||
fsm *f;
|
||||
u_char *inp;
|
||||
int len;
|
||||
{
|
||||
u_char code, id;
|
||||
|
||||
FSMDEBUG((LOG_INFO, "fsm_rcoderej(%s).", PROTO_NAME(f)));
|
||||
|
||||
if (len < HEADERLEN) {
|
||||
FSMDEBUG((LOG_INFO, "fsm_rcoderej: Rcvd short Code-Reject packet!"));
|
||||
return;
|
||||
}
|
||||
GETCHAR(code, inp);
|
||||
GETCHAR(id, inp);
|
||||
syslog(LOG_WARNING, "%s: Rcvd Code-Reject for code %d, id %d",
|
||||
PROTO_NAME(f), code, id);
|
||||
|
||||
if( f->state == ACKRCVD )
|
||||
f->state = REQSENT;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fsm_protreject - Peer doesn't speak this protocol.
|
||||
*
|
||||
* Treat this as a catastrophic error (RXJ-).
|
||||
*/
|
||||
void
|
||||
fsm_protreject(f)
|
||||
fsm *f;
|
||||
{
|
||||
switch( f->state ){
|
||||
case CLOSING:
|
||||
UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
|
||||
/* FALLTHROUGH */
|
||||
case CLOSED:
|
||||
f->state = CLOSED;
|
||||
if( f->callbacks->finished )
|
||||
(*f->callbacks->finished)(f);
|
||||
break;
|
||||
|
||||
case STOPPING:
|
||||
case REQSENT:
|
||||
case ACKRCVD:
|
||||
case ACKSENT:
|
||||
UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
|
||||
/* FALLTHROUGH */
|
||||
case STOPPED:
|
||||
f->state = STOPPED;
|
||||
if( f->callbacks->finished )
|
||||
(*f->callbacks->finished)(f);
|
||||
break;
|
||||
|
||||
case OPENED:
|
||||
if( f->callbacks->down )
|
||||
(*f->callbacks->down)(f);
|
||||
|
||||
/* Init restart counter, send Terminate-Request */
|
||||
f->retransmits = f->maxtermtransmits;
|
||||
fsm_sdata(f, TERMREQ, f->reqid = ++f->id,
|
||||
(u_char *) f->term_reason, f->term_reason_len);
|
||||
TIMEOUT(fsm_timeout, f, f->timeouttime);
|
||||
--f->retransmits;
|
||||
|
||||
f->state = STOPPING;
|
||||
break;
|
||||
|
||||
default:
|
||||
FSMDEBUG((LOG_INFO, "%s: Protocol-reject event in state %d!",
|
||||
PROTO_NAME(f), f->state));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fsm_sconfreq - Send a Configure-Request.
|
||||
*/
|
||||
static void
|
||||
fsm_sconfreq(f, retransmit)
|
||||
fsm *f;
|
||||
int retransmit;
|
||||
{
|
||||
u_char *outp;
|
||||
int cilen;
|
||||
|
||||
if( f->state != REQSENT && f->state != ACKRCVD && f->state != ACKSENT ){
|
||||
/* Not currently negotiating - reset options */
|
||||
if( f->callbacks->resetci )
|
||||
(*f->callbacks->resetci)(f);
|
||||
f->nakloops = 0;
|
||||
}
|
||||
|
||||
if( !retransmit ){
|
||||
/* New request - reset retransmission counter, use new ID */
|
||||
f->retransmits = f->maxconfreqtransmits;
|
||||
f->reqid = ++f->id;
|
||||
}
|
||||
|
||||
f->seen_ack = 0;
|
||||
|
||||
/*
|
||||
* Make up the request packet
|
||||
*/
|
||||
outp = outpacket_buf + PPP_HDRLEN + HEADERLEN;
|
||||
if( f->callbacks->cilen && f->callbacks->addci ){
|
||||
cilen = (*f->callbacks->cilen)(f);
|
||||
if( cilen > peer_mru[f->unit] - HEADERLEN )
|
||||
cilen = peer_mru[f->unit] - HEADERLEN;
|
||||
if (f->callbacks->addci)
|
||||
(*f->callbacks->addci)(f, outp, &cilen);
|
||||
} else
|
||||
cilen = 0;
|
||||
|
||||
/* send the request to our peer */
|
||||
fsm_sdata(f, CONFREQ, f->reqid, outp, cilen);
|
||||
|
||||
/* start the retransmit timer */
|
||||
--f->retransmits;
|
||||
TIMEOUT(fsm_timeout, f, f->timeouttime);
|
||||
|
||||
FSMDEBUG((LOG_INFO, "%s: sending Configure-Request, id %d",
|
||||
PROTO_NAME(f), f->reqid));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fsm_sdata - Send some data.
|
||||
*
|
||||
* Used for all packets sent to our peer by this module.
|
||||
*/
|
||||
void
|
||||
fsm_sdata(f, code, id, data, datalen)
|
||||
fsm *f;
|
||||
u_char code, id;
|
||||
u_char *data;
|
||||
int datalen;
|
||||
{
|
||||
u_char *outp;
|
||||
int outlen;
|
||||
|
||||
/* Adjust length to be smaller than MTU */
|
||||
outp = outpacket_buf;
|
||||
if (datalen > peer_mru[f->unit] - HEADERLEN)
|
||||
datalen = peer_mru[f->unit] - HEADERLEN;
|
||||
if (datalen && data != outp + PPP_HDRLEN + HEADERLEN)
|
||||
BCOPY(data, outp + PPP_HDRLEN + HEADERLEN, datalen);
|
||||
outlen = datalen + HEADERLEN;
|
||||
MAKEHEADER(outp, f->protocol);
|
||||
PUTCHAR(code, outp);
|
||||
PUTCHAR(id, outp);
|
||||
PUTSHORT(outlen, outp);
|
||||
output(f->unit, outpacket_buf, outlen + PPP_HDRLEN);
|
||||
|
||||
FSMDEBUG((LOG_INFO, "fsm_sdata(%s): Sent code %d, id %d.",
|
||||
PROTO_NAME(f), code, id));
|
||||
}
|
@ -1,144 +0,0 @@
|
||||
/*
|
||||
* fsm.h - {Link, IP} Control Protocol Finite State Machine definitions.
|
||||
*
|
||||
* Copyright (c) 1989 Carnegie Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Carnegie Mellon University. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Packet header = Code, id, length.
|
||||
*/
|
||||
#define HEADERLEN (sizeof (u_char) + sizeof (u_char) + sizeof (u_short))
|
||||
|
||||
|
||||
/*
|
||||
* CP (LCP, IPCP, etc.) codes.
|
||||
*/
|
||||
#define CONFREQ 1 /* Configuration Request */
|
||||
#define CONFACK 2 /* Configuration Ack */
|
||||
#define CONFNAK 3 /* Configuration Nak */
|
||||
#define CONFREJ 4 /* Configuration Reject */
|
||||
#define TERMREQ 5 /* Termination Request */
|
||||
#define TERMACK 6 /* Termination Ack */
|
||||
#define CODEREJ 7 /* Code Reject */
|
||||
|
||||
|
||||
/*
|
||||
* Each FSM is described by an fsm structure and fsm callbacks.
|
||||
*/
|
||||
typedef struct fsm {
|
||||
int unit; /* Interface unit number */
|
||||
int protocol; /* Data Link Layer Protocol field value */
|
||||
int state; /* State */
|
||||
int flags; /* Contains option bits */
|
||||
u_char id; /* Current id */
|
||||
u_char reqid; /* Current request id */
|
||||
u_char seen_ack; /* Have received valid Ack/Nak/Rej to Req */
|
||||
int timeouttime; /* Timeout time in milliseconds */
|
||||
int maxconfreqtransmits; /* Maximum Configure-Request transmissions */
|
||||
int retransmits; /* Number of retransmissions left */
|
||||
int maxtermtransmits; /* Maximum Terminate-Request transmissions */
|
||||
int nakloops; /* Number of nak loops since last ack */
|
||||
int maxnakloops; /* Maximum number of nak loops tolerated */
|
||||
struct fsm_callbacks *callbacks; /* Callback routines */
|
||||
char *term_reason; /* Reason for closing protocol */
|
||||
int term_reason_len; /* Length of term_reason */
|
||||
} fsm;
|
||||
|
||||
|
||||
typedef struct fsm_callbacks {
|
||||
void (*resetci) /* Reset our Configuration Information */
|
||||
(fsm *);
|
||||
int (*cilen) /* Length of our Configuration Information */
|
||||
(fsm *);
|
||||
void (*addci) /* Add our Configuration Information */
|
||||
(fsm *, u_char *, int *);
|
||||
int (*ackci) /* ACK our Configuration Information */
|
||||
(fsm *, u_char *, int);
|
||||
int (*nakci) /* NAK our Configuration Information */
|
||||
(fsm *, u_char *, int);
|
||||
int (*rejci) /* Reject our Configuration Information */
|
||||
(fsm *, u_char *, int);
|
||||
int (*reqci) /* Request peer's Configuration Information */
|
||||
(fsm *, u_char *, int *, int);
|
||||
void (*up) /* Called when fsm reaches OPENED state */
|
||||
(fsm *);
|
||||
void (*down) /* Called when fsm leaves OPENED state */
|
||||
(fsm *);
|
||||
void (*starting) /* Called when we want the lower layer */
|
||||
(fsm *);
|
||||
void (*finished) /* Called when we don't want the lower layer */
|
||||
(fsm *);
|
||||
void (*protreject) /* Called when Protocol-Reject received */
|
||||
(int);
|
||||
void (*retransmit) /* Retransmission is necessary */
|
||||
(fsm *);
|
||||
int (*extcode) /* Called when unknown code received */
|
||||
(fsm *, int, int, u_char *, int);
|
||||
char *proto_name; /* String name for protocol (for messages) */
|
||||
} fsm_callbacks;
|
||||
|
||||
|
||||
/*
|
||||
* Link states.
|
||||
*/
|
||||
#define INITIAL 0 /* Down, hasn't been opened */
|
||||
#define STARTING 1 /* Down, been opened */
|
||||
#define CLOSED 2 /* Up, hasn't been opened */
|
||||
#define STOPPED 3 /* Open, waiting for down event */
|
||||
#define CLOSING 4 /* Terminating the connection, not open */
|
||||
#define STOPPING 5 /* Terminating, but open */
|
||||
#define REQSENT 6 /* We've sent a Config Request */
|
||||
#define ACKRCVD 7 /* We've received a Config Ack */
|
||||
#define ACKSENT 8 /* We've sent a Config Ack */
|
||||
#define OPENED 9 /* Connection available */
|
||||
|
||||
|
||||
/*
|
||||
* Flags - indicate options controlling FSM operation
|
||||
*/
|
||||
#define OPT_PASSIVE 1 /* Don't die if we don't get a response */
|
||||
#define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */
|
||||
#define OPT_SILENT 4 /* Wait for peer to speak first */
|
||||
|
||||
|
||||
/*
|
||||
* Timeouts.
|
||||
*/
|
||||
#define DEFTIMEOUT 3 /* Timeout time in seconds */
|
||||
#define DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */
|
||||
#define DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */
|
||||
#define DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */
|
||||
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
void fsm_init(fsm *);
|
||||
void fsm_lowerup(fsm *);
|
||||
void fsm_lowerdown(fsm *);
|
||||
void fsm_open(fsm *);
|
||||
void fsm_close(fsm *, char *);
|
||||
void fsm_input(fsm *, u_char *, int);
|
||||
void fsm_protreject(fsm *);
|
||||
void fsm_sdata(fsm *, int, int, u_char *, int);
|
||||
|
||||
|
||||
/*
|
||||
* Variables
|
||||
*/
|
||||
extern int peer_mru[]; /* currently negotiated peer MRU (per unit) */
|
1531
usr.sbin/pppd/ipcp.c
1531
usr.sbin/pppd/ipcp.c
File diff suppressed because it is too large
Load Diff
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* ipcp.h - IP Control Protocol definitions.
|
||||
*
|
||||
* Copyright (c) 1989 Carnegie Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Carnegie Mellon University. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Options.
|
||||
*/
|
||||
#define CI_ADDRS 1 /* IP Addresses */
|
||||
#define CI_COMPRESSTYPE 2 /* Compression Type */
|
||||
#define CI_ADDR 3
|
||||
|
||||
#define CI_MS_DNS1 129 /* Primary DNS value */
|
||||
#define CI_MS_WINS1 130 /* Primary WINS value */
|
||||
#define CI_MS_DNS2 131 /* Secondary DNS value */
|
||||
#define CI_MS_WINS2 132 /* Secondary WINS value */
|
||||
|
||||
#define MAX_STATES 16 /* from slcompress.h */
|
||||
|
||||
#define IPCP_VJMODE_OLD 1 /* "old" mode (option # = 0x0037) */
|
||||
#define IPCP_VJMODE_RFC1172 2 /* "old-rfc"mode (option # = 0x002d) */
|
||||
#define IPCP_VJMODE_RFC1332 3 /* "new-rfc"mode (option # = 0x002d, */
|
||||
/* maxslot and slot number compression) */
|
||||
|
||||
#define IPCP_VJ_COMP 0x002d /* current value for VJ compression option*/
|
||||
#define IPCP_VJ_COMP_OLD 0x0037 /* "old" (i.e, broken) value for VJ */
|
||||
/* compression option*/
|
||||
|
||||
typedef struct ipcp_options {
|
||||
int neg_addr : 1; /* Negotiate IP Address? */
|
||||
int old_addrs : 1; /* Use old (IP-Addresses) option? */
|
||||
int req_addr : 1; /* Ask peer to send IP address? */
|
||||
int default_route : 1; /* Assign default route through interface? */
|
||||
int proxy_arp : 1; /* Make proxy ARP entry for peer? */
|
||||
int neg_vj : 1; /* Van Jacobson Compression? */
|
||||
int old_vj : 1; /* use old (short) form of VJ option? */
|
||||
int accept_local : 1; /* accept peer's value for ouraddr */
|
||||
int accept_remote : 1; /* accept peer's value for hisaddr */
|
||||
u_short vj_protocol; /* protocol value to use in VJ option */
|
||||
u_char maxslotindex, cflag; /* values for RFC1332 VJ compression neg. */
|
||||
u_int32_t ouraddr, hisaddr; /* Addresses in NETWORK BYTE ORDER */
|
||||
u_int32_t dnsaddr[2]; /* Primary and secondary MS DNS entries */
|
||||
u_int32_t winsaddr[2]; /* Primary and secondary MS WINS entries */
|
||||
} ipcp_options;
|
||||
|
||||
extern fsm ipcp_fsm[];
|
||||
extern ipcp_options ipcp_wantoptions[];
|
||||
extern ipcp_options ipcp_gotoptions[];
|
||||
extern ipcp_options ipcp_allowoptions[];
|
||||
extern ipcp_options ipcp_hisoptions[];
|
||||
|
||||
char *ip_ntoa(u_int32_t);
|
||||
|
||||
extern struct protent ipcp_protent;
|
File diff suppressed because it is too large
Load Diff
@ -1,129 +0,0 @@
|
||||
/*
|
||||
ipv6cp.h - PPP IPV6 Control Protocol.
|
||||
Copyright (C) 1999 Tommi Komulainen <Tommi.Komulainen@iki.fi>
|
||||
|
||||
Redistribution and use in source and binary forms are permitted
|
||||
provided that the above copyright notice and this paragraph are
|
||||
duplicated in all such forms. The name of the author may not be
|
||||
used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
/* Original version, based on RFC2023 :
|
||||
|
||||
Copyright (c) 1995, 1996, 1997 Francis.Dupont@inria.fr, INRIA Rocquencourt,
|
||||
Alain.Durand@imag.fr, IMAG,
|
||||
Jean-Luc.Richier@imag.fr, IMAG-LSR.
|
||||
|
||||
Copyright (c) 1998, 1999 Francis.Dupont@inria.fr, GIE DYADE,
|
||||
Alain.Durand@imag.fr, IMAG,
|
||||
Jean-Luc.Richier@imag.fr, IMAG-LSR.
|
||||
|
||||
Ce travail a été fait au sein du GIE DYADE (Groupement d'Intérêt
|
||||
Économique ayant pour membres BULL S.A. et l'INRIA).
|
||||
|
||||
Ce logiciel informatique est disponible aux conditions
|
||||
usuelles dans la recherche, c'est-à-dire qu'il peut
|
||||
être utilisé, copié, modifié, distribué à l'unique
|
||||
condition que ce texte soit conservé afin que
|
||||
l'origine de ce logiciel soit reconnue.
|
||||
|
||||
Le nom de l'Institut National de Recherche en Informatique
|
||||
et en Automatique (INRIA), de l'IMAG, ou d'une personne morale
|
||||
ou physique ayant participé à l'élaboration de ce logiciel ne peut
|
||||
être utilisé sans son accord préalable explicite.
|
||||
|
||||
Ce logiciel est fourni tel quel sans aucune garantie,
|
||||
support ou responsabilité d'aucune sorte.
|
||||
Ce logiciel est dérivé de sources d'origine
|
||||
"University of California at Berkeley" et
|
||||
"Digital Equipment Corporation" couvertes par des copyrights.
|
||||
|
||||
L'Institut d'Informatique et de Mathématiques Appliquées de Grenoble (IMAG)
|
||||
est une fédération d'unités mixtes de recherche du CNRS, de l'Institut National
|
||||
Polytechnique de Grenoble et de l'Université Joseph Fourier regroupant
|
||||
sept laboratoires dont le laboratoire Logiciels, Systèmes, Réseaux (LSR).
|
||||
|
||||
This work has been done in the context of GIE DYADE (joint R & D venture
|
||||
between BULL S.A. and INRIA).
|
||||
|
||||
This software is available with usual "research" terms
|
||||
with the aim of retain credits of the software.
|
||||
Permission to use, copy, modify and distribute this software for any
|
||||
purpose and without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies,
|
||||
and the name of INRIA, IMAG, or any contributor not be used in advertising
|
||||
or publicity pertaining to this material without the prior explicit
|
||||
permission. The software is provided "as is" without any
|
||||
warranties, support or liabilities of any kind.
|
||||
This software is derived from source code from
|
||||
"University of California at Berkeley" and
|
||||
"Digital Equipment Corporation" protected by copyrights.
|
||||
|
||||
Grenoble's Institute of Computer Science and Applied Mathematics (IMAG)
|
||||
is a federation of seven research units funded by the CNRS, National
|
||||
Polytechnic Institute of Grenoble and University Joseph Fourier.
|
||||
The research unit in Software, Systems, Networks (LSR) is member of IMAG.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Derived from :
|
||||
*
|
||||
*
|
||||
* ipcp.h - IP Control Protocol definitions.
|
||||
*
|
||||
* Copyright (c) 1989 Carnegie Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Carnegie Mellon University. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: ipv6cp.h,v 1.3 1999/09/30 19:57:45 masputra Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Options.
|
||||
*/
|
||||
#define CI_IFACEID 1 /* Interface Identifier */
|
||||
#define CI_COMPRESSTYPE 2 /* Compression Type */
|
||||
|
||||
/* No compression types yet defined.
|
||||
*#define IPV6CP_COMP 0x004f
|
||||
*/
|
||||
typedef struct ipv6cp_options {
|
||||
int neg_ifaceid; /* Negotiate interface identifier? */
|
||||
int req_ifaceid; /* Ask peer to send interface identifier? */
|
||||
int accept_local; /* accept peer's value for iface id? */
|
||||
int opt_local; /* ourtoken set by option */
|
||||
int opt_remote; /* histoken set by option */
|
||||
int use_ip; /* use IP as interface identifier */
|
||||
#if defined(SOL2)
|
||||
int use_persistent; /* use uniquely persistent value for address */
|
||||
#endif /* defined(SOL2) */
|
||||
int neg_vj; /* Van Jacobson Compression? */
|
||||
u_short vj_protocol; /* protocol value to use in VJ option */
|
||||
eui64_t ourid, hisid; /* Interface identifiers */
|
||||
} ipv6cp_options;
|
||||
|
||||
extern fsm ipv6cp_fsm[];
|
||||
extern ipv6cp_options ipv6cp_wantoptions[];
|
||||
extern ipv6cp_options ipv6cp_gotoptions[];
|
||||
extern ipv6cp_options ipv6cp_allowoptions[];
|
||||
extern ipv6cp_options ipv6cp_hisoptions[];
|
||||
|
||||
extern struct protent ipv6cp_protent;
|
||||
|
||||
extern int setifaceid(char **arg);
|
File diff suppressed because it is too large
Load Diff
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* ipxcp.h - IPX Control Protocol definitions.
|
||||
*
|
||||
* Copyright (c) 1989 Carnegie Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Carnegie Mellon University. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Options.
|
||||
*/
|
||||
#define IPX_NETWORK_NUMBER 1 /* IPX Network Number */
|
||||
#define IPX_NODE_NUMBER 2
|
||||
#define IPX_COMPRESSION_PROTOCOL 3
|
||||
#define IPX_ROUTER_PROTOCOL 4
|
||||
#define IPX_ROUTER_NAME 5
|
||||
#define IPX_COMPLETE 6
|
||||
|
||||
/* Values for the router protocol */
|
||||
#define IPX_NONE 0
|
||||
#define RIP_SAP 2
|
||||
#define NLSP 4
|
||||
|
||||
typedef struct ipxcp_options {
|
||||
int neg_node : 1; /* Negotiate IPX node number? */
|
||||
int req_node : 1; /* Ask peer to send IPX node number? */
|
||||
|
||||
int neg_nn : 1; /* Negotiate IPX network number? */
|
||||
int req_nn : 1; /* Ask peer to send IPX network number */
|
||||
|
||||
int neg_name : 1; /* Negotiate IPX router name */
|
||||
int neg_complete : 1; /* Negotiate completion */
|
||||
int neg_router : 1; /* Negotiate IPX router number */
|
||||
|
||||
int accept_local : 1; /* accept peer's value for ournode */
|
||||
int accept_remote : 1; /* accept peer's value for hisnode */
|
||||
int accept_network : 1; /* accept network number */
|
||||
|
||||
int tried_nlsp : 1; /* I have suggested NLSP already */
|
||||
int tried_rip : 1; /* I have suggested RIP/SAP already */
|
||||
|
||||
u_int32_t his_network; /* base network number */
|
||||
u_int32_t our_network; /* our value for network number */
|
||||
u_int32_t network; /* the final network number */
|
||||
|
||||
u_char his_node[6]; /* peer's node number */
|
||||
u_char our_node[6]; /* our node number */
|
||||
u_char name [48]; /* name of the router */
|
||||
int router; /* routing protocol */
|
||||
} ipxcp_options;
|
||||
|
||||
extern fsm ipxcp_fsm[];
|
||||
extern ipxcp_options ipxcp_wantoptions[];
|
||||
extern ipxcp_options ipxcp_gotoptions[];
|
||||
extern ipxcp_options ipxcp_allowoptions[];
|
||||
extern ipxcp_options ipxcp_hisoptions[];
|
||||
|
||||
extern struct protent ipxcp_protent;
|
1859
usr.sbin/pppd/lcp.c
1859
usr.sbin/pppd/lcp.c
File diff suppressed because it is too large
Load Diff
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* lcp.h - Link Control Protocol definitions.
|
||||
*
|
||||
* Copyright (c) 1989 Carnegie Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Carnegie Mellon University. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Options.
|
||||
*/
|
||||
#define CI_MRU 1 /* Maximum Receive Unit */
|
||||
#define CI_ASYNCMAP 2 /* Async Control Character Map */
|
||||
#define CI_AUTHTYPE 3 /* Authentication Type */
|
||||
#define CI_QUALITY 4 /* Quality Protocol */
|
||||
#define CI_MAGICNUMBER 5 /* Magic Number */
|
||||
#define CI_PCOMPRESSION 7 /* Protocol Field Compression */
|
||||
#define CI_ACCOMPRESSION 8 /* Address/Control Field Compression */
|
||||
#define CI_CALLBACK 13 /* callback */
|
||||
|
||||
/*
|
||||
* LCP-specific packet types.
|
||||
*/
|
||||
#define PROTREJ 8 /* Protocol Reject */
|
||||
#define ECHOREQ 9 /* Echo Request */
|
||||
#define ECHOREP 10 /* Echo Reply */
|
||||
#define DISCREQ 11 /* Discard Request */
|
||||
#define CBCP_OPT 6 /* Use callback control protocol */
|
||||
|
||||
/*
|
||||
* The state of options is described by an lcp_options structure.
|
||||
*/
|
||||
typedef struct lcp_options {
|
||||
int passive : 1; /* Don't die if we don't get a response */
|
||||
int silent : 1; /* Wait for the other end to start first */
|
||||
int restart : 1; /* Restart vs. exit after close */
|
||||
int neg_mru : 1; /* Negotiate the MRU? */
|
||||
int neg_asyncmap : 1; /* Negotiate the async map? */
|
||||
int neg_upap : 1; /* Ask for UPAP authentication? */
|
||||
int neg_chap : 1; /* Ask for CHAP authentication? */
|
||||
int neg_magicnumber : 1; /* Ask for magic number? */
|
||||
int neg_pcompression : 1; /* HDLC Protocol Field Compression? */
|
||||
int neg_accompression : 1; /* HDLC Address/Control Field Compression? */
|
||||
int neg_lqr : 1; /* Negotiate use of Link Quality Reports */
|
||||
int neg_cbcp : 1; /* Negotiate use of CBCP */
|
||||
u_short mru; /* Value of MRU */
|
||||
u_char chap_mdtype; /* which MD type (hashing algorithm) */
|
||||
u_int32_t asyncmap; /* Value of async map */
|
||||
u_int32_t magicnumber;
|
||||
int numloops; /* Number of loops during magic number neg. */
|
||||
u_int32_t lqr_period; /* Reporting period for LQR 1/100ths second */
|
||||
} lcp_options;
|
||||
|
||||
extern fsm lcp_fsm[];
|
||||
extern lcp_options lcp_wantoptions[];
|
||||
extern lcp_options lcp_gotoptions[];
|
||||
extern lcp_options lcp_allowoptions[];
|
||||
extern lcp_options lcp_hisoptions[];
|
||||
extern u_int32_t xmit_accm[][8];
|
||||
|
||||
#define DEFMRU 1500 /* Try for this */
|
||||
#define MINMRU 128 /* No MRUs below this */
|
||||
#define MAXMRU 16384 /* Normally limit MRU to this */
|
||||
|
||||
void lcp_open(int);
|
||||
void lcp_close(int, char *);
|
||||
void lcp_lowerup(int);
|
||||
void lcp_lowerdown(int);
|
||||
void lcp_sprotrej(int, u_char *, int); /* send protocol reject */
|
||||
|
||||
extern struct protent lcp_protent;
|
||||
|
||||
/* Default number of times we receive our magic number from the peer
|
||||
before deciding the link is looped-back. */
|
||||
#define DEFLOOPBACKFAIL 10
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
* magic.c - PPP Magic Number routines.
|
||||
*
|
||||
* Copyright (c) 1989 Carnegie Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Carnegie Mellon University. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] = "$FreeBSD$";
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "pppd.h"
|
||||
#include "magic.h"
|
||||
|
||||
extern long mrand48(void);
|
||||
extern void srand48(long);
|
||||
|
||||
/*
|
||||
* magic_init - Initialize the magic number generator.
|
||||
*
|
||||
* Attempts to compute a random number seed which will not repeat.
|
||||
* The current method uses the current hostid, current process ID
|
||||
* and current time, currently.
|
||||
*/
|
||||
void
|
||||
magic_init()
|
||||
{
|
||||
long seed;
|
||||
struct timeval t;
|
||||
|
||||
gettimeofday(&t, NULL);
|
||||
seed = get_host_seed() ^ t.tv_sec ^ t.tv_usec ^ getpid();
|
||||
srand48(seed);
|
||||
}
|
||||
|
||||
/*
|
||||
* magic - Returns the next magic number.
|
||||
*/
|
||||
u_int32_t
|
||||
magic()
|
||||
{
|
||||
return (u_int32_t) mrand48();
|
||||
}
|
||||
|
||||
#ifdef NO_DRAND48
|
||||
/*
|
||||
* Substitute procedures for those systems which don't have
|
||||
* drand48 et al.
|
||||
*/
|
||||
|
||||
double
|
||||
drand48()
|
||||
{
|
||||
return (double)random() / (double)0x7fffffffL; /* 2**31-1 */
|
||||
}
|
||||
|
||||
long
|
||||
mrand48()
|
||||
{
|
||||
return random();
|
||||
}
|
||||
|
||||
void
|
||||
srand48(seedval)
|
||||
long seedval;
|
||||
{
|
||||
srandom((int)seedval);
|
||||
}
|
||||
|
||||
#endif
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* magic.h - PPP Magic Number definitions.
|
||||
*
|
||||
* Copyright (c) 1989 Carnegie Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Carnegie Mellon University. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
void magic_init(void); /* Initialize the magic number generator */
|
||||
u_int32_t magic(void); /* Returns the next magic number */
|
1723
usr.sbin/pppd/main.c
1723
usr.sbin/pppd/main.c
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,6 +0,0 @@
|
||||
/* $FreeBSD$ */
|
||||
#define PATCHLEVEL 5
|
||||
|
||||
#define VERSION "2.3"
|
||||
#define IMPLEMENTATION ""
|
||||
#define DATE "4 May 1998"
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* define path names
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifdef HAVE_PATHS_H
|
||||
#include <paths.h>
|
||||
|
||||
#else
|
||||
#define _PATH_VARRUN "/etc/ppp/"
|
||||
#define _PATH_DEVNULL "/dev/null"
|
||||
#endif
|
||||
|
||||
#define _PATH_UPAPFILE "/etc/ppp/pap-secrets"
|
||||
#define _PATH_CHAPFILE "/etc/ppp/chap-secrets"
|
||||
#define _PATH_SYSOPTIONS "/etc/ppp/options"
|
||||
#define _PATH_IPUP "/etc/ppp/ip-up"
|
||||
#define _PATH_IPDOWN "/etc/ppp/ip-down"
|
||||
#define _PATH_AUTHUP "/etc/ppp/auth-up"
|
||||
#define _PATH_AUTHDOWN "/etc/ppp/auth-down"
|
||||
#define _PATH_TTYOPT "/etc/ppp/options."
|
||||
#define _PATH_CONNERRS "/var/log/connect-errors"
|
||||
#define _PATH_USEROPT ".ppprc"
|
||||
#define _PATH_PEERFILES "/etc/ppp/peers/"
|
||||
#define _PATH_PPPDENY "/etc/ppp/ppp.deny"
|
||||
#define _PATH_PPPSHELLS "/etc/ppp/ppp.shells"
|
||||
|
||||
#ifdef INET6
|
||||
#define _PATH_IPV6UP "/etc/ppp/ipv6-up"
|
||||
#define _PATH_IPV6DOWN "/etc/ppp/ipv6-down"
|
||||
#endif
|
||||
|
||||
#ifdef IPX_CHANGE
|
||||
#define _PATH_IPXUP "/etc/ppp/ipx-up"
|
||||
#define _PATH_IPXDOWN "/etc/ppp/ipx-down"
|
||||
#endif /* IPX_CHANGE */
|
1247
usr.sbin/pppd/pppd.8
1247
usr.sbin/pppd/pppd.8
File diff suppressed because it is too large
Load Diff
@ -1,509 +0,0 @@
|
||||
/*
|
||||
* pppd.h - PPP daemon global declarations.
|
||||
*
|
||||
* Copyright (c) 1989 Carnegie Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Carnegie Mellon University. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
*/
|
||||
|
||||
#ifndef __PPPD_H__
|
||||
#define __PPPD_H__
|
||||
|
||||
#include <stdio.h> /* for FILE */
|
||||
#include <sys/param.h> /* for MAXPATHLEN and BSD4_4, if defined */
|
||||
#include <sys/types.h> /* for u_int32_t, if defined */
|
||||
#include <sys/time.h> /* for struct timeval */
|
||||
#include <net/ppp_defs.h>
|
||||
|
||||
#if __STDC__
|
||||
#include <stdarg.h>
|
||||
#define __V(x) x
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#define __V(x) (va_alist) va_dcl
|
||||
#define const
|
||||
#endif
|
||||
|
||||
#ifdef INET6
|
||||
#include "eui64.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Limits.
|
||||
*/
|
||||
|
||||
#define NUM_PPP 1 /* One PPP interface supported (per process) */
|
||||
#define MAXWORDLEN 1024 /* max length of word in file (incl null) */
|
||||
#define MAXARGS 1 /* max # args to a command */
|
||||
#define MAXNAMELEN 256 /* max length of hostname or name for auth */
|
||||
#define MAXSECRETLEN 256 /* max length of password or secret */
|
||||
|
||||
/*
|
||||
* Global variables.
|
||||
*/
|
||||
|
||||
extern int hungup; /* Physical layer has disconnected */
|
||||
extern int ifunit; /* Interface unit number */
|
||||
extern char ifname[]; /* Interface name */
|
||||
extern int ttyfd; /* Serial device file descriptor */
|
||||
extern char hostname[]; /* Our hostname */
|
||||
extern u_char outpacket_buf[]; /* Buffer for outgoing packets */
|
||||
extern int phase; /* Current state of link - see values below */
|
||||
extern int baud_rate; /* Current link speed in bits/sec */
|
||||
extern char *progname; /* Name of this program */
|
||||
extern int redirect_stderr;/* Connector's stderr should go to file */
|
||||
extern char peer_authname[];/* Authenticated name of peer */
|
||||
extern int privileged; /* We were run by real-uid root */
|
||||
extern int need_holdoff; /* Need holdoff period after link terminates */
|
||||
extern char **script_env; /* Environment variables for scripts */
|
||||
extern int detached; /* Have detached from controlling tty */
|
||||
|
||||
/*
|
||||
* Variables set by command-line options.
|
||||
*/
|
||||
|
||||
extern int debug; /* Debug flag */
|
||||
extern int kdebugflag; /* Tell kernel to print debug messages */
|
||||
extern int default_device; /* Using /dev/tty or equivalent */
|
||||
extern char devnam[]; /* Device name */
|
||||
extern int crtscts; /* Use hardware flow control */
|
||||
extern int modem; /* Use modem control lines */
|
||||
extern int inspeed; /* Input/Output speed requested */
|
||||
extern u_int32_t netmask; /* IP netmask to set on interface */
|
||||
extern int lockflag; /* Create lock file to lock the serial dev */
|
||||
extern int nodetach; /* Don't detach from controlling tty */
|
||||
extern char *connector; /* Script to establish physical link */
|
||||
extern char *disconnector; /* Script to disestablish physical link */
|
||||
extern char *welcomer; /* Script to welcome client after connection */
|
||||
extern int max_con_attempts;/* Maximum number of times to try dialing */
|
||||
extern int maxconnect; /* Maximum connect time (seconds) */
|
||||
extern char user[]; /* Our name for authenticating ourselves */
|
||||
extern char passwd[]; /* Password for PAP */
|
||||
extern int auth_required; /* Peer is required to authenticate */
|
||||
extern int proxyarp; /* Set up proxy ARP entry for peer */
|
||||
extern int persist; /* Reopen link after it goes down */
|
||||
extern int uselogin; /* Use /etc/passwd for checking PAP */
|
||||
extern int lcp_echo_interval; /* Interval between LCP echo-requests */
|
||||
extern int lcp_echo_fails; /* Tolerance to unanswered echo-requests */
|
||||
extern char our_name[]; /* Our name for authentication purposes */
|
||||
extern char remote_name[]; /* Peer's name for authentication */
|
||||
extern int explicit_remote;/* remote_name specified with remotename opt */
|
||||
extern int usehostname; /* Use hostname for our_name */
|
||||
extern int disable_defaultip; /* Don't use hostname for default IP adrs */
|
||||
extern int demand; /* Do dial-on-demand */
|
||||
extern char *ipparam; /* Extra parameter for ip up/down scripts */
|
||||
extern int cryptpap; /* Others' PAP passwords are encrypted */
|
||||
extern int idle_time_limit;/* Shut down link if idle for this long */
|
||||
extern int holdoff; /* Dead time before restarting */
|
||||
extern int refuse_pap; /* Don't wanna auth. ourselves with PAP */
|
||||
extern int refuse_chap; /* Don't wanna auth. ourselves with CHAP */
|
||||
#ifdef PPP_FILTER
|
||||
extern struct bpf_program pass_filter; /* Filter for pkts to pass */
|
||||
extern struct bpf_program active_filter; /* Filter for link-active pkts */
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef MSLANMAN
|
||||
extern int ms_lanman; /* Nonzero if use LanMan password instead of NT */
|
||||
/* Has meaning only with MS-CHAP challenges */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Values for phase.
|
||||
*/
|
||||
#define PHASE_DEAD 0
|
||||
#define PHASE_INITIALIZE 1
|
||||
#define PHASE_DORMANT 2
|
||||
#define PHASE_ESTABLISH 3
|
||||
#define PHASE_AUTHENTICATE 4
|
||||
#define PHASE_CALLBACK 5
|
||||
#define PHASE_NETWORK 6
|
||||
#define PHASE_TERMINATE 7
|
||||
#define PHASE_HOLDOFF 8
|
||||
|
||||
/*
|
||||
* The following struct gives the addresses of procedures to call
|
||||
* for a particular protocol.
|
||||
*/
|
||||
struct protent {
|
||||
u_short protocol; /* PPP protocol number */
|
||||
/* Initialization procedure */
|
||||
void (*init)(int unit);
|
||||
/* Process a received packet */
|
||||
void (*input)(int unit, u_char *pkt, int len);
|
||||
/* Process a received protocol-reject */
|
||||
void (*protrej)(int unit);
|
||||
/* Lower layer has come up */
|
||||
void (*lowerup)(int unit);
|
||||
/* Lower layer has gone down */
|
||||
void (*lowerdown)(int unit);
|
||||
/* Open the protocol */
|
||||
void (*open)(int unit);
|
||||
/* Close the protocol */
|
||||
void (*close)(int unit, char *reason);
|
||||
/* Print a packet in readable form */
|
||||
int (*printpkt)(u_char *pkt, int len,
|
||||
void (*printer)(void *, char *, ...),
|
||||
void *arg);
|
||||
/* Process a received data packet */
|
||||
void (*datainput)(int unit, u_char *pkt, int len);
|
||||
int enabled_flag; /* 0 iff protocol is disabled */
|
||||
char *name; /* Text name of protocol */
|
||||
/* Check requested options, assign defaults */
|
||||
void (*check_options)(void);
|
||||
/* Configure interface for demand-dial */
|
||||
int (*demand_conf)(int unit);
|
||||
/* Say whether to bring up link for this pkt */
|
||||
int (*active_pkt)(u_char *pkt, int len);
|
||||
};
|
||||
|
||||
/* Table of pointers to supported protocols */
|
||||
extern struct protent *protocols[];
|
||||
|
||||
/*
|
||||
* Prototypes.
|
||||
*/
|
||||
|
||||
/* Procedures exported from main.c. */
|
||||
void detach(void); /* Detach from controlling tty */
|
||||
void die(int); /* Cleanup and exit */
|
||||
void quit(void); /* like die(1) */
|
||||
void novm(char *); /* Say we ran out of memory, and die */
|
||||
void timeout(void (*func)(void *), void *arg, int t);
|
||||
/* Call func(arg) after t seconds */
|
||||
void untimeout(void (*func)(void *), void *arg);
|
||||
/* Cancel call to func(arg) */
|
||||
int run_program(char *prog, char **args, int must_exist);
|
||||
/* Run program prog with args in child */
|
||||
void demuxprotrej(int, int);
|
||||
/* Demultiplex a Protocol-Reject */
|
||||
void format_packet(u_char *, int, void (*) (void *, char *, ...),
|
||||
void *); /* Format a packet in human-readable form */
|
||||
void log_packet(u_char *, int, char *, int);
|
||||
/* Format a packet and log it with syslog */
|
||||
void print_string(char *, int, void (*) (void *, char *, ...),
|
||||
void *); /* Format a string for output */
|
||||
int fmtmsg(char *, int, char *, ...); /* sprintf++ */
|
||||
int vfmtmsg(char *, int, char *, va_list); /* vsprintf++ */
|
||||
void script_setenv(char *, char *); /* set script env var */
|
||||
void script_unsetenv(char *); /* unset script env var */
|
||||
|
||||
/* Procedures exported from auth.c */
|
||||
void link_required(int); /* we are starting to use the link */
|
||||
void link_terminated(int); /* we are finished with the link */
|
||||
void link_down(int); /* the LCP layer has left the Opened state */
|
||||
void link_established(int); /* the link is up; authenticate now */
|
||||
void np_up(int, int); /* a network protocol has come up */
|
||||
void np_down(int, int); /* a network protocol has gone down */
|
||||
void np_finished(int, int); /* a network protocol no longer needs link */
|
||||
void auth_peer_fail(int, int);
|
||||
/* peer failed to authenticate itself */
|
||||
void auth_peer_success(int, int, char *, int);
|
||||
/* peer successfully authenticated itself */
|
||||
void auth_withpeer_fail(int, int);
|
||||
/* we failed to authenticate ourselves */
|
||||
void auth_withpeer_success(int, int);
|
||||
/* we successfully authenticated ourselves */
|
||||
void auth_check_options(void);
|
||||
/* check authentication options supplied */
|
||||
void auth_reset(int); /* check what secrets we have */
|
||||
int check_passwd(int, char *, int, char *, int, char **, int *);
|
||||
/* Check peer-supplied username/password */
|
||||
int get_secret(int, char *, char *, char *, int *, int);
|
||||
/* get "secret" for chap */
|
||||
int auth_ip_addr(int, u_int32_t);
|
||||
/* check if IP address is authorized */
|
||||
int bad_ip_adrs(u_int32_t);
|
||||
/* check if IP address is unreasonable */
|
||||
void check_access(FILE *, char *);
|
||||
/* check permissions on secrets file */
|
||||
|
||||
/* Procedures exported from demand.c */
|
||||
void demand_conf(void); /* config interface(s) for demand-dial */
|
||||
void demand_block(void); /* set all NPs to queue up packets */
|
||||
void demand_unblock(void); /* set all NPs to pass packets */
|
||||
void demand_discard(void); /* set all NPs to discard packets */
|
||||
void demand_rexmit(int); /* retransmit saved frames for an NP */
|
||||
int loop_chars(unsigned char *, int); /* process chars from loopback */
|
||||
int loop_frame(unsigned char *, int); /* process frame from loopback */
|
||||
|
||||
/* Procedures exported from sys-*.c */
|
||||
void sys_init(void); /* Do system-dependent initialization */
|
||||
void sys_cleanup(void); /* Restore system state before exiting */
|
||||
void sys_check_options(void); /* Check options specified */
|
||||
void sys_close(void); /* Clean up in a child before execing */
|
||||
int ppp_available(void); /* Test whether ppp kernel support exists */
|
||||
void open_ppp_loopback(void); /* Open loopback for demand-dialling */
|
||||
void establish_ppp(int); /* Turn serial port into a ppp interface */
|
||||
void restore_loop(void); /* Transfer ppp unit back to loopback */
|
||||
void disestablish_ppp(int); /* Restore port to normal operation */
|
||||
void clean_check(void); /* Check if line was 8-bit clean */
|
||||
void set_up_tty(int, int); /* Set up port's speed, parameters, etc. */
|
||||
void restore_tty(int); /* Restore port's original parameters */
|
||||
void setdtr(int, int); /* Raise or lower port's DTR line */
|
||||
void output(int, u_char *, int); /* Output a PPP packet */
|
||||
void wait_input(struct timeval *);
|
||||
/* Wait for input, with timeout */
|
||||
void wait_loop_output(struct timeval *);
|
||||
/* Wait for pkt from loopback, with timeout */
|
||||
void wait_time(struct timeval *); /* Wait for given length of time */
|
||||
int read_packet(u_char *); /* Read PPP packet */
|
||||
int get_loop_output(void); /* Read pkts from loopback */
|
||||
void ppp_send_config(int, int, u_int32_t, int, int);
|
||||
/* Configure i/f transmit parameters */
|
||||
void ppp_set_xaccm(int, ext_accm);
|
||||
/* Set extended transmit ACCM */
|
||||
void ppp_recv_config(int, int, u_int32_t, int, int);
|
||||
/* Configure i/f receive parameters */
|
||||
int ccp_test(int, u_char *, int, int);
|
||||
/* Test support for compression scheme */
|
||||
void ccp_flags_set(int, int, int);
|
||||
/* Set kernel CCP state */
|
||||
int ccp_fatal_error(int); /* Test for fatal decomp error in kernel */
|
||||
int get_idle_time(int, struct ppp_idle *);
|
||||
/* Find out how long link has been idle */
|
||||
int sifvjcomp(int, int, int, int);
|
||||
/* Configure VJ TCP header compression */
|
||||
int sifup(int); /* Configure i/f up (for IP) */
|
||||
int sifnpmode(int u, int proto, enum NPmode mode);
|
||||
/* Set mode for handling packets for proto */
|
||||
int sifdown(int); /* Configure i/f down (for IP) */
|
||||
int sifaddr(int, u_int32_t, u_int32_t, u_int32_t);
|
||||
/* Configure IP addresses for i/f */
|
||||
int cifaddr(int, u_int32_t, u_int32_t);
|
||||
/* Reset i/f IP addresses */
|
||||
#ifdef INET6
|
||||
int sif6addr(int, eui64_t, eui64_t);
|
||||
/* Configure IPv6 addresses for i/f */
|
||||
int cif6addr(int, eui64_t, eui64_t);
|
||||
/* Remove an IPv6 address from i/f */
|
||||
#endif
|
||||
int sifdefaultroute(int, u_int32_t, u_int32_t);
|
||||
/* Create default route through i/f */
|
||||
int cifdefaultroute(int, u_int32_t, u_int32_t);
|
||||
/* Delete default route through i/f */
|
||||
int sifproxyarp(int, u_int32_t);
|
||||
/* Add proxy ARP entry for peer */
|
||||
int cifproxyarp(int, u_int32_t);
|
||||
/* Delete proxy ARP entry for peer */
|
||||
u_int32_t GetMask(u_int32_t); /* Get appropriate netmask for address */
|
||||
int lock(char *); /* Create lock file for device */
|
||||
void unlock(void); /* Delete previously-created lock file */
|
||||
int daemon(int, int); /* Detach us from terminal session */
|
||||
void logwtmp(const char *, const char *, const char *);
|
||||
/* Write entry to wtmp file */
|
||||
int get_host_seed(void); /* Get host-dependent random number seed */
|
||||
#ifdef PPP_FILTER
|
||||
int set_filters(struct bpf_program *pass, struct bpf_program *active);
|
||||
/* Set filter programs in kernel */
|
||||
#endif
|
||||
|
||||
/* Procedures exported from options.c */
|
||||
int parse_args(int argc, char **argv);
|
||||
/* Parse options from arguments given */
|
||||
void usage(void); /* Print a usage message */
|
||||
int options_from_file(char *filename, int must_exist, int check_prot,
|
||||
int privileged);
|
||||
/* Parse options from an options file */
|
||||
int options_from_user(void); /* Parse options from user's .ppprc */
|
||||
int options_for_tty(void); /* Parse options from /etc/ppp/options.tty */
|
||||
void scan_args(int argc, char **argv);
|
||||
/* Look for tty name in command-line args */
|
||||
int getword(FILE *f, char *word, int *newlinep, char *filename);
|
||||
/* Read a word from a file */
|
||||
void option_error(char *fmt, ...);
|
||||
/* Print an error message about an option */
|
||||
int setipaddr(char *); /* set IP addresses */
|
||||
|
||||
|
||||
/*
|
||||
* This structure is used to store information about certain
|
||||
* options, such as where the option value came from (/etc/ppp/options,
|
||||
* command line, etc.) and whether it came from a privileged source.
|
||||
*/
|
||||
|
||||
struct option_info {
|
||||
int priv; /* was value set by sysadmin? */
|
||||
char *source; /* where option came from */
|
||||
};
|
||||
|
||||
extern struct option_info auth_req_info;
|
||||
extern struct option_info connector_info;
|
||||
extern struct option_info disconnector_info;
|
||||
extern struct option_info welcomer_info;
|
||||
extern struct option_info devnam_info;
|
||||
|
||||
/*
|
||||
* Inline versions of get/put char/short/long.
|
||||
* Pointer is advanced; we assume that both arguments
|
||||
* are lvalues and will already be in registers.
|
||||
* cp MUST be u_char *.
|
||||
*/
|
||||
#define GETCHAR(c, cp) { \
|
||||
(c) = *(cp)++; \
|
||||
}
|
||||
#define PUTCHAR(c, cp) { \
|
||||
*(cp)++ = (u_char) (c); \
|
||||
}
|
||||
|
||||
|
||||
#define GETSHORT(s, cp) { \
|
||||
(s) = *(cp)++ << 8; \
|
||||
(s) |= *(cp)++; \
|
||||
}
|
||||
#define PUTSHORT(s, cp) { \
|
||||
*(cp)++ = (u_char) ((s) >> 8); \
|
||||
*(cp)++ = (u_char) (s); \
|
||||
}
|
||||
|
||||
#define GETLONG(l, cp) { \
|
||||
(l) = *(cp)++ << 8; \
|
||||
(l) |= *(cp)++; (l) <<= 8; \
|
||||
(l) |= *(cp)++; (l) <<= 8; \
|
||||
(l) |= *(cp)++; \
|
||||
}
|
||||
#define PUTLONG(l, cp) { \
|
||||
*(cp)++ = (u_char) ((l) >> 24); \
|
||||
*(cp)++ = (u_char) ((l) >> 16); \
|
||||
*(cp)++ = (u_char) ((l) >> 8); \
|
||||
*(cp)++ = (u_char) (l); \
|
||||
}
|
||||
|
||||
#define INCPTR(n, cp) ((cp) += (n))
|
||||
#define DECPTR(n, cp) ((cp) -= (n))
|
||||
|
||||
#undef FALSE
|
||||
#define FALSE 0
|
||||
#undef TRUE
|
||||
#define TRUE 1
|
||||
|
||||
/*
|
||||
* System dependent definitions for user-level 4.3BSD UNIX implementation.
|
||||
*/
|
||||
|
||||
#define DEMUXPROTREJ(u, p) demuxprotrej(u, p)
|
||||
|
||||
#define TIMEOUT(r, f, t) timeout((r), (f), (t))
|
||||
#define UNTIMEOUT(r, f) untimeout((r), (f))
|
||||
|
||||
#define BCOPY(s, d, l) memcpy(d, s, l)
|
||||
#define BZERO(s, n) memset(s, 0, n)
|
||||
#define EXIT(u) quit()
|
||||
|
||||
#define PRINTMSG(m, l) { m[l] = '\0'; syslog(LOG_INFO, "Remote message: %s", m); }
|
||||
|
||||
/*
|
||||
* MAKEHEADER - Add Header fields to a packet.
|
||||
*/
|
||||
#define MAKEHEADER(p, t) { \
|
||||
PUTCHAR(PPP_ALLSTATIONS, p); \
|
||||
PUTCHAR(PPP_UI, p); \
|
||||
PUTSHORT(t, p); }
|
||||
|
||||
|
||||
#ifdef DEBUGALL
|
||||
#define DEBUGMAIN 1
|
||||
#define DEBUGFSM 1
|
||||
#define DEBUGLCP 1
|
||||
#define DEBUGIPCP 1
|
||||
#define DEBUGUPAP 1
|
||||
#define DEBUGCHAP 1
|
||||
#endif
|
||||
|
||||
#ifndef LOG_PPP /* we use LOG_LOCAL2 for syslog by default */
|
||||
#if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \
|
||||
|| defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
|
||||
|| defined(DEBUGCHAP) || defined(DEBUG)
|
||||
#define LOG_PPP LOG_LOCAL2
|
||||
#else
|
||||
#define LOG_PPP LOG_DAEMON
|
||||
#endif
|
||||
#endif /* LOG_PPP */
|
||||
|
||||
#ifdef DEBUGMAIN
|
||||
#define MAINDEBUG(x) if (debug) syslog x
|
||||
#else
|
||||
#define MAINDEBUG(x)
|
||||
#endif
|
||||
|
||||
#ifdef DEBUGSYS
|
||||
#define SYSDEBUG(x) if (debug) syslog x
|
||||
#else
|
||||
#define SYSDEBUG(x)
|
||||
#endif
|
||||
|
||||
#ifdef DEBUGFSM
|
||||
#define FSMDEBUG(x) if (debug) syslog x
|
||||
#else
|
||||
#define FSMDEBUG(x)
|
||||
#endif
|
||||
|
||||
#ifdef DEBUGLCP
|
||||
#define LCPDEBUG(x) if (debug) syslog x
|
||||
#else
|
||||
#define LCPDEBUG(x)
|
||||
#endif
|
||||
|
||||
#ifdef DEBUGIPCP
|
||||
#define IPCPDEBUG(x) if (debug) syslog x
|
||||
#else
|
||||
#define IPCPDEBUG(x)
|
||||
#endif
|
||||
|
||||
#ifdef DEBUGIPV6CP
|
||||
#define IPV6CPDEBUG(x) if (debug) syslog x
|
||||
#else
|
||||
#define IPV6CPDEBUG(x)
|
||||
#endif
|
||||
|
||||
#ifdef DEBUGUPAP
|
||||
#define UPAPDEBUG(x) if (debug) syslog x
|
||||
#else
|
||||
#define UPAPDEBUG(x)
|
||||
#endif
|
||||
|
||||
#ifdef DEBUGCHAP
|
||||
#define CHAPDEBUG(x) if (debug) syslog x
|
||||
#else
|
||||
#define CHAPDEBUG(x)
|
||||
#endif
|
||||
|
||||
#ifdef DEBUGIPXCP
|
||||
#define IPXCPDEBUG(x) if (debug) syslog x
|
||||
#else
|
||||
#define IPXCPDEBUG(x)
|
||||
#endif
|
||||
|
||||
#ifndef SIGTYPE
|
||||
#if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
|
||||
#define SIGTYPE void
|
||||
#else
|
||||
#define SIGTYPE int
|
||||
#endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
|
||||
#endif /* SIGTYPE */
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) ((a) < (b)? (a): (b))
|
||||
#endif
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) ((a) > (b)? (a): (b))
|
||||
#endif
|
||||
|
||||
#endif /* __PPP_H__ */
|
File diff suppressed because it is too large
Load Diff
@ -1,618 +0,0 @@
|
||||
/*
|
||||
* upap.c - User/Password Authentication Protocol.
|
||||
*
|
||||
* Copyright (c) 1989 Carnegie Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Carnegie Mellon University. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] = "$FreeBSD$";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "pppd.h"
|
||||
#include "upap.h"
|
||||
|
||||
/*
|
||||
* Protocol entry points.
|
||||
*/
|
||||
static void upap_init(int);
|
||||
static void upap_lowerup(int);
|
||||
static void upap_lowerdown(int);
|
||||
static void upap_input(int, u_char *, int);
|
||||
static void upap_protrej(int);
|
||||
static int upap_printpkt(u_char *, int,
|
||||
void (*)(void *, char *, ...), void *);
|
||||
|
||||
struct protent pap_protent = {
|
||||
PPP_PAP,
|
||||
upap_init,
|
||||
upap_input,
|
||||
upap_protrej,
|
||||
upap_lowerup,
|
||||
upap_lowerdown,
|
||||
NULL,
|
||||
NULL,
|
||||
upap_printpkt,
|
||||
NULL,
|
||||
1,
|
||||
"PAP",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
upap_state upap[NUM_PPP]; /* UPAP state; one for each unit */
|
||||
|
||||
static void upap_timeout(void *);
|
||||
static void upap_reqtimeout(void *);
|
||||
static void upap_rauthreq(upap_state *, u_char *, int, int);
|
||||
static void upap_rauthack(upap_state *, u_char *, int, int);
|
||||
static void upap_rauthnak(upap_state *, u_char *, int, int);
|
||||
static void upap_sauthreq(upap_state *);
|
||||
static void upap_sresp(upap_state *, int, int, char *, int);
|
||||
|
||||
|
||||
/*
|
||||
* upap_init - Initialize a UPAP unit.
|
||||
*/
|
||||
static void
|
||||
upap_init(unit)
|
||||
int unit;
|
||||
{
|
||||
upap_state *u = &upap[unit];
|
||||
|
||||
u->us_unit = unit;
|
||||
u->us_user = NULL;
|
||||
u->us_userlen = 0;
|
||||
u->us_passwd = NULL;
|
||||
u->us_passwdlen = 0;
|
||||
u->us_clientstate = UPAPCS_INITIAL;
|
||||
u->us_serverstate = UPAPSS_INITIAL;
|
||||
u->us_id = 0;
|
||||
u->us_timeouttime = UPAP_DEFTIMEOUT;
|
||||
u->us_maxtransmits = 10;
|
||||
u->us_reqtimeout = UPAP_DEFREQTIME;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* upap_authwithpeer - Authenticate us with our peer (start client).
|
||||
*
|
||||
* Set new state and send authenticate's.
|
||||
*/
|
||||
void
|
||||
upap_authwithpeer(unit, user, password)
|
||||
int unit;
|
||||
char *user, *password;
|
||||
{
|
||||
upap_state *u = &upap[unit];
|
||||
|
||||
/* Save the username and password we're given */
|
||||
u->us_user = user;
|
||||
u->us_userlen = strlen(user);
|
||||
u->us_passwd = password;
|
||||
u->us_passwdlen = strlen(password);
|
||||
u->us_transmits = 0;
|
||||
|
||||
/* Lower layer up yet? */
|
||||
if (u->us_clientstate == UPAPCS_INITIAL ||
|
||||
u->us_clientstate == UPAPCS_PENDING) {
|
||||
u->us_clientstate = UPAPCS_PENDING;
|
||||
return;
|
||||
}
|
||||
|
||||
upap_sauthreq(u); /* Start protocol */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* upap_authpeer - Authenticate our peer (start server).
|
||||
*
|
||||
* Set new state.
|
||||
*/
|
||||
void
|
||||
upap_authpeer(unit)
|
||||
int unit;
|
||||
{
|
||||
upap_state *u = &upap[unit];
|
||||
|
||||
/* Lower layer up yet? */
|
||||
if (u->us_serverstate == UPAPSS_INITIAL ||
|
||||
u->us_serverstate == UPAPSS_PENDING) {
|
||||
u->us_serverstate = UPAPSS_PENDING;
|
||||
return;
|
||||
}
|
||||
|
||||
u->us_serverstate = UPAPSS_LISTEN;
|
||||
if (u->us_reqtimeout > 0)
|
||||
TIMEOUT(upap_reqtimeout, u, u->us_reqtimeout);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* upap_timeout - Retransmission timer for sending auth-reqs expired.
|
||||
*/
|
||||
static void
|
||||
upap_timeout(arg)
|
||||
void *arg;
|
||||
{
|
||||
upap_state *u = (upap_state *) arg;
|
||||
|
||||
if (u->us_clientstate != UPAPCS_AUTHREQ)
|
||||
return;
|
||||
|
||||
if (u->us_transmits >= u->us_maxtransmits) {
|
||||
/* give up in disgust */
|
||||
syslog(LOG_ERR, "No response to PAP authenticate-requests");
|
||||
u->us_clientstate = UPAPCS_BADAUTH;
|
||||
auth_withpeer_fail(u->us_unit, PPP_PAP);
|
||||
return;
|
||||
}
|
||||
|
||||
upap_sauthreq(u); /* Send Authenticate-Request */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* upap_reqtimeout - Give up waiting for the peer to send an auth-req.
|
||||
*/
|
||||
static void
|
||||
upap_reqtimeout(arg)
|
||||
void *arg;
|
||||
{
|
||||
upap_state *u = (upap_state *) arg;
|
||||
|
||||
if (u->us_serverstate != UPAPSS_LISTEN)
|
||||
return; /* huh?? */
|
||||
|
||||
auth_peer_fail(u->us_unit, PPP_PAP);
|
||||
u->us_serverstate = UPAPSS_BADAUTH;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* upap_lowerup - The lower layer is up.
|
||||
*
|
||||
* Start authenticating if pending.
|
||||
*/
|
||||
static void
|
||||
upap_lowerup(unit)
|
||||
int unit;
|
||||
{
|
||||
upap_state *u = &upap[unit];
|
||||
|
||||
if (u->us_clientstate == UPAPCS_INITIAL)
|
||||
u->us_clientstate = UPAPCS_CLOSED;
|
||||
else if (u->us_clientstate == UPAPCS_PENDING) {
|
||||
upap_sauthreq(u); /* send an auth-request */
|
||||
}
|
||||
|
||||
if (u->us_serverstate == UPAPSS_INITIAL)
|
||||
u->us_serverstate = UPAPSS_CLOSED;
|
||||
else if (u->us_serverstate == UPAPSS_PENDING) {
|
||||
u->us_serverstate = UPAPSS_LISTEN;
|
||||
if (u->us_reqtimeout > 0)
|
||||
TIMEOUT(upap_reqtimeout, u, u->us_reqtimeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* upap_lowerdown - The lower layer is down.
|
||||
*
|
||||
* Cancel all timeouts.
|
||||
*/
|
||||
static void
|
||||
upap_lowerdown(unit)
|
||||
int unit;
|
||||
{
|
||||
upap_state *u = &upap[unit];
|
||||
|
||||
if (u->us_clientstate == UPAPCS_AUTHREQ) /* Timeout pending? */
|
||||
UNTIMEOUT(upap_timeout, u); /* Cancel timeout */
|
||||
if (u->us_serverstate == UPAPSS_LISTEN && u->us_reqtimeout > 0)
|
||||
UNTIMEOUT(upap_reqtimeout, u);
|
||||
|
||||
u->us_clientstate = UPAPCS_INITIAL;
|
||||
u->us_serverstate = UPAPSS_INITIAL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* upap_protrej - Peer doesn't speak this protocol.
|
||||
*
|
||||
* This shouldn't happen. In any case, pretend lower layer went down.
|
||||
*/
|
||||
static void
|
||||
upap_protrej(unit)
|
||||
int unit;
|
||||
{
|
||||
upap_state *u = &upap[unit];
|
||||
|
||||
if (u->us_clientstate == UPAPCS_AUTHREQ) {
|
||||
syslog(LOG_ERR, "PAP authentication failed due to protocol-reject");
|
||||
auth_withpeer_fail(unit, PPP_PAP);
|
||||
}
|
||||
if (u->us_serverstate == UPAPSS_LISTEN) {
|
||||
syslog(LOG_ERR, "PAP authentication of peer failed (protocol-reject)");
|
||||
auth_peer_fail(unit, PPP_PAP);
|
||||
}
|
||||
upap_lowerdown(unit);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* upap_input - Input UPAP packet.
|
||||
*/
|
||||
static void
|
||||
upap_input(unit, inpacket, l)
|
||||
int unit;
|
||||
u_char *inpacket;
|
||||
int l;
|
||||
{
|
||||
upap_state *u = &upap[unit];
|
||||
u_char *inp;
|
||||
u_char code, id;
|
||||
int len;
|
||||
|
||||
/*
|
||||
* Parse header (code, id and length).
|
||||
* If packet too short, drop it.
|
||||
*/
|
||||
inp = inpacket;
|
||||
if (l < UPAP_HEADERLEN) {
|
||||
UPAPDEBUG((LOG_INFO, "pap_input: rcvd short header."));
|
||||
return;
|
||||
}
|
||||
GETCHAR(code, inp);
|
||||
GETCHAR(id, inp);
|
||||
GETSHORT(len, inp);
|
||||
if (len < UPAP_HEADERLEN) {
|
||||
UPAPDEBUG((LOG_INFO, "pap_input: rcvd illegal length."));
|
||||
return;
|
||||
}
|
||||
if (len > l) {
|
||||
UPAPDEBUG((LOG_INFO, "pap_input: rcvd short packet."));
|
||||
return;
|
||||
}
|
||||
len -= UPAP_HEADERLEN;
|
||||
|
||||
/*
|
||||
* Action depends on code.
|
||||
*/
|
||||
switch (code) {
|
||||
case UPAP_AUTHREQ:
|
||||
upap_rauthreq(u, inp, id, len);
|
||||
break;
|
||||
|
||||
case UPAP_AUTHACK:
|
||||
upap_rauthack(u, inp, id, len);
|
||||
break;
|
||||
|
||||
case UPAP_AUTHNAK:
|
||||
upap_rauthnak(u, inp, id, len);
|
||||
break;
|
||||
|
||||
default: /* XXX Need code reject */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* upap_rauth - Receive Authenticate.
|
||||
*/
|
||||
static void
|
||||
upap_rauthreq(u, inp, id, len)
|
||||
upap_state *u;
|
||||
u_char *inp;
|
||||
int id;
|
||||
int len;
|
||||
{
|
||||
u_char ruserlen, rpasswdlen;
|
||||
char *ruser, *rpasswd;
|
||||
int retcode;
|
||||
char *msg;
|
||||
int msglen;
|
||||
|
||||
UPAPDEBUG((LOG_INFO, "pap_rauth: Rcvd id %d.", id));
|
||||
|
||||
if (u->us_serverstate < UPAPSS_LISTEN)
|
||||
return;
|
||||
|
||||
/*
|
||||
* If we receive a duplicate authenticate-request, we are
|
||||
* supposed to return the same status as for the first request.
|
||||
*/
|
||||
if (u->us_serverstate == UPAPSS_OPEN) {
|
||||
upap_sresp(u, UPAP_AUTHACK, id, "", 0); /* return auth-ack */
|
||||
return;
|
||||
}
|
||||
if (u->us_serverstate == UPAPSS_BADAUTH) {
|
||||
upap_sresp(u, UPAP_AUTHNAK, id, "", 0); /* return auth-nak */
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse user/passwd.
|
||||
*/
|
||||
if (len < sizeof (u_char)) {
|
||||
UPAPDEBUG((LOG_INFO, "pap_rauth: rcvd short packet."));
|
||||
return;
|
||||
}
|
||||
GETCHAR(ruserlen, inp);
|
||||
len -= sizeof (u_char) + ruserlen + sizeof (u_char);
|
||||
if (len < 0) {
|
||||
UPAPDEBUG((LOG_INFO, "pap_rauth: rcvd short packet."));
|
||||
return;
|
||||
}
|
||||
ruser = (char *) inp;
|
||||
INCPTR(ruserlen, inp);
|
||||
GETCHAR(rpasswdlen, inp);
|
||||
if (len < rpasswdlen) {
|
||||
UPAPDEBUG((LOG_INFO, "pap_rauth: rcvd short packet."));
|
||||
return;
|
||||
}
|
||||
rpasswd = (char *) inp;
|
||||
|
||||
/*
|
||||
* Check the username and password given.
|
||||
*/
|
||||
retcode = check_passwd(u->us_unit, ruser, ruserlen, rpasswd,
|
||||
rpasswdlen, &msg, &msglen);
|
||||
BZERO(rpasswd, rpasswdlen);
|
||||
|
||||
upap_sresp(u, retcode, id, msg, msglen);
|
||||
|
||||
if (retcode == UPAP_AUTHACK) {
|
||||
u->us_serverstate = UPAPSS_OPEN;
|
||||
auth_peer_success(u->us_unit, PPP_PAP, ruser, ruserlen);
|
||||
} else {
|
||||
u->us_serverstate = UPAPSS_BADAUTH;
|
||||
auth_peer_fail(u->us_unit, PPP_PAP);
|
||||
}
|
||||
|
||||
if (u->us_reqtimeout > 0)
|
||||
UNTIMEOUT(upap_reqtimeout, u);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* upap_rauthack - Receive Authenticate-Ack.
|
||||
*/
|
||||
static void
|
||||
upap_rauthack(u, inp, id, len)
|
||||
upap_state *u;
|
||||
u_char *inp;
|
||||
int id;
|
||||
int len;
|
||||
{
|
||||
u_char msglen;
|
||||
char *msg;
|
||||
|
||||
UPAPDEBUG((LOG_INFO, "pap_rauthack: Rcvd id %d.", id));
|
||||
if (u->us_clientstate != UPAPCS_AUTHREQ) /* XXX */
|
||||
return;
|
||||
|
||||
/*
|
||||
* Parse message.
|
||||
*/
|
||||
if (len < sizeof (u_char)) {
|
||||
UPAPDEBUG((LOG_INFO, "pap_rauthack: rcvd short packet."));
|
||||
return;
|
||||
}
|
||||
GETCHAR(msglen, inp);
|
||||
len -= sizeof (u_char);
|
||||
if (len < msglen) {
|
||||
UPAPDEBUG((LOG_INFO, "pap_rauthack: rcvd short packet."));
|
||||
return;
|
||||
}
|
||||
msg = (char *) inp;
|
||||
PRINTMSG(msg, msglen);
|
||||
|
||||
u->us_clientstate = UPAPCS_OPEN;
|
||||
|
||||
auth_withpeer_success(u->us_unit, PPP_PAP);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* upap_rauthnak - Receive Authenticate-Nakk.
|
||||
*/
|
||||
static void
|
||||
upap_rauthnak(u, inp, id, len)
|
||||
upap_state *u;
|
||||
u_char *inp;
|
||||
int id;
|
||||
int len;
|
||||
{
|
||||
u_char msglen;
|
||||
char *msg;
|
||||
|
||||
UPAPDEBUG((LOG_INFO, "pap_rauthnak: Rcvd id %d.", id));
|
||||
if (u->us_clientstate != UPAPCS_AUTHREQ) /* XXX */
|
||||
return;
|
||||
|
||||
/*
|
||||
* Parse message.
|
||||
*/
|
||||
if (len < sizeof (u_char)) {
|
||||
UPAPDEBUG((LOG_INFO, "pap_rauthnak: rcvd short packet."));
|
||||
return;
|
||||
}
|
||||
GETCHAR(msglen, inp);
|
||||
len -= sizeof (u_char);
|
||||
if (len < msglen) {
|
||||
UPAPDEBUG((LOG_INFO, "pap_rauthnak: rcvd short packet."));
|
||||
return;
|
||||
}
|
||||
msg = (char *) inp;
|
||||
PRINTMSG(msg, msglen);
|
||||
|
||||
u->us_clientstate = UPAPCS_BADAUTH;
|
||||
|
||||
syslog(LOG_ERR, "PAP authentication failed");
|
||||
auth_withpeer_fail(u->us_unit, PPP_PAP);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* upap_sauthreq - Send an Authenticate-Request.
|
||||
*/
|
||||
static void
|
||||
upap_sauthreq(u)
|
||||
upap_state *u;
|
||||
{
|
||||
u_char *outp;
|
||||
int outlen;
|
||||
|
||||
outlen = UPAP_HEADERLEN + 2 * sizeof (u_char) +
|
||||
u->us_userlen + u->us_passwdlen;
|
||||
outp = outpacket_buf;
|
||||
|
||||
MAKEHEADER(outp, PPP_PAP);
|
||||
|
||||
PUTCHAR(UPAP_AUTHREQ, outp);
|
||||
PUTCHAR(++u->us_id, outp);
|
||||
PUTSHORT(outlen, outp);
|
||||
PUTCHAR(u->us_userlen, outp);
|
||||
BCOPY(u->us_user, outp, u->us_userlen);
|
||||
INCPTR(u->us_userlen, outp);
|
||||
PUTCHAR(u->us_passwdlen, outp);
|
||||
BCOPY(u->us_passwd, outp, u->us_passwdlen);
|
||||
|
||||
output(u->us_unit, outpacket_buf, outlen + PPP_HDRLEN);
|
||||
|
||||
UPAPDEBUG((LOG_INFO, "pap_sauth: Sent id %d.", u->us_id));
|
||||
|
||||
TIMEOUT(upap_timeout, u, u->us_timeouttime);
|
||||
++u->us_transmits;
|
||||
u->us_clientstate = UPAPCS_AUTHREQ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* upap_sresp - Send a response (ack or nak).
|
||||
*/
|
||||
static void
|
||||
upap_sresp(u, code, id, msg, msglen)
|
||||
upap_state *u;
|
||||
u_char code, id;
|
||||
char *msg;
|
||||
int msglen;
|
||||
{
|
||||
u_char *outp;
|
||||
int outlen;
|
||||
|
||||
outlen = UPAP_HEADERLEN + sizeof (u_char) + msglen;
|
||||
outp = outpacket_buf;
|
||||
MAKEHEADER(outp, PPP_PAP);
|
||||
|
||||
PUTCHAR(code, outp);
|
||||
PUTCHAR(id, outp);
|
||||
PUTSHORT(outlen, outp);
|
||||
PUTCHAR(msglen, outp);
|
||||
BCOPY(msg, outp, msglen);
|
||||
output(u->us_unit, outpacket_buf, outlen + PPP_HDRLEN);
|
||||
|
||||
UPAPDEBUG((LOG_INFO, "pap_sresp: Sent code %d, id %d.", code, id));
|
||||
}
|
||||
|
||||
/*
|
||||
* upap_printpkt - print the contents of a PAP packet.
|
||||
*/
|
||||
static char *upap_codenames[] = {
|
||||
"AuthReq", "AuthAck", "AuthNak"
|
||||
};
|
||||
|
||||
static int
|
||||
upap_printpkt(p, plen, printer, arg)
|
||||
u_char *p;
|
||||
int plen;
|
||||
void (*printer)(void *, char *, ...);
|
||||
void *arg;
|
||||
{
|
||||
int code, id, len;
|
||||
int mlen, ulen, wlen;
|
||||
char *user, *pwd, *msg;
|
||||
u_char *pstart;
|
||||
|
||||
if (plen < UPAP_HEADERLEN)
|
||||
return 0;
|
||||
pstart = p;
|
||||
GETCHAR(code, p);
|
||||
GETCHAR(id, p);
|
||||
GETSHORT(len, p);
|
||||
if (len < UPAP_HEADERLEN || len > plen)
|
||||
return 0;
|
||||
|
||||
if (code >= 1 && code <= sizeof(upap_codenames) / sizeof(char *))
|
||||
printer(arg, " %s", upap_codenames[code-1]);
|
||||
else
|
||||
printer(arg, " code=0x%x", code);
|
||||
printer(arg, " id=0x%x", id);
|
||||
len -= UPAP_HEADERLEN;
|
||||
switch (code) {
|
||||
case UPAP_AUTHREQ:
|
||||
if (len < 1)
|
||||
break;
|
||||
ulen = p[0];
|
||||
if (len < ulen + 2)
|
||||
break;
|
||||
wlen = p[ulen + 1];
|
||||
if (len < ulen + wlen + 2)
|
||||
break;
|
||||
user = (char *) (p + 1);
|
||||
pwd = (char *) (p + ulen + 2);
|
||||
p += ulen + wlen + 2;
|
||||
len -= ulen + wlen + 2;
|
||||
printer(arg, " user=");
|
||||
print_string(user, ulen, printer, arg);
|
||||
printer(arg, " password=");
|
||||
print_string(pwd, wlen, printer, arg);
|
||||
break;
|
||||
case UPAP_AUTHACK:
|
||||
case UPAP_AUTHNAK:
|
||||
if (len < 1)
|
||||
break;
|
||||
mlen = p[0];
|
||||
if (len < mlen + 1)
|
||||
break;
|
||||
msg = (char *) (p + 1);
|
||||
p += mlen + 1;
|
||||
len -= mlen + 1;
|
||||
printer(arg, " ");
|
||||
print_string(msg, mlen, printer, arg);
|
||||
break;
|
||||
}
|
||||
|
||||
/* print the rest of the bytes in the packet */
|
||||
for (; len > 0; --len) {
|
||||
GETCHAR(code, p);
|
||||
printer(arg, " %.2x", code);
|
||||
}
|
||||
|
||||
return p - pstart;
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
* upap.h - User/Password Authentication Protocol definitions.
|
||||
*
|
||||
* Copyright (c) 1989 Carnegie Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Carnegie Mellon University. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Packet header = Code, id, length.
|
||||
*/
|
||||
#define UPAP_HEADERLEN (sizeof (u_char) + sizeof (u_char) + sizeof (u_short))
|
||||
|
||||
|
||||
/*
|
||||
* UPAP codes.
|
||||
*/
|
||||
#define UPAP_AUTHREQ 1 /* Authenticate-Request */
|
||||
#define UPAP_AUTHACK 2 /* Authenticate-Ack */
|
||||
#define UPAP_AUTHNAK 3 /* Authenticate-Nak */
|
||||
|
||||
|
||||
/*
|
||||
* Each interface is described by upap structure.
|
||||
*/
|
||||
typedef struct upap_state {
|
||||
int us_unit; /* Interface unit number */
|
||||
char *us_user; /* User */
|
||||
int us_userlen; /* User length */
|
||||
char *us_passwd; /* Password */
|
||||
int us_passwdlen; /* Password length */
|
||||
int us_clientstate; /* Client state */
|
||||
int us_serverstate; /* Server state */
|
||||
u_char us_id; /* Current id */
|
||||
int us_timeouttime; /* Timeout (seconds) for auth-req retrans. */
|
||||
int us_transmits; /* Number of auth-reqs sent */
|
||||
int us_maxtransmits; /* Maximum number of auth-reqs to send */
|
||||
int us_reqtimeout; /* Time to wait for auth-req from peer */
|
||||
} upap_state;
|
||||
|
||||
|
||||
/*
|
||||
* Client states.
|
||||
*/
|
||||
#define UPAPCS_INITIAL 0 /* Connection down */
|
||||
#define UPAPCS_CLOSED 1 /* Connection up, haven't requested auth */
|
||||
#define UPAPCS_PENDING 2 /* Connection down, have requested auth */
|
||||
#define UPAPCS_AUTHREQ 3 /* We've sent an Authenticate-Request */
|
||||
#define UPAPCS_OPEN 4 /* We've received an Ack */
|
||||
#define UPAPCS_BADAUTH 5 /* We've received a Nak */
|
||||
|
||||
/*
|
||||
* Server states.
|
||||
*/
|
||||
#define UPAPSS_INITIAL 0 /* Connection down */
|
||||
#define UPAPSS_CLOSED 1 /* Connection up, haven't requested auth */
|
||||
#define UPAPSS_PENDING 2 /* Connection down, have requested auth */
|
||||
#define UPAPSS_LISTEN 3 /* Listening for an Authenticate */
|
||||
#define UPAPSS_OPEN 4 /* We've sent an Ack */
|
||||
#define UPAPSS_BADAUTH 5 /* We've sent a Nak */
|
||||
|
||||
|
||||
/*
|
||||
* Timeouts.
|
||||
*/
|
||||
#define UPAP_DEFTIMEOUT 3 /* Timeout (seconds) for retransmitting req */
|
||||
#define UPAP_DEFREQTIME 30 /* Time to wait for auth-req from peer */
|
||||
|
||||
extern upap_state upap[];
|
||||
|
||||
void upap_authwithpeer(int, char *, char *);
|
||||
void upap_authpeer(int);
|
||||
|
||||
extern struct protent pap_protent;
|
@ -1,6 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= pppstats
|
||||
MAN= pppstats.8
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,218 +0,0 @@
|
||||
.\" @(#) $FreeBSD$
|
||||
.TH PPPSTATS 8 "26 June 1995"
|
||||
.SH NAME
|
||||
pppstats \- print PPP statistics
|
||||
.SH SYNOPSIS
|
||||
.B pppstats
|
||||
[
|
||||
.B -a
|
||||
] [
|
||||
.B -v
|
||||
] [
|
||||
.B -r
|
||||
] [
|
||||
.B -z
|
||||
] [
|
||||
.B -c
|
||||
.I <count>
|
||||
] [
|
||||
.B -w
|
||||
.I <secs>
|
||||
] [
|
||||
.I interface
|
||||
]
|
||||
.ti 12
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B pppstats
|
||||
utility reports PPP-related statistics at regular intervals for the
|
||||
specified PPP interface. If the interface is unspecified, it will
|
||||
default to ppp0.
|
||||
The display is split horizontally
|
||||
into input and output sections containing columns of statistics
|
||||
describing the properties and volume of packets received and
|
||||
transmitted by the interface.
|
||||
.PP
|
||||
The options are as follows:
|
||||
.TP
|
||||
.B -a
|
||||
Display absolute values rather than deltas. With this option, all
|
||||
reports show statistics for the time since the link was initiated.
|
||||
Without this option, the second and subsequent reports show statistics
|
||||
for the time since the last report.
|
||||
.TP
|
||||
.B -c \fIcount
|
||||
Repeat the display
|
||||
.I count
|
||||
times. If this option is not specified, the default repeat count is 1
|
||||
if the
|
||||
.B -w
|
||||
option is not specified, otherwise infinity.
|
||||
.TP
|
||||
.B -r
|
||||
Display additional statistics summarizing the compression ratio
|
||||
achieved by the packet compression algorithm in use.
|
||||
.TP
|
||||
.B -v
|
||||
Display additional statistics relating to the performance of the Van
|
||||
Jacobson TCP header compression algorithm.
|
||||
.TP
|
||||
.B -w \fIwait
|
||||
Pause
|
||||
.I wait
|
||||
seconds between each display. If this option is not specified, the
|
||||
default interval is 5 seconds.
|
||||
.TP
|
||||
.B -z
|
||||
Instead of the standard display, show statistics indicating the
|
||||
performance of the packet compression algorithm in use.
|
||||
.PP
|
||||
The following fields are printed on the input side when the
|
||||
.B -z
|
||||
option is not used:
|
||||
.TP
|
||||
.B IN
|
||||
The total number of bytes received by this interface.
|
||||
.TP
|
||||
.B PACK
|
||||
The total number of packets received by this interface.
|
||||
.TP
|
||||
.B VJCOMP
|
||||
The number of header-compressed TCP packets received by this interface.
|
||||
.TP
|
||||
.B VJUNC
|
||||
The number of header-uncompressed TCP packets received by this
|
||||
interface. Not reported when the
|
||||
.B -r
|
||||
option is specified.
|
||||
.TP
|
||||
.B VJERR
|
||||
The number of corrupted or bogus header-compressed TCP packets
|
||||
received by this interface. Not reported when the
|
||||
.B -r
|
||||
option is specified.
|
||||
.TP
|
||||
.B VJTOSS
|
||||
The number of VJ header-compressed TCP packets dropped on reception by
|
||||
this interface because of preceding errors. Only reported when the
|
||||
.B -v
|
||||
option is specified.
|
||||
.TP
|
||||
.B NON-VJ
|
||||
The total number of non-TCP packets received by this interface.
|
||||
Only
|
||||
reported when the
|
||||
.B -v
|
||||
option is specified.
|
||||
.TP
|
||||
.B RATIO
|
||||
The compression ratio achieved for received packets by the
|
||||
packet compression scheme in use, defined as the uncompressed size
|
||||
divided by the compressed size.
|
||||
Only reported when the
|
||||
.B -r
|
||||
option is specified.
|
||||
.TP
|
||||
.B UBYTE
|
||||
The total number of bytes received, after decompression of compressed
|
||||
packets. Only reported when the
|
||||
.B -r
|
||||
option is specified.
|
||||
.PP
|
||||
The following fields are printed on the output side:
|
||||
.TP
|
||||
.B OUT
|
||||
The total number of bytes transmitted from this interface.
|
||||
.TP
|
||||
.B PACK
|
||||
The total number of packets transmitted from this interface.
|
||||
.TP
|
||||
.B VJCOMP
|
||||
The number of TCP packets transmitted from this interface with
|
||||
VJ-compressed TCP headers.
|
||||
.TP
|
||||
.B VJUNC
|
||||
The number of TCP packets transmitted from this interface with
|
||||
VJ-uncompressed TCP headers.
|
||||
Not reported when the
|
||||
.B -r
|
||||
option is specified.
|
||||
.TP
|
||||
.B NON-VJ
|
||||
The total number of non-TCP packets transmitted from this interface.
|
||||
Not reported when the
|
||||
.B -r
|
||||
option is specified.
|
||||
.TP
|
||||
.B VJSRCH
|
||||
The number of searches for the cached header entry for a VJ header
|
||||
compressed TCP packet. Only reported when the
|
||||
.B -v
|
||||
option is specified.
|
||||
.TP
|
||||
.B VJMISS
|
||||
The number of failed searches for the cached header entry for a
|
||||
VJ header compressed TCP packet. Only reported when the
|
||||
.B -v
|
||||
option is specified.
|
||||
.TP
|
||||
.B RATIO
|
||||
The compression ratio achieved for transmitted packets by the
|
||||
packet compression scheme in use, defined as the size
|
||||
before compression divided by the compressed size.
|
||||
Only reported when the
|
||||
.B -r
|
||||
option is specified.
|
||||
.TP
|
||||
.B UBYTE
|
||||
The total number of bytes to be transmitted, before packet compression
|
||||
is applied. Only reported when the
|
||||
.B -r
|
||||
option is specified.
|
||||
.PP
|
||||
When the
|
||||
.B -z
|
||||
option is specified,
|
||||
.B pppstats
|
||||
instead displays the following fields, relating to the packet
|
||||
compression algorithm currently in use. If packet compression is not
|
||||
in use, these fields will all display zeroes. The fields displayed on
|
||||
the input side are:
|
||||
.TP
|
||||
.B COMPRESSED BYTE
|
||||
The number of bytes of compressed packets received.
|
||||
.TP
|
||||
.B COMPRESSED PACK
|
||||
The number of compressed packets received.
|
||||
.TP
|
||||
.B INCOMPRESSIBLE BYTE
|
||||
The number of bytes of incompressible packets (that is, those which
|
||||
were transmitted in uncompressed form) received.
|
||||
.TP
|
||||
.B INCOMPRESSIBLE PACK
|
||||
The number of incompressible packets received.
|
||||
.TP
|
||||
.B COMP RATIO
|
||||
The recent compression ratio for incoming packets, defined as the
|
||||
uncompressed size divided by the compressed size (including both
|
||||
compressible and incompressible packets).
|
||||
.PP
|
||||
The fields displayed on the output side are:
|
||||
.TP
|
||||
.B COMPRESSED BYTE
|
||||
The number of bytes of compressed packets transmitted.
|
||||
.TP
|
||||
.B COMPRESSED PACK
|
||||
The number of compressed packets transmitted.
|
||||
.TP
|
||||
.B INCOMPRESSIBLE BYTE
|
||||
The number of bytes of incompressible packets transmitted (that is,
|
||||
those which were transmitted in uncompressed form).
|
||||
.TP
|
||||
.B INCOMPRESSIBLE PACK
|
||||
The number of incompressible packets transmitted.
|
||||
.TP
|
||||
.B COMP RATIO
|
||||
The recent compression ratio for outgoing packets.
|
||||
.SH SEE ALSO
|
||||
pppd(8)
|
@ -1,519 +0,0 @@
|
||||
/*
|
||||
* print PPP statistics:
|
||||
* pppstats [-a|-d] [-v|-r|-z] [-c count] [-w wait] [interface]
|
||||
*
|
||||
* -a Show absolute values rather than deltas
|
||||
* -d Show data rate (kB/s) rather than bytes
|
||||
* -v Show more stats for VJ TCP header compression
|
||||
* -r Show compression ratio
|
||||
* -z Show compression statistics instead of default display
|
||||
*
|
||||
* History:
|
||||
* perkins@cps.msu.edu: Added compression statistics and alternate
|
||||
* display. 11/94
|
||||
* Brad Parker (brad@cayman.com) 6/92
|
||||
*
|
||||
* from the original "slstats" by Van Jacobson
|
||||
*
|
||||
* Copyright (c) 1989 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Berkeley. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] = "$FreeBSD$";
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <net/ppp_defs.h>
|
||||
|
||||
#ifndef STREAMS
|
||||
#include <sys/socket.h> /* *BSD, Linux, NeXT, Ultrix etc. */
|
||||
#include <net/if.h>
|
||||
#include <net/if_ppp.h>
|
||||
|
||||
#else /* STREAMS */
|
||||
#include <sys/stropts.h> /* SVR4, Solaris 2, SunOS 4, OSF/1, etc. */
|
||||
#include <net/pppio.h>
|
||||
|
||||
#endif /* STREAMS */
|
||||
|
||||
int vflag, rflag, zflag; /* select type of display */
|
||||
int aflag; /* print absolute values, not deltas */
|
||||
int dflag; /* print data rates, not bytes */
|
||||
int interval, count;
|
||||
int infinite;
|
||||
int unit;
|
||||
int s; /* socket or /dev/ppp file descriptor */
|
||||
int signalled; /* set if alarm goes off "early" */
|
||||
char *progname;
|
||||
char *interface;
|
||||
|
||||
#if defined(SUNOS4) || defined(ULTRIX) || defined(NeXT)
|
||||
extern int optind;
|
||||
extern char *optarg;
|
||||
#endif
|
||||
|
||||
static void usage(void);
|
||||
static void catchalarm(int);
|
||||
static void get_ppp_stats(struct ppp_stats *);
|
||||
static void get_ppp_cstats(struct ppp_comp_stats *);
|
||||
static void intpr(void);
|
||||
|
||||
int main(int, char *argv[]);
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr, "usage: %s [-a|-d] [-v|-r|-z] [-c count] [-w wait] [interface]\n",
|
||||
progname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Called if an interval expires before intpr has completed a loop.
|
||||
* Sets a flag to not wait for the alarm.
|
||||
*/
|
||||
static void
|
||||
catchalarm(arg)
|
||||
int arg;
|
||||
{
|
||||
signalled = 1;
|
||||
}
|
||||
|
||||
|
||||
#ifndef STREAMS
|
||||
static void
|
||||
get_ppp_stats(curp)
|
||||
struct ppp_stats *curp;
|
||||
{
|
||||
struct ifpppstatsreq req;
|
||||
|
||||
memset (&req, 0, sizeof (req));
|
||||
|
||||
#ifdef _linux_
|
||||
req.stats_ptr = (caddr_t) &req.stats;
|
||||
#undef ifr_name
|
||||
#define ifr_name ifr__name
|
||||
#endif
|
||||
|
||||
strncpy(req.ifr_name, interface, sizeof(req.ifr_name));
|
||||
if (ioctl(s, SIOCGPPPSTATS, &req) < 0) {
|
||||
fprintf(stderr, "%s: ", progname);
|
||||
if (errno == ENOTTY)
|
||||
fprintf(stderr, "kernel support missing\n");
|
||||
else
|
||||
perror("couldn't get PPP statistics");
|
||||
exit(1);
|
||||
}
|
||||
*curp = req.stats;
|
||||
}
|
||||
|
||||
static void
|
||||
get_ppp_cstats(csp)
|
||||
struct ppp_comp_stats *csp;
|
||||
{
|
||||
struct ifpppcstatsreq creq;
|
||||
|
||||
memset (&creq, 0, sizeof (creq));
|
||||
|
||||
#ifdef _linux_
|
||||
creq.stats_ptr = (caddr_t) &creq.stats;
|
||||
#undef ifr_name
|
||||
#define ifr_name ifr__name
|
||||
#endif
|
||||
|
||||
strncpy(creq.ifr_name, interface, sizeof(creq.ifr_name));
|
||||
if (ioctl(s, SIOCGPPPCSTATS, &creq) < 0) {
|
||||
fprintf(stderr, "%s: ", progname);
|
||||
if (errno == ENOTTY) {
|
||||
fprintf(stderr, "no kernel compression support\n");
|
||||
if (zflag)
|
||||
exit(1);
|
||||
rflag = 0;
|
||||
} else {
|
||||
perror("couldn't get PPP compression stats");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _linux_
|
||||
if (creq.stats.c.bytes_out == 0)
|
||||
creq.stats.c.ratio = 0.0;
|
||||
else
|
||||
creq.stats.c.ratio = (double) creq.stats.c.in_count /
|
||||
(double) creq.stats.c.bytes_out;
|
||||
|
||||
if (creq.stats.d.bytes_out == 0)
|
||||
creq.stats.d.ratio = 0.0;
|
||||
else
|
||||
creq.stats.d.ratio = (double) creq.stats.d.in_count /
|
||||
(double) creq.stats.d.bytes_out;
|
||||
#endif
|
||||
|
||||
*csp = creq.stats;
|
||||
}
|
||||
|
||||
#else /* STREAMS */
|
||||
|
||||
int
|
||||
strioctl(fd, cmd, ptr, ilen, olen)
|
||||
int fd, cmd, ilen, olen;
|
||||
char *ptr;
|
||||
{
|
||||
struct strioctl str;
|
||||
|
||||
str.ic_cmd = cmd;
|
||||
str.ic_timout = 0;
|
||||
str.ic_len = ilen;
|
||||
str.ic_dp = ptr;
|
||||
if (ioctl(fd, I_STR, &str) == -1)
|
||||
return -1;
|
||||
if (str.ic_len != olen)
|
||||
fprintf(stderr, "strioctl: expected %d bytes, got %d for cmd %x\n",
|
||||
olen, str.ic_len, cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
get_ppp_stats(curp)
|
||||
struct ppp_stats *curp;
|
||||
{
|
||||
if (strioctl(s, PPPIO_GETSTAT, curp, 0, sizeof(*curp)) < 0) {
|
||||
fprintf(stderr, "%s: ", progname);
|
||||
if (errno == EINVAL)
|
||||
fprintf(stderr, "kernel support missing\n");
|
||||
else
|
||||
perror("couldn't get PPP statistics");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
get_ppp_cstats(csp)
|
||||
struct ppp_comp_stats *csp;
|
||||
{
|
||||
if (strioctl(s, PPPIO_GETCSTAT, csp, 0, sizeof(*csp)) < 0) {
|
||||
fprintf(stderr, "%s: ", progname);
|
||||
if (errno == ENOTTY) {
|
||||
fprintf(stderr, "no kernel compression support\n");
|
||||
if (zflag)
|
||||
exit(1);
|
||||
rflag = 0;
|
||||
} else {
|
||||
perror("couldn't get PPP compression statistics");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* STREAMS */
|
||||
|
||||
#define MAX0(a) ((int)(a) > 0? (a): 0)
|
||||
#define V(offset) MAX0(cur.offset - old.offset)
|
||||
#define W(offset) MAX0(ccs.offset - ocs.offset)
|
||||
|
||||
#define RATIO(c, i, u) ((c) == 0? 1.0: (u) / ((double)(c) + (i)))
|
||||
#define CRATE(x) RATIO(W(x.comp_bytes), W(x.inc_bytes), W(x.unc_bytes))
|
||||
|
||||
#define KBPS(n) ((n) / (interval * 1000.0))
|
||||
|
||||
/*
|
||||
* Print a running summary of interface statistics.
|
||||
* Repeat display every interval seconds, showing statistics
|
||||
* collected over that interval. Assumes that interval is non-zero.
|
||||
* First line printed is cumulative.
|
||||
*/
|
||||
static void
|
||||
intpr()
|
||||
{
|
||||
register int line = 0;
|
||||
sigset_t oldmask, mask;
|
||||
char *bunit;
|
||||
int ratef = 0;
|
||||
struct ppp_stats cur, old;
|
||||
struct ppp_comp_stats ccs, ocs;
|
||||
|
||||
memset(&old, 0, sizeof(old));
|
||||
memset(&ocs, 0, sizeof(ocs));
|
||||
|
||||
while (1) {
|
||||
get_ppp_stats(&cur);
|
||||
if (zflag || rflag)
|
||||
get_ppp_cstats(&ccs);
|
||||
|
||||
(void)signal(SIGALRM, catchalarm);
|
||||
signalled = 0;
|
||||
(void)alarm(interval);
|
||||
|
||||
if ((line % 20) == 0) {
|
||||
if (zflag) {
|
||||
printf("IN: COMPRESSED INCOMPRESSIBLE COMP | ");
|
||||
printf("OUT: COMPRESSED INCOMPRESSIBLE COMP\n");
|
||||
bunit = dflag? "KB/S": "BYTE";
|
||||
printf(" %s PACK %s PACK RATIO | ", bunit, bunit);
|
||||
printf(" %s PACK %s PACK RATIO", bunit, bunit);
|
||||
} else {
|
||||
printf("%8.8s %6.6s %6.6s",
|
||||
"IN", "PACK", "VJCOMP");
|
||||
|
||||
if (!rflag)
|
||||
printf(" %6.6s %6.6s", "VJUNC", "VJERR");
|
||||
if (vflag)
|
||||
printf(" %6.6s %6.6s", "VJTOSS", "NON-VJ");
|
||||
if (rflag)
|
||||
printf(" %6.6s %6.6s", "RATIO", "UBYTE");
|
||||
printf(" | %8.8s %6.6s %6.6s",
|
||||
"OUT", "PACK", "VJCOMP");
|
||||
|
||||
if (!rflag)
|
||||
printf(" %6.6s %6.6s", "VJUNC", "NON-VJ");
|
||||
if (vflag)
|
||||
printf(" %6.6s %6.6s", "VJSRCH", "VJMISS");
|
||||
if (rflag)
|
||||
printf(" %6.6s %6.6s", "RATIO", "UBYTE");
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
if (zflag) {
|
||||
if (ratef) {
|
||||
printf("%8.3f %6u %8.3f %6u %6.2f",
|
||||
KBPS(W(d.comp_bytes)),
|
||||
W(d.comp_packets),
|
||||
KBPS(W(d.inc_bytes)),
|
||||
W(d.inc_packets),
|
||||
ccs.d.ratio / 256.0);
|
||||
printf(" | %8.3f %6u %8.3f %6u %6.2f",
|
||||
KBPS(W(c.comp_bytes)),
|
||||
W(c.comp_packets),
|
||||
KBPS(W(c.inc_bytes)),
|
||||
W(c.inc_packets),
|
||||
ccs.c.ratio / 256.0);
|
||||
} else {
|
||||
printf("%8u %6u %8u %6u %6.2f",
|
||||
W(d.comp_bytes),
|
||||
W(d.comp_packets),
|
||||
W(d.inc_bytes),
|
||||
W(d.inc_packets),
|
||||
ccs.d.ratio / 256.0);
|
||||
printf(" | %8u %6u %8u %6u %6.2f",
|
||||
W(c.comp_bytes),
|
||||
W(c.comp_packets),
|
||||
W(c.inc_bytes),
|
||||
W(c.inc_packets),
|
||||
ccs.c.ratio / 256.0);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (ratef)
|
||||
printf("%8.3f", KBPS(V(p.ppp_ibytes)));
|
||||
else
|
||||
printf("%8u", V(p.ppp_ibytes));
|
||||
printf(" %6u %6u",
|
||||
V(p.ppp_ipackets),
|
||||
V(vj.vjs_compressedin));
|
||||
if (!rflag)
|
||||
printf(" %6u %6u",
|
||||
V(vj.vjs_uncompressedin),
|
||||
V(vj.vjs_errorin));
|
||||
if (vflag)
|
||||
printf(" %6u %6u",
|
||||
V(vj.vjs_tossed),
|
||||
V(p.ppp_ipackets) - V(vj.vjs_compressedin)
|
||||
- V(vj.vjs_uncompressedin) - V(vj.vjs_errorin));
|
||||
if (rflag) {
|
||||
printf(" %6.2f ", CRATE(d));
|
||||
if (ratef)
|
||||
printf("%6.2f", KBPS(W(d.unc_bytes)));
|
||||
else
|
||||
printf("%6u", W(d.unc_bytes));
|
||||
}
|
||||
if (ratef)
|
||||
printf(" | %8.3f", KBPS(V(p.ppp_obytes)));
|
||||
else
|
||||
printf(" | %8u", V(p.ppp_obytes));
|
||||
printf(" %6u %6u",
|
||||
V(p.ppp_opackets),
|
||||
V(vj.vjs_compressed));
|
||||
if (!rflag)
|
||||
printf(" %6u %6u",
|
||||
V(vj.vjs_packets) - V(vj.vjs_compressed),
|
||||
V(p.ppp_opackets) - V(vj.vjs_packets));
|
||||
if (vflag)
|
||||
printf(" %6u %6u",
|
||||
V(vj.vjs_searches),
|
||||
V(vj.vjs_misses));
|
||||
if (rflag) {
|
||||
printf(" %6.2f ", CRATE(c));
|
||||
if (ratef)
|
||||
printf("%6.2f", KBPS(W(c.unc_bytes)));
|
||||
else
|
||||
printf("%6u", W(c.unc_bytes));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
line++;
|
||||
|
||||
count--;
|
||||
if (!infinite && !count)
|
||||
break;
|
||||
|
||||
sigemptyset(&mask);
|
||||
sigaddset(&mask, SIGALRM);
|
||||
sigprocmask(SIG_BLOCK, &mask, &oldmask);
|
||||
if (!signalled) {
|
||||
sigemptyset(&mask);
|
||||
sigsuspend(&mask);
|
||||
}
|
||||
sigprocmask(SIG_SETMASK, &oldmask, NULL);
|
||||
signalled = 0;
|
||||
(void)alarm(interval);
|
||||
|
||||
if (!aflag) {
|
||||
old = cur;
|
||||
ocs = ccs;
|
||||
ratef = dflag;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int c;
|
||||
#ifdef STREAMS
|
||||
char *dev;
|
||||
#endif
|
||||
|
||||
interface = "ppp0";
|
||||
if ((progname = strrchr(argv[0], '/')) == NULL)
|
||||
progname = argv[0];
|
||||
else
|
||||
++progname;
|
||||
|
||||
while ((c = getopt(argc, argv, "advrzc:w:")) != -1) {
|
||||
switch (c) {
|
||||
case 'a':
|
||||
++aflag;
|
||||
break;
|
||||
case 'd':
|
||||
++dflag;
|
||||
break;
|
||||
case 'v':
|
||||
++vflag;
|
||||
break;
|
||||
case 'r':
|
||||
++rflag;
|
||||
break;
|
||||
case 'z':
|
||||
++zflag;
|
||||
break;
|
||||
case 'c':
|
||||
count = atoi(optarg);
|
||||
if (count <= 0)
|
||||
usage();
|
||||
break;
|
||||
case 'w':
|
||||
interval = atoi(optarg);
|
||||
if (interval <= 0)
|
||||
usage();
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (!interval && count)
|
||||
interval = 5;
|
||||
if (interval && !count)
|
||||
infinite = 1;
|
||||
if (!interval && !count)
|
||||
count = 1;
|
||||
if (aflag)
|
||||
dflag = 0;
|
||||
|
||||
if (argc > 1)
|
||||
usage();
|
||||
if (argc > 0)
|
||||
interface = argv[0];
|
||||
|
||||
if (sscanf(interface, "ppp%d", &unit) != 1) {
|
||||
fprintf(stderr, "%s: invalid interface '%s' specified\n",
|
||||
progname, interface);
|
||||
}
|
||||
|
||||
#ifndef STREAMS
|
||||
{
|
||||
struct ifreq ifr;
|
||||
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
fprintf(stderr, "%s: ", progname);
|
||||
perror("couldn't create IP socket");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef _linux_
|
||||
#undef ifr_name
|
||||
#define ifr_name ifr_ifrn.ifrn_name
|
||||
#endif
|
||||
strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
|
||||
if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
|
||||
fprintf(stderr, "%s: nonexistent interface '%s' specified\n",
|
||||
progname, interface);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
#else /* STREAMS */
|
||||
#ifdef __osf__
|
||||
dev = "/dev/streams/ppp";
|
||||
#else
|
||||
dev = "/dev/ppp";
|
||||
#endif
|
||||
if ((s = open(dev, O_RDONLY)) < 0) {
|
||||
fprintf(stderr, "%s: couldn't open ", progname);
|
||||
perror(dev);
|
||||
exit(1);
|
||||
}
|
||||
if (strioctl(s, PPPIO_ATTACH, &unit, sizeof(int), 0) < 0) {
|
||||
fprintf(stderr, "%s: ppp%d is not available\n", progname, unit);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#endif /* STREAMS */
|
||||
|
||||
intpr();
|
||||
exit(0);
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 7/19/93
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= sliplogin
|
||||
MAN= sliplogin.8
|
||||
BINOWN= root
|
||||
BINGRP= network
|
||||
BINMODE=4550
|
||||
PRECIOUSPROG=
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,44 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* From: @(#)pathnames.h 8.1 (Berkeley) 6/6/93
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef COMPAT
|
||||
#include <paths.h>
|
||||
#else
|
||||
#define _PATH_DEVNULL "/dev/null"
|
||||
#endif
|
||||
|
||||
#define _PATH_ACCESS "/etc/sliphome/slip.hosts"
|
||||
#define _PATH_SLPARMS "/etc/sliphome/slip.slparms"
|
||||
#define _PATH_SLIP_LOGIN "/etc/sliphome/slip.login"
|
||||
#define _PATH_SLIP_LOGOUT "/etc/sliphome/slip.logout"
|
||||
#define _PATH_DEBUG "/tmp/sliplogin.XXXXXX"
|
||||
|
@ -1,317 +0,0 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)sliplogin.8 8.2 (Berkeley) 1/5/94
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd January 5, 1994
|
||||
.Dt SLIPLOGIN 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm sliplogin
|
||||
.Nd attach a serial line network interface
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Ar loginname Op Ar device
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility is used to turn the terminal line on standard input (or
|
||||
.Ar device )
|
||||
into a Serial Line IP
|
||||
.Pq Tn SLIP
|
||||
link to a remote host.
|
||||
To do this, the program
|
||||
searches the file
|
||||
.Pa /etc/sliphome/slip.hosts
|
||||
for an entry matching
|
||||
.Ar loginname
|
||||
(which defaults to the current login name if omitted).
|
||||
If a matching entry is found, the line is configured appropriately
|
||||
for slip (8-bit transparent i/o) and converted to
|
||||
.Tn SLIP
|
||||
line discipline using the optional line discipline parameters.
|
||||
.Pp
|
||||
The optional line discipline parameters consist of one or more of
|
||||
the following;
|
||||
.Sq normal ,
|
||||
.Sq compress ,
|
||||
.Sq noicmp ,
|
||||
or
|
||||
.Sq autocomp
|
||||
which correspond respectively to
|
||||
.Sq use normal line discipline
|
||||
(no header compression),
|
||||
.Sq enable VJ header compression ,
|
||||
.Sq throw away ICMP packets ,
|
||||
and
|
||||
.Sq auto enable VJ header compression
|
||||
(only if the remote end of the link also supports it).
|
||||
.Pp
|
||||
Then a shell script is invoked to initialize the slip
|
||||
interface with the appropriate local and remote
|
||||
.Tn IP
|
||||
address,
|
||||
netmask, etc.
|
||||
.Pp
|
||||
The usual initialization script is
|
||||
.Pa /etc/sliphome/slip.login
|
||||
but, if particular hosts need special initialization, the file
|
||||
.Pa /etc/sliphome/slip.login. Ns Ar loginname
|
||||
will be executed instead if it exists.
|
||||
The script is invoked with the parameters
|
||||
.Bl -tag -width slipunit
|
||||
.It Em slipunit
|
||||
The unit number of the slip interface assigned to this line.
|
||||
E.g.,
|
||||
.Sy 0
|
||||
for
|
||||
.Sy sl0 .
|
||||
.It Em speed
|
||||
The speed of the line.
|
||||
.It Em args
|
||||
The arguments from the
|
||||
.Pa /etc/sliphome/slip.hosts
|
||||
entry, in order starting with
|
||||
.Ar loginname .
|
||||
.El
|
||||
.Pp
|
||||
Only the super-user may attach a network interface.
|
||||
The interface is
|
||||
automatically detached when the other end hangs up or the
|
||||
.Nm
|
||||
process dies.
|
||||
If the kernel slip
|
||||
module has been configured for it, all routes through that interface will
|
||||
also disappear at the same time.
|
||||
If there is other processing a site
|
||||
would like done on hangup, the file
|
||||
.Pa /etc/sliphome/slip.logout
|
||||
or
|
||||
.Pa /etc/sliphome/slip.logout. Ns Ar loginname
|
||||
is executed if it exists.
|
||||
It is given the same arguments as the login script.
|
||||
.Ss Format of /etc/sliphome/slip.hosts
|
||||
Comments (lines starting with a `#') and blank lines (or started
|
||||
with space) are ignored.
|
||||
Other lines must start with a
|
||||
.Ar loginname
|
||||
but the remaining arguments can be whatever is appropriate for the
|
||||
.Pa slip.login
|
||||
file that will be executed for that name.
|
||||
Arguments are separated by white space and follow normal
|
||||
.Xr sh 1
|
||||
quoting conventions (however,
|
||||
.Ar loginname
|
||||
cannot be quoted).
|
||||
Usually, lines have the form
|
||||
.Bd -literal -offset indent
|
||||
loginname local-address remote-address netmask opt-args
|
||||
.Ed
|
||||
.Pp
|
||||
where
|
||||
.Em local-address
|
||||
and
|
||||
.Em remote-address
|
||||
are the IP host names or addresses of the local and remote ends of the
|
||||
slip line and
|
||||
.Em netmask
|
||||
is the appropriate IP netmask.
|
||||
These arguments are passed
|
||||
directly to
|
||||
.Xr ifconfig 8 .
|
||||
.Em Opt-args
|
||||
are optional arguments used to configure the line.
|
||||
.Sh FreeBSD Additions
|
||||
An additional SLIP configuration file (if present) is
|
||||
.Pa /etc/sliphome/slip.slparms .
|
||||
If particular hosts need different configurations, the file
|
||||
.Pa /etc/sliphome/slip.slparms. Ns Ar loginname
|
||||
will be parsed instead if it exists.
|
||||
.Ss Format of /etc/sliphome/slip.slparms*
|
||||
Comments (lines starting with a `#') and blank lines (or started with
|
||||
space) are ignored.
|
||||
This file contains from one to three numeric parameters separated with spaces,
|
||||
in order:
|
||||
.Ar keepalive ,
|
||||
.Ar outfill
|
||||
and
|
||||
.Ar slunit .
|
||||
.Bl -tag -width keepalive
|
||||
.It Ar keepalive
|
||||
Set SLIP "keep alive" timeout in seconds.
|
||||
If FRAME_END is not received in
|
||||
this amount of time,
|
||||
.Nm
|
||||
closes the line and exits.
|
||||
The default value is no timeout (zero).
|
||||
.It Ar outfill
|
||||
Set SLIP "out fill" timeout in seconds.
|
||||
It forces at least one FRAME_END
|
||||
to be sent during this time period, which is necessary for the "keep alive"
|
||||
timeout on the remote side.
|
||||
The default value is no timeout (zero).
|
||||
.It Ar slunit
|
||||
Set the SLIP unit number directly.
|
||||
Use with caution, because no check is made
|
||||
for two interfaces with same number.
|
||||
By default sliplogin dynamically assigns the unit number.
|
||||
.El
|
||||
.Pp
|
||||
If latter two parameters are omitted, they will not affect the
|
||||
corresponding SLIP configuration.
|
||||
If any of first two parameters is equal to zero, it will not affect
|
||||
the corresponding SLIP configuration.
|
||||
.Sh FILES
|
||||
.Bl -tag -width indent
|
||||
.It Pa /etc/sliphome/slip.hosts
|
||||
list of host login names and parameters.
|
||||
.It Pa /etc/sliphome/slip.login
|
||||
script executed when a connection is made.
|
||||
.It Pa /etc/sliphome/slip.login. Ns Ar loginname
|
||||
script executed when a connection is made by
|
||||
.Ar loginname .
|
||||
.It Pa /etc/sliphome/slip.logout
|
||||
script executed when a connection is lost.
|
||||
.It Pa /etc/sliphome/slip.logout. Ns Ar loginname
|
||||
script executed when a connection is lost by
|
||||
.Ar loginname .
|
||||
.It Pa /etc/sliphome/slip.slparms
|
||||
extra parameters file.
|
||||
.It Pa /etc/sliphome/slip.slparms. Ns Ar loginname
|
||||
extra parameters file for
|
||||
.Ar loginname .
|
||||
.It Pa /var/run/ Ns Ar ttyXn Ns Pa .if
|
||||
contains the name of the network interface used by the sliplogin process on
|
||||
.Ar ttyXn .
|
||||
.It Pa /var/run/ Ns Ar slX Ns Pa .pid
|
||||
contains the PID of the sliplogin process which is using interface
|
||||
.Ar slX .
|
||||
.El
|
||||
.Sh EXAMPLES
|
||||
The normal use of
|
||||
.Nm
|
||||
is to create a
|
||||
.Pa /etc/passwd
|
||||
entry for each legal, remote slip site with
|
||||
.Nm
|
||||
as the shell for that entry.
|
||||
E.g.,
|
||||
.Bd -literal
|
||||
Sfoo:ikhuy6:2010:1:slip line to foo:/tmp:/usr/sbin/sliplogin
|
||||
.Ed
|
||||
.Pp
|
||||
(Our convention is to name the account used by remote host
|
||||
.Ar hostname
|
||||
as
|
||||
.Em Shostname . )
|
||||
Then an entry is added to
|
||||
.Pa slip.hosts
|
||||
that looks like:
|
||||
.Pp
|
||||
.Bd -literal -offset indent -compact
|
||||
Sfoo `hostname` foo netmask
|
||||
.Ed
|
||||
.Pp
|
||||
where
|
||||
.Em `hostname`
|
||||
will be evaluated by
|
||||
.Xr sh 1
|
||||
to the local host name and
|
||||
.Em netmask
|
||||
is the local host IP netmask.
|
||||
.Pp
|
||||
Note that
|
||||
.Nm
|
||||
must be setuid to root and, while not a security hole, moral defectives
|
||||
can use it to place terminal lines in an unusable state and/or deny
|
||||
access to legitimate users of a remote slip line.
|
||||
To prevent this,
|
||||
.Nm
|
||||
is installed as user
|
||||
.Em root ,
|
||||
group
|
||||
.Em network
|
||||
and mode 4550 so that only members of group
|
||||
.Em network
|
||||
may run
|
||||
.Nm .
|
||||
The system administrator should make sure that all legitimate users
|
||||
are a member of the correct group.
|
||||
.Sh DIAGNOSTICS
|
||||
The
|
||||
.Nm
|
||||
utility logs various information to the system log daemon,
|
||||
.Xr syslogd 8 ,
|
||||
with a facility code of
|
||||
.Em daemon .
|
||||
The messages are listed here, grouped by severity level.
|
||||
.Pp
|
||||
.Sy Error Severity
|
||||
.Bl -tag -width Ds -compact
|
||||
.It Sy ioctl (TCGETS): Em reason
|
||||
A
|
||||
.Dv TCGETS
|
||||
.Fn ioctl
|
||||
to get the line parameters failed.
|
||||
.Pp
|
||||
.It Sy ioctl (TCSETS): Em reason
|
||||
A
|
||||
.Dv TCSETS
|
||||
.Fn ioctl
|
||||
to set the line parameters failed.
|
||||
.Pp
|
||||
.It Sy /etc/sliphome/slip.hosts: Em reason
|
||||
The
|
||||
.Pa /etc/sliphome/slip.hosts
|
||||
file could not be opened.
|
||||
.Pp
|
||||
.It Sy access denied for Em user
|
||||
No entry for
|
||||
.Em user
|
||||
was found in
|
||||
.Pa /etc/sliphome/slip.hosts .
|
||||
.El
|
||||
.Pp
|
||||
.Sy Notice Severity
|
||||
.Bl -tag -width Ds -compact
|
||||
.It Sy "attaching slip unit" Em unit Sy for Ar loginname
|
||||
.Tn SLIP
|
||||
unit
|
||||
.Em unit
|
||||
was successfully attached.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr slattach 8 ,
|
||||
.Xr syslogd 8
|
||||
.Pp
|
||||
.Pa /usr/share/examples/sliplogin
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
utility appeared in
|
||||
.Bx 4.3 Reno .
|
@ -1,544 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1990, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)sliplogin.c 8.2 (Berkeley) 2/1/94";
|
||||
static char rscid[] = "@(#)$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* sliplogin.c
|
||||
* [MUST BE RUN SUID, SLOPEN DOES A SUSER()!]
|
||||
*
|
||||
* This program initializes its own tty port to be an async TCP/IP interface.
|
||||
* It sets the line discipline to slip, invokes a shell script to initialize
|
||||
* the network interface, then pauses forever waiting for hangup.
|
||||
*
|
||||
* It is a remote descendant of several similar programs with incestuous ties:
|
||||
* - Kirk Smith's slipconf, modified by Richard Johnsson @ DEC WRL.
|
||||
* - slattach, probably by Rick Adams but touched by countless hordes.
|
||||
* - the original sliplogin for 4.2bsd, Doug Kingston the mover behind it.
|
||||
*
|
||||
* There are two forms of usage:
|
||||
*
|
||||
* "sliplogin"
|
||||
* Invoked simply as "sliplogin", the program looks up the username
|
||||
* in the file /etc/slip.hosts.
|
||||
* If an entry is found, the line on fd0 is configured for SLIP operation
|
||||
* as specified in the file.
|
||||
*
|
||||
* "sliplogin IPhostlogin </dev/ttyb"
|
||||
* Invoked by root with a username, the name is looked up in the
|
||||
* /etc/slip.hosts file and if found fd0 is configured as in case 1.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
#include <syslog.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include <termios.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/slip.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <paths.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include "pathnames.h"
|
||||
|
||||
extern char **environ;
|
||||
|
||||
static char *restricted_environ[] = {
|
||||
"PATH=" _PATH_STDPATH,
|
||||
NULL
|
||||
};
|
||||
|
||||
int unit;
|
||||
int slip_mode;
|
||||
speed_t speed;
|
||||
int uid;
|
||||
int keepal;
|
||||
int outfill;
|
||||
int slunit;
|
||||
char loginargs[BUFSIZ];
|
||||
char loginfile[MAXPATHLEN];
|
||||
char loginname[BUFSIZ];
|
||||
static char raddr[32]; /* remote address */
|
||||
char ifname[IFNAMSIZ]; /* interface name */
|
||||
static char pidfilename[MAXPATHLEN]; /* name of pid file */
|
||||
static char iffilename[MAXPATHLEN]; /* name of if file */
|
||||
static pid_t pid; /* our pid */
|
||||
|
||||
char *
|
||||
make_ipaddr(void)
|
||||
{
|
||||
static char address[20] ="";
|
||||
struct hostent *he;
|
||||
unsigned long ipaddr;
|
||||
|
||||
address[0] = '\0';
|
||||
if ((he = gethostbyname(raddr)) != NULL) {
|
||||
ipaddr = ntohl(*(long *)he->h_addr_list[0]);
|
||||
sprintf(address, "%lu.%lu.%lu.%lu",
|
||||
ipaddr >> 24,
|
||||
(ipaddr & 0x00ff0000) >> 16,
|
||||
(ipaddr & 0x0000ff00) >> 8,
|
||||
(ipaddr & 0x000000ff));
|
||||
}
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
struct slip_modes {
|
||||
char *sm_name;
|
||||
int sm_or_flag;
|
||||
int sm_and_flag;
|
||||
} modes[] = {
|
||||
"normal", 0 , 0 ,
|
||||
"compress", IFF_LINK0, IFF_LINK2,
|
||||
"noicmp", IFF_LINK1, 0 ,
|
||||
"autocomp", IFF_LINK2, IFF_LINK0,
|
||||
};
|
||||
|
||||
void
|
||||
findid(name)
|
||||
char *name;
|
||||
{
|
||||
FILE *fp;
|
||||
static char slopt[5][16];
|
||||
static char laddr[16];
|
||||
static char mask[16];
|
||||
char slparmsfile[MAXPATHLEN];
|
||||
char user[16];
|
||||
char buf[128];
|
||||
int i, j, n;
|
||||
|
||||
environ = restricted_environ; /* minimal protection for system() */
|
||||
|
||||
(void)strncpy(loginname, name, sizeof(loginname)-1);
|
||||
loginname[sizeof(loginname)-1] = '\0';
|
||||
|
||||
if ((fp = fopen(_PATH_ACCESS, "r")) == NULL) {
|
||||
accfile_err:
|
||||
syslog(LOG_ERR, "%s: %m\n", _PATH_ACCESS);
|
||||
exit(1);
|
||||
}
|
||||
while (fgets(loginargs, sizeof(loginargs) - 1, fp)) {
|
||||
if (ferror(fp))
|
||||
goto accfile_err;
|
||||
if (loginargs[0] == '#' || isspace(loginargs[0]))
|
||||
continue;
|
||||
n = sscanf(loginargs, "%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s\n",
|
||||
user, laddr, raddr, mask, slopt[0], slopt[1],
|
||||
slopt[2], slopt[3], slopt[4]);
|
||||
if (n < 4) {
|
||||
syslog(LOG_ERR, "%s: wrong format\n", _PATH_ACCESS);
|
||||
exit(1);
|
||||
}
|
||||
if (strcmp(user, name) != 0)
|
||||
continue;
|
||||
|
||||
(void) fclose(fp);
|
||||
|
||||
slip_mode = 0;
|
||||
for (i = 0; i < n - 4; i++) {
|
||||
for (j = 0; j < sizeof(modes)/sizeof(struct slip_modes);
|
||||
j++) {
|
||||
if (strcmp(modes[j].sm_name, slopt[i]) == 0) {
|
||||
slip_mode |= (modes[j].sm_or_flag);
|
||||
slip_mode &= ~(modes[j].sm_and_flag);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* we've found the guy we're looking for -- see if
|
||||
* there's a login file we can use. First check for
|
||||
* one specific to this host. If none found, try for
|
||||
* a generic one.
|
||||
*/
|
||||
(void)snprintf(loginfile, sizeof(loginfile), "%s.%s",
|
||||
_PATH_SLIP_LOGIN, name);
|
||||
if (access(loginfile, R_OK|X_OK) != 0) {
|
||||
(void)strncpy(loginfile, _PATH_SLIP_LOGIN,
|
||||
sizeof(loginfile) - 1);
|
||||
loginfile[sizeof(loginfile) - 1] = '\0';
|
||||
if (access(loginfile, R_OK|X_OK)) {
|
||||
syslog(LOG_ERR,
|
||||
"access denied for %s - no %s\n",
|
||||
name, _PATH_SLIP_LOGIN);
|
||||
exit(5);
|
||||
}
|
||||
}
|
||||
(void)snprintf(slparmsfile, sizeof(slparmsfile), "%s.%s", _PATH_SLPARMS, name);
|
||||
if (access(slparmsfile, R_OK|X_OK) != 0) {
|
||||
(void)strncpy(slparmsfile, _PATH_SLPARMS, sizeof(slparmsfile)-1);
|
||||
slparmsfile[sizeof(slparmsfile)-1] = '\0';
|
||||
if (access(slparmsfile, R_OK|X_OK))
|
||||
*slparmsfile = '\0';
|
||||
}
|
||||
keepal = outfill = 0;
|
||||
slunit = -1;
|
||||
if (*slparmsfile) {
|
||||
if ((fp = fopen(slparmsfile, "r")) == NULL) {
|
||||
slfile_err:
|
||||
syslog(LOG_ERR, "%s: %m\n", slparmsfile);
|
||||
exit(1);
|
||||
}
|
||||
n = 0;
|
||||
while (fgets(buf, sizeof(buf) - 1, fp) != NULL) {
|
||||
if (ferror(fp))
|
||||
goto slfile_err;
|
||||
if (buf[0] == '#' || isspace(buf[0]))
|
||||
continue;
|
||||
n = sscanf(buf, "%d %d %d", &keepal, &outfill, &slunit);
|
||||
if (n < 1) {
|
||||
slwrong_fmt:
|
||||
syslog(LOG_ERR, "%s: wrong format\n", slparmsfile);
|
||||
exit(1);
|
||||
}
|
||||
(void) fclose(fp);
|
||||
break;
|
||||
}
|
||||
if (n == 0)
|
||||
goto slwrong_fmt;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
syslog(LOG_ERR, "SLIP access denied for %s\n", name);
|
||||
exit(4);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
char *
|
||||
sigstr(s)
|
||||
int s;
|
||||
{
|
||||
static char buf[32];
|
||||
|
||||
switch (s) {
|
||||
case SIGHUP: return("HUP");
|
||||
case SIGINT: return("INT");
|
||||
case SIGQUIT: return("QUIT");
|
||||
case SIGILL: return("ILL");
|
||||
case SIGTRAP: return("TRAP");
|
||||
case SIGIOT: return("IOT");
|
||||
case SIGEMT: return("EMT");
|
||||
case SIGFPE: return("FPE");
|
||||
case SIGKILL: return("KILL");
|
||||
case SIGBUS: return("BUS");
|
||||
case SIGSEGV: return("SEGV");
|
||||
case SIGSYS: return("SYS");
|
||||
case SIGPIPE: return("PIPE");
|
||||
case SIGALRM: return("ALRM");
|
||||
case SIGTERM: return("TERM");
|
||||
case SIGURG: return("URG");
|
||||
case SIGSTOP: return("STOP");
|
||||
case SIGTSTP: return("TSTP");
|
||||
case SIGCONT: return("CONT");
|
||||
case SIGCHLD: return("CHLD");
|
||||
case SIGTTIN: return("TTIN");
|
||||
case SIGTTOU: return("TTOU");
|
||||
case SIGIO: return("IO");
|
||||
case SIGXCPU: return("XCPU");
|
||||
case SIGXFSZ: return("XFSZ");
|
||||
case SIGVTALRM: return("VTALRM");
|
||||
case SIGPROF: return("PROF");
|
||||
case SIGWINCH: return("WINCH");
|
||||
#ifdef SIGLOST
|
||||
case SIGLOST: return("LOST");
|
||||
#endif
|
||||
case SIGUSR1: return("USR1");
|
||||
case SIGUSR2: return("USR2");
|
||||
}
|
||||
(void)snprintf(buf, sizeof(buf), "sig %d", s);
|
||||
return(buf);
|
||||
}
|
||||
|
||||
void
|
||||
hup_handler(s)
|
||||
int s;
|
||||
{
|
||||
char logoutfile[MAXPATHLEN];
|
||||
|
||||
(void) close(0);
|
||||
seteuid(0);
|
||||
(void)snprintf(logoutfile, sizeof(logoutfile), "%s.%s",
|
||||
_PATH_SLIP_LOGOUT, loginname);
|
||||
if (access(logoutfile, R_OK|X_OK) != 0) {
|
||||
(void)strncpy(logoutfile, _PATH_SLIP_LOGOUT,
|
||||
sizeof(logoutfile) - 1);
|
||||
logoutfile[sizeof(logoutfile) - 1] = '\0';
|
||||
}
|
||||
if (access(logoutfile, R_OK|X_OK) == 0) {
|
||||
char logincmd[2*MAXPATHLEN+32];
|
||||
|
||||
(void) snprintf(logincmd, sizeof(logincmd), "%s %d %ld %s", logoutfile, unit, speed, loginargs);
|
||||
(void) system(logincmd);
|
||||
}
|
||||
syslog(LOG_INFO, "closed %s slip unit %d (%s)\n", loginname, unit,
|
||||
sigstr(s));
|
||||
if (unlink(pidfilename) < 0 && errno != ENOENT)
|
||||
syslog(LOG_WARNING, "unable to delete pid file: %m");
|
||||
if (unlink(iffilename) < 0 && errno != ENOENT)
|
||||
syslog(LOG_WARNING, "unable to delete if file: %m");
|
||||
exit(1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
|
||||
/* Modify the slip line mode and add any compression or no-icmp flags. */
|
||||
void line_flags(unit)
|
||||
int unit;
|
||||
{
|
||||
struct ifreq ifr;
|
||||
int s;
|
||||
|
||||
/* open a socket as the handle to the interface */
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
syslog(LOG_ERR, "socket: %m");
|
||||
exit(1);
|
||||
}
|
||||
sprintf(ifr.ifr_name, "sl%d", unit);
|
||||
|
||||
/* get the flags for the interface */
|
||||
if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
|
||||
syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Assert any compression or no-icmp flags. */
|
||||
#define SLMASK (~(IFF_LINK0 | IFF_LINK1 | IFF_LINK2))
|
||||
ifr.ifr_flags &= SLMASK;
|
||||
ifr.ifr_flags |= slip_mode;
|
||||
if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&ifr) < 0) {
|
||||
syslog(LOG_ERR, "ioctl (SIOCSIFFLAGS): %m");
|
||||
exit(1);
|
||||
}
|
||||
close(s);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int fd, s, ldisc;
|
||||
char *name;
|
||||
struct termios tios;
|
||||
char logincmd[2*BUFSIZ+32];
|
||||
|
||||
FILE *pidfile; /* pid file */
|
||||
FILE *iffile; /* interfaces file */
|
||||
char *p;
|
||||
int n;
|
||||
char devnam[MAXPATHLEN] = _PATH_TTY; /* Device name */
|
||||
|
||||
if ((name = strrchr(argv[0], '/')) == NULL)
|
||||
name = argv[0];
|
||||
s = getdtablesize();
|
||||
for (fd = 3 ; fd < s ; fd++)
|
||||
(void) close(fd);
|
||||
openlog(name, LOG_PID|LOG_PERROR, LOG_DAEMON);
|
||||
uid = getuid();
|
||||
if (argc > 1) {
|
||||
findid(argv[1]);
|
||||
|
||||
/*
|
||||
* Disassociate from current controlling terminal, if any,
|
||||
* and ensure that the slip line is our controlling terminal.
|
||||
*/
|
||||
if (daemon(1, 1)) {
|
||||
syslog(LOG_ERR, "daemon(1, 1): %m");
|
||||
exit(1);
|
||||
}
|
||||
if (argc > 2) {
|
||||
if ((fd = open(argv[2], O_RDWR)) == -1) {
|
||||
syslog(LOG_ERR, "open %s: %m", argv[2]);
|
||||
exit(2);
|
||||
}
|
||||
(void) dup2(fd, 0);
|
||||
if (fd > 2)
|
||||
close(fd);
|
||||
}
|
||||
if (ioctl(0, TIOCSCTTY, 0) == -1) {
|
||||
syslog(LOG_ERR, "ioctl (TIOCSCTTY): %m");
|
||||
exit(1);
|
||||
}
|
||||
if (tcsetpgrp(0, getpid()) < 0) {
|
||||
syslog(LOG_ERR, "tcsetpgrp failed: %m");
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
if ((name = getlogin()) == NULL) {
|
||||
syslog(LOG_ERR, "access denied - login name not found\n");
|
||||
exit(1);
|
||||
}
|
||||
findid(name);
|
||||
}
|
||||
(void) fchmod(0, 0600);
|
||||
(void) fprintf(stderr, "starting slip login for %s\n", loginname);
|
||||
(void) fprintf(stderr, "your address is %s\n\n", make_ipaddr());
|
||||
|
||||
(void) fflush(stderr);
|
||||
sleep(1);
|
||||
|
||||
/* set up the line parameters */
|
||||
if (tcgetattr(0, &tios) < 0) {
|
||||
syslog(LOG_ERR, "tcgetattr: %m");
|
||||
exit(1);
|
||||
}
|
||||
cfmakeraw(&tios);
|
||||
if (tcsetattr(0, TCSAFLUSH, &tios) < 0) {
|
||||
syslog(LOG_ERR, "tcsetattr: %m");
|
||||
exit(1);
|
||||
}
|
||||
speed = cfgetispeed(&tios);
|
||||
|
||||
ldisc = SLIPDISC;
|
||||
if (ioctl(0, TIOCSETD, &ldisc) < 0) {
|
||||
syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
|
||||
exit(1);
|
||||
}
|
||||
if (slunit >= 0 && ioctl(0, SLIOCSUNIT, &slunit) < 0) {
|
||||
syslog(LOG_ERR, "ioctl (SLIOCSUNIT): %m");
|
||||
exit(1);
|
||||
}
|
||||
/* find out what unit number we were assigned */
|
||||
if (ioctl(0, SLIOCGUNIT, &unit) < 0) {
|
||||
syslog(LOG_ERR, "ioctl (SLIOCGUNIT): %m");
|
||||
exit(1);
|
||||
}
|
||||
(void) signal(SIGHUP, hup_handler);
|
||||
(void) signal(SIGTERM, hup_handler);
|
||||
|
||||
if (keepal > 0) {
|
||||
(void) signal(SIGURG, hup_handler);
|
||||
if (ioctl(0, SLIOCSKEEPAL, &keepal) < 0) {
|
||||
syslog(LOG_ERR, "ioctl(SLIOCSKEEPAL): %m");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (outfill > 0 && ioctl(0, SLIOCSOUTFILL, &outfill) < 0) {
|
||||
syslog(LOG_ERR, "ioctl(SLIOCSOUTFILL): %m");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* write pid to file */
|
||||
pid = getpid();
|
||||
(void) sprintf(ifname, "sl%d", unit);
|
||||
(void) sprintf(pidfilename, "%s%s.pid", _PATH_VARRUN, ifname);
|
||||
if ((pidfile = fopen(pidfilename, "w")) != NULL) {
|
||||
fprintf(pidfile, "%d\n", pid);
|
||||
(void) fclose(pidfile);
|
||||
} else {
|
||||
syslog(LOG_ERR, "Failed to create pid file %s: %m",
|
||||
pidfilename);
|
||||
pidfilename[0] = 0;
|
||||
}
|
||||
|
||||
/* write interface unit number to file */
|
||||
p = ttyname(0);
|
||||
if (p)
|
||||
strcpy(devnam, p);
|
||||
for (n = strlen(devnam); n > 0; n--)
|
||||
if (devnam[n] == '/') {
|
||||
n++;
|
||||
break;
|
||||
}
|
||||
(void) sprintf(iffilename, "%s%s.if", _PATH_VARRUN, &devnam[n]);
|
||||
if ((iffile = fopen(iffilename, "w")) != NULL) {
|
||||
fprintf(iffile, "sl%d\n", unit);
|
||||
(void) fclose(iffile);
|
||||
} else {
|
||||
syslog(LOG_ERR, "Failed to create if file %s: %m", iffilename);
|
||||
iffilename[0] = 0;
|
||||
}
|
||||
|
||||
|
||||
syslog(LOG_INFO, "attaching slip unit %d for %s\n", unit, loginname);
|
||||
(void)snprintf(logincmd, sizeof(logincmd), "%s %d %ld %s", loginfile, unit, speed,
|
||||
loginargs);
|
||||
/*
|
||||
* aim stdout and errout at /dev/null so logincmd output won't
|
||||
* babble into the slip tty line.
|
||||
*/
|
||||
(void) close(1);
|
||||
if ((fd = open(_PATH_DEVNULL, O_WRONLY)) != 1) {
|
||||
if (fd < 0) {
|
||||
syslog(LOG_ERR, "open %s: %m", _PATH_DEVNULL);
|
||||
exit(1);
|
||||
}
|
||||
(void) dup2(fd, 1);
|
||||
(void) close(fd);
|
||||
}
|
||||
(void) dup2(1, 2);
|
||||
|
||||
/*
|
||||
* Run login and logout scripts as root (real and effective);
|
||||
* current route(8) is setuid root, and checks the real uid
|
||||
* to see whether changes are allowed (or just "route get").
|
||||
*/
|
||||
(void) setuid(0);
|
||||
if (s = system(logincmd)) {
|
||||
syslog(LOG_ERR, "%s login failed: exit status %d from %s",
|
||||
loginname, s, loginfile);
|
||||
exit(6);
|
||||
}
|
||||
|
||||
/* Handle any compression or no-icmp flags. */
|
||||
line_flags(unit);
|
||||
|
||||
/* reset uid to users' to allow the user to give a signal. */
|
||||
seteuid(uid);
|
||||
/* twiddle thumbs until we get a signal */
|
||||
while (1)
|
||||
sigpause(0);
|
||||
|
||||
/* NOTREACHED */
|
||||
}
|
Loading…
Reference in New Issue
Block a user