summaryrefslogtreecommitdiffstats
path: root/src/log.c
diff options
context:
space:
mode:
author/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org>2008-01-03 15:51:48 +0000
committer/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org>2008-01-03 15:51:48 +0000
commitc41a0d3efc957505e72067e99a873ce66be0834a (patch)
tree31202265c1acd117df130ef0e9b466a005e8cabe /src/log.c
parentd6978c9faadf9552bcb522d56d40c8aefa2e503e (diff)
o add support for connection logging to the statistics mode via Logfile
o minor irrelevant fixes for uncommon error paths and fix several typos o use LOG_INFO for connection logging, use LOG_NOTICE for other information o minor error handling updates
Diffstat (limited to 'src/log.c')
-rw-r--r--src/log.c56
1 files changed, 44 insertions, 12 deletions
diff --git a/src/log.c b/src/log.c
index 5fea1c3..e3f2102 100644
--- a/src/log.c
+++ b/src/log.c
@@ -24,22 +24,31 @@
#include <string.h>
#include "conntrackd.h"
-FILE *init_log(char *filename)
+int init_log(void)
{
- FILE *fd = NULL;
+ if (CONFIG(logfile)[0]) {
+ STATE(log) = fopen(CONFIG(logfile), "a+");
+ if (STATE(log) == NULL) {
+ fprintf(stderr, "can't open log file `%s'\n",
+ CONFIG(logfile));
+ return -1;
+ }
+ }
- if (filename[0]) {
- fd = fopen(filename, "a+");
- if (fd == NULL) {
- fprintf(stderr, "can't open log file `%s'\n", filename);
- return NULL;
+ if (CONFIG(stats).logfile[0]) {
+ STATE(stats_log) = fopen(CONFIG(stats).logfile, "a+");
+ if (STATE(stats_log) == NULL) {
+ fprintf(stderr, "can't open log file `%s'\n",
+ CONFIG(stats).logfile);
+ return -1;
}
}
- if (CONFIG(syslog_facility) != -1)
+ if (CONFIG(syslog_facility) != -1 ||
+ CONFIG(stats).syslog_facility != -1)
openlog(PACKAGE, LOG_PID, CONFIG(syslog_facility));
- return fd;
+ return 0;
}
void dlog(FILE *fd, int priority, char *format, ...)
@@ -85,10 +94,33 @@ void dlog(FILE *fd, int priority, char *format, ...)
}
}
-void close_log(FILE *fd)
+void dlog_ct(FILE *fd, struct nf_conntrack *ct)
+{
+ time_t t;
+ char buf[1024];
+ char *tmp;
+
+ if (fd) {
+ t = time(NULL);
+ ctime_r(&t, buf);
+ tmp = buf + strlen(buf);
+ buf[strlen(buf)-1]='\t';
+ nfct_snprintf(buf+strlen(buf), 1024-strlen(buf), ct, 0, 0, 0);
+ fprintf(fd, "%s\n", buf);
+ fflush(fd);
+ }
+
+ if (CONFIG(stats).syslog_facility != -1)
+ syslog(LOG_INFO, "%s", tmp);
+}
+
+void close_log(void)
{
- if (fd != NULL)
- fclose(fd);
+ if (STATE(log) != NULL)
+ fclose(STATE(log));
+
+ if (STATE(stats_log) != NULL)
+ fclose(STATE(stats_log));
if (CONFIG(syslog_facility) != -1)
closelog();