summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-02-23 14:18:13 +0000
committerChristian Pointner <equinox@anytun.org>2009-02-23 14:18:13 +0000
commit364cdcb626efa89061100efce7eb168155da9906 (patch)
tree57165429664bfacdebea904e51cc5eab9893104f /src
parentadded string_list (diff)
added extended logging support
Diffstat (limited to 'src')
-rw-r--r--src/auth_algo.c20
-rw-r--r--src/bsd/tun.c20
-rw-r--r--src/cipher.c26
-rw-r--r--src/daemon.h26
-rw-r--r--src/key_derivation.c40
-rw-r--r--src/linux/tun.c12
-rw-r--r--src/log.c148
-rw-r--r--src/log.h62
-rw-r--r--src/log_targets.h335
-rw-r--r--src/string_list.c3
-rw-r--r--src/sysexec.h4
-rw-r--r--src/uanytun.c37
-rw-r--r--src/udp.c8
13 files changed, 621 insertions, 120 deletions
diff --git a/src/auth_algo.c b/src/auth_algo.c
index 299b86b..db57418 100644
--- a/src/auth_algo.c
+++ b/src/auth_algo.c
@@ -54,7 +54,7 @@ int auth_algo_init(auth_algo_t* aa, const char* type)
else if(!strcmp(type, "sha1"))
aa->type_ = aa_sha1;
else {
- log_printf(ERR, "unknown auth algo type");
+ log_printf(ERROR, "unknown auth algo type");
return -1;
}
@@ -95,7 +95,7 @@ void auth_algo_generate(auth_algo_t* aa, key_derivation_t* kd, key_store_dir_t d
else if(aa->type_ == aa_sha1)
auth_algo_sha1_generate(aa, kd, dir, packet);
else {
- log_printf(ERR, "unknown auth algo type");
+ log_printf(ERROR, "unknown auth algo type");
return;
}
}
@@ -110,7 +110,7 @@ int auth_algo_check_tag(auth_algo_t* aa, key_derivation_t* kd, key_store_dir_t d
else if(aa->type_ == aa_sha1)
return auth_algo_sha1_check_tag(aa, kd, dir, packet);
else {
- log_printf(ERR, "unknown auth algo type");
+ log_printf(ERROR, "unknown auth algo type");
return 0;
}
}
@@ -141,7 +141,7 @@ int auth_algo_sha1_init(auth_algo_t* aa)
#ifndef USE_SSL_CRYPTO
gcry_error_t err = gcry_md_open(&params->handle_, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC);
if(err) {
- log_printf(ERR, "failed to open message digest algo: %s", gcry_strerror(err));
+ log_printf(ERROR, "failed to open message digest algo: %s", gcry_strerror(err));
return -1;
}
#else
@@ -179,11 +179,11 @@ void auth_algo_sha1_generate(auth_algo_t* aa, key_derivation_t* kd, key_store_di
return;
if(!aa || !aa->params_) {
- log_printf(ERR, "auth algo not initialized");
+ log_printf(ERROR, "auth algo not initialized");
return;
}
if(!kd) {
- log_printf(ERR, "no key derivation supplied");
+ log_printf(ERROR, "no key derivation supplied");
return;
}
auth_algo_sha1_param_t* params = aa->params_;
@@ -195,7 +195,7 @@ void auth_algo_sha1_generate(auth_algo_t* aa, key_derivation_t* kd, key_store_di
#ifndef USE_SSL_CRYPTO
gcry_error_t err = gcry_md_setkey(params->handle_, aa->key_.buf_, aa->key_.length_);
if(err) {
- log_printf(ERR, "failed to set hmac key: %s", gcry_strerror(err));
+ log_printf(ERROR, "failed to set hmac key: %s", gcry_strerror(err));
return;
}
@@ -227,11 +227,11 @@ int auth_algo_sha1_check_tag(auth_algo_t* aa, key_derivation_t* kd, key_store_di
return 0;
if(!aa || !aa->params_) {
- log_printf(ERR, "auth algo not initialized");
+ log_printf(ERROR, "auth algo not initialized");
return 0;
}
if(!kd) {
- log_printf(ERR, "no key derivation supplied");
+ log_printf(ERROR, "no key derivation supplied");
return 0;
}
auth_algo_sha1_param_t* params = aa->params_;
@@ -243,7 +243,7 @@ int auth_algo_sha1_check_tag(auth_algo_t* aa, key_derivation_t* kd, key_store_di
#ifndef USE_SSL_CRYPTO
gcry_error_t err = gcry_md_setkey(params->handle_, aa->key_.buf_, aa->key_.length_);
if(err) {
- log_printf(ERR, "failed to set hmac key: %s", gcry_strerror(err));
+ log_printf(ERROR, "failed to set hmac key: %s", gcry_strerror(err));
return -1;
}
diff --git a/src/bsd/tun.c b/src/bsd/tun.c
index d52cf67..4c50c40 100644
--- a/src/bsd/tun.c
+++ b/src/bsd/tun.c
@@ -86,12 +86,12 @@ int tun_init(tun_device_t* dev, const char* dev_name, const char* dev_type, cons
}
#endif
else {
- log_printf(ERR, "unable to recognize type of device (tun or tap)");
+ log_printf(ERROR, "unable to recognize type of device (tun or tap)");
tun_close(dev);
return -1;
}
if(!device_file) {
- log_printf(ERR, "can't open device file: memory error");
+ log_printf(ERROR, "can't open device file: memory error");
tun_close(dev);
return -2;
}
@@ -103,7 +103,7 @@ int tun_init(tun_device_t* dev, const char* dev_name, const char* dev_type, cons
asprintf(&device_file_tmp, "%s%d", device_file, dev_id);
if(!device_file_tmp) {
- log_printf(ERR, "can't open device file: memory error");
+ log_printf(ERROR, "can't open device file: memory error");
free(device_file);
tun_close(dev);
return -2;
@@ -121,9 +121,9 @@ int tun_init(tun_device_t* dev, const char* dev_name, const char* dev_type, cons
if(dev->fd_ < 0) {
if(dynamic)
- log_printf(ERR, "can't open device file dynamically: no unused node left");
+ log_printf(ERROR, "can't open device file dynamically: no unused node left");
else
- log_printf(ERR, "can't open device file (%s): %m", device_file);
+ log_printf(ERROR, "can't open device file (%s): %m", device_file);
tun_close(dev);
return -1;
@@ -135,7 +135,7 @@ int tun_init(tun_device_t* dev, const char* dev_name, const char* dev_type, cons
dev->actual_name_ = strdup(dev_name);
if(!dev->actual_name_) {
- log_printf(ERR, "can't open device file: memory error");
+ log_printf(ERROR, "can't open device file: memory error");
tun_close(dev);
return -2;
}
@@ -165,7 +165,7 @@ int tun_init_post(tun_device_t* dev)
struct tuninfo ti;
if (ioctl(dev->fd_, TUNGIFINFO, &ti) < 0) {
- log_printf(ERR, "can't enable multicast for interface");
+ log_printf(ERROR, "can't enable multicast for interface");
return -1;
}
@@ -174,7 +174,7 @@ int tun_init_post(tun_device_t* dev)
ti.flags &= ~IFF_POINTOPOINT;
if (ioctl(dev->fd_, TUNSIFINFO, &ti) < 0) {
- log_printf(ERR, "can't enable multicast for interface");
+ log_printf(ERROR, "can't enable multicast for interface");
return -1;
}
return 0;
@@ -316,13 +316,13 @@ void tun_do_ifconfig(tun_device_t* dev)
asprintf(&command, "/sbin/ifconfig %s %s netmask %s mtu %d%s", dev->actual_name_, dev->net_addr_,
dev->net_mask_, dev->mtu_, end);
if(!command) {
- log_printf(ERR, "Execution of ifconfig failed");
+ log_printf(ERROR, "Execution of ifconfig failed");
return;
}
int result = system(command);
if(result == -1)
- log_printf(ERR, "Execution of ifconfig failed");
+ log_printf(ERROR, "Execution of ifconfig failed");
else
log_printf(NOTICE, "ifconfig returned %d", WEXITSTATUS(result));
diff --git a/src/cipher.c b/src/cipher.c
index f585471..28d9bf6 100644
--- a/src/cipher.c
+++ b/src/cipher.c
@@ -70,7 +70,7 @@ int cipher_init(cipher_t* c, const char* type, int8_t anytun02_compat)
}
#endif
else {
- log_printf(ERR, "unknown cipher type");
+ log_printf(ERROR, "unknown cipher type");
return -1;
}
@@ -127,7 +127,7 @@ int cipher_encrypt(cipher_t* c, key_derivation_t* kd, key_store_dir_t dir, plain
seq_nr, sender_id, mux);
#endif
else {
- log_printf(ERR, "unknown cipher type");
+ log_printf(ERROR, "unknown cipher type");
return -1;
}
@@ -160,7 +160,7 @@ int cipher_decrypt(cipher_t* c, key_derivation_t* kd, key_store_dir_t dir, encry
encrypted_packet_get_mux(in));
#endif
else {
- log_printf(ERR, "unknown cipher type");
+ log_printf(ERROR, "unknown cipher type");
return -1;
}
@@ -219,14 +219,14 @@ int cipher_aesctr_init(cipher_t* c)
case 192: algo = GCRY_CIPHER_AES192; break;
case 256: algo = GCRY_CIPHER_AES256; break;
default: {
- log_printf(ERR, "cipher key length of %d Bits is not supported", c->key_length_);
+ log_printf(ERROR, "cipher key length of %d Bits is not supported", c->key_length_);
return -1;
}
}
gcry_error_t err = gcry_cipher_open(&params->handle_, algo, GCRY_CIPHER_MODE_CTR, 0);
if(err) {
- log_printf(ERR, "failed to open cipher: %s", gcry_strerror(err));
+ log_printf(ERROR, "failed to open cipher: %s", gcry_strerror(err));
return -1;
}
#endif
@@ -279,12 +279,12 @@ int cipher_aesctr_calc_ctr(cipher_t* c, key_derivation_t* kd, key_store_dir_t di
int32_t cipher_aesctr_crypt(cipher_t* c, key_derivation_t* kd, key_store_dir_t dir, u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t olen, seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux)
{
if(!c || !c->params_) {
- log_printf(ERR, "cipher not initialized");
+ log_printf(ERROR, "cipher not initialized");
return -1;
}
if(!kd) {
- log_printf(ERR, "no key derivation supplied");
+ log_printf(ERROR, "no key derivation supplied");
return -1;
}
@@ -297,38 +297,38 @@ int32_t cipher_aesctr_crypt(cipher_t* c, key_derivation_t* kd, key_store_dir_t d
#ifdef USE_SSL_CRYPTO
ret = AES_set_encrypt_key(c->key_.buf_, c->key_length_, &params->aes_key_);
if(ret) {
- log_printf(ERR, "failed to set cipher ssl aes-key (code: %d)", ret);
+ log_printf(ERROR, "failed to set cipher ssl aes-key (code: %d)", ret);
return -1;
}
#else
gcry_error_t err = gcry_cipher_setkey(params->handle_, c->key_.buf_, c->key_.length_);
if(err) {
- log_printf(ERR, "failed to set cipher key: %s", gcry_strerror(err));
+ log_printf(ERROR, "failed to set cipher key: %s", gcry_strerror(err));
return -1;
}
#endif
ret = cipher_aesctr_calc_ctr(c, kd, dir, seq_nr, sender_id, mux);
if(ret < 0) {
- log_printf(ERR, "failed to calculate cipher CTR");
+ log_printf(ERROR, "failed to calculate cipher CTR");
return ret;
}
#ifndef USE_SSL_CRYPTO
err = gcry_cipher_setctr(params->handle_, params->ctr_.buf_, C_AESCTR_CTR_LENGTH);
if(err) {
- log_printf(ERR, "failed to set cipher CTR: %s", gcry_strerror(err));
+ log_printf(ERROR, "failed to set cipher CTR: %s", gcry_strerror(err));
return -1;
}
err = gcry_cipher_encrypt(params->handle_, out, olen, in, ilen);
if(err) {
- log_printf(ERR, "failed to de/encrypt packet: %s", gcry_strerror(err));
+ log_printf(ERROR, "failed to de/encrypt packet: %s", gcry_strerror(err));
return -1;
}
#else
if(C_AESCTR_CTR_LENGTH != AES_BLOCK_SIZE) {
- log_printf(ERR, "failed to set cipher CTR: size don't fits");
+ log_printf(ERROR, "failed to set cipher CTR: size don't fits");
return -1;
}
u_int32_t num = 0;
diff --git a/src/daemon.h b/src/daemon.h
index 071765e..4cc10e8 100644
--- a/src/daemon.h
+++ b/src/daemon.h
@@ -59,7 +59,7 @@ int priv_init(priv_info_t* priv, const char* username, const char* groupname)
priv->pw_ = getpwnam(username);
if(!priv->pw_) {
- log_printf(ERR, "unkown user %s", username);
+ log_printf(ERROR, "unkown user %s", username);
return -1;
}
@@ -69,7 +69,7 @@ int priv_init(priv_info_t* priv, const char* username, const char* groupname)
priv->gr_ = getgrgid(priv->pw_->pw_gid);
if(!priv->gr_) {
- log_printf(ERR, "unkown group %s", groupname);
+ log_printf(ERROR, "unkown group %s", groupname);
return -1;
}
@@ -79,24 +79,24 @@ int priv_init(priv_info_t* priv, const char* username, const char* groupname)
int priv_drop(priv_info_t* priv)
{
if(!priv || !priv->pw_ || !priv->gr_) {
- log_printf(ERR, "privileges not initialized properly");
+ log_printf(ERROR, "privileges not initialized properly");
return -1;
}
if(setgid(priv->gr_->gr_gid)) {
- log_printf(ERR, "setgid('%s') failed: %m", priv->gr_->gr_name);
+ log_printf(ERROR, "setgid('%s') failed: %m", priv->gr_->gr_name);
return -1;
}
gid_t gr_list[1];
gr_list[0] = priv->gr_->gr_gid;
if(setgroups (1, gr_list)) {
- log_printf(ERR, "setgroups(['%s']) failed: %m", priv->gr_->gr_name);
+ log_printf(ERROR, "setgroups(['%s']) failed: %m", priv->gr_->gr_name);
return -1;
}
if(setuid(priv->pw_->pw_uid)) {
- log_printf(ERR, "setuid('%s') failed: %m", priv->pw_->pw_name);
+ log_printf(ERROR, "setuid('%s') failed: %m", priv->pw_->pw_name);
return -1;
}
@@ -108,17 +108,17 @@ int priv_drop(priv_info_t* priv)
int do_chroot(const char* chrootdir)
{
if(getuid() != 0) {
- log_printf(ERR, "this programm has to be run as root in order to run in a chroot");
+ log_printf(ERROR, "this programm has to be run as root in order to run in a chroot");
return -1;
}
if(chroot(chrootdir)) {
- log_printf(ERR, "can't chroot to %s: %m", chrootdir);
+ log_printf(ERROR, "can't chroot to %s: %m", chrootdir);
return -1;
}
log_printf(NOTICE, "we are in chroot jail (%s) now", chrootdir);
if(chdir("/")) {
- log_printf(ERR, "can't change to /: %m");
+ log_printf(ERROR, "can't change to /: %m");
return -1;
}
}
@@ -129,7 +129,7 @@ void daemonize()
pid = fork();
if(pid < 0) {
- log_printf(ERR, "daemonizing failed at fork(): %m, exitting");
+ log_printf(ERROR, "daemonizing failed at fork(): %m, exitting");
exit(-1);
}
if(pid) exit(0);
@@ -137,19 +137,19 @@ void daemonize()
umask(0);
if(setsid() < 0) {
- log_printf(ERR, "daemonizing failed at setsid(): %m, exitting");
+ log_printf(ERROR, "daemonizing failed at setsid(): %m, exitting");
exit(-1);
}
pid = fork();
if(pid < 0) {
- log_printf(ERR, "daemonizing failed at fork(): %m, exitting");
+ log_printf(ERROR, "daemonizing failed at fork(): %m, exitting");
exit(-1);
}
if(pid) exit(0);
if ((chdir("/")) < 0) {
- log_printf(ERR, "daemonizing failed at chdir(): %m, exitting");
+ log_printf(ERROR, "daemonizing failed at chdir(): %m, exitting");
exit(-1);
}
diff --git a/src/key_derivation.c b/src/key_derivation.c
index 43277be..cbc7472 100644
--- a/src/key_derivation.c
+++ b/src/key_derivation.c
@@ -69,7 +69,7 @@ int key_derivation_init(key_derivation_t* kd, const char* type, int8_t ld_kdr, i
}
}
else {
- log_printf(ERR, "unknown key derivation type");
+ log_printf(ERROR, "unknown key derivation type");
return -1;
}
@@ -132,13 +132,13 @@ int key_derivation_generate_master_key(key_derivation_t* kd, const char* passphr
return -1;
if(kd->master_key_.buf_) {
- log_printf(ERR, "master key and passphrase provided, ignoring passphrase");
+ log_printf(ERROR, "master key and passphrase provided, ignoring passphrase");
return 0;
}
log_printf(NOTICE, "using passphrase to generate master key");
if(!key_length || (key_length % 8)) {
- log_printf(ERR, "bad master key length");
+ log_printf(ERROR, "bad master key length");
return -1;
}
@@ -147,7 +147,7 @@ int key_derivation_generate_master_key(key_derivation_t* kd, const char* passphr
#else
if(key_length > (SHA256_DIGEST_LENGTH * 8)) {
#endif
- log_printf(ERR, "master key too long for passphrase algorithm");
+ log_printf(ERROR, "master key too long for passphrase algorithm");
return -1;
}
@@ -188,13 +188,13 @@ int key_derivation_generate_master_salt(key_derivation_t* kd, const char* passph
return -1;
if(kd->master_salt_.buf_) {
- log_printf(ERR, "master salt and passphrase provided, ignoring passphrase");
+ log_printf(ERROR, "master salt and passphrase provided, ignoring passphrase");
return 0;
}
log_printf(NOTICE, "using passphrase to generate master salt");
if(!salt_length || (salt_length % 8)) {
- log_printf(ERR, "bad master salt length");
+ log_printf(ERROR, "bad master salt length");
return -1;
}
@@ -203,7 +203,7 @@ int key_derivation_generate_master_salt(key_derivation_t* kd, const char* passph
#else
if(salt_length > (SHA_DIGEST_LENGTH * 8)) {
#endif
- log_printf(ERR, "master salt too long for passphrase algorithm");
+ log_printf(ERROR, "master salt too long for passphrase algorithm");
return -1;
}
@@ -266,7 +266,7 @@ int key_derivation_generate(key_derivation_t* kd, key_store_dir_t dir, satp_prf_
return -1;
if(label >= KD_LABEL_COUNT) {
- log_printf(ERR, "label 0x%02X out of range", label);
+ log_printf(ERROR, "label 0x%02X out of range", label);
return -1;
}
@@ -276,7 +276,7 @@ int key_derivation_generate(key_derivation_t* kd, key_store_dir_t dir, satp_prf_
else if(kd->type_ == kd_aes_ctr)
ret = key_derivation_aesctr_generate(kd, dir, label, seq_nr, key, len);
else {
- log_printf(ERR, "unknown key derivation type");
+ log_printf(ERROR, "unknown key derivation type");
return -1;
}
return ret;
@@ -326,26 +326,26 @@ int key_derivation_aesctr_init(key_derivation_t* kd, const char* passphrase)
case 192: algo = GCRY_CIPHER_AES192; break;
case 256: algo = GCRY_CIPHER_AES256; break;
default: {
- log_printf(ERR, "key derivation key length of %d Bits is not supported", kd->key_length_);
+ log_printf(ERROR, "key derivation key length of %d Bits is not supported", kd->key_length_);
return -1;
}
}
gcry_error_t err = gcry_cipher_open(&params->handle_, algo, GCRY_CIPHER_MODE_CTR, 0);
if(err) {
- log_printf(ERR, "failed to open key derivation cipher: %s", gcry_strerror(err));
+ log_printf(ERROR, "failed to open key derivation cipher: %s", gcry_strerror(err));
return -1;
}
err = gcry_cipher_setkey(params->handle_, kd->master_key_.buf_, kd->master_key_.length_);
if(err) {
- log_printf(ERR, "failed to set key derivation key: %s", gcry_strerror(err));
+ log_printf(ERROR, "failed to set key derivation key: %s", gcry_strerror(err));
return -1;
}
#else
int ret = AES_set_encrypt_key(kd->master_key_.buf_, kd->master_key_.length_*8, &params->aes_key_);
if(ret) {
- log_printf(ERR, "failed to set key derivation ssl aes-key (code: %d)", ret);
+ log_printf(ERROR, "failed to set key derivation ssl aes-key (code: %d)", ret);
return -1;
}
#endif
@@ -387,7 +387,7 @@ int key_derivation_aesctr_calc_ctr(key_derivation_t* kd, key_store_dir_t dir, se
}
if(kd->master_salt_.length_ != KD_AESCTR_SALT_LENGTH) {
- log_printf(ERR, "master salt has the wrong length");
+ log_printf(ERROR, "master salt has the wrong length");
return -1;
}
memcpy(params->ctr_.salt_.buf_, kd->master_salt_.buf_, KD_AESCTR_SALT_LENGTH);
@@ -407,7 +407,7 @@ int key_derivation_aesctr_calc_ctr(key_derivation_t* kd, key_store_dir_t dir, se
int key_derivation_aesctr_generate(key_derivation_t* kd, key_store_dir_t dir, satp_prf_label_t label, seq_nr_t seq_nr, u_int8_t* key, u_int32_t len)
{
if(!kd || !kd->params_ || !kd->master_key_.buf_ || !kd->master_salt_.buf_) {
- log_printf(ERR, "key derivation not initialized or no key or salt set");
+ log_printf(ERROR, "key derivation not initialized or no key or salt set");
return -1;
}
@@ -416,7 +416,7 @@ int key_derivation_aesctr_generate(key_derivation_t* kd, key_store_dir_t dir, sa
seq_nr_t r;
int ret = key_derivation_aesctr_calc_ctr(kd, dir, &r, label, seq_nr);
if(ret < 0) {
- log_printf(ERR, "failed to calculate key derivation CTR");
+ log_printf(ERROR, "failed to calculate key derivation CTR");
return -1;
}
else if(!ret) {
@@ -432,25 +432,25 @@ int key_derivation_aesctr_generate(key_derivation_t* kd, key_store_dir_t dir, sa
#ifndef USE_SSL_CRYPTO
gcry_error_t err = gcry_cipher_reset(params->handle_);
if(err) {
- log_printf(ERR, "failed to reset key derivation cipher: %s", gcry_strerror(err));
+ log_printf(ERROR, "failed to reset key derivation cipher: %s", gcry_strerror(err));
return -1;
}
err = gcry_cipher_setctr(params->handle_, params->ctr_.buf_, KD_AESCTR_CTR_LENGTH);
if(err) {
- log_printf(ERR, "failed to set key derivation CTR: %s", gcry_strerror(err));
+ log_printf(ERROR, "failed to set key derivation CTR: %s", gcry_strerror(err));
return -1;
}
memset(key, 0, len);
err = gcry_cipher_encrypt(params->handle_, key, len, NULL, 0);
if(err) {
- log_printf(ERR, "failed to generate key derivation bitstream: %s", gcry_strerror(err));
+ log_printf(ERROR, "failed to generate key derivation bitstream: %s", gcry_strerror(err));
return -1;
}
#else
if(KD_AESCTR_CTR_LENGTH != AES_BLOCK_SIZE) {
- log_printf(ERR, "failed to set key derivation CTR: size don't fits");
+ log_printf(ERROR, "failed to set key derivation CTR: size don't fits");
return -1;
}
u_int32_t num = 0;
diff --git a/src/linux/tun.c b/src/linux/tun.c
index 1faf49d..87cc815 100644
--- a/src/linux/tun.c
+++ b/src/linux/tun.c
@@ -64,7 +64,7 @@ int tun_init(tun_device_t* dev, const char* dev_name, const char* dev_type, cons
dev->fd_ = open(DEFAULT_DEVICE, O_RDWR);
if(dev->fd_ < 0) {
- log_printf(ERR, "can't open device file (%s): %m", DEFAULT_DEVICE);
+ log_printf(ERROR, "can't open device file (%s): %m", DEFAULT_DEVICE);
tun_close(dev);
return -1;
}
@@ -81,7 +81,7 @@ int tun_init(tun_device_t* dev, const char* dev_name, const char* dev_type, cons
dev->with_pi_ = 0;
}
else {
- log_printf(ERR, "unable to recognize type of device (tun or tap)");
+ log_printf(ERROR, "unable to recognize type of device (tun or tap)");
tun_close(dev);
return -1;
}
@@ -94,13 +94,13 @@ int tun_init(tun_device_t* dev, const char* dev_name, const char* dev_type, cons
} else if(!ioctl(dev->fd_, (('T' << 8) | 202), &ifr)) {
dev->actual_name_ = strdup(ifr.ifr_name);
} else {
- log_printf(ERR, "tun/tap device ioctl failed: %m");
+ log_printf(ERROR, "tun/tap device ioctl failed: %m");
tun_close(dev);
return -1;
}
if(!dev->actual_name_) {
- log_printf(ERR, "can't open device file: memory error");
+ log_printf(ERROR, "can't open device file: memory error");
tun_close(dev);
return -2;
}
@@ -192,13 +192,13 @@ void tun_do_ifconfig(tun_device_t* dev)
char* command = NULL;
asprintf(&command, "/sbin/ifconfig %s %s netmask %s mtu %d", dev->actual_name_, dev->net_addr_, dev->net_mask_, dev->mtu_);
if(!command) {
- log_printf(ERR, "Execution of ifconfig failed");
+ log_printf(ERROR, "Execution of ifconfig failed");
return;
}
int result = system(command);
if(result == -1)
- log_printf(ERR, "Execution of ifconfig failed");
+ log_printf(ERROR, "Execution of ifconfig failed");
else
log_printf(NOTICE, "ifconfig returned %d", WEXITSTATUS(result));
diff --git a/src/log.c b/src/log.c
index 77e998f..aea8ff4 100644
--- a/src/log.c
+++ b/src/log.c
@@ -34,22 +34,160 @@
#include "datatypes.h"
+#include <string.h>
#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define SYSLOG_NAMES
+#include <syslog.h>
+
#include "log.h"
-log_facility_t g_facility = DAEMON;
+log_t stdlog;
+
+#include "log_targets.h"
+
+const char* log_prio_to_string(log_prio_t prio)
+{
+ switch(prio) {
+ case ERROR: return "ERROR";
+ case WARNING: return "WARNING";
+ case NOTICE: return "NOTICE";
+ case INFO: return "INFO";
+ case DEBUG: return "DEBUG";
+ }
+ return "UNKNOWN";
+}
+
+log_target_type_t log_target_parse_type(const char* conf)
+{
+ if(!conf)
+ return TARGET_UNKNOWN;
+
+ if(!strncmp(conf, "syslog", 6)) return TARGET_SYSLOG;
+ if(!strncmp(conf, "file", 4)) return TARGET_FILE;
+ if(!strncmp(conf, "stdout", 6)) return TARGET_STDOUT;
+ if(!strncmp(conf, "stderr", 6)) return TARGET_STDERR;
+
+ return TARGET_UNKNOWN;
+}
-void log_init(const char* name, log_facility_t facility)
+int log_targets_add(log_targets_t* targets, const char* conf)
{
- g_facility = facility;
- openlog(name, LOG_PID | LOG_NDELAY, facility);
+ if(!targets)
+ return -1;
+
+ log_target_t* new_target = NULL;
+ switch(log_target_parse_type(conf)) {
+ case TARGET_SYSLOG: new_target = log_target_syslog_new(); break;
+ case TARGET_FILE: new_target = log_target_file_new(); break;
+ case TARGET_STDOUT: new_target = log_target_stdout_new(); break;
+ case TARGET_STDERR: new_target = log_target_stderr_new(); break;
+ default: return -3;
+ }
+ if(!new_target)
+ return -2;
+
+ const char* prioptr = strchr(conf, ':');
+ if(!prioptr || prioptr[1] == 0) {
+ free(new_target);
+ return -1;
+ }
+ prioptr++;
+ if(!isdigit(prioptr[0]) || (prioptr[1] != 0 && prioptr[1] != ',')) {
+ free(new_target);
+ return -1;
+ }
+ new_target->max_prio_ = prioptr[0] - '0';
+
+ if(new_target->init != NULL) {
+ const char* confptr = NULL;
+ if(prioptr[1] != 0)
+ confptr = prioptr+2;
+
+ int ret = (*new_target->init)(new_target, confptr);
+ if(ret) {
+ free(new_target);
+ return ret;
+ }
+ }
+
+ if(new_target->open != NULL)
+ (*new_target->open)(new_target);
+
+
+ if(!targets->first_) {
+ targets->first_ = new_target;
+ }
+ else {
+ log_target_t* tmp = targets->first_;
+ while(tmp->next_)
+ tmp = tmp->next_;
+
+ tmp->next_ = new_target;
+ }
+ return 0;
+}
+
+void log_targets_log(log_targets_t* targets, log_prio_t prio, const char* msg)
+{
+ if(!targets)
+ return;
+
+ log_target_t* tmp = targets->first_;
+ while(tmp) {
+ if(tmp->log != NULL && tmp->enabled_ && tmp->max_prio_ >= prio)
+ (*tmp->log)(tmp, prio, msg);
+
+ tmp = tmp->next_;
+ }
+}
+
+void log_targets_clear(log_targets_t* targets)
+{
+ if(!targets)
+ return;
+
+ while(targets->first_) {
+ log_target_t* tmp = targets->first_;
+ targets->first_ = tmp->next_;
+ if(tmp->close != NULL)
+ (*tmp->close)(tmp);
+ if(tmp->clear != NULL)
+ (*tmp->clear)(tmp);
+ free(tmp);
+ }
+}
+
+
+void log_init()
+{
+ stdlog.targets_.first_ = NULL;
+}
+
+void log_close()
+{
+ log_targets_clear(&stdlog.targets_);
+}
+
+int log_add_target(const char* conf)
+{
+ if(!conf)
+ return -1;
+
+ return log_targets_add(&stdlog.targets_, conf);
}
void log_printf(log_prio_t prio, const char* fmt, ...)
{
+ static char msg[MSG_LENGTH_MAX];
+
va_list args;
va_start(args, fmt);
- vsyslog(prio | g_facility, fmt, args);
+ vsnprintf(msg, MSG_LENGTH_MAX, fmt, args);
va_end(args);
+
+ log_targets_log(&stdlog.targets_, prio, msg);
}
diff --git a/src/log.h b/src/log.h
index 99f4a60..293a28f 100644
--- a/src/log.h
+++ b/src/log.h
@@ -35,27 +35,51 @@
#ifndef _LOG_H_
#define _LOG_H_
-#include <syslog.h>
-
-enum log_facility_enum { USER = LOG_USER, MAIL = LOG_MAIL,
- DAEMON = LOG_DAEMON, AUTH = LOG_AUTH,
- SYSLOG = LOG_SYSLOG, LPR = LOG_LPR,
- NEWS = LOG_NEWS, UUCP = LOG_UUCP,
- CRON = LOG_CRON, AUTHPRIV = LOG_AUTHPRIV,
- FTP = LOG_FTP, LOCAL0 = LOG_LOCAL0,
- LOCAL1 = LOG_LOCAL1, LOCAL2 = LOG_LOCAL2,
- LOCAL3 = LOG_LOCAL3, LOCAL4 = LOG_LOCAL4,
- LOCAL5 = LOG_LOCAL5, LOCAL6 = LOG_LOCAL6,
- LOCAL7 = LOG_LOCAL7 };
-typedef enum log_facility_enum log_facility_t;
-
-enum log_prio_enum { EMERG = LOG_EMERG, ALERT = LOG_ALERT,
- CRIT = LOG_CRIT, ERR = LOG_ERR,
- WARNING = LOG_WARNING, NOTICE = LOG_NOTICE,
- INFO = LOG_INFO, DEBUG = LOG_DEBUG };
+#define MSG_LENGTH_MAX 150
+
+enum log_prio_enum { ERROR = 1, WARNING = 2, NOTICE = 3,
+ INFO = 4, DEBUG = 5 };
typedef enum log_prio_enum log_prio_t;
-void log_init(const char* name, log_facility_t facility);
+const char* log_prio_to_string(log_prio_t prio);
+
+enum log_target_type_enum { TARGET_SYSLOG , TARGET_STDOUT, TARGET_STDERR, TARGET_FILE , TARGET_UNKNOWN };
+typedef enum log_target_type_enum log_target_type_t;
+
+struct log_target_struct {
+ log_target_type_t type_;
+ int (*init)(struct log_target_struct* self, const char* conf);
+ void (*open)(struct log_target_struct* self);
+ void (*log)(struct log_target_struct* self, log_prio_t prio, const char* msg);
+ void (*close)(struct log_target_struct* self);
+ void (*clear)(struct log_target_struct* self);
+ int opened_;
+ int enabled_;
+ log_prio_t max_prio_;
+ void* param_;
+ struct log_target_struct* next_;
+};
+typedef struct log_target_struct log_target_t;
+
+
+struct log_targets_struct {
+ log_target_t* first_;
+};
+typedef struct log_targets_struct log_targets_t;
+
+int log_targets_add(log_targets_t* targets, const char* conf);
+void log_targets_log(log_targets_t* targets, log_prio_t prio, const char* msg);
+void log_targets_clear(log_targets_t* targets);
+
+
+struct log_struct {
+ log_targets_t targets_;
+};
+typedef struct log_struct log_t;
+
+void log_init();
+void log_close();
+int log_add_target(const char* conf);
void log_printf(log_prio_t prio, const char* fmt, ...);
#endif
diff --git a/src/log_targets.h b/src/log_targets.h
new file mode 100644
index 0000000..66f13a0
--- /dev/null
+++ b/src/log_targets.h
@@ -0,0 +1,335 @@
+/*
+ * uAnytun
+ *
+ * uAnytun is a tiny implementation of SATP. Unlike Anytun which is a full
+ * featured implementation uAnytun has no support for multiple connections
+ * or synchronisation. It is a small single threaded implementation intended
+ * to act as a client on small platforms.
+ * The secure anycast tunneling protocol (satp) defines a protocol used
+ * for communication between any combination of unicast and anycast
+ * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
+ * mode and allows tunneling of every ETHER TYPE protocol (e.g.
+ * ethernet, ip, arp ...). satp directly includes cryptography and
+ * message authentication based on the methodes used by SRTP. It is
+ * intended to deliver a generic, scaleable and secure solution for
+ * tunneling and relaying of packets of any protocol.
+ *
+ *
+ * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ *
+ * This file is part of uAnytun.
+ *
+ * uAnytun is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * uAnytun is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with uAnytun. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+enum syslog_facility_enum { USER = LOG_USER, MAIL = LOG_MAIL,
+ DAEMON = LOG_DAEMON, AUTH = LOG_AUTH,
+ SYSLOG = LOG_SYSLOG, LPR = LOG_LPR,
+ NEWS = LOG_NEWS, UUCP = LOG_UUCP,
+ CRON = LOG_CRON, AUTHPRIV = LOG_AUTHPRIV,
+ FTP = LOG_FTP, LOCAL0 = LOG_LOCAL0,
+ LOCAL1 = LOG_LOCAL1, LOCAL2 = LOG_LOCAL2,
+ LOCAL3 = LOG_LOCAL3, LOCAL4 = LOG_LOCAL4,
+ LOCAL5 = LOG_LOCAL5, LOCAL6 = LOG_LOCAL6,
+ LOCAL7 = LOG_LOCAL7 };
+typedef enum syslog_facility_enum syslog_facility_t;
+
+struct log_target_syslog_param_struct {
+ char* logname_;
+ syslog_facility_t facility_;
+};
+typedef struct log_target_syslog_param_struct log_target_syslog_param_t;
+
+int log_target_syslog_init(log_target_t* self, const char* conf)
+{
+ if(!self || (conf && conf[0] == 0))
+ return -1;
+
+ self->param_ = malloc(sizeof(log_target_syslog_param_t));
+ if(!self->param_)
+ return -2;
+
+ char* logname;
+ const char* end = NULL;
+ if(!conf)
+ logname = strdup("uanytun");
+ else {
+ end = strchr(conf, ',');
+ if(end) {
+ size_t len = (size_t)(end - conf);
+ if(!len) {
+ free(self->param_);
+ return -1;
+ }
+ logname = malloc(len+1);
+ if(logname) {
+ strncpy(logname, conf, len);
+ logname[len] = 0;
+ }
+ }
+ else
+ logname = strdup(conf);
+ }
+
+ if(!logname) {
+ free(self->param_);
+ return -2;
+ }
+ ((log_target_syslog_param_t*)(self->param_))->logname_ = logname;
+
+ if(!end) {
+ ((log_target_syslog_param_t*)(self->param_))->facility_ = DAEMON;
+ return 0;
+ }
+
+ if(end[1] == 0 || end[1] == ',') {
+ free(logname);
+ free(self->param_);
+ return -1;
+ }
+
+ const char* start = end + 1;
+ end = strchr(start, ',');
+ int i;
+ for(i=0;;++i) {
+ if(facilitynames[i].c_name == NULL) {
+ free(logname);
+ free(self->param_);
+ return -1;
+ }
+
+ if(( end && !strncmp(start, facilitynames[i].c_name, (size_t)(end - start)) && facilitynames[i].c_name[(size_t)(end-start)] == 0) ||
+ (!end && !strcmp(start, facilitynames[i].c_name))) {
+ ((log_target_syslog_param_t*)(self->param_))->facility_ = facilitynames[i].c_val;
+ break;
+ }
+ }
+
+ return 0;
+}
+
+void log_target_syslog_open(log_target_t* self)
+{
+ if(!self || !self->param_)
+ return;
+
+ openlog(((log_target_syslog_param_t*)(self->param_))->logname_, LOG_PID, ((log_target_syslog_param_t*)(self->param_))->facility_);
+ self->opened_ = 1;
+}
+
+void log_target_syslog_log(log_target_t* self, log_prio_t prio, const char* msg)
+{
+ if(!self || !self->param_ || !self->opened_)
+ return;
+
+ syslog((prio + 2) | ((log_target_syslog_param_t*)(self->param_))->facility_, "%s", msg);
+}
+
+void log_target_syslog_close(log_target_t* self)
+{
+ closelog();
+ self->opened_ = 0;
+}
+
+void log_target_syslog_clear(log_target_t* self)
+{
+ if(!self || !self->param_)
+ return;
+
+ if(((log_target_syslog_param_t*)(self->param_))->logname_)
+ free(((log_target_syslog_param_t*)(self->param_))->logname_);
+
+ free(self->param_);
+}
+
+log_target_t* log_target_syslog_new()
+{
+ log_target_t* tmp = malloc(sizeof(log_target_t));
+ if(!tmp)
+ return NULL;
+
+ tmp->type_ = TARGET_SYSLOG;
+ tmp->init = &log_target_syslog_init;
+ tmp->open = &log_target_syslog_open;
+ tmp->log = &log_target_syslog_log;
+ tmp->close = &log_target_syslog_close;
+ tmp->clear = &log_target_syslog_clear;
+ tmp->opened_ = 0;
+ tmp->enabled_ = 1;
+ tmp->max_prio_ = NOTICE;
+ tmp->param_ = NULL;
+ tmp->next_ = NULL;
+
+ return tmp;
+}
+
+
+struct log_target_file_param_struct {
+ char* logfilename_;
+ FILE* file_;
+};
+typedef struct log_target_file_param_struct log_target_file_param_t;
+
+int log_target_file_init(log_target_t* self, const char* conf)
+{
+ if(!self || (conf && conf[0] == 0))
+ return -1;
+
+ self->param_ = malloc(sizeof(log_target_file_param_t));
+ if(!self->param_)
+ return -2;
+
+ char* logfilename;
+ if(!conf)
+ logfilename = strdup("uanytun.log");
+ else {
+ const char* end = strchr(conf, ',');
+ if(end) {
+ size_t len = (size_t)(end - conf);
+ if(!len) {
+ free(self->param_);
+ return -1;
+ }
+ logfilename = malloc(len+1);
+ if(logfilename) {
+ strncpy(logfilename, conf, len);
+ logfilename[len] = 0;
+ }
+ }
+ else
+ logfilename = strdup(conf);
+ }
+
+ if(!logfilename) {
+ free(self->param_);
+ return -2;
+ }
+ ((log_target_file_param_t*)(self->param_))->logfilename_ = logfilename;
+ ((log_target_file_param_t*)(self->param_))->file_ = NULL;
+
+ return 0;
+}
+
+void log_target_file_open(log_target_t* self)
+{
+ if(!self || !self->param_)
+ return;
+
+ ((log_target_file_param_t*)(self->param_))->file_ = fopen(((log_target_file_param_t*)(self->param_))->logfilename_, "w");
+ if(((log_target_file_param_t*)(self->param_))->file_)
+ self->opened_ = 1;
+}
+
+void log_target_file_log(log_target_t* self, log_prio_t prio, const char* msg)
+{
+ if(!self || !self->param_)
+ return;
+
+ fprintf(((log_target_file_param_t*)(self->param_))->file_, "%s-%s\n", log_prio_to_string(prio), msg);
+}
+
+void log_target_file_close(log_target_t* self)
+{
+ if(!self || !self->param_)
+ return;
+
+ fclose(((log_target_file_param_t*)(self->param_))->file_);
+ self->opened_ = 0;
+}
+
+void log_target_file_clear(log_target_t* self)
+{
+ if(!self || !self->param_)
+ return;
+
+ if(((log_target_file_param_t*)(self->param_))->logfilename_)
+ free(((log_target_file_param_t*)(self->param_))->logfilename_);
+
+ free(self->param_);
+}
+
+
+log_target_t* log_target_file_new()
+{
+ log_target_t* tmp = malloc(sizeof(log_target_t));
+ if(!tmp)
+ return NULL;
+
+ tmp->type_ = TARGET_FILE;
+ tmp->init = &log_target_file_init;
+ tmp->open = &log_target_file_open;
+ tmp->log = &log_target_file_log;
+ tmp->close = &log_target_file_close;
+ tmp->clear = &log_target_file_clear;
+ tmp->opened_ = 0;
+ tmp->enabled_ = 1;
+ tmp->max_prio_ = NOTICE;
+ tmp->param_ = NULL;
+ tmp->next_ = NULL;
+
+ return tmp;
+}
+
+
+void log_target_stdout_log(log_target_t* self, log_prio_t prio, const char* msg)
+{
+ printf("%s-%s\n", log_prio_to_string(prio), msg);
+}
+
+log_target_t* log_target_stdout_new()
+{
+ log_target_t* tmp = malloc(sizeof(log_target_t));
+ if(!tmp)
+ return NULL;
+
+ tmp->type_ = TARGET_STDOUT;
+ tmp->init = NULL;
+ tmp->open = NULL;
+ tmp->log = &log_target_stdout_log;
+ tmp->close = NULL;
+ tmp->clear = NULL;
+ tmp->opened_ = 0;
+ tmp->enabled_ = 1;
+ tmp->max_prio_ = NOTICE;
+ tmp->param_ = NULL;
+ tmp->next_ = NULL;
+
+ return tmp;
+}
+
+
+void log_target_stderr_log(log_target_t* self, log_prio_t prio, const char* msg)
+{
+ fprintf(stderr, "%s-%s\n", log_prio_to_string(prio), msg);
+}
+
+log_target_t* log_target_stderr_new()
+{
+ log_target_t* tmp = malloc(sizeof(log_target_t));
+ if(!tmp)
+ return NULL;
+
+ tmp->type_ = TARGET_STDERR;
+ tmp->init = NULL;
+ tmp->open = NULL;
+ tmp->log = &log_target_stderr_log;
+ tmp->close = NULL;
+ tmp->clear = NULL;
+ tmp->opened_ = 0;
+ tmp->enabled_ = 1;
+ tmp->max_prio_ = NOTICE;
+ tmp->param_ = NULL;
+ tmp->next_ = NULL;
+
+ return tmp;
+}
diff --git a/src/string_list.c b/src/string_list.c
index fa35789..bb59ff6 100644
--- a/src/string_list.c
+++ b/src/string_list.c
@@ -33,6 +33,7 @@
*/
#include <string.h>
+#include <stdlib.h>
#include <stdio.h>
#include "string_list.h"
@@ -63,7 +64,7 @@ void string_list_clear(string_list_t* list)
int string_list_add(string_list_t* list, const char* string)
{
if(!list)
- return;
+ return -1;
if(!list->first) {
list->first = malloc(sizeof(string_list_element_t));
diff --git a/src/sysexec.h b/src/sysexec.h
index 07cac2c..a50ec06 100644
--- a/src/sysexec.h
+++ b/src/sysexec.h
@@ -58,7 +58,7 @@ int exec_script(const char* script, const char* ifname)
}
execl("/bin/sh", "/bin/sh", script, ifname, NULL);
// if execl return, an error occurred
- log_printf(ERR, "error on executing script: %m");
+ log_printf(ERROR, "error on executing script: %m");
return -1;
}
int status = 0;
@@ -68,7 +68,7 @@ int exec_script(const char* script, const char* ifname)
else if(WIFSIGNALED(status))
log_printf(NOTICE, "script '%s' terminated after signal %d", script, WTERMSIG(status));
else
- log_printf(ERR, "executing script: unkown error");
+ log_printf(ERROR, "executing script: unkown error");
return status;
diff --git a/src/uanytun.c b/src/uanytun.c
index ab7f905..9080dd3 100644
--- a/src/uanytun.c
+++ b/src/uanytun.c
@@ -79,13 +79,13 @@ int init_libgcrypt()
gcry_error_t err = gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
if(err) {
- log_printf(ERR, "failed to disable secure memory: %s", gcry_strerror(err));
+ log_printf(ERROR, "failed to disable secure memory: %s", gcry_strerror(err));
return -1;
}
err = gcry_control(GCRYCTL_INITIALIZATION_FINISHED);
if(err) {
- log_printf(ERR, "failed to finish libgcrypt initialization: %s", gcry_strerror(err));
+ log_printf(ERROR, "failed to finish libgcrypt initialization: %s", gcry_strerror(err));
return -1;
}
@@ -103,14 +103,14 @@ int init_main_loop(options_t* opt, cipher_t* c, auth_algo_t* aa, key_derivation_
{
int ret = cipher_init(c, opt->cipher_, opt->anytun02_compat_);
if(ret) {
- log_printf(ERR, "could not initialize cipher of type %s", opt->cipher_);
+ log_printf(ERROR, "could not initialize cipher of type %s", opt->cipher_);
return ret;
}
#ifndef NO_CRYPT
ret = auth_algo_init(aa, opt->auth_algo_);
if(ret) {
- log_printf(ERR, "could not initialize auth algo of type %s", opt->auth_algo_);
+ log_printf(ERROR, "could not initialize auth algo of type %s", opt->auth_algo_);
cipher_close(c);
return ret;
}
@@ -119,7 +119,7 @@ int init_main_loop(options_t* opt, cipher_t* c, auth_algo_t* aa, key_derivation_
log_printf(NOTICE, "enabling anytun 0.2.x crypto compatiblity mode");
ret = key_derivation_init(kd, opt->kd_prf_, opt->ld_kdr_, opt->anytun02_compat_, opt->passphrase_, opt->key_.buf_, opt->key_.length_, opt->salt_.buf_, opt->salt_.length_);
if(ret) {
- log_printf(ERR, "could not initialize key derivation of type %s", opt->kd_prf_);
+ log_printf(ERROR, "could not initialize key derivation of type %s", opt->kd_prf_);
cipher_close(c);
auth_algo_close(aa);
return ret;
@@ -147,7 +147,7 @@ int process_tun_data(tun_device_t* dev, udp_socket_t* sock, options_t* opt, plai
int len = tun_read(dev, plain_packet_get_payload(plain_packet), plain_packet_get_payload_length(plain_packet));
if(len == -1) {
- log_printf(ERR, "error on reading from device: %m");
+ log_printf(ERROR, "error on reading from device: %m");
return 0;
}
@@ -171,7 +171,7 @@ int process_tun_data(tun_device_t* dev, udp_socket_t* sock, options_t* opt, plai
len = udp_write(sock, encrypted_packet_get_packet(encrypted_packet), encrypted_packet_get_length(encrypted_packet));
if(len == -1)
- log_printf(ERR, "error on sending udp packet: %m");
+ log_printf(ERROR, "error on sending udp packet: %m");
return 0;
}
@@ -186,7 +186,7 @@ int process_sock_data(tun_device_t* dev, udp_socket_t* sock, options_t* opt, pla
memset(&remote, 0, sizeof(udp_endpoint_t));
int len = udp_read(sock, encrypted_packet_get_packet(encrypted_packet), encrypted_packet_get_length(encrypted_packet), &remote);
if(len == -1) {
- log_printf(ERR, "error on receiving udp packet: %m");
+ log_printf(ERROR, "error on receiving udp packet: %m");
return 0;
}
else if(len < encrypted_packet_get_header_length()) {
@@ -213,7 +213,7 @@ int process_sock_data(tun_device_t* dev, udp_socket_t* sock, options_t* opt, pla
return 0;
}
else if(result < 0) {
- log_printf(ERR, "memory error at sequence window");
+ log_printf(ERROR, "memory error at sequence window");
return -2;
}
@@ -236,7 +236,7 @@ int process_sock_data(tun_device_t* dev, udp_socket_t* sock, options_t* opt, pla
len = tun_write(dev, plain_packet_get_payload(plain_packet), plain_packet_get_payload_length(plain_packet));
if(len == -1)
- log_printf(ERR, "error on writing to device: %m");
+ log_printf(ERROR, "error on writing to device: %m");
return 0;
}
@@ -272,7 +272,7 @@ int main_loop(tun_device_t* dev, udp_socket_t* sock, options_t* opt)
int ret = select(nfds, &readfds, NULL, NULL, NULL);
if(ret == -1 && errno != EINTR) {
- log_printf(ERR, "select returned with error: %m");
+ log_printf(ERROR, "select returned with error: %m");
return_value = -1;
break;
}
@@ -327,7 +327,8 @@ void print_hex_dump(const u_int8_t* buf, u_int32_t len)
int main(int argc, char* argv[])
{
- log_init("uanytun", DAEMON);
+ log_init();
+ log_add_target("syslog:3,uanytun,daemon");
log_printf(NOTICE, "just started...");
options_t opt;
@@ -336,11 +337,11 @@ int main(int argc, char* argv[])
options_clear(&opt);
if(ret > 0) {
fprintf(stderr, "syntax error near: %s\n\n", argv[ret]);
- log_printf(ERR, "syntax error, exitting");
+ log_printf(ERROR, "syntax error, exitting");
}
if(ret == -2) {
fprintf(stderr, "memory error on options_parse, exitting\n");
- log_printf(ERR, "memory error on options_parse, exitting");
+ log_printf(ERROR, "memory error on options_parse, exitting");
}
if(ret == -1 || ret > 0)
@@ -358,7 +359,7 @@ int main(int argc, char* argv[])
#ifndef USE_SSL_CRYPTO
ret = init_libgcrypt();
if(ret) {
- log_printf(ERR, "error on libgcrpyt initialization, exitting");
+ log_printf(ERROR, "error on libgcrpyt initialization, exitting");
options_clear(&opt);
exit(ret);
}
@@ -368,7 +369,7 @@ int main(int argc, char* argv[])
tun_device_t dev;
ret = tun_init(&dev, opt.dev_name_, opt.dev_type_, opt.ifconfig_param_.net_addr_, opt.ifconfig_param_.prefix_length_);
if(ret) {
- log_printf(ERR, "error on tun_init, exitting");
+ log_printf(ERROR, "error on tun_init, exitting");
options_clear(&opt);
exit(ret);
}
@@ -383,7 +384,7 @@ int main(int argc, char* argv[])
udp_socket_t sock;
ret = udp_init(&sock, opt.local_addr_, opt.local_port_);
if(ret) {
- log_printf(ERR, "error on udp_init, exitting");
+ log_printf(ERROR, "error on udp_init, exitting");
options_clear(&opt);
tun_close(&dev);
exit(ret);
@@ -440,5 +441,7 @@ int main(int argc, char* argv[])
else
log_printf(NOTICE, "shutdown after signal");
+ log_close();
+
return ret;
}
diff --git a/src/udp.c b/src/udp.c
index 933cbeb..23d97af 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -71,7 +71,7 @@ int udp_init(udp_socket_t* sock, const char* local_addr, const char* port)
int errcode = getaddrinfo(local_addr, port, &hints, &res);
if (errcode != 0) {
- log_printf(ERR, "Error resolving local address: %s", gai_strerror(errcode));
+ log_printf(ERROR, "Error resolving local address: %s", gai_strerror(errcode));
udp_close(sock);
return -1;
}
@@ -80,7 +80,7 @@ int udp_init(udp_socket_t* sock, const char* local_addr, const char* port)
sock->fd_ = socket(res->ai_family, SOCK_DGRAM, 0);
if(sock->fd_ < 0) {
- log_printf(ERR, "Error on opening udp socket: %m");
+ log_printf(ERROR, "Error on opening udp socket: %m");
freeaddrinfo(res);
udp_close(sock);
return -1;
@@ -88,7 +88,7 @@ int udp_init(udp_socket_t* sock, const char* local_addr, const char* port)
errcode = bind(sock->fd_, res->ai_addr, res->ai_addrlen);
if(errcode) {
- log_printf(ERR, "Error on binding udp socket: %m");
+ log_printf(ERROR, "Error on binding udp socket: %m");
freeaddrinfo(res);
udp_close(sock);
return -1;
@@ -117,7 +117,7 @@ void udp_set_remote(udp_socket_t* sock, const char* remote_addr, const char* por
int errcode = getaddrinfo(remote_addr, port, &hints, &res);
if (errcode != 0) {
- log_printf(ERR, "Error resolving remote address: %s", gai_strerror(errcode));
+ log_printf(ERROR, "Error resolving remote address: %s", gai_strerror(errcode));
return;
}
memcpy(&(sock->remote_end_), res->ai_addr, sizeof(*(res->ai_addr)));