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
2 changed files with 66 additions and 13 deletions

View File

@ -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 ,

View File

@ -45,6 +45,7 @@
#include <paths.h>
#include <signal.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.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
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);