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.27 2002/09/15 14:55:53 guus Exp $
+ $Id: net_setup.c,v 1.1.2.33 2003/07/06 22:11:32 guus Exp $
*/
#include "config.h"
#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,
#include "route.h"
#include "device.h"
#include "event.h"
+#include "logger.h"
#include "system.h"
cp();
- if(!c->rsa_key)
+ if(!c->rsa_key) {
c->rsa_key = RSA_new();
+// RSA_blinding_on(c->rsa_key, NULL);
+ }
/* First, check for simple PublicKey statement */
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;
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;
c->rsa_key = PEM_read_RSA_PUBKEY(fp, &c->rsa_key, NULL, NULL);
fclose(fp);
- if(c->rsa_key)
+ if(c->rsa_key) {
+// RSA_blinding_on(c->rsa_key, NULL);
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 {
if(fp) {
c->rsa_key = PEM_read_RSA_PUBKEY(fp, &c->rsa_key, NULL, NULL);
+// RSA_blinding_on(c->rsa_key, NULL);
fclose(fp);
}
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;
}
if(get_config_string(lookup_config(config_tree, "PrivateKey"), &key)) {
myself->connection->rsa_key = RSA_new();
+// RSA_blinding_on(myself->connection->rsa_key, NULL);
BN_hex2bn(&myself->connection->rsa_key->d, key);
BN_hex2bn(&myself->connection->rsa_key->e, "FFFF");
free(key);
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;
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;
}
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;
}
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;
}
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);
&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))
(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
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);
- } else
- addressfamily = AF_INET;
+ }
get_config_bool(lookup_config(config_tree, "Hostnames"), &hostnames);
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;
}
}
keylifetime = 3600;
keyexpires = now + keylifetime;
+
+ EVP_CIPHER_CTX_init(&packet_ctx);
+ EVP_DecryptInit_ex(&packet_ctx, myself->cipher, NULL, myself->key, myself->key + myself->cipher->key_len);
/* Check if we want to use message authentication codes... */
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;
}
}
&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;
}
}
if(get_config_int
(lookup_config(myself->connection->config_tree, "Compression"),
&myself->compression)) {
- if(myself->compression < 0 || myself->compression > 9) {
- syslog(LOG_ERR, _("Bogus compression level!"));
+ if(myself->compression < 0 || myself->compression > 11) {
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Bogus compression level!"));
return -1;
}
} else
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;
}
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);
}
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;
}
*/
int setup_network_connections(void)
{
- char *envp[4];
+ char *envp[5];
int i;
cp();
if(setup_device() < 0)
return -1;
+ if(setup_myself() < 0)
+ return -1;
+
/* Run tinc-up script to further initialize the tap interface */
asprintf(&envp[0], "NETNAME=%s", netname ? : "");
asprintf(&envp[1], "DEVICE=%s", device ? : "");
asprintf(&envp[2], "INTERFACE=%s", interface ? : "");
- envp[3] = NULL;
+ asprintf(&envp[3], "NAME=%s", myself->name);
+ envp[4] = NULL;
execute_script("tinc-up", envp);
- for(i = 0; i < 4; i++)
+ for(i = 0; i < 5; i++)
free(envp[i]);
- if(setup_myself() < 0)
- return -1;
-
try_outgoing_connections();
return 0;
{
avl_node_t *node, *next;
connection_t *c;
- char *envp[4];
+ char *envp[5];
int i;
cp();
asprintf(&envp[0], "NETNAME=%s", netname ? : "");
asprintf(&envp[1], "DEVICE=%s", device ? : "");
asprintf(&envp[2], "INTERFACE=%s", interface ? : "");
- envp[3] = NULL;
+ asprintf(&envp[3], "NAME=%s", myself->name);
+ envp[4] = NULL;
execute_script("tinc-down", envp);