summaryrefslogtreecommitdiffstats
path: root/sbin/slattach
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1995-09-18 13:33:30 +0000
committerache <ache@FreeBSD.org>1995-09-18 13:33:30 +0000
commit403d6f6b4d998a049b1b504fd8dfe00e99d8c9ad (patch)
tree88b90a2dc81c7ed7202b1219c19a0e4480cc9203 /sbin/slattach
parentd12995ce7a25a3b2d1aba913a2a6e01afb1a4bc8 (diff)
downloadFreeBSD-src-403d6f6b4d998a049b1b504fd8dfe00e99d8c9ad.zip
FreeBSD-src-403d6f6b4d998a049b1b504fd8dfe00e99d8c9ad.tar.gz
New options:
-K #: set SLIP keepalive timeout -O #: set SLIP outfil timeout -U #: set SLIP unit number sighup handler now sets tty disc for non-redial case too. Implement SIGURG handling (from keepalive). POSIXing speed settings.
Diffstat (limited to 'sbin/slattach')
-rw-r--r--sbin/slattach/slattach.865
-rw-r--r--sbin/slattach/slattach.c78
2 files changed, 113 insertions, 30 deletions
diff --git a/sbin/slattach/slattach.8 b/sbin/slattach/slattach.8
index f3b8182..3160618 100644
--- a/sbin/slattach/slattach.8
+++ b/sbin/slattach/slattach.8
@@ -31,7 +31,7 @@
.\"
.\" @(#)slattach.8 6.4 (Berkeley) 3/16/91
.\"
-.\" $Header: /home/ncvs/src/sbin/slattach/slattach.8,v 1.3 1994/08/23 08:28:31 rich Exp $
+.\" $Header: /home/ncvs/src/sbin/slattach/slattach.8,v 1.4 1995/03/12 15:04:16 joerg Exp $
.\"
.Dd April 4, 1993
.Dt SLATTACH 8
@@ -41,17 +41,20 @@
.Nd attach serial lines as network interfaces
.Sh SYNOPSIS
.Nm Slattach
-.Op \-a
-.Op \-c
-.Op \-e exit-command
-.Op \-f
-.Op \-h
-.Op \-l
-.Op \-n
-.Op \-r redial-command
-.Op \-s baudrate
-.Op \-u unit-command
-.Op \-z
+.Op Fl a
+.Op Fl c
+.Op Fl e Ar exit-command
+.Op Fl f
+.Op Fl h
+.Op Fl l
+.Op Fl n
+.Op Fl r Ar redial-command
+.Op Fl s Ar baudrate
+.Op Fl u Ar unit-command
+.Op Fl z
+.Op Fl K Ar keepalive
+.Op Fl O Ar outfill
+.Op Fl U Ar unit
.Ar ttyname
.Sh DESCRIPTION
.Nm Slattach
@@ -60,35 +63,35 @@ and to define the network source and destination addresses.
The following operands are supported by
.Nm slattach :
.Bl -tag -width Ar
-.It Ar \-a
+.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 Ar \-c
+.It Fl c
Enables 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 Ar \-e exit-command
+.It Fl e Ar exit-command
Specifies a command to be invoked within a shell (sh -c exit-command)
before slattach exits.
-.It Ar \-f
+.It Fl f
Disables the invocation of daemon() to run slattach in the background.
-.It Ar \-h
+.It Fl h
Turn on cts/rts style flow control on the slip port, by default no flow
control is done.
-.It Ar \-l
+.It Fl l
disable modem control (CLOCAL) and ignore carrier detect on the slip
port. By default the redial-command is invoked upon carrier drop and
slattach aborts if no redial-command is specified.
-.It Ar \-n
+.It Fl n
Throw away ICMP packets. The slip interface will ignore ICMP packets
to prevent slow lines being saturated by ICMP responses.
-.It Ar \-r redial-command
+.It Fl r Ar redial-command
Specifies a command to be invoked within a shell (sh -c
redial-command) whenever carrier is lost on the line.
-.It Ar \-s baudrate
+.It Fl s Ar baudrate
Specifies the speed of the connection. If not specified, the
default of 9600 is used.
-.It Ar \-u unit-command
+.It Fl u Ar unit-command
When the line is switched to slip discipline, run
.Ql sh \-c unit-command <last> <current>
where <last> and <current> are the slip unit numbers when the line was
@@ -98,9 +101,23 @@ using more than one slip line. Slattach will abort if the unit number
changes and
.Ql \-u unit-command
was not specified.
-.It Ar \-z
+.It Fl z
forces redial
redial-cmd upon startup irrespective of carrier.
+.It Fl K Ar keepalive
+Set SLIP "keep alive" timeout in seconds. If FRAME_END not received in this
+timeout, reconnect occurse. 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 cause at least one FRAME_END
+will be sended during this timeout.
+Needed for "keep alive" timeout on other side.
+Default value is no timeout.
+.It Fl U Ar unit
+Set SLIP unit number directly. Use with caution, no check for two
+interfaces with same number made.
+Default is dynamic assignment.
.It Ar ttyname
Specifies the name of the tty device.
.Ar Ttyname
@@ -179,6 +196,8 @@ This file contains the numerical process ID of the
process and can be examined by scripts in oder to send a signal to
.Nm slattch .
.Sh SEE ALSO
+.Xr startslip 1 ,
+.Xr sliplogin 8 ,
.Xr netstat 1 ,
.Xr netintro 4 ,
.Xr ifconfig 8 ,
diff --git a/sbin/slattach/slattach.c b/sbin/slattach/slattach.c
index 915175f..b6b3e0d 100644
--- a/sbin/slattach/slattach.c
+++ b/sbin/slattach/slattach.c
@@ -68,6 +68,7 @@ static char rcsid[] = "$Id";
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 */
@@ -80,10 +81,13 @@ 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 */
-int speed = DEFAULT_BAUD; /* baud rate of tty */
+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 demon if zero, else don't fork. */
+int keepal = 0; /* keepalive timeout */
+int outfill = 0; /* outfill timeout */
+int sl_unit = -1; /* unit number */
int exiting = 0; /* allready running exit_handler */
struct termios tty; /* tty configuration/state */
@@ -95,7 +99,8 @@ char *config_cmd = 0; /* command to exec if slip unit changes. */
char *exit_cmd = 0; /* command to exec before exiting. */
static char usage_str[] = "\
-usage: %s [-acfhlnz] [-e command] [-r command] [-s speed] [-u command] device\n\
+usage: %s [-acfhlnz] [-e command] [-r command] [-s speed] [-u command] \\\n\
+ [-K timeout] [-O timeout] [-U unit] device\n\
-a -- autoenable VJ compression\n\
-c -- enable VJ compression\n\
-e ECMD -- run ECMD before exiting\n\
@@ -106,7 +111,11 @@ usage: %s [-acfhlnz] [-e command] [-r command] [-s speed] [-u command] device\n\
-r RCMD -- run RCMD upon loss of carrier\n\
-s # -- set baud rate (default 9600)\n\
-u UCMD -- run 'UCMD <old sl#> <new sl#>' before switch to slip discipline\n\
- -z -- run RCMD upon startup irrespective of carrier\n";
+ -z -- run RCMD upon startup irrespective of carrier\n\
+ -K # -- set SLIP \"keep alive\" timeout (default 0)\n\
+ -O # -- set SLIP \"out fill\" timeout (default 0)\n\
+ -U # -- set SLIP unit number (default is dynamic)\n\
+";
int main(int argc, char **argv)
{
@@ -115,7 +124,7 @@ int main(int argc, char **argv)
extern int optind;
char *cp;
- while ((option = getopt(argc, argv, "ace:fhlnr:s:u:z")) != EOF) {
+ while ((option = getopt(argc, argv, "ace:fhlnr:s:u:zK:O:U:")) != EOF) {
switch (option) {
case 'a':
slflags |= IFF_LINK2;
@@ -152,6 +161,15 @@ int main(int argc, char **argv)
case 'z':
redial_on_startup = 1;
break;
+ case 'K':
+ keepal = atoi(optarg);
+ break;
+ case 'O':
+ outfill = atoi(optarg);
+ break;
+ case 'U':
+ sl_unit = atoi(optarg);
+ break;
default:
fprintf(stderr, "%s: Invalid option -- '%c'\n",
argv[0], option);
@@ -282,7 +300,7 @@ 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;
- tty.c_ispeed = tty.c_ospeed = speed;
+ cfsetspeed(&tty, speed);
/* set the line speed and flow control */
if (tcsetattr(fd, TCSAFLUSH, &tty) < 0) {
syslog(LOG_ERR, "tcsetattr(TCSAFLUSH): %m");
@@ -308,6 +326,11 @@ void slip_discipline()
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");
@@ -319,6 +342,18 @@ void slip_discipline()
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) {
@@ -379,6 +414,8 @@ void configure_network()
/* signup_handler() is invoked when carrier drops, eg. before redial. */
void sighup_handler()
{
+ int ttydisc = TTYDISC;
+
if(exiting) return;
again:
/* invoke a shell for redial_cmd or punt. */
@@ -401,8 +438,14 @@ again:
/* force a redial if no carrier */
goto again;
}
- }
+ } else
+ setup_line(0);
} else {
+ if (ioctl(fd, TIOCSETD, &ttydisc) < 0) {
+ syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
+ exit_handler(1);
+ }
+ 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)) {
@@ -421,7 +464,6 @@ again:
dev, unit);
}
}
- setup_line(0);
slip_discipline();
configure_network();
}
@@ -432,6 +474,28 @@ void sigint_handler()
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()
{
OpenPOWER on IntegriCloud