summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2008-12-28 13:15:53 +0000
committerChristian Pointner <equinox@anytun.org>2008-12-28 13:15:53 +0000
commit8094722a717c708f7e8b684b3fd45612f8649b5d (patch)
treee7b541c68658f242acbe6e3094ec2edcd83b9c80
parentsome cleanup (diff)
added options parser
-rw-r--r--src/Makefile4
-rw-r--r--src/options.c193
-rw-r--r--src/options.h75
-rw-r--r--src/uanytun.c10
4 files changed, 282 insertions, 0 deletions
diff --git a/src/Makefile b/src/Makefile
index d2461ad..de8a6bb 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -47,6 +47,7 @@ endif
OBJS = log.o \
signal.o \
+ options.o \
tun.o \
udp.o \
plain_packet.o \
@@ -69,6 +70,9 @@ log.o: log.c log.h
signal.o: signal.c signal.h
$(CC) $(CCFLAGS) $< -c
+options.o: options.c options.h
+ $(CC) $(CCFLAGS) $< -c
+
tun.o: tun.c tun.h
$(CC) $(CCFLAGS) $< -c
diff --git a/src/options.c b/src/options.c
new file mode 100644
index 0000000..11987b4
--- /dev/null
+++ b/src/options.c
@@ -0,0 +1,193 @@
+/*
+ * ľAnytun
+ *
+ * ľAnytun is a tiny implementation of SATP. Unlike Anytun which is a full
+ * featured implementation ľAnytun 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 ľAnytun.
+ *
+ * ľAnytun 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.
+ *
+ * ľAnytun 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 ľAnytun. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "datatypes.h"
+
+#include "options.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+int options_parse(options_t** opt, int argc, char* argv[])
+{
+ if(!opt)
+ return -1;
+
+ *opt = malloc(sizeof(options_t));
+ options_default(*opt);
+
+ return 0;
+}
+
+void options_default(options_t* opt)
+{
+ if(!opt)
+ return;
+
+ opt->progname_ = strdup("uanytun");
+ opt->daemonize_ = 1;
+ opt->chroot_ = 0;
+ opt->username_ = strdup("nobody");
+ opt->chroot_dir_ = strdup("/var/run/uanytun");
+ opt->pid_file_ = NULL;
+ opt->sender_id_ = 0;
+ opt->local_addr_ = NULL;
+ opt->local_port_ = strdup("4444");
+ opt->remote_addr_ = NULL;
+ opt->remote_port_ = strdup("4444");
+ opt->dev_name_ = NULL;
+ opt->dev_type_ = NULL;
+ opt->ifconfig_param_local_ = NULL;
+ opt->ifconfig_param_remote_netmask_ = NULL;
+ opt->post_up_script_ = NULL;
+ opt->seq_window_size_ = 100;
+ opt->cipher_ = strdup("aes-ctr");
+ opt->kd_prf_ = strdup("aes-ctr");
+ opt->auth_algo_ = strdup("sha1");
+ opt->mux_ = 0;
+ opt->key_ = NULL;
+ opt->key_length_ = 0;
+ opt->salt_ = NULL;
+ opt->salt_length_ = 0;
+}
+
+void options_clear(options_t** opt)
+{
+ if(!opt || !(*opt))
+ return;
+
+ if((*opt)->progname_)
+ free((*opt)->progname_);
+ if((*opt)->username_)
+ free((*opt)->username_);
+ if((*opt)->chroot_dir_)
+ free((*opt)->chroot_dir_);
+ if((*opt)->pid_file_)
+ free((*opt)->pid_file_);
+ if((*opt)->local_addr_)
+ free((*opt)->local_addr_);
+ if((*opt)->local_port_)
+ free((*opt)->local_port_);
+ if((*opt)->remote_addr_)
+ free((*opt)->remote_addr_);
+ if((*opt)->remote_port_)
+ free((*opt)->remote_port_);
+ if((*opt)->dev_name_)
+ free((*opt)->dev_name_);
+ if((*opt)->dev_type_)
+ free((*opt)->dev_type_);
+ if((*opt)->ifconfig_param_local_)
+ free((*opt)->ifconfig_param_local_);
+ if((*opt)->ifconfig_param_remote_netmask_)
+ free((*opt)->ifconfig_param_remote_netmask_);
+ if((*opt)->post_up_script_)
+ free((*opt)->post_up_script_);
+ if((*opt)->cipher_)
+ free((*opt)->cipher_);
+ if((*opt)->kd_prf_)
+ free((*opt)->kd_prf_);
+ if((*opt)->auth_algo_)
+ free((*opt)->auth_algo_);
+ if((*opt)->key_)
+ free((*opt)->key_);
+ if((*opt)->salt_)
+ free((*opt)->salt_);
+
+ free(*opt);
+ *opt = NULL;
+}
+
+void options_print_usage()
+{
+ printf("USAGE:\n");
+ printf("uanytun [-h|--help] prints this...\n");
+// printf(" [-f|--config] <file> the config file\n");
+ printf(" [-D|--nodaemonize] don't run in background\n");
+ printf(" [-C|--chroot] chroot and drop privileges\n");
+ printf(" [-u|--username] <username> if chroot change to this user\n");
+ printf(" [-H|--chroot-dir] <path> chroot to this directory\n");
+ printf(" [-P|--write-pid] <path> write pid to this file\n");
+ printf(" [-i|--interface] <ip-address> local ip address to bind to\n");
+ printf(" [-p|--port] <port> local port to bind to\n");
+ printf(" [-r|--remote-host] <hostname|ip> remote host\n");
+ printf(" [-o|--remote-port] <port> remote port\n");
+ printf(" [-d|--dev] <name> device name\n");
+ printf(" [-t|--type] <tun|tap> device type\n");
+ printf(" [-n|--ifconfig] <local> the local address for the tun/tap device\n");
+ printf(" <remote|netmask> the remote address(tun) or netmask(tap)\n");
+ printf(" [-x|--post-up-script] <script> script gets called after interface is created\n");
+ printf(" [-s|--sender-id ] <sender id> the sender id to use\n");
+ printf(" [-w|--window-size] <window size> seqence number window size\n");
+ printf(" [-m|--mux] <mux-id> the multiplex id to use\n");
+ printf(" [-c|--cipher] <cipher type> payload encryption algorithm\n");
+ printf(" [-a|--auth-algo] <algo type> message authentication algorithm\n");
+// printf(" [-k|--kd-prf] <kd-prf type> key derivation pseudo random function\n");
+// printf(" [-K|--key] <master key> master key to use for encryption\n");
+// printf(" [-A|--salt] <master salt> master salt to use for encryption\n");
+}
+
+void options_print(options_t* opt)
+{
+ printf("progname: '%s'\n", opt->progname_);
+ printf("daemonize: %d\n", opt->daemonize_);
+ printf("chroot: %d\n", opt->chroot_);
+ printf("username: '%s'\n", opt->username_);
+ printf("chroot_dir: '%s'\n", opt->chroot_dir_);
+ printf("pid_file: '%s'\n", opt->pid_file_);
+ printf("local_addr: '%s'\n", opt->local_addr_);
+ printf("local_port: '%s'\n", opt->local_port_);
+ printf("remote_addr: '%s'\n", opt->remote_addr_);
+ printf("remote_port: '%s'\n", opt->remote_port_);
+ printf("dev_name: '%s'\n", opt->dev_name_);
+ printf("dev_type: '%s'\n", opt->dev_type_);
+ printf("ifconfig_local: '%s'\n", opt->ifconfig_param_local_);
+ printf("ifconfig_remote_netmask: '%s'\n", opt->ifconfig_param_remote_netmask_);
+ printf("post_up_script: '%s'\n", opt->post_up_script_);
+ printf("sender_id: %d\n", opt->sender_id_);
+ printf("mux: %d\n", opt->mux_);
+ printf("seq_window_size: %d\n", opt->seq_window_size_);
+ printf("cipher: '%s'\n", opt->cipher_);
+ printf("auth_algo: '%s'\n", opt->auth_algo_);
+ printf("kd_prf: '%s'\n", opt->kd_prf_);
+
+ u_int32_t i;
+ printf("key_[%d]: '", opt->key_length_);
+ for(i=0; i<opt->key_length_; ++i) printf("%02X", opt->key_[i]);
+ printf("'\n");
+
+ printf("salt_[%d]: '", opt->salt_length_);
+ for(i=0; i<opt->salt_length_; ++i) printf("%02X", opt->salt_[i]);
+ printf("'\n");
+}
diff --git a/src/options.h b/src/options.h
new file mode 100644
index 0000000..bc0f296
--- /dev/null
+++ b/src/options.h
@@ -0,0 +1,75 @@
+/*
+ * ľAnytun
+ *
+ * ľAnytun is a tiny implementation of SATP. Unlike Anytun which is a full
+ * featured implementation ľAnytun 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 ľAnytun.
+ *
+ * ľAnytun 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.
+ *
+ * ľAnytun 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 ľAnytun. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _OPTIONS_H_
+#define _OPTIONS_H_
+
+struct options_struct {
+ char* progname_;
+ int daemonize_;
+ int chroot_;
+ char* username_;
+ char* chroot_dir_;
+ char* pid_file_;
+ sender_id_t sender_id_;
+ char* local_addr_;
+ char* local_port_;
+ char* remote_addr_;
+ char* remote_port_;
+ char* dev_name_;
+ char* dev_type_;
+ char* ifconfig_param_local_;
+ char* ifconfig_param_remote_netmask_;
+ char* post_up_script_;
+ window_size_t seq_window_size_;
+ char* cipher_;
+ char* kd_prf_;
+ char* auth_algo_;
+ mux_t mux_;
+ u_int8_t* key_;
+ u_int32_t key_length_;
+ u_int8_t* salt_;
+ u_int32_t salt_length_;
+};
+typedef struct options_struct options_t;
+
+int options_parse(options_t** opt, int argc, char* argv[]);
+void options_default(options_t* opt);
+void options_clear(options_t** opt);
+void options_print_usage();
+void options_print(options_t* opt);
+
+
+#endif
+
diff --git a/src/uanytun.c b/src/uanytun.c
index c302764..68df6b6 100644
--- a/src/uanytun.c
+++ b/src/uanytun.c
@@ -40,6 +40,8 @@
#include "log.h"
#include "signal.h"
+#include "options.h"
+
#include "tun.h"
#include "udp.h"
@@ -111,6 +113,13 @@ int main(int argc, char* argv[])
log_init("uanytun", DAEMON);
signal_init();
+ options_t* opt;
+ int ret = options_parse(&opt, argc, argv);
+ if(ret)
+ exit(ret);
+
+ options_print(opt);
+
// chrootAndDrop("/var/run/", "nobody");
// daemonize();
// log_printf(INFO, "running in background now");
@@ -144,6 +153,7 @@ int main(int argc, char* argv[])
/* tun_close(&dev); */
/* udp_close(&sock); */
+ options_clear(&opt);
return 0;
}