summaryrefslogtreecommitdiff
path: root/src/ptunnel.c
diff options
context:
space:
mode:
authorMasaq- <tilt@techie.com>2019-01-28 02:34:32 +0000
committerMasaq- <tilt@techie.com>2019-01-28 02:34:32 +0000
commit0c249d89747d613ebe3d39a2467c08137349f668 (patch)
tree87e98da359f4e76517c34176f5ac39e715769498 /src/ptunnel.c
parent8a7a9a83ae7b15755cf7c459872670abca4cbd14 (diff)
extend the protocol to load options from the data section
Diffstat (limited to 'src/ptunnel.c')
-rw-r--r--src/ptunnel.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/ptunnel.c b/src/ptunnel.c
index 8766acf..6f9fdc7 100644
--- a/src/ptunnel.c
+++ b/src/ptunnel.c
@@ -536,7 +536,7 @@ void* pt_proxy(void *args) {
* room in our send window AND we either don't use a password, or
* have been authenticated.
*/
- if (cur->sock && cur->send_wait_ack < kPing_window_size &&
+ if (cur->sock && cur->send_wait_ack < cur->window_size &&
(!opts.password || cur->authenticated))
{
FD_SET(cur->sock, &set);
@@ -558,10 +558,14 @@ void* pt_proxy(void *args) {
if (cur->state == kProxy_start) {
pt_log(kLog_verbose, "Sending proxy request.\n");
cur->last_ack = time_as_double();
- queue_packet(fwd_sock, cur->pkt_type, 0, 0, cur->id_no, cur->id_no,
+ uint16_t extended_options[3];
+ extended_options[0] = htons(cur->window_size);
+ extended_options[1] = htons(cur->ack_interval*1000);
+ extended_options[2] = htons(cur->resend_interval*1000);
+ queue_packet(fwd_sock, cur->pkt_type, (char *)extended_options, sizeof(extended_options), cur->id_no, cur->id_no,
&cur->my_seq, cur->send_ring, &cur->send_idx, &cur->send_wait_ack,
cur->dst_ip, cur->dst_port, cur->state | cur->type_flag,
- &cur->dest_addr, cur->next_remote_seq, &cur->send_first_ack, &cur->ping_seq);
+ &cur->dest_addr, cur->next_remote_seq, &cur->send_first_ack, &cur->ping_seq, cur->window_size);
cur->xfer.icmp_out++;
cur->state = kProto_data;
}
@@ -591,7 +595,7 @@ void* pt_proxy(void *args) {
queue_packet(fwd_sock, cur->pkt_type, cur->buf, bytes, cur->id_no,
cur->icmp_id, &cur->my_seq, cur->send_ring, &cur->send_idx,
&cur->send_wait_ack, 0, 0, cur->state | cur->type_flag,
- &cur->dest_addr, cur->next_remote_seq, &cur->send_first_ack, &cur->ping_seq);
+ &cur->dest_addr, cur->next_remote_seq, &cur->send_first_ack, &cur->ping_seq, cur->window_size);
}
prev = cur;
tmp = cur->next;
@@ -622,11 +626,11 @@ void* pt_proxy(void *args) {
continue;
}
if (cur->recv_wait_send && cur->sock)
- cur->xfer.bytes_in += send_packets(cur->recv_ring, &cur->recv_xfer_idx, &cur->recv_wait_send, &cur->sock);
+ cur->xfer.bytes_in += send_packets(cur->recv_ring, &cur->recv_xfer_idx, &cur->recv_wait_send, &cur->sock, cur->window_size);
/* Check for any icmp packets requiring resend, and resend _only_ the first packet. */
idx = cur->send_first_ack;
- if (cur->send_ring[idx].pkt && cur->send_ring[idx].last_resend+kResend_interval < now) {
+ if (cur->send_ring[idx].pkt && cur->send_ring[idx].last_resend+cur->resend_interval < now) {
pt_log(kLog_debug, "Resending packet with seq-no %d.\n", cur->send_ring[idx].seq_no);
cur->send_ring[idx].last_resend = now;
cur->send_ring[idx].pkt->seq = htons(cur->ping_seq);
@@ -639,14 +643,14 @@ void* pt_proxy(void *args) {
cur->xfer.icmp_resent++;
}
/* Figure out if it's time to send an explicit acknowledgement */
- if (cur->last_ack+1.0 < now && cur->send_wait_ack < kPing_window_size &&
+ if (cur->last_ack+cur->ack_interval < now && cur->send_wait_ack < cur->window_size &&
cur->remote_ack_val+1 != cur->next_remote_seq)
{
cur->last_ack = now;
queue_packet(fwd_sock, cur->pkt_type, 0, 0, cur->id_no, cur->icmp_id,
&cur->my_seq, cur->send_ring, &cur->send_idx, &cur->send_wait_ack,
cur->dst_ip, cur->dst_port, kProto_ack | cur->type_flag,
- &cur->dest_addr, cur->next_remote_seq, &cur->send_first_ack, &cur->ping_seq);
+ &cur->dest_addr, cur->next_remote_seq, &cur->send_first_ack, &cur->ping_seq, cur->window_size);
cur->xfer.icmp_ack_out++;
}
}
@@ -794,10 +798,10 @@ void send_termination_msg(proxy_desc_t *cur, int icmp_sock) {
queue_packet(icmp_sock, cur->pkt_type, 0, 0, cur->id_no, cur->icmp_id, &cur->my_seq,
cur->send_ring, &cur->send_idx, &cur->send_wait_ack, 0, 0,
kProto_close | cur->type_flag, &cur->dest_addr, cur->next_remote_seq,
- &cur->send_first_ack, &cur->ping_seq);
+ &cur->send_first_ack, &cur->ping_seq, cur->window_size);
queue_packet(icmp_sock, cur->pkt_type, 0, 0, cur->id_no, cur->icmp_id, &cur->my_seq,
cur->send_ring, &cur->send_idx, &cur->send_wait_ack, 0, 0,
kProto_close | cur->type_flag, &cur->dest_addr, cur->next_remote_seq,
- &cur->send_first_ack, &cur->ping_seq);
+ &cur->send_first_ack, &cur->ping_seq, cur->window_size);
cur->xfer.icmp_out += 2;
}