Large cleanup:

- Removed hostname lookup (it blocks, and you can always do it yourself)
- Reorganized debug levels (after hints from Axel M�ller):
  0	Startup message and errors
  1	Connection logging
  2	Meta protocol information
  3	Verbose meta protocol (includes copy of transmitted requests)
  4	Packet information (logs transmission/errors of UDP packets)
  5	Verbose packet information (every single byte, not implemented yet
	to protect ourselves from filling up /var/log directories)
- Made log messages more consistent
This commit is contained in:
Guus Sliepen 2000-06-25 15:16:12 +00:00
parent 3c54a513b0
commit 7f7e158aae
6 changed files with 200 additions and 185 deletions

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: encr.c,v 1.12 2000/05/31 18:23:06 zarq Exp $
$Id: encr.c,v 1.12.4.1 2000/06/25 15:16:11 guus Exp $
*/
#include "config.h"
@ -150,7 +150,7 @@ cp
else
my_key_expiry = (time_t)(time(NULL) + cfg->data.val);
syslog(LOG_NOTICE, _("Generating %d bits keys."), PRIVATE_KEY_BITS);
syslog(LOG_NOTICE, _("Generating %d bits keys"), PRIVATE_KEY_BITS);
if((f = fopen("/dev/urandom", "r")) == NULL)
{

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.2 2000/06/24 12:35:42 guus Exp $
$Id: net.c,v 1.35.4.3 2000/06/25 15:16:11 guus Exp $
*/
#include "config.h"
@ -247,7 +247,7 @@ void flush_queues(conn_list_t *cl)
cp
if(cl->sq)
{
if(debug_lvl > 1)
if(debug_lvl > 3)
syslog(LOG_DEBUG, _("Flushing send queue for " IP_ADDR_S),
IP_ADDR_V(cl->vpn_ip));
flush_queue(cl, &(cl->sq), xsend);
@ -255,7 +255,7 @@ cp
if(cl->rq)
{
if(debug_lvl > 1)
if(debug_lvl > 3)
syslog(LOG_DEBUG, _("Flushing receive queue for " IP_ADDR_S),
IP_ADDR_V(cl->vpn_ip));
flush_queue(cl, &(cl->rq), xrecv);
@ -272,9 +272,9 @@ int send_packet(ip_t to, vpn_packet_t *packet)
cp
if((cl = lookup_conn(to)) == NULL)
{
if(debug_lvl > 2)
if(debug_lvl > 3)
{
syslog(LOG_NOTICE, _("trying to look up " IP_ADDR_S " in connection list failed."),
syslog(LOG_NOTICE, _("Trying to look up " IP_ADDR_S " in connection list failed!"),
IP_ADDR_V(to));
}
@ -285,8 +285,8 @@ cp
for(cl = conn_list; cl != NULL && !cl->status.outgoing; cl = cl->next);
if(!cl)
{ /* No open outgoing connection has been found. */
if(debug_lvl > 2)
syslog(LOG_NOTICE, _("There is no remote host I can send this packet to."));
if(debug_lvl > 3)
syslog(LOG_NOTICE, _("There is no remote host I can send this packet to!"));
return -1;
}
}
@ -298,8 +298,8 @@ cp
for(cl = conn_list; cl != NULL && !cl->status.outgoing; cl = cl->next);
if(!cl)
{ /* No open outgoing connection has been found. */
if(debug_lvl > 2)
syslog(LOG_NOTICE, _("There is no remote host I can send this packet to."));
if(debug_lvl > 3)
syslog(LOG_NOTICE, _("There is no remote host I can send this packet to!"));
return -1;
}
}
@ -314,9 +314,9 @@ cp
{
if((cl = lookup_conn(cl->vpn_ip)) == NULL)
{
if(debug_lvl > 2)
if(debug_lvl > 3)
{
syslog(LOG_NOTICE, _("indirect look up " IP_ADDR_S " in connection list failed."),
syslog(LOG_NOTICE, _("Indirect look up " IP_ADDR_S " in connection list failed!"),
IP_ADDR_V(to));
}
@ -325,7 +325,7 @@ cp
return -1;
}
if(cl->flags & INDIRECTDATA) /* This should not happen */
if(debug_lvl > 1)
if(debug_lvl > 3)
{
syslog(LOG_NOTICE, _("double indirection for " IP_ADDR_S),
IP_ADDR_V(to));
@ -351,8 +351,8 @@ cp
if(!cl->status.active)
{
add_queue(&(cl->sq), packet, packet->len + 2);
if(debug_lvl > 1)
syslog(LOG_INFO, _(IP_ADDR_S " is not ready, queueing packet."), IP_ADDR_V(cl->vpn_ip));
if(debug_lvl > 3)
syslog(LOG_INFO, _(IP_ADDR_S " is not ready, queueing packet"), IP_ADDR_V(cl->vpn_ip));
return 0; /* We don't want to mess up, do we? */
}
@ -516,9 +516,8 @@ cp
return -1;
}
cl->hostname = hostlookup(htonl(cl->real_ip));
syslog(LOG_INFO, _("Connected to %s:%hd"), cl->hostname, cl->port);
syslog(LOG_INFO, _("Connected to " IP_ADDR_S ":%hd"),
IP_ADDR_V(cl->real_ip), cl->port);
cp
return 0;
}
@ -539,7 +538,7 @@ cp
if(setup_outgoing_meta_socket(ncn) < 0)
{
syslog(LOG_ERR, _("Could not set up a meta connection."));
syslog(LOG_ERR, _("Could not set up a meta connection!"));
free_conn_element(ncn);
return -1;
}
@ -595,7 +594,7 @@ cp
myself->status.active = 1;
syslog(LOG_NOTICE, _("Ready: listening on port %d."), myself->port);
syslog(LOG_NOTICE, _("Ready: listening on port %d"), myself->port);
cp
return 0;
}
@ -618,7 +617,7 @@ cp
if(seconds_till_retry>300) /* Don't wait more than 5 minutes. */
seconds_till_retry = 300;
alarm(seconds_till_retry);
syslog(LOG_ERR, _("Still failed to connect to other. Will retry in %d seconds."),
syslog(LOG_ERR, _("Still failed to connect to other, will retry in %d seconds"),
seconds_till_retry);
}
cp
@ -651,7 +650,7 @@ cp
signal(SIGALRM, sigalrm_handler);
seconds_till_retry = 300;
alarm(seconds_till_retry);
syslog(LOG_NOTICE, _("Try to re-establish outgoing connection in 5 minutes."));
syslog(LOG_NOTICE, _("Trying to re-establish outgoing connection in 5 minutes"));
}
cp
return 0;
@ -689,7 +688,7 @@ cp
close(tap_fd);
destroy_conn_list();
syslog(LOG_NOTICE, _("Terminating."));
syslog(LOG_NOTICE, _("Terminating"));
cp
return;
}
@ -702,7 +701,7 @@ int setup_vpn_connection(conn_list_t *cl)
int nfd, flags;
struct sockaddr_in a;
cp
if(debug_lvl > 1)
if(debug_lvl > 0)
syslog(LOG_DEBUG, _("Opening UDP socket to " IP_ADDR_S), IP_ADDR_V(cl->real_ip));
nfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
@ -754,7 +753,6 @@ cp
return NULL;
}
p->hostname = hostlookup(ci.sin_addr.s_addr);
p->real_ip = ntohl(ci.sin_addr.s_addr);
p->meta_socket = sfd;
p->status.meta = 1;
@ -762,7 +760,8 @@ cp
p->last_ping_time = time(NULL);
p->want_ping = 0;
syslog(LOG_NOTICE, _("Connection from %s:%d"), p->hostname, htons(ci.sin_port));
syslog(LOG_NOTICE, _("Connection from " IP_ADDR_S ":%d"),
IP_ADDR_V(p->real_ip), htons(ci.sin_port));
if(send_basic_info(p) < 0)
{
@ -874,7 +873,8 @@ cp
return;
if(debug_lvl > 0)
syslog(LOG_NOTICE, _("Closing connection with %s."), cl->hostname);
syslog(LOG_NOTICE, _("Closing connection with " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
if(cl->status.timeout)
send_timeout(cl);
@ -890,7 +890,7 @@ cp
signal(SIGALRM, sigalrm_handler);
seconds_till_retry = 5;
alarm(seconds_till_retry);
syslog(LOG_NOTICE, _("Try to re-establish outgoing connection in 5 seconds."));
syslog(LOG_NOTICE, _("Trying to re-establish outgoing connection in 5 seconds"));
}
cl->status.active = 0;
@ -942,8 +942,9 @@ cp
{
if(p->status.pinged && !p->status.got_pong)
{
syslog(LOG_INFO, _("%s (" IP_ADDR_S ") didn't respond to ping"),
p->hostname, IP_ADDR_V(p->vpn_ip));
if(debug_lvl > 1)
syslog(LOG_INFO, _(IP_ADDR_S " (" IP_ADDR_S ") didn't respond to ping"),
IP_ADDR_V(p->vpn_ip), IP_ADDR_V(p->real_ip));
p->status.timeout = 1;
terminate_connection(p);
}
@ -981,7 +982,7 @@ cp
{
shutdown(nfd, 2);
close(nfd);
syslog(LOG_NOTICE, _("Closed attempted connection."));
syslog(LOG_NOTICE, _("Closed attempted connection"));
return 0;
}
@ -1014,7 +1015,7 @@ cp
if(cl->buflen >= MAXBUFSIZE)
{
syslog(LOG_ERR, _("Metadata read buffer overflow."));
syslog(LOG_ERR, _("Metadata read buffer overflow!"));
return -1;
}
@ -1045,26 +1046,29 @@ cp
if(cl->reqlen)
{
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("Got request from " IP_ADDR_S " (" IP_ADDR_S "): %s"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip), cl->buffer);
if(sscanf(cl->buffer, "%d", &request) == 1)
{
if((request < 0) || (request > 255) || (request_handlers[request] == NULL))
{
syslog(LOG_ERR, _("Unknown request: %s"), cl->buffer);
syslog(LOG_ERR, _("Unknown request from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
return -1;
}
if(debug_lvl > 3)
syslog(LOG_DEBUG, _("Got request: %s"), cl->buffer);
if(request_handlers[request](cl)) /* Something went wrong. Probably scriptkiddies. Terminate. */
{
syslog(LOG_ERR, _("Error while processing request from " IP_ADDR_S), IP_ADDR_V(cl->real_ip));
syslog(LOG_ERR, _("Error while processing request from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
return -1;
}
}
else
{
syslog(LOG_ERR, _("Bogus data received."));
syslog(LOG_ERR, _("Bogus data received from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
return -1;
}
@ -1152,7 +1156,7 @@ cp
ether_type = ntohs(*((unsigned short*)(&vp.data[12])));
if(ether_type != 0x0800)
{
if(debug_lvl > 0)
if(debug_lvl > 3)
syslog(LOG_INFO, _("Non-IP ethernet frame %04x from " MAC_ADDR_S),
ether_type, MAC_ADDR_V(vp.data[6]));
return;
@ -1160,7 +1164,7 @@ cp
if(lenin < 32)
{
if(debug_lvl > 0)
if(debug_lvl > 3)
syslog(LOG_INFO, _("Dropping short packet"));
return;
}
@ -1171,7 +1175,7 @@ cp
if(debug_lvl > 3)
syslog(LOG_DEBUG, _("An IP packet (%04x) for " IP_ADDR_S " from " IP_ADDR_S),
ether_type, IP_ADDR_V(to), IP_ADDR_V(from));
if(debug_lvl > 4)
if(debug_lvl > 3)
syslog(LOG_DEBUG, _(MAC_ADDR_S " to " MAC_ADDR_S),
MAC_ADDR_V(vp.data[0]), MAC_ADDR_V(vp.data[6]));

View file

@ -104,7 +104,7 @@ typedef struct conn_list_t {
ip_t vpn_ip; /* his vpn ip */
ip_t vpn_mask; /* his vpn network address */
ip_t real_ip; /* his real (internet) ip */
char *hostname; /* the hostname of its real ip */
/* char *hostname; /* the hostname of its real ip */
short unsigned int port; /* his portnumber */
int flags; /* his flags */
int socket; /* our udp vpn socket */

View file

@ -16,7 +16,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 2000/05/31 18:23:06 zarq Exp $
$Id: netutl.c,v 1.12.4.1 2000/06/25 15:16:12 guus Exp $
*/
#include "config.h"
@ -85,8 +85,6 @@ cp
void free_conn_element(conn_list_t *p)
{
cp
if(p->hostname)
free(p->hostname);
if(p->sq)
destroy_queue(p->sq);
if(p->rq)
@ -160,10 +158,10 @@ cp
cp
}
/*
/* Hostlookups stink. (GS)
look up the name associated with the ip
address `addr'
*/
char *hostlookup(unsigned long addr)
{
char *name;
@ -195,6 +193,7 @@ cp
cp
return name;
}
*/
/*
Turn a string into an IP addy with netmask

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.1 2000/06/23 19:27:03 guus Exp $
$Id: protocol.c,v 1.28.4.2 2000/06/25 15:16:12 guus Exp $
*/
#include "config.h"
@ -50,18 +50,20 @@ int buflen;
int send_ack(conn_list_t *cl)
{
cp
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("Send ACK to %s"), cl->hostname);
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Sending ACK to " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
buflen = snprintf(buffer, MAXBUFSIZE, "%d\n", ACK);
if((write(cl->meta_socket, buffer, buflen)) < 0)
{
syslog(LOG_ERR, _("send failed: %d:%d: %m"), __FILE__, __LINE__);
syslog(LOG_ERR, _("Send failed: %d:%d: %m"), __FILE__, __LINE__);
return -1;
}
syslog(LOG_NOTICE, _("Connection with %s activated."), cl->hostname);
syslog(LOG_NOTICE, _("Connection with " IP_ADDR_S " (" IP_ADDR_S ") activated"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
cp
return 0;
}
@ -69,16 +71,16 @@ cp
int send_termreq(conn_list_t *cl)
{
cp
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("Send TERMREQ to " IP_ADDR_S),
IP_ADDR_V(cl->vpn_ip));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Sending TERMREQ to " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
buflen = snprintf(buffer, MAXBUFSIZE, "%d %lx\n", TERMREQ, myself->vpn_ip);
if(write(cl->meta_socket, buffer, buflen) < 0)
{
if(debug_lvl > 1)
syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__);
syslog(LOG_ERR, _("Send failed: %s:%d: %m"), __FILE__, __LINE__);
return -1;
}
cp
@ -88,15 +90,15 @@ cp
int send_timeout(conn_list_t *cl)
{
cp
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("Send TIMEOUT to " IP_ADDR_S),
IP_ADDR_V(cl->vpn_ip));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Sending TIMEOUT to " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
buflen = snprintf(buffer, MAXBUFSIZE, "%d %lx\n", PINGTIMEOUT, myself->vpn_ip);
if((write(cl->meta_socket, buffer, buflen)) < 0)
{
syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__);
syslog(LOG_ERR, _("Send failed: %s:%d: %m"), __FILE__, __LINE__);
return -1;
}
cp
@ -106,15 +108,15 @@ cp
int send_del_host(conn_list_t *cl, conn_list_t *new_host)
{
cp
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("Sending delete host " IP_ADDR_S " to " IP_ADDR_S),
IP_ADDR_V(new_host->vpn_ip), IP_ADDR_V(cl->vpn_ip));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Sending DEL_HOST for " IP_ADDR_S " to " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(new_host->vpn_ip), IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
buflen = snprintf(buffer, MAXBUFSIZE, "%d %lx\n", DEL_HOST, new_host->vpn_ip);
if((write(cl->meta_socket, buffer, buflen)) < 0)
{
syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__);
syslog(LOG_ERR, _("Send failed: %s:%d: %m"), __FILE__, __LINE__);
return -1;
}
cp
@ -124,14 +126,15 @@ cp
int send_ping(conn_list_t *cl)
{
cp
if(debug_lvl > 3)
syslog(LOG_DEBUG, _("pinging " IP_ADDR_S), IP_ADDR_V(cl->vpn_ip));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Sending PING to " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
buflen = snprintf(buffer, MAXBUFSIZE, "%d\n", PING);
if((write(cl->meta_socket, buffer, buflen)) < 0)
{
syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__);
syslog(LOG_ERR, _("Send failed: %s:%d: %m"), __FILE__, __LINE__);
return -1;
}
cp
@ -141,11 +144,15 @@ cp
int send_pong(conn_list_t *cl)
{
cp
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Sending PONG to " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
buflen = snprintf(buffer, MAXBUFSIZE, "%d\n", PONG);
if((write(cl->meta_socket, buffer, buflen)) < 0)
{
syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__);
syslog(LOG_ERR, _("Send failed: %s:%d: %m"), __FILE__, __LINE__);
return -1;
}
cp
@ -157,10 +164,6 @@ int send_add_host(conn_list_t *cl, conn_list_t *new_host)
ip_t real_ip;
int flags;
cp
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("Sending add host to " IP_ADDR_S),
IP_ADDR_V(cl->vpn_ip));
real_ip = new_host->real_ip;
flags = new_host->flags;
@ -177,11 +180,15 @@ cp
real_ip = myself->vpn_ip;
}
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Sending ADD_HOST for " IP_ADDR_S " (" IP_ADDR_S ") to " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(new_host->vpn_ip), IP_ADDR_V(real_ip), IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
buflen = snprintf(buffer, MAXBUFSIZE, "%d %lx %lx/%lx:%x %d\n", ADD_HOST, new_host->real_ip, new_host->vpn_ip, new_host->vpn_mask, new_host->port, flags);
if((write(cl->meta_socket, buffer, buflen)) < 0)
{
syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__);
syslog(LOG_ERR, _("Send failed: %s:%d: %m"), __FILE__, __LINE__);
return -1;
}
cp
@ -191,15 +198,15 @@ cp
int send_key_changed(conn_list_t *cl, conn_list_t *src)
{
cp
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("Sending KEY_CHANGED to " IP_ADDR_S),
IP_ADDR_V(cl->vpn_ip));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Sending KEY_CHANGED origin " IP_ADDR_S " to " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(src->vpn_ip), IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
buflen = snprintf(buffer, MAXBUFSIZE, "%d %lx\n", KEY_CHANGED, src->vpn_ip);
if((write(cl->meta_socket, buffer, buflen)) < 0)
{
syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__);
syslog(LOG_ERR, _("Send failed: %s:%d: %m"), __FILE__, __LINE__);
return -1;
}
cp
@ -219,15 +226,15 @@ cp
int send_basic_info(conn_list_t *cl)
{
cp
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("Send BASIC_INFO to " IP_ADDR_S),
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Sending BASIC_INFO to " IP_ADDR_S),
IP_ADDR_V(cl->real_ip));
buflen = snprintf(buffer, MAXBUFSIZE, "%d %d %lx/%lx:%x %d\n", BASIC_INFO, PROT_CURRENT, myself->vpn_ip, myself->vpn_mask, myself->port, myself->flags);
if((write(cl->meta_socket, buffer, buflen)) < 0)
{
syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__);
syslog(LOG_ERR, _("Send failed: %s:%d: %m"), __FILE__, __LINE__);
return -1;
}
cp
@ -240,15 +247,15 @@ int send_passphrase(conn_list_t *cl)
cp
encrypt_passphrase(&tmp);
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("Send PASSPHRASE %s to " IP_ADDR_S),
tmp.phrase, IP_ADDR_V(cl->vpn_ip));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Sending PASSPHRASE to " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
buflen = snprintf(buffer, MAXBUFSIZE, "%d %s\n", PASSPHRASE, tmp.phrase);
if((write(cl->meta_socket, buffer, buflen)) < 0)
{
syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__);
syslog(LOG_ERR, _("Send failed: %s:%d: %m"), __FILE__, __LINE__);
return -1;
}
cp
@ -258,21 +265,22 @@ cp
int send_public_key(conn_list_t *cl)
{
cp
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("Send PUBLIC_KEY %s to " IP_ADDR_S),
my_public_key_base36, IP_ADDR_V(cl->vpn_ip));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Sending PUBLIC_KEY to " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
buflen = snprintf(buffer, MAXBUFSIZE, "%d %s\n", PUBLIC_KEY, my_public_key_base36);
if((write(cl->meta_socket, buffer, buflen)) < 0)
{
syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__);
syslog(LOG_ERR, _("Send failed: %s:%d: %m"), __FILE__, __LINE__);
return -1;
}
cp
return 0;
}
/* WDN doet deze functie? (GS)
int send_calculate(conn_list_t *cl, char *k)
{
cp
@ -280,12 +288,13 @@ cp
if((write(cl->meta_socket, buffer, buflen)) < 0)
{
syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__);
syslog(LOG_ERR, _("Send failed: %s:%d: %m"), __FILE__, __LINE__);
return -1;
}
cp
return 0;
}
*/
int send_key_request(ip_t to)
{
@ -294,20 +303,20 @@ cp
fw = lookup_conn(to);
if(!fw)
{
syslog(LOG_ERR, _("Attempting to send key request to " IP_ADDR_S ", which does not exist?"),
syslog(LOG_ERR, _("Attempting to send REQ_KEY to " IP_ADDR_S ", which does not exist?"),
IP_ADDR_V(to));
return -1;
}
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("Sending out request for public key to " IP_ADDR_S),
IP_ADDR_V(fw->nexthop->vpn_ip));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Sending REQ_KEY to " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(fw->nexthop->vpn_ip), IP_ADDR_V(fw->nexthop->real_ip));
buflen = snprintf(buffer, MAXBUFSIZE, "%d %lx %lx\n", REQ_KEY, to, myself->vpn_ip);
if((write(fw->nexthop->meta_socket, buffer, buflen)) < 0)
{
syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__);
syslog(LOG_ERR, _("Send failed: %s:%d: %m"), __FILE__, __LINE__);
return -1;
}
fw->status.waitingforkey = 1;
@ -324,14 +333,14 @@ cp
if(!fw)
{
syslog(LOG_ERR, _("Attempting to send key answer to " IP_ADDR_S ", which does not exist?"),
syslog(LOG_ERR, _("Attempting to send ANS_KEY to " IP_ADDR_S ", which does not exist?"),
IP_ADDR_V(to));
return -1;
}
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("Sending public key to " IP_ADDR_S),
IP_ADDR_V(fw->nexthop->vpn_ip));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Sending ANS_KEY to " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(fw->nexthop->vpn_ip), IP_ADDR_V(fw->nexthop->real_ip));
buflen = snprintf(buffer, MAXBUFSIZE, "%d %lx %lx %d %s\n", ANS_KEY, to, myself->vpn_ip, my_key_expiry, my_public_key_base36);
@ -383,26 +392,23 @@ cp
int basic_info_h(conn_list_t *cl)
{
cp
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Got BASIC_INFO from " IP_ADDR_S), IP_ADDR_V(cl->real_ip));
if(sscanf(cl->buffer, "%*d %d %lx/%lx:%hx %d", &cl->protocol_version, &cl->vpn_ip, &cl->vpn_mask, &cl->port, &cl->flags) != 5)
{
syslog(LOG_ERR, _("got bad BASIC_INFO request: %s"), cl->buffer);
syslog(LOG_ERR, _("Got bad BASIC_INFO from " IP_ADDR_S),
IP_ADDR_V(cl->real_ip));
return -1;
}
if(cl->protocol_version != PROT_CURRENT)
{
syslog(LOG_ERR, _("Peer uses incompatible protocol version %d."),
syslog(LOG_ERR, _("Peer uses incompatible protocol version %d"),
cl->protocol_version);
return -1;
}
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("got BASIC_INFO(%hd," IP_ADDR_S "," IP_ADDR_S ")"), cl->port,
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->vpn_mask));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Peer uses protocol version %d"),
cl->protocol_version);
if(cl->status.outgoing)
{
if(setup_vpn_connection(cl) < 0)
@ -426,13 +432,15 @@ cp
if(sscanf(cl->buffer, "%*d %as", &(cl->pp->phrase)) != 1)
{
syslog(LOG_ERR, _("got bad PASSPHRASE request: %s"), cl->buffer);
syslog(LOG_ERR, _("Got bad PASSPHRASE from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
return -1;
}
cl->pp->len = strlen(cl->pp->phrase);
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("got PASSPHRASE"));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Got PASSPHRASE from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
if(cl->status.outgoing)
send_passphrase(cl);
@ -449,23 +457,22 @@ int public_key_h(conn_list_t *cl)
cp
if(sscanf(cl->buffer, "%*d %as", &g_n) != 1)
{
syslog(LOG_ERR, _("got bad PUBLIC_KEY request: %s"), cl->buffer);
syslog(LOG_ERR, _("Got bad PUBLIC_KEY from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
return -1;
}
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("got PUBLIC_KEY %s"), g_n);
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Got PUBLIC_KEY from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
if(verify_passphrase(cl, g_n))
{
/* intruder! */
syslog(LOG_ERR, _("Intruder: passphrase does not match."));
syslog(LOG_ERR, _("Intruder: passphrase does not match!"));
return -1;
}
if(debug_lvl > 2)
syslog(LOG_INFO, _("Passphrase OK"));
if(cl->status.outgoing)
send_public_key(cl);
else
@ -491,11 +498,13 @@ cp
int ack_h(conn_list_t *cl)
{
cp
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("got ACK"));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Got ACK from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
cl->status.active = 1;
syslog(LOG_NOTICE, _("Connection with %s activated."), cl->hostname);
syslog(LOG_NOTICE, _("Connection with " IP_ADDR_S " (" IP_ADDR_S ") activated"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
cp
return 0;
}
@ -503,7 +512,10 @@ cp
int termreq_h(conn_list_t *cl)
{
cp
syslog(LOG_NOTICE, _(IP_ADDR_S " wants to quit"), IP_ADDR_V(cl->vpn_ip));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Got TERMREQ from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
cl->status.termreq = 1;
terminate_connection(cl);
@ -515,8 +527,10 @@ cp
int timeout_h(conn_list_t *cl)
{
cp
if(!cl->status.active) return -1;
syslog(LOG_NOTICE, _(IP_ADDR_S " says it's gotten a timeout from us"), IP_ADDR_V(cl->vpn_ip));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Got TIMEOUT from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
cl->status.termreq = 1;
terminate_connection(cl);
cp
@ -532,18 +546,19 @@ cp
if(sscanf(cl->buffer, "%*d %lx", &vpn_ip) != 1)
{
syslog(LOG_ERR, _("got bad DEL_HOST request: %s"), cl->buffer);
syslog(LOG_ERR, _("Got bad DEL_HOST from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
return -1;
}
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("got DEL_HOST for " IP_ADDR_S),
IP_ADDR_V(vpn_ip));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Got DEL_HOST for " IP_ADDR_S " from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(vpn_ip), IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
if(!(fw = lookup_conn(vpn_ip)))
{
syslog(LOG_ERR, _("Somebody wanted to delete " IP_ADDR_S " which does not exist?"),
IP_ADDR_V(vpn_ip));
syslog(LOG_ERR, _("Got DEL_HOST for " IP_ADDR_S " from " IP_ADDR_S " (" IP_ADDR_S ") which does not exist?"),
IP_ADDR_V(vpn_ip), IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
return 0;
}
@ -558,9 +573,10 @@ cp
int ping_h(conn_list_t *cl)
{
cp
if(!cl->status.active) return -1;
if(debug_lvl > 3)
syslog(LOG_DEBUG, _("responding to ping from " IP_ADDR_S), IP_ADDR_V(cl->vpn_ip));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Got PING from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
cl->status.pinged = 0;
cl->status.got_pong = 1;
@ -572,9 +588,10 @@ cp
int pong_h(conn_list_t *cl)
{
cp
if(!cl->status.active) return -1;
if(debug_lvl > 3)
syslog(LOG_DEBUG, _("ok, got pong from " IP_ADDR_S), IP_ADDR_V(cl->vpn_ip));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Got PONG from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
cl->status.got_pong = 1;
cp
return 0;
@ -593,15 +610,14 @@ cp
return -1;
if(sscanf(cl->buffer, "%*d %lx %lx/%lx:%hx %d", &real_ip, &vpn_ip, &vpn_mask, &port, &flags) != 5)
{
syslog(LOG_ERR, _("got bad ADD_HOST request: %s"), cl->buffer);
syslog(LOG_ERR, _("Got bad ADD_HOST from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
return -1;
}
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("Add host request from " IP_ADDR_S), IP_ADDR_V(cl->vpn_ip));
if(debug_lvl > 3)
syslog(LOG_DEBUG, _("got ADD_HOST(" IP_ADDR_S "," IP_ADDR_S ",%hd)"),
IP_ADDR_V(vpn_ip), IP_ADDR_V(vpn_mask), port);
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Got ADD_HOST from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
/*
Suggestion of Hans Bayle
@ -611,9 +627,8 @@ cp
if(fw->nexthop == cl)
notify_others(fw, cl, send_add_host);
else
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Invalid add_host request from " IP_ADDR_S),
IP_ADDR_V(cl->vpn_ip));
syslog(LOG_DEBUG, _("Invalid ADD_HOST from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
return 0;
}
@ -623,7 +638,6 @@ cp
ncn->vpn_mask = vpn_mask;
ncn->port = port;
ncn->flags = flags;
ncn->hostname = hostlookup(real_ip);
ncn->nexthop = cl;
ncn->next = conn_list;
conn_list = ncn;
@ -642,13 +656,14 @@ cp
if(!cl->status.active) return -1;
if(sscanf(cl->buffer, "%*d %lx %lx", &to, &from) != 2)
{
syslog(LOG_ERR, _("got bad request: %s"), cl->buffer);
syslog(LOG_ERR, _("Got bad REQ_KEY from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
return -1;
}
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("got REQ_KEY from " IP_ADDR_S " for " IP_ADDR_S),
IP_ADDR_V(from), IP_ADDR_V(to));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Got REQ_KEY origin " IP_ADDR_S " destination " IP_ADDR_S " from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(from), IP_ADDR_V(to), IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
if((to & myself->vpn_mask) == (myself->vpn_ip & myself->vpn_mask))
{ /* hey! they want something from ME! :) */
@ -660,20 +675,20 @@ cp
if(!fw)
{
syslog(LOG_ERR, _("Attempting to forward key request to " IP_ADDR_S ", which does not exist?"),
syslog(LOG_ERR, _("Attempting to forward REQ_KEY to " IP_ADDR_S ", which does not exist?"),
IP_ADDR_V(to));
return -1;
}
if(debug_lvl > 3)
syslog(LOG_DEBUG, _("Forwarding request for public key to " IP_ADDR_S),
IP_ADDR_V(fw->nexthop->vpn_ip));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Forwarding REQ_KEY to " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(fw->nexthop->vpn_ip), IP_ADDR_V(fw->nexthop->real_ip));
cl->buffer[cl->reqlen-1] = '\n';
if(write(fw->nexthop->meta_socket, cl->buffer, cl->reqlen) < 0)
{
syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__);
syslog(LOG_ERR, _("Send failed: %s:%d: %m"), __FILE__, __LINE__);
return -1;
}
cp
@ -726,23 +741,22 @@ cp
if(!cl->status.active) return -1;
if(sscanf(cl->buffer, "%*d %lx %lx %d %as", &to, &from, &expiry, &key) != 4)
{
syslog(LOG_ERR, _("got bad ANS_KEY request: %s"), cl->buffer);
syslog(LOG_ERR, _("Got bad ANS_KEY from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
return -1;
}
if(debug_lvl > 3)
syslog(LOG_DEBUG, _("got ANS_KEY from " IP_ADDR_S " for " IP_ADDR_S),
IP_ADDR_V(from), IP_ADDR_V(to));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Got ANS_KEY origin " IP_ADDR_S " destination " IP_ADDR_S " from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(from), IP_ADDR_V(to), IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
if(to == myself->vpn_ip)
{ /* hey! that key's for ME! :) */
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("Yeah! key arrived. Now do something with it."));
gk = lookup_conn(from);
if(!gk)
{
syslog(LOG_ERR, _("Receiving key from " IP_ADDR_S ", which does not exist?"),
syslog(LOG_ERR, _("Receiving ANS_KEY from " IP_ADDR_S ", which does not exist?"),
IP_ADDR_V(from));
return -1;
}
@ -758,20 +772,20 @@ cp
if(!fw)
{
syslog(LOG_ERR, _("Attempting to forward key to " IP_ADDR_S ", which does not exist?"),
syslog(LOG_ERR, _("Attempting to forward ANS_KEY to " IP_ADDR_S ", which does not exist?"),
IP_ADDR_V(to));
return -1;
}
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("Forwarding public key to " IP_ADDR_S),
IP_ADDR_V(fw->nexthop->vpn_ip));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Forwarding ANS_KEY to " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(fw->nexthop->vpn_ip), IP_ADDR_V(fw->nexthop->real_ip));
cl->buffer[cl->reqlen-1] = '\n';
if((write(fw->nexthop->meta_socket, cl->buffer, cl->reqlen)) < 0)
{
syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__);
syslog(LOG_ERR, _("Send failed: %s:%d: %m"), __FILE__, __LINE__);
return -1;
}
cp
@ -786,19 +800,20 @@ cp
if(!cl->status.active) return -1;
if(sscanf(cl->buffer, "%*d %lx", &from) != 1)
{
syslog(LOG_ERR, _("got bad ANS_KEY request: %s"), cl->buffer);
syslog(LOG_ERR, _("Got bad KEY_CHANGED from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
return -1;
}
if(debug_lvl > 2)
syslog(LOG_DEBUG, _("got KEY_CHANGED from " IP_ADDR_S),
IP_ADDR_V(from));
if(debug_lvl > 1)
syslog(LOG_DEBUG, _("Got KEY_CHANGED origin " IP_ADDR_S " from " IP_ADDR_S " (" IP_ADDR_S ")"),
IP_ADDR_V(from), IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
ik = lookup_conn(from);
if(!ik)
{
syslog(LOG_ERR, _("Got changed key from " IP_ADDR_S ", which does not exist?"),
syslog(LOG_ERR, _("Got KEY_CHANGED from " IP_ADDR_S ", which does not exist?"),
IP_ADDR_V(from));
return -1;
}
@ -806,9 +821,6 @@ cp
ik->status.validkey = 0;
ik->status.waitingforkey = 0;
if(debug_lvl > 3)
syslog(LOG_DEBUG, _("Forwarding key invalidation request"));
notify_others(cl, ik, send_key_changed);
cp
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: tincd.c,v 1.10 2000/05/31 18:23:06 zarq Exp $
$Id: tincd.c,v 1.10.4.1 2000/06/25 15:16:12 guus Exp $
*/
#include "config.h"
@ -156,7 +156,7 @@ parse_options(int argc, char **argv, char **envp)
void memory_full(int size)
{
syslog(LOG_ERR, _("Memory exhausted (last is %s:%d) (couldn't allocate %d bytes); exiting."), cp_file, cp_line, size);
syslog(LOG_ERR, _("Memory exhausted (last is %s:%d) (couldn't allocate %d bytes), exiting."), cp_file, cp_line, size);
exit(1);
}
@ -210,11 +210,11 @@ int detach(void)
openlog(identname, LOG_CONS | LOG_PID, LOG_DAEMON);
if(debug_lvl > 1)
syslog(LOG_NOTICE, _("tincd %s (%s %s) starting, debug level %d."),
if(debug_lvl > 0)
syslog(LOG_NOTICE, _("tincd %s (%s %s) starting, debug level %d"),
VERSION, __DATE__, __TIME__, debug_lvl);
else
syslog(LOG_NOTICE, _("tincd %s starting, debug level %d."), VERSION, debug_lvl);
syslog(LOG_NOTICE, _("tincd %s starting"), VERSION, debug_lvl);
xalloc_fail_func = memory_full;
@ -229,7 +229,7 @@ void cleanup_and_exit(int c)
close_network_connections();
if(debug_lvl > 0)
syslog(LOG_INFO, _("Total bytes written: tap %d, socket %d; bytes read: tap %d, socket %d."),
syslog(LOG_INFO, _("Total bytes written: tap %d, socket %d; bytes read: tap %d, socket %d"),
total_tap_out, total_socket_out, total_tap_in, total_socket_in);
closelog();
@ -410,10 +410,10 @@ RETSIGTYPE
sigsegv_handler(int a)
{
if(cp_file)
syslog(LOG_NOTICE, _("Got SEGV signal after %s line %d. Trying to re-execute."),
syslog(LOG_NOTICE, _("Got SEGV signal after %s line %d, trying to re-execute"),
cp_file, cp_line);
else
syslog(LOG_NOTICE, _("Got SEGV signal; trying to re-execute."));
syslog(LOG_NOTICE, _("Got SEGV signal, trying to re-execute"));
signal(SIGSEGV, sigsegv_square);
@ -458,10 +458,10 @@ RETSIGTYPE
sighuh(int a)
{
if(cp_file)
syslog(LOG_NOTICE, _("Got unexpected signal (%d) after %s line %d."),
syslog(LOG_NOTICE, _("Got unexpected signal %d after %s line %d"),
a, cp_file, cp_line);
else
syslog(LOG_NOTICE, _("Got unexpected signal (%d)."), a);
syslog(LOG_NOTICE, _("Got unexpected signal %d"), a);
}
void