summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1999-10-19 15:21:09 +0000
committerbrian <brian@FreeBSD.org>1999-10-19 15:21:09 +0000
commit39e862702cb354c8fc1e7409caac87dbe04262b6 (patch)
treeba173d916e21466c26e400811308058ee15e4c7c /usr.sbin
parentcaa1d925297044819d7dd7fd4dbc629042fc4d0f (diff)
downloadFreeBSD-src-39e862702cb354c8fc1e7409caac87dbe04262b6.zip
FreeBSD-src-39e862702cb354c8fc1e7409caac87dbe04262b6.tar.gz
Add the -unit command line switch for specifying the tun device.
Warn about -alias being depricated (but still allow it). Don't moan twice about failing to open any tun device. Fix a diagnostic and add the -quiet switch to the usage message.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ppp/bundle.c22
-rw-r--r--usr.sbin/ppp/bundle.h2
-rw-r--r--usr.sbin/ppp/iface.c4
-rw-r--r--usr.sbin/ppp/main.c104
-rw-r--r--usr.sbin/ppp/ppp.818
-rw-r--r--usr.sbin/ppp/ppp.8.m418
6 files changed, 120 insertions, 48 deletions
diff --git a/usr.sbin/ppp/bundle.c b/usr.sbin/ppp/bundle.c
index 1dca617..6131d70 100644
--- a/usr.sbin/ppp/bundle.c
+++ b/usr.sbin/ppp/bundle.c
@@ -599,10 +599,10 @@ bundle_UnlockTun(struct bundle *bundle)
}
struct bundle *
-bundle_Create(const char *prefix, int type, const char **argv)
+bundle_Create(const char *prefix, int type, int unit, const char **argv)
{
static struct bundle bundle; /* there can be only one */
- int enoentcount, err;
+ int enoentcount, err, minunit, maxunit;
const char *ifname;
#ifdef KLDSYM_LOOKUP
int kldtried;
@@ -616,12 +616,19 @@ bundle_Create(const char *prefix, int type, const char **argv)
return NULL;
}
+ if (unit == -1) {
+ minunit = 0;
+ maxunit = -1;
+ } else {
+ minunit = unit;
+ maxunit = unit + 1;
+ }
err = ENOENT;
enoentcount = 0;
#ifdef KLDSYM_LOOKUP
kldtried = 0;
#endif
- for (bundle.unit = 0; ; bundle.unit++) {
+ for (bundle.unit = minunit; bundle.unit != maxunit; bundle.unit++) {
snprintf(bundle.dev.Name, sizeof bundle.dev.Name, "%s%d",
prefix, bundle.unit);
bundle.dev.fd = ID0open(bundle.dev.Name, O_RDWR);
@@ -629,7 +636,7 @@ bundle_Create(const char *prefix, int type, const char **argv)
break;
else if (errno == ENXIO) {
#ifdef KLDSYM_LOOKUP
- if (bundle.unit == 0 && !kldtried++) {
+ if (bundle.unit == minunit && !kldtried++) {
/*
* XXX: For some odd reason, FreeBSD (right now) allows if_tun.ko to
* load even when the kernel contains the tun device. This lookup
@@ -658,8 +665,11 @@ bundle_Create(const char *prefix, int type, const char **argv)
}
if (bundle.dev.fd < 0) {
- log_Printf(LogWARN, "No available tunnel devices found (%s).\n",
- strerror(err));
+ if (unit == -1)
+ log_Printf(LogWARN, "No available tunnel devices found (%s)\n",
+ strerror(err));
+ else
+ log_Printf(LogWARN, "%s%d: %s\n", prefix, unit, strerror(err));
return NULL;
}
diff --git a/usr.sbin/ppp/bundle.h b/usr.sbin/ppp/bundle.h
index 7e3f607..b2e59ce 100644
--- a/usr.sbin/ppp/bundle.h
+++ b/usr.sbin/ppp/bundle.h
@@ -142,7 +142,7 @@ struct bundle {
#define descriptor2bundle(d) \
((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL)
-extern struct bundle *bundle_Create(const char *, int, const char **);
+extern struct bundle *bundle_Create(const char *, int, int, const char **);
extern void bundle_Destroy(struct bundle *);
extern const char *bundle_PhaseName(struct bundle *);
#define bundle_Phase(b) ((b)->phase)
diff --git a/usr.sbin/ppp/iface.c b/usr.sbin/ppp/iface.c
index fa6ecdf..ebe6803 100644
--- a/usr.sbin/ppp/iface.c
+++ b/usr.sbin/ppp/iface.c
@@ -118,18 +118,20 @@ iface_Create(const char *name)
mib[5] = 0;
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) {
- fprintf(stderr, "clean: sysctl: estimate: %s\n",
+ fprintf(stderr, "iface_Create: sysctl: estimate: %s\n",
strerror(errno));
close(s);
return NULL;
}
if ((buf = (char *)malloc(needed)) == NULL) {
+ fprintf(stderr, "iface_Create: malloc failed: %s\n", strerror(errno));
close(s);
return NULL;
}
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
+ fprintf(stderr, "iface_Create: sysctl: %s\n", strerror(errno));
free(buf);
close(s);
return NULL;
diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c
index b2cffe3..64b8483 100644
--- a/usr.sbin/ppp/main.c
+++ b/usr.sbin/ppp/main.c
@@ -33,6 +33,7 @@
#include <paths.h>
#include <signal.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <termios.h>
@@ -185,39 +186,66 @@ Usage(void)
#ifndef NOALIAS
" [-nat]"
#endif
- " [system ...]\n");
+ " [-quiet] [-unit N] [system ...]\n");
exit(EX_START);
}
+struct switches {
+ unsigned nat : 1;
+ unsigned fg : 1;
+ unsigned quiet : 1;
+ int mode;
+ int unit;
+};
+
static int
-ProcessArgs(int argc, char **argv, int *mode, int *nat, int *fg, int *quiet)
+ProcessArgs(int argc, char **argv, struct switches *sw)
{
int optc, newmode, arg;
char *cp;
optc = 0;
- *mode = PHYS_INTERACTIVE;
- *nat = 0;
- *fg = 0;
- *quiet = 0;
+ memset(sw, '\0', sizeof *sw);
+ sw->mode = PHYS_INTERACTIVE;
+ sw->unit = -1;
+
for (arg = 1; arg < argc && *argv[arg] == '-'; arg++, optc++) {
cp = argv[arg] + 1;
newmode = Nam2mode(cp);
switch (newmode) {
case PHYS_NONE:
- if (strcmp(cp, "nat") == 0 || strcmp(cp, "alias") == 0) {
+ if (strcmp(cp, "nat") == 0) {
#ifdef NONAT
- log_Printf(LogWARN, "Cannot load libalias (compiled out)\n");
+ log_Printf(LogWARN, "%s ignored: NAT is compiled out\n", argv[arg]);
#else
- *nat = 1;
+ sw->nat = 1;
#endif
optc--; /* this option isn't exclusive */
+ } else if (strcmp(cp, "alias") == 0) {
+#ifdef NONAT
+ log_Printf(LogWARN, "%s ignored: NAT is compiled out\n", argv[arg]);
+ fprintf(stderr, "%s ignored: NAT is compiled out\n", argv[arg]);
+#else
+ log_Printf(LogWARN, "%s is depricated\n", argv[arg]);
+ fprintf(stderr, "%s is depricated\n", argv[arg]);
+ sw->nat = 1;
+#endif
+ optc--; /* this option isn't exclusive */
+ } else if (strncmp(cp, "unit", 4) == 0) {
+ if (cp[4] == '\0') {
+ if (++arg == argc) {
+ fprintf(stderr, "-unit: Expected unit number\n");
+ Usage();
+ } else
+ sw->unit = atoi(argv[arg]);
+ } else
+ sw->unit = atoi(cp + 4);
} else if (strcmp(cp, "quiet") == 0) {
- *quiet = 1;
+ sw->quiet = 1;
optc--; /* this option isn't exclusive */
} else if (strcmp(cp, "foreground") == 0) {
- *mode = PHYS_BACKGROUND; /* Kinda like background mode */
- *fg = 1;
+ sw->mode = PHYS_BACKGROUND; /* Kinda like background mode */
+ sw->fg = 1;
} else
Usage();
break;
@@ -227,7 +255,7 @@ ProcessArgs(int argc, char **argv, int *mode, int *nat, int *fg, int *quiet)
break;
default:
- *mode = newmode;
+ sw->mode = newmode;
}
}
@@ -236,7 +264,7 @@ ProcessArgs(int argc, char **argv, int *mode, int *nat, int *fg, int *quiet)
exit(EX_START);
}
- if (*mode == PHYS_AUTO && arg == argc) {
+ if (sw->mode == PHYS_AUTO && arg == argc) {
fprintf(stderr, "A system must be specified in auto mode.\n");
exit(EX_START);
}
@@ -265,9 +293,10 @@ main(int argc, char **argv)
{
char *name;
const char *lastlabel;
- int nfds, mode, nat, fg, quiet, label, arg;
+ int nfds, label, arg;
struct bundle *bundle;
struct prompt *prompt;
+ struct switches sw;
nfds = getdtablesize();
if (nfds >= FD_SETSIZE)
@@ -285,7 +314,7 @@ main(int argc, char **argv)
#ifndef NONAT
PacketAliasInit();
#endif
- label = ProcessArgs(argc, argv, &mode, &nat, &fg, &quiet);
+ label = ProcessArgs(argc, argv, &sw);
/*
* A FreeBSD & OpenBSD hack to dodge a bug in the tty driver that drops
@@ -294,7 +323,7 @@ main(int argc, char **argv)
* routing table and then run ppp in interactive mode. The `show route'
* command will drop chunks of data !!!
*/
- if (mode == PHYS_INTERACTIVE) {
+ if (sw.mode == PHYS_INTERACTIVE) {
close(STDIN_FILENO);
if (open(_PATH_TTY, O_RDONLY) != STDIN_FILENO) {
fprintf(stderr, "Cannot open %s for input !\n", _PATH_TTY);
@@ -303,7 +332,7 @@ main(int argc, char **argv)
}
/* Allow output for the moment (except in direct mode) */
- if (mode == PHYS_DIRECT)
+ if (sw.mode == PHYS_DIRECT)
prompt = NULL;
else
SignalPrompt = prompt = prompt_Create(NULL, NULL, PROMPT_STD);
@@ -329,28 +358,27 @@ main(int argc, char **argv)
if (label < argc)
for (arg = label; arg < argc; arg++)
- CheckLabel(argv[arg], prompt, mode);
+ CheckLabel(argv[arg], prompt, sw.mode);
else
- CheckLabel("default", prompt, mode);
+ CheckLabel("default", prompt, sw.mode);
- if (!quiet)
- prompt_Printf(prompt, "Working in %s mode\n", mode2Nam(mode));
+ if (!sw.quiet)
+ prompt_Printf(prompt, "Working in %s mode\n", mode2Nam(sw.mode));
- if ((bundle = bundle_Create(TUN_PREFIX, mode, (const char **)argv)) == NULL) {
- log_Printf(LogWARN, "bundle_Create: %s\n", strerror(errno));
+ if ((bundle = bundle_Create(TUN_PREFIX, sw.mode, sw.unit,
+ (const char **)argv)) == NULL)
return EX_START;
- }
/* NOTE: We may now have changed argv[1] via a ``set proctitle'' */
if (prompt) {
prompt->bundle = bundle; /* couldn't do it earlier */
- if (!quiet)
+ if (!sw.quiet)
prompt_Printf(prompt, "Using interface: %s\n", bundle->iface->name);
}
SignalBundle = bundle;
- bundle->NatEnabled = nat;
- if (nat)
+ bundle->NatEnabled = sw.nat;
+ if (sw.nat)
bundle->cfg.opt |= OPT_IFACEALIAS;
if (system_Select(bundle, "default", CONFFILE, prompt, NULL) < 0)
@@ -363,7 +391,7 @@ main(int argc, char **argv)
sig_signal(SIGALRM, SIG_IGN);
signal(SIGPIPE, SIG_IGN);
- if (mode == PHYS_INTERACTIVE)
+ if (sw.mode == PHYS_INTERACTIVE)
sig_signal(SIGTSTP, TerminalStop);
sig_signal(SIGUSR2, BringDownServer);
@@ -380,20 +408,20 @@ main(int argc, char **argv)
/* In case the last label did a ``load'' */
bundle_SetLabel(bundle, lastlabel);
- if (mode == PHYS_AUTO &&
+ if (sw.mode == PHYS_AUTO &&
bundle->ncp.ipcp.cfg.peer_range.ipaddr.s_addr == INADDR_ANY) {
prompt_Printf(prompt, "You must ``set ifaddr'' with a peer address "
"in auto mode.\n");
AbortProgram(EX_START);
}
- if (mode != PHYS_INTERACTIVE) {
- if (mode != PHYS_DIRECT) {
- if (!fg) {
+ if (sw.mode != PHYS_INTERACTIVE) {
+ if (sw.mode != PHYS_DIRECT) {
+ if (!sw.fg) {
int bgpipe[2];
pid_t bgpid;
- if (mode == PHYS_BACKGROUND && pipe(bgpipe)) {
+ if (sw.mode == PHYS_BACKGROUND && pipe(bgpipe)) {
log_Printf(LogERROR, "pipe: %s\n", strerror(errno));
AbortProgram(EX_SOCK);
}
@@ -407,7 +435,7 @@ main(int argc, char **argv)
if (bgpid) {
char c = EX_NORMAL;
- if (mode == PHYS_BACKGROUND) {
+ if (sw.mode == PHYS_BACKGROUND) {
close(bgpipe[1]);
BGPid = bgpid;
/* If we get a signal, kill the child */
@@ -431,7 +459,7 @@ main(int argc, char **argv)
close(bgpipe[0]);
}
return c;
- } else if (mode == PHYS_BACKGROUND) {
+ } else if (sw.mode == PHYS_BACKGROUND) {
close(bgpipe[0]);
bundle->notify.fd = bgpipe[1];
}
@@ -444,7 +472,7 @@ main(int argc, char **argv)
close(STDOUT_FILENO);
close(STDERR_FILENO);
close(STDIN_FILENO);
- if (!fg)
+ if (!sw.fg)
setsid();
} else {
/* -direct - STDIN_FILENO gets used by physical_Open */
@@ -460,7 +488,7 @@ main(int argc, char **argv)
prompt_Required(prompt);
}
- log_Printf(LogPHASE, "PPP Started (%s mode).\n", mode2Nam(mode));
+ log_Printf(LogPHASE, "PPP Started (%s mode).\n", mode2Nam(sw.mode));
DoLoop(bundle);
AbortProgram(EX_NORMAL);
diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8
index 79f6802..4970a1b 100644
--- a/usr.sbin/ppp/ppp.8
+++ b/usr.sbin/ppp/ppp.8
@@ -8,9 +8,10 @@
.Nd Point to Point Protocol (a.k.a. user-ppp)
.Sh SYNOPSIS
.Nm
+.Op Fl Va mode
.Op Fl nat
.Op Fl quiet
-.Op Fl Va mode
+.Op Fl unit Ns Ar N
.Op Ar system Ns
.No ...
.Sh DESCRIPTION
@@ -48,6 +49,21 @@ flag tells
to be silent at startup rather than displaying the mode and interface
to standard output.
.Pp
+The
+.Fl unit
+flag tells
+.Nm
+to only attempt to open
+.Pa /dev/tun Ns Ar N .
+Normally,
+.Nm
+will start with a value of 0 for
+.Ar N ,
+and keep trying to open a tunnel device by incrementing the value of
+.Ar N
+by one each time until it succeeds. If it fails three times in a row
+because the device file is missing, it gives up.
+.Pp
The following
.Va mode Ns No s
are understood by
diff --git a/usr.sbin/ppp/ppp.8.m4 b/usr.sbin/ppp/ppp.8.m4
index 79f6802..4970a1b 100644
--- a/usr.sbin/ppp/ppp.8.m4
+++ b/usr.sbin/ppp/ppp.8.m4
@@ -8,9 +8,10 @@
.Nd Point to Point Protocol (a.k.a. user-ppp)
.Sh SYNOPSIS
.Nm
+.Op Fl Va mode
.Op Fl nat
.Op Fl quiet
-.Op Fl Va mode
+.Op Fl unit Ns Ar N
.Op Ar system Ns
.No ...
.Sh DESCRIPTION
@@ -48,6 +49,21 @@ flag tells
to be silent at startup rather than displaying the mode and interface
to standard output.
.Pp
+The
+.Fl unit
+flag tells
+.Nm
+to only attempt to open
+.Pa /dev/tun Ns Ar N .
+Normally,
+.Nm
+will start with a value of 0 for
+.Ar N ,
+and keep trying to open a tunnel device by incrementing the value of
+.Ar N
+by one each time until it succeeds. If it fails three times in a row
+because the device file is missing, it gives up.
+.Pp
The following
.Va mode Ns No s
are understood by
OpenPOWER on IntegriCloud