Changeset ee58d0d for lib/protocols_l2.c


Ignore:
Timestamp:
08/12/11 14:22:16 (10 years ago)
Author:
Shane Alcock <salcock@…>
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:
c29a0e0
Parents:
44028d4
Message:
  • Improved performance by caching more stuff, especially L2 headers and various "remaining" values - not much point caching something if you need to re-read the entire packet to calculate "remaining" still :)
  • Also improved performance of trace_get_layer2 by avoiding an effective double call of trace_get_packet_buffer
  • Fixed bug with payload length calculation if the packet has extra padding beyond what the IP len states
  • Improved (hopefully) performance when reading ERF traces by avoiding updating the drops counter if the loss counter was zero (should save an ntohs at least)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/protocols_l2.c

    r14cc9ce ree58d0d  
    350350        if (remaining == NULL)
    351351                remaining = &dummyrem;
    352        
    353         meta = trace_get_packet_meta(packet, linktype, remaining);
     352
     353        if (packet->l2_header) {
     354                /* Use cached values */
     355                *linktype = packet->link_type;
     356                *remaining = packet->l2_remaining;
     357                return packet->l2_header;
     358        }
     359
     360        /* Code looks a bit inefficient, but I'm actually trying to avoid
     361         * calling trace_get_packet_buffer more than once like we used to.
     362         */
     363       
     364        meta = trace_get_packet_buffer(packet, linktype, remaining);
    354365
    355366        /* If there are no meta-data headers, we just return the start of the
    356367         * packet buffer, along with the linktype, etc.
    357368         */
    358         if (meta == NULL)
    359                 return trace_get_packet_buffer(packet, linktype, remaining);
    360        
     369        switch(*linktype) {
     370                /* meta points to a layer 2 header! */
     371                case TRACE_TYPE_HDLC_POS:
     372                case TRACE_TYPE_ETH:
     373                case TRACE_TYPE_ATM:
     374                case TRACE_TYPE_80211:
     375                case TRACE_TYPE_NONE:
     376                case TRACE_TYPE_POS:
     377                case TRACE_TYPE_AAL5:
     378                case TRACE_TYPE_DUCK:
     379                case TRACE_TYPE_LLCSNAP:
     380                case TRACE_TYPE_PPP:
     381                case TRACE_TYPE_METADATA:
     382                case TRACE_TYPE_NONDATA:
     383                        ((libtrace_packet_t*)packet)->link_type = *linktype;
     384                        ((libtrace_packet_t*)packet)->l2_header = meta;
     385                        ((libtrace_packet_t*)packet)->l2_remaining = *remaining;
     386                        return meta;
     387                case TRACE_TYPE_LINUX_SLL:
     388                case TRACE_TYPE_80211_RADIO:
     389                case TRACE_TYPE_80211_PRISM:
     390                case TRACE_TYPE_PFLOG:
     391                        break;
     392        }
     393
    361394        /* If there are meta-data headers, we need to skip over them until we
    362395         * find a non-meta data header and return that.
     
    381414                                case TRACE_TYPE_METADATA:
    382415                                case TRACE_TYPE_NONDATA:
     416                                        ((libtrace_packet_t*)packet)->link_type = *linktype;
     417                                        ((libtrace_packet_t*)packet)->l2_header = meta;
     418                                        ((libtrace_packet_t*)packet)->l2_remaining = *remaining;
    383419                                        return meta;
    384420                                case TRACE_TYPE_LINUX_SLL:
     
    396432                meta = nexthdr;
    397433        }
     434
    398435}
    399436
Note: See TracChangeset for help on using the changeset viewer.