slitheen-proxy.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /* Name: slitheen-proxy.c
  2. * Author: Cecylia Bocovich
  3. *
  4. * This code runs the main functions for the Slitheen relay station to tap and
  5. * modify data.
  6. *
  7. */
  8. #include <pcap.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <unistd.h>
  12. #include <string.h>
  13. #include <pthread.h>
  14. #include <sys/ioctl.h>
  15. #include <net/if.h>
  16. #include <openssl/ssl.h>
  17. #include "util.h"
  18. #include "flow.h"
  19. #include "slitheen.h"
  20. #include "relay.h"
  21. #include "crypto.h"
  22. #include "cryptothread.h"
  23. void save_packet(flow *f, struct packet_info *info);
  24. void update_window_expiration(flow *f, struct packet_info *info);
  25. void retransmit(flow *f, struct packet_info *info, uint32_t data_to_fill);
  26. void usage(void){
  27. printf("Usage: slitheen-proxy [internal network interface] [NAT interface]\n");
  28. }
  29. int main(int argc, char *argv[]){
  30. pthread_t t1, t2;
  31. char *dev1 = NULL; /* Device that leads to the internal network */
  32. char *dev2 = NULL; /* Device that leads out to the world */
  33. struct sniff_args outbound;
  34. struct sniff_args inbound;
  35. if (argc != 3) {
  36. usage();
  37. return(2);
  38. }
  39. dev1 = argv[1];
  40. dev2 = argv[2];
  41. if(init_tables()){
  42. exit(1);
  43. }
  44. if(init_session_cache()){
  45. exit(1);
  46. }
  47. init_crypto_locks();
  48. /* Create threads */
  49. outbound.readdev = dev1;
  50. outbound.writedev = dev2;
  51. inbound.readdev = dev2;
  52. inbound.writedev = dev1;
  53. pthread_create(&t1, NULL, sniff_packets, (void *) &outbound);
  54. pthread_create(&t2, NULL, sniff_packets, (void *) &inbound);
  55. pthread_join(t1, NULL);
  56. pthread_join(t2, NULL);
  57. pthread_exit(NULL);
  58. crypto_locks_cleanup();
  59. return(0);
  60. }
  61. void *sniff_packets(void *args){
  62. pcap_t *rd_handle;
  63. pcap_t *wr_handle;
  64. char rd_errbuf[BUFSIZ];
  65. char wr_errbuf[BUFSIZ];
  66. uint8_t MAC[ETHER_ADDR_LEN];
  67. bpf_u_int32 mask;
  68. bpf_u_int32 net;
  69. char *readdev, *writedev;
  70. struct sniff_args *arg_st = (struct sniff_args *) args;
  71. readdev = arg_st->readdev;
  72. writedev = arg_st->writedev;
  73. //Find MAC address of each interface
  74. struct ifreq ifr;
  75. int s = socket(AF_INET, SOCK_DGRAM, 0);
  76. strcpy(ifr.ifr_name, writedev);
  77. ioctl(s, SIOCGIFHWADDR, &ifr);
  78. memcpy(MAC, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
  79. close(s);
  80. if (pcap_lookupnet(readdev, &net, &mask, rd_errbuf) == -1){
  81. fprintf(stderr, "Can't get netmask for device %s\n", readdev);
  82. exit(2);
  83. }
  84. rd_handle = pcap_open_live(readdev, BUFSIZ, 0, 0, rd_errbuf);
  85. if (rd_handle == NULL){
  86. fprintf(stderr, "Couldn't open device %s: %s\n", readdev, rd_errbuf);
  87. }
  88. if(pcap_datalink(rd_handle) != DLT_EN10MB) {
  89. fprintf(stderr, "Device %s does not provide Ethernet headers - not supported\n", readdev);
  90. exit(2);
  91. }
  92. if(pcap_setdirection(rd_handle, PCAP_D_IN)){
  93. fprintf(stderr, "Platform does not support write direction. Update filters with MAC address\n");
  94. exit(2);
  95. }
  96. wr_handle = pcap_open_live(writedev, BUFSIZ, 0, 0, wr_errbuf);
  97. if (wr_handle == NULL){
  98. fprintf(stderr, "Couldn't open device %s: %s\n", writedev, wr_errbuf);
  99. }
  100. struct inject_args iargs;
  101. iargs.mac_addr = MAC;
  102. iargs.write_dev = wr_handle;
  103. /*callback function*/
  104. pcap_loop(rd_handle, -1, got_packet, (unsigned char *) &iargs);
  105. /*Sniff a packet*/
  106. pcap_close(rd_handle);
  107. return NULL;
  108. }
  109. /*
  110. * Injects a packet back out the opposite interface
  111. */
  112. void inject_packet(struct inject_args *iargs, const struct pcap_pkthdr *header, uint8_t *packet){
  113. pcap_t *handle = iargs->write_dev;
  114. //write back out to the MAC ADDR it came in on
  115. memmove(packet, packet+ETHER_ADDR_LEN, ETHER_ADDR_LEN);
  116. memcpy(packet+ETHER_ADDR_LEN, iargs->mac_addr, ETHER_ADDR_LEN);
  117. if((pcap_inject(handle, packet, header->len)) < 0 ){
  118. fprintf(stderr, "Error: %s\n", pcap_geterr(handle));
  119. printf("Length: %d\n", header->len);
  120. }
  121. #ifdef DEBUG
  122. fprintf(stderr, "injected the following packet:\n");
  123. for(int i=0; i< header->len; i++){
  124. fprintf(stderr, "%02x ", packet[i]);
  125. }
  126. fprintf(stderr, "\n");
  127. #endif
  128. free(packet);
  129. }
  130. /**
  131. * Runs when pcap_loop receives a packet from the specified interface
  132. * If the received packet is a tcp packet, processes it and then writes it back out
  133. * to the interface
  134. *
  135. */
  136. void got_packet(uint8_t *args, const struct pcap_pkthdr *header, const uint8_t *packet){
  137. struct inject_args *iargs = (struct inject_args *) args;
  138. uint8_t *tmp_packet = emalloc(header->len);
  139. memcpy(tmp_packet, packet, header->len);
  140. process_packet(iargs, header, tmp_packet);
  141. }
  142. /* This function receives a full ip packet and then:
  143. * 1) identifies the flow
  144. * 2) adds the packet to the flow's data chain
  145. * 3) updates the flow's state
  146. */
  147. void process_packet(struct inject_args *iargs, const struct pcap_pkthdr *header, uint8_t *packet){
  148. struct packet_info *info = emalloc(sizeof(struct packet_info));
  149. extract_packet_headers(packet, info);
  150. //Ignore non-TCP packets (shouldn't actually get any)
  151. if((info->ip_hdr == NULL) || (info->tcp_hdr == NULL)){
  152. free(info);
  153. free(packet);
  154. return;
  155. }
  156. /* Checks to see if this is a possibly tagged hello msg */
  157. if ((info->record_hdr != NULL) && (info->record_hdr->type == HS)){ /* This is a TLS handshake */
  158. check_handshake(info);
  159. }
  160. /* Now if flow is in table, update state */
  161. flow *observed;
  162. if((observed = check_flow(info)) != NULL){
  163. #ifdef DEBUG
  164. /*Check sequence number and replay application data if necessary*/
  165. fprintf(stdout,"Flow: %x:%d > %x:%d (%s)\n", info->ip_hdr->src.s_addr, ntohs(info->tcp_hdr->src_port), info->ip_hdr->dst.s_addr, ntohs(info->tcp_hdr->dst_port), (info->ip_hdr->src.s_addr != observed->src_ip.s_addr)? "incoming":"outgoing");
  166. fprintf(stdout,"ID number: %u\n", htonl(info->ip_hdr->id));
  167. fprintf(stdout,"Sequence number: %u\n", htonl(info->tcp_hdr->sequence_num));
  168. fprintf(stdout,"Acknowledgement number: %u\n", htonl(info->tcp_hdr->ack_num));
  169. #endif
  170. uint8_t incoming = (info->ip_hdr->src.s_addr != observed->src_ip.s_addr)? 1 : 0;
  171. uint32_t seq_num = htonl(info->tcp_hdr->sequence_num);
  172. uint32_t expected_seq = (incoming)? observed->downstream_seq_num : observed->upstream_seq_num;
  173. #ifdef DEBUG
  174. fprintf(stdout,"Expected sequence number: %u\n", expected_seq);
  175. #endif
  176. /* Remove acknowledged data from queue after TCP window is exceeded */
  177. update_window_expiration(observed, info);
  178. /* fill with retransmit data, process new data */
  179. uint32_t data_to_fill;
  180. uint32_t data_to_process;
  181. if(seq_num > expected_seq){
  182. data_to_process = info->app_data_len;
  183. data_to_fill = 0;
  184. } else if (seq_num + info->app_data_len > expected_seq){
  185. data_to_fill = expected_seq - seq_num;
  186. data_to_process = seq_num + info->app_data_len - expected_seq;
  187. } else {
  188. data_to_fill = info->app_data_len;
  189. data_to_process = 0;
  190. }
  191. uint8_t *p = info->app_data;
  192. if(data_to_fill){ //retransmit
  193. printf("Retransmiting data (%u:%u)\n", seq_num, seq_num + info->app_data_len);
  194. retransmit(observed, info, data_to_fill);
  195. }
  196. p += data_to_fill;
  197. if(data_to_process){
  198. if(p != info->app_data){
  199. printf("UH OH something weird might happen\n");
  200. }
  201. if(observed->application){
  202. if(seq_num > expected_seq){
  203. //For now, enters into FORFEIT state
  204. //TODO: change upstream behaviour to try to mask slitheen hdr
  205. //printf("ERROR: future packet in app data, forfeiting flow\n");
  206. remove_flow(observed);
  207. goto err;
  208. }
  209. replace_packet(observed, info);
  210. } else {
  211. //We're still in the TLS handshake; hold packets misordered packets
  212. if(seq_num > expected_seq){
  213. //Delay and process later
  214. frame *new_frame = ecalloc(1, sizeof(frame));
  215. new_frame->iargs = iargs;
  216. new_frame->packet = packet;
  217. new_frame->header = header;
  218. new_frame->seq_num = seq_num;
  219. new_frame->next = NULL;
  220. frame_queue *queue = (incoming) ? observed->ds_frame_queue : observed->us_frame_queue;
  221. printf("Delay processing of frame (seq = %u )\n", seq_num);
  222. //add to end of list
  223. if(queue->first_frame == NULL){
  224. queue->first_frame = new_frame;
  225. } else {
  226. frame *last = queue->first_frame;
  227. while(last->next != NULL){
  228. last = last->next;
  229. }
  230. last->next = new_frame;
  231. }
  232. free(info);
  233. observed->ref_ctr--;
  234. printf("Misordered packet. %p ref_ctr %d\n", observed, observed->ref_ctr);
  235. return; //TODO: fix terrible spaghetti returns
  236. }
  237. /* Pass data to packet chain */
  238. if(observed->stall){
  239. }
  240. if(add_packet(observed, info)){//removed_flow
  241. goto err;
  242. }
  243. }
  244. /* Update TCP state */
  245. if(info->tcp_hdr->flags & (FIN | RST) ){
  246. /* Remove flow from table, connection ended */
  247. remove_flow(observed);
  248. goto err;
  249. }
  250. /* add packet to application data queue */
  251. save_packet(observed, info);
  252. }
  253. /*process and release held frames with current sequence numbers*/
  254. frame_queue *queue = (incoming) ? observed->ds_frame_queue : observed->us_frame_queue;
  255. frame *first = queue->first_frame;
  256. frame *prev = queue->first_frame;
  257. expected_seq = (incoming)? observed->downstream_seq_num : observed->upstream_seq_num;
  258. while (first != NULL){
  259. if(first->seq_num <= expected_seq){
  260. //remove from queue and process
  261. if(first == queue->first_frame) {
  262. queue->first_frame = first->next;
  263. } else {
  264. prev->next = first->next;
  265. }
  266. printf("Now processing frame (seq = %u )\n", first->seq_num);
  267. process_packet(iargs, first->header, first->packet);
  268. free(first);
  269. first = queue->first_frame;
  270. prev = queue->first_frame;
  271. } else {
  272. prev = first;
  273. first = first->next;
  274. }
  275. }
  276. observed->ref_ctr--;
  277. printf("Finished processing packet. %p ref_ctr %d\n", observed, observed->ref_ctr);
  278. }
  279. err:
  280. free(info);//Note: don't free this while a thread is using it
  281. inject_packet(iargs, header, packet);
  282. return;
  283. }
  284. //TODO: rewrite this function to remove bloat
  285. void save_packet(flow *f, struct packet_info *info){
  286. uint8_t incoming = (info->ip_hdr->src.s_addr != f->src_ip.s_addr)? 1 : 0;
  287. uint32_t seq_num = htonl(info->tcp_hdr->sequence_num);
  288. //add new app block
  289. packet *new_block = ecalloc(1, sizeof(packet));
  290. new_block->seq_num = htonl(info->tcp_hdr->sequence_num);
  291. new_block->data = ecalloc(1, info->app_data_len);
  292. memcpy(new_block->data, info->app_data, info->app_data_len);
  293. new_block->len = info->app_data_len;
  294. new_block->next = NULL;
  295. new_block->expiration = 0;
  296. packet *saved_data = (incoming)? f->downstream_app_data->first_packet :
  297. f->upstream_app_data->first_packet;
  298. //put app data block in queue
  299. if(saved_data == NULL){
  300. if(incoming){
  301. f->downstream_app_data->first_packet = new_block;
  302. if(new_block->seq_num ==
  303. f->downstream_seq_num){
  304. f->downstream_seq_num += new_block->len;
  305. #ifdef DEBUG
  306. printf("Updated downstream expected seqnum to %u\n",
  307. f->downstream_seq_num );
  308. #endif
  309. }
  310. } else {
  311. f->upstream_app_data->first_packet = new_block;
  312. if(new_block->seq_num ==
  313. f->upstream_seq_num){
  314. f->upstream_seq_num += new_block->len;
  315. #ifdef DEBUG
  316. printf("Updated upstream expected seqnum to %u\n",
  317. f->upstream_seq_num );
  318. #endif
  319. }
  320. }
  321. } else {
  322. uint8_t saved = 0;
  323. while(saved_data->next != NULL){
  324. if(!saved && (saved_data->next->seq_num > seq_num)){
  325. new_block->next = saved_data->next;
  326. saved_data->next = new_block;
  327. saved = 1;
  328. }
  329. //update expected sequence number
  330. if(incoming){
  331. if(saved_data->next->seq_num ==
  332. f->downstream_seq_num){
  333. f->downstream_seq_num += saved_data->next->len;
  334. #ifdef DEBUG
  335. printf("Updated downstream expected seqnum to %u\n",
  336. f->downstream_seq_num );
  337. #endif
  338. }
  339. } else {//outgoing
  340. if(saved_data->next->seq_num ==
  341. f->upstream_seq_num){
  342. f->upstream_seq_num += saved_data->next->len;
  343. #ifdef DEBUG
  344. printf("Updated upstream expected seqnum to %u\n",
  345. f->upstream_seq_num );
  346. #endif
  347. }
  348. }
  349. saved_data = saved_data->next;
  350. }
  351. if(!saved){
  352. saved_data->next = new_block;
  353. //update expected sequence number
  354. if(incoming){
  355. if(saved_data->next->seq_num ==
  356. f->downstream_seq_num){
  357. f->downstream_seq_num += saved_data->next->len;
  358. #ifdef DEBUG
  359. printf("Updated downstream expected seqnum to %u\n",
  360. f->downstream_seq_num );
  361. #endif
  362. }
  363. } else {//outgoing
  364. if(saved_data->next->seq_num ==
  365. f->upstream_seq_num){
  366. f->upstream_seq_num += saved_data->next->len;
  367. #ifdef DEBUG
  368. printf("Updated upstream expected seqnum to %u\n",
  369. f->upstream_seq_num );
  370. #endif
  371. }
  372. }
  373. }
  374. }
  375. }
  376. /**
  377. * This function cleans up data that has been acked, after the TCP window of the recipient has been
  378. * exceeded. This ensures that a retransmisson of the data will no longer occur.
  379. *
  380. * Sets the expiration for recent data base on the TCP window
  381. */
  382. void update_window_expiration(flow *f, struct packet_info *info){
  383. uint8_t incoming = (info->ip_hdr->src.s_addr != f->src_ip.s_addr)? 1 : 0;
  384. uint32_t ack_num = htonl(info->tcp_hdr->ack_num);
  385. uint32_t end_seq = htonl(info->tcp_hdr->sequence_num) + info->app_data_len - 1;
  386. uint32_t window = ack_num + htons(info->tcp_hdr->win_size);
  387. #ifdef DEBUG
  388. printf("Received sequence number %u\n", htonl(info->tcp_hdr->sequence_num));
  389. printf("Acknowledged up to %u with window expiring at %u\n", ack_num, window);
  390. printf("Removing all packets up to %u\n", end_seq);
  391. #endif
  392. packet *saved_data = (incoming)? f->downstream_app_data->first_packet :
  393. f->upstream_app_data->first_packet;
  394. while((saved_data != NULL) && (saved_data->expiration != 0) && (end_seq > saved_data->expiration)){
  395. //remove entire block
  396. if(incoming){
  397. f->downstream_app_data->first_packet = saved_data->next;
  398. } else {
  399. f->upstream_app_data->first_packet = saved_data->next;
  400. }
  401. free(saved_data->data);
  402. free(saved_data);
  403. saved_data = (incoming)? f->downstream_app_data->first_packet :
  404. f->upstream_app_data->first_packet;
  405. #ifdef DEBUG
  406. if(saved_data != NULL){
  407. printf("Currently saved seq_num is now %u\n", saved_data->seq_num);
  408. } else {
  409. printf("Acked all data, queue is empty\n");
  410. }
  411. #endif
  412. }
  413. /* Update expiration for packets based on TCP window size */
  414. saved_data = (incoming)? f->upstream_app_data->first_packet :
  415. f->downstream_app_data->first_packet;
  416. while((saved_data != NULL) && (ack_num > saved_data->seq_num)){
  417. //update window
  418. if(ack_num >= saved_data->seq_num + saved_data->len){
  419. //remove entire block
  420. saved_data->expiration = window;
  421. }
  422. saved_data = saved_data->next;
  423. }
  424. }
  425. /**
  426. * This function retransmits previously sent (and possibly modified) data
  427. *
  428. */
  429. void retransmit(flow *f, struct packet_info *info, uint32_t data_to_fill){
  430. uint8_t *p = info->app_data;
  431. uint32_t seq_num = htonl(info->tcp_hdr->sequence_num);
  432. uint8_t incoming = (info->ip_hdr->src.s_addr != f->src_ip.s_addr)? 1 : 0;
  433. packet *saved_data = (incoming)? f->downstream_app_data->first_packet :
  434. f->upstream_app_data->first_packet;
  435. while(data_to_fill > 0){
  436. if(saved_data == NULL){
  437. //have already acked all data
  438. p += data_to_fill;
  439. seq_num += data_to_fill;
  440. data_to_fill -= data_to_fill;
  441. continue;
  442. }
  443. if(seq_num < saved_data->seq_num){
  444. //we are missing a block. Use what was given
  445. if(saved_data->seq_num - seq_num > data_to_fill){
  446. //skip the rest
  447. p += data_to_fill;
  448. seq_num += data_to_fill;
  449. data_to_fill -= data_to_fill;
  450. } else {
  451. p += saved_data->seq_num - seq_num;
  452. data_to_fill -= saved_data->seq_num - seq_num;
  453. seq_num += saved_data->seq_num - seq_num;
  454. }
  455. } else if ( seq_num == saved_data->seq_num) {
  456. if(data_to_fill >= saved_data->len){
  457. //exhaust this block and move onto next one
  458. memcpy(p, saved_data->data, saved_data->len);
  459. p += saved_data->len;
  460. seq_num += saved_data->len;
  461. data_to_fill -= saved_data->len;
  462. saved_data = saved_data->next;
  463. } else {
  464. //fill with partial block
  465. memcpy(p, saved_data->data, data_to_fill);
  466. p += data_to_fill;
  467. seq_num += data_to_fill;
  468. data_to_fill -= data_to_fill;
  469. }
  470. } else { //seq_num > saved_data->seq_num
  471. uint32_t offset = seq_num - saved_data->seq_num;
  472. if(offset > saved_data->len){
  473. saved_data = saved_data->next;
  474. offset -= saved_data->len;
  475. } else {
  476. if(data_to_fill > saved_data->len - offset){
  477. memcpy(p, saved_data->data + offset, saved_data->len - offset);
  478. p += saved_data->len - offset;
  479. seq_num += saved_data->len - offset;
  480. data_to_fill -= saved_data->len - offset;
  481. saved_data = saved_data->next;
  482. } else {
  483. memcpy(p, saved_data->data + offset, data_to_fill);
  484. p += data_to_fill;
  485. seq_num += data_to_fill;
  486. data_to_fill -= data_to_fill;
  487. }
  488. }
  489. }
  490. }
  491. tcp_checksum(info);//update checksum
  492. }
  493. /** This function extracts the ip, tcp, and tls record headers
  494. * from a received packet (if they exist), and put them in
  495. * a packet_info struct
  496. *
  497. */
  498. void extract_packet_headers(uint8_t *packet, struct packet_info *info){
  499. /* First fill in IP header */
  500. uint8_t *p = packet;
  501. p += ETHER_HEADER_LEN; //skip ethernet header
  502. info->ip_hdr = (struct ip_header*) p;
  503. info->size_ip_hdr = IP_HEADER_LEN(info->ip_hdr);
  504. /* Verify this is an IP packet */
  505. if( (info->ip_hdr->versionihl >>4) != 4){
  506. info->ip_hdr = NULL;
  507. info->size_ip_hdr = 0;
  508. info->tcp_hdr = NULL;
  509. info->size_tcp_hdr = 0;
  510. info->record_hdr = NULL;
  511. return;
  512. }
  513. /* If this is a TCP segment, fill in TCP header */
  514. if (info->ip_hdr->proto == IPPROTO_TCP){
  515. p += info->size_ip_hdr; //skip IP header
  516. info->tcp_hdr = (struct tcp_header*) p;
  517. info->size_tcp_hdr = TCP_HEADER_LEN(info->tcp_hdr);
  518. p += info->size_tcp_hdr;
  519. } else {
  520. info->tcp_hdr = NULL;
  521. info->size_tcp_hdr = 0;
  522. info->record_hdr = NULL;
  523. return;
  524. }
  525. /* If the application data contains a TLS record, fill in hdr */
  526. info->app_data_len = htons(info->ip_hdr->len) - (info->size_ip_hdr + info->size_tcp_hdr);
  527. if(info->app_data_len > 0){
  528. info->app_data = p;
  529. info->record_hdr = (struct tls_header*) p;
  530. //check to see if this is a valid record
  531. if((info->record_hdr->type < 0x14) || (info->record_hdr->type > 0x18)){
  532. info->record_hdr = NULL;
  533. }
  534. } else {
  535. info->record_hdr = NULL;
  536. info->app_data = NULL;
  537. }
  538. return;
  539. }
  540. /** Copies a packet_info structure and returns a pointer to the duplicate.
  541. */
  542. struct packet_info *copy_packet_info(struct packet_info *src_info){
  543. struct packet_info *dst_info = emalloc(sizeof(struct packet_info));
  544. dst_info->ip_hdr = src_info->ip_hdr;
  545. dst_info->tcp_hdr = src_info->tcp_hdr;
  546. dst_info->size_tcp_hdr = src_info->size_tcp_hdr;
  547. dst_info->size_ip_hdr = src_info->size_ip_hdr;
  548. dst_info->app_data = src_info->app_data;
  549. dst_info->app_data_len = src_info->app_data_len;
  550. return dst_info;
  551. }