X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fprotocol.c;h=79d52733b881027470f112a7fa1c25d2574f8fe2;hb=3a316823b971396a428f020f401b9fe41252d98d;hp=fc16ffe7c08b66166e114094daab6dd814e78a29;hpb=079dcd01794187d2857e1233f6c9930310812593;p=tinc diff --git a/src/protocol.c b/src/protocol.c index fc16ffe7..79d52733 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -1,7 +1,7 @@ /* protocol.c -- handle the meta-protocol, basic functions Copyright (C) 1999-2005 Ivo Timmermans, - 2000-2012 Guus Sliepen + 2000-2013 Guus Sliepen 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 @@ -30,7 +30,7 @@ bool tunnelserver = false; bool strictsubnets = false; -bool experimental = false; +bool experimental = true; /* Jumptable for the request handlers */ @@ -41,6 +41,9 @@ static bool (*request_handlers[])(connection_t *, const char *) = { add_subnet_h, del_subnet_h, add_edge_h, del_edge_h, key_changed_h, req_key_h, ans_key_h, tcppacket_h, control_h, + NULL, NULL, /* Not "real" requests (yet) */ + sptps_tcppacket_h, + udp_info_h, mtu_info_h, }; /* Request names */ @@ -51,21 +54,11 @@ static char (*request_name[]) = { "PING", "PONG", "ADD_SUBNET", "DEL_SUBNET", "ADD_EDGE", "DEL_EDGE", "KEY_CHANGED", "REQ_KEY", "ANS_KEY", "PACKET", "CONTROL", + "REQ_PUBKEY", "ANS_PUBKEY", "SPTPS_PACKET", "UDP_INFO", "MTU_INFO", }; static splay_tree_t *past_request_tree; -bool check_id(const char *id) { - if(!id || !*id) - return false; - - for(; *id; id++) - if(!isalnum(*id) && *id != '_') - return false; - - return true; -} - /* Generic request routines - takes care of logging and error detection as well */ @@ -79,10 +72,11 @@ bool send_request(connection_t *c, const char *format, ...) { input buffer anyway */ va_start(args, format); - len = vsnprintf(request, MAXBUFSIZE, format, args); + len = vsnprintf(request, sizeof(request), format, args); + request[sizeof(request) - 1] = 0; va_end(args); - if(len < 0 || len > MAXBUFSIZE - 1) { + if(len < 0 || len > sizeof(request) - 1) { logger(DEBUG_ALWAYS, LOG_ERR, "Output buffer overflow while sending request to %s (%s)", c->name, c->hostname); return false; @@ -107,7 +101,7 @@ void forward_request(connection_t *from, const char *request) { char tmp[len + 1]; memcpy(tmp, request, len); tmp[len] = '\n'; - broadcast_meta(from, tmp, sizeof tmp); + broadcast_meta(from, tmp, sizeof(tmp)); } bool receive_request(connection_t *c, const char *request) { @@ -143,7 +137,8 @@ bool receive_request(connection_t *c, const char *request) { if(!request_handlers[reqno](c, request)) { /* Something went wrong. Probably scriptkiddies. Terminate. */ - logger(DEBUG_ALWAYS, LOG_ERR, "Error while processing %s from %s (%s)", request_name[reqno], c->name, c->hostname); + if(reqno != TERMREQ) + logger(DEBUG_ALWAYS, LOG_ERR, "Error while processing %s from %s (%s)", request_name[reqno], c->name, c->hostname); return false; } } else { @@ -193,9 +188,9 @@ bool seen_request(const char *request) { logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Already seen request"); return true; } else { - new = xmalloc(sizeof *new); + new = xmalloc(sizeof(*new)); new->request = xstrdup(request); - new->firstseen = time(NULL); + new->firstseen = now.tv_sec; splay_insert(past_request_tree, new); timeout_add(&past_request_timeout, age_past_requests, NULL, &(struct timeval){10, rand() % 100000}); return false;