Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


added network server files
[palacios.git] / misc / network_servers / vtl / test / vtl_ack.cc
1 #include "vtl_ack.h"
2
3
4 int make_ack_pkt(tcp_model_t * model, RawEthernetPacket * data_pkt, RawEthernetPacket * ack_pkt) {
5   unsigned long * seq_num_ptr ;
6   unsigned long seq_num = 0;
7   unsigned long rem_seq_num = 0;
8   unsigned long  payload_len = 0;
9   unsigned short tcp_hdr_len = 0;
10   unsigned long ack = 0;
11   unsigned long local_ts = 0;
12   unsigned short tcp_cksum = 0;
13   unsigned char ip_hdr_len = IP_HDR_LEN(pkt->data);
14   unsigned short ip_pkt_len = *(unsigned short *)(pkt->data + ETH_HDR_LEN + 2);
15   unsigned short ack_ip_pkt_len = *(unsigned short *)(ack_pkt->data + ETH_HDR_LEN + 2);
16   unsigned char ack_ip_hdr_len = IP_HDR_LEN(ack_pkt->data);
17
18   ip_pkt_len = ntohs(ip_pkt_len);
19   ack_ip_pkt_len = ntohs(ack_ip_pkt_len);
20
21   seq_num_ptr = (unsigned long *)(pkt->data + ETH_HDR_LEN + ip_hdr_len + 4);
22   seq_num = ntohl(*seq_num_ptr);
23   JRLDBG("Sequence Number = %lu\n", seq_num);
24
25   tcp_hdr_len = (*(pkt->data + ETH_HDR_LEN + ip_hdr_len + 12) & 0xf0) >> 2;
26
27   if (is_syn_pkt(pkt) == 1) {
28     ack = seq_num + 1;
29   } else {    
30     payload_len = ip_pkt_len  - (ip_hdr_len + tcp_hdr_len);
31     
32     JRLDBG("TCP Header Length = %hu\n", tcp_hdr_len);
33     JRLDBG("Payload Length = %lu\n", payload_len);
34     
35     ack = seq_num + payload_len;
36     JRLDBG("Ack Num = %lu\n", ack);
37   }
38
39   // Set IP id 
40   g_vtp_cons[vcon_i].ip_id--;
41   *(unsigned short *)(ack_pkt->data + ETH_HDR_LEN + 4) = htons(g_vtp_cons[vcon_i].ip_id);
42
43   // Recompute IP checksum
44   *(unsigned short *)(ack_pkt->data + ETH_HDR_LEN + 10) = 0;
45   *(unsigned short *)(ack_pkt->data + ETH_HDR_LEN + 10) = get_ip_checksum(ack_pkt);
46
47   //return 0;
48   // Set Sequence Number
49   rem_seq_num = htonl(g_vtp_cons[vcon_i].rem_seq_num);
50   *(unsigned long *)(ack_pkt->data + ETH_HDR_LEN + ack_ip_hdr_len + 4) = rem_seq_num;
51  
52   // Set ACK Number
53   ack = htonl(ack);
54   *(unsigned long *)(ack_pkt->data + ETH_HDR_LEN + ack_ip_hdr_len + 8) = ack;
55
56   // Set TCP Timestamp option
57   local_ts = get_tcp_timestamp(pkt->data + ETH_HDR_LEN + ack_ip_hdr_len + 20, tcp_hdr_len - 20);
58
59   /* We use this for debugging:
60    * If the TCPDump trace shows timestamps with the value of '5' then they are our packets
61    */
62   
63   *(unsigned long *)(ack_pkt->data + ETH_HDR_LEN + ack_ip_hdr_len + 24) = g_vtp_cons[vcon_i].tcp_timestamp;
64   //*(unsigned long *)(ack_pkt->data + ETH_HDR_LEN + ip_hdr_len + 24) = htonl(5);
65
66
67   *(unsigned long *)(ack_pkt->data + ETH_HDR_LEN + ack_ip_hdr_len + 28) = local_ts;
68
69   // Zero TCP chksum
70   *(unsigned short *)(ack_pkt->data + ETH_HDR_LEN + ack_ip_hdr_len + 16) = 0;
71
72   // Get TCP chksum
73   tcp_cksum = get_tcp_checksum(ack_pkt, ack_ip_pkt_len - ack_ip_hdr_len);
74
75   // Set TCP chksum
76   *(unsigned short *)(ack_pkt->data + ETH_HDR_LEN + ack_ip_hdr_len + 16) = tcp_cksum;
77
78
79 }