From fd845ee4c36d3764058da18deb05d8d8bdb98509 Mon Sep 17 00:00:00 2001 From: Brian Somers Date: Tue, 3 Oct 2000 20:41:00 +0000 Subject: [PATCH] o Load netgraph.ko, ng_ether.ko and ng_pppoe.ko as required (I'm sure this used not to be necessary). o Allow ``-n ngdebug'' to specify something to pass to NgSetDebug() and redirect NgSetDebug() output to syslog(8) in daemon() mode. o Xref ng_ether(8) and NgSetDebug(4). o Correct the type of the response passed to NgRecvData. --- libexec/pppoed/pppoed.8 | 13 ++++++++ libexec/pppoed/pppoed.c | 66 +++++++++++++++++++++++++++++++++-------- 2 files changed, 66 insertions(+), 13 deletions(-) diff --git a/libexec/pppoed/pppoed.8 b/libexec/pppoed/pppoed.8 index 808c3dde85a8..c00a74404fb2 100644 --- a/libexec/pppoed/pppoed.8 +++ b/libexec/pppoed/pppoed.8 @@ -37,6 +37,7 @@ .Op Fl P Ar pidfile .Op Fl a Ar name .Op Fl e Ar exec +.Op Fl n Ar ngdebug .Op Fl p Ar provider .Ar interface .Sh DESCRIPTION @@ -121,6 +122,12 @@ If the flag is given, additional diagnostics are provided (see the .Sx DIAGNOSTICS section below). +If the +.Fl n +flag is given, +.Fn NgSetDebug +is called with an argument of +.Ar ngdebug . .Pp If .Ar pidfile @@ -142,6 +149,10 @@ will report on the child processes creation of a new netgraph socket, it's service offer and the invocation of the .Em PPP program. +If the +.Fl n +option is given, netgraph diagnostic messages are also redirected to +.Xr syslogd 8 . .Pp It is sometimes useful to add the following to .Pa /etc/syslog.conf : @@ -155,8 +166,10 @@ and the following to .Dl /var/log/pppoed.log 640 3 100 * Z .Pp .Sh SEE ALSO +.Xr NgSetDebug 3 , .Xr netgraph 4 , .Xr syslog.conf 5 , +.Xr ng_ether 8 , .Xr ng_pppoe 8 , .Xr ng_socket 8 , .Xr ppp 8 , diff --git a/libexec/pppoed/pppoed.c b/libexec/pppoed/pppoed.c index 86063099bc8b..87e9c10a4dc2 100644 --- a/libexec/pppoed/pppoed.c +++ b/libexec/pppoed/pppoed.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -416,14 +417,53 @@ Spawn(const char *prog, const char *acname, const char *exec, } } +#ifndef NOKLDLOAD +int +LoadModules(void) +{ + const char *module[] = { "netgraph", "ng_socket", "ng_ether", "ng_pppoe" }; + int f; + + for (f = 0; f < sizeof module / sizeof *module; f++) + if (modfind(module[f]) == -1 && kldload(module[f]) == -1) { + fprintf(stderr, "kldload: %s: %s\n", module[f], strerror(errno)); + return 0; + } + + return 1; +} +#endif + +void +nglog(const char *fmt, ...) +{ + char nfmt[256]; + va_list ap; + + snprintf(nfmt, sizeof nfmt, "%s: %s", fmt, strerror(errno)); + va_start(ap, fmt); + vsyslog(LOG_INFO, nfmt, ap); + va_end(ap); +} + +void +nglogx(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vsyslog(LOG_INFO, fmt, ap); + va_end(ap); +} + int main(int argc, char **argv) { - char hostname[MAXHOSTNAMELEN]; - char response[1024], *exec, rhook[NG_HOOKLEN + 1]; + char hostname[MAXHOSTNAMELEN], *exec, rhook[NG_HOOKLEN + 1]; + unsigned char response[1024]; const char *prog, *provider, *acname; struct ngm_connect ngc; - int ch, cs, ds, ret, optF, optd, sz, f; + int ch, cs, ds, ret, optF, optd, optn, sz, f; prog = strrchr(argv[0], '/'); prog = prog ? prog + 1 : argv[0]; @@ -431,9 +471,9 @@ main(int argc, char **argv) exec = NULL; acname = NULL; provider = ""; - optF = optd = 0; + optF = optd = optn = 0; - while ((ch = getopt(argc, argv, "FP:a:de:p:")) != -1) { + while ((ch = getopt(argc, argv, "FP:a:de:n:p:")) != -1) { switch (ch) { case 'F': optF = 1; @@ -455,6 +495,11 @@ main(int argc, char **argv) exec = optarg; break; + case 'n': + optn = 1; + NgSetDebug(atoi(optarg)); + break; + case 'p': provider = optarg; break; @@ -495,15 +540,8 @@ main(int argc, char **argv) } #ifndef NOKLDLOAD - if (modfind("netgraph") == -1) { - fputs("Can't run without options NETGRAPH in the kernel\n", stderr); + if (!LoadModules()) return EX_UNAVAILABLE; - } - - if (modfind("ng_socket") == -1 && kldload("ng_socket") == -1) { - perror("kldload: ng_socket"); - return EX_UNAVAILABLE; - } #endif /* Create a socket node */ @@ -543,6 +581,8 @@ main(int argc, char **argv) } openlog(prog, LOG_PID | (optF ? LOG_PERROR : 0), LOG_DAEMON); + if (!optF && optn) + NgSetErrLog(nglog, nglogx); signal(SIGHUP, Fairwell); signal(SIGINT, Fairwell);