- Fixing little things
- Two tinc daemons can connect to eachother now (but they disconnect right after the ACKs).
This commit is contained in:
parent
6e32b870ee
commit
bb3d18d56f
5 changed files with 74 additions and 46 deletions
12
lib/utils.c
12
lib/utils.c
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
@ -30,21 +31,22 @@ volatile int (cp_line[]) = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
volatile char (*cp_file[]) = {"?", "?", "?", "?", "?", "?", "?", "?"};
|
volatile char (*cp_file[]) = {"?", "?", "?", "?", "?", "?", "?", "?"};
|
||||||
volatile int cp_index = 0;
|
volatile int cp_index = 0;
|
||||||
|
|
||||||
char *charbin2hex = "0123456789ABCDEF";
|
char *hexadecimals = "0123456789ABCDEF";
|
||||||
|
|
||||||
int charhex2bin(char c)
|
int charhex2bin(char c)
|
||||||
{
|
{
|
||||||
if(isdigit(c))
|
if(isdigit(c))
|
||||||
return c - '0';
|
return c - '0';
|
||||||
else
|
else
|
||||||
return tolower(c) - 'a' + 10;
|
return toupper(c) - 'A' + 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void hex2bin(char *src, char *dst, int length)
|
void hex2bin(char *src, char *dst, int length)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<length; i++)
|
for(i=0; i<length; i++)
|
||||||
dst[i] = charhex2bin(src[i*2])<<4 || charhex2bin(src[i*2+1]);
|
dst[i] = charhex2bin(src[i*2])*16 + charhex2bin(src[i*2+1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bin2hex(char *src, char *dst, int length)
|
void bin2hex(char *src, char *dst, int length)
|
||||||
|
@ -52,8 +54,8 @@ void bin2hex(char *src, char *dst, int length)
|
||||||
int i;
|
int i;
|
||||||
for(i=length-1; i>=0; i--)
|
for(i=length-1; i>=0; i--)
|
||||||
{
|
{
|
||||||
dst[i*2+1] = charbin2hex[(unsigned char)src[i] & 15];
|
dst[i*2+1] = hexadecimals[(unsigned char)src[i] & 15];
|
||||||
dst[i*2] = charbin2hex[(unsigned char)src[i]>>4];
|
dst[i*2] = hexadecimals[(unsigned char)src[i]>>4];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: conf.c,v 1.9.4.14 2000/10/15 00:59:34 guus Exp $
|
$Id: conf.c,v 1.9.4.15 2000/10/16 16:33:29 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ add_config_val(config_t **cfg, int argtype, char *val)
|
||||||
cp
|
cp
|
||||||
p = (config_t*)xmalloc(sizeof(*p));
|
p = (config_t*)xmalloc(sizeof(*p));
|
||||||
p->data.val = 0;
|
p->data.val = 0;
|
||||||
|
|
||||||
switch(argtype)
|
switch(argtype)
|
||||||
{
|
{
|
||||||
case TYPE_INT:
|
case TYPE_INT:
|
||||||
|
@ -225,7 +225,7 @@ cp
|
||||||
const config_t *get_config_val(config_t *p, which_t type)
|
const config_t *get_config_val(config_t *p, which_t type)
|
||||||
{
|
{
|
||||||
cp
|
cp
|
||||||
for(p = config; p != NULL; p = p->next)
|
for(; p != NULL; p = p->next)
|
||||||
if(p->which == type)
|
if(p->which == type)
|
||||||
break;
|
break;
|
||||||
cp
|
cp
|
||||||
|
@ -239,7 +239,7 @@ cp
|
||||||
const config_t *get_next_config_val(config_t *p, which_t type, int index)
|
const config_t *get_next_config_val(config_t *p, which_t type, int index)
|
||||||
{
|
{
|
||||||
cp
|
cp
|
||||||
for(p = config; p != NULL; p = p->next)
|
for(; p != NULL; p = p->next)
|
||||||
if(p->which == type)
|
if(p->which == type)
|
||||||
if(--index < 0)
|
if(--index < 0)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: connlist.c,v 1.1.2.4 2000/10/15 00:59:34 guus Exp $
|
$Id: connlist.c,v 1.1.2.5 2000/10/16 16:33:29 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
@ -120,7 +120,8 @@ void conn_list_add(conn_list_t *cl)
|
||||||
cp
|
cp
|
||||||
cl->next = conn_list;
|
cl->next = conn_list;
|
||||||
cl->prev = NULL;
|
cl->prev = NULL;
|
||||||
cl->next->prev = cl;
|
if(cl->next)
|
||||||
|
cl->next->prev = cl;
|
||||||
conn_list = cl;
|
conn_list = cl;
|
||||||
cp
|
cp
|
||||||
}
|
}
|
||||||
|
|
68
src/net.c
68
src/net.c
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: net.c,v 1.35.4.38 2000/10/15 20:30:39 guus Exp $
|
$Id: net.c,v 1.35.4.39 2000/10/16 16:33:29 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -535,6 +535,8 @@ cp
|
||||||
if(debug_lvl > 0)
|
if(debug_lvl > 0)
|
||||||
syslog(LOG_INFO, _("Connected to %s port %hd"),
|
syslog(LOG_INFO, _("Connected to %s port %hd"),
|
||||||
cl->hostname, cl->port);
|
cl->hostname, cl->port);
|
||||||
|
|
||||||
|
cl->status.meta = 1;
|
||||||
cp
|
cp
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -546,18 +548,42 @@ cp
|
||||||
an authentication sequence during which
|
an authentication sequence during which
|
||||||
we will do just that.
|
we will do just that.
|
||||||
*/
|
*/
|
||||||
int setup_outgoing_connection(char *hostname)
|
int setup_outgoing_connection(char *name)
|
||||||
{
|
{
|
||||||
conn_list_t *ncn;
|
conn_list_t *ncn;
|
||||||
struct hostent *h;
|
struct hostent *h;
|
||||||
|
config_t *cfg;
|
||||||
cp
|
cp
|
||||||
if(!(h = gethostbyname(hostname)))
|
if(check_id(name))
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Error looking up `%s': %m"), hostname);
|
syslog(LOG_ERR, _("Invalid name for outgoing connection"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ncn = new_conn_list();
|
ncn = new_conn_list();
|
||||||
|
asprintf(&ncn->name, "%s", name);
|
||||||
|
|
||||||
|
if(read_host_config(ncn))
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, _("Error reading host configuration file for %s"));
|
||||||
|
free_conn_list(ncn);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(cfg = get_config_val(ncn->config, address)))
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, _("No address specified for %s"));
|
||||||
|
free_conn_list(ncn);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(h = gethostbyname(cfg->data.ptr)))
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, _("Error looking up `%s': %m"), cfg->data.ptr);
|
||||||
|
free_conn_list(ncn);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
ncn->address = ntohl(*((ip_t*)(h->h_addr_list[0])));
|
ncn->address = ntohl(*((ip_t*)(h->h_addr_list[0])));
|
||||||
ncn->hostname = hostlookup(htonl(ncn->address));
|
ncn->hostname = hostlookup(htonl(ncn->address));
|
||||||
|
|
||||||
|
@ -569,10 +595,15 @@ cp
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ncn->status.meta = 1;
|
|
||||||
ncn->status.outgoing = 1;
|
ncn->status.outgoing = 1;
|
||||||
ncn->next = conn_list;
|
ncn->buffer = xmalloc(MAXBUFSIZE);
|
||||||
conn_list = ncn;
|
ncn->buflen = 0;
|
||||||
|
ncn->last_ping_time = time(NULL);
|
||||||
|
ncn->want_ping = 0;
|
||||||
|
|
||||||
|
conn_list_add(ncn);
|
||||||
|
|
||||||
|
send_id(ncn);
|
||||||
cp
|
cp
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -596,7 +627,7 @@ cp
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
myself->name = (char*)cfg->data.val;
|
asprintf(&myself->name, "%s", (char*)cfg->data.val);
|
||||||
|
|
||||||
if(check_id(myself->name))
|
if(check_id(myself->name))
|
||||||
{
|
{
|
||||||
|
@ -648,9 +679,12 @@ sigalrm_handler(int a)
|
||||||
{
|
{
|
||||||
config_t const *cfg;
|
config_t const *cfg;
|
||||||
cp
|
cp
|
||||||
/* FIXME! Use name instead of upstreamip.
|
cfg = get_next_config_val(config, connectto, upstreamindex++);
|
||||||
cfg = get_next_config_val(config, upstreamip, upstreamindex++);
|
|
||||||
*/
|
if(!upstreamindex && !cfg)
|
||||||
|
/* No upstream IP given, we're listen only. */
|
||||||
|
return;
|
||||||
|
|
||||||
while(cfg)
|
while(cfg)
|
||||||
{
|
{
|
||||||
if(!setup_outgoing_connection(cfg->data.ptr)) /* function returns 0 when there are no problems */
|
if(!setup_outgoing_connection(cfg->data.ptr)) /* function returns 0 when there are no problems */
|
||||||
|
@ -658,7 +692,7 @@ cp
|
||||||
signal(SIGALRM, SIG_IGN);
|
signal(SIGALRM, SIG_IGN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// cfg = get_next_config_val(config, upstreamip, upstreamindex++); /* Or else we try the next ConnectTo line */
|
cfg = get_next_config_val(config, connectto, upstreamindex++); /* Or else we try the next ConnectTo line */
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGALRM, sigalrm_handler);
|
signal(SIGALRM, sigalrm_handler);
|
||||||
|
@ -690,7 +724,7 @@ cp
|
||||||
if(setup_myself() < 0)
|
if(setup_myself() < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// if((cfg = get_next_config_val(config, upstreamip, upstreamindex++)) == NULL)
|
if((cfg = get_next_config_val(config, connectto, upstreamindex++)) == NULL)
|
||||||
/* No upstream IP given, we're listen only. */
|
/* No upstream IP given, we're listen only. */
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -698,7 +732,7 @@ cp
|
||||||
{
|
{
|
||||||
if(!setup_outgoing_connection(cfg->data.ptr)) /* function returns 0 when there are no problems */
|
if(!setup_outgoing_connection(cfg->data.ptr)) /* function returns 0 when there are no problems */
|
||||||
return 0;
|
return 0;
|
||||||
// cfg = get_next_config_val(config, upstreamip, upstreamindex++); /* Or else we try the next ConnectTo line */
|
cfg = get_next_config_val(config, connectto, upstreamindex++); /* Or else we try the next ConnectTo line */
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGALRM, sigalrm_handler);
|
signal(SIGALRM, sigalrm_handler);
|
||||||
|
@ -822,11 +856,7 @@ cp
|
||||||
syslog(LOG_NOTICE, _("Connection from %s port %d"),
|
syslog(LOG_NOTICE, _("Connection from %s port %d"),
|
||||||
p->hostname, htons(ci.sin_port));
|
p->hostname, htons(ci.sin_port));
|
||||||
|
|
||||||
if(send_id(p) < 0)
|
p->allow_request = ID;
|
||||||
{
|
|
||||||
free_conn_list(p);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
cp
|
cp
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: protocol.c,v 1.28.4.40 2000/10/15 00:59:35 guus Exp $
|
$Id: protocol.c,v 1.28.4.41 2000/10/16 16:33:30 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -154,6 +154,8 @@ cp
|
||||||
|
|
||||||
int send_id(conn_list_t *cl)
|
int send_id(conn_list_t *cl)
|
||||||
{
|
{
|
||||||
|
cp
|
||||||
|
cl->allow_request = CHALLENGE;
|
||||||
cp
|
cp
|
||||||
return send_request(cl, "%d %s %d %lx", ID, myself->name, myself->protocol_version, myself->options);
|
return send_request(cl, "%d %s %d %lx", ID, myself->name, myself->protocol_version, myself->options);
|
||||||
}
|
}
|
||||||
|
@ -187,7 +189,7 @@ cp
|
||||||
|
|
||||||
/* Load information about peer */
|
/* Load information about peer */
|
||||||
|
|
||||||
if(!read_host_config(cl))
|
if(read_host_config(cl))
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Peer %s had unknown identity (%s)"), cl->hostname, cl->name);
|
syslog(LOG_ERR, _("Peer %s had unknown identity (%s)"), cl->hostname, cl->name);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -202,6 +204,7 @@ cp
|
||||||
if(cl->status.outgoing)
|
if(cl->status.outgoing)
|
||||||
{
|
{
|
||||||
if((old = lookup_id(cl->name)))
|
if((old = lookup_id(cl->name)))
|
||||||
|
if(old != cl)
|
||||||
{
|
{
|
||||||
if(debug_lvl > DEBUG_CONNECTIONS)
|
if(debug_lvl > DEBUG_CONNECTIONS)
|
||||||
syslog(LOG_NOTICE, _("Uplink %s (%s) is already in our connection list"), cl->name, cl->hostname);
|
syslog(LOG_NOTICE, _("Uplink %s (%s) is already in our connection list"), cl->name, cl->hostname);
|
||||||
|
@ -211,10 +214,6 @@ cp
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send a challenge to verify the identity */
|
|
||||||
|
|
||||||
cl->allow_request = CHAL_REPLY;
|
|
||||||
cp
|
cp
|
||||||
return send_challenge(cl);
|
return send_challenge(cl);
|
||||||
}
|
}
|
||||||
|
@ -313,7 +312,7 @@ int chal_reply_h(conn_list_t *cl)
|
||||||
char *hishash;
|
char *hishash;
|
||||||
char myhash[SHA_DIGEST_LENGTH];
|
char myhash[SHA_DIGEST_LENGTH];
|
||||||
cp
|
cp
|
||||||
if(sscanf(cl->buffer, "%*d %as", &hishash) != 2)
|
if(sscanf(cl->buffer, "%*d %as", &hishash) != 1)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Got bad CHAL_REPLY from %s (%s)"), cl->name, cl->hostname);
|
syslog(LOG_ERR, _("Got bad CHAL_REPLY from %s (%s)"), cl->name, cl->hostname);
|
||||||
free(hishash);
|
free(hishash);
|
||||||
|
@ -339,7 +338,7 @@ cp
|
||||||
|
|
||||||
/* Verify the incoming hash with the calculated hash */
|
/* Verify the incoming hash with the calculated hash */
|
||||||
|
|
||||||
if(!memcmp(hishash, myhash, SHA_DIGEST_LENGTH))
|
if(memcmp(hishash, myhash, SHA_DIGEST_LENGTH))
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Intruder: wrong challenge reply from %s (%s)"), cl->name, cl->hostname);
|
syslog(LOG_ERR, _("Intruder: wrong challenge reply from %s (%s)"), cl->name, cl->hostname);
|
||||||
free(hishash);
|
free(hishash);
|
||||||
|
@ -354,19 +353,15 @@ cp
|
||||||
*/
|
*/
|
||||||
cp
|
cp
|
||||||
if(cl->status.outgoing)
|
if(cl->status.outgoing)
|
||||||
{
|
|
||||||
cl->allow_request = ACK;
|
|
||||||
return send_ack(cl);
|
return send_ack(cl);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
cl->allow_request = CHALLENGE;
|
|
||||||
return send_id(cl);
|
return send_id(cl);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int send_ack(conn_list_t *cl)
|
int send_ack(conn_list_t *cl)
|
||||||
{
|
{
|
||||||
|
cp
|
||||||
|
cl->allow_request = ACK;
|
||||||
cp
|
cp
|
||||||
return send_request(cl, "%d", ACK);
|
return send_request(cl, "%d", ACK);
|
||||||
}
|
}
|
||||||
|
@ -1051,11 +1046,11 @@ char (*request_name[]) = {
|
||||||
/* Status strings */
|
/* Status strings */
|
||||||
|
|
||||||
char (*status_text[]) = {
|
char (*status_text[]) = {
|
||||||
"FIXME: status text",
|
"Warning",
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Error strings */
|
/* Error strings */
|
||||||
|
|
||||||
char (*error_text[]) = {
|
char (*error_text[]) = {
|
||||||
"FIXME: error text",
|
"Error",
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue