diff -Nru 6tunnel-0.11rc2/6tunnel.1 6tunnel-0.12/6tunnel.1 --- 6tunnel-0.11rc2/6tunnel.1 2005-08-18 16:52:15.000000000 +0000 +++ 6tunnel-0.12/6tunnel.1 2016-10-24 20:42:34.000000000 +0000 @@ -1,8 +1,8 @@ .\" -.\" 6tunnel v0.11 -.\" (C) Copyright 2000-2005 by Wojtek Kaniewski +.\" 6tunnel v0.12 +.\" (C) Copyright 2000-2005,2013,2016 by Wojtek Kaniewski .\" -.TH 6TUNNEL 1 "Aug 18, 2005" +.TH 6TUNNEL 1 "Oct 22, 2016" .SH NAME 6tunnel \- tunnelling for application that don't speak IPv6 .SH SYNOPSIS @@ -76,7 +76,7 @@ .B 6tunnel will use the IPv4 one. In other cases, use .B \-4 -parameter which makes IPv4 address the preffered one. For IPv6-to-any tunnels +parameter which makes IPv4 address the preferred one. For IPv6-to-any tunnels use .B \-6 which makes @@ -88,7 +88,7 @@ Exit after first connection. .TP .B \-4 -Preffer IPv4 endpoint if the machine has both address types. +Prefer IPv4 endpoint if the machine has both address types. .TP .B \-6 Listen on IPv6 address (IPv4 is default). @@ -100,8 +100,7 @@ Force tunneling even if remote host is not resolvable at the execution time. .TP .B \-h -Print hex dump of every packet received or sent (hu-huh, Beavis, he said -hex dump!) +Print hex dump of every packet received or sent. .TP .BI \-u "\ " username Change UID and GID after bind(). @@ -147,6 +146,15 @@ .TP .B \-v Be verbose and don't detach. +.SH NOTES +Option +.B \-H +to disable all resolver hints has been removed since proper combination +of +.B \-4 +and +.B \-6 +will yield in any combination of IPv4 and IPv6 sources and destinations. .SH SIGNALS Sending SIGHUP forces map file reload. .SH THANKS @@ -158,6 +166,7 @@ .SH AUTHORS Wojtek Kaniewski (wojtekka@toxygen.net), Dariusz Jackowski (ascent@linux.pl), -Ramunas Lukosevicus (lukoramu@parok.lt) +Ramunas Lukosevicus (lukoramu@parok.lt), +Roland Stigge (stigge@antcom.de) .SH "SEE ALSO" .BR ssh (1) diff -Nru 6tunnel-0.11rc2/6tunnel.c 6tunnel-0.12/6tunnel.c --- 6tunnel-0.11rc2/6tunnel.c 2005-08-18 17:02:50.000000000 +0000 +++ 6tunnel-0.12/6tunnel.c 2016-10-24 20:42:34.000000000 +0000 @@ -1,10 +1,11 @@ /* - * 6tunnel v0.11 - * (C) Copyright 2000-2005 by Wojtek Kaniewski + * 6tunnel v0.12 + * (C) Copyright 2000-2005,2013,2016 by Wojtek Kaniewski * * Contributions by: * - Dariusz Jackowski * - Ramunas Lukosevicius + * - Roland Stigge * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 2 as @@ -43,26 +44,30 @@ } while(0) int verbose = 0, conn_count = 0; -int remote_port, verbose, hint = AF_INET6, hexdump = 0; -char *remote_host, *ircpass = NULL; -char *ircsendpass = NULL, remote[128]; +int remote_port, verbose, hexdump = 0; +int remote_hint[2] = { AF_INET6, AF_INET }; +int local_hint = AF_INET; +char *remote_host, *irc_pass = NULL; +char *irc_send_pass = NULL; char *pid_file = NULL; const char *source_host; -typedef struct map { +typedef struct source_map { char *ipv4; char *ipv6; - struct map *next; -} map_t; + struct source_map *next; +} source_map_t; -map_t *map_list = NULL; -char *map_file = NULL; +source_map_t *source_map = NULL; +char *source_map_file = NULL; char *xmalloc(int size) { char *tmp; - if (!(tmp = malloc(size))) { + tmp = malloc(size); + + if (tmp == NULL) { perror("malloc"); exit(1); } @@ -74,7 +79,9 @@ { char *tmp; - if (!(tmp = realloc(ptr, size))) { + tmp = realloc(ptr, size); + + if (tmp == NULL) { perror("realloc"); exit(1); } @@ -86,7 +93,9 @@ { char *tmp; - if (!(tmp = strdup(str))) { + tmp = strdup(str); + + if (tmp == NULL) { perror("strdup"); exit(1); } @@ -94,23 +103,57 @@ return tmp; } -struct sockaddr *resolve_host(const char *name, int hint) +char *xntop(const struct sockaddr *sa) { - struct addrinfo *ai = NULL, hints; + char *tmp = NULL; + + if (sa->sa_family == AF_INET) + { + struct sockaddr_in *sin = (struct sockaddr_in*) sa; + + tmp = xmalloc(INET_ADDRSTRLEN); + + if (inet_ntop(sa->sa_family, &sin->sin_addr, tmp, INET_ADDRSTRLEN) == NULL) + { + free(tmp); + tmp = NULL; + } + } + else if (sa->sa_family == AF_INET6) + { + struct sockaddr_in6 *sin6 = (struct sockaddr_in6*) sa; + tmp = xmalloc(INET6_ADDRSTRLEN); + + if (inet_ntop(sa->sa_family, &sin6->sin6_addr, tmp, INET6_ADDRSTRLEN) == NULL) + { + free(tmp); + tmp = NULL; + } + } + + return tmp; +} + +struct addrinfo *resolve_host(const char *name, int port, int hint) +{ + struct addrinfo *result = NULL; + struct addrinfo hints; + char port_str[16]; + int rc; + + snprintf(port_str, sizeof(port_str), "%u", port); memset(&hints, 0, sizeof(hints)); hints.ai_family = hint; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = (name == NULL && port != 0) ? AI_PASSIVE : 0; - if (!getaddrinfo(name, NULL, &hints, &ai) && ai) { - char *tmp; - - tmp = xmalloc(ai->ai_addrlen); - memcpy(tmp, ai->ai_addr, ai->ai_addrlen); + rc = getaddrinfo(name, (port != 0) ? port_str : NULL, &hints, &result); - freeaddrinfo(ai); + if (rc == 0) + return result; - return (struct sockaddr*) tmp; - } + debug("resolver %s port %d hint %d failed: %s\n", name, port, hint, gai_strerror(rc)); return NULL; } @@ -145,33 +188,39 @@ } } -const char *map_find(const char *ipv4) +const char *source_map_find(const char *ipv4) { - map_t *m; + source_map_t *m; - for (m = map_list; m; m = m->next) { - if (!strcmp(m->ipv4, ipv4)) + for (m = source_map; m != NULL; m = m->next) { + if (strcmp(m->ipv4, ipv4) == 0) return m->ipv6; } - for (m = map_list; m; m = m->next) { - if (!strcmp(m->ipv4, "0.0.0.0") || !strcmp(m->ipv4, "default")) + for (m = source_map; m != NULL; m = m->next) { + if ((strcmp(m->ipv4, "0.0.0.0") == 0) || (strcmp(m->ipv4, "default") == 0)) return m->ipv6; } return source_host; } -void make_tunnel(int rsock, const char *remote) +void make_tunnel(int rsock, const char *client_addr) { char buf[4096], *outbuf = NULL, *inbuf = NULL; int sock = -1, outlen = 0, inlen = 0; struct sockaddr *sa = NULL; const char *source; + struct addrinfo *connect_ai = NULL; + struct addrinfo *bind_ai = NULL; + struct addrinfo *ai_ptr; + int source_hint; + + if (source_map != NULL) { + source = source_map_find(client_addr); - if (map_list) { - if (!(source = map_find(remote))) { - debug("<%d> connection from unmapped address (%s), disconnecting\n", rsock, remote); + if (source == NULL) { + debug("<%d> connection from unmapped address (%s), disconnecting\n", rsock, client_addr); goto cleanup; } @@ -179,7 +228,7 @@ } else source = source_host; - if (ircpass) { + if (irc_pass != NULL) { int i, ret; for (i = 0; i < sizeof(buf) - 1; i++) { @@ -194,75 +243,103 @@ if (i > 0 && buf[i - 1] == '\r') buf[i - 1] = 0; - if (i == 4095 || strncasecmp(buf, "PASS ", 5)) { + if (i == 4095 || strncasecmp(buf, "PASS ", 5) != 0) { char *tmp; debug("<%d> irc proxy auth failed - junk\n", rsock); tmp = "ERROR :Closing link: Make your client send password first\r\n"; - write(rsock, tmp, strlen(tmp)); - + if (write(rsock, tmp, strlen(tmp)) != strlen(tmp)) { + // Do nothing. We're failing anyway. + } + goto cleanup; } - if (strcmp(buf + 5, ircpass)) { + if (strcmp(buf + 5, irc_pass) != 0) { char *tmp; debug("<%d> irc proxy auth failed - password incorrect\n", rsock); tmp = ":6tunnel 464 * :Password incorrect\r\nERROR :Closing link: Password incorrect\r\n"; - write(rsock, tmp, strlen(tmp)); + if (write(rsock, tmp, strlen(tmp)) != strlen(tmp)) { + // Do nothing. We're failing anyway. + } goto cleanup; } - debug("<%d> irc proxy auth succeded\n", rsock); - } - - if (!(sa = resolve_host(remote_host, hint))) { - debug("<%d> unable to resolve %s\n", rsock, remote_host); - goto cleanup; + debug("<%d> irc proxy auth succeeded\n", rsock); } - if ((sock = socket(sa->sa_family, SOCK_STREAM, 0)) == -1) { - debug("<%d> unable to create socket (%s)\n", rsock, strerror(errno)); - goto cleanup; - } + connect_ai = resolve_host(remote_host, remote_port, remote_hint[0]); - free(sa); - sa = NULL; + if (connect_ai == NULL) { + connect_ai = resolve_host(remote_host, remote_port, remote_hint[1]); - if (source) { - if (!(sa = resolve_host(source, hint))) { - debug("<%d> unable to resolve source host (%s)\n", rsock, source); + if (connect_ai == NULL) { + debug("<%d> unable to resolve %s,%d\n", rsock, remote_host, remote_port); goto cleanup; } - if (bind(sock, sa, (hint == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))) { - debug("<%d> unable to bind to source host (%s)\n", rsock, source); + source_hint = remote_hint[1]; + } else { + source_hint = remote_hint[0]; + } + + for (ai_ptr = connect_ai; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { + sock = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, 0); + + if (sock == -1) { + if (ai_ptr->ai_next != NULL) + continue; + debug("<%d> unable to create socket (%s)\n", rsock, strerror(errno)); goto cleanup; } - free(sa); - sa = NULL; - } + if (source != NULL) + { + bind_ai = resolve_host(source, 0, source_hint); + + if (bind_ai == NULL) { + debug("<%d> unable to resolve source host (%s)\n", rsock, (source != NULL) ? source : "default"); + goto cleanup; + } - sa = resolve_host(remote_host, hint); + if (bind(sock, bind_ai->ai_addr, bind_ai->ai_addrlen) == -1) { + if (ai_ptr->ai_next != NULL) { + close(sock); + sock = -1; + continue; + } + debug("<%d> unable to bind to source host (%s)\n", rsock, (source != NULL) ? source : "default"); + goto cleanup; + } - ((struct sockaddr_in*) sa)->sin_port = htons(remote_port); + freeaddrinfo(bind_ai); + bind_ai = NULL; + } + + if (connect(sock, ai_ptr->ai_addr, ai_ptr->ai_addrlen) != -1) + break; - if (connect(sock, sa, (sa->sa_family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))) { - debug("<%d> connection refused (%s,%d)\n", rsock, remote_host, remote_port); - goto cleanup; + if (ai_ptr->ai_next == NULL) { + debug("<%d> connection failed (%s,%d)\n", rsock, remote_host, remote_port); + goto cleanup; + } + + close(sock); + sock = -1; } - free(sa); - sa = NULL; + freeaddrinfo(connect_ai); + connect_ai = NULL; debug("<%d> connected to %s,%d\n", rsock, remote_host, remote_port); - if (ircsendpass) { - snprintf(buf, 4096, "PASS %s\r\n", ircsendpass); - write(sock, buf, strlen(buf)); + if (irc_send_pass != NULL) { + snprintf(buf, sizeof(buf), "PASS %s\r\n", irc_send_pass); + if (write(sock, buf, strlen(buf)) != strlen(buf)) + goto cleanup; } for (;;) { @@ -314,7 +391,7 @@ } if (FD_ISSET(sock, &rds)) { - if ((ret = read(sock, buf, 4096)) < 1) + if ((ret = read(sock, buf, sizeof(buf))) < 1) goto cleanup; if (hexdump) { @@ -335,7 +412,7 @@ } if (FD_ISSET(rsock, &rds)) { - if ((ret = read(rsock, buf, 4096)) < 1) + if ((ret = read(rsock, buf, sizeof(buf))) < 1) goto cleanup; if (hexdump) { @@ -356,10 +433,12 @@ } } - cleanup: - if (sa) - free(sa); + if (connect_ai != NULL) + freeaddrinfo(connect_ai); + + if (bind_ai != NULL) + freeaddrinfo(bind_ai); close(rsock); @@ -375,16 +454,16 @@ " [-I pass] [-L limit] [-A filename] [-p pidfile]\n" " [-m mapfile] localport remotehost [remoteport]\n" "\n" -" -1 allow only one connection and quit\n" -" -4 preffer IPv4 endpoints\n" -" -6 bind to IPv6 address\n" +" -1 allow only single connection and quit\n" +" -4 connect to IPv4 endpoints (default: connect to IPv6)\n" +" -6 bind to IPv6 address (default: bind to IPv4)\n" " -d don't detach\n" " -f force tunneling (even if remotehost isn't resolvable)\n" " -h print hex dump of packets\n" " -i act like irc proxy and ask for password\n" " -I send specified password to the irc server\n" " -l bind to specified address\n" -" -L limit simultanous connections\n" +" -L limit simultaneous connections\n" " -p write down pid to specified file\n" " -s connect using specified address\n" " -m read specified IPv4-to-IPv6 map file\n" @@ -402,14 +481,14 @@ return; } -void map_destroy(void) +void source_map_destroy(void) { - map_t *m; + source_map_t *m; - debug("map_destroy()\n"); + debug("source_map_destroy()\n"); - for (m = map_list; m; ) { - map_t *n; + for (m = source_map; m != NULL; ) { + source_map_t *n; free(m->ipv4); free(m->ipv6); @@ -418,7 +497,7 @@ free(n); } - map_list = NULL; + source_map = NULL; } void map_read(void) @@ -426,19 +505,18 @@ char buf[256]; FILE *f; - if (!map_file) - return; + debug("reading map from %s\n", source_map_file); - debug("reading map from %s\n", map_file); + f = fopen(source_map_file, "r"); - if (!(f = fopen(map_file, "r"))) { + if (f == NULL) { debug("unable to read map file, ignoring\n"); return; } - while (fgets(buf, sizeof(buf), f)) { + while (fgets(buf, sizeof(buf), f) != NULL) { char *p, *ipv4, *ipv6; - map_t *m; + source_map_t *m; for (p = buf; *p == ' ' || *p == '\t'; p++); @@ -468,11 +546,11 @@ debug("[%s] mapped to [%s]\n", ipv4, ipv6); - m = (map_t*) xmalloc(sizeof(map_t)); + m = (source_map_t*) xmalloc(sizeof(source_map_t)); m->ipv4 = xstrdup(ipv4); m->ipv6 = xstrdup(ipv6); - m->next = map_list; - map_list = m; + m->next = source_map; + source_map = m; } fclose(f); @@ -480,7 +558,7 @@ void sighup() { - map_destroy(); + source_map_destroy(); map_read(); signal(SIGHUP, sighup); @@ -498,7 +576,7 @@ void sigterm() { - if (pid_file) + if (pid_file != NULL) unlink(pid_file); exit(0); @@ -506,19 +584,23 @@ int main(int argc, char **argv) { - int force = 0, lsock, csock, one = 0, jeden = 1, local_port; - int detach = 1, listen6 = 0, sa_len, conn_limit = 0; - char optc, *username = NULL, *bind_host = NULL; + int force = 0, listen_fd, single_connection = 0, jeden = 1, local_port; + int detach = 1, sa_len, conn_limit = 0, optc; + const char *username = NULL; + char *local_host = NULL; + struct addrinfo *ai; + struct addrinfo *ai_ptr; struct sockaddr *sa; - struct sockaddr_in laddr, caddr; + struct sockaddr_in laddr; struct sockaddr_in6 laddr6; - int caddrlen = sizeof(caddr); struct passwd *pw = NULL; + char *tmp; + int source_hint; - while ((optc = getopt(argc, argv, "1dv46fs:l:I:i:hu:m:L:A:p:")) != -1) { + while ((optc = getopt(argc, argv, "1dv46fHs:l:I:i:hu:m:L:A:p:")) != -1) { switch (optc) { case '1': - one = 1; + single_connection = 1; break; case 'd': detach = 0; @@ -527,42 +609,46 @@ verbose = 1; break; case '4': - hint = AF_INET; + remote_hint[0] = AF_INET; + remote_hint[1] = AF_INET6; break; case '6': - listen6 = 1; + local_hint = AF_INET6; break; case 's': - source_host = xstrdup(optarg); + source_host = optarg; break; case 'l': - bind_host = xstrdup(optarg); + local_host = optarg; break; - case 'r': + case 'f': force = 1; break; case 'i': - ircpass = xstrdup(optarg); + irc_pass = xstrdup(optarg); clear_argv(argv[optind - 1]); break; case 'I': - ircsendpass = xstrdup(optarg); + irc_send_pass = xstrdup(optarg); clear_argv(argv[optind - 1]); break; case 'h': hexdump = 1; break; case 'u': - username = xstrdup(optarg); + username = optarg; break; case 'm': - map_file = xstrdup(optarg); + source_map_file = optarg; break; case 'L': conn_limit = atoi(optarg); break; case 'p': - pid_file = xstrdup(optarg); + pid_file = optarg; + break; + case 'H': + fprintf(stderr, "%s: warning: -H is deprecated, please use proper combination of -4 and -6.\n", argv[0]); break; default: return 1; @@ -583,88 +669,128 @@ exit(1); } - if (username && !(pw = getpwnam(username))) { - fprintf(stderr, "%s: unknown user %s\n", argv[0], username); - exit(1); + if (username != NULL) { + pw = getpwnam(username); + + if (pw == NULL) { + fprintf(stderr, "%s: unknown user %s\n", argv[0], username); + exit(1); + } } - if (map_file) + if (source_map_file != NULL) map_read(); local_port = atoi(argv[optind++]); remote_host = argv[optind++]; remote_port = (argc == optind) ? local_port : atoi(argv[optind]); + /* Check if destination and source hosts are resolvable. If it's expected to be + * available later, -f can be used. */ + debug("resolving %s\n", remote_host); - if (!(sa = resolve_host(remote_host, hint)) && !force) { - fprintf(stderr, "%s: unable to resolve host %s\n", argv[0], remote_host); - exit(1); + ai = resolve_host(remote_host, remote_port, remote_hint[0]); + + if (ai == NULL) { + ai = resolve_host(remote_host, remote_port, remote_hint[1]); + + if (ai == NULL && !force) { + fprintf(stderr, "%s: unable to resolve host %s\n", argv[0], remote_host); + exit(1); + } + + source_hint = remote_hint[1]; + } else { + source_hint = remote_hint[0]; } - free(sa); - sa = NULL; + if (source_hint == AF_INET && local_hint == AF_INET) + fprintf(stderr, "%s: warning: both local and remote addresses are IPv4\n", argv[0]); - if (bind_host) { - debug("resolving %s\n", bind_host); + if (source_hint == AF_INET6 && local_hint == AF_INET6) + fprintf(stderr, "%s: warning: both local and remote addresses are IPv6\n", argv[0]); - if (!(sa = resolve_host(bind_host, (listen6) ? AF_INET6 : AF_INET))) { - fprintf(stderr, "%s: unable to resolve host %s\n", argv[0], remote_host); + tmp = xntop(ai->ai_addr); + debug("resolved to %s\n", tmp); + free(tmp); + + freeaddrinfo(ai); + + if (source_host != NULL) { + debug("resolving %s\n", source_host); + + ai = resolve_host(source_host, 0, source_hint); + + if (ai == NULL && !force) { + fprintf(stderr, "%s: unable to resolve host %s\n", argv[0], source_host); exit(1); } + + tmp = xntop(ai->ai_addr); + debug("resolved to %s\n", tmp); + free(tmp); + + freeaddrinfo(ai); + } + + /* Resolve local address for bind(). In case of NULL address resolve_host() will + * return INADDR_ANY or in6addr_any, so we can bind either way. */ + + debug("resolving local address %s\n", (local_host != NULL) ? local_host : "default"); + + ai = resolve_host(local_host, local_port, local_hint); + + if (ai == NULL) { + fprintf(stderr, "%s: unable to resolve host %s\n", argv[0], local_host); + exit(1); } + + tmp = xntop(ai->ai_addr); + debug("resolved to %s\n", tmp); + free(tmp); + + /* Now that we know that hosts are resolvable, dump some debugging information. */ - debug("local: %s,%d; ", (bind_host) ? bind_host : "default", local_port); + debug("local: %s,%d; ", (local_host != NULL) ? local_host : "default", local_port); debug("remote: %s,%d; ", remote_host, remote_port); - if (map_file) + if (source_map != NULL) debug("source: mapped\n"); else - debug("source: %s\n", (source_host) ? source_host : "default"); + debug("source: %s\n", (source_host != NULL) ? source_host : "default"); - if (!listen6) { - lsock = socket(PF_INET, SOCK_STREAM, 0); + /* Now bind. */ - memset(&laddr, 0, (sa_len = sizeof(laddr))); - laddr.sin_family = AF_INET; - laddr.sin_port = htons(local_port); - - if (sa) { - memcpy(&laddr.sin_addr, &((struct sockaddr_in*) sa)->sin_addr, sizeof(struct in_addr)); - free(sa); - } - - sa = (struct sockaddr*) &laddr; - } else { - lsock = socket(PF_INET6, SOCK_STREAM, 0); - - memset(&laddr6, 0, (sa_len = sizeof(laddr6))); - laddr6.sin6_family = AF_INET6; - laddr6.sin6_port = htons(local_port); - - if (sa) { - memcpy(&laddr6.sin6_addr, &((struct sockaddr_in6*) sa)->sin6_addr, sizeof(struct in6_addr)); - free(sa); - } + listen_fd = socket(ai->ai_family, ai->ai_socktype, 0); - sa = (struct sockaddr*) &laddr6; + if (listen_fd == -1) { + perror("socket"); + exit(1); } - if (setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, &jeden, sizeof(jeden)) == -1) { + if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &jeden, sizeof(jeden)) == -1) { perror("setsockopt"); exit(1); } - if (bind(lsock, sa, sa_len)) { - perror("bind"); - exit(1); + for (ai_ptr = ai; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { + if (bind(listen_fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen) == -1 && ai_ptr->ai_next == NULL) { + perror("bind"); + exit(1); + } } - if (listen(lsock, 100)) { + if (listen(listen_fd, 100) == -1) { perror("listen"); exit(1); } + freeaddrinfo(ai); + ai = NULL; + + /* Daemonize. */ + if (detach) { int i, ret; @@ -684,7 +810,9 @@ exit(0); } - if (pid_file) { + /* Store process id if requested. */ + + if (pid_file != NULL) { FILE *f = fopen(pid_file, "w"); if (!f) @@ -695,9 +823,13 @@ } } - if (username && ((setgid(pw->pw_gid) == -1) || (setuid(pw->pw_uid) == -1))) { - perror("setuid/setgid"); - exit(1); + /* Change user and group id if requested. */ + + if (pw != NULL) { + if ((setgid(pw->pw_gid) == -1) || (setuid(pw->pw_uid) == -1)) { + perror("setuid/setgid"); + exit(1); + } } setsid(); @@ -709,11 +841,16 @@ for (;;) { int ret; fd_set rds; + int client_fd; + char *client_addr; + int client_port; + struct sockaddr sa; + unsigned int sa_len = sizeof(sa); FD_ZERO(&rds); - FD_SET(lsock, &rds); + FD_SET(listen_fd, &rds); - if (select(lsock + 1, &rds, NULL, NULL, NULL) == -1) { + if (select(listen_fd + 1, &rds, NULL, NULL, NULL) == -1) { if (errno == EINTR) continue; @@ -721,22 +858,24 @@ break; } - if ((csock = accept(lsock, (struct sockaddr*) &caddr, &caddrlen)) == -1) { + client_fd = accept(listen_fd, &sa, &sa_len); + + if (client_fd == -1) { perror("accept"); break; } - inet_ntop(caddr.sin_family, (caddr.sin_family == AF_INET) ? - &caddr.sin_addr : - (void*) &(((struct sockaddr_in6*)&caddr)->sin6_addr), - remote, sizeof(remote)); + client_addr = xntop(&sa); + + client_port = (sa.sa_family == AF_INET) ? ((struct sockaddr_in*) &sa)->sin_port : + ((struct sockaddr_in6*) &sa)->sin6_port; - debug("<%d> connection from %s,%d", csock, remote, ntohs(caddr.sin_port)); + debug("<%d> connection from %s,%d", client_fd, client_addr, ntohs(client_port)); if (conn_limit && (conn_count >= conn_limit)) { debug(" -- rejected due to limit.\n"); - shutdown(csock, 2); - close(csock); + shutdown(client_fd, 2); + close(client_fd); continue; } @@ -749,31 +888,34 @@ if ((ret = fork()) == -1) { debug(" -- fork() failed.\n"); - shutdown(csock, 2); - close(csock); + shutdown(client_fd, 2); + close(client_fd); + free(client_addr); continue; } if (!ret) { signal(SIGHUP, SIG_IGN); - close(lsock); + close(listen_fd); debug("\n"); - make_tunnel(csock, remote); - debug("<%d> connection closed\n", csock); + make_tunnel(client_fd, client_addr); + free(client_addr); + debug("<%d> connection closed\n", client_fd); exit(0); } - close(csock); + close(client_fd); + free(client_addr); - if (one) { - shutdown(lsock, 2); - close(lsock); + if (single_connection) { + shutdown(listen_fd, 2); + close(listen_fd); exit(0); } } - close(lsock); + close(listen_fd); exit(1); } diff -Nru 6tunnel-0.11rc2/autogen.sh 6tunnel-0.12/autogen.sh --- 6tunnel-0.11rc2/autogen.sh 2002-11-24 00:40:13.000000000 +0000 +++ 6tunnel-0.12/autogen.sh 2016-10-24 20:42:34.000000000 +0000 @@ -1,3 +1,3 @@ #!/bin/sh -autoconf +autoreconf --install test x$NOCONFIGURE = x && ./configure diff -Nru 6tunnel-0.11rc2/ChangeLog 6tunnel-0.12/ChangeLog --- 6tunnel-0.11rc2/ChangeLog 2005-08-18 16:59:44.000000000 +0000 +++ 6tunnel-0.12/ChangeLog 2016-10-24 20:42:34.000000000 +0000 @@ -1,4 +1,15 @@ -0.11 (2005-08-18) +0.12 (2016-10-24) + +Changes by Wojtek Kaniewski : +- make -4 and -6 work the way they were intended, +- remove -H option, but leave enough information for the users to get the + same result, +- warn when both local and remote address are of the same type. + +Changes by Jari Aalto : +- spelling fixes. + +0.11 (2016-02-26) Changes by Wojtek Kaniewski : - changed license to GPL version 2. There was no license information before @@ -7,13 +18,21 @@ were dead and googling for them gave no useful information. The missing features have been rewritten from scratch. If any offending code is still here, please let me know. I've done my best, but I haven't used any - version control 5 years ago. -- changed e-mail address. + version control 5 years ago, +- changed e-mail address, +- ignore IPv4/IPv6 address hints when option -H is present. Changes by Ramunas Lukosevicius - fixed source mapping bug, - SIGHUP reloads map file. +Changes by Roland Stigge +- fix an error in the "hints" handling of the host resolver which confused + local/source and remote hint (AF_INET/AF_INET6). + +Changes by Olaf Rempel +- correct option -f. + 0.10 (2003-06-12) Changes by Wojtek Kaniewski : diff -Nru 6tunnel-0.11rc2/configure.ac 6tunnel-0.12/configure.ac --- 6tunnel-0.11rc2/configure.ac 1970-01-01 00:00:00.000000000 +0000 +++ 6tunnel-0.12/configure.ac 2016-10-24 20:42:34.000000000 +0000 @@ -0,0 +1,36 @@ +AC_INIT([6tunnel],[0.12],[]) +AM_INIT_AUTOMAKE([1.14 foreign silent-rules subdir-objects tar-pax]) +AC_PROG_CC +AC_PROG_INSTALL +AC_PROG_MAKE_SET +AC_PATH_PROG(STRIP, strip, :) + +test -d /usr/local/v6/lib && LIBS="$LIBS -L/usr/local/v6/lib" +test -d /usr/inet6/lib && LIBS="$LIBS -L/usr/inet6/lib" +test -d /usr/local/inet6/lib && LIBS="$LIBS -L/usr/local/inet6/lib" + +AC_CHECK_LIB(nsl, t_accept, LIBS="$LIBS -lnsl") +AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket") +AC_CHECK_LIB(inet6, main, LIBS="$LIBS -linet6") + +AC_STDC_HEADERS +AC_HAVE_HEADERS(sys/socket.h netinet/in.h arpa/inet.h netdb.h, , AC_MSG_ERROR([Socket related headers missing.])) +AC_CHECK_FUNCS(getaddrinfo, , AC_MSG_ERROR([Your system doesn't support IPv6.])) + +AC_MSG_CHECKING([for AF_INET6]) +AC_TRY_COMPILE([#include ], [int x = AF_INET6;], [ + AC_MSG_RESULT(yes) +], [ + AC_MSG_RESULT(no) + AC_MSG_ERROR([Your system doesn't support IPv6.]) +]) + +AC_SUBST(VERSION) +VERSION=`grep '6tunnel v' 6tunnel.c | sed 's/.*v//'` + +AC_CONFIG_FILES([ + Makefile +]) + +AC_OUTPUT + diff -Nru 6tunnel-0.11rc2/configure.in 6tunnel-0.12/configure.in --- 6tunnel-0.11rc2/configure.in 2002-11-24 00:59:24.000000000 +0000 +++ 6tunnel-0.12/configure.in 1970-01-01 00:00:00.000000000 +0000 @@ -1,32 +0,0 @@ -AC_INIT(6tunnel.c) - -AC_PROG_CC -AC_PROG_INSTALL -AC_PROG_MAKE_SET -AC_PATH_PROG(STRIP, strip, :) - -test -d /usr/local/v6/lib && LIBS="$LIBS -L/usr/local/v6/lib" -test -d /usr/inet6/lib && LIBS="$LIBS -L/usr/inet6/lib" -test -d /usr/local/inet6/lib && LIBS="$LIBS -L/usr/local/inet6/lib" - -AC_CHECK_LIB(nsl, t_accept, LIBS="$LIBS -lnsl") -AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket") -AC_CHECK_LIB(inet6, main, LIBS="$LIBS -linet6") - -AC_STDC_HEADERS -AC_HAVE_HEADERS(sys/socket.h netinet/in.h arpa/inet.h netdb.h, , AC_MSG_ERROR([Socket related headers missing.])) -AC_CHECK_FUNCS(getaddrinfo, , AC_MSG_ERROR([Your system doesn't support IPv6.])) - -AC_MSG_CHECKING([for AF_INET6]) -AC_TRY_COMPILE([#include ], [int x = AF_INET6;], [ - AC_MSG_RESULT(yes) -], [ - AC_MSG_RESULT(no) - AC_MSG_ERROR([Your system doesn't support IPv6.]) -]) - -AC_SUBST(VERSION) -VERSION=`grep '6tunnel v' 6tunnel.c | sed 's/.*v//'` - -AC_OUTPUT(Makefile) - diff -Nru 6tunnel-0.11rc2/debian/changelog 6tunnel-0.12/debian/changelog --- 6tunnel-0.11rc2/debian/changelog 2013-05-24 04:23:29.000000000 +0000 +++ 6tunnel-0.12/debian/changelog 2016-10-25 04:08:11.000000000 +0000 @@ -1,3 +1,49 @@ +6tunnel (1:0.12-1) unstable; urgency=medium + + * New upstream release + - Warn if both addresses are already IPV4 (Closes: 610979) + * debian/copyright + - (Comment): Move info to this standard header. + - Update URLs + * debian/patches + - Delete. Included in upstream release. + 20-resolve-ipv4-address--bug601030.patch + 25-spelling.patch + 30-manpage.patch + * debian/source/options + - Ignore autoconf files. + * debian/watch + - Update to Github. + + -- Jari Aalto Tue, 25 Oct 2016 07:08:11 +0300 + +6tunnel (1:0.11-1) unstable; urgency=medium + + * New upstream release. + * debian/source/options: + - New file. + * debian/copyright: + - Update years. + - (X-Upstream-*): New fields. + * debian/patches + - (10, 15): f-option and ARM patches removed. Included in upstream. + * debian/rules: + - (override_dh_auto_configure): Call autoconf -f -i. + + -- Jari Aalto Tue, 18 Oct 2016 18:41:22 +0300 + +6tunnel (0.11rc2-9) unstable; urgency=medium + + * debian/control + - (Standards-Version): Update to 3.9.8. + - (Vcs-*): Update to anonscm.debian.git. + * debian/patches + - (25): New. Fix spelling in binary (Lintian). + * debian/watch + - Update. + + -- Jari Aalto Tue, 18 Oct 2016 09:54:45 +0300 + 6tunnel (0.11rc2-8) unstable; urgency=low * debian/control diff -Nru 6tunnel-0.11rc2/debian/control 6tunnel-0.12/debian/control --- 6tunnel-0.11rc2/debian/control 2013-05-24 04:23:29.000000000 +0000 +++ 6tunnel-0.12/debian/control 2016-10-25 04:08:11.000000000 +0000 @@ -3,10 +3,10 @@ Priority: optional Maintainer: Jari Aalto Build-Depends: debhelper (>= 9), autoconf -Standards-Version: 3.9.4 -Vcs-Browser: http://git.debian.org/?p=collab-maint/6tunnel.git -Vcs-Git: git://git.debian.org/git/collab-maint/6tunnel.git -Homepage: http://toxygen.net/6tunnel +Standards-Version: 3.9.8 +Vcs-Browser: https://anonscm.debian.org/gitweb/?p=collab-maint/6tunnel.git +Vcs-Git: https://anonscm.debian.org/git/collab-maint/6tunnel.git +Homepage: https://toxygen.net/6tunnel Package: 6tunnel Architecture: any diff -Nru 6tunnel-0.11rc2/debian/copyright 6tunnel-0.12/debian/copyright --- 6tunnel-0.11rc2/debian/copyright 2013-05-24 04:23:29.000000000 +0000 +++ 6tunnel-0.12/debian/copyright 2016-10-25 04:08:11.000000000 +0000 @@ -1,9 +1,13 @@ -Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0 +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: 6tunnel Upstream-Contact: Wojtek Kaniewski Source: http://toxygen.net/6tunnel +X-Upstream-Vcs: git clone https://github.com/wojtekka/6tunnel.git +X-Upstream-Bts: https://github.com/wojtekka/6tunnel/issues +Comment: As of 2010-10-24 the upstream address wojtekka@irc.pl mentioned in the "ChangeLog" file no longer exists. + Latest code is in Github. Files: * Copyright: @@ -18,7 +22,7 @@ Files: debian/* Copyright: - 2010, 2012, 2013 Jari Aalto + 2010-2016 Jari Aalto 2002, 2003, 2005, 2006 Thomas Seyrat License: GPL-2+ diff -Nru 6tunnel-0.11rc2/debian/patches/10-6tunnel.c--option-f.patch 6tunnel-0.12/debian/patches/10-6tunnel.c--option-f.patch --- 6tunnel-0.11rc2/debian/patches/10-6tunnel.c--option-f.patch 2013-05-24 04:23:29.000000000 +0000 +++ 6tunnel-0.12/debian/patches/10-6tunnel.c--option-f.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,29 +0,0 @@ -From 353c025fd2fe72d7c342a8a694727cca7298256e Mon Sep 17 00:00:00 2001 -From: Jari Aalto -Date: Wed, 17 Mar 2010 10:14:18 +0200 -Subject: [PATCH] 6tunnel.c: Correct option -f. By Olaf Rempel -Organization: Private -Content-Type: text/plain; charset="utf-8" -Content-Transfer-Encoding: 8bit - -Signed-off-by: Jari Aalto ---- - 6tunnel.c | 2 +- - 1 files changed, 1 insertions(+), 1 deletions(-) - -diff --git a/6tunnel.c b/6tunnel.c -index 7b6d657..ce1d292 100644 ---- a/6tunnel.c -+++ b/6tunnel.c -@@ -538,7 +538,7 @@ int main(int argc, char **argv) - case 'l': - bind_host = xstrdup(optarg); - break; -- case 'r': -+ case 'f': - force = 1; - break; - case 'i': --- -1.7.0 - diff -Nru 6tunnel-0.11rc2/debian/patches/15-arm-arch.patch 6tunnel-0.12/debian/patches/15-arm-arch.patch --- 6tunnel-0.11rc2/debian/patches/15-arm-arch.patch 2013-05-24 04:23:29.000000000 +0000 +++ 6tunnel-0.12/debian/patches/15-arm-arch.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,30 +0,0 @@ -From 6096ce243d5ee87e2c13c55eb3b5a3cbccf87931 Mon Sep 17 00:00:00 2001 -From: Jari Aalto -Date: Sun, 7 Nov 2010 09:56:48 +0200 -Subject: [PATCH] In ARM getopt() is unsigned by Martijn -Organization: Private -Content-Type: text/plain; charset="utf-8" -Content-Transfer-Encoding: 8bit - -Signed-off-by: Jari Aalto ---- - 6tunnel.c | 3 ++- - 1 files changed, 2 insertions(+), 1 deletions(-) - -diff --git a/6tunnel.c b/6tunnel.c -index ce1d292..1e517f5 100644 ---- a/6tunnel.c -+++ b/6tunnel.c -@@ -508,7 +508,8 @@ int main(int argc, char **argv) - { - int force = 0, lsock, csock, one = 0, jeden = 1, local_port; - int detach = 1, listen6 = 0, sa_len, conn_limit = 0; -- char optc, *username = NULL, *bind_host = NULL; -+ char *username = NULL, *bind_host = NULL; -+ int optc; - struct sockaddr *sa; - struct sockaddr_in laddr, caddr; - struct sockaddr_in6 laddr6; --- -1.7.2.3 - diff -Nru 6tunnel-0.11rc2/debian/patches/20-resolve-ipv4-address--bug601030.patch 6tunnel-0.12/debian/patches/20-resolve-ipv4-address--bug601030.patch --- 6tunnel-0.11rc2/debian/patches/20-resolve-ipv4-address--bug601030.patch 2013-05-24 04:23:29.000000000 +0000 +++ 6tunnel-0.12/debian/patches/20-resolve-ipv4-address--bug601030.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,113 +0,0 @@ -From dc5f073a30eff5a6080fb046954e2ca1603a3ad4 Mon Sep 17 00:00:00 2001 -From: Jari Aalto -Date: Sun, 7 Nov 2010 10:02:42 +0200 -Subject: [PATCH] Fix can't resolve IPv4 address by Roland Stigge -Organization: Private -Content-Type: text/plain; charset="utf-8" -Content-Transfer-Encoding: 8bit - -Signed-off-by: Jari Aalto ---- - 6tunnel.c | 24 +++++++++++++----------- - 1 files changed, 13 insertions(+), 11 deletions(-) - -diff --git a/6tunnel.c b/6tunnel.c -index 1e517f5..787c25c 100644 ---- a/6tunnel.c -+++ b/6tunnel.c -@@ -43,7 +43,9 @@ - } while(0) - - int verbose = 0, conn_count = 0; --int remote_port, verbose, hint = AF_INET6, hexdump = 0; -+int remote_port, verbose, hexdump = 0; -+int remote_hint = AF_INET6; -+int local_hint = AF_INET; - char *remote_host, *ircpass = NULL; - char *ircsendpass = NULL, remote[128]; - char *pid_file = NULL; -@@ -218,7 +220,7 @@ void make_tunnel(int rsock, const char *remote) - debug("<%d> irc proxy auth succeded\n", rsock); - } - -- if (!(sa = resolve_host(remote_host, hint))) { -+ if (!(sa = resolve_host(remote_host, remote_hint))) { - debug("<%d> unable to resolve %s\n", rsock, remote_host); - goto cleanup; - } -@@ -232,12 +234,12 @@ void make_tunnel(int rsock, const char *remote) - sa = NULL; - - if (source) { -- if (!(sa = resolve_host(source, hint))) { -+ if (!(sa = resolve_host(source, local_hint))) { - debug("<%d> unable to resolve source host (%s)\n", rsock, source); - goto cleanup; - } - -- if (bind(sock, sa, (hint == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))) { -+ if (bind(sock, sa, (local_hint == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))) { - debug("<%d> unable to bind to source host (%s)\n", rsock, source); - goto cleanup; - } -@@ -246,7 +248,7 @@ void make_tunnel(int rsock, const char *remote) - sa = NULL; - } - -- sa = resolve_host(remote_host, hint); -+ sa = resolve_host(remote_host, remote_hint); - - ((struct sockaddr_in*) sa)->sin_port = htons(remote_port); - -@@ -507,7 +509,7 @@ void sigterm() - int main(int argc, char **argv) - { - int force = 0, lsock, csock, one = 0, jeden = 1, local_port; -- int detach = 1, listen6 = 0, sa_len, conn_limit = 0; -+ int detach = 1, sa_len = 0, conn_limit = 0; - char *username = NULL, *bind_host = NULL; - int optc; - struct sockaddr *sa; -@@ -528,10 +530,10 @@ int main(int argc, char **argv) - verbose = 1; - break; - case '4': -- hint = AF_INET; - break; - case '6': -- listen6 = 1; -+ remote_hint = AF_INET; -+ local_hint = AF_INET6; - break; - case 's': - source_host = xstrdup(optarg); -@@ -598,7 +600,7 @@ int main(int argc, char **argv) - - debug("resolving %s\n", remote_host); - -- if (!(sa = resolve_host(remote_host, hint)) && !force) { -+ if (!(sa = resolve_host(remote_host, remote_hint)) && !force) { - fprintf(stderr, "%s: unable to resolve host %s\n", argv[0], remote_host); - exit(1); - } -@@ -609,7 +611,7 @@ int main(int argc, char **argv) - if (bind_host) { - debug("resolving %s\n", bind_host); - -- if (!(sa = resolve_host(bind_host, (listen6) ? AF_INET6 : AF_INET))) { -+ if (!(sa = resolve_host(bind_host, local_hint))) { - fprintf(stderr, "%s: unable to resolve host %s\n", argv[0], remote_host); - exit(1); - } -@@ -623,7 +625,7 @@ int main(int argc, char **argv) - else - debug("source: %s\n", (source_host) ? source_host : "default"); - -- if (!listen6) { -+ if (local_hint == AF_INET) { - lsock = socket(PF_INET, SOCK_STREAM, 0); - - memset(&laddr, 0, (sa_len = sizeof(laddr))); --- -1.7.2.3 - diff -Nru 6tunnel-0.11rc2/debian/patches/30-manpage.patch 6tunnel-0.12/debian/patches/30-manpage.patch --- 6tunnel-0.11rc2/debian/patches/30-manpage.patch 2013-05-24 04:23:29.000000000 +0000 +++ 6tunnel-0.12/debian/patches/30-manpage.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,28 +0,0 @@ -From: Jari Aalto -Subject: Fix typos -Bug-Debian: http://bugs.debian.org/709334 - ---- - 6tunnel.1 | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - ---- a/6tunnel.1 -+++ b/6tunnel.1 -@@ -76,7 +76,7 @@ - .B 6tunnel - will use the IPv4 one. In other cases, use - .B \-4 --parameter which makes IPv4 address the preffered one. For IPv6-to-any tunnels -+parameter which makes IPv4 address the preferred one. For IPv6-to-any tunnels - use - .B \-6 - which makes -@@ -88,7 +88,7 @@ - Exit after first connection. - .TP - .B \-4 --Preffer IPv4 endpoint if the machine has both address types. -+Prefer IPv4 endpoint if the machine has both address types. - .TP - .B \-6 - Listen on IPv6 address (IPv4 is default). diff -Nru 6tunnel-0.11rc2/debian/patches/series 6tunnel-0.12/debian/patches/series --- 6tunnel-0.11rc2/debian/patches/series 2013-05-24 04:23:29.000000000 +0000 +++ 6tunnel-0.12/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 @@ -1,4 +0,0 @@ -10-6tunnel.c--option-f.patch -15-arm-arch.patch -20-resolve-ipv4-address--bug601030.patch -30-manpage.patch diff -Nru 6tunnel-0.11rc2/debian/rules 6tunnel-0.12/debian/rules --- 6tunnel-0.11rc2/debian/rules 2013-05-24 04:23:29.000000000 +0000 +++ 6tunnel-0.12/debian/rules 2016-10-25 04:08:11.000000000 +0000 @@ -8,7 +8,7 @@ $(MAKE) install prefix=$(CURDIR)/debian/6tunnel/usr override_dh_auto_configure: - [ -f Makefile ] || sh ./autogen.sh + [ -f Makefile ] || sh ./autogen.sh || autoconf -f -i dh_auto_configure %: diff -Nru 6tunnel-0.11rc2/debian/source/options 6tunnel-0.12/debian/source/options --- 6tunnel-0.11rc2/debian/source/options 1970-01-01 00:00:00.000000000 +0000 +++ 6tunnel-0.12/debian/source/options 2016-10-25 04:08:11.000000000 +0000 @@ -0,0 +1 @@ +extend-diff-ignore = "configure|Makefile|m4|compile|depcomp|missing" diff -Nru 6tunnel-0.11rc2/debian/watch 6tunnel-0.12/debian/watch --- 6tunnel-0.11rc2/debian/watch 2013-05-24 04:23:29.000000000 +0000 +++ 6tunnel-0.12/debian/watch 2016-10-25 04:08:11.000000000 +0000 @@ -1,3 +1,8 @@ version=3 -opts=uversionmangle=s/(\d)[_\.\-\+]?((RC|rc|pre|dev|beta|alpha|b|a)\d*)$/$1~$2/,dversionmangle=s/(\d)(rc\d*)$/$1~$2/ \ -http://toxygen.net/6tunnel/6tunnel-(\d.*)\.(?:tgz|tbz2|tar\.(?:gz|bz2|xz)) +# opts=uversionmangle=s/(\d)[_\.\-\+]?((RC|rc|pre|dev|beta|alpha|b|a)\d*)$/$1~$2/,dversionmangle=s/(\d)(rc\d*)$/$1~$2/ \ +# http://toxygen.net/6tunnel/6tunnel-(\d.*)\.(?:tgz|tbz2|tar\.(?:gz|bz2|xz)) +# http://toxygen.net/6tunnel/6tunnel-([\d.]+)\.(?:tar\.(?:gz|bz2|xz)) + +opts=filenamemangle=s/.+\/(\d\S*)\.tar\.gz/6tunnel-$1\.tar\.gz/ \ + https://github.com/wojtekka/6tunnel/tags .*/(\d\S*)\.tar\.gz + diff -Nru 6tunnel-0.11rc2/.gitignore 6tunnel-0.12/.gitignore --- 6tunnel-0.11rc2/.gitignore 1970-01-01 00:00:00.000000000 +0000 +++ 6tunnel-0.12/.gitignore 2016-10-24 20:42:34.000000000 +0000 @@ -0,0 +1,15 @@ +.deps/ +6tunnel +*.o +*.tar.gz +Makefile +Makefile.in +aclocal.m4 +autom4te.cache/ +compile +config.log +config.status +configure +depcomp +missing + diff -Nru 6tunnel-0.11rc2/Makefile.am 6tunnel-0.12/Makefile.am --- 6tunnel-0.11rc2/Makefile.am 1970-01-01 00:00:00.000000000 +0000 +++ 6tunnel-0.12/Makefile.am 2016-10-24 20:42:34.000000000 +0000 @@ -0,0 +1,7 @@ + +bin_PROGRAMS = 6tunnel + +6tunnel_SOURCES = 6tunnel.c + +dist_man_MANS = 6tunnel.1 + diff -Nru 6tunnel-0.11rc2/Makefile.in 6tunnel-0.12/Makefile.in --- 6tunnel-0.11rc2/Makefile.in 2002-11-24 01:18:47.000000000 +0000 +++ 6tunnel-0.12/Makefile.in 1970-01-01 00:00:00.000000000 +0000 @@ -1,43 +0,0 @@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ -bindir = @bindir@ -mandir = @mandir@ - -CC = @CC@ -CFLAGS = @CFLAGS@ -Wall -LDFLAGS = @LIBS@ @LDFLAGS@ -INSTALL = @INSTALL@ -STRIP = @STRIP@ -VERSION = @VERSION@ - -default: 6tunnel - -6tunnel: 6tunnel.c - -.PHONY: install - -install: - $(STRIP) 6tunnel - $(INSTALL) -d $(bindir) - $(INSTALL) 6tunnel $(bindir) - - $(INSTALL) -d $(mandir)/man1 - $(INSTALL) 6tunnel.1 $(mandir)/man1 - -.PHONY: clean - -clean: - rm -f 6tunnel *.o *~ core 6tunnel-*.tar.gz config.log config.status - -.PHONY: distclean - -distclean: clean - rm -f Makefile - -.PHONY: tarball - -tarball: distclean - cd ..; mv 6tunnel 6tunnel-$(VERSION); tar zcvf 6tunnel-$(VERSION)/6tunnel-$(VERSION).tar.gz --exclude 6tunnel-$(VERSION)/6tunnel-$(VERSION).tar.gz --exclude 6tunnel-$(VERSION)/older 6tunnel-$(VERSION); mv 6tunnel-$(VERSION) 6tunnel - - - diff -Nru 6tunnel-0.11rc2/README.md 6tunnel-0.12/README.md --- 6tunnel-0.11rc2/README.md 1970-01-01 00:00:00.000000000 +0000 +++ 6tunnel-0.12/README.md 2016-10-24 20:42:34.000000000 +0000 @@ -0,0 +1,41 @@ +# 6tunnel + +6tunnel allows you to use services provided by IPv6 hosts with +IPv4-only applications and vice-versa. It can bind to any of your IPv4 +(default) or IPv6 addresses and forward all data to IPv4 or IPv6 +(default) host. For example + +``` +6tunnel -1 6668 irc6.net 6667 +``` + +will be enough to connect to IPv6 irc server with + +``` +irc foobar localhost:6668 +``` + +If you don't wish to run 6tunnel every time you want to show your +`:c001:` or `:dead:` IPv6 address on IRC, you can use `-i` parameter, which +makes 6tunnel ask your client for specified password. Just run + +``` +6tunnel -i dupa.8 31337 irc6.net 6667 +``` + +and then type + +``` +irc foobar localhost:31337:dupa.8 +``` + +If your IRC server requires you to send password, specify it with `-I` +parameter -- after successful proxy authentication 6tunnel will send it +to the server. + +6tunnel can also be used as a tunnel for all other combinations of IPv4 +and IPv6 endpoints. If remote host doesn't have any IPv6 addresses, +6tunnel will use the IPv4 one. In other cases, use -4 parameter which +makes IPv4 address the preffered one. For IPv6-to-any tunnels use -6 +which makes 6tunnel bind to IPv6 address. + diff -Nru 6tunnel-0.11rc2/test.py 6tunnel-0.12/test.py --- 6tunnel-0.11rc2/test.py 1970-01-01 00:00:00.000000000 +0000 +++ 6tunnel-0.12/test.py 2016-10-24 20:42:34.000000000 +0000 @@ -0,0 +1,149 @@ +#!/usr/bin/env python + +import os +import socket +import time +import select + +(SUCCESS, COMMAND_FAIL, CONNECT_FAIL, DISCONNECT, ACCEPT_FAIL, DATA_MISMATCH) = range(6) +labels = ["success", "command fail", "connection fail", "disconnection", "accept fail", "data mismatch"] + +def test(expect, client_af, server_af, from_ip, to_ip, args="", client_sends_first="NICK nick\r\n", server_receives="NICK nick\r\n", app_responds="", app_inserts="", server_sends_then=":localhost 001 nick :Welcome\r\n"): + # Open and close a socket to get random port available + + client_sock = socket.socket(client_af, socket.SOCK_STREAM, 0) + client_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True) + client_sock.bind(('', 0)) + client_port = client_sock.getsockname()[1] + client_sock.close() + + # Open a socket for mock server + + server_sock = socket.socket(server_af, socket.SOCK_STREAM, 0) + server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True) + server_sock.bind(('', 0)) + server_sock.listen(0) + server_port = server_sock.getsockname()[1] + + all_args = "-1 %s %d %s %d" % (args, client_port, to_ip, server_port) + print "Running with %s" % all_args + if os.system("./6tunnel " + all_args) != 0: + if expect != COMMAND_FAIL: + raise Exception("expected %s yet command failed" % labels[expect]) + else: + return + + client_sock = socket.socket(client_af, socket.SOCK_STREAM, 0) + + # Give 6tunnel instance some time to initialize + + connected = False + for i in range(10): + try: + client_sock.connect((from_ip, client_port)) + except socket.error: + time.sleep(0.1) + else: + connected = True + break + + if not connected: + if expect != CONNECT_FAIL: + raise Exception("expected %s yet connect failed" % labels[expect]) + else: + return + + # Send first data + + client_sock.send(client_sends_first) + + # Wait for 6tunnel to connect to the server + + rlist, wlist, xlist = select.select([server_sock], [], [], 1) + + if not rlist: + if expect != ACCEPT_FAIL: + raise Exception("expected %s yet accept failed" % labels[expect]) + else: + return + + accept_sock = server_sock.accept()[0] + + # Make sure that 6tunnel doesn't send anything to the client + + rlist, wlist, xlist = select.select([client_sock], [], [], 1) + + if rlist: + try: + res = client_sock.recv(1) + if not res: + raise socket.error + except socket.error: + if expect != DISCONNECT: + raise Exception("expected %s yet disconnected" % labels[expect]) + else: + return + + raise Exception("unexpected data sent to client") + + # Do the data exchange + + if app_responds: + tmp = client_sock.recv(len(app_responds)) + if tmp != app_responds: + raise Exception("expected 6tunnel response \"%s\" yet did not receive" % app_responds) + + if app_inserts: + tmp = accept_sock.recv(len(app_inserts)) + if tmp != app_inserts: + raise Exception("expected 6tunnel insert \"%s\" yet did not receive" % app_sends_first) + + if accept_sock.recv(len(server_receives)) != server_receives: + raise Exception("data mismatch") + + accept_sock.send(server_sends_then) + + if client_sock.recv(len(server_sends_then)) != server_sends_then: + raise Exception("data mismatch") + + accept_sock.close() + server_sock.close() + client_sock.close() + + if expect != SUCCESS: + raise Exception("expected %d yet succeeded" % expect) + +test(SUCCESS, socket.AF_INET, socket.AF_INET6, '127.0.0.1', '::1') +test(SUCCESS, socket.AF_INET, socket.AF_INET6, '127.0.0.1', '::1', '-l 127.0.0.1') +test(COMMAND_FAIL, socket.AF_INET, socket.AF_INET6, '127.0.0.1', '::1', '-l ::1') +test(SUCCESS, socket.AF_INET, socket.AF_INET6, '127.0.0.1', '::1', '-s ::1') +test(COMMAND_FAIL, socket.AF_INET, socket.AF_INET6, '127.0.0.1', '::1', '-s 127.0.0.1') + +test(SUCCESS, socket.AF_INET, socket.AF_INET, '127.0.0.1', '127.0.0.1', '-4') +test(SUCCESS, socket.AF_INET, socket.AF_INET, '127.0.0.1', '127.0.0.1', '-4 -l 127.0.0.1') +test(COMMAND_FAIL, socket.AF_INET, socket.AF_INET, '127.0.0.1', '127.0.0.1', '-4 -l ::1') +test(SUCCESS, socket.AF_INET, socket.AF_INET, '127.0.0.1', '127.0.0.1', '-4 -s 127.0.0.1') +test(COMMAND_FAIL, socket.AF_INET, socket.AF_INET, '127.0.0.1', '127.0.0.1', '-4 -s ::1') + +test(SUCCESS, socket.AF_INET6, socket.AF_INET, '::1', '127.0.0.1', '-4 -6') +test(SUCCESS, socket.AF_INET6, socket.AF_INET, '::1', '127.0.0.1', '-4 -6 -l ::1') +test(COMMAND_FAIL, socket.AF_INET6, socket.AF_INET, '::1', '127.0.0.1', '-4 -6 -l 127.0.0.1') +test(SUCCESS, socket.AF_INET6, socket.AF_INET, '::1', '127.0.0.1', '-4 -6 -s 127.0.0.1') +test(COMMAND_FAIL, socket.AF_INET6, socket.AF_INET, '::1', '127.0.0.1', '-4 -6 -s ::1') + +test(SUCCESS, socket.AF_INET6, socket.AF_INET6, '::1', '::1', '-6') +test(SUCCESS, socket.AF_INET6, socket.AF_INET6, '::1', '::1', '-6 -l ::1') +test(COMMAND_FAIL, socket.AF_INET6, socket.AF_INET6, '::1', '::1', '-6 -l 127.0.0.1') +test(SUCCESS, socket.AF_INET6, socket.AF_INET6, '::1', '::1', '-6 -s ::1') +test(COMMAND_FAIL, socket.AF_INET6, socket.AF_INET6, '::1', '::1', '-6 -s 127.0.0.1') + +# Test IRC password options + +test(SUCCESS, socket.AF_INET, socket.AF_INET6, '127.0.0.1', '::1', '-I password', app_inserts="PASS password\r\n") + +test(ACCEPT_FAIL, socket.AF_INET, socket.AF_INET6, '127.0.0.1', '::1', '-i password', client_sends_first="NICK nick\r\n") + +test(ACCEPT_FAIL, socket.AF_INET, socket.AF_INET6, '127.0.0.1', '::1', '-i password', client_sends_first="PASS invalid\r\nNICK nick\r\n", app_responds=":6tunnel 464 * :Password incorrect\r\n") + +test(SUCCESS, socket.AF_INET, socket.AF_INET6, '127.0.0.1', '::1', '-i password', client_sends_first="PASS password\r\nNICK nick\r\n") + diff -Nru 6tunnel-0.11rc2/TODO 6tunnel-0.12/TODO --- 6tunnel-0.11rc2/TODO 1970-01-01 00:00:00.000000000 +0000 +++ 6tunnel-0.12/TODO 2016-10-24 20:42:34.000000000 +0000 @@ -0,0 +1,2 @@ +Resolve all names after startup -- Simonas Kareiva +UDP tunneling -- Nuno Amorim