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)
Multiple -L working a79c3fd655d045683f097675d9acb8e4d582c175 GDR! 2023-03-15 07:59:00
It buildsmake 8011c477ececd3cac58dafc5d54c1721d6550fce GDR! 2023-03-15 06:35:50
Cleanup 450509a24e93e855753f9c51dd04dde7e4ad7e3a GDR! 2023-03-14 20:02:33
Introduce local forward ID 71f125f17cd36582e0dc98e6bc9aca560e445c5a GDR! 2023-03-14 19:53:36
half way there 0250be7b29cceeaa0dd7b86ebcbf8f86b062b239 GDR! 2021-04-27 10:37:26
Clean indentation in client.c 972abf9b40a55b43ff3f1721f9d06bbb4abadf5f GDR! 2020-11-23 21:35:04
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
Commit a79c3fd655d045683f097675d9acb8e4d582c175 - Multiple -L working
Author: GDR!
Author date (UTC): 2023-03-15 07:59
Committer name: GDR!
Committer date (UTC): 2023-03-15 07:59
Parent(s): 8011c477ececd3cac58dafc5d54c1721d6550fce
Signer:
Signing key: 557FAEF4E8799852
Signing status: E
Tree: cbd8b637d8b110e52c3857af1395a92bd0434214
File Lines added Lines deleted
client.c 27 14
gitversion.h 1 1
main.c 7 5
main.h 5 4
File client.c changed (mode: 100644) (index e56cd90..5ef2980)
... ... int handle_acktunnel_frame(protocol_frame *rcvd_frame)
124 124 { {
125 125 uint32_t local_forward_id; uint32_t local_forward_id;
126 126 local_port_forward *forward; local_port_forward *forward;
127 tunnel *tun;
127 128
128 129 if(!client_mode) if(!client_mode)
129 130 { {
 
... ... int handle_acktunnel_frame(protocol_frame *rcvd_frame)
144 145
145 146 local_forward_id = INT32_AT((rcvd_frame->data), 0); local_forward_id = INT32_AT((rcvd_frame->data), 0);
146 147
148 log_printf(L_DEBUG2, "Got ACK tunnel frame for local forward %ld", local_forward_id);
149
147 150 forward = find_pending_forward_by_id(local_forward_id); forward = find_pending_forward_by_id(local_forward_id);
148 151 if(!forward) if(!forward)
149 152 { {
150 153 log_printf(L_WARNING, "Got ACK tunnel with wrong forward ID %ld", local_forward_id); log_printf(L_WARNING, "Got ACK tunnel with wrong forward ID %ld", local_forward_id);
151 154 return -1; return -1;
152 155 } }
153 LL_DELETE(pending_port_forwards, forward);
154 LL_APPEND(local_port_forwards, forward);
155 156
156 forward->tun = tunnel_create(
157 0, /* sockfd */
157 tun = tunnel_create(
158 forward->accept_sockfd, /* sockfd */
158 159 rcvd_frame->connid, rcvd_frame->connid,
159 160 rcvd_frame->friendnumber rcvd_frame->friendnumber
160 161 ); );
161 162
162 163 /* Mark that we can accept() another connection */ /* Mark that we can accept() another connection */
163 forward->tun->sockfd = -1;
164 forward->accept_sockfd = -1;
164 165
165 166 // printf("New tunnel ID: %d\n", tun->connid); // printf("New tunnel ID: %d\n", tun->connid);
166 167
167 168 if(client_local_port_mode || client_pipe_mode) if(client_local_port_mode || client_pipe_mode)
168 169 { {
169 update_select_nfds(forward->tun->sockfd);
170 FD_SET(forward->tun->sockfd, &client_master_fdset);
170 update_select_nfds(tun->sockfd);
171 FD_SET(tun->sockfd, &client_master_fdset);
171 172 if(client_local_port_mode) if(client_local_port_mode)
172 173 { {
173 log_printf(L_INFO, "Accepted a new connection on port %d\n", forward->local_port);
174 log_printf(L_INFO, "Accepted a new connection on port %d sockfd %d\n", forward->local_port);
174 175 } }
175 176 } }
176 177 else else
 
... ... int do_client_loop(uint8_t *tox_id_str)
348 349 if(connection_status != TOX_CONNECTION_NONE) if(connection_status != TOX_CONNECTION_NONE)
349 350 { {
350 351 state = CLIENT_STATE_CONNECTED; state = CLIENT_STATE_CONNECTED;
352 log_printf(L_DEBUG2, "Entered CLIENT_STATE_CONNECTED");
351 353 } }
352 354 break; break;
353 355 case CLIENT_STATE_CONNECTED: case CLIENT_STATE_CONNECTED:
 
... ... int do_client_loop(uint8_t *tox_id_str)
393 395 invitation_sent_time = time(NULL); invitation_sent_time = time(NULL);
394 396 invitations_sent++; invitations_sent++;
395 397 state = CLIENT_STATE_SENTREQUEST; state = CLIENT_STATE_SENTREQUEST;
398 log_printf(L_DEBUG2, "Entered CLIENT_STATE_SENTREQUEST");
396 399 log_printf(L_INFO, "Waiting for friend to accept us...\n"); log_printf(L_INFO, "Waiting for friend to accept us...\n");
397 400 } }
398 401 break; break;
 
... ... int do_client_loop(uint8_t *tox_id_str)
414 417 const char* status = readable_connection_status(friend_connection_status); const char* status = readable_connection_status(friend_connection_status);
415 418 log_printf(L_INFO, "Friend request accepted (%s)!\n", status); log_printf(L_INFO, "Friend request accepted (%s)!\n", status);
416 419 state = CLIENT_STATE_REQUEST_ACCEPTED; state = CLIENT_STATE_REQUEST_ACCEPTED;
420 log_printf(L_DEBUG2, "Entered CLIENT_STATE_REQUEST_ACCEPTED");
417 421 } }
418 422 else else
419 423 { {
 
... ... int do_client_loop(uint8_t *tox_id_str)
433 437 } }
434 438
435 439 state = CLIENT_STATE_CONNECTED; state = CLIENT_STATE_CONNECTED;
440 log_printf(L_DEBUG2, "Entered CLIENT_STATE_CONNECTED");
436 441 } }
437 442 } }
438 443 } }
 
... ... int do_client_loop(uint8_t *tox_id_str)
442 447 if(ping_mode) if(ping_mode)
443 448 { {
444 449 state = CLIENT_STATE_SEND_PING; state = CLIENT_STATE_SEND_PING;
450 log_printf(L_DEBUG2, "Entered CLIENT_STATE_SEND_PING");
445 451 } }
446 452 else if(client_pipe_mode) else if(client_pipe_mode)
447 453 { {
448 454 state = CLIENT_STATE_SETUP_PIPE; state = CLIENT_STATE_SETUP_PIPE;
455 log_printf(L_DEBUG2, "Entered CLIENT_STATE_SETUP_PIPE");
449 456 } }
450 457 else else
451 458 { {
452 459 state = CLIENT_STATE_BIND_PORT; state = CLIENT_STATE_BIND_PORT;
460 log_printf(L_DEBUG2, "Entered CLIENT_STATE_BIND_PORT");
453 461 } }
454 462 break; break;
455 463 case CLIENT_STATE_SEND_PING: case CLIENT_STATE_SEND_PING:
 
... ... int do_client_loop(uint8_t *tox_id_str)
472 480 if(custom_packet_error == TOX_ERR_FRIEND_CUSTOM_PACKET_OK) if(custom_packet_error == TOX_ERR_FRIEND_CUSTOM_PACKET_OK)
473 481 { {
474 482 state = CLIENT_STATE_PING_SENT; state = CLIENT_STATE_PING_SENT;
483 log_printf(L_DEBUG2, "Entered CLIENT_STATE_PING_SENT");
475 484 } }
476 485 else else
477 486 { {
 
... ... int do_client_loop(uint8_t *tox_id_str)
485 494 case CLIENT_STATE_BIND_PORT: case CLIENT_STATE_BIND_PORT:
486 495 LL_FOREACH(local_port_forwards, port_forward) LL_FOREACH(local_port_forwards, port_forward)
487 496 { {
497 log_printf(L_DEBUG2, "Processing local port %d", port_forward->local_port);
488 498 if(port_forward->bind_sockfd < 0) if(port_forward->bind_sockfd < 0)
489 499 { {
490 500 log_printf(L_ERROR, "Shutting down - could not bind to listening port %d\n", port_forward->local_port); log_printf(L_ERROR, "Shutting down - could not bind to listening port %d\n", port_forward->local_port);
491 501 state = CLIENT_STATE_SHUTDOWN; state = CLIENT_STATE_SHUTDOWN;
502 log_printf(L_DEBUG2, "Entered CLIENT_STATE_SHUTDOWN");
492 503 break; break;
493 504 } }
494 505 else else
495 506 { {
496 507 state = CLIENT_STATE_FORWARDING; state = CLIENT_STATE_FORWARDING;
508 log_printf(L_DEBUG2, "Entered CLIENT_STATE_FORWARDING");
497 509 } }
498 510 } }
499 511 break; break;
 
... ... int do_client_loop(uint8_t *tox_id_str)
508 520 ); );
509 521 } }
510 522 state = CLIENT_STATE_FORWARDING; state = CLIENT_STATE_FORWARDING;
523 log_printf(L_DEBUG2, "Entered CLIENT_STATE_FORWARDING");
511 524 break; break;
512 525 case CLIENT_STATE_REQUEST_TUNNEL: case CLIENT_STATE_REQUEST_TUNNEL:
513 526 LL_FOREACH(local_port_forwards, port_forward) LL_FOREACH(local_port_forwards, port_forward)
 
... ... int do_client_loop(uint8_t *tox_id_str)
522 535 state = CLIENT_STATE_WAIT_FOR_ACKTUNNEL; state = CLIENT_STATE_WAIT_FOR_ACKTUNNEL;
523 536 break; break;
524 537 case CLIENT_STATE_WAIT_FOR_ACKTUNNEL: case CLIENT_STATE_WAIT_FOR_ACKTUNNEL:
525 /* TODO REMOTE_L */
526 538 LL_FOREACH(local_port_forwards, port_forward) LL_FOREACH(local_port_forwards, port_forward)
527 539 { {
528 port_forward->tun->sockfd = 0;
540 port_forward->accept_sockfd = 0;
529 541 send_tunnel_request_packet( send_tunnel_request_packet(
530 542 port_forward->remote_host, port_forward->remote_host,
531 543 port_forward->remote_port, port_forward->remote_port,
 
... ... int do_client_loop(uint8_t *tox_id_str)
545 557 tv.tv_sec = 0; tv.tv_sec = 0;
546 558 tv.tv_usec = 20000; tv.tv_usec = 20000;
547 559 fds = client_master_fdset; fds = client_master_fdset;
548
549 /* TODO MULTIPLE_L loop over tunnels and sockfds */
560
550 561 /* Handle accepting new connections */ /* Handle accepting new connections */
551 562 LL_FOREACH(local_port_forwards, port_forward) LL_FOREACH(local_port_forwards, port_forward)
552 563 { {
553 564 if(!client_pipe_mode && if(!client_pipe_mode &&
554 port_forward->tun->sockfd <= 0) /* Don't accept if we're already waiting to establish a tunnel */
565 port_forward->accept_sockfd <= 0) /* Don't accept if we're already waiting to establish a tunnel */
555 566 { {
567 log_printf(L_DEBUG2, "FORWARDING: checking fd %d for local port %d", port_forward->bind_sockfd, port_forward->local_port);
556 568 accept_fd = accept(port_forward->bind_sockfd, NULL, NULL); accept_fd = accept(port_forward->bind_sockfd, NULL, NULL);
557 569 if(accept_fd != -1) if(accept_fd != -1)
558 570 { {
559 571 log_printf(L_INFO, "Accepting a new connection - requesting tunnel...\n"); log_printf(L_INFO, "Accepting a new connection - requesting tunnel...\n");
560 572
561 573 /* Open a new tunnel for this FD */ /* Open a new tunnel for this FD */
562 port_forward->tun->sockfd = accept_fd;
574 port_forward->accept_sockfd = accept_fd;
563 575 send_tunnel_request_packet( send_tunnel_request_packet(
564 576 port_forward->remote_host, port_forward->remote_host,
565 577 port_forward->remote_port, port_forward->remote_port,
 
... ... int do_client_loop(uint8_t *tox_id_str)
704 716 else else
705 717 { {
706 718 state = CLIENT_STATE_FORWARDING; state = CLIENT_STATE_FORWARDING;
719 log_printf(L_DEBUG2, "Entered CLIENT_STATE_FORWARDING");
707 720 } }
708 721 } }
709 722 } }
File gitversion.h changed (mode: 100644) (index 5de8342..1e38c13)
1 #define GITVERSION "450509a24e93e855753f9c51dd04dde7e4ad7e3a"
1 #define GITVERSION "8011c477ececd3cac58dafc5d54c1721d6550fce"
File main.c changed (mode: 100644) (index 6fccb63..4df4ab4)
... ... rule *rules = NULL;
46 46
47 47 /* Ports and hostname for port forwarding */ /* Ports and hostname for port forwarding */
48 48 local_port_forward *local_port_forwards = NULL; local_port_forward *local_port_forwards = NULL;
49 /* Non-acknowledged local port forwards */
50 local_port_forward *pending_port_forwards = NULL;
51 49 uint32_t last_forward_id; uint32_t last_forward_id;
52 50
53 51 /* Whether to daemonize/fork after startup */ /* Whether to daemonize/fork after startup */
 
... ... local_port_forward *find_pending_forward_by_id(uint32_t local_forward_id)
213 211 { {
214 212 local_port_forward *forward; local_port_forward *forward;
215 213
216 LL_FOREACH(pending_port_forwards, forward)
214 LL_FOREACH(local_port_forwards, forward)
217 215 { {
218 216 if(forward->forward_id == local_forward_id) if(forward->forward_id == local_forward_id)
219 217 { {
 
... ... void parse_lossless_packet(Tox *tox, uint32_t friendnumber, const uint8_t *data,
689 687 if(data[0] != PROTOCOL_MAGIC_HIGH || data[1] != PROTOCOL_MAGIC_LOW) if(data[0] != PROTOCOL_MAGIC_HIGH || data[1] != PROTOCOL_MAGIC_LOW)
690 688 { {
691 689 log_printf(L_WARNING, "Received data frame with invalid protocol magic number 0x%x%x\n", data[0], data[1]); log_printf(L_WARNING, "Received data frame with invalid protocol magic number 0x%x%x\n", data[0], data[1]);
690 if(data[0] == (PROTOCOL_MAGIC_V1 >> 8) && data[1] == (PROTOCOL_MAGIC_V1 & 0xff))
691 {
692 log_printf(L_ERROR, "Tuntox on the other end uses old protocol version 1. Please upgrade it.");
693 }
692 694 return; return;
693 695 } }
694 696
 
... ... int main(int argc, char *argv[])
1347 1349 exit(1); exit(1);
1348 1350 } }
1349 1351
1350 LL_APPEND(pending_port_forwards, port_forward);
1352 LL_APPEND(local_port_forwards, port_forward);
1351 1353
1352 1354 if(min_log_level == L_UNSET) if(min_log_level == L_UNSET)
1353 1355 { {
 
... ... int main(int argc, char *argv[])
1369 1371 { {
1370 1372 min_log_level = L_ERROR; min_log_level = L_ERROR;
1371 1373 } }
1372 LL_APPEND(pending_port_forwards, port_forward);
1374 LL_APPEND(local_port_forwards, port_forward);
1373 1375 log_printf(L_INFO, "Forwarding remote port %d to stdin/out\n", port_forward->remote_port); log_printf(L_INFO, "Forwarding remote port %d to stdin/out\n", port_forward->remote_port);
1374 1376 break; break;
1375 1377 case 'p': case 'p':
File main.h changed (mode: 100644) (index e046990..5a97c4b)
27 27
28 28
29 29 #define PROTOCOL_MAGIC_V1 0xa26a #define PROTOCOL_MAGIC_V1 0xa26a
30 #define PROTOCOL_MAGIC PROTOCOL_MAGIC_V1
30 #define PROTOCOL_MAGIC_V2 0xa26b
31 #define PROTOCOL_MAGIC PROTOCOL_MAGIC_V2
31 32 #define PROTOCOL_MAGIC_HIGH (PROTOCOL_MAGIC >> 8) #define PROTOCOL_MAGIC_HIGH (PROTOCOL_MAGIC >> 8)
32 33 #define PROTOCOL_MAGIC_LOW (PROTOCOL_MAGIC & 0xff) #define PROTOCOL_MAGIC_LOW (PROTOCOL_MAGIC & 0xff)
33 34 #define PACKET_TYPE_PONG 0x0100 #define PACKET_TYPE_PONG 0x0100
 
... ... typedef struct local_port_forward_t {
91 92 /* Sock representing the local port - call accept() on it */ /* Sock representing the local port - call accept() on it */
92 93 int bind_sockfd; int bind_sockfd;
93 94
94 /* Client mode tunnel object for this port forward */
95 tunnel *tun;
95 /* If tunnel open is pending, accepted sockfd is temporarly stored here */
96 /* -1 = we can accept another connection */
97 int accept_sockfd;
96 98
97 99 /* When the forward has been created - used in ack timeouts */ /* When the forward has been created - used in ack timeouts */
98 100 time_t created; time_t created;
 
... ... extern int select_nfds;
137 139 extern tunnel *by_id; extern tunnel *by_id;
138 140
139 141 extern local_port_forward *local_port_forwards; extern local_port_forward *local_port_forwards;
140 extern local_port_forward *pending_port_forwards;
141 142
142 143 local_port_forward *find_pending_forward_by_id(uint32_t local_forward_id); local_port_forward *find_pending_forward_by_id(uint32_t local_forward_id);
143 144
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