aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasaq- <tilt@techie.com>2019-01-30 20:04:08 +0000
committerMasaq- <tilt@techie.com>2019-01-30 20:04:08 +0000
commite5d53acbe1c11d9437648071f550d14e19439f01 (patch)
tree001efbdc536822e5d87e52c4baa02d85094181a6
parent0c249d89747d613ebe3d39a2467c08137349f668 (diff)
require authentication
-rw-r--r--src/pdesc.c1
-rw-r--r--src/pdesc.h1
-rw-r--r--src/pkt.c52
-rw-r--r--src/pkt.h4
4 files changed, 36 insertions, 22 deletions
diff --git a/src/pdesc.c b/src/pdesc.c
index af580e8..b39648f 100644
--- a/src/pdesc.c
+++ b/src/pdesc.c
@@ -114,6 +114,7 @@ proxy_desc_t *create_and_insert_proxy_desc(uint16_t id_no, uint16_t icmp_id,
cur->window_size = 64;
cur->ack_interval = 1.0;
cur->resend_interval = 1.5;
+ memset(cur->extended_options, 0, sizeof(cur->extended_options));
cur->send_ring = calloc(cur->window_size, sizeof(icmp_desc_t));
cur->recv_ring = calloc(cur->window_size, sizeof(forward_desc_t *));
return cur;
diff --git a/src/pdesc.h b/src/pdesc.h
index e8180fd..d4c463d 100644
--- a/src/pdesc.h
+++ b/src/pdesc.h
@@ -159,6 +159,7 @@ typedef struct proxy_desc_t {
uint16_t window_size;
double ack_interval;
double resend_interval;
+ uint16_t extended_options[3];
icmp_desc_t *send_ring;
forward_desc_t **recv_ring;
xfer_stats_t xfer;
diff --git a/src/pkt.c b/src/pkt.c
index e984aa9..410991d 100644
--- a/src/pkt.c
+++ b/src/pkt.c
@@ -181,6 +181,9 @@ void handle_packet(char *buf, unsigned bytes, int is_pcap, struct sockaddr_in *a
}
if (pt_pkt->data_len > 0) {
handle_data(pkt, bytes, 0, 0, 0, 0, cur, 0);
+ if (!opts.password) {
+ handle_extended_options(cur);
+ }
}
if (init_state == kProto_authenticate) {
pt_log(kLog_debug, "Sending authentication challenge..\n");
@@ -250,6 +253,7 @@ void handle_packet(char *buf, unsigned bytes, int is_pcap, struct sockaddr_in *a
cur->authenticated)
{
pt_log(kLog_verbose, "Remote end authenticated successfully.\n");
+ handle_extended_options(cur);
/* Authentication has succeeded, so now we can proceed
* to handle incoming TCP data.
*/
@@ -314,7 +318,7 @@ void handle_packet(char *buf, unsigned bytes, int is_pcap, struct sockaddr_in *a
* onto the passed-in receive ring.
*/
void handle_data(icmp_echo_packet_t *pkt, int total_len, forward_desc_t *ring[],
- int *await_send, int *insert_idx, uint16_t *next_expected_seq, void *cur, uint16_t window_size)
+ int *await_send, int *insert_idx, uint16_t *next_expected_seq, void *vcur, uint16_t window_size)
{
ping_tunnel_pkt_t *pt_pkt = (ping_tunnel_pkt_t*)pkt->data;
int expected_len = sizeof(ip_packet_t) + sizeof(icmp_echo_packet_t) +
@@ -343,32 +347,17 @@ void handle_data(icmp_echo_packet_t *pkt, int total_len, forward_desc_t *ring[],
*/
exit(0);
}
- if (cur) {
+ if (vcur) {
+ proxy_desc_t *cur = (proxy_desc_t *)vcur;
uint16_t *extended_options = (uint16_t *)pt_pkt->data;
if (pt_pkt->data_len >= 2) {
- extended_options[0] = ntohs(extended_options[0]);
- if (extended_options[0] > 0) {
- ((proxy_desc_t *)cur)->window_size = extended_options[0];
- free(((proxy_desc_t *)cur)->send_ring);
- free(((proxy_desc_t *)cur)->recv_ring);
- ((proxy_desc_t *)cur)->send_ring = calloc(((proxy_desc_t *)cur)->window_size, sizeof(icmp_desc_t));
- ((proxy_desc_t *)cur)->recv_ring = calloc(((proxy_desc_t *)cur)->window_size, sizeof(forward_desc_t *));
- pt_log(kLog_verbose, "Received extended option for window size %d \n", ((proxy_desc_t *)cur)->window_size);
- }
+ cur->extended_options[0] = ntohs(extended_options[0]);
}
if (pt_pkt->data_len >= 4) {
- extended_options[1] = ntohs(extended_options[1]);
- if (extended_options[1] > 0) {
- ((proxy_desc_t *)cur)->ack_interval = extended_options[1] / 1000.0;
- pt_log(kLog_verbose, "Received extended option for ack interval %f \n", ((proxy_desc_t *)cur)->ack_interval);
- }
+ cur->extended_options[1] = ntohs(extended_options[1]);
}
if (pt_pkt->data_len >= 6) {
- extended_options[2] = ntohs(extended_options[2]);
- if (extended_options[2] > 0) {
- ((proxy_desc_t *)cur)->resend_interval = extended_options[2] / 1000.0;
- pt_log(kLog_verbose, "Received extended option for resend interval %f \n", ((proxy_desc_t *)cur)->resend_interval);
- }
+ cur->extended_options[2] = ntohs(extended_options[2]);
}
return;
}
@@ -429,6 +418,27 @@ void handle_data(icmp_echo_packet_t *pkt, int total_len, forward_desc_t *ring[],
}
}
+void handle_extended_options(void *vcur)
+{
+ proxy_desc_t *cur = (proxy_desc_t *)vcur;
+ if (cur->extended_options[0] > 0) {
+ cur->window_size = cur->extended_options[0];
+ free(cur->send_ring);
+ free(cur->recv_ring);
+ cur->send_ring = calloc(cur->window_size, sizeof(icmp_desc_t));
+ cur->recv_ring = calloc(cur->window_size, sizeof(forward_desc_t *));
+ pt_log(kLog_verbose, "Received extended option for window size %d \n", cur->window_size);
+ }
+ if (cur->extended_options[1] > 0) {
+ cur->ack_interval = cur->extended_options[1] / 1000.0;
+ pt_log(kLog_verbose, "Received extended option for ack interval %f \n", cur->ack_interval);
+ }
+ if (cur->extended_options[2] > 0) {
+ cur->resend_interval = cur->extended_options[2] / 1000.0;
+ pt_log(kLog_verbose, "Received extended option for resend interval %f \n", cur->resend_interval);
+ }
+}
+
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)
diff --git a/src/pkt.h b/src/pkt.h
index f390737..8002f78 100644
--- a/src/pkt.h
+++ b/src/pkt.h
@@ -138,7 +138,9 @@ typedef struct icmp_desc_t icmp_desc_t;
void handle_packet(char *buf, unsigned bytes, int is_pcap, struct sockaddr_in *addr, int icmp_sock);
void handle_data(icmp_echo_packet_t *pkt, int total_len, forward_desc_t **ring,
- int *await_send, int *insert_idx, uint16_t *next_expected_seq, void *cur, uint16_t window_size);
+ int *await_send, int *insert_idx, uint16_t *next_expected_seq, void *vcur, uint16_t window_size);
+
+void handle_extended_options(void *vcur);
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,