to a separate file.
dnl Process this file with autoconf to produce a configure script.
-dnl $Id: configure.in,v 1.13.2.63 2003/07/06 17:49:49 guus Exp $
+dnl $Id: configure.in,v 1.13.2.64 2003/07/06 22:11:31 guus Exp $
AC_PREREQ(2.53)
AC_INIT(src/tincd.c)
AC_FUNC_ALLOCA
AC_TYPE_SIGNAL
AC_CHECK_FUNCS([asprintf daemon fcloseall flock ftime get_current_dir_name \
-putenv select strdup strerror strsignal strtol unsetenv mlockall])
+putenv select strdup strerror strsignal strtol unsetenv mlockall vsyslog])
jm_FUNC_MALLOC
jm_FUNC_REALLOC
#include "fake-getaddrinfo.h"
#include "fake-getnameinfo.h"
-enum {
- DEBUG_NOTHING = 0, /* Quiet mode, only show starting/stopping of the daemon */
- DEBUG_CONNECTIONS = 1, /* Show (dis)connects of other tinc daemons via TCP */
- DEBUG_ERROR = 2, /* Show error messages received from other hosts */
- DEBUG_STATUS = 2, /* Show status messages received from other hosts */
- DEBUG_PROTOCOL = 3, /* Show the requests that are sent/received */
- DEBUG_META = 4, /* Show contents of every request that is sent/received */
- DEBUG_TRAFFIC = 5, /* Show network traffic information */
- DEBUG_PACKET = 6, /* Show contents of each packet that is being sent/received */
- DEBUG_SCARY_THINGS = 10 /* You have been warned */
-};
-
#define min(a,b) (((a)<(b))?(a):(b))
#ifdef ENABLE_TRACING
## Produce this file with automake to get Makefile.in
-# $Id: Makefile.am,v 1.4.4.29 2003/06/07 13:18:31 guus Exp $
+# $Id: Makefile.am,v 1.4.4.30 2003/07/06 22:11:31 guus Exp $
sbin_PROGRAMS = tincd
EXTRA_DIST = linux/device.c freebsd/device.c openbsd/device.c solaris/device.c netbsd/device.c darwin/device.c cygwin/device.c
-tincd_SOURCES = conf.c connection.c device.c edge.c event.c graph.c meta.c net.c net_packet.c net_setup.c \
+tincd_SOURCES = conf.c connection.c device.c edge.c event.c graph.c logger.c meta.c net.c net_packet.c net_setup.c \
net_socket.c netutl.c node.c process.c protocol.c protocol_auth.c protocol_edge.c protocol_misc.c \
protocol_key.c protocol_subnet.c route.c subnet.c tincd.c
INCLUDES = @INCLUDES@ -I$(top_builddir) -I$(top_srcdir)/lib
-noinst_HEADERS = conf.h connection.h device.h edge.h event.h graph.h meta.h net.h netutl.h node.h process.h \
+noinst_HEADERS = conf.h connection.h device.h edge.h event.h graph.h logger.h meta.h net.h netutl.h node.h process.h \
protocol.h route.h subnet.h
LIBS = @LIBS@ @LIBINTL@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: conf.c,v 1.9.4.61 2002/09/15 12:26:24 guus Exp $
+ $Id: conf.c,v 1.9.4.62 2003/07/06 22:11:31 guus Exp $
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
-#include <syslog.h>
#include <string.h>
#include <xalloc.h>
#include "conf.h"
#include "netutl.h" /* for str2address */
+#include "logger.h"
#include "system.h"
avl_tree_t *config_tree;
-int debug_lvl = 0;
int pingtimeout = 0; /* seconds before timeout */
char *confbase = NULL; /* directory in which all config files are */
char *netname = NULL; /* name of the vpn network */
return 1;
}
- syslog(LOG_ERR, _("\"yes\" or \"no\" expected for configuration variable %s in %s line %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("\"yes\" or \"no\" expected for configuration variable %s in %s line %d"),
cfg->variable, cfg->file, cfg->line);
return 0;
if(sscanf(cfg->value, "%d", result) == 1)
return 1;
- syslog(LOG_ERR, _("Integer expected for configuration variable %s in %s line %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Integer expected for configuration variable %s in %s line %d"),
cfg->variable, cfg->file, cfg->line);
return 0;
return 1;
}
- syslog(LOG_ERR, _("Hostname or IP address expected for configuration variable %s in %s line %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Hostname or IP address expected for configuration variable %s in %s line %d"),
cfg->variable, cfg->file, cfg->line);
return 0;
subnet = str2net(cfg->value);
if(!subnet) {
- syslog(LOG_ERR, _("Subnet expected for configuration variable %s in %s line %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Subnet expected for configuration variable %s in %s line %d"),
cfg->variable, cfg->file, cfg->line);
return 0;
}
&& maskcheck(&subnet->net.ipv4.address, subnet->net.ipv4.prefixlength, sizeof(ipv4_t)))
|| ((subnet->type == SUBNET_IPV6)
&& maskcheck(&subnet->net.ipv6.address, subnet->net.ipv6.prefixlength, sizeof(ipv6_t)))) {
- syslog(LOG_ERR, _ ("Network address and prefix length do not match for configuration variable %s in %s line %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _ ("Network address and prefix length do not match for configuration variable %s in %s line %d"),
cfg->variable, cfg->file, cfg->line);
free(subnet);
return 0;
fp = fopen(fname, "r");
if(!fp) {
- syslog(LOG_ERR, _("Cannot open config file %s: %s"), fname,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Cannot open config file %s: %s"), fname,
strerror(errno));
return -3;
}
value = strtok(NULL, "\t\n\r =");
if(!value || value[0] == '#') {
- syslog(LOG_ERR, _("No value for variable `%s' on line %d while reading config file %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("No value for variable `%s' on line %d while reading config file %s"),
variable, lineno, fname);
break;
}
x = read_config_file(config_tree, fname);
if(x == -1) { /* System error: complain */
- syslog(LOG_ERR, _("Failed to read `%s': %s"), fname, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Failed to read `%s': %s"), fname, strerror(errno));
}
free(fname);
char l[MAXBUFSIZE];
if(*file != '/') {
- syslog(LOG_ERR, _("`%s' is not an absolute path"), file);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("`%s' is not an absolute path"), file);
return 0;
}
check1:
if(lstat(f, &s) < 0) {
- syslog(LOG_ERR, _("Couldn't stat `%s': %s"), f, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Couldn't stat `%s': %s"), f, strerror(errno));
return 0;
}
if(s.st_uid != geteuid()) {
- syslog(LOG_ERR, _("`%s' is owned by UID %d instead of %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("`%s' is owned by UID %d instead of %d"),
f, s.st_uid, geteuid());
return 0;
}
if(S_ISLNK(s.st_mode)) {
- syslog(LOG_WARNING, _("Warning: `%s' is a symlink"), f);
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Warning: `%s' is a symlink"), f);
if(readlink(f, l, MAXBUFSIZE) < 0) {
- syslog(LOG_ERR, _("Unable to read symbolic link `%s': %s"), f,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unable to read symbolic link `%s': %s"), f,
strerror(errno));
return 0;
}
check2:
if(lstat(f, &s) < 0 && errno != ENOENT) {
- syslog(LOG_ERR, _("Couldn't stat `%s': %s"), f, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Couldn't stat `%s': %s"), f, strerror(errno));
return 0;
}
return 1;
if(s.st_uid != geteuid()) {
- syslog(LOG_ERR, _("`%s' is owned by UID %d instead of %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("`%s' is owned by UID %d instead of %d"),
f, s.st_uid, geteuid());
return 0;
}
if(S_ISLNK(s.st_mode)) {
- syslog(LOG_WARNING, _("Warning: `%s' is a symlink"), f);
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Warning: `%s' is a symlink"), f);
if(readlink(f, l, MAXBUFSIZE) < 0) {
- syslog(LOG_ERR, _("Unable to read symbolic link `%s': %s"), f,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unable to read symbolic link `%s': %s"), f,
strerror(errno));
return 0;
}
if(s.st_mode & 0007) {
/* Accessible by others */
- syslog(LOG_ERR, _("`%s' has unsecure permissions"), f);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("`%s' has unsecure permissions"), f);
return 0;
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: conf.h,v 1.6.4.35 2002/09/15 12:26:24 guus Exp $
+ $Id: conf.h,v 1.6.4.36 2003/07/06 22:11:31 guus Exp $
*/
#ifndef __TINC_CONF_H__
extern avl_tree_t *config_tree;
-extern int debug_lvl;
extern int pingtimeout;
extern int maxtimeout;
extern int bypass_security;
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: connection.c,v 1.1.2.36 2003/06/25 20:55:05 guus Exp $
+ $Id: connection.c,v 1.1.2.37 2003/07/06 22:11:31 guus Exp $
*/
#include "config.h"
#include <stdio.h>
-#include <syslog.h>
#include <string.h>
#include <sys/time.h>
#include "conf.h"
#include <utils.h>
#include "subnet.h"
+#include "logger.h"
#include "xalloc.h"
#include "system.h"
cp();
- syslog(LOG_DEBUG, _("Connections:"));
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Connections:"));
for(node = connection_tree->head; node; node = node->next) {
c = (connection_t *) node->data;
- syslog(LOG_DEBUG, _(" %s at %s options %lx socket %d status %04x"),
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" %s at %s options %lx socket %d status %04x"),
c->name, c->hostname, c->options, c->socket, c->status);
}
- syslog(LOG_DEBUG, _("End of connections."));
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("End of connections."));
}
int read_connection_config(connection_t *c)
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: device.c,v 1.1.2.5 2003/06/11 19:28:36 guus Exp $
+ $Id: device.c,v 1.1.2.6 2003/07/06 22:11:33 guus Exp $
*/
#include "config.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
-#include <syslog.h>
#include <string.h>
#include <utils.h>
#include "conf.h"
#include "net.h"
-#include "subnet.h"
+#include "logger.h"
#include "system.h"
interface = rindex(device, '/') ? rindex(device, '/') + 1 : device;
if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
- syslog(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
return -1;
}
device_info = _("Stub device for Cygwin environment");
- syslog(LOG_INFO, _("%s is a %s"), device, device_info);
+ logger(DEBUG_ALWAYS, LOG_INFO, _("%s is a %s"), device, device_info);
return 0;
}
cp();
if((lenin = read(device_fd, packet->data, MTU)) <= 0) {
- syslog(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
device, strerror(errno));
return -1;
}
device_total_in += packet->len;
- if(debug_lvl >= DEBUG_TRAFFIC) {
- syslog(LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
device_info);
- }
return 0;
}
{
cp();
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Writing packet of %d bytes to %s"),
packet->len, device_info);
if(write(device_fd, packet->data, packet->len) < 0) {
- syslog(LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
strerror(errno));
return -1;
}
{
cp();
- syslog(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
- syslog(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
- syslog(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: device.c,v 1.1.2.6 2003/06/11 19:28:36 guus Exp $
+ $Id: device.c,v 1.1.2.7 2003/07/06 22:11:33 guus Exp $
*/
#include "config.h"
#include <fcntl.h>
#include <net/if.h>
#include <unistd.h>
-#include <syslog.h>
#include <string.h>
#include <utils.h>
#include "conf.h"
#include "net.h"
-#include "subnet.h"
+#include "logger.h"
#include "system.h"
interface = rindex(device, '/') ? rindex(device, '/') + 1 : device;
if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
- syslog(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
return -1;
}
device_info = _("MacOS/X tun device");
- syslog(LOG_INFO, _("%s is a %s"), device, device_info);
+ logger(DEBUG_ALWAYS, LOG_INFO, _("%s is a %s"), device, device_info);
return 0;
}
cp();
if((lenin = read(device_fd, packet->data + 14, MTU - 14)) <= 0) {
- syslog(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
device, strerror(errno));
return -1;
}
device_total_in += packet->len;
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Read packet of %d bytes from %s"),
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Read packet of %d bytes from %s"),
packet->len, device_info);
return 0;
{
cp();
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Writing packet of %d bytes to %s"),
packet->len, device_info);
if(write(device_fd, packet->data + 14, packet->len - 14) < 0) {
- syslog(LOG_ERR, _("Error while writing to %s %s: %s"), device_info,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while writing to %s %s: %s"), device_info,
device, strerror(errno));
return -1;
}
{
cp();
- syslog(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
- syslog(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
- syslog(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: edge.c,v 1.1.2.18 2002/09/10 22:12:33 guus Exp $
+ $Id: edge.c,v 1.1.2.19 2003/07/06 22:11:31 guus Exp $
*/
#include "config.h"
#include <stdio.h>
-#include <syslog.h>
#include <string.h>
#include <avl_tree.h>
#include "subnet.h"
#include "edge.h"
#include "node.h"
+#include "logger.h"
#include "xalloc.h"
#include "system.h"
cp();
- syslog(LOG_DEBUG, _("Edges:"));
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Edges:"));
for(node = node_tree->head; node; node = node->next) {
n = (node_t *) node->data;
for(node2 = n->edge_tree->head; node2; node2 = node2->next) {
e = (edge_t *) node2->data;
address = sockaddr2hostname(&e->address);
- syslog(LOG_DEBUG, _(" %s to %s at %s options %lx weight %d"),
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" %s to %s at %s options %lx weight %d"),
e->from->name, e->to->name, address, e->options, e->weight);
free(address);
}
}
- syslog(LOG_DEBUG, _("End of edges."));
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("End of edges."));
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: device.c,v 1.1.2.9 2003/06/11 19:28:37 guus Exp $
+ $Id: device.c,v 1.1.2.10 2003/07/06 22:11:34 guus Exp $
*/
#include "config.h"
#include <fcntl.h>
#include <net/if.h>
#include <unistd.h>
-#include <syslog.h>
#include <string.h>
#include <utils.h>
#include "conf.h"
#include "net.h"
-#include "subnet.h"
+#include "logger.h"
#include "system.h"
interface = rindex(device, '/') ? rindex(device, '/') + 1 : device;
if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
- syslog(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
return -1;
}
device_info = _("FreeBSD tap device");
- syslog(LOG_INFO, _("%s is a %s"), device, device_info);
+ logger(DEBUG_ALWAYS, LOG_INFO, _("%s is a %s"), device, device_info);
return 0;
}
cp();
if((lenin = read(device_fd, packet->data, MTU)) <= 0) {
- syslog(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
device, strerror(errno));
return -1;
}
device_total_in += packet->len;
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Read packet of %d bytes from %s"),
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Read packet of %d bytes from %s"),
packet->len, device_info);
return 0;
{
cp();
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Writing packet of %d bytes to %s"),
packet->len, device_info);
if(write(device_fd, packet->data, packet->len) < 0) {
- syslog(LOG_ERR, _("Error while writing to %s %s: %s"), device_info,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while writing to %s %s: %s"), device_info,
device, strerror(errno));
return -1;
}
{
cp();
- syslog(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
- syslog(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
- syslog(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: graph.c,v 1.1.2.22 2003/01/17 00:37:17 guus Exp $
+ $Id: graph.c,v 1.1.2.23 2003/07/06 22:11:31 guus Exp $
*/
/* We need to generate two trees from the graph:
#include "config.h"
#include <stdio.h>
-#include <syslog.h>
#include <string.h>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#include "connection.h"
#include "process.h"
#include "device.h"
+#include "logger.h"
#include "system.h"
if(!edge_weight_tree->head)
return;
- if(debug_lvl >= DEBUG_SCARY_THINGS)
- syslog(LOG_DEBUG, "Running Kruskal's algorithm:");
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Running Kruskal's algorithm:");
/* Clear visited status on nodes */
safe_edges++;
- if(debug_lvl >= DEBUG_SCARY_THINGS)
- syslog(LOG_DEBUG, " Adding edge %s - %s weight %d", e->from->name,
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, " Adding edge %s - %s weight %d", e->from->name,
e->to->name, e->weight);
if(skipped) {
}
}
- if(debug_lvl >= DEBUG_SCARY_THINGS)
- syslog(LOG_DEBUG, "Done, counted %d nodes and %d safe edges.", nodes,
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Done, counted %d nodes and %d safe edges.", nodes,
safe_edges);
}
if(n->status.visited != n->status.reachable) {
n->status.reachable = !n->status.reachable;
- if(debug_lvl >= DEBUG_TRAFFIC) {
- if(n->status.reachable)
- syslog(LOG_DEBUG, _("Node %s (%s) became reachable"),
- n->name, n->hostname);
- else
- syslog(LOG_DEBUG, _("Node %s (%s) became unreachable"),
- n->name, n->hostname);
- }
+ if(n->status.reachable)
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Node %s (%s) became reachable"),
+ n->name, n->hostname);
+ else
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Node %s (%s) became unreachable"),
+ n->name, n->hostname);
n->status.validkey = 0;
n->status.waitingforkey = 0;
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: device.c,v 1.1.2.15 2003/06/11 19:28:37 guus Exp $
+ $Id: device.c,v 1.1.2.16 2003/07/06 22:11:35 guus Exp $
*/
#include "config.h"
#include <fcntl.h>
#include <net/if.h>
#include <unistd.h>
-#include <syslog.h>
#include <string.h>
#include <sys/ioctl.h>
#include <utils.h>
#include "conf.h"
#include "net.h"
-#include "subnet.h"
#include "route.h"
+#include "logger.h"
#include "system.h"
device_fd = open(device, O_RDWR | O_NONBLOCK);
if(device_fd < 0) {
- syslog(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
return -1;
}
strncpy(ifrname, ifr.ifr_name, IFNAMSIZ);
interface = ifrname;
} else if(!ioctl(device_fd, (('T' << 8) | 202), (void *) &ifr)) {
- syslog(LOG_WARNING, _("Old ioctl() request was needed for %s"), device);
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Old ioctl() request was needed for %s"), device);
strncpy(ifrname, ifr.ifr_name, IFNAMSIZ);
interface = ifrname;
} else
interface = rindex(device, '/') ? rindex(device, '/') + 1 : device;
}
- syslog(LOG_INFO, _("%s is a %s"), device, device_info);
+ logger(DEBUG_ALWAYS, LOG_INFO, _("%s is a %s"), device, device_info);
return 0;
}
lenin = read(device_fd, packet->data + 10, MTU - 10);
if(lenin <= 0) {
- syslog(LOG_ERR, _("Error while reading from %s %s: %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while reading from %s %s: %s"),
device_info, device, strerror(errno));
return -1;
}
lenin = read(device_fd, packet->data, MTU);
if(lenin <= 0) {
- syslog(LOG_ERR, _("Error while reading from %s %s: %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while reading from %s %s: %s"),
device_info, device, strerror(errno));
return -1;
}
lenin = read(device_fd, packet->data - 2, MTU + 2);
if(lenin <= 0) {
- syslog(LOG_ERR, _("Error while reading from %s %s: %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while reading from %s %s: %s"),
device_info, device, strerror(errno));
return -1;
}
device_total_in += packet->len;
- if(debug_lvl >= DEBUG_TRAFFIC) {
- syslog(LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
device_info);
- }
return 0;
}
{
cp();
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Writing packet of %d bytes to %s"),
packet->len, device_info);
switch(device_type) {
case DEVICE_TYPE_TUN:
packet->data[10] = packet->data[11] = 0;
if(write(device_fd, packet->data + 10, packet->len - 10) < 0) {
- syslog(LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
strerror(errno));
return -1;
}
break;
case DEVICE_TYPE_TAP:
if(write(device_fd, packet->data, packet->len) < 0) {
- syslog(LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
strerror(errno));
return -1;
}
*(short int *)(packet->data - 2) = packet->len;
if(write(device_fd, packet->data - 2, packet->len + 2) < 0) {
- syslog(LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
strerror(errno));
return -1;
}
{
cp();
- syslog(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
- syslog(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
- syslog(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
}
--- /dev/null
+/*
+ logger.c -- logging code
+ Copyright (C) 2003 Guus Sliepen <guus@sliepen.eu.org>
+ 2003 Ivo Timmermans <ivo@o2w.nl>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id: logger.c,v 1.1.2.1 2003/07/06 22:11:31 guus Exp $
+*/
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <syslog.h>
+
+#include "conf.h"
+#include "logger.h"
+
+#include "system.h"
+
+volatile int debug_level = DEBUG_NOTHING;
+int logmode = LOGMODE_STDERR;
+pid_t logpid;
+extern char *logfilename;
+FILE *logfile = NULL;
+const char *logident = NULL;
+
+void openlogger(const char *ident, int mode) {
+ char *fname;
+
+ logident = ident;
+ logmode = mode;
+
+ switch(mode) {
+ case LOGMODE_STDERR:
+ logpid = getpid();
+ break;
+ case LOGMODE_FILE:
+ logpid = getpid();
+ logfile = fopen(logfilename, "a");
+ if(!logfile)
+ logmode = LOGMODE_NULL;
+ break;
+ case LOGMODE_SYSLOG:
+ openlog(logident, LOG_CONS | LOG_PID, LOG_DAEMON);
+ break;
+ }
+}
+
+void vlogger(int priority, const char *format, va_list ap) {
+ switch(logmode) {
+ case LOGMODE_STDERR:
+ vfprintf(stderr, format, ap);
+ fprintf(stderr, "\n");
+ break;
+ case LOGMODE_FILE:
+ fprintf(logfile, "%d %s[%d]: ", time(NULL), logident, logpid);
+ vfprintf(logfile, format, ap);
+ fprintf(logfile, "\n");
+ break;
+ case LOGMODE_SYSLOG:
+#ifdef HAVE_VSYSLOG
+ vsyslog(priority, format, ap);
+#else
+ {
+ char message[4096];
+ vsnprintf(message, sizeof(message), format, ap);
+ syslog(priority, "%s", message);
+ }
+#endif
+ break;
+ }
+}
+
+void closelogger(void) {
+ switch(logmode) {
+ case LOGMODE_FILE:
+ fclose(logfile);
+ break;
+ case LOGMODE_SYSLOG:
+ closelog();
+ break;
+ }
+}
--- /dev/null
+#ifndef __TINC_LOGGER_H__
+
+#include <syslog.h>
+#include <stdarg.h>
+
+enum {
+ DEBUG_NOTHING = 0, /* Quiet mode, only show starting/stopping of the daemon */
+ DEBUG_ALWAYS = 0,
+ DEBUG_CONNECTIONS = 1, /* Show (dis)connects of other tinc daemons via TCP */
+ DEBUG_ERROR = 2, /* Show error messages received from other hosts */
+ DEBUG_STATUS = 2, /* Show status messages received from other hosts */
+ DEBUG_PROTOCOL = 3, /* Show the requests that are sent/received */
+ DEBUG_META = 4, /* Show contents of every request that is sent/received */
+ DEBUG_TRAFFIC = 5, /* Show network traffic information */
+ DEBUG_PACKET = 6, /* Show contents of each packet that is being sent/received */
+ DEBUG_SCARY_THINGS = 10 /* You have been warned */
+};
+
+enum {
+ LOGMODE_NULL,
+ LOGMODE_STDERR,
+ LOGMODE_FILE,
+ LOGMODE_SYSLOG
+};
+
+extern volatile int debug_level;
+extern void openlogger(const char *, int);
+extern void vlogger(int, const char *, va_list ap);
+extern void closelogger(void);
+
+/* Inline logger function because it's used quite often */
+
+static inline void logger(int level, int priority, const char *format, ...) {
+ va_list ap;
+
+ if(level == DEBUG_ALWAYS || debug_level >= level) {
+ va_start(ap, format);
+ vlogger(priority, format, ap);
+ va_end(ap);
+ }
+}
+
+#endif /* __TINC_LOGGER_H__ */
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: meta.c,v 1.1.2.33 2003/03/19 11:45:05 guus Exp $
+ $Id: meta.c,v 1.1.2.34 2003/07/06 22:11:31 guus Exp $
*/
#include "config.h"
#include <avl_tree.h>
#include <errno.h>
-#include <syslog.h>
#include <unistd.h>
#include <string.h>
/* This line must be below the rest for FreeBSD */
#include "connection.h"
#include "system.h"
#include "protocol.h"
+#include "logger.h"
int send_meta(connection_t *c, char *buffer, int length)
{
cp();
- if(debug_lvl >= DEBUG_META)
- syslog(LOG_DEBUG, _("Sending %d bytes of metadata to %s (%s)"), length,
+ logger(DEBUG_META, LOG_DEBUG, _("Sending %d bytes of metadata to %s (%s)"), length,
c->name, c->hostname);
if(c->status.encryptout) {
if(result <= 0) {
if(errno == EINTR)
continue;
- syslog(LOG_ERR, _("Sending meta data to %s (%s) failed: %s"), c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Sending meta data to %s (%s) failed: %s"), c->name,
c->hostname, strerror(errno));
return -1;
}
cp();
if(getsockopt(c->socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0) {
- syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%s %s (%s)"), __FILE__,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("This is a bug: %s:%d: %d:%s %s (%s)"), __FILE__,
__LINE__, c->socket, strerror(errno), c->name, c->hostname);
return -1;
}
if(x) {
- syslog(LOG_ERR, _("Metadata socket error for %s (%s): %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Metadata socket error for %s (%s): %s"),
c->name, c->hostname, strerror(x));
return -1;
}
if(lenin <= 0) {
if(lenin == 0) {
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Connection closed by %s (%s)"),
+ logger(DEBUG_CONNECTIONS, LOG_NOTICE, _("Connection closed by %s (%s)"),
c->name, c->hostname);
} else if(errno == EINTR)
return 0;
else
- syslog(LOG_ERR, _("Metadata socket read error for %s (%s): %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Metadata socket read error for %s (%s): %s"),
c->name, c->hostname, strerror(errno));
return -1;
}
if(c->buflen >= MAXBUFSIZE) {
- syslog(LOG_ERR, _("Metadata read buffer overflow for %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Metadata read buffer overflow for %s (%s)"),
c->name, c->hostname);
return -1;
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net.c,v 1.35.4.187 2003/07/06 17:15:25 guus Exp $
+ $Id: net.c,v 1.35.4.188 2003/07/06 22:11:32 guus Exp $
*/
#include "config.h"
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <syslog.h>
#include <unistd.h>
#include <sys/ioctl.h>
/* SunOS really wants sys/socket.h BEFORE net/if.h,
#include "route.h"
#include "device.h"
#include "event.h"
+#include "logger.h"
#include "system.h"
cp();
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_DEBUG, _("Purging unreachable nodes"));
+ logger(DEBUG_PROTOCOL, LOG_DEBUG, _("Purging unreachable nodes"));
for(nnode = node_tree->head; nnode; nnode = nnext) {
nnext = nnode->next;
n = (node_t *) nnode->data;
if(!n->status.reachable) {
- if(debug_lvl >= DEBUG_SCARY_THINGS)
- syslog(LOG_DEBUG, _("Purging node %s (%s)"), n->name,
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, _("Purging node %s (%s)"), n->name,
n->hostname);
for(snode = n->subnet_tree->head; snode; snode = snext) {
if(c->status.remove)
return;
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Closing connection with %s (%s)"),
+ logger(DEBUG_CONNECTIONS, LOG_NOTICE, _("Closing connection with %s (%s)"),
c->name, c->hostname);
c->status.remove = 1;
if(c->last_ping_time + pingtimeout < now) {
if(c->status.active) {
if(c->status.pinged) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_INFO, _("%s (%s) didn't respond to PING"),
+ logger(DEBUG_CONNECTIONS, LOG_INFO, _("%s (%s) didn't respond to PING"),
c->name, c->hostname);
c->status.timeout = 1;
terminate_connection(c, 1);
}
} else {
if(c->status.remove) {
- syslog(LOG_WARNING, _("Old connection_t for %s (%s) status %04x still lingering, deleting..."),
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Old connection_t for %s (%s) status %04x still lingering, deleting..."),
c->name, c->hostname, c->status);
connection_del(c);
continue;
}
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_WARNING, _("Timeout from %s (%s) during authentication"),
+ logger(DEBUG_CONNECTIONS, LOG_WARNING, _("Timeout from %s (%s) during authentication"),
c->name, c->hostname);
terminate_connection(c, 0);
}
if(!result)
finish_connecting(c);
else {
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_DEBUG,
+ logger(DEBUG_CONNECTIONS, LOG_DEBUG,
_("Error while connecting to %s (%s): %s"),
c->name, c->hostname, strerror(result));
close(c->socket);
if(r < 0) {
if(errno != EINTR && errno != EAGAIN) {
- syslog(LOG_ERR, _("Error while waiting for input: %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while waiting for input: %s"),
strerror(errno));
cp_trace();
dump_connections();
/* Should we regenerate our key? */
if(keyexpires < now) {
- if(debug_lvl >= DEBUG_STATUS)
- syslog(LOG_INFO, _("Regenerating symmetric key"));
+ logger(DEBUG_STATUS, LOG_INFO, _("Regenerating symmetric key"));
RAND_pseudo_bytes(myself->key, myself->keylength);
EVP_DecryptInit_ex(&packet_ctx, myself->cipher, NULL, myself->key, myself->key + myself->cipher->key_len);
}
if(sigalrm) {
- syslog(LOG_INFO, _("Flushing event queue"));
+ logger(DEBUG_ALWAYS, LOG_INFO, _("Flushing event queue"));
while(event_tree->head) {
event = (event_t *) event_tree->head->data;
init_configuration(&config_tree);
if(read_server_config()) {
- syslog(LOG_ERR, _("Unable to reread configuration file, exitting."));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unable to reread configuration file, exitting."));
exit(1);
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net_packet.c,v 1.1.2.30 2003/05/07 11:21:58 guus Exp $
+ $Id: net_packet.c,v 1.1.2.31 2003/07/06 22:11:32 guus Exp $
*/
#include "config.h"
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
-#include <syslog.h>
#include <unistd.h>
#include <sys/ioctl.h>
/* SunOS really wants sys/socket.h BEFORE net/if.h,
#include "route.h"
#include "device.h"
#include "event.h"
+#include "logger.h"
#include "system.h"
(char *) &inpkt->seqno, inpkt->len, hmac, NULL);
if(memcmp(hmac, (char *) &inpkt->seqno + inpkt->len, myself->maclength)) {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Got unauthenticated packet from %s (%s)"),
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Got unauthenticated packet from %s (%s)"),
n->name, n->hostname);
return;
}
if(inpkt->seqno != n->received_seqno + 1) {
if(inpkt->seqno >= n->received_seqno + sizeof(n->late) * 8) {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_WARNING, _("Lost %d packets from %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Lost %d packets from %s (%s)"),
inpkt->seqno - n->received_seqno - 1, n->name, n->hostname);
memset(n->late, 0, sizeof(n->late));
} else if (inpkt->seqno <= n->received_seqno) {
if(inpkt->seqno <= n->received_seqno - sizeof(n->late) * 8 || !(n->late[(inpkt->seqno / 8) % sizeof(n->late)] & (1 << inpkt->seqno % 8))) {
- syslog(LOG_WARNING, _("Got late or replayed packet from %s (%s), seqno %d, last received %d"),
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Got late or replayed packet from %s (%s), seqno %d, last received %d"),
n->name, n->hostname, inpkt->seqno, n->received_seqno);
} else
for(i = n->received_seqno + 1; i < inpkt->seqno; i++)
outpkt = pkt[nextpkt++];
if((outpkt->len = uncompress_packet(outpkt->data, inpkt->data, inpkt->len, myself->compression)) < 0) {
- syslog(LOG_ERR, _("Error while uncompressing packet from %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while uncompressing packet from %s (%s)"),
n->name, n->hostname);
return;
}
{
cp();
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Received packet of %d bytes from %s (%s)"),
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Received packet of %d bytes from %s (%s)"),
packet->len, n->name, n->hostname);
route_incoming(n, packet);
/* Make sure we have a valid key */
if(!n->status.validkey) {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_INFO,
+ logger(DEBUG_TRAFFIC, LOG_INFO,
_("No valid key known yet for %s (%s), queueing packet"),
n->name, n->hostname);
outpkt = pkt[nextpkt++];
if((outpkt->len = compress_packet(outpkt->data, inpkt->data, inpkt->len, n->compression)) < 0) {
- syslog(LOG_ERR, _("Error while compressing packet to %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while compressing packet to %s (%s)"),
n->name, n->hostname);
return;
}
if(priorityinheritance && origpriority != priority
&& listen_socket[sock].sa.sa.sa_family == AF_INET) {
priority = origpriority;
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Setting outgoing packet priority to %d"),
- priority);
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Setting outgoing packet priority to %d"), priority);
if(setsockopt(listen_socket[sock].udp, SOL_IP, IP_TOS, &priority, sizeof(priority))) /* SO_PRIORITY doesn't seem to work */
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "setsockopt",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("System call `%s' failed: %s"), "setsockopt",
strerror(errno));
}
#endif
if((sendto(listen_socket[sock].udp, (char *) &inpkt->seqno, inpkt->len, 0, &(n->address.sa), SALEN(n->address.sa))) < 0) {
- syslog(LOG_ERR, _("Error sending packet to %s (%s): %s"), n->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error sending packet to %s (%s): %s"), n->name,
n->hostname, strerror(errno));
return;
}
cp();
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_ERR, _("Sending packet of %d bytes to %s (%s)"),
+ logger(DEBUG_TRAFFIC, LOG_ERR, _("Sending packet of %d bytes to %s (%s)"),
packet->len, n->name, n->hostname);
if(n == myself) {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_NOTICE, _("Packet is looping back to us!"));
-
+ logger(DEBUG_TRAFFIC, LOG_NOTICE, _("Packet is looping back to us!"));
return;
}
if(!n->status.reachable) {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_INFO, _("Node %s (%s) is not reachable"),
+ logger(DEBUG_TRAFFIC, LOG_INFO, _("Node %s (%s) is not reachable"),
n->name, n->hostname);
-
return;
}
via = (n->via == myself) ? n->nexthop : n->via;
- if(via != n && debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_ERR, _("Sending packet to %s via %s (%s)"),
+ if(via != n)
+ logger(DEBUG_TRAFFIC, LOG_ERR, _("Sending packet to %s via %s (%s)"),
n->name, via->name, n->via->hostname);
if((myself->options | via->options) & OPTION_TCPONLY) {
cp();
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_INFO, _("Broadcasting packet of %d bytes from %s (%s)"),
+ logger(DEBUG_TRAFFIC, LOG_INFO, _("Broadcasting packet of %d bytes from %s (%s)"),
packet->len, from->name, from->hostname);
for(node = connection_tree->head; node; node = node->next) {
cp();
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_INFO, _("Flushing queue for %s (%s)"), n->name, n->hostname);
+ logger(DEBUG_TRAFFIC, LOG_INFO, _("Flushing queue for %s (%s)"), n->name, n->hostname);
for(node = n->queue->head; node; node = next) {
next = node->next;
cp();
if(getsockopt(sock, SOL_SOCKET, SO_ERROR, &x, &l) < 0) {
- syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("This is a bug: %s:%d: %d:%s"),
__FILE__, __LINE__, sock, strerror(errno));
cp_trace();
exit(1);
}
if(x) {
- syslog(LOG_ERR, _("Incoming data socket error: %s"), strerror(x));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Incoming data socket error: %s"), strerror(x));
return;
}
pkt.len = recvfrom(sock, (char *) &pkt.seqno, MAXSIZE, 0, &from.sa, &fromlen);
if(pkt.len <= 0) {
- syslog(LOG_ERR, _("Receiving packet failed: %s"), strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Receiving packet failed: %s"), strerror(errno));
return;
}
if(!n) {
hostname = sockaddr2hostname(&from);
- syslog(LOG_WARNING, _("Received UDP packet from unknown source %s"),
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Received UDP packet from unknown source %s"),
hostname);
free(hostname);
return;
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net_setup.c,v 1.1.2.32 2003/06/25 20:52:59 guus Exp $
+ $Id: net_setup.c,v 1.1.2.33 2003/07/06 22:11:32 guus Exp $
*/
#include "config.h"
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
-#include <syslog.h>
#include <unistd.h>
#include <sys/ioctl.h>
/* SunOS really wants sys/socket.h BEFORE net/if.h,
#include "route.h"
#include "device.h"
#include "event.h"
+#include "logger.h"
#include "system.h"
fp = fopen(fname, "r");
if(!fp) {
- syslog(LOG_ERR, _("Error reading RSA public key file `%s': %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error reading RSA public key file `%s': %s"),
fname, strerror(errno));
free(fname);
return -1;
fp = fopen(fname, "r");
if(!fp) {
- syslog(LOG_ERR, _("Error reading RSA public key file `%s': %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error reading RSA public key file `%s': %s"),
fname, strerror(errno));
free(fname);
return -1;
return 0;
}
- syslog(LOG_ERR, _("Reading RSA public key file `%s' failed: %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Reading RSA public key file `%s' failed: %s"),
fname, strerror(errno));
return -1;
} else {
if(c->rsa_key)
return 0;
- syslog(LOG_ERR, _("No public key for %s specified!"), c->name);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("No public key for %s specified!"), c->name);
return -1;
}
fp = fopen(fname, "r");
if(!fp) {
- syslog(LOG_ERR, _("Error reading RSA private key file `%s': %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error reading RSA private key file `%s': %s"),
fname, strerror(errno));
free(fname);
return -1;
fclose(fp);
if(!myself->connection->rsa_key) {
- syslog(LOG_ERR, _("Reading RSA private key file `%s' failed: %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Reading RSA private key file `%s' failed: %s"),
fname, strerror(errno));
return -1;
}
myself->connection->protocol_version = PROT_CURRENT;
if(!get_config_string(lookup_config(config_tree, "Name"), &name)) { /* Not acceptable */
- syslog(LOG_ERR, _("Name for tinc daemon required!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Name for tinc daemon required!"));
return -1;
}
if(check_id(name)) {
- syslog(LOG_ERR, _("Invalid name for myself!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Invalid name for myself!"));
free(name);
return -1;
}
return -1;
if(read_connection_config(myself->connection)) {
- syslog(LOG_ERR, _("Cannot open host configuration file for myself!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Cannot open host configuration file for myself!"));
return -1;
}
else if(!strcasecmp(mode, "hub"))
routing_mode = RMODE_HUB;
else {
- syslog(LOG_ERR, _("Invalid routing mode!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Invalid routing mode!"));
return -1;
}
free(mode);
&priorityinheritance);
#if !defined(SOL_IP) || !defined(IP_TOS)
if(priorityinheritance)
- syslog(LOG_WARNING, _("PriorityInheritance not supported on this platform"));
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("PriorityInheritance not supported on this platform"));
#endif
if(!get_config_int(lookup_config(config_tree, "MACExpire"), &macexpire))
(lookup_config(myself->connection->config_tree, "MaxTimeout"),
&maxtimeout)) {
if(maxtimeout <= 0) {
- syslog(LOG_ERR, _("Bogus maximum timeout!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Bogus maximum timeout!"));
return -1;
}
} else
else if(!strcasecmp(afname, "any"))
addressfamily = AF_UNSPEC;
else {
- syslog(LOG_ERR, _("Invalid address family!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Invalid address family!"));
return -1;
}
free(afname);
myself->cipher = EVP_get_cipherbyname(cipher);
if(!myself->cipher) {
- syslog(LOG_ERR, _("Unrecognized cipher type!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unrecognized cipher type!"));
return -1;
}
}
myself->digest = EVP_get_digestbyname(digest);
if(!myself->digest) {
- syslog(LOG_ERR, _("Unrecognized digest type!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unrecognized digest type!"));
return -1;
}
}
&myself->maclength)) {
if(myself->digest) {
if(myself->maclength > myself->digest->md_size) {
- syslog(LOG_ERR, _("MAC length exceeds size of digest!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("MAC length exceeds size of digest!"));
return -1;
} else if(myself->maclength < 0) {
- syslog(LOG_ERR, _("Bogus MAC length!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Bogus MAC length!"));
return -1;
}
}
(lookup_config(myself->connection->config_tree, "Compression"),
&myself->compression)) {
if(myself->compression < 0 || myself->compression > 11) {
- syslog(LOG_ERR, _("Bogus compression level!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Bogus compression level!"));
return -1;
}
} else
err = getaddrinfo(address, myport, &hint, &ai);
if(err || !ai) {
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "getaddrinfo",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("System call `%s' failed: %s"), "getaddrinfo",
gai_strerror(err));
return -1;
}
if(listen_socket[listen_sockets].udp < 0)
continue;
- if(debug_lvl >= DEBUG_CONNECTIONS) {
+ if(debug_level >= DEBUG_CONNECTIONS) {
hostname = sockaddr2hostname((sockaddr_t *) aip->ai_addr);
- syslog(LOG_NOTICE, _("Listening on %s"), hostname);
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Listening on %s"), hostname);
free(hostname);
}
freeaddrinfo(ai);
if(listen_sockets)
- syslog(LOG_NOTICE, _("Ready"));
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Ready"));
else {
- syslog(LOG_ERR, _("Unable to create any listening socket!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unable to create any listening socket!"));
return -1;
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net_socket.c,v 1.1.2.24 2003/06/11 19:27:35 guus Exp $
+ $Id: net_socket.c,v 1.1.2.25 2003/07/06 22:11:32 guus Exp $
*/
#include "config.h"
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
-#include <syslog.h>
#include <unistd.h>
#include <sys/ioctl.h>
/* SunOS really wants sys/socket.h BEFORE net/if.h,
#include "route.h"
#include "device.h"
#include "event.h"
+#include "logger.h"
#include "system.h"
nfd = socket(sa->sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
if(nfd < 0) {
- syslog(LOG_ERR, _("Creating metasocket failed: %s"), strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Creating metasocket failed: %s"), strerror(errno));
return -1;
}
if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) {
close(nfd);
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "fcntl",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("System call `%s' failed: %s"), "fcntl",
strerror(errno));
return -1;
}
if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr))) {
close(nfd);
- syslog(LOG_ERR, _("Can't bind to interface %s: %s"), interface,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't bind to interface %s: %s"), interface,
strerror(errno));
return -1;
}
#else
- syslog(LOG_WARNING, _("BindToInterface not supported on this platform"));
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("BindToInterface not supported on this platform"));
#endif
}
if(bind(nfd, &sa->sa, SALEN(sa->sa))) {
close(nfd);
addrstr = sockaddr2hostname(sa);
- syslog(LOG_ERR, _("Can't bind to %s/tcp: %s"), addrstr,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't bind to %s/tcp: %s"), addrstr,
strerror(errno));
free(addrstr);
return -1;
if(listen(nfd, 3)) {
close(nfd);
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "listen",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("System call `%s' failed: %s"), "listen",
strerror(errno));
return -1;
}
nfd = socket(sa->sa.sa_family, SOCK_DGRAM, IPPROTO_UDP);
if(nfd < 0) {
- syslog(LOG_ERR, _("Creating UDP socket failed: %s"), strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Creating UDP socket failed: %s"), strerror(errno));
return -1;
}
flags = fcntl(nfd, F_GETFL);
if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) {
close(nfd);
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "fcntl",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("System call `%s' failed: %s"), "fcntl",
strerror(errno));
return -1;
}
if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr))) {
close(nfd);
- syslog(LOG_ERR, _("Can't bind to interface %s: %s"), interface,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't bind to interface %s: %s"), interface,
strerror(errno));
return -1;
}
if(bind(nfd, &sa->sa, SALEN(sa->sa))) {
close(nfd);
addrstr = sockaddr2hostname(sa);
- syslog(LOG_ERR, _("Can't bind to %s/udp: %s"), addrstr,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't bind to %s/udp: %s"), addrstr,
strerror(errno));
free(addrstr);
return -1;
event->data = outgoing;
event_add(event);
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE,
+ logger(DEBUG_CONNECTIONS, LOG_NOTICE,
_("Trying to re-establish outgoing connection in %d seconds"),
outgoing->timeout);
}
{
cp();
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_INFO, _("Connected to %s (%s)"), c->name, c->hostname);
+ logger(DEBUG_CONNECTIONS, LOG_INFO, _("Connected to %s (%s)"), c->name, c->hostname);
c->last_ping_time = now;
begin:
if(!c->outgoing->ai) {
if(!c->outgoing->cfg) {
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_ERR, _("Could not set up a meta connection to %s"),
+ logger(DEBUG_CONNECTIONS, LOG_ERR, _("Could not set up a meta connection to %s"),
c->name);
c->status.remove = 1;
retry_outgoing(c->outgoing);
c->hostname = sockaddr2hostname(&c->address);
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_INFO, _("Trying to connect to %s (%s)"), c->name,
+ logger(DEBUG_CONNECTIONS, LOG_INFO, _("Trying to connect to %s (%s)"), c->name,
c->hostname);
c->socket = socket(c->address.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
if(c->socket == -1) {
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_ERR, _("Creating socket for %s failed: %s"), c->hostname,
+ logger(DEBUG_CONNECTIONS, LOG_ERR, _("Creating socket for %s failed: %s"), c->hostname,
strerror(errno));
goto begin;
flags = fcntl(c->socket, F_GETFL);
if(fcntl(c->socket, F_SETFL, flags | O_NONBLOCK) < 0) {
- syslog(LOG_ERR, _("fcntl for %s: %s"), c->hostname, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("fcntl for %s: %s"), c->hostname, strerror(errno));
}
/* Connect */
close(c->socket);
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_ERR, _("%s: %s"), c->hostname, strerror(errno));
+ logger(DEBUG_CONNECTIONS, LOG_ERR, _("%s: %s"), c->hostname, strerror(errno));
goto begin;
}
if(n)
if(n->connection) {
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_INFO, _("Already connected to %s"), outgoing->name);
+ logger(DEBUG_CONNECTIONS, LOG_INFO, _("Already connected to %s"), outgoing->name);
n->connection->outgoing = outgoing;
return;
outgoing->cfg = lookup_config(c->config_tree, "Address");
if(!outgoing->cfg) {
- syslog(LOG_ERR, _("No address specified for %s"), c->name);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("No address specified for %s"), c->name);
free_connection(c);
free(outgoing->name);
free(outgoing);
fd = accept(sock, &sa.sa, &len);
if(fd < 0) {
- syslog(LOG_ERR, _("Accepting a new connection failed: %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Accepting a new connection failed: %s"),
strerror(errno));
return -1;
}
c->socket = fd;
c->last_ping_time = now;
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Connection from %s"), c->hostname);
+ logger(DEBUG_CONNECTIONS, LOG_NOTICE, _("Connection from %s"), c->hostname);
connection_add(c);
get_config_string(cfg, &name);
if(check_id(name)) {
- syslog(LOG_ERR,
+ logger(DEBUG_ALWAYS, LOG_ERR,
_("Invalid name for outgoing connection in %s line %d"),
cfg->file, cfg->line);
free(name);
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: device.c,v 1.1.2.8 2003/06/11 19:28:37 guus Exp $
+ $Id: device.c,v 1.1.2.9 2003/07/06 22:11:35 guus Exp $
*/
#include "config.h"
#include <fcntl.h>
#include <net/if.h>
#include <unistd.h>
-#include <syslog.h>
#include <string.h>
#include <utils.h>
#include "conf.h"
#include "net.h"
-#include "subnet.h"
+#include "logger.h"
#include "system.h"
if(!get_config_string(lookup_config(config_tree, "Interface"), &interface))
interface = rindex(device, '/') ? rindex(device, '/') + 1 : device;
if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
- syslog(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
return -1;
}
device_info = _("NetBSD tun device");
- syslog(LOG_INFO, _("%s is a %s"), device, device_info);
+ logger(DEBUG_ALWAYS, LOG_INFO, _("%s is a %s"), device, device_info);
return 0;
}
cp();
if((lenin = read(device_fd, packet->data + 14, MTU - 14)) <= 0) {
- syslog(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
device, strerror(errno));
return -1;
}
device_total_in += packet->len;
- if(debug_lvl >= DEBUG_TRAFFIC) {
- syslog(LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
device_info);
}
{
cp();
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Writing packet of %d bytes to %s"),
packet->len, device_info);
if(write(device_fd, packet->data + 14, packet->len - 14) < 0) {
- syslog(LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
strerror(errno));
return -1;
}
{
cp();
- syslog(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
- syslog(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
- syslog(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: netutl.c,v 1.12.4.44 2002/09/09 22:32:44 guus Exp $
+ $Id: netutl.c,v 1.12.4.45 2003/07/06 22:11:32 guus Exp $
*/
#include "config.h"
#include <string.h>
#include <signal.h>
#include <sys/socket.h>
-#include <syslog.h>
#include <arpa/inet.h>
#include <utils.h>
#include "conf.h"
#include "net.h"
#include "netutl.h"
+#include "logger.h"
#include "system.h"
err = getaddrinfo(address, service, &hint, &ai);
if(err) {
- if(debug_lvl >= DEBUG_ERROR)
- syslog(LOG_WARNING, _("Error looking up %s port %s: %s\n"), address,
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Error looking up %s port %s: %s\n"), address,
service, gai_strerror(err));
- cp_trace();
return NULL;
}
err = getaddrinfo(address, port, &hint, &ai);
if(err || !ai) {
- syslog(LOG_ERR, _("Error looking up %s port %s: %s\n"), address, port,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error looking up %s port %s: %s\n"), address, port,
gai_strerror(err));
cp_trace();
raise(SIGFPE);
err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV);
if(err) {
- syslog(LOG_ERR, _("Error while translating addresses: %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while translating addresses: %s"),
gai_strerror(err));
cp_trace();
raise(SIGFPE);
err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port),
hostnames ? 0 : (NI_NUMERICHOST | NI_NUMERICSERV));
if(err) {
- syslog(LOG_ERR, _("Error while looking up hostname: %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while looking up hostname: %s"),
gai_strerror(err));
}
return memcmp(&a->in6.sin6_port, &b->in6.sin6_port, sizeof(a->in6.sin6_port));
default:
- syslog(LOG_ERR, _("sockaddrcmp() was called with unknown address family %d, exitting!"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("sockaddrcmp() was called with unknown address family %d, exitting!"),
a->sa.sa_family);
cp_trace();
raise(SIGFPE);
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: node.c,v 1.1.2.19 2003/05/06 21:13:17 guus Exp $
+ $Id: node.c,v 1.1.2.20 2003/07/06 22:11:32 guus Exp $
*/
#include "config.h"
#include <string.h>
-#include <syslog.h>
#include <avl_tree.h>
#include "node.h"
#include "netutl.h"
#include "net.h"
+#include "logger.h"
+
#include <utils.h>
#include <xalloc.h>
cp();
- syslog(LOG_DEBUG, _("Nodes:"));
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Nodes:"));
for(node = node_tree->head; node; node = node->next) {
n = (node_t *) node->data;
- syslog(LOG_DEBUG, _(" %s at %s cipher %d digest %d maclength %d compression %d options %lx status %04x nexthop %s via %s"),
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" %s at %s cipher %d digest %d maclength %d compression %d options %lx status %04x nexthop %s via %s"),
n->name, n->hostname, n->cipher ? n->cipher->nid : 0,
n->digest ? n->digest->type : 0, n->maclength, n->compression,
n->options, n->status, n->nexthop ? n->nexthop->name : "-",
n->via ? n->via->name : "-");
}
- syslog(LOG_DEBUG, _("End of nodes."));
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("End of nodes."));
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: device.c,v 1.1.2.13 2003/06/11 19:28:37 guus Exp $
+ $Id: device.c,v 1.1.2.14 2003/07/06 22:11:37 guus Exp $
*/
#include "config.h"
#include <fcntl.h>
#include <net/if.h>
#include <unistd.h>
-#include <syslog.h>
#include <string.h>
#include <utils.h>
#include "conf.h"
#include "net.h"
-#include "subnet.h"
+#include "logger.h"
#include "system.h"
if(!get_config_string(lookup_config(config_tree, "Interface"), &interface))
interface = rindex(device, '/') ? rindex(device, '/') + 1 : device;
if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
- syslog(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
return -1;
}
device_info = _("OpenBSD tun device");
- syslog(LOG_INFO, _("%s is a %s"), device, device_info);
+ logger(DEBUG_ALWAYS, LOG_INFO, _("%s is a %s"), device, device_info);
return 0;
}
cp();
if((lenin = readv(device_fd, vector, 2)) <= 0) {
- syslog(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
device, strerror(errno));
return -1;
}
break;
default:
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_ERR,
- _
- ("Unknown address family %d while reading packet from %s %s"),
+ logger(DEBUG_TRAFFIC, LOG_ERR,
+ _ ("Unknown address family %d while reading packet from %s %s"),
ntohl(type), device_info, device);
return -1;
}
device_total_in += packet->len;
- if(debug_lvl >= DEBUG_TRAFFIC) {
- syslog(LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
device_info);
}
cp();
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Writing packet of %d bytes to %s"),
packet->len, device_info);
af = (packet->data[12] << 8) + packet->data[13];
type = htonl(AF_INET6);
break;
default:
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_ERR,
+ logger(DEBUG_TRAFFIC, LOG_ERR,
_("Unknown address family %d while writing packet to %s %s"),
af, device_info, device);
return -1;
vector[1].iov_len = packet->len - 14;
if(writev(device_fd, vector, 2) < 0) {
- syslog(LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
strerror(errno));
return -1;
}
{
cp();
- syslog(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
- syslog(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
- syslog(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: process.c,v 1.1.2.50 2002/09/30 19:04:37 zarq Exp $
+ $Id: process.c,v 1.1.2.51 2003/07/06 22:11:32 guus Exp $
*/
#include "config.h"
#include <signal.h>
#include <stdio.h>
#include <string.h>
-#include <syslog.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "device.h"
#include "connection.h"
#include "device.h"
+#include "logger.h"
#include "system.h"
extern char *identname;
extern char *pidfilename;
extern char **g_argv;
+extern int use_logfile;
sigset_t emptysigset;
-static int saved_debug_lvl = -1;
+static int saved_debug_level = -1;
extern int sighup;
extern int sigalrm;
void memory_full(int size)
{
- syslog(LOG_ERR, _("Memory exhausted (couldn't allocate %d bytes), exitting."), size);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Memory exhausted (couldn't allocate %d bytes), exitting."), size);
cp_trace();
exit(1);
}
close_network_connections();
- if(debug_lvl > DEBUG_NOTHING)
+ if(debug_level > DEBUG_NOTHING)
dump_device_stats();
- syslog(LOG_NOTICE, _("Terminating"));
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Terminating"));
closelog();
exit(c);
return -1;
}
- openlog(identname, LOG_CONS | LOG_PID, LOG_DAEMON);
+ openlogger(identname, use_logfile?LOGMODE_FILE:(do_detach?LOGMODE_SYSLOG:LOGMODE_STDERR));
- if(debug_lvl > DEBUG_NOTHING)
- syslog(LOG_NOTICE, _("tincd %s (%s %s) starting, debug level %d"),
- VERSION, __DATE__, __TIME__, debug_lvl);
- else
- syslog(LOG_NOTICE, _("tincd %s starting"), VERSION);
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("tincd %s (%s %s) starting, debug level %d"),
+ VERSION, __DATE__, __TIME__, debug_level);
xalloc_fail_func = memory_full;
}
/*
- Execute the program name, with sane environment. All output will be
- redirected to syslog.
+ Execute the program name, with sane environment.
*/
void _execute_script(const char *scriptname, char **envp)
__attribute__ ((noreturn));
chdir("/");
+ closelogger();
+
/* Close all file descriptors */
- closelog(); /* <- this means we cannot use syslog() here anymore! */
fcloseall();
execl(scriptname, NULL);
/* No return on success */
- openlog("tinc", LOG_CONS | LOG_PID, LOG_DAEMON);
- syslog(LOG_ERR, _("Could not execute `%s': %s"), scriptname,
+ openlogger(identname, use_logfile?LOGMODE_FILE:(do_detach?LOGMODE_SYSLOG:LOGMODE_STDERR));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Could not execute `%s': %s"), scriptname,
strerror(errno));
exit(errno);
}
pid = fork();
if(pid < 0) {
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "fork",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("System call `%s' failed: %s"), "fork",
strerror(errno));
return -1;
}
if(pid) {
- if(debug_lvl >= DEBUG_STATUS)
- syslog(LOG_INFO, _("Executing script %s"), name);
+ logger(DEBUG_STATUS, LOG_INFO, _("Executing script %s"), name);
free(scriptname);
if(waitpid(pid, &status, 0) == pid) {
if(WIFEXITED(status)) { /* Child exited by itself */
if(WEXITSTATUS(status)) {
- syslog(LOG_ERR, _("Process %d (%s) exited with non-zero status %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Process %d (%s) exited with non-zero status %d"),
pid, name, WEXITSTATUS(status));
return -1;
} else
return 0;
} else if(WIFSIGNALED(status)) { /* Child was killed by a signal */
- syslog(LOG_ERR, _("Process %d (%s) was killed by signal %d (%s)"), pid,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Process %d (%s) was killed by signal %d (%s)"), pid,
name, WTERMSIG(status), strsignal(WTERMSIG(status)));
return -1;
} else { /* Something strange happened */
-
- syslog(LOG_ERR, _("Process %d (%s) terminated abnormally"), pid,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Process %d (%s) terminated abnormally"), pid,
name);
return -1;
}
} else {
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "waitpid",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("System call `%s' failed: %s"), "waitpid",
strerror(errno));
return -1;
}
RETSIGTYPE sigterm_handler(int a)
{
- if(debug_lvl > DEBUG_NOTHING)
- syslog(LOG_NOTICE, _("Got TERM signal"));
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Got TERM signal"));
cleanup_and_exit(0);
}
RETSIGTYPE sigquit_handler(int a)
{
- if(debug_lvl > DEBUG_NOTHING)
- syslog(LOG_NOTICE, _("Got QUIT signal"));
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Got QUIT signal"));
cleanup_and_exit(0);
}
RETSIGTYPE fatal_signal_square(int a)
{
- syslog(LOG_ERR, _("Got another fatal signal %d (%s): not restarting."), a,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got another fatal signal %d (%s): not restarting."), a,
strsignal(a));
cp_trace();
exit(1);
RETSIGTYPE fatal_signal_handler(int a)
{
struct sigaction act;
- syslog(LOG_ERR, _("Got fatal signal %d (%s)"), a, strsignal(a));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got fatal signal %d (%s)"), a, strsignal(a));
cp_trace();
if(do_detach) {
- syslog(LOG_NOTICE, _("Trying to re-execute in 5 seconds..."));
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Trying to re-execute in 5 seconds..."));
act.sa_handler = fatal_signal_square;
act.sa_mask = emptysigset;
remove_pid(pidfilename);
execvp(g_argv[0], g_argv);
} else {
- syslog(LOG_NOTICE, _("Not restarting."));
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Not restarting."));
exit(1);
}
}
RETSIGTYPE sighup_handler(int a)
{
- if(debug_lvl > DEBUG_NOTHING)
- syslog(LOG_NOTICE, _("Got HUP signal"));
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Got HUP signal"));
sighup = 1;
}
RETSIGTYPE sigint_handler(int a)
{
- if(saved_debug_lvl != -1) {
- syslog(LOG_NOTICE, _("Reverting to old debug level (%d)"),
- saved_debug_lvl);
- debug_lvl = saved_debug_lvl;
- saved_debug_lvl = -1;
+ if(saved_debug_level != -1) {
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Reverting to old debug level (%d)"),
+ saved_debug_level);
+ debug_level = saved_debug_level;
+ saved_debug_level = -1;
} else {
- syslog(LOG_NOTICE, _("Temporarily setting debug level to 5. Kill me with SIGINT again to go back to level %d."),
- debug_lvl);
- saved_debug_lvl = debug_lvl;
- debug_lvl = 5;
+ logger(DEBUG_ALWAYS, LOG_NOTICE,
+ _("Temporarily setting debug level to 5. Kill me with SIGINT again to go back to level %d."),
+ debug_level);
+ saved_debug_level = debug_level;
+ debug_level = 5;
}
}
RETSIGTYPE sigalrm_handler(int a)
{
- if(debug_lvl > DEBUG_NOTHING)
- syslog(LOG_NOTICE, _("Got ALRM signal"));
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Got ALRM signal"));
sigalrm = 1;
}
RETSIGTYPE unexpected_signal_handler(int a)
{
- syslog(LOG_WARNING, _("Got unexpected signal %d (%s)"), a, strsignal(a));
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Got unexpected signal %d (%s)"), a, strsignal(a));
cp_trace();
}
RETSIGTYPE ignore_signal_handler(int a)
{
- if(debug_lvl >= DEBUG_SCARY_THINGS) {
- syslog(LOG_DEBUG, _("Ignored signal %d (%s)"), a, strsignal(a));
- cp_trace();
- }
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, _("Ignored signal %d (%s)"), a, strsignal(a));
}
struct {
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: protocol.c,v 1.28.4.137 2002/09/09 22:32:49 guus Exp $
+ $Id: protocol.c,v 1.28.4.138 2003/07/06 22:11:32 guus Exp $
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include "protocol.h"
#include "meta.h"
#include "connection.h"
+#include "logger.h"
#include "system.h"
va_end(args);
if(len < 0 || len > MAXBUFSIZE - 1) {
- syslog(LOG_ERR, _("Output buffer overflow while sending request to %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Output buffer overflow while sending request to %s (%s)"),
c->name, c->hostname);
return -1;
}
- if(debug_lvl >= DEBUG_PROTOCOL) {
+ if(debug_level >= DEBUG_PROTOCOL) {
sscanf(buffer, "%d", &request);
- if(debug_lvl >= DEBUG_META)
- syslog(LOG_DEBUG, _("Sending %s to %s (%s): %s"),
+ if(debug_level >= DEBUG_META)
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Sending %s to %s (%s): %s"),
request_name[request], c->name, c->hostname, buffer);
else
- syslog(LOG_DEBUG, _("Sending %s to %s (%s)"), request_name[request],
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Sending %s to %s (%s)"), request_name[request],
c->name, c->hostname);
}
cp();
- if(debug_lvl >= DEBUG_PROTOCOL) {
+ if(debug_level >= DEBUG_PROTOCOL) {
sscanf(from->buffer, "%d", &request);
- if(debug_lvl >= DEBUG_META)
- syslog(LOG_DEBUG, _("Forwarding %s from %s (%s): %s"),
+ if(debug_level >= DEBUG_META)
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Forwarding %s from %s (%s): %s"),
request_name[request], from->name, from->hostname,
from->buffer);
else
- syslog(LOG_DEBUG, _("Forwarding %s from %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Forwarding %s from %s (%s)"),
request_name[request], from->name, from->hostname);
}
if(sscanf(c->buffer, "%d", &request) == 1) {
if((request < 0) || (request >= LAST) || !request_handlers[request]) {
- if(debug_lvl >= DEBUG_META)
- syslog(LOG_DEBUG, _("Unknown request from %s (%s): %s"),
+ if(debug_level >= DEBUG_META)
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Unknown request from %s (%s): %s"),
c->name, c->hostname, c->buffer);
else
- syslog(LOG_ERR, _("Unknown request from %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unknown request from %s (%s)"),
c->name, c->hostname);
return -1;
} else {
- if(debug_lvl >= DEBUG_PROTOCOL) {
- if(debug_lvl >= DEBUG_META)
- syslog(LOG_DEBUG, _("Got %s from %s (%s): %s"),
+ if(debug_level >= DEBUG_PROTOCOL) {
+ if(debug_level >= DEBUG_META)
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Got %s from %s (%s): %s"),
request_name[request], c->name, c->hostname,
c->buffer);
else
- syslog(LOG_DEBUG, _("Got %s from %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Got %s from %s (%s)"),
request_name[request], c->name, c->hostname);
}
}
if((c->allow_request != ALL) && (c->allow_request != request)) {
- syslog(LOG_ERR, _("Unauthorized request from %s (%s)"), c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unauthorized request from %s (%s)"), c->name,
c->hostname);
return -1;
}
if(request_handlers[request] (c))
/* Something went wrong. Probably scriptkiddies. Terminate. */
{
- syslog(LOG_ERR, _("Error while processing %s from %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while processing %s from %s (%s)"),
request_name[request], c->name, c->hostname);
return -1;
}
} else {
- syslog(LOG_ERR, _("Bogus data received from %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Bogus data received from %s (%s)"),
c->name, c->hostname);
return -1;
}
p.request = request;
if(avl_search(past_request_tree, &p)) {
- if(debug_lvl >= DEBUG_SCARY_THINGS)
- syslog(LOG_DEBUG, _("Already seen request"));
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, _("Already seen request"));
return 1;
} else {
new = (past_request_t *) xmalloc(sizeof(*new));
left++;
}
- if(debug_lvl >= DEBUG_SCARY_THINGS && left + deleted)
- syslog(LOG_DEBUG, _("Aging past requests: deleted %d, left %d\n"),
+ if(left || deleted)
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, _("Aging past requests: deleted %d, left %d\n"),
deleted, left);
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: protocol_auth.c,v 1.1.4.20 2003/07/06 17:15:25 guus Exp $
+ $Id: protocol_auth.c,v 1.1.4.21 2003/07/06 22:11:32 guus Exp $
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include "node.h"
#include "edge.h"
#include "graph.h"
+#include "logger.h"
#include "system.h"
cp();
if(sscanf(c->buffer, "%*d " MAX_STRING " %d", name, &c->protocol_version) != 2) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ID", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "ID", c->name,
c->hostname);
return -1;
}
/* Check if identity is a valid name */
if(check_id(name)) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ID", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s): %s"), "ID", c->name,
c->hostname, "invalid name");
return -1;
}
if(c->name) {
if(strcmp(c->name, name)) {
- syslog(LOG_ERR, _("Peer %s is %s instead of %s"), c->hostname, name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Peer %s is %s instead of %s"), c->hostname, name,
c->name);
return -1;
}
/* Check if version matches */
if(c->protocol_version != myself->connection->protocol_version) {
- syslog(LOG_ERR, _("Peer %s (%s) uses incompatible version %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Peer %s (%s) uses incompatible version %d"),
c->name, c->hostname, c->protocol_version);
return -1;
}
bla = read_connection_config(c);
if(bla) {
- syslog(LOG_ERR, _("Peer %s had unknown identity (%s)"), c->hostname,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Peer %s had unknown identity (%s)"), c->hostname,
c->name);
return -1;
}
c->outkey[0] &= 0x7F;
- if(debug_lvl >= DEBUG_SCARY_THINGS) {
+ if(debug_level >= DEBUG_SCARY_THINGS) {
bin2hex(c->outkey, buffer, len);
buffer[len * 2] = '\0';
- syslog(LOG_DEBUG, _("Generated random meta key (unencrypted): %s"),
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Generated random meta key (unencrypted): %s"),
buffer);
}
*/
if(RSA_public_encrypt(len, c->outkey, buffer, c->rsa_key, RSA_NO_PADDING) != len) {
- syslog(LOG_ERR, _("Error during encryption of meta key for %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error during encryption of meta key for %s (%s)"),
c->name, c->hostname);
return -1;
}
cp();
if(sscanf(c->buffer, "%*d %d %d %d %d " MAX_STRING, &cipher, &digest, &maclength, &compression, buffer) != 5) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "METAKEY", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "METAKEY", c->name,
c->hostname);
return -1;
}
/* Check if the length of the meta key is all right */
if(strlen(buffer) != len * 2) {
- syslog(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name, c->hostname, "wrong keylength");
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Possible intruder %s (%s): %s"), c->name, c->hostname, "wrong keylength");
return -1;
}
/* Decrypt the meta key */
if(RSA_private_decrypt(len, buffer, c->inkey, myself->connection->rsa_key, RSA_NO_PADDING) != len) { /* See challenge() */
- syslog(LOG_ERR, _("Error during encryption of meta key for %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error during encryption of meta key for %s (%s)"),
c->name, c->hostname);
return -1;
}
- if(debug_lvl >= DEBUG_SCARY_THINGS) {
+ if(debug_level >= DEBUG_SCARY_THINGS) {
bin2hex(c->inkey, buffer, len);
buffer[len * 2] = '\0';
- syslog(LOG_DEBUG, _("Received random meta key (unencrypted): %s"), buffer);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Received random meta key (unencrypted): %s"), buffer);
}
/* All incoming requests will now be encrypted. */
c->incipher = EVP_get_cipherbynid(cipher);
if(!c->incipher) {
- syslog(LOG_ERR, _("%s (%s) uses unknown cipher!"), c->name, c->hostname);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("%s (%s) uses unknown cipher!"), c->name, c->hostname);
return -1;
}
c->indigest = EVP_get_digestbynid(digest);
if(!c->indigest) {
- syslog(LOG_ERR, _("Node %s (%s) uses unknown digest!"), c->name, c->hostname);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Node %s (%s) uses unknown digest!"), c->name, c->hostname);
return -1;
}
if(c->inmaclength > c->indigest->md_size || c->inmaclength < 0) {
- syslog(LOG_ERR, _("%s (%s) uses bogus MAC length!"), c->name, c->hostname);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("%s (%s) uses bogus MAC length!"), c->name, c->hostname);
return -1;
}
} else {
cp();
if(sscanf(c->buffer, "%*d " MAX_STRING, buffer) != 1) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "CHALLENGE", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "CHALLENGE", c->name,
c->hostname);
return -1;
}
/* Check if the length of the challenge is all right */
if(strlen(buffer) != len * 2) {
- syslog(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
c->hostname, "wrong challenge length");
return -1;
}
cp();
if(sscanf(c->buffer, "%*d " MAX_STRING, hishash) != 1) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "CHAL_REPLY", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "CHAL_REPLY", c->name,
c->hostname);
return -1;
}
/* Check if the length of the hash is all right */
if(strlen(hishash) != c->outdigest->md_size * 2) {
- syslog(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
c->hostname, _("wrong challenge reply length"));
return -1;
}
/* Verify the incoming hash with the calculated hash */
if(memcmp(hishash, myhash, c->outdigest->md_size)) {
- syslog(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
c->hostname, _("wrong challenge reply"));
- if(debug_lvl >= DEBUG_SCARY_THINGS) {
+ if(debug_level >= DEBUG_SCARY_THINGS) {
bin2hex(myhash, hishash, SHA_DIGEST_LENGTH);
hishash[SHA_DIGEST_LENGTH * 2] = '\0';
- syslog(LOG_DEBUG, _("Expected challenge reply: %s"), hishash);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Expected challenge reply: %s"), hishash);
}
return -1;
cp();
- if(sscanf
- (c->buffer, "%*d " MAX_STRING " %d %lx", hisport, &weight, &options) != 3) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ACK", c->name,
+ if(sscanf(c->buffer, "%*d " MAX_STRING " %d %lx", hisport, &weight, &options) != 3) {
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "ACK", c->name,
c->hostname);
return -1;
}
} else {
if(n->connection) {
/* Oh dear, we already have a connection to this node. */
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_DEBUG, _("Established a second connection with %s (%s), closing old connection"),
+ logger(DEBUG_CONNECTIONS, LOG_DEBUG, _("Established a second connection with %s (%s), closing old connection"),
n->name, n->hostname);
terminate_connection(n->connection, 0);
/* Run graph algorithm to purge key and make sure up/down scripts are rerun with new IP addresses and stuff */
c->allow_request = ALL;
c->status.active = 1;
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Connection with %s (%s) activated"), c->name,
+ logger(DEBUG_CONNECTIONS, LOG_NOTICE, _("Connection with %s (%s) activated"), c->name,
c->hostname);
/* Send him everything we know */
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: protocol_edge.c,v 1.1.4.15 2002/09/24 11:43:34 guus Exp $
+ $Id: protocol_edge.c,v 1.1.4.16 2003/07/06 22:11:32 guus Exp $
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include "node.h"
#include "edge.h"
#include "graph.h"
+#include "logger.h"
#include "system.h"
if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %lx %d",
from_name, to_name, to_address, to_port, &options, &weight) != 6) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ADD_EDGE", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "ADD_EDGE", c->name,
c->hostname);
return -1;
}
/* Check if names are valid */
if(check_id(from_name)) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_EDGE", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_EDGE", c->name,
c->hostname, _("invalid name"));
return -1;
}
if(check_id(to_name)) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_EDGE", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_EDGE", c->name,
c->hostname, _("invalid name"));
return -1;
}
if(e) {
if(e->weight != weight || e->options != options || sockaddrcmp(&e->address, &address)) {
if(from == myself) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) for ourself which does not match existing entry"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) for ourself which does not match existing entry"),
"ADD_EDGE", c->name, c->hostname);
send_add_edge(c, e);
return 0;
} else {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) which does not match existing entry"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) which does not match existing entry"),
"ADD_EDGE", c->name, c->hostname);
edge_del(e);
graph();
} else
return 0;
} else if(from == myself) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) for ourself which does not exist"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) for ourself which does not exist"),
"ADD_EDGE", c->name, c->hostname);
e = new_edge();
e->from = from;
cp();
if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING, from_name, to_name) != 2) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "DEL_EDGE", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "DEL_EDGE", c->name,
c->hostname);
return -1;
}
/* Check if names are valid */
if(check_id(from_name)) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_EDGE", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_EDGE", c->name,
c->hostname, _("invalid name"));
return -1;
}
if(check_id(to_name)) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_EDGE", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_EDGE", c->name,
c->hostname, _("invalid name"));
return -1;
}
from = lookup_node(from_name);
if(!from) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_ERR, _("Got %s from %s (%s) which does not appear in the edge tree"),
+ logger(DEBUG_PROTOCOL, LOG_ERR, _("Got %s from %s (%s) which does not appear in the edge tree"),
"DEL_EDGE", c->name, c->hostname);
return 0;
}
to = lookup_node(to_name);
if(!to) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_ERR, _("Got %s from %s (%s) which does not appear in the edge tree"),
+ logger(DEBUG_PROTOCOL, LOG_ERR, _("Got %s from %s (%s) which does not appear in the edge tree"),
"DEL_EDGE", c->name, c->hostname);
return 0;
}
e = lookup_edge(from, to);
if(!e) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) which does not appear in the edge tree"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) which does not appear in the edge tree"),
"DEL_EDGE", c->name, c->hostname);
return 0;
}
if(e->from == myself) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) for ourself"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) for ourself"),
"DEL_EDGE", c->name, c->hostname);
send_add_edge(c, e); /* Send back a correction */
return 0;
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: protocol_key.c,v 1.1.4.16 2003/05/06 21:13:18 guus Exp $
+ $Id: protocol_key.c,v 1.1.4.17 2003/07/06 22:11:32 guus Exp $
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include "meta.h"
#include "connection.h"
#include "node.h"
+#include "logger.h"
#include "system.h"
cp();
if(sscanf(c->buffer, "%*d %*x " MAX_STRING, name) != 1) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "KEY_CHANGED",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "KEY_CHANGED",
c->name, c->hostname);
return -1;
}
n = lookup_node(name);
if(!n) {
- syslog(LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist"),
"KEY_CHANGED", c->name, c->hostname, name);
return -1;
}
cp();
if(sscanf(c->buffer, "%*d " MAX_STRING " " MAX_STRING, from_name, to_name) != 2) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "REQ_KEY", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "REQ_KEY", c->name,
c->hostname);
return -1;
}
from = lookup_node(from_name);
if(!from) {
- syslog(LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist in our connection list"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist in our connection list"),
"REQ_KEY", c->name, c->hostname, from_name);
return -1;
}
to = lookup_node(to_name);
if(!to) {
- syslog(LOG_ERR, _("Got %s from %s (%s) destination %s which does not exist in our connection list"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got %s from %s (%s) destination %s which does not exist in our connection list"),
"REQ_KEY", c->name, c->hostname, to_name);
return -1;
}
if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %d %d %d",
from_name, to_name, key, &cipher, &digest, &maclength,
&compression) != 7) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ANS_KEY", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "ANS_KEY", c->name,
c->hostname);
return -1;
}
from = lookup_node(from_name);
if(!from) {
- syslog(LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist in our connection list"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist in our connection list"),
"ANS_KEY", c->name, c->hostname, from_name);
return -1;
}
to = lookup_node(to_name);
if(!to) {
- syslog(LOG_ERR, _("Got %s from %s (%s) destination %s which does not exist in our connection list"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got %s from %s (%s) destination %s which does not exist in our connection list"),
"ANS_KEY", c->name, c->hostname, to_name);
return -1;
}
from->cipher = EVP_get_cipherbynid(cipher);
if(!from->cipher) {
- syslog(LOG_ERR, _("Node %s (%s) uses unknown cipher!"), from->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Node %s (%s) uses unknown cipher!"), from->name,
from->hostname);
return -1;
}
if(from->keylength != from->cipher->key_len + from->cipher->iv_len) {
- syslog(LOG_ERR, _("Node %s (%s) uses wrong keylength!"), from->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Node %s (%s) uses wrong keylength!"), from->name,
from->hostname);
return -1;
}
from->digest = EVP_get_digestbynid(digest);
if(!from->digest) {
- syslog(LOG_ERR, _("Node %s (%s) uses unknown digest!"), from->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Node %s (%s) uses unknown digest!"), from->name,
from->hostname);
return -1;
}
if(from->maclength > from->digest->md_size || from->maclength < 0) {
- syslog(LOG_ERR, _("Node %s (%s) uses bogus MAC length!"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Node %s (%s) uses bogus MAC length!"),
from->name, from->hostname);
return -1;
}
}
if(compression < 0 || compression > 11) {
- syslog(LOG_ERR, _("Node %s (%s) uses bogus compression level!"), from->name, from->hostname);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Node %s (%s) uses bogus compression level!"), from->name, from->hostname);
return -1;
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: protocol_misc.c,v 1.1.4.7 2002/09/09 22:33:04 guus Exp $
+ $Id: protocol_misc.c,v 1.1.4.8 2003/07/06 22:11:33 guus Exp $
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include "protocol.h"
#include "meta.h"
#include "connection.h"
+#include "logger.h"
#include "system.h"
cp();
if(sscanf(c->buffer, "%*d %d " MAX_STRING, &statusno, statusstring) != 2) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "STATUS",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "STATUS",
c->name, c->hostname);
return -1;
}
- if(debug_lvl >= DEBUG_STATUS) {
- syslog(LOG_NOTICE, _("Status message from %s (%s): %s: %s"),
+ logger(DEBUG_STATUS, LOG_NOTICE, _("Status message from %s (%s): %s: %s"),
c->name, c->hostname, status_text[statusno], statusstring);
- }
return 0;
}
cp();
if(sscanf(c->buffer, "%*d %d " MAX_STRING, &err, errorstring) != 2) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ERROR",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "ERROR",
c->name, c->hostname);
return -1;
}
- if(debug_lvl >= DEBUG_ERROR) {
- syslog(LOG_NOTICE, _("Error message from %s (%s): %s: %s"),
+ logger(DEBUG_ERROR, LOG_NOTICE, _("Error message from %s (%s): %s: %s"),
c->name, c->hostname, strerror(err), errorstring);
- }
terminate_connection(c, c->status.active);
cp();
if(sscanf(c->buffer, "%*d %hd", &len) != 1) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "PACKET", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "PACKET", c->name,
c->hostname);
return -1;
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: protocol_subnet.c,v 1.1.4.9 2002/09/09 22:33:13 guus Exp $
+ $Id: protocol_subnet.c,v 1.1.4.10 2003/07/06 22:11:33 guus Exp $
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include "meta.h"
#include "connection.h"
#include "node.h"
+#include "logger.h"
#include "system.h"
/* If we don't know this subnet, but we are the owner, retaliate with a DEL_SUBNET */
if(owner == myself) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) for ourself"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) for ourself"),
"ADD_SUBNET", c->name, c->hostname);
s->owner = myself;
send_del_subnet(c, s);
owner = lookup_node(name);
if(!owner) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) for %s which is not in our node tree"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) for %s which is not in our node tree"),
"DEL_SUBNET", c->name, c->hostname, name);
return 0;
}
free_subnet(s);
if(!find) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) for %s which does not appear in his subnet tree"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) for %s which does not appear in his subnet tree"),
"DEL_SUBNET", c->name, c->hostname, name);
return 0;
}
/* If we are the owner of this subnet, retaliate with an ADD_SUBNET */
if(owner == myself) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) for ourself"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) for ourself"),
"DEL_SUBNET", c->name, c->hostname);
send_add_subnet(c, find);
return 0;
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: device.c,v 1.1.2.5 2003/06/11 19:28:38 guus Exp $
+ $Id: device.c,v 1.1.2.6 2003/07/06 22:11:37 guus Exp $
*/
#include "config.h"
#include <fcntl.h>
#include <net/if.h>
#include <unistd.h>
-#include <syslog.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <utils.h>
#include "conf.h"
#include "net.h"
-#include "subnet.h"
+#include "logger.h"
#include "system.h"
device_info = _("raw socket");
if((device_fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) {
- syslog(LOG_ERR, _("Could not open %s: %s"), device_info,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Could not open %s: %s"), device_info,
strerror(errno));
return -1;
}
strncpy(ifr.ifr_ifrn.ifrn_name, interface, IFNAMSIZ);
if(ioctl(device_fd, SIOCGIFINDEX, &ifr)) {
close(device_fd);
- syslog(LOG_ERR, _("Can't find interface %s: %s"), interface,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't find interface %s: %s"), interface,
strerror(errno));
return -1;
}
sa.sll_ifindex = ifr.ifr_ifindex;
if(bind(device_fd, (struct sockaddr *) &sa, (socklen_t) sizeof(sa))) {
- syslog(LOG_ERR, _("Could not bind to %s: %s"), device, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Could not bind to %s: %s"), device, strerror(errno));
return -1;
}
- syslog(LOG_INFO, _("%s is a %s"), device, device_info);
+ logger(DEBUG_ALWAYS, LOG_INFO, _("%s is a %s"), device, device_info);
return 0;
}
cp();
if((lenin = read(device_fd, packet->data, MTU)) <= 0) {
- syslog(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
device, strerror(errno));
return -1;
}
device_total_in += packet->len;
- if(debug_lvl >= DEBUG_TRAFFIC) {
- syslog(LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
device_info);
}
{
cp();
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Writing packet of %d bytes to %s"),
packet->len, device_info);
if(write(device_fd, packet->data, packet->len) < 0) {
- syslog(LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
strerror(errno));
return -1;
}
{
cp();
- syslog(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
- syslog(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
- syslog(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: route.c,v 1.1.2.53 2003/07/06 17:49:49 guus Exp $
+ $Id: route.c,v 1.1.2.54 2003/07/06 22:11:33 guus Exp $
*/
#include "config.h"
#include <netinet/if_ether.h>
#include <utils.h>
#include <xalloc.h>
-#include <syslog.h>
#include <string.h>
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#include "route.h"
#include "protocol.h"
#include "device.h"
+#include "logger.h"
#include "system.h"
/* If we don't know this MAC address yet, store it */
if(!subnet || subnet->owner != myself) {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_INFO, _("Learned new MAC address %hx:%hx:%hx:%hx:%hx:%hx"),
+ logger(DEBUG_TRAFFIC, LOG_INFO, _("Learned new MAC address %hx:%hx:%hx:%hx:%hx:%hx"),
address->x[0], address->x[1], address->x[2], address->x[3],
address->x[4], address->x[5]);
next = node->next;
s = (subnet_t *) node->data;
if(s->type == SUBNET_MAC && s->net.mac.lastseen && s->net.mac.lastseen + macexpire < now) {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_INFO, _("MAC address %hx:%hx:%hx:%hx:%hx:%hx expired"),
+ logger(DEBUG_TRAFFIC, LOG_INFO, _("MAC address %hx:%hx:%hx:%hx:%hx:%hx expired"),
s->net.mac.address.x[0], s->net.mac.address.x[1],
s->net.mac.address.x[2], s->net.mac.address.x[3],
s->net.mac.address.x[4], s->net.mac.address.x[5]);
subnet = lookup_subnet_ipv4((ipv4_t *) & packet->data[30]);
if(!subnet) {
- if(debug_lvl >= DEBUG_TRAFFIC) {
- syslog(LOG_WARNING, _("Cannot route packet: unknown IPv4 destination address %d.%d.%d.%d"),
+ logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: unknown IPv4 destination address %d.%d.%d.%d"),
packet->data[30], packet->data[31], packet->data[32],
packet->data[33]);
- }
route_ipv4_unreachable(packet, ICMP_NET_UNKNOWN);
return NULL;
subnet = lookup_subnet_ipv6((ipv6_t *) & packet->data[38]);
if(!subnet) {
- if(debug_lvl >= DEBUG_TRAFFIC) {
- syslog(LOG_WARNING, _("Cannot route packet: unknown IPv6 destination address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
+ logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: unknown IPv6 destination address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
ntohs(*(uint16_t *) & packet->data[38]),
ntohs(*(uint16_t *) & packet->data[40]),
ntohs(*(uint16_t *) & packet->data[42]),
ntohs(*(uint16_t *) & packet->data[48]),
ntohs(*(uint16_t *) & packet->data[50]),
ntohs(*(uint16_t *) & packet->data[52]));
- }
#ifdef HAVE_NETINET_IP6_H
route_ipv6_unreachable(packet, ICMP6_DST_UNREACH_ADDR);
#endif
if(ns->nd_ns_hdr.icmp6_type != ND_NEIGHBOR_SOLICIT ||
opt->nd_opt_type != ND_OPT_SOURCE_LINKADDR) {
- if(debug_lvl > DEBUG_TRAFFIC) {
- syslog(LOG_WARNING, _("Cannot route packet: received unknown type neighbor solicitation request"));
- }
+ logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: received unknown type neighbor solicitation request"));
return;
}
checksum = inet_checksum(ns, sizeof(*ns) + 8, checksum);
if(checksum) {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_WARNING, _("Cannot route packet: checksum error for neighbor solicitation request"));
+ logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: checksum error for neighbor solicitation request"));
return;
}
subnet = lookup_subnet_ipv6((ipv6_t *) & ns->nd_ns_target);
if(!subnet) {
- if(debug_lvl >= DEBUG_TRAFFIC) {
- syslog(LOG_WARNING, _("Cannot route packet: neighbor solicitation request for unknown address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
+ logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: neighbor solicitation request for unknown address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
ntohs(((uint16_t *) & ns->nd_ns_target)[0]),
ntohs(((uint16_t *) & ns->nd_ns_target)[1]),
ntohs(((uint16_t *) & ns->nd_ns_target)[2]),
ntohs(((uint16_t *) & ns->nd_ns_target)[5]),
ntohs(((uint16_t *) & ns->nd_ns_target)[6]),
ntohs(((uint16_t *) & ns->nd_ns_target)[7]));
- }
return;
}
if(ntohs(arp->arp_hrd) != ARPHRD_ETHER || ntohs(arp->arp_pro) != ETHERTYPE_IP ||
arp->arp_hln != ETHER_ADDR_LEN || arp->arp_pln != 4 || ntohs(arp->arp_op) != ARPOP_REQUEST) {
- if(debug_lvl > DEBUG_TRAFFIC) {
- syslog(LOG_WARNING, _("Cannot route packet: received unknown type ARP request"));
- }
+ logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: received unknown type ARP request"));
return;
}
subnet = lookup_subnet_ipv4((ipv4_t *) arp->arp_tpa);
if(!subnet) {
- if(debug_lvl >= DEBUG_TRAFFIC) {
- syslog(LOG_WARNING, _("Cannot route packet: ARP request for unknown address %d.%d.%d.%d"),
+ logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: ARP request for unknown address %d.%d.%d.%d"),
arp->arp_tpa[0], arp->arp_tpa[1], arp->arp_tpa[2],
arp->arp_tpa[3]);
- }
-
return;
}
return;
default:
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_WARNING, _("Cannot route packet: unknown type %hx"), type);
+ logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: unknown type %hx"), type);
return;
}
if(n)
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: device.c,v 1.1.2.12 2003/06/11 19:28:38 guus Exp $
+ $Id: device.c,v 1.1.2.13 2003/07/06 22:11:37 guus Exp $
*/
#include <sys/socket.h>
#include <net/if.h>
#include <unistd.h>
-#include <syslog.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stropts.h>
#include <utils.h>
#include "conf.h"
#include "net.h"
-#include "subnet.h"
+#include "logger.h"
#include "system.h"
device = DEFAULT_DEVICE;
if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
- syslog(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
return -1;
}
ppa = atoi(ptr);
if((ip_fd = open("/dev/ip", O_RDWR, 0)) < 0) {
- syslog(LOG_ERR, _("Could not open /dev/ip: %s"), strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Could not open /dev/ip: %s"), strerror(errno));
return -1;
}
/* Assign a new PPA and get its unit number. */
if((ppa = ioctl(device_fd, TUNNEWPPA, ppa)) < 0) {
- syslog(LOG_ERR, _("Can't assign new interface: %s"), strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't assign new interface: %s"), strerror(errno));
return -1;
}
if((if_fd = open(device, O_RDWR, 0)) < 0) {
- syslog(LOG_ERR, _("Could not open %s twice: %s"), device,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Could not open %s twice: %s"), device,
strerror(errno));
return -1;
}
if(ioctl(if_fd, I_PUSH, "ip") < 0) {
- syslog(LOG_ERR, _("Can't push IP module: %s"), strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't push IP module: %s"), strerror(errno));
return -1;
}
/* Assign ppa according to the unit number returned by tun device */
if(ioctl(if_fd, IF_UNITSEL, (char *) &ppa) < 0) {
- syslog(LOG_ERR, _("Can't set PPA %d: %s"), ppa, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't set PPA %d: %s"), ppa, strerror(errno));
return -1;
}
if(ioctl(ip_fd, I_LINK, if_fd) < 0) {
- syslog(LOG_ERR, _("Can't link TUN device to IP: %s"), strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't link TUN device to IP: %s"), strerror(errno));
return -1;
}
device_info = _("Solaris tun device");
- syslog(LOG_INFO, _("%s is a %s"), device, device_info);
+ logger(DEBUG_ALWAYS, LOG_INFO, _("%s is a %s"), device, device_info);
return 0;
}
cp();
if((lenin = read(device_fd, packet->data + 14, MTU - 14)) <= 0) {
- syslog(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
device, strerror(errno));
return -1;
}
device_total_in += packet->len;
- if(debug_lvl >= DEBUG_TRAFFIC) {
- syslog(LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
device_info);
- }
return 0;
}
{
cp();
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Writing packet of %d bytes to %s"),
packet->len, device_info);
if(write(device_fd, packet->data + 14, packet->len - 14) < 0) {
- syslog(LOG_ERR, _("Can't write to %s %s: %s"), device_info, packet->len,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't write to %s %s: %s"), device_info, packet->len,
strerror(errno));
return -1;
}
{
cp();
- syslog(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
- syslog(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
- syslog(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: subnet.c,v 1.1.2.43 2002/09/15 14:55:54 guus Exp $
+ $Id: subnet.c,v 1.1.2.44 2003/07/06 22:11:33 guus Exp $
*/
#include "config.h"
#include <stdio.h>
-#include <syslog.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include "node.h"
#include "subnet.h"
#include "netutl.h"
+#include "logger.h"
#include "system.h"
case SUBNET_IPV6:
return subnet_compare_ipv6(a, b);
default:
- syslog(LOG_ERR, _("subnet_compare() was called with unknown subnet type %d, exitting!"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("subnet_compare() was called with unknown subnet type %d, exitting!"),
a->type);
cp_trace();
exit(0);
break;
default:
- syslog(LOG_ERR,
+ logger(DEBUG_ALWAYS, LOG_ERR,
_("net2str() was called with unknown subnet type %d, exiting!"),
subnet->type);
cp_trace();
cp();
- syslog(LOG_DEBUG, _("Subnet list:"));
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Subnet list:"));
for(node = subnet_tree->head; node; node = node->next) {
subnet = (subnet_t *) node->data;
netstr = net2str(subnet);
- syslog(LOG_DEBUG, _(" %s owner %s"), netstr, subnet->owner->name);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" %s owner %s"), netstr, subnet->owner->name);
free(netstr);
}
- syslog(LOG_DEBUG, _("End of subnet list."));
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("End of subnet list."));
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: tincd.c,v 1.10.4.69 2003/07/06 17:15:25 guus Exp $
+ $Id: tincd.c,v 1.10.4.70 2003/07/06 22:11:33 guus Exp $
*/
#include "config.h"
#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
-#include <syslog.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include "process.h"
#include "protocol.h"
#include "subnet.h"
+#include "logger.h"
#include "system.h"
/* If nonzero, disable swapping for this process. */
int do_mlock = 0;
+/* If nonzero, write log entries to a separate file. */
+int use_logfile = 0;
+
char *identname = NULL; /* program name for syslog */
char *pidfilename = NULL; /* pid file location */
+char *logfilename = NULL; /* log file location */
char **g_argv; /* a copy of the cmdline arguments */
char **environment; /* A pointer to the environment on
startup */
{"debug", optional_argument, NULL, 'd'},
{"bypass-security", no_argument, &bypass_security, 1},
{"mlock", no_argument, &do_mlock, 1},
+ {"logfile", optional_argument, NULL, 'F'},
{NULL, 0, NULL, 0}
};
" -n, --net=NETNAME Connect to net NETNAME.\n"
" -K, --generate-keys[=BITS] Generate public/private RSA keypair.\n"
" -L, --mlock Lock tinc into main memory.\n"
+ " -F, --logfile[=FILENAME] Write log entries to a logfile.\n"
" --help Display this help and exit.\n"
" --version Output version information and exit.\n\n"));
printf(_("Report bugs to tinc@nl.linux.org.\n"));
int r;
int option_index = 0;
- while((r = getopt_long(argc, argv, "c:DLd::k::n:K::", long_options, &option_index)) != EOF) {
+ while((r = getopt_long(argc, argv, "c:DLd::k::n:K::F::", long_options, &option_index)) != EOF) {
switch (r) {
case 0: /* long option */
break;
case 'd': /* inc debug level */
if(optarg)
- debug_lvl = atoi(optarg);
+ debug_level = atoi(optarg);
else
- debug_lvl++;
+ debug_level++;
break;
case 'k': /* kill old tincds */
break;
case 'n': /* net name given */
- netname = xmalloc(strlen(optarg) + 1);
- strcpy(netname, optarg);
+ netname = xstrdup(optarg);
break;
case 'K': /* generate public/private keypair */
generate_keys = 1024;
break;
+ case 'F': /* write log entries to a file */
+ use_logfile = 1;
+ if(optarg)
+ logfilename = xstrdup(optarg);
+ break;
+
case '?':
usage(1);
if(netname) {
if(!pidfilename)
asprintf(&pidfilename, LOCALSTATEDIR "/run/tinc.%s.pid", netname);
+ if(!logfilename)
+ asprintf(&logfilename, LOCALSTATEDIR "/log/tinc.%s.log", netname);
if(!confbase)
asprintf(&confbase, "%s/tinc/%s", CONFDIR, netname);
else
- syslog(LOG_INFO, _("Both netname and configuration directory given, using the latter..."));
+ logger(DEBUG_ALWAYS, LOG_INFO, _("Both netname and configuration directory given, using the latter..."));
if(!identname)
asprintf(&identname, "tinc.%s", netname);
} else {
if(!pidfilename)
pidfilename = LOCALSTATEDIR "/run/tinc.pid";
+ if(!logfilename)
+ logfilename = LOCALSTATEDIR "/log/tinc.log";
if(!confbase)
asprintf(&confbase, "%s/tinc", CONFDIR);
if(kill_tincd)
exit(kill_other(kill_tincd));
-#ifndef LOG_PERROR
- openlog("tinc", LOG_CONS, LOG_DAEMON); /* Catch all syslog() calls issued before detaching */
-#else
- openlog("tinc", LOG_PERROR, LOG_DAEMON); /* Catch all syslog() calls issued before detaching */
-#endif
+ openlogger("tinc", LOGMODE_STDERR);
/* Lock all pages into memory if requested */
if(do_mlock)
#ifdef HAVE_MLOCKALL
if(mlockall(MCL_CURRENT | MCL_FUTURE)) {
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "mlockall",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("System call `%s' failed: %s"), "mlockall",
strerror(errno));
#else
{
- syslog(LOG_ERR, _("mlockall() not supported on this platform!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("mlockall() not supported on this platform!"));
#endif
return -1;
}
exit(1);
if(lzo_init() != LZO_E_OK) {
- syslog(LOG_ERR, _("Error initializing LZO compressor!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error initializing LZO compressor!"));
exit(1);
}
cleanup_and_exit(1);
}
- syslog(LOG_ERR, _("Unrecoverable error"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unrecoverable error"));
cp_trace();
if(do_detach) {
- syslog(LOG_NOTICE, _("Restarting in %d seconds!"), maxtimeout);
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Restarting in %d seconds!"), maxtimeout);
sleep(maxtimeout);
} else {
- syslog(LOG_ERR, _("Not restarting."));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Not restarting."));
exit(1);
}
}