Changeset 7c72e4d for lib/trace.c


Ignore:
Timestamp:
06/20/07 13:10:40 (14 years ago)
Author:
Perry Lorier <perry@…>
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:
8ee3dbd
Parents:
f93f0b3
Message:

Add caching of trace_get_capture_length() (since this is used a lot in protocol
decodes to figure out if we captured the full header we're about to decode).

Add caching of the l3 header (avoiding parsing the linktype/l2/l2.5 protocol
headers).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/trace.c

    r984f7da r7c72e4d  
    632632        libtrace_packet_t *packet =
    633633                (libtrace_packet_t*)calloc((size_t)1,sizeof(libtrace_packet_t));
     634
    634635        packet->buf_control=TRACE_CTRL_PACKET;
     636        packet->capture_length=-1;
    635637        return packet;
    636638}
     
    687689         * structure */
    688690        packet->trace = libtrace;
     691
     692        /* Finalise the packet, freeing any resources the format module
     693         * may have allocated it
     694         */
     695        if (libtrace->format->fin_packet) {
     696                libtrace->format->fin_packet(packet);
     697        }
     698
     699        /* Clear the packet cache */
     700        packet->capture_length = -1;
     701        packet->l3_header = NULL;
     702        packet->l3_ethertype = 0;
    689703
    690704        if (libtrace->format->read_packet) {
     
    838852}
    839853
    840 DLLEXPORT size_t trace_get_capture_length(const libtrace_packet_t *packet)
    841 {
    842         if (packet->trace->format->get_capture_length) {
    843                 return packet->trace->format->get_capture_length(packet);
    844         }
    845         return ~0U;
     854DLLEXPORT size_t trace_get_capture_length(libtrace_packet_t *packet)
     855{
     856        /* Cache the capture length */
     857        if (packet->capture_length == -1) {
     858                if (!packet->trace->format->get_capture_length)
     859                        return ~0U;
     860                packet->capture_length =
     861                        packet->trace->format->get_capture_length(packet);
     862        }
     863
     864        return packet->capture_length;
    846865}
    847866       
Note: See TracChangeset for help on using the changeset viewer.