summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/ppp/main.c')
-rw-r--r--usr.sbin/ppp/main.c104
1 files changed, 66 insertions, 38 deletions
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);
OpenPOWER on IntegriCloud