Changeset c5fe79a


Ignore:
Timestamp:
11/24/09 17:50:51 (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:
93928b7
Parents:
43351e9
Message:

fixing bugs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/tracereplay/tracereplay.c

    r43351e9 rc5fe79a  
    4444  while (sum>>16)
    4545    sum = (sum & 0xffff) + (sum >> 16);
    46   printf("%04X\n",~sum);
    4746  return ~sum;
    4847}
     
    5049static void udp_tcp_checksum(libtrace_ip_t *ip, uint32_t* remaining) {
    5150
    52   uint32_t sum;
    53   uint32_t pseudoheader[3];
    54   uint8_t * other8;
    55   uint16_t * other16;
    56  
    57   uint8_t proto;
    58 
     51
     52
     53  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   */
    5966  void * transportheader = trace_get_payload_from_ip(ip,&proto,remaining);
    6067
    61   uint16_t * check = 0;
     68  printf("l3 payload length: %d\n",*remaining); 
     69
     70  uint16_t * check = NULL;
    6271  uint16_t tsum = 0;
    6372
     
    7584
    7685  if(proto == 17 ) {
     86    printf("udp  length: %d\n",sizeof(libtrace_udp_t));
    7787    libtrace_udp_t * udp_header = transportheader;
    7888    udp_header -> check = 0;
    7989    check = &udp_header -> check;
    8090    *other16 = *remaining + sizeof(libtrace_udp_t);
    81     tsum = checksum(transportheader,*other16);
     91    tsum = checksum(transportheader,*remaining + sizeof(libtrace_udp_t));
    8292  }
    8393  else if(proto == 6) {
     94   
    8495    libtrace_tcp_t * tcp_header = transportheader;
    8596    tcp_header -> check = 0;
    8697    check = &tcp_header -> check;
    8798    *other16 = *remaining + sizeof(libtrace_tcp_t);
    88     tsum = checksum(transportheader,*other16);
    89   }
    90 
    91   sum = ~(~checksum(pseudoheader,3*sizeof(uint32_t)) + ~tsum);
     99    //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);
    92106
    93107  while (sum>>16)
     
    95109 
    96110  if(check != NULL) {
    97     *check = (uint16_t)sum;
     111    *check = (uint16_t)~sum;
    98112  }
    99113 
     
    103117
    104118static libtrace_packet_t * per_packet(libtrace_packet_t *packet) {
    105   uint32_t remaining
    106   libtrace_linktype_t linktype;
     119  uint32_t remaining = 0
     120  libtrace_linktype_t linktype = 0;
    107121  void * pkt_buffer = trace_get_packet_buffer(packet,&linktype,&remaining);
    108122  remaining = 0;
     123  libtrace_ip_t * header = NULL;
     124  uint16_t sum = 0;
    109125  libtrace_packet_t *new_packet = trace_create_packet();
    110126 
    111127  size_t wire_length = trace_get_wire_length(packet);
    112128
    113   libtrace_ip_t * header;
    114   void * l3_header;
    115   uint16_t sum;
    116   uint16_t ethertype;
    117 
    118   l3_header = trace_get_layer3(packet, &ethertype, &remaining);
     129  printf("wire length: %d\n",wire_length);
    119130
    120131  if(linktype == TRACE_TYPE_ETH || linktype == TRACE_TYPE_80211) {
    121132    wire_length -= FCS_SIZE;
    122     remaining -= FCS_SIZE;
    123   }
     133  }
     134
     135  printf("wire length after FCS: %d\n",wire_length);
    124136
    125137  trace_construct_packet(new_packet,linktype,pkt_buffer,wire_length);
    126138 
    127139
    128   //header = trace_get_ip(new_packet);
    129   //if(header != NULL) {
    130 
    131   l3_header = trace_get_layer3(packet, &ethertype, &remaining);
    132   if(ethertype == 0x0800) {
    133     header = (libtrace_ip_t *) l3_header;
     140  header = trace_get_ip(new_packet);
     141  if(header != NULL) {
     142    wire_length -= sizeof(libtrace_ip_t);
    134143    header -> ip_sum = 0;
    135     printf("after zero %04X\n", header -> ip_sum);
    136     sum = checksum(l3_header,header->ip_hl*sizeof(uint32_t));
    137     printf("first %04X\n", sum);
     144    sum = checksum(header,header->ip_hl*sizeof(uint32_t));
    138145    header -> ip_sum = sum;
    139     printf("final %04X\n", header -> ip_sum);
    140     udp_tcp_checksum(header,&remaining);
     146    udp_tcp_checksum(header,&wire_length);
    141147  }
    142148
     
    319325                libtrace_packet_t * new = per_packet(packet);
    320326
     327                //libtrace_ip_t * header;
     328                //              header = trace_get_ip(new);
     329
     330                //printf("before write: %04X\n",header->ip_sum);
     331               
    321332                if (trace_write_packet(output, new) < 0) {
    322333                        trace_perror_output(output, "Writing packet");
Note: See TracChangeset for help on using the changeset viewer.