Ignore:
Timestamp:
02/22/11 10:01:08 (2 years ago)
Author:
salcock
Message:
  • Fixed poor performance of the event API by greatly reducing the amount of packets created, copied and freed
  • We now cache the transport header and payload length for each packet
  • We now deal with Linux SLL Ethernet captures taken using tcpdump with -i any correctly.
  • Changed parameters for internal function trace_get_payload_from_sll - it now sets both the arphrd type and the next protocol
  • Moved ARPHRD definitions into a separate header file, as they come in handy anywhere we deal with SLL headers
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/protocols_transport.c

    r1663 r1691  
    6868        size_t len = 0; 
    6969 
    70          
    71  
     70        /* Just use the cached length if we can */ 
     71        if (packet->payload_length != -1) 
     72                return packet->payload_length;   
     73 
     74        /* Set to zero so that we can return early without having to  
     75         * worry about forgetting to update the cached value */ 
     76        ((libtrace_packet_t *)packet)->payload_length = 0; 
    7277        layer = trace_get_layer3(packet, &ethertype, &rem); 
    73  
    7478        if (!layer) 
    7579                return 0; 
     
    122126        } 
    123127 
     128 
     129        ((libtrace_packet_t *)packet)->payload_length = len; 
    124130        return len; 
    125131 
     
    139145 
    140146        if (!remaining) remaining=&dummy_remaining; 
     147 
     148        if (packet->l4_header) { 
     149                void *link; 
     150                libtrace_linktype_t linktype; 
     151                link = trace_get_packet_buffer(packet, &linktype, remaining); 
     152                if (!link) 
     153                        return NULL; 
     154                *proto = packet->transport_proto; 
     155                *remaining -= (packet->l4_header - link); 
     156                return packet->l4_header; 
     157        } 
    141158 
    142159        transport = trace_get_layer3(packet,&ethertype,remaining); 
     
    154171                                 (libtrace_ip6_t*)transport, proto,remaining); 
    155172                        } 
    156                         return transport; 
     173                        break; 
    157174                case TRACE_ETHERTYPE_IPV6: /* IPv6 */ 
    158                         return trace_get_payload_from_ip6( 
     175                        transport = trace_get_payload_from_ip6( 
    159176                                (libtrace_ip6_t*)transport, proto, remaining); 
     177                        break; 
     178                default: 
     179                        *proto = 0; 
     180                        transport = NULL; 
     181                        break; 
    160182                         
    161183        } 
    162184 
    163         *proto=0; 
    164         return NULL; 
     185        ((libtrace_packet_t *)packet)->transport_proto = *proto; 
     186        ((libtrace_packet_t *)packet)->l4_header = transport; 
     187 
     188 
     189        return transport; 
    165190} 
    166191 
Note: See TracChangeset for help on using the changeset viewer.