From 8094722a717c708f7e8b684b3fd45612f8649b5d Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 28 Dec 2008 13:15:53 +0000 Subject: added options parser --- src/Makefile | 4 ++ src/options.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/options.h | 75 +++++++++++++++++++++++ src/uanytun.c | 10 +++ 4 files changed, 282 insertions(+) create mode 100644 src/options.c create mode 100644 src/options.h 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 + * + * 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 . + */ + +#include "datatypes.h" + +#include "options.h" + +#include +#include +#include + +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] the config file\n"); + printf(" [-D|--nodaemonize] don't run in background\n"); + printf(" [-C|--chroot] chroot and drop privileges\n"); + printf(" [-u|--username] if chroot change to this user\n"); + printf(" [-H|--chroot-dir] chroot to this directory\n"); + printf(" [-P|--write-pid] write pid to this file\n"); + printf(" [-i|--interface] local ip address to bind to\n"); + printf(" [-p|--port] local port to bind to\n"); + printf(" [-r|--remote-host] remote host\n"); + printf(" [-o|--remote-port] remote port\n"); + printf(" [-d|--dev] device name\n"); + printf(" [-t|--type] device type\n"); + printf(" [-n|--ifconfig] the local address for the tun/tap device\n"); + printf(" the remote address(tun) or netmask(tap)\n"); + printf(" [-x|--post-up-script]