Changeset 43351e9 for tools


Ignore:
Timestamp:
11/23/09 17:41:28 (11 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:
c5fe79a
Parents:
ff7d949
Message:

working on getting udp and tcp checksums going. Seem to have broken ip checksums again, works fine when I use trace_get_ip instead of trace_get_layer3 though.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/tracereplay/tracereplay.c

    rff7d949 r43351e9  
    55  specified interface.
    66  It pads packets with zeroes to reach the original length of the packet
    7   and recalculates crc checksums in ip/tcp/udp headers.
     7  and recalculates checksums in ip/tcp/udp headers.
    88
    99  Authors: Andreas Loef and Yuwei Wang
     
    3939
    4040  if(count > 0) {
    41     sum += buff;
     41    sum += *buff;
    4242  }
    4343 
    4444  while (sum>>16)
    4545    sum = (sum & 0xffff) + (sum >> 16);
    46 
     46  printf("%04X\n",~sum);
    4747  return ~sum;
    4848}
    4949
    50 static uint16_t udp_tcp_checksum(libtrace_packet_t *packet) {
     50static void udp_tcp_checksum(libtrace_ip_t *ip, uint32_t* remaining) {
    5151
    5252  uint32_t sum;
    53 
    54 
     53  uint32_t pseudoheader[3];
     54  uint8_t * other8;
     55  uint16_t * other16;
     56 
     57  uint8_t proto;
     58
     59  void * transportheader = trace_get_payload_from_ip(ip,&proto,remaining);
     60
     61  uint16_t * check = 0;
     62  uint16_t tsum = 0;
     63
     64  pseudoheader[0] = (uint32_t) (ip -> ip_src).s_addr;
     65  pseudoheader[1] = (uint32_t)(ip -> ip_dst).s_addr;
     66 
     67  other8 = (uint8_t *) &pseudoheader[2];
     68
     69  *other8 = 0x00;
     70  other8++;
     71  *other8 = ip -> ip_p;
     72  other8++;
     73 
     74  other16 = (uint16_t *) other8;
     75
     76  if(proto == 17 ) {
     77    libtrace_udp_t * udp_header = transportheader;
     78    udp_header -> check = 0;
     79    check = &udp_header -> check;
     80    *other16 = *remaining + sizeof(libtrace_udp_t);
     81    tsum = checksum(transportheader,*other16);
     82  }
     83  else if(proto == 6) {
     84    libtrace_tcp_t * tcp_header = transportheader;
     85    tcp_header -> check = 0;
     86    check = &tcp_header -> check;
     87    *other16 = *remaining + sizeof(libtrace_tcp_t);
     88    tsum = checksum(transportheader,*other16);
     89  }
     90
     91  sum = ~(~checksum(pseudoheader,3*sizeof(uint32_t)) + ~tsum);
     92
     93  while (sum>>16)
     94    sum = (sum & 0xffff) + (sum >> 16);
     95 
     96  if(check != NULL) {
     97    *check = (uint16_t)sum;
     98  }
     99 
    55100
    56101}
     
    58103
    59104static libtrace_packet_t * per_packet(libtrace_packet_t *packet) {
    60  
    61   uint32_t remaining;
     105  uint32_t remaining; 
    62106  libtrace_linktype_t linktype;
    63107  void * pkt_buffer = trace_get_packet_buffer(packet,&linktype,&remaining);
     108  remaining = 0;
    64109  libtrace_packet_t *new_packet = trace_create_packet();
    65 
     110 
    66111  size_t wire_length = trace_get_wire_length(packet);
    67112
    68113  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);
    69119
    70120  if(linktype == TRACE_TYPE_ETH || linktype == TRACE_TYPE_80211) {
    71121    wire_length -= FCS_SIZE;
     122    remaining -= FCS_SIZE;
    72123  }
    73124
     
    75126 
    76127
    77   header = trace_get_ip(new_packet);
    78   if(header != NULL) {
     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;
    79134    header -> ip_sum = 0;
    80     header -> ip_sum = checksum(header,header->ip_hl*sizeof(uint32_t));
    81   }
     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);
     138    header -> ip_sum = sum;
     139    printf("final %04X\n", header -> ip_sum);
     140    udp_tcp_checksum(header,&remaining);
     141  }
     142
     143
    82144
    83145  return new_packet;
Note: See TracChangeset for help on using the changeset viewer.