aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2020-03-12 21:05:36 +0100
committerToni Uhlig <matzeton@googlemail.com>2020-03-12 21:05:36 +0100
commitb43097ae53f5ce3cb4fc2c167e0625ce88e68e82 (patch)
tree8ba1a58de9238347a0f432b0e8483e6e6b6b5e7d
parentfcc8c6479f1c66091c9a21e2da20e85fdb3bdc4b (diff)
moved proxy descriptor search into getter function
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--src/pkt.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/pkt.c b/src/pkt.c
index 7b1a2c1..2ea8cff 100644
--- a/src/pkt.c
+++ b/src/pkt.c
@@ -188,6 +188,22 @@ static void handle_auth_response(unsigned bytes, int icmp_sock,
}
}
+static proxy_desc_t * get_proxy_descriptor(uint16_t id_no)
+{
+ proxy_desc_t * cur;
+
+ /* Find the relevant connection, if it exists */
+ pthread_mutex_lock(&chain_lock);
+ for (cur = chain; cur; cur = cur->next) {
+ if (cur->id_no == id_no) {
+ break;
+ }
+ }
+ pthread_mutex_unlock(&chain_lock);
+
+ return cur;
+}
+
/* handle_proxy_packet:
* Processes incoming ICMP packets for the proxy. The packet can come either from the
* packet capture lib, or from the actual socket or both.
@@ -230,13 +246,8 @@ void handle_packet(char * buf, unsigned bytes, int is_pcap, struct sockaddr_in *
pkt->seq = ntohs(pkt->seq);
pt_pkt->id_no = ntohs(pt_pkt->id_no);
pt_pkt->seq_no = ntohs(pt_pkt->seq_no);
- /* Find the relevant connection, if it exists */
- pthread_mutex_lock(&chain_lock);
- for (cur = chain; cur; cur = cur->next) {
- if (cur->id_no == pt_pkt->id_no)
- break;
- }
- pthread_mutex_unlock(&chain_lock);
+
+ cur = get_proxy_descriptor(pt_pkt->id_no);
/* Handle the packet if it comes from "the other end." This is a bit tricky
* to get right, since we receive both our own and the other end's packets.