diff options
-rw-r--r-- | README | 31 | ||||
-rw-r--r-- | src/linux/tun.c | 24 | ||||
-rw-r--r-- | src/options.c | 29 | ||||
-rw-r--r-- | src/uanytun.c | 14 |
4 files changed, 54 insertions, 44 deletions
@@ -7,6 +7,15 @@ Linux build-essential libgcrypt11-dev + +OpenBSD +------- + +libgcrypt +libgpg-error +gmake + + Installation ============ @@ -21,21 +30,9 @@ Building from source # ./configure # make +Notes: + - on OpenBSD you have to use gmake instead of make + - currently there is no support for using IPv6 as + outer Protocol because OpenBSD does not support + V4-Mapped adresses - -Errors: -------- - -Note: Cannot open TUN/TAP dev /dev/net/tun: No such file or directory (errno=2) -Cannot open TUN/TAP dev /dev/anytun0: No such file or directory (errno=2) - -Solution: Enabling tun/tap device ------------------------------------- - -modprobe tun -cd /dev -./MAKEDEV tun - -edit /etc/modules and add the line -tun -to load the module automatically diff --git a/src/linux/tun.c b/src/linux/tun.c index da623ae..a6d0d4b 100644 --- a/src/linux/tun.c +++ b/src/linux/tun.c @@ -62,16 +62,12 @@ void tun_init(tun_device_t** dev, const char* dev_name, const char* dev_type, co return; tun_conf(*dev, dev_name, dev_type, ifcfg_lp, ifcfg_rnmp, 1400); + (*dev)->actual_name_ = NULL; (*dev)->fd_ = open(DEFAULT_DEVICE, O_RDWR); if((*dev)->fd_ < 0) { log_printf(ERR, "can't open device file (%s): %m", DEFAULT_DEVICE); - if((*dev)->local_) - free((*dev)->local_); - if((*dev)->remote_netmask_) - free((*dev)->remote_netmask_); - free(*dev); - *dev = NULL; + tun_close(dev); return; } @@ -88,12 +84,7 @@ void tun_init(tun_device_t** dev, const char* dev_name, const char* dev_type, co } else { log_printf(ERR, "unable to recognize type of device (tun or tap)"); - if((*dev)->local_) - free((*dev)->local_); - if((*dev)->remote_netmask_) - free((*dev)->remote_netmask_); - free(*dev); - *dev = NULL; + tun_close(dev); return; } @@ -106,8 +97,13 @@ void tun_init(tun_device_t** dev, const char* dev_name, const char* dev_type, co (*dev)->actual_name_ = strdup(ifr.ifr_name); } else { log_printf(ERR, "tun/tap device ioctl failed: %m"); - free(*dev); - *dev = NULL; + tun_close(dev); + return; + } + + if(!(*dev)->actual_name_) { + log_printf(ERR, "can't open device file: memory error"); + tun_close(dev); return; } diff --git a/src/options.c b/src/options.c index 79f60e8..c329ee8 100644 --- a/src/options.c +++ b/src/options.c @@ -52,7 +52,7 @@ else if(!strcmp(str,SHORT) || !strcmp(str,LONG)) \ { \ if(argc < 1 || argv[i+1][0] == '-') \ - return -1; \ + return i; \ VALUE = atoi(argv[i+1]); \ argc--; \ i++; \ @@ -62,9 +62,11 @@ else if(!strcmp(str,SHORT) || !strcmp(str,LONG)) \ { \ if(argc < 1 || argv[i+1][0] == '-') \ - return -1; \ + return i; \ if(VALUE) free(VALUE); \ VALUE = strdup(argv[i+1]); \ + if(!VALUE) \ + return -2; \ argc--; \ i++; \ } @@ -74,11 +76,15 @@ { \ if(argc < 2 || \ argv[i+1][0] == '-' || argv[i+2][0] == '-') \ - return -1; \ + return i; \ if(VALUE1) free(VALUE1); \ VALUE1 = strdup(argv[i+1]); \ + if(!VALUE1) \ + return -2; \ if(VALUE2) free(VALUE2); \ VALUE2 = strdup(argv[i+2]); \ + if(!VALUE2) \ + return -2; \ argc-=2; \ i+=2; \ } @@ -87,10 +93,11 @@ else if(!strcmp(str,SHORT) || !strcmp(str,LONG)) \ { \ if(argc < 1 || argv[i+1][0] == '-') \ - return -1; \ + return i; \ if(VALUE.buf_) free(VALUE.buf_); \ VALUE = options_parse_hex_string(argv[i+1]); \ - if(!VALUE.buf_) return -1; \ + if(!VALUE.buf_) \ + return -2; \ size_t j; \ for(j=0; j < strlen(argv[i+1]); ++j) \ argv[i+1][j] = '#'; \ @@ -106,7 +113,8 @@ buffer_t options_parse_hex_string(const char* hex) buffer.length_ = 0; buffer.buf_ = NULL; - if(hex_len%2) return buffer; + if(hex_len%2) + return buffer; buffer.length_ = hex_len/2; buffer.buf_ = malloc(buffer.length_); @@ -133,13 +141,16 @@ int options_parse(options_t** opt, int argc, char* argv[]) *opt = malloc(sizeof(options_t)); if(!*opt) - return -1; + return -2; options_default(*opt); if((*opt)->progname_) free((*opt)->progname_); (*opt)->progname_ = strdup(argv[0]); + if(!(*opt)->progname_) + return -2; + argc--; int i; @@ -149,7 +160,7 @@ int options_parse(options_t** opt, int argc, char* argv[]) argc--; if(!strcmp(str,"-h") || !strcmp(str,"--help")) - return 1; + return -1; PARSE_INVERSE_BOOL_PARAM("-D","--nodaemonize", (*opt)->daemonize_) PARSE_BOOL_PARAM("-C","--chroot", (*opt)->chroot_) PARSE_STRING_PARAM("-u","--username", (*opt)->username_) @@ -172,7 +183,7 @@ int options_parse(options_t** opt, int argc, char* argv[]) PARSE_HEXSTRING_PARAM_SEC("-K","--key", (*opt)->key_) PARSE_HEXSTRING_PARAM_SEC("-A","--salt", (*opt)->salt_) else - return -1; + return i; } if(!strcmp((*opt)->cipher_, "null") && !strcmp((*opt)->auth_algo_, "null")) { diff --git a/src/uanytun.c b/src/uanytun.c index fa2a207..7c49934 100644 --- a/src/uanytun.c +++ b/src/uanytun.c @@ -179,16 +179,22 @@ int main(int argc, char* argv[]) log_init("uanytun", DAEMON); signal_init(); - log_printf(NOTICE, "just started..."); - options_t* opt; int ret = options_parse(&opt, argc, argv); if(ret) { - options_print_usage(); - log_printf(ERR, "error on options_parse, exitting"); + options_clear(&opt); + if(ret > 0) + fprintf(stderr, "syntax error near: %s\n\n", argv[ret]); + if(ret == -2) + fprintf(stderr, "memory error on options_parse, exitting\n"); + + if(ret == -1 || ret > 0) + options_print_usage(); + exit(ret); } + log_printf(NOTICE, "just started..."); tun_device_t* dev; tun_init(&dev, opt->dev_name_, opt->dev_type_, opt->ifconfig_param_local_, opt->ifconfig_param_remote_netmask_); |