Define logger(), cleans up source code and allows us to write log entries

to a separate file.
This commit is contained in:
Guus Sliepen 2003-07-06 22:11:37 +00:00
parent 8681047030
commit 0b9175e998
35 changed files with 582 additions and 560 deletions

View file

@ -1,6 +1,6 @@
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)
@ -114,7 +114,7 @@ AC_FUNC_MEMCMP
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

View file

@ -26,18 +26,6 @@
#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

View file

@ -1,17 +1,17 @@
## 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@

View file

@ -19,7 +19,7 @@
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"
@ -30,11 +30,9 @@
#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>
@ -43,12 +41,12 @@
#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 */
@ -172,7 +170,7 @@ int get_config_bool(config_t *cfg, int *result)
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;
@ -188,7 +186,7 @@ int get_config_int(config_t *cfg, int *result)
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;
@ -222,7 +220,7 @@ int get_config_address(config_t *cfg, struct addrinfo **result)
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;
@ -240,7 +238,7 @@ int get_config_subnet(config_t *cfg, subnet_t ** result)
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;
}
@ -251,7 +249,7 @@ int get_config_subnet(config_t *cfg, subnet_t ** result)
&& 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;
@ -350,7 +348,7 @@ int read_config_file(avl_tree_t *config_tree, const char *fname)
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;
}
@ -388,7 +386,7 @@ int read_config_file(avl_tree_t *config_tree, const char *fname)
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;
}
@ -423,7 +421,7 @@ int read_server_config()
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);
@ -450,7 +448,7 @@ int is_safe_path(const char *file)
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;
}
@ -466,21 +464,21 @@ int is_safe_path(const char *file)
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;
}
@ -494,7 +492,7 @@ check1:
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;
}
@ -502,16 +500,16 @@ check2:
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;
}
@ -522,7 +520,7 @@ check2:
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;
}

View file

@ -17,7 +17,7 @@
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__
@ -40,7 +40,6 @@ typedef struct config_t {
extern avl_tree_t *config_tree;
extern int debug_lvl;
extern int pingtimeout;
extern int maxtimeout;
extern int bypass_security;

View file

@ -17,13 +17,12 @@
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>
@ -35,6 +34,7 @@
#include "conf.h"
#include <utils.h>
#include "subnet.h"
#include "logger.h"
#include "xalloc.h"
#include "system.h"
@ -124,15 +124,15 @@ void dump_connections(void)
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)

View file

@ -17,7 +17,7 @@
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"
@ -28,13 +28,12 @@
#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"
@ -60,13 +59,13 @@ int setup_device(void)
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;
}
@ -85,7 +84,7 @@ int read_packet(vpn_packet_t *packet)
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;
}
@ -94,10 +93,8 @@ int read_packet(vpn_packet_t *packet)
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;
}
@ -106,12 +103,11 @@ int write_packet(vpn_packet_t *packet)
{
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;
}
@ -125,7 +121,7 @@ void dump_device_stats(void)
{
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);
}

View file

@ -17,7 +17,7 @@
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"
@ -31,13 +31,12 @@
#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"
@ -65,13 +64,13 @@ int setup_device(void)
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;
}
@ -94,7 +93,7 @@ int read_packet(vpn_packet_t *packet)
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;
}
@ -106,8 +105,7 @@ int read_packet(vpn_packet_t *packet)
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;
@ -117,12 +115,11 @@ int write_packet(vpn_packet_t *packet)
{
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;
}
@ -134,7 +131,7 @@ void dump_device_stats(void)
{
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);
}

View file

@ -17,13 +17,12 @@
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>
@ -36,6 +35,7 @@
#include "subnet.h"
#include "edge.h"
#include "node.h"
#include "logger.h"
#include "xalloc.h"
#include "system.h"
@ -154,18 +154,18 @@ void dump_edges(void)
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."));
}

View file

@ -17,7 +17,7 @@
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"
@ -31,13 +31,12 @@
#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"
@ -65,13 +64,13 @@ int setup_device(void)
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;
}
@ -94,7 +93,7 @@ int read_packet(vpn_packet_t *packet)
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;
}
@ -103,8 +102,7 @@ int read_packet(vpn_packet_t *packet)
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;
@ -114,12 +112,11 @@ int write_packet(vpn_packet_t *packet)
{
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;
}
@ -131,7 +128,7 @@ void dump_device_stats(void)
{
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);
}

View file

@ -17,7 +17,7 @@
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:
@ -47,7 +47,6 @@
#include "config.h"
#include <stdio.h>
#include <syslog.h>
#include <string.h>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
@ -63,6 +62,7 @@
#include "connection.h"
#include "process.h"
#include "device.h"
#include "logger.h"
#include "system.h"
@ -95,8 +95,7 @@ void mst_kruskal(void)
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 */
@ -132,8 +131,7 @@ void mst_kruskal(void)
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) {
@ -143,8 +141,7 @@ void mst_kruskal(void)
}
}
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);
}
@ -262,14 +259,12 @@ void sssp_bfs(void)
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;

View file

@ -17,7 +17,7 @@
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"
@ -29,7 +29,6 @@
#include <fcntl.h>
#include <net/if.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
#include <sys/ioctl.h>
@ -47,8 +46,8 @@
#include <utils.h>
#include "conf.h"
#include "net.h"
#include "subnet.h"
#include "route.h"
#include "logger.h"
#include "system.h"
@ -89,7 +88,7 @@ int setup_device(void)
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;
}
@ -114,7 +113,7 @@ int setup_device(void)
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
@ -127,7 +126,7 @@ int setup_device(void)
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;
}
@ -154,7 +153,7 @@ int read_packet(vpn_packet_t *packet)
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;
}
@ -165,7 +164,7 @@ int read_packet(vpn_packet_t *packet)
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;
}
@ -176,7 +175,7 @@ int read_packet(vpn_packet_t *packet)
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;
}
@ -187,10 +186,8 @@ int read_packet(vpn_packet_t *packet)
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;
}
@ -199,22 +196,21 @@ int write_packet(vpn_packet_t *packet)
{
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;
}
@ -223,7 +219,7 @@ int write_packet(vpn_packet_t *packet)
*(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;
}
@ -239,7 +235,7 @@ void dump_device_stats(void)
{
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);
}

95
src/logger.c Normal file
View file

@ -0,0 +1,95 @@
/*
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;
}
}

43
src/logger.h Normal file
View file

@ -0,0 +1,43 @@
#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__ */

View file

@ -17,7 +17,7 @@
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"
@ -25,7 +25,6 @@
#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 */
@ -38,6 +37,7 @@
#include "connection.h"
#include "system.h"
#include "protocol.h"
#include "logger.h"
int send_meta(connection_t *c, char *buffer, int length)
{
@ -48,8 +48,7 @@ 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) {
@ -64,7 +63,7 @@ int send_meta(connection_t *c, char *buffer, int length)
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;
}
@ -102,13 +101,13 @@ int receive_meta(connection_t *c)
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;
}
@ -126,13 +125,12 @@ int receive_meta(connection_t *c)
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;
@ -195,7 +193,7 @@ int receive_meta(connection_t *c)
}
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;
}

View file

@ -17,7 +17,7 @@
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"
@ -32,7 +32,6 @@
#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,
@ -71,6 +70,7 @@
#include "route.h"
#include "device.h"
#include "event.h"
#include "logger.h"
#include "system.h"
@ -91,16 +91,14 @@ void purge(void)
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) {
@ -181,8 +179,7 @@ void terminate_connection(connection_t *c, int report)
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;
@ -235,8 +232,7 @@ void check_dead_connections(void)
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);
@ -245,13 +241,12 @@ void check_dead_connections(void)
}
} 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);
}
@ -292,8 +287,7 @@ void check_network_activity(fd_set * f)
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);
@ -347,7 +341,7 @@ void main_loop(void)
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();
@ -378,8 +372,7 @@ void main_loop(void)
/* 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);
@ -395,7 +388,7 @@ void main_loop(void)
}
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;
@ -419,7 +412,7 @@ void main_loop(void)
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);
}

View file

@ -17,7 +17,7 @@
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"
@ -32,7 +32,6 @@
#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,
@ -76,6 +75,7 @@
#include "route.h"
#include "device.h"
#include "event.h"
#include "logger.h"
#include "system.h"
@ -149,8 +149,7 @@ void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
(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;
}
@ -179,14 +178,13 @@ void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
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++)
@ -206,7 +204,7 @@ void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
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;
}
@ -233,8 +231,7 @@ void receive_packet(node_t *n, vpn_packet_t *packet)
{
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);
@ -258,8 +255,7 @@ void send_udppacket(node_t *n, vpn_packet_t *inpkt)
/* 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);
@ -290,7 +286,7 @@ void send_udppacket(node_t *n, vpn_packet_t *inpkt)
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;
}
@ -341,17 +337,15 @@ void send_udppacket(node_t *n, vpn_packet_t *inpkt)
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;
}
@ -368,29 +362,24 @@ void send_packet(node_t *n, vpn_packet_t *packet)
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) {
@ -409,8 +398,7 @@ void broadcast_packet(node_t *from, vpn_packet_t *packet)
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) {
@ -427,8 +415,7 @@ void flush_queue(node_t *n)
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;
@ -449,21 +436,21 @@ void handle_incoming_vpn_data(int sock)
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;
}
@ -473,7 +460,7 @@ void handle_incoming_vpn_data(int sock)
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;

View file

@ -17,7 +17,7 @@
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"
@ -32,7 +32,6 @@
#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,
@ -72,6 +71,7 @@
#include "route.h"
#include "device.h"
#include "event.h"
#include "logger.h"
#include "system.h"
@ -107,7 +107,7 @@ int read_rsa_public_key(connection_t *c)
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;
@ -124,7 +124,7 @@ int read_rsa_public_key(connection_t *c)
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;
@ -139,7 +139,7 @@ int read_rsa_public_key(connection_t *c)
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 {
@ -179,7 +179,7 @@ int read_rsa_public_key(connection_t *c)
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;
}
@ -207,7 +207,7 @@ int read_rsa_private_key(void)
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;
@ -219,7 +219,7 @@ int read_rsa_private_key(void)
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;
}
@ -256,12 +256,12 @@ int setup_myself(void)
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;
}
@ -273,7 +273,7 @@ int setup_myself(void)
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;
}
@ -329,7 +329,7 @@ int setup_myself(void)
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);
@ -340,7 +340,7 @@ int setup_myself(void)
&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))
@ -350,7 +350,7 @@ int setup_myself(void)
(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
@ -364,7 +364,7 @@ int setup_myself(void)
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);
@ -382,7 +382,7 @@ int setup_myself(void)
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;
}
}
@ -417,7 +417,7 @@ int setup_myself(void)
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;
}
}
@ -431,10 +431,10 @@ int setup_myself(void)
&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;
}
}
@ -449,7 +449,7 @@ int setup_myself(void)
(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
@ -481,7 +481,7 @@ int setup_myself(void)
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;
}
@ -501,9 +501,9 @@ int setup_myself(void)
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);
}
@ -514,9 +514,9 @@ int setup_myself(void)
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;
}

View file

@ -17,7 +17,7 @@
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"
@ -32,7 +32,6 @@
#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,
@ -68,6 +67,7 @@
#include "route.h"
#include "device.h"
#include "event.h"
#include "logger.h"
#include "system.h"
@ -99,7 +99,7 @@ int setup_listen_socket(sockaddr_t *sa)
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;
}
@ -107,7 +107,7 @@ int setup_listen_socket(sockaddr_t *sa)
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;
}
@ -134,19 +134,19 @@ int setup_listen_socket(sockaddr_t *sa)
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;
@ -154,7 +154,7 @@ int setup_listen_socket(sockaddr_t *sa)
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;
}
@ -177,14 +177,14 @@ int setup_vpn_in_socket(sockaddr_t *sa)
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;
}
@ -200,7 +200,7 @@ int setup_vpn_in_socket(sockaddr_t *sa)
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;
}
@ -210,7 +210,7 @@ int setup_vpn_in_socket(sockaddr_t *sa)
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;
@ -236,8 +236,7 @@ void retry_outgoing(outgoing_t *outgoing)
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);
}
@ -246,8 +245,7 @@ void finish_connecting(connection_t *c)
{
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;
@ -264,8 +262,7 @@ void do_outgoing_connection(connection_t *c)
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);
@ -300,15 +297,13 @@ begin:
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;
@ -331,7 +326,7 @@ 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 */
@ -346,8 +341,7 @@ begin:
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;
}
@ -368,8 +362,7 @@ void setup_outgoing_connection(outgoing_t *outgoing)
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;
@ -388,7 +381,7 @@ void setup_outgoing_connection(outgoing_t *outgoing)
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);
@ -418,7 +411,7 @@ int handle_new_meta_connection(int sock)
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;
}
@ -436,8 +429,7 @@ int handle_new_meta_connection(int sock)
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);
@ -460,7 +452,7 @@ void try_outgoing_connections(void)
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);

View file

@ -17,7 +17,7 @@
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"
@ -32,13 +32,12 @@
#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"
@ -69,13 +68,13 @@ int setup_device(void)
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;
}
@ -94,7 +93,7 @@ int read_packet(vpn_packet_t *packet)
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;
}
@ -106,8 +105,7 @@ int read_packet(vpn_packet_t *packet)
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);
}
@ -118,12 +116,11 @@ int write_packet(vpn_packet_t *packet)
{
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;
}
@ -135,7 +132,7 @@ void dump_device_stats(void)
{
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);
}

View file

@ -17,7 +17,7 @@
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"
@ -33,7 +33,6 @@
#include <string.h>
#include <signal.h>
#include <sys/socket.h>
#include <syslog.h>
#include <arpa/inet.h>
#include <utils.h>
@ -43,6 +42,7 @@
#include "conf.h"
#include "net.h"
#include "netutl.h"
#include "logger.h"
#include "system.h"
@ -67,10 +67,8 @@ struct addrinfo *str2addrinfo(char *address, char *service, int socktype)
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;
}
@ -94,7 +92,7 @@ sockaddr_t str2sockaddr(char *address, char *port)
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);
@ -119,7 +117,7 @@ void sockaddr2str(sockaddr_t *sa, char **addrstr, char **portstr)
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);
@ -147,7 +145,7 @@ char *sockaddr2hostname(sockaddr_t *sa)
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));
}
@ -188,7 +186,7 @@ int sockaddrcmp(sockaddr_t *a, sockaddr_t *b)
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);

View file

@ -17,18 +17,19 @@
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>
@ -172,16 +173,16 @@ void dump_nodes(void)
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."));
}

View file

@ -17,7 +17,7 @@
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"
@ -32,13 +32,12 @@
#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"
@ -69,13 +68,13 @@ int setup_device(void)
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;
}
@ -96,7 +95,7 @@ int read_packet(vpn_packet_t *packet)
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;
}
@ -113,10 +112,8 @@ int read_packet(vpn_packet_t *packet)
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;
}
@ -125,8 +122,7 @@ int read_packet(vpn_packet_t *packet)
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);
}
@ -141,8 +137,7 @@ int write_packet(vpn_packet_t *packet)
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];
@ -155,8 +150,7 @@ int write_packet(vpn_packet_t *packet)
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;
@ -168,7 +162,7 @@ int write_packet(vpn_packet_t *packet)
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;
}
@ -180,7 +174,7 @@ void dump_device_stats(void)
{
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);
}

View file

@ -17,7 +17,7 @@
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"
@ -27,7 +27,6 @@
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -46,6 +45,7 @@
#include "device.h"
#include "connection.h"
#include "device.h"
#include "logger.h"
#include "system.h"
@ -55,10 +55,11 @@ int do_detach = 1;
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;
@ -66,7 +67,7 @@ extern int do_purge;
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);
}
@ -95,10 +96,10 @@ void cleanup_and_exit(int c)
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);
@ -199,13 +200,10 @@ int detach(void)
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;
@ -213,8 +211,7 @@ int detach(void)
}
/*
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));
@ -227,15 +224,16 @@ void _execute_script(const char *scriptname, char **envp)
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);
}
@ -262,37 +260,35 @@ int execute_script(const char *name, char **envp)
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;
}
@ -310,22 +306,20 @@ int execute_script(const char *name, char **envp)
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);
@ -334,11 +328,11 @@ RETSIGTYPE fatal_signal_square(int a)
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;
@ -350,37 +344,36 @@ RETSIGTYPE fatal_signal_handler(int a)
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;
}
@ -405,16 +398,13 @@ RETSIGTYPE sigwinch_handler(int a)
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 {

View file

@ -17,7 +17,7 @@
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"
@ -26,7 +26,6 @@
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
@ -38,6 +37,7 @@
#include "protocol.h"
#include "meta.h"
#include "connection.h"
#include "logger.h"
#include "system.h"
@ -74,18 +74,18 @@ int send_request(connection_t *c, const char *format, ...)
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);
}
@ -104,14 +104,14 @@ int forward_request(connection_t *from)
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);
}
@ -128,28 +128,28 @@ int receive_request(connection_t *c)
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;
}
@ -157,12 +157,12 @@ int receive_request(connection_t *c)
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;
}
@ -208,8 +208,7 @@ int seen_request(char *request)
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));
@ -238,8 +237,8 @@ void age_past_requests(void)
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);
}

View file

@ -17,14 +17,13 @@
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>
@ -46,6 +45,7 @@
#include "node.h"
#include "edge.h"
#include "graph.h"
#include "logger.h"
#include "system.h"
@ -65,7 +65,7 @@ int id_h(connection_t *c)
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;
}
@ -73,7 +73,7 @@ int id_h(connection_t *c)
/* 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;
}
@ -82,7 +82,7 @@ int id_h(connection_t *c)
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;
}
@ -92,7 +92,7 @@ int id_h(connection_t *c)
/* 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;
}
@ -110,7 +110,7 @@ int id_h(connection_t *c)
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;
}
@ -166,10 +166,10 @@ int send_metakey(connection_t *c)
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);
}
@ -181,7 +181,7 @@ int send_metakey(connection_t *c)
*/
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;
}
@ -221,7 +221,7 @@ int metakey_h(connection_t *c)
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;
}
@ -231,7 +231,7 @@ int metakey_h(connection_t *c)
/* 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;
}
@ -250,15 +250,15 @@ int metakey_h(connection_t *c)
/* 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. */
@ -269,7 +269,7 @@ int metakey_h(connection_t *c)
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;
}
@ -289,12 +289,12 @@ int metakey_h(connection_t *c)
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 {
@ -348,7 +348,7 @@ int challenge_h(connection_t *c)
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;
}
@ -358,7 +358,7 @@ int challenge_h(connection_t *c)
/* 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;
}
@ -412,7 +412,7 @@ int chal_reply_h(connection_t *c)
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;
}
@ -420,7 +420,7 @@ int chal_reply_h(connection_t *c)
/* 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;
}
@ -438,13 +438,13 @@ int chal_reply_h(connection_t *c)
/* 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;
@ -515,9 +515,8 @@ int ack_h(connection_t *c)
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;
}
@ -533,8 +532,7 @@ int ack_h(connection_t *c)
} 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 */
@ -551,8 +549,7 @@ int ack_h(connection_t *c)
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 */

View file

@ -17,14 +17,13 @@
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>
@ -42,6 +41,7 @@
#include "node.h"
#include "edge.h"
#include "graph.h"
#include "logger.h"
#include "system.h"
@ -79,7 +79,7 @@ int add_edge_h(connection_t *c)
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;
}
@ -87,13 +87,13 @@ int add_edge_h(connection_t *c)
/* 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;
}
@ -130,14 +130,12 @@ int add_edge_h(connection_t *c)
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();
@ -145,8 +143,7 @@ int add_edge_h(connection_t *c)
} 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;
@ -193,7 +190,7 @@ int del_edge_h(connection_t *c)
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;
}
@ -201,13 +198,13 @@ int del_edge_h(connection_t *c)
/* 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;
}
@ -220,8 +217,7 @@ int del_edge_h(connection_t *c)
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;
}
@ -229,8 +225,7 @@ int del_edge_h(connection_t *c)
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;
}
@ -240,15 +235,13 @@ int del_edge_h(connection_t *c)
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;

View file

@ -17,14 +17,13 @@
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>
@ -40,6 +39,7 @@
#include "meta.h"
#include "connection.h"
#include "node.h"
#include "logger.h"
#include "system.h"
@ -67,7 +67,7 @@ int key_changed_h(connection_t *c)
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;
}
@ -78,7 +78,7 @@ int key_changed_h(connection_t *c)
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;
}
@ -109,7 +109,7 @@ int req_key_h(connection_t *c)
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;
}
@ -117,7 +117,7 @@ int req_key_h(connection_t *c)
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;
}
@ -125,7 +125,7 @@ int req_key_h(connection_t *c)
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;
}
@ -173,7 +173,7 @@ int ans_key_h(connection_t *c)
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;
}
@ -181,7 +181,7 @@ int ans_key_h(connection_t *c)
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;
}
@ -189,7 +189,7 @@ int ans_key_h(connection_t *c)
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;
}
@ -220,13 +220,13 @@ int ans_key_h(connection_t *c)
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;
}
@ -240,13 +240,13 @@ int ans_key_h(connection_t *c)
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;
}
@ -255,7 +255,7 @@ int ans_key_h(connection_t *c)
}
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;
}

View file

@ -17,14 +17,13 @@
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>
@ -37,6 +36,7 @@
#include "protocol.h"
#include "meta.h"
#include "connection.h"
#include "logger.h"
#include "system.h"
@ -60,15 +60,13 @@ int status_h(connection_t *c)
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;
}
@ -91,15 +89,13 @@ int error_h(connection_t *c)
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);
@ -185,7 +181,7 @@ int tcppacket_h(connection_t *c)
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;
}

View file

@ -17,14 +17,13 @@
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>
@ -40,6 +39,7 @@
#include "meta.h"
#include "connection.h"
#include "node.h"
#include "logger.h"
#include "system.h"
@ -114,8 +114,7 @@ int add_subnet_h(connection_t *c)
/* 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);
@ -177,8 +176,7 @@ int del_subnet_h(connection_t *c)
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;
}
@ -205,8 +203,7 @@ int del_subnet_h(connection_t *c)
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;
}
@ -214,8 +211,7 @@ int del_subnet_h(connection_t *c)
/* 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;

View file

@ -17,7 +17,7 @@
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"
@ -29,7 +29,6 @@
#include <fcntl.h>
#include <net/if.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@ -39,7 +38,7 @@
#include <utils.h>
#include "conf.h"
#include "net.h"
#include "subnet.h"
#include "logger.h"
#include "system.h"
@ -73,7 +72,7 @@ int setup_device(void)
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;
}
@ -82,7 +81,7 @@ int setup_device(void)
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;
}
@ -93,11 +92,11 @@ int setup_device(void)
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;
}
@ -120,7 +119,7 @@ int read_packet(vpn_packet_t *packet)
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;
}
@ -129,8 +128,7 @@ int read_packet(vpn_packet_t *packet)
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);
}
@ -141,12 +139,11 @@ int write_packet(vpn_packet_t *packet)
{
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;
}
@ -160,7 +157,7 @@ void dump_device_stats(void)
{
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);
}

View file

@ -17,7 +17,7 @@
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"
@ -45,7 +45,6 @@
#include <netinet/if_ether.h>
#include <utils.h>
#include <xalloc.h>
#include <syslog.h>
#include <string.h>
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
@ -59,6 +58,7 @@
#include "route.h"
#include "protocol.h"
#include "device.h"
#include "logger.h"
#include "system.h"
@ -130,8 +130,7 @@ void learn_mac(mac_t *address)
/* 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]);
@ -164,8 +163,7 @@ void age_mac(void)
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]);
@ -274,11 +272,9 @@ node_t *route_ipv4(vpn_packet_t *packet)
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;
@ -371,8 +367,7 @@ node_t *route_ipv6(vpn_packet_t *packet)
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]),
@ -381,7 +376,6 @@ node_t *route_ipv6(vpn_packet_t *packet)
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
@ -431,9 +425,7 @@ void route_neighborsol(vpn_packet_t *packet)
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;
}
@ -450,8 +442,7 @@ void route_neighborsol(vpn_packet_t *packet)
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;
}
@ -460,8 +451,7 @@ void route_neighborsol(vpn_packet_t *packet)
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]),
@ -470,7 +460,6 @@ void route_neighborsol(vpn_packet_t *packet)
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;
}
@ -543,9 +532,7 @@ void route_arp(vpn_packet_t *packet)
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;
}
@ -554,12 +541,9 @@ void route_arp(vpn_packet_t *packet)
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;
}
@ -614,8 +598,7 @@ void route_outgoing(vpn_packet_t *packet)
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)

View file

@ -17,7 +17,7 @@
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 $
*/
@ -31,7 +31,6 @@
#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>
@ -43,7 +42,7 @@
#include <utils.h>
#include "conf.h"
#include "net.h"
#include "subnet.h"
#include "logger.h"
#include "system.h"
@ -69,7 +68,7 @@ int setup_device(void)
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;
}
@ -81,35 +80,35 @@ int setup_device(void)
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;
}
@ -118,7 +117,7 @@ int setup_device(void)
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;
}
@ -137,7 +136,7 @@ int read_packet(vpn_packet_t *packet)
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;
}
@ -149,10 +148,8 @@ int read_packet(vpn_packet_t *packet)
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;
}
@ -161,12 +158,11 @@ int write_packet(vpn_packet_t *packet)
{
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;
}
@ -180,7 +176,7 @@ void dump_device_stats(void)
{
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);
}

View file

@ -17,13 +17,12 @@
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>
@ -39,6 +38,7 @@
#include "node.h"
#include "subnet.h"
#include "netutl.h"
#include "logger.h"
#include "system.h"
@ -111,7 +111,7 @@ int subnet_compare(subnet_t *a, subnet_t *b)
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);
@ -295,7 +295,7 @@ char *net2str(subnet_t *subnet)
break;
default:
syslog(LOG_ERR,
logger(DEBUG_ALWAYS, LOG_ERR,
_("net2str() was called with unknown subnet type %d, exiting!"),
subnet->type);
cp_trace();
@ -411,14 +411,14 @@ void dump_subnets(void)
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."));
}

View file

@ -17,7 +17,7 @@
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"
@ -28,7 +28,6 @@
#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <syslog.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
@ -61,6 +60,7 @@
#include "process.h"
#include "protocol.h"
#include "subnet.h"
#include "logger.h"
#include "system.h"
@ -85,8 +85,12 @@ int bypass_security = 0;
/* 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 */
@ -102,6 +106,7 @@ static struct option const long_options[] = {
{"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}
};
@ -119,6 +124,7 @@ static void usage(int status)
" -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"));
@ -132,7 +138,7 @@ void parse_options(int argc, char **argv, char **envp)
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;
@ -152,9 +158,9 @@ void parse_options(int argc, char **argv, char **envp)
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 */
@ -189,8 +195,7 @@ void parse_options(int argc, char **argv, char **envp)
break;
case 'n': /* net name given */
netname = xmalloc(strlen(optarg) + 1);
strcpy(netname, optarg);
netname = xstrdup(optarg);
break;
case 'K': /* generate public/private keypair */
@ -208,6 +213,12 @@ void parse_options(int argc, char **argv, char **envp)
generate_keys = 1024;
break;
case 'F': /* write log entries to a file */
use_logfile = 1;
if(optarg)
logfilename = xstrdup(optarg);
break;
case '?':
usage(1);
@ -317,17 +328,21 @@ void make_names(void)
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);
@ -367,22 +382,18 @@ int main(int argc, char **argv, char **envp)
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;
}
@ -406,7 +417,7 @@ int main(int argc, char **argv, char **envp)
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);
}
@ -419,14 +430,14 @@ int main(int argc, char **argv, char **envp)
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);
}
}