- Fixed memory leak.
- Implemented SIGHUP configuration file reloading. - Other small changes.
This commit is contained in:
parent
18c85caac3
commit
0f9ad1f047
6 changed files with 230 additions and 178 deletions
43
src/conf.c
43
src/conf.c
|
@ -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.3 2000/06/27 20:10:47 guus Exp $
|
||||
$Id: conf.c,v 1.9.4.4 2000/06/29 19:47:02 guus Exp $
|
||||
*/
|
||||
|
||||
|
||||
|
@ -36,12 +36,17 @@
|
|||
|
||||
#include "conf.h"
|
||||
#include "netutl.h" /* for strtoip */
|
||||
#include <utils.h> /* for cp */
|
||||
|
||||
#include "system.h"
|
||||
|
||||
config_t *config;
|
||||
int debug_lvl = 0;
|
||||
int timeout = 0; /* seconds before timeout */
|
||||
char *configfilename = NULL;
|
||||
|
||||
/* Will be set if HUP signal is received. It will be processed when it is safe. */
|
||||
int sighup = 0;
|
||||
|
||||
typedef struct internal_config_t {
|
||||
char *name;
|
||||
|
@ -77,7 +82,7 @@ add_config_val(config_t **cfg, int argtype, char *val)
|
|||
{
|
||||
config_t *p, *r;
|
||||
char *q;
|
||||
|
||||
cp
|
||||
p = (config_t*)xmalloc(sizeof(*p));
|
||||
p->data.val = 0;
|
||||
|
||||
|
@ -120,6 +125,7 @@ add_config_val(config_t **cfg, int argtype, char *val)
|
|||
}
|
||||
|
||||
free(p);
|
||||
cp
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -133,7 +139,7 @@ readconfig(const char *fname, FILE *fp)
|
|||
char *p, *q;
|
||||
int i, lineno = 0;
|
||||
config_t *cfg;
|
||||
|
||||
cp
|
||||
line = (char *)xmalloc(80 * sizeof(char));
|
||||
temp_buf = (char *)xmalloc(80 * sizeof(char));
|
||||
|
||||
|
@ -188,6 +194,7 @@ readconfig(const char *fname, FILE *fp)
|
|||
if(!config)
|
||||
config = cfg;
|
||||
}
|
||||
cp
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -197,7 +204,7 @@ int
|
|||
read_config_file(const char *fname)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
cp
|
||||
if((fp = fopen (fname, "r")) == NULL)
|
||||
{
|
||||
fprintf(stderr, _("Could not open %s: %s\n"), fname, sys_errlist[errno]);
|
||||
|
@ -208,7 +215,7 @@ read_config_file(const char *fname)
|
|||
return -1;
|
||||
|
||||
fclose (fp);
|
||||
|
||||
cp
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -219,11 +226,11 @@ const config_t *
|
|||
get_config_val(which_t type)
|
||||
{
|
||||
config_t *p;
|
||||
|
||||
cp
|
||||
for(p = config; p != NULL; p = p->next)
|
||||
if(p->which == type)
|
||||
return p;
|
||||
|
||||
cp
|
||||
/* Not found */
|
||||
return NULL;
|
||||
}
|
||||
|
@ -236,12 +243,30 @@ const config_t *
|
|||
get_next_config_val(which_t type, int index)
|
||||
{
|
||||
config_t *p;
|
||||
|
||||
cp
|
||||
for(p = config; p != NULL; p = p->next)
|
||||
if(p->which == type)
|
||||
if(--index < 0)
|
||||
return p;
|
||||
|
||||
cp
|
||||
/* Not found */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
Remove the complete configuration tree.
|
||||
*/
|
||||
void clear_config()
|
||||
{
|
||||
config_t *p, *next;
|
||||
cp
|
||||
for(p = config; p; p = next)
|
||||
{
|
||||
next = p->next;
|
||||
if(p->data.ptr)
|
||||
free(p->data.ptr);
|
||||
free(p);
|
||||
}
|
||||
config = NULL;
|
||||
cp
|
||||
}
|
||||
|
|
|
@ -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.3 2000/06/27 20:10:47 guus Exp $
|
||||
$Id: conf.h,v 1.6.4.4 2000/06/29 19:47:03 guus Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TINC_CONF_H__
|
||||
|
@ -71,6 +71,8 @@ extern config_t *config;
|
|||
extern int debug_lvl;
|
||||
extern int timeout;
|
||||
extern int upstreamindex;
|
||||
extern int sighup;
|
||||
extern char *configfilename;
|
||||
|
||||
extern config_t *add_config_val(config_t **, int, char *);
|
||||
extern int read_config_file(const char *);
|
||||
|
|
100
src/net.c
100
src/net.c
|
@ -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.14 2000/06/29 17:09:05 guus Exp $
|
||||
$Id: net.c,v 1.35.4.15 2000/06/29 19:47:03 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
@ -794,7 +794,7 @@ cp
|
|||
|
||||
if(send_basic_info(p) < 0)
|
||||
{
|
||||
free(p);
|
||||
free_conn_element(p);
|
||||
return NULL;
|
||||
}
|
||||
cp
|
||||
|
@ -904,13 +904,40 @@ cp
|
|||
|
||||
if(cl->status.timeout)
|
||||
send_timeout(cl);
|
||||
else if(!cl->status.termreq)
|
||||
/* else if(!cl->status.termreq)
|
||||
send_termreq(cl);
|
||||
|
||||
close(cl->socket);
|
||||
*/
|
||||
|
||||
if(cl->socket)
|
||||
close(cl->socket);
|
||||
if(cl->status.meta)
|
||||
close(cl->meta_socket);
|
||||
|
||||
cl->status.remove = 1;
|
||||
|
||||
/* If this cl isn't active, don't send any DEL_HOSTs. */
|
||||
if(cl->status.active)
|
||||
notify_others(cl,NULL,send_del_host);
|
||||
|
||||
cp
|
||||
/* Find all connections that were lost because they were behind cl
|
||||
(the connection that was dropped). */
|
||||
if(cl->status.meta)
|
||||
for(p = conn_list; p != NULL; p = p->next)
|
||||
{
|
||||
if((p->nexthop == cl) && (p != cl))
|
||||
{
|
||||
if(cl->status.active && p->status.active)
|
||||
notify_others(p,cl,send_del_host);
|
||||
if(cl->socket)
|
||||
close(cl->socket);
|
||||
p->status.active = 0;
|
||||
p->status.remove = 1;
|
||||
}
|
||||
}
|
||||
|
||||
cl->status.active = 0;
|
||||
|
||||
if(cl->status.outgoing)
|
||||
{
|
||||
signal(SIGALRM, sigalrm_handler);
|
||||
|
@ -918,40 +945,6 @@ cp
|
|||
alarm(seconds_till_retry);
|
||||
syslog(LOG_NOTICE, _("Trying to re-establish outgoing connection in 5 seconds"));
|
||||
}
|
||||
|
||||
cl->status.remove = 1;
|
||||
|
||||
/* If this cl isn't active, don't send any DEL_HOSTs. */
|
||||
if(!cl->status.active)
|
||||
return;
|
||||
|
||||
cl->status.active = 0;
|
||||
notify_others(cl,NULL,send_del_host);
|
||||
|
||||
cp
|
||||
/* Find all connections that were lost because they were behind cl
|
||||
(the connection that was dropped). */
|
||||
if(cl->status.meta)
|
||||
for(p = conn_list; p != NULL; p = p->next)
|
||||
{
|
||||
if(p->nexthop == cl)
|
||||
{
|
||||
if(p->status.active)
|
||||
notify_others(p,cl,send_del_host);
|
||||
p->status.active = 0;
|
||||
p->status.remove = 1;
|
||||
}
|
||||
}
|
||||
|
||||
cp
|
||||
/* Then send a notification about all these connections to all hosts
|
||||
that are still connected to us.
|
||||
for(p = conn_list; p != NULL; p = p->next)
|
||||
if(p->status.active && p->status.meta)
|
||||
for(q = conn_list; q != NULL; q = q->next)
|
||||
if(q->status.remove)
|
||||
send_del_host(p, q);
|
||||
*/
|
||||
cp
|
||||
}
|
||||
|
||||
|
@ -1015,7 +1008,7 @@ cp
|
|||
return -1;
|
||||
}
|
||||
|
||||
if((ncn = create_new_connection(nfd)) == NULL)
|
||||
if(!(ncn = create_new_connection(nfd)))
|
||||
{
|
||||
shutdown(nfd, 2);
|
||||
close(nfd);
|
||||
|
@ -1242,10 +1235,29 @@ cp
|
|||
|
||||
if((r = select(FD_SETSIZE, &fset, NULL, NULL, &tv)) < 0)
|
||||
{
|
||||
if(errno == EINTR) /* because of alarm */
|
||||
continue;
|
||||
syslog(LOG_ERR, _("Error while waiting for input: %m"));
|
||||
return;
|
||||
if(errno != EINTR) /* because of alarm */
|
||||
{
|
||||
syslog(LOG_ERR, _("Error while waiting for input: %m"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(sighup)
|
||||
{
|
||||
close_network_connections();
|
||||
clear_config();
|
||||
if(read_config_file(configfilename))
|
||||
{
|
||||
syslog(LOG_ERR, _("Unable to reread configuration file, exitting"));
|
||||
exit(0);
|
||||
}
|
||||
if(setup_network_connections())
|
||||
{
|
||||
syslog(LOG_ERR, _("Unable to restart, exitting"));
|
||||
exit(0);
|
||||
}
|
||||
sighup = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(last_ping_check + timeout < time(NULL))
|
||||
|
|
|
@ -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.16 2000/06/29 17:09:06 guus Exp $
|
||||
$Id: protocol.c,v 1.28.4.17 2000/06/29 19:47:03 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
@ -391,6 +391,7 @@ cp
|
|||
|
||||
int basic_info_h(conn_list_t *cl)
|
||||
{
|
||||
conn_list_t *old;
|
||||
cp
|
||||
if(debug_lvl > 1)
|
||||
syslog(LOG_DEBUG, _("Got BASIC_INFO from %s"), cl->real_hostname);
|
||||
|
@ -413,24 +414,28 @@ cp
|
|||
|
||||
if(cl->status.outgoing)
|
||||
{
|
||||
/* First check if the host we connected to is already in our
|
||||
connection list. If so, we are probably making a loop, which
|
||||
is not desirable.
|
||||
*/
|
||||
|
||||
if(old=lookup_conn(cl->vpn_ip))
|
||||
{
|
||||
if(debug_lvl>0)
|
||||
syslog(LOG_NOTICE, _("Uplink %s (%s) is already in our connection list"),
|
||||
cl->vpn_hostname, cl->real_hostname);
|
||||
cl->status.outgoing = 0;
|
||||
old->status.outgoing = 1;
|
||||
terminate_connection(cl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(setup_vpn_connection(cl) < 0)
|
||||
return -1;
|
||||
send_basic_info(cl);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* First check if the host we connected to is already in our
|
||||
connection list. If so, we are probably making a loop, which
|
||||
is not desirable. It should not happen though.
|
||||
*/
|
||||
|
||||
if(lookup_conn(cl->vpn_ip))
|
||||
{
|
||||
if(debug_lvl>0)
|
||||
syslog(LOG_NOTICE, _("Uplink %s (%s) is already in our connection list, aborting connect"),
|
||||
cl->vpn_hostname, cl->real_hostname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(setup_vpn_connection(cl) < 0)
|
||||
return -1;
|
||||
|
|
15
src/tincd.c
15
src/tincd.c
|
@ -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.4 2000/06/29 17:09:08 guus Exp $
|
||||
$Id: tincd.c,v 1.10.4.5 2000/06/29 19:47:04 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
@ -62,7 +62,7 @@ static int kill_tincd = 0;
|
|||
static int do_detach = 1;
|
||||
|
||||
char *confbase = NULL; /* directory in which all config files are */
|
||||
char *configfilename = NULL; /* configuration file name */
|
||||
/* char *configfilename = NULL; /* configuration file name, moved to config.c */
|
||||
char *identname; /* program name for syslog */
|
||||
char *netname = NULL; /* name of the vpn network */
|
||||
char *pidfilename; /* pid file location */
|
||||
|
@ -416,7 +416,6 @@ sigsegv_handler(int a)
|
|||
syslog(LOG_NOTICE, _("Got SEGV signal, trying to re-execute"));
|
||||
|
||||
signal(SIGSEGV, sigsegv_square);
|
||||
|
||||
close_network_connections();
|
||||
remove_pid(pidfilename);
|
||||
execvp(g_argv[0], g_argv);
|
||||
|
@ -426,17 +425,15 @@ RETSIGTYPE
|
|||
sighup_handler(int a)
|
||||
{
|
||||
if(debug_lvl > 0)
|
||||
syslog(LOG_NOTICE, _("Got HUP signal"));
|
||||
close_network_connections();
|
||||
setup_network_connections();
|
||||
/* FIXME: read config-file and re-establish network connections */
|
||||
syslog(LOG_NOTICE, _("Got HUP signal, rereading configuration and restarting"));
|
||||
sighup = 1;
|
||||
}
|
||||
|
||||
RETSIGTYPE
|
||||
sigint_handler(int a)
|
||||
{
|
||||
if(debug_lvl > 0)
|
||||
syslog(LOG_NOTICE, _("Got INT signal"));
|
||||
syslog(LOG_NOTICE, _("Got INT signal, exitting"));
|
||||
cleanup_and_exit(0);
|
||||
}
|
||||
|
||||
|
@ -450,7 +447,7 @@ RETSIGTYPE
|
|||
sigusr2_handler(int a)
|
||||
{
|
||||
if(debug_lvl > 1)
|
||||
syslog(LOG_NOTICE, _("Forcing new key generation"));
|
||||
syslog(LOG_NOTICE, _("Got USR2 signal, forcing new key generation"));
|
||||
regenerate_keys();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue