aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2019-12-03 23:37:49 +0100
committerToni Uhlig <matzeton@googlemail.com>2019-12-03 23:37:49 +0100
commiteb00e46daf4c41764c005fc35245a67d116d3aae (patch)
tree727b6a22fbb417f0652a943ae471cb97b3ae5339
parent9af622e80841e3c5d56006801f47ce9062cf488d (diff)
reduced function signature and removed dead code in acknowledge handling
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--src/pkt.c84
-rw-r--r--src/pkt.h4
2 files changed, 24 insertions, 64 deletions
diff --git a/src/pkt.c b/src/pkt.c
index 0dae386..485ed72 100644
--- a/src/pkt.c
+++ b/src/pkt.c
@@ -315,9 +315,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((uint16_t)pt_pkt->ack, cur);
cur->last_activity = now;
}
}
@@ -463,68 +461,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(uint16_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 {
diff --git a/src/pkt.h b/src/pkt.h
index 0b7ee65..c400aed 100644
--- a/src/pkt.h
+++ b/src/pkt.h
@@ -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(uint16_t seq_no, proxy_desc_t *cur);
#endif