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.
This commit is contained in:
Brian Somers 2000-10-03 20:41:00 +00:00
parent 32002b3434
commit fd845ee4c3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=66602
2 changed files with 66 additions and 13 deletions

View File

@ -37,6 +37,7 @@
.Op Fl P Ar pidfile .Op Fl P Ar pidfile
.Op Fl a Ar name .Op Fl a Ar name
.Op Fl e Ar exec .Op Fl e Ar exec
.Op Fl n Ar ngdebug
.Op Fl p Ar provider .Op Fl p Ar provider
.Ar interface .Ar interface
.Sh DESCRIPTION .Sh DESCRIPTION
@ -121,6 +122,12 @@ If the
flag is given, additional diagnostics are provided (see the flag is given, additional diagnostics are provided (see the
.Sx DIAGNOSTICS .Sx DIAGNOSTICS
section below). section below).
If the
.Fl n
flag is given,
.Fn NgSetDebug
is called with an argument of
.Ar ngdebug .
.Pp .Pp
If If
.Ar pidfile .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 service offer and the invocation of the
.Em PPP .Em PPP
program. program.
If the
.Fl n
option is given, netgraph diagnostic messages are also redirected to
.Xr syslogd 8 .
.Pp .Pp
It is sometimes useful to add the following to It is sometimes useful to add the following to
.Pa /etc/syslog.conf : .Pa /etc/syslog.conf :
@ -155,8 +166,10 @@ and the following to
.Dl /var/log/pppoed.log 640 3 100 * Z .Dl /var/log/pppoed.log 640 3 100 * Z
.Pp .Pp
.Sh SEE ALSO .Sh SEE ALSO
.Xr NgSetDebug 3 ,
.Xr netgraph 4 , .Xr netgraph 4 ,
.Xr syslog.conf 5 , .Xr syslog.conf 5 ,
.Xr ng_ether 8 ,
.Xr ng_pppoe 8 , .Xr ng_pppoe 8 ,
.Xr ng_socket 8 , .Xr ng_socket 8 ,
.Xr ppp 8 , .Xr ppp 8 ,

View File

@ -45,6 +45,7 @@
#include <paths.h> #include <paths.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sysexits.h> #include <sysexits.h>
@ -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 int
main(int argc, char **argv) main(int argc, char **argv)
{ {
char hostname[MAXHOSTNAMELEN]; char hostname[MAXHOSTNAMELEN], *exec, rhook[NG_HOOKLEN + 1];
char response[1024], *exec, rhook[NG_HOOKLEN + 1]; unsigned char response[1024];
const char *prog, *provider, *acname; const char *prog, *provider, *acname;
struct ngm_connect ngc; 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 = strrchr(argv[0], '/');
prog = prog ? prog + 1 : argv[0]; prog = prog ? prog + 1 : argv[0];
@ -431,9 +471,9 @@ main(int argc, char **argv)
exec = NULL; exec = NULL;
acname = NULL; acname = NULL;
provider = ""; 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) { switch (ch) {
case 'F': case 'F':
optF = 1; optF = 1;
@ -455,6 +495,11 @@ main(int argc, char **argv)
exec = optarg; exec = optarg;
break; break;
case 'n':
optn = 1;
NgSetDebug(atoi(optarg));
break;
case 'p': case 'p':
provider = optarg; provider = optarg;
break; break;
@ -495,15 +540,8 @@ main(int argc, char **argv)
} }
#ifndef NOKLDLOAD #ifndef NOKLDLOAD
if (modfind("netgraph") == -1) { if (!LoadModules())
fputs("Can't run without options NETGRAPH in the kernel\n", stderr);
return EX_UNAVAILABLE; return EX_UNAVAILABLE;
}
if (modfind("ng_socket") == -1 && kldload("ng_socket") == -1) {
perror("kldload: ng_socket");
return EX_UNAVAILABLE;
}
#endif #endif
/* Create a socket node */ /* Create a socket node */
@ -543,6 +581,8 @@ main(int argc, char **argv)
} }
openlog(prog, LOG_PID | (optF ? LOG_PERROR : 0), LOG_DAEMON); openlog(prog, LOG_PID | (optF ? LOG_PERROR : 0), LOG_DAEMON);
if (!optF && optn)
NgSetErrLog(nglog, nglogx);
signal(SIGHUP, Fairwell); signal(SIGHUP, Fairwell);
signal(SIGINT, Fairwell); signal(SIGINT, Fairwell);