Browse Source

re-enabled and improved logging of packet headers and payload (SEND)

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Toni Uhlig 2 years ago
parent
commit
011c923648
3 changed files with 11 additions and 6 deletions
  1. 7 1
      src/pdesc.c
  2. 1 1
      src/pdesc.h
  3. 3 4
      src/pkt.c

+ 7 - 1
src/pdesc.c

@@ -60,7 +60,7 @@
 proxy_desc_t *create_and_insert_proxy_desc(uint16_t id_no, uint16_t icmp_id,
                                            int sock, struct sockaddr_in *addr,
 			                               uint32_t dst_ip, uint32_t dst_port,
-                                           uint32_t init_state, uint32_t type) {
+                                           uint32_t init_state, enum pkt_flag type) {
 	proxy_desc_t *cur;
 
 	pthread_mutex_lock(&chain_lock);
@@ -243,6 +243,12 @@ int queue_packet(int sock_fd, proxy_desc_t *cur, char *buf, size_t bufsiz,
 	                      cur->my_seq, state_name[state & (~kFlag_mask)],
 	                      ack_val, cur->pkt_type,
 	                      ((state & kUser_flag) == kUser_flag ? "yes" : "no"));
+    log_sendrecv_hexstr("SEND ICMP", pkt, sizeof(*pkt));
+    log_sendrecv_hexstr("SEND PTNG", pt_pkt, sizeof(*pt_pkt));
+    if (pkt_len - (pt_pkt->data - (char *)pkt) > 0) {
+        log_sendrecv_hexstr("SEND PAYL", pt_pkt->data, pkt_len - (pt_pkt->data - (char *)pkt));
+    }
+
 	err  = sendto(sock_fd, (const void*)pkt, pkt_len, 0,
 	              (struct sockaddr*)&cur->dest_addr, sizeof(struct sockaddr));
 	if (err < 0) {

+ 1 - 1
src/pdesc.h

@@ -172,7 +172,7 @@ proxy_desc_t * create_and_insert_proxy_desc(uint16_t id_no,
                                             uint32_t dst_ip,
                                             uint32_t dst_port,
                                             uint32_t init_state,
-                                            uint32_t type);
+                                            enum pkt_flag type);
 
 void remove_proxy_desc(proxy_desc_t * cur, proxy_desc_t * prev);
 

+ 3 - 4
src/pkt.c

@@ -237,7 +237,7 @@ void handle_packet(char * buf, unsigned bytes, int is_pcap, struct sockaddr_in *
     }
 
     if (opts.udp || opts.unprivileged) {
-        ip_pkt = 0;
+        ip_pkt = NULL;
         pkt = (icmp_echo_packet_t *)buf;
         pt_pkt = (ping_tunnel_pkt_t *)pkt->data;
     } else {
@@ -297,9 +297,8 @@ void handle_packet(char * buf, unsigned bytes, int is_pcap, struct sockaddr_in *
            is_pcap);
     log_sendrecv_hexstr("RECV ICMP", pkt, sizeof(*pkt));
     log_sendrecv_hexstr("RECV PTNG", pt_pkt, sizeof(*pt_pkt));
-    if (bytes > sizeof(icmp_echo_packet_t) + sizeof(ping_tunnel_pkt_t)) {
-        log_sendrecv_hexstr("RECV PAYL", buf + sizeof(icmp_echo_packet_t) + sizeof(ping_tunnel_pkt_t),
-                                         bytes - sizeof(icmp_echo_packet_t) - sizeof(ping_tunnel_pkt_t));
+    if (bytes - (pt_pkt->data - buf) > 0) {
+        log_sendrecv_hexstr("RECV PAYL", pt_pkt->data, bytes - (pt_pkt->data - buf));
     }
 
     /* This test essentially verifies that the packet comes from someone who isn't us. */