From 3ea69c7e3c63fceed58f82a92a40faa7e7565386 Mon Sep 17 00:00:00 2001 From: laforge Date: Tue, 16 Apr 2002 12:44:41 +0000 Subject: command line option support --- README | 10 +++-- ulogd.c | 125 +++++++++++++++++++++++++++++++++++++++++-------------------- ulogd.init | 10 ++--- 3 files changed, 95 insertions(+), 50 deletions(-) diff --git a/README b/README index b6f1eab..dd41f77 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ Userspace logging facility for netfilter / linux 2.4 -$Id: README,v 1.5 2001/05/20 13:51:46 laforge Exp $ +$Id: README,v 1.6 2001/05/20 15:01:35 laforge Exp $ Project Homepage: http://www.gnumonks.org/projects/ Mailinglist: http://lists.gnumonks.org/mailman/listinfo/ulogd/ @@ -38,7 +38,9 @@ logging to a file) are included. ===> USAGE -YOU MUST INSTALL THE ulog-patch from netfilter patch-o-matic FIRST !! +The kernel part of the userspace logging facility (ipt_ULOG.o) is included +in kernels >= 2.4.18-pre8. If you are running older kernel versions, you MUST +install the ulog-patch from netfilter patch-o-matic FIRST !! Please go to the netfilter homepage (http://netfilter.gnumonks.org/) and download the latest iptables package. There is a system called @@ -75,14 +77,14 @@ group 32. All packets get tagged with the ulog prefix "inp" iptables -A INPUT -j ULOG -p tcp --dport 80 --ulog-nlgroup 32 --ulog-prefix inp -In the latest Version (0.2) I added another parameter (--ulog-cprange). +Since version 0.2, I added another parameter (--ulog-cprange). Using this parameter You are able to specify how much octets of the packet should be copied from the kernel to userspace. Setting --ulog-cprange to 0 does always copy the whole packet. Default is 0 ===> COPYRIGHT + CREDITS -The code is (C) 2000 by Harald Welte +The code is (C) 2000-2002 by Harald Welte Thanks also to the valuable Contributions of Daniel Stone, Alexander Janssen and Michael Stolovitzsky. diff --git a/ulogd.c b/ulogd.c index 4abbd5a..b70a1f3 100644 --- a/ulogd.c +++ b/ulogd.c @@ -1,6 +1,6 @@ -/* ulogd, Version $Revision: 1.22 $ +/* ulogd, Version $Revision: 1.23 $ * - * $Id: ulogd.c,v 1.22 2001/07/04 00:22:54 laforge Exp $ + * $Id: ulogd.c,v 1.23 2001/09/01 11:56:27 laforge Exp $ * * userspace logging daemon for the netfilter ULOG target * of the linux 2.4 netfilter subsystem. @@ -20,13 +20,18 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: ulogd.c,v 1.16 2001/05/26 23:19:28 laforge Exp $ + * $Id: ulogd.c,v 1.23 2001/09/01 11:56:27 laforge Exp $ * * Modifications: * 14 Jun 2001 Martin Josefsson * - added SIGHUP handler for logfile cycling + * + * 10 Feb 2002 Alessandro Bono + * - added support for non-fork mode + * - added support for logging to stdout */ +#include #include #include #include @@ -36,6 +41,7 @@ #include #include #include +#include #include #include "conffile.h" #include "ulogd.h" @@ -446,11 +452,15 @@ static int load_plugin(char *file) /* open the logfile */ static int logfile_open(const char *name) { - logfile = fopen(name, "a"); - if (!logfile) { - fprintf(stderr, "ERROR: unable to open logfile %s: %s\n", - name, strerror(errno)); - exit(2); + if (!strcmp(name,"stdout")) { + logfile = stdout; + else { + logfile = fopen(name, "a"); + if (!logfile) { + fprintf(stderr, "ERROR: can't open logfile %s: %s\n", + name, strerror(errno)); + exit(2); + } } return 0; } @@ -523,7 +533,8 @@ static void sigterm_handler(int signal) ipulog_destroy_handle(libulog_h); free(libulog_buf); - fclose(logfile); + if (logfile != stdout) + fclose(logfile); exit(0); } @@ -539,11 +550,46 @@ static void sighup_handler(int signal) } } +static struct option opts[] = { + { "version", 0, NULL, 'V' }, + { "daemon", 0, NULL, 'd' }, + { "help", 0, NULL, 'h' }, + { 0 } +}; + int main(int argc, char* argv[]) { int len; + char argch; + int daemonize = 0; ulog_packet_msg_t *upkt; + while ((argch = getopt_long(argc, argv, "Vdh::", opts, NULL)) != -1) { + switch (argch) { + default: + case '?': + if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); + else + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); + + print_usage(); + exit(1); + break; + case 'h': + print_usage(); + exit(0); + break; + case 'd': + daemonize = 1; + break; + case 'V': + printf("ulogd Version %s\n"); + printf("Copyright (C) 2000-2002 Harald Welte\n"); + break + } + } + if (init_conffile(ULOGD_CONFIGFILE)) { ulogd_log(ULOGD_FATAL, "parse_conffile error\n"); exit(1); @@ -577,41 +623,38 @@ int main(int argc, char* argv[]) exit(1); } -#ifndef DEBUG - if (!fork()) { - - fclose(stdout); + if (daemonize){ + if (fork()) { + exit(0); + } + if (logfile != stdout) + fclose(stdout); fclose(stderr); -#endif - signal(SIGTERM, &sigterm_handler); - signal(SIGHUP, &sighup_handler); + } - ulogd_log(ULOGD_NOTICE, - "initialization finished, entering main loop\n"); - - /* endless loop receiving packets and handling them over to - * handle_packet */ - while (len = ipulog_read(libulog_h, libulog_buf, MYBUFSIZ, 1)) { - - if (len <= 0) { - /* this is not supposed to happen */ - ulogd_log(ULOGD_ERROR, "ipulog_read == %d!\n", - len); - } else { - while (upkt = ipulog_get_packet(libulog_h, - libulog_buf, len)) { - DEBUGP("==> packet received\n"); - handle_packet(upkt); - } - } - } + signal(SIGTERM, &sigterm_handler); + signal(SIGHUP, &sighup_handler); + + ulogd_log(ULOGD_NOTICE, + "initialization finished, entering main loop\n"); - /* hackish, but result is the same */ - sigterm_handler(SIGTERM); + /* endless loop receiving packets and handling them over to + * handle_packet */ + while (len = ipulog_read(libulog_h, libulog_buf, MYBUFSIZ, 1)) { -#ifndef DEBUG - } else { - exit(0); + if (len <= 0) { + /* this is not supposed to happen */ + ulogd_log(ULOGD_ERROR, "ipulog_read == %d!\n", + len); + } else { + while (upkt = ipulog_get_packet(libulog_h, + libulog_buf, len)) { + DEBUGP("==> packet received\n"); + handle_packet(upkt); + } + } } -#endif + + /* hackish, but result is the same */ + sigterm_handler(SIGTERM); } diff --git a/ulogd.init b/ulogd.init index f56e3c5..b58a6f7 100755 --- a/ulogd.init +++ b/ulogd.init @@ -10,7 +10,7 @@ function start() { - gprintf "Starting %s: " "ulogd" + printf "Starting %s: " "ulogd" daemon /usr/sbin/ulogd echo touch /var/lock/subsys/ulogd @@ -19,8 +19,8 @@ function start() function stop() { - gprintf "Stopping %s: " "ulogd" - killprocparent ulogd + printf "Stopping %s: " "ulogd" + killproc ulogd echo rm -f /var/lock/subsys/ulogd } @@ -28,7 +28,7 @@ function stop() function reload() { - pid=`pidoffather ulogd` + pid=`pidof ulogd` if [ "x$pid" != "x" ]; then kill -HUP $pid 2>/dev/null fi @@ -54,7 +54,7 @@ case "$1" in status ulogd ;; *) - gprintf "Usage: %s {start|stop|status|restart|reload}\n" "ulogd" + printf "Usage: %s {start|stop|status|restart|reload}\n" "ulogd" exit 1 esac -- cgit v1.2.3