summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2014-07-13 19:07:26 +0000
committerChristian Pointner <equinox@anytun.org>2014-07-13 19:07:26 +0000
commit1d94af90acccaac5665715f921e72727e3951c22 (patch)
treed3788857d86494e518b356c67ff57c3e64aea878
parentalso use select for writes to unix socket (diff)
only one unix socket for key exchange because seperation of data and control doesn't make sense...
-rw-r--r--src/keyexchange.c37
-rw-r--r--src/keyexchange.h5
-rw-r--r--src/options.c18
-rw-r--r--src/options.h3
-rw-r--r--src/uanytun.c2
5 files changed, 23 insertions, 42 deletions
diff --git a/src/keyexchange.c b/src/keyexchange.c
index 0806ad6..bea600f 100644
--- a/src/keyexchange.c
+++ b/src/keyexchange.c
@@ -55,40 +55,30 @@
#include <errno.h>
#include <string.h>
-int keyexchange_init(keyexchange_t* kx, const char* path_control, const char* path_data)
+int keyexchange_init(keyexchange_t* kx, const char* socket_path)
{
if(!kx)
return -1;
memset(kx->data_buf_, 0, sizeof(kx->data_buf_));
kx->data_buf_len_ = 0;
-// int ret = unixdomain_init(&(kx->control_interface_), path_control);
- int ret = unixdomain_init(&(kx->control_interface_), NULL); // ignore control interface for now
- if(ret) return ret;
-
- ret = unixdomain_init(&(kx->data_interface_), path_data);
- if(ret)
- unixdomain_close(&(kx->control_interface_));
-
- return ret;
+ return unixdomain_init(&(kx->socket_), socket_path);
}
int keyexchange_fill_fd_set(keyexchange_t* kx, fd_set* read, fd_set* write)
{
- int maxfd = unixdomain_fill_fd_set(&(kx->data_interface_), read);
+ int maxfd = unixdomain_fill_fd_set(&(kx->socket_), read);
if(kx->data_buf_len_) {
- FD_SET(kx->data_interface_.client_fd_, write);
- maxfd = (kx->data_interface_.client_fd_ > maxfd) ? kx->data_interface_.client_fd_ : maxfd;
+ FD_SET(kx->socket_.client_fd_, write);
+ maxfd = (kx->socket_.client_fd_ > maxfd) ? kx->socket_.client_fd_ : maxfd;
}
- // ignoring control interface for now
return maxfd;
}
void keyexchange_close(keyexchange_t* kx)
{
- unixdomain_close(&(kx->control_interface_));
- unixdomain_close(&(kx->data_interface_));
+ unixdomain_close(&(kx->socket_));
}
static int keyexchange_handle_accept(keyexchange_t* kx, unixdomain_t* sock)
@@ -107,13 +97,13 @@ static int keyexchange_handle_read_data(keyexchange_t* kx)
{
// TODO: don't overwrite existing data
// fix sizeof
- int len = unixdomain_read(&(kx->data_interface_), kx->data_buf_, sizeof(kx->data_buf_) - 1);
+ int len = unixdomain_read(&(kx->socket_), kx->data_buf_, sizeof(kx->data_buf_) - 1);
if(len <= 0) {
if(!len)
log_printf(INFO, "key exchange: data interface disconnected");
else
log_printf(ERROR, "key exchange: data interface error: %s", strerror(errno));
- kx->data_interface_.client_fd_ = -1;
+ kx->socket_.client_fd_ = -1;
} else {
// TODO: this is a temporary fix for strings ending with linefeed
if(kx->data_buf_[len-1] == '\n')
@@ -130,7 +120,7 @@ static int keyexchange_handle_read_data(keyexchange_t* kx)
static int keyexchange_handle_write_data(keyexchange_t* kx)
{
- int ret = unixdomain_write(&(kx->data_interface_), kx->data_buf_, kx->data_buf_len_);
+ int ret = unixdomain_write(&(kx->socket_), kx->data_buf_, kx->data_buf_len_);
// TODO: handle partial writes
kx->data_buf_len_ = 0;
return ret;
@@ -138,15 +128,14 @@ static int keyexchange_handle_write_data(keyexchange_t* kx)
int keyexchange_handle(keyexchange_t* kx, fd_set* rreadyfds, fd_set* wreadyfds)
{
- if(FD_ISSET(kx->data_interface_.server_fd_, rreadyfds))
- return keyexchange_handle_accept(kx, &(kx->data_interface_));
+ if(FD_ISSET(kx->socket_.server_fd_, rreadyfds))
+ return keyexchange_handle_accept(kx, &(kx->socket_));
- if(FD_ISSET(kx->data_interface_.client_fd_, rreadyfds))
+ if(FD_ISSET(kx->socket_.client_fd_, rreadyfds))
return keyexchange_handle_read_data(kx);
- if(FD_ISSET(kx->data_interface_.client_fd_, wreadyfds))
+ if(FD_ISSET(kx->socket_.client_fd_, wreadyfds))
return keyexchange_handle_write_data(kx);
- // control interface for now
return 0;
}
diff --git a/src/keyexchange.h b/src/keyexchange.h
index 615eb6d..548634c 100644
--- a/src/keyexchange.h
+++ b/src/keyexchange.h
@@ -54,12 +54,11 @@
struct keyexchange_struct {
u_int8_t data_buf_[2048]; // TODO: constant...
u_int32_t data_buf_len_;
- unixdomain_t data_interface_;
- unixdomain_t control_interface_;
+ unixdomain_t socket_;
};
typedef struct keyexchange_struct keyexchange_t;
-int keyexchange_init(keyexchange_t* kx, const char* path_control, const char* path_data);
+int keyexchange_init(keyexchange_t* kx, const char* socket_path);
int keyexchange_fill_fd_set(keyexchange_t* kx, fd_set* read, fd_set* write);
void keyexchange_close(keyexchange_t* kx);
diff --git a/src/options.c b/src/options.c
index 26b9cb7..43349c4 100644
--- a/src/options.c
+++ b/src/options.c
@@ -281,8 +281,7 @@ int options_parse(options_t* opt, int argc, char* argv[])
PARSE_STRING_PARAM("-c","--cipher", opt->cipher_)
PARSE_STRING_PARAM("-a","--auth-algo", opt->auth_algo_)
PARSE_INT_PARAM("-b","--auth-tag-length", opt->auth_tag_length_)
- PARSE_STRING_PARAM("-z","--kx-control", opt->kx_control_interface_)
- PARSE_STRING_PARAM("-Z","--kx-data", opt->kx_data_interface_)
+ PARSE_STRING_PARAM("-z","--kx-socket", opt->kx_socket_)
#endif
else
return i;
@@ -380,8 +379,7 @@ void options_default(options_t* opt)
opt->cipher_ = strdup("aes-ctr");
opt->auth_algo_ = strdup("sha1");
opt->auth_tag_length_ = 10;
- opt->kx_control_interface_ = NULL;
- opt->kx_data_interface_ = NULL;
+ opt->kx_socket_ = NULL;
#else
opt->cipher_ = strdup("null");
opt->auth_tag_length_ = 0;
@@ -433,10 +431,8 @@ void options_clear(options_t* opt)
free(opt->kd_prf_);
if(opt->passphrase_)
free(opt->passphrase_);
- if(opt->kx_control_interface_)
- free(opt->kx_control_interface_);
- if(opt->kx_data_interface_)
- free(opt->kx_data_interface_);
+ if(opt->kx_socket_)
+ free(opt->kx_socket_);
#endif
if(opt->key_.buf_)
free(opt->key_.buf_);
@@ -483,8 +479,7 @@ void options_print_usage()
printf(" [-c|--cipher] <cipher type> payload encryption algorithm\n");
printf(" [-a|--auth-algo] <algo type> message authentication algorithm\n");
printf(" [-b|--auth-tag-length] <length> length of the auth tag\n");
- printf(" [-z|--kx-control] <path> path to the key exchange control socket\n");
- printf(" [-Z|--kx-data] <path> path to the key exchange data socket\n");
+ printf(" [-z|--kx-socket] <path> path to the key exchange control socket\n");
#endif
}
@@ -541,8 +536,7 @@ void options_print(options_t* opt)
case ROLE_RIGHT: printf("right\n"); break;
default: printf("??\n"); break;
}
- printf(" kx_control: '%s'\n", opt->kx_control_interface_);
- printf(" kx_data: '%s'\n", opt->kx_data_interface_);
+ printf(" kx_socket: '%s'\n", opt->kx_socket_);
#endif
u_int32_t i;
diff --git a/src/options.h b/src/options.h
index a8fa6bf..3941ebe 100644
--- a/src/options.h
+++ b/src/options.h
@@ -90,8 +90,7 @@ struct options_struct {
char* auth_algo_;
char* passphrase_;
role_t role_;
- char* kx_control_interface_;
- char* kx_data_interface_;
+ char* kx_socket_;
#endif
u_int32_t auth_tag_length_;
buffer_t key_;
diff --git a/src/uanytun.c b/src/uanytun.c
index e7d7de7..a66b43f 100644
--- a/src/uanytun.c
+++ b/src/uanytun.c
@@ -81,7 +81,7 @@ typedef u_int8_t auth_algo_t;
int init_main_loop(options_t* opt, keyexchange_t* kx, cipher_t* c, auth_algo_t* aa, key_derivation_t* kd, seq_win_t* seq_win)
{
- int ret = keyexchange_init(kx, opt->kx_control_interface_, opt->kx_data_interface_);
+ int ret = keyexchange_init(kx, opt->kx_socket_);
if(ret) {
log_printf(ERROR, "could not initialize key exchange interface");
return ret;