diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2020-01-28 23:53:41 +0100 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2020-01-28 23:53:41 +0100 |
commit | 596fee4002237651b741f1cef5f9d298423dbec7 (patch) | |
tree | 74b9d642b547f63c975319874e5e9f7e8cf2dc2b | |
parent | 0fcfc3a9acaff4d03ccf33fe411ab0bb441a0f41 (diff) | |
parent | 057bcf9b019c9aaec332d4a44eab93a991731a9a (diff) |
Merge branch 'master' of ssh://github.com/lnslbrty/ptunnel-ng
-rw-r--r-- | .gitlab-ci.yml | 2 | ||||
-rw-r--r-- | src/options.c | 1 | ||||
-rw-r--r-- | src/pkt.c | 100 | ||||
-rw-r--r-- | src/pkt.h | 4 | ||||
-rw-r--r-- | src/ptunnel.c | 2 |
5 files changed, 37 insertions, 72 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6bb6ce6..873d889 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -50,7 +50,7 @@ build-debian: when: always build-archlinux: - image: finalduty/archlinux:daily + image: archlinux/base:latest script: - useradd builduser -m - passwd -d builduser diff --git a/src/options.c b/src/options.c index ee8e249..69d842c 100644 --- a/src/options.c +++ b/src/options.c @@ -323,6 +323,7 @@ static void print_multiline(const char *prefix, const char *multiline) { const char *start, *end; start = multiline; + end = NULL; do { if (start) { end = strstr(start, sep); @@ -122,8 +122,9 @@ void handle_packet(char *buf, unsigned bytes, int is_pcap, struct sockaddr_in *a if (!is_pcap) cur->xfer.icmp_in++; } - else + else { type_flag = kProxy_flag; + } pkt_flag = pt_pkt->state & kFlag_mask; pt_pkt->state &= ~kFlag_mask; @@ -241,6 +242,7 @@ void handle_packet(char *buf, unsigned bytes, int is_pcap, struct sockaddr_in *a generate_response_md5(&challenge->plain, &challenge->digest); } + memcpy(cur->buf, challenge, sizeof(challenge_t)); queue_packet(icmp_sock, cur, cur->buf, sizeof(challenge_t), 0, 0, kProto_authenticate | cur->type_flag); /* We have authenticated locally. @@ -314,9 +316,7 @@ void handle_packet(char *buf, unsigned bytes, int is_pcap, struct sockaddr_in *a } handle_data(pkt, bytes, cur, 0); } - handle_ack((uint16_t)pt_pkt->ack, cur->send_ring, &cur->send_wait_ack, - 0, cur->send_idx, &cur->send_first_ack, &cur->remote_ack_val, - is_pcap, cur->window_size); + handle_ack(pt_pkt->ack, cur); cur->last_activity = now; } } @@ -385,8 +385,9 @@ void handle_data(icmp_echo_packet_t *pkt, int total_len, proxy_desc_t *cur, int cur->recv_wait_send++; cur->recv_idx++; } - else if (cur->recv_ring[cur->recv_idx]) + else { pt_log(kLog_debug, "Dup packet?\n"); + } cur->next_remote_seq++; if (cur->recv_idx >= cur->window_size) @@ -416,8 +417,9 @@ void handle_data(icmp_echo_packet_t *pkt, int total_len, proxy_desc_t *cur, int pos = (cur->recv_idx + d) % cur->window_size; } } - else if (cur->window_size && d < cur->window_size) + else if (cur->window_size && d < cur->window_size) { pos = (cur->recv_idx + d) % cur->window_size; + } if (pos != -1) { if (!cur->recv_ring[pos]) { @@ -428,9 +430,9 @@ void handle_data(icmp_echo_packet_t *pkt, int total_len, proxy_desc_t *cur, int cur->recv_wait_send++; } } - /* else - * pt_log(kLog_debug, "Packet discarded - outside receive window.\n"); - */ + else { + pt_log(kLog_info, "Packet discarded - outside receive window.\n"); + } } } @@ -461,68 +463,32 @@ void handle_extended_options(proxy_desc_t *cur) } } -void handle_ack(uint16_t seq_no, icmp_desc_t ring[], int *packets_awaiting_ack, - int one_ack_only, int insert_idx, int *first_ack, - uint16_t *remote_ack, int is_pcap, uint16_t window_size) +void handle_ack(uint32_t seq_no, proxy_desc_t *cur) { - int i, j, k; - ping_tunnel_pkt_t *pt_pkt; + if (cur->send_wait_ack > 0) { + int i, can_ack = 0, count = 0; + i = cur->send_idx - 1; + if (i < 0) + i = cur->window_size - 1; - if (*packets_awaiting_ack > 0) { - if (one_ack_only) { - for (i = 0; i < window_size; i++) { - if (ring[i].pkt && ring[i].seq_no == seq_no && !is_pcap) { - pt_log(kLog_debug, "Received ack for only seq %d\n", seq_no); - pt_pkt = (ping_tunnel_pkt_t*)ring[i].pkt->data; - /* WARNING: We make the dangerous assumption here that packets arrive in order! */ - *remote_ack = (uint16_t) ntohl(pt_pkt->ack); - free(ring[i].pkt); - ring[i].pkt = 0; - ring[i].pkt_len = 0; - (*packets_awaiting_ack)--; - if (i == *first_ack) { - for (j = 1; j < window_size; j += 2) { - k = (i + j) % window_size; - if (ring[k].pkt) { - *first_ack = k; - break; - } - /* we have looped through everything */ - if (k == i) - *first_ack = insert_idx; - } - } - return; - } + pt_log(kLog_debug, "Received ack-series starting at seq %d\n", seq_no); + while (count < cur->window_size) { + if (!cur->send_ring[i].pkt) + break; + if (cur->send_ring[i].seq_no == seq_no) + can_ack = 1; + else if (!can_ack) + cur->send_first_ack = i; + if (can_ack) { + free(cur->send_ring[i].pkt); + cur->send_ring[i].pkt = 0; + cur->send_ring[i].pkt_len = 0; + cur->send_wait_ack--; } - } - else { - int i, can_ack = 0, count = 0; - i = insert_idx-1; + i--; if (i < 0) - i = window_size - 1; - - pt_log(kLog_debug, "Received ack-series starting at seq %d\n", seq_no); - while (count < window_size) { - if (!ring[i].pkt) - break; - - if (ring[i].seq_no == seq_no) - can_ack = 1; - else if (!can_ack) - *first_ack = i; - - if (can_ack) { - free(ring[i].pkt); - ring[i].pkt = 0; - ring[i].pkt_len = 0; - (*packets_awaiting_ack)--; - } - i--; - if (i < 0) - i = window_size - 1; - count++; - } + i = cur->window_size - 1; + count++; } } else { @@ -142,8 +142,6 @@ void handle_data(icmp_echo_packet_t *pkt, int total_len, proxy_desc_t *cur, int void handle_extended_options(proxy_desc_t *cur); -void handle_ack(uint16_t seq_no, icmp_desc_t *ring, int *packets_awaiting_ack, - int one_ack_only, int insert_idx, int *first_ack, - uint16_t *remote_ack, int is_pcap, uint16_t window_size); +void handle_ack(uint32_t seq_no, proxy_desc_t *cur); #endif diff --git a/src/ptunnel.c b/src/ptunnel.c index dde63d3..a8c0a40 100644 --- a/src/ptunnel.c +++ b/src/ptunnel.c @@ -385,7 +385,7 @@ void pt_forwarder(void) { } } addr = dest_addr; - rand_id = (uint16_t) pt_random(); + rand_id = pt_random(); create_and_insert_proxy_desc(rand_id, rand_id, new_sock, &addr, opts.given_dst_ip, opts.given_dst_port, kProxy_start, kUser_flag); pthread_mutex_unlock(&num_threads_lock); } |