gdr / tuntox (public) (License: GPLv3) (since 2017-01-24) (hash sha1)
Tunnel TCP connections over the Tox protocol
List of commits:
Subject Hash Author Date (UTC)
Attempt at multiple -L options a64e90ea042ac785edf492c25735b3ba9bb8eca8 GDR! 2020-11-23 19:03:38
New docker image address at dockerhub 2e9e79947ecb9b62add1ff957d6b71a448d1d87b GDR! 2020-08-15 18:00:18
Add missing dockerfile d91e8ea5765bacfe3072d709d8c552d7f59f18d1 GDR! 2020-08-15 17:42:53
Perform a complete build inside Docker 92312438844988e45da6b1804cdb19ca7beef7bd GDR! 2020-08-15 17:19:52
Fix gcc warnings about strncpy a0fb587f1be623423db9d1e9882341731fab8ec5 GDR! 2020-08-15 16:50:44
Fix travis 07fd5cd5506b65afbd15c7289a341cb27da71114 GDR! 2020-08-15 16:36:25
Use py3 in travis c5e965f824faaa1a95647c469d0d8e4add17b3cd GDR! 2020-08-15 16:29:57
FreeBSD build instructions d20567154fb91de3a73baac9361d3ae99984e55c GDR! 2020-08-15 14:44:23
FAQ - links to packages 8691dbe266c51f788f763e0af3c712f3bab97f6f GDR! 2020-08-15 14:01:38
Try to name the deb appropiately 9e834d9af82f5819a59313c0b2276ba0dc2b0477 GDR! 2020-08-15 08:11:32
Lets try creating .tar.gz without dh_make 5d4dee4428e17f76b3b4a8ca769fad8695d8f02d GDR! 2020-08-15 08:04:57
Prevent dh_make warnings from stopping the build ca6a8b1f62e307c0430856619fc2b7797a71ec94 GDR! 2020-08-15 08:00:28
-y for dh_make 194a2bb10b581765d0a2a4c3e78965d4ad0e40df GDR! 2020-08-15 07:57:58
fix dh_make 7ae361ddb1d5d9e310c196e37c9e50e907c7d79c GDR! 2020-08-15 07:54:45
ci 5d7cfcb28e5b477e366dda746b40a99df4a7604f GDR! 2020-08-15 07:45:39
Build instructions for deb packages 0aaee3cc822c784e9bbf5d171ca188ba6fe4ed72 GDR! 2020-08-15 07:13:10
Deb building works 0583691495f0dcfa146c2111d6b2484328880a6d GDR! 2020-08-15 07:10:30
python2->python3 ac66a9f9bfaf86f4c8575c43e04ea87ac8abedb8 GDR! 2020-08-15 06:55:49
Make install support 11dc6ec3eb2cae9c861d1eb6fcfe68b4522b4210 GDR! 2020-08-14 10:42:23
Move generate_tox_bootstrap.py to python3 d4cf8be653cadc7ee0b2c44f771c5dcc6d34713a GDR! 2020-08-14 10:29:41
Commit a64e90ea042ac785edf492c25735b3ba9bb8eca8 - Attempt at multiple -L options
Author: GDR!
Author date (UTC): 2020-11-23 19:03
Committer name: GDR!
Committer date (UTC): 2020-11-23 19:03
Parent(s): 2e9e79947ecb9b62add1ff957d6b71a448d1d87b
Signer:
Signing key:
Signing status: N
Tree: d2887f9442348664f4792998ae0f931b23d5a7a1
File Lines added Lines deleted
client.c 51 37
gitversion.h 1 1
main.c 14 4
main.h 15 0
File client.c changed (mode: 100644) (index 3073e5d..40e7cd9)
... ... int state = CLIENT_STATE_INITIAL;
15 15 /* Used in ping mode */ /* Used in ping mode */
16 16 struct timespec ping_sent_time; struct timespec ping_sent_time;
17 17
18 /* Client mode tunnel */
19 tunnel client_tunnel;
20
21 /* Sock representing the local port - call accept() on it */
22 int bind_sockfd;
23
24 18 fd_set client_master_fdset; fd_set client_master_fdset;
25 19
26 20 int handle_pong_frame() int handle_pong_frame()
 
... ... int handle_pong_frame()
42 36 return 0; return 0;
43 37 } }
44 38
45 int local_bind()
39 int local_bind_one(local_port_forward *port_forward)
46 40 { {
47 41 struct addrinfo hints, *res; struct addrinfo hints, *res;
48 42 char port[6]; char port[6];
 
... ... int local_bind()
51 45 int gai_status; int gai_status;
52 46 int setsockopt_status; int setsockopt_status;
53 47
54 snprintf(port, 6, "%d", local_port);
48 snprintf(port, 6, "%d", port_forward->local_port);
55 49
56 50 memset(&hints, 0, sizeof hints); memset(&hints, 0, sizeof hints);
57 51 hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever
 
... ... int local_bind()
65 59 exit(1); exit(1);
66 60 } }
67 61
68 bind_sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
69 if(bind_sockfd < 0)
62 port_forward->bind_sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
63 if(port_forward->bind_sockfd < 0)
70 64 { {
71 65 log_printf(L_ERROR, "Could not create a socket for local listening: %s\n", strerror(errno)); log_printf(L_ERROR, "Could not create a socket for local listening: %s\n", strerror(errno));
72 66 freeaddrinfo(res); freeaddrinfo(res);
73 67 exit(1); exit(1);
74 68 } }
75 69
76 setsockopt_status = setsockopt(bind_sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
70 setsockopt_status = setsockopt(port_forward->bind_sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
77 71 if(setsockopt_status < 0) if(setsockopt_status < 0)
78 72 { {
79 73 log_printf(L_ERROR, "Could not set socket options: %s\n", log_printf(L_ERROR, "Could not set socket options: %s\n",
 
... ... int local_bind()
83 77 } }
84 78
85 79 /* Set O_NONBLOCK to make accept() non-blocking */ /* Set O_NONBLOCK to make accept() non-blocking */
86 if (-1 == (flags = fcntl(bind_sockfd, F_GETFL, 0)))
80 if (-1 == (flags = fcntl(port_forward->bind_sockfd, F_GETFL, 0)))
87 81 { {
88 82 flags = 0; flags = 0;
89 83 } }
90 if(fcntl(bind_sockfd, F_SETFL, flags | O_NONBLOCK) < 0)
84 if(fcntl(port_forward->bind_sockfd, F_SETFL, flags | O_NONBLOCK) < 0)
91 85 { {
92 86 log_printf(L_ERROR, "Could not make the socket non-blocking: %s\n", strerror(errno)); log_printf(L_ERROR, "Could not make the socket non-blocking: %s\n", strerror(errno));
93 87 freeaddrinfo(res); freeaddrinfo(res);
94 88 exit(1); exit(1);
95 89 } }
96 90
97 if(bind(bind_sockfd, res->ai_addr, res->ai_addrlen) < 0)
91 if(bind(port_forward->bind_sockfd, res->ai_addr, res->ai_addrlen) < 0)
98 92 { {
99 log_printf(L_ERROR, "Bind to port %d failed: %s\n", local_port, strerror(errno));
93 log_printf(L_ERROR, "Bind to port %d failed: %s\n", port_forward->local_port, strerror(errno));
100 94 freeaddrinfo(res); freeaddrinfo(res);
101 close(bind_sockfd);
95 close(port_forward->bind_sockfd);
102 96 exit(1); exit(1);
103 97 } }
104 98
105 99 freeaddrinfo(res); freeaddrinfo(res);
106 100
107 if(listen(bind_sockfd, 1) < 0)
101 if(listen(port_forward->bind_sockfd, 1) < 0)
108 102 { {
109 log_printf(L_ERROR, "Listening on port %d failed: %s\n", local_port, strerror(errno));
110 close(bind_sockfd);
103 log_printf(L_ERROR, "Listening on port %d failed: %s\n", port_forward->local_port, strerror(errno));
104 close(port_forward->bind_sockfd);
111 105 exit(1); exit(1);
112 106 } }
113 107
114 log_printf(L_DEBUG, "Bound to local port %d\n", local_port);
108 log_printf(L_DEBUG, "Bound to local port %d\n", port_forward->local_port);
115 109
116 110 return 0; return 0;
117 111 } }
118 112
113 int local_bind() {
114 local_port_forward *port_forward;
115
116 LL_FOREACH(local_port_forwards, port_forward)
117 {
118 local_bind_one(port_forward);
119 }
120 }
121
119 122 /* Bind the client.sockfd to a tunnel */ /* Bind the client.sockfd to a tunnel */
120 123 int handle_acktunnel_frame(protocol_frame *rcvd_frame) int handle_acktunnel_frame(protocol_frame *rcvd_frame)
121 124 { {
 
... ... int do_client_loop(uint8_t *tox_id_str)
288 291 uint32_t invitations_sent = 0; uint32_t invitations_sent = 0;
289 292 TOX_ERR_FRIEND_QUERY friend_query_error; TOX_ERR_FRIEND_QUERY friend_query_error;
290 293 TOX_ERR_FRIEND_CUSTOM_PACKET custom_packet_error; TOX_ERR_FRIEND_CUSTOM_PACKET custom_packet_error;
294 local_port_forward *port_forward;
291 295
292 296 client_tunnel.sockfd = 0; client_tunnel.sockfd = 0;
293 297 FD_ZERO(&client_master_fdset); FD_ZERO(&client_master_fdset);
 
... ... int do_client_loop(uint8_t *tox_id_str)
457 461 break; break;
458 462
459 463 case CLIENT_STATE_BIND_PORT: case CLIENT_STATE_BIND_PORT:
460 if(bind_sockfd < 0)
461 {
462 log_printf(L_ERROR, "Shutting down - could not bind to listening port\n");
463 state = CLIENT_STATE_SHUTDOWN;
464 }
465 else
464 LL_FOREACH(local_port_forwards, port_forward)
466 465 { {
467 state = CLIENT_STATE_FORWARDING;
466 if(port_forward->bind_sockfd < 0)
467 {
468 log_printf(L_ERROR, "Shutting down - could not bind to listening port %d\n", port_forward->local_port);
469 state = CLIENT_STATE_SHUTDOWN;
470 break;
471 }
472 else
473 {
474 state = CLIENT_STATE_FORWARDING;
475 }
468 476 } }
469 477 break; break;
470 478 case CLIENT_STATE_SETUP_PIPE: case CLIENT_STATE_SETUP_PIPE:
471 send_tunnel_request_packet(
472 remote_host,
473 remote_port,
474 friendnumber
475 );
479 LL_FOREACH(local_port_forwards, port_forward)
480 {
481 send_tunnel_request_packet(
482 port_forward->remote_host,
483 port_forward->remote_port,
484 friendnumber
485 );
486 }
476 487 state = CLIENT_STATE_FORWARDING; state = CLIENT_STATE_FORWARDING;
477 488 break; break;
478 489 case CLIENT_STATE_REQUEST_TUNNEL: case CLIENT_STATE_REQUEST_TUNNEL:
479 send_tunnel_request_packet(
480 remote_host,
481 remote_port,
482 friendnumber
483 );
490 LL_FOREACH(local_port_forwards, port_forward)
491 {
492 send_tunnel_request_packet(
493 port_forward->remote_host,
494 port_forward->remote_port,
495 friendnumber
496 );
497 }
484 498 state = CLIENT_STATE_WAIT_FOR_ACKTUNNEL; state = CLIENT_STATE_WAIT_FOR_ACKTUNNEL;
485 499 break; break;
486 500 case CLIENT_STATE_WAIT_FOR_ACKTUNNEL: case CLIENT_STATE_WAIT_FOR_ACKTUNNEL:
File gitversion.h changed (mode: 100644) (index fdb8a74..9dd48c6)
1 #define GITVERSION "0a8b0399cfac7873d350e4b2a90ec5203178922c"
1 #define GITVERSION "2e9e79947ecb9b62add1ff957d6b71a448d1d87b"
File main.c changed (mode: 100644) (index ed2020e..bd4215c)
... ... enum rules_policy_enum rules_policy = NONE;
45 45 rule *rules = NULL; rule *rules = NULL;
46 46
47 47 /* Ports and hostname for port forwarding */ /* Ports and hostname for port forwarding */
48 int remote_port = 0;
49 char *remote_host = NULL;
50 int local_port = 0;
48 local_port_forward *local_port_forwards = NULL;
51 49
52 50 /* Whether to daemonize/fork after startup */ /* Whether to daemonize/fork after startup */
53 51 int daemonize = 0; int daemonize = 0;
 
... ... int main(int argc, char *argv[])
1275 1273 switch(oc) switch(oc)
1276 1274 { {
1277 1275 case 'L': case 'L':
1276 local_port_forward *port_forward = calloc(sizeof(local_port_forward), 1);
1277
1278 if(!port_forward) {
1279 log_printf(L_ERROR, "Could not allocate memory for port forward\n");
1280 exit(1);
1281 }
1282
1278 1283 /* Local port forwarding */ /* Local port forwarding */
1279 1284 client_mode = 1; client_mode = 1;
1280 1285 client_local_port_mode = 1; client_local_port_mode = 1;
1281 if(parse_local_port_forward(optarg, &local_port, &remote_host, &remote_port) < 0)
1286
1287
1288 if(parse_local_port_forward(optarg, &(port_forward->local_port), &(port_forward->remote_host), &(port_forward->remote_port)) < 0)
1282 1289 { {
1283 1290 log_printf(L_ERROR, "Invalid value for -L option - use something like -L 22:127.0.0.1:22\n"); log_printf(L_ERROR, "Invalid value for -L option - use something like -L 22:127.0.0.1:22\n");
1284 1291 exit(1); exit(1);
1285 1292 } }
1293
1294 LL_APPEND(local_port_forwards, port_forward);
1295
1286 1296 if(min_log_level == L_UNSET) if(min_log_level == L_UNSET)
1287 1297 { {
1288 1298 min_log_level = L_INFO; min_log_level = L_INFO;
File main.h changed (mode: 100644) (index 17fb9b9..945049d)
... ... typedef struct protocol_frame_t {
79 79 uint8_t *data; uint8_t *data;
80 80 } protocol_frame; } protocol_frame;
81 81
82 /* A list of local port forwards (listen locally, forward to server */
83 typedef struct local_port_forward_t {
84 int local_port;
85 char *remote_host;
86 int remote_port;
87
88 /* Sock representing the local port - call accept() on it */
89 int bind_sockfd;
90
91 /* Client mode tunnel object for this port forward */
92 tunnel *tun;
93
94 struct local_port_forward_t *next;
95 } local_port_forward;
96
82 97 /* Rules policy */ /* Rules policy */
83 98 enum rules_policy_enum { VALIDATE, NONE }; enum rules_policy_enum { VALIDATE, NONE };
84 99 typedef struct rule { typedef struct rule {
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/gdr/tuntox

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/gdr/tuntox

Clone this repository using git:
git clone git://git.rocketgit.com/user/gdr/tuntox

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main