Ignore:
Timestamp:
11/25/09 19:28:50 (12 years ago)
Author:
Andreas Löf <andreas.lof@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
effd683
Parents:
c5fe79a
Message:

still broken, but less complicated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/tracereplay/tracereplay.c

    rc5fe79a r93928b7  
    2727#define FCS_SIZE 4
    2828
     29
     30
     31
    2932/* This function assumes that the relevant fields have been zeroed out. RFC 1071*/
    3033static uint16_t checksum(void * buffer, uint16_t length) {
     
    3942
    4043  if(count > 0) {
    41     sum += *buff;
     44    sum += (*buff << 8);
    4245  }
    4346 
    4447  while (sum>>16)
    4548    sum = (sum & 0xffff) + (sum >> 16);
     49  printf("%04X\n",sum);
    4650  return ~sum;
    4751}
    4852
    49 static void udp_tcp_checksum(libtrace_ip_t *ip, uint32_t* remaining) {
    50 
    51 
     53static void udp_tcp_checksum(libtrace_ip_t *ip, uint32_t length) {
     54
     55  uint32_t remaining = 0;
    5256
    5357  uint32_t sum = 0;
    54   uint32_t pseudoheader[3] = {0,0,0};
    55   uint8_t * other8 = NULL;
    56   uint16_t * other16 = NULL;
    57  
    58   uint8_t proto = 0;
    59 
    60   printf("IP payload length: %d\n",*remaining);
    61  
    62   /*
    63     Remaining gets the wrong value here.
    64 
    65    */
    66   void * transportheader = trace_get_payload_from_ip(ip,&proto,remaining);
    67 
    68   printf("l3 payload length: %d\n",*remaining); 
     58 
     59  uint16_t protocol = ip->ip_p;
     60
     61  uint16_t temp;
     62
     63  sum += ~checksum(&ip->ip_src,sizeof(uint32_t));
     64  sum += ~checksum(&ip->ip_dst,sizeof(uint32_t));
     65  temp = htons(protocol);
     66  sum += ~checksum(&temp,sizeof(uint16_t));
     67  temp = htons(length);
     68  sum += ~checksum(&temp,sizeof(uint16_t));
     69
     70
     71  printf("IP payload length: %d\n",length);
     72 
     73  void * transportheader = trace_get_payload_from_ip(ip,NULL,NULL);
    6974
    7075  uint16_t * check = NULL;
    7176  uint16_t tsum = 0;
    7277
    73   pseudoheader[0] = (uint32_t) (ip -> ip_src).s_addr;
    74   pseudoheader[1] = (uint32_t)(ip -> ip_dst).s_addr;
    75  
    76   other8 = (uint8_t *) &pseudoheader[2];
    77 
    78   *other8 = 0x00;
    79   other8++;
    80   *other8 = ip -> ip_p;
    81   other8++;
    82  
    83   other16 = (uint16_t *) other8;
    84 
    85   if(proto == 17 ) {
    86     printf("udp  length: %d\n",sizeof(libtrace_udp_t));
     78  printf("proto: %d\n",ip->ip_p);
     79
     80  if(protocol == 17 ) {
    8781    libtrace_udp_t * udp_header = transportheader;
    88     udp_header -> check = 0;
     82    printf("udp  length: %d\n",ntohs(udp_header -> len));
    8983    check = &udp_header -> check;
    90     *other16 = *remaining + sizeof(libtrace_udp_t);
    91     tsum = checksum(transportheader,*remaining + sizeof(libtrace_udp_t));
    92   }
    93   else if(proto == 6) {
    94    
     84    *check = 0;
     85    printf("l3 payload length: %d\n",length); 
     86    tsum = checksum(transportheader, length);
     87    int odd = 0;//length % 2;
     88  }
     89  else if(protocol == 6) {
    9590    libtrace_tcp_t * tcp_header = transportheader;
    9691    tcp_header -> check = 0;
    9792    check = &tcp_header -> check;
    98     *other16 = *remaining + sizeof(libtrace_tcp_t);
     93
    9994    //use tcp header length and datagram length instead
    100     tsum = checksum(transportheader,*remaining+sizeof(libtrace_tcp_t));
    101   }
    102 
    103   *other16 = *remaining;
    104 
    105   sum = (~checksum(pseudoheader,3*sizeof(uint32_t)) + ~tsum);
     95    tsum = checksum(transportheader,length);
     96  }
     97
     98
     99  printf("tsum: %04X\n", tsum);
     100
     101  sum = ~tsum;
    106102
    107103  while (sum>>16)
     
    140136  header = trace_get_ip(new_packet);
    141137  if(header != NULL) {
    142     wire_length -= sizeof(libtrace_ip_t);
     138    wire_length -= sizeof(uint32_t)*header->ip_hl;
    143139    header -> ip_sum = 0;
    144140    sum = checksum(header,header->ip_hl*sizeof(uint32_t));
    145141    header -> ip_sum = sum;
    146     udp_tcp_checksum(header,&wire_length);
    147   }
    148 
    149 
     142    udp_tcp_checksum(header,ntohs(header->ip_len) - sizeof(uint32_t)*header->ip_hl);
     143  }
    150144
    151145  return new_packet;
Note: See TracChangeset for help on using the changeset viewer.