Changeset c0506ea for lib/trace.c


Ignore:
Timestamp:
09/20/11 14:21:53 (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:
c0ccccd
Parents:
2cf2c2d
Message:
  • We now use pcap_create and pcap_activate for pcap interfaces if libpcap 1.0 or later is available. This doesn't seem to make much of a difference performance-wise, as pcap_open_live was updated to use these functions anyway. This means if mmapped packet capture is available, we would have used it via pcap_open_live anyway.
  • Added a new function (trace_interrupt). Calling this function will set an internal variable which can be used to cause any blocking read_packet function to exit with an EOF. Useful for programs that are handling signals themselves and need a way to tell libtrace to stop. Prior to this, programs like tracestats would not exit on Ctrl-C if reading from a pcap interface which was not receiving any packets.
  • Updated pcap interface format to respond to trace_interrupt.
  • Optimising trace_apply_filter to minimise calls to trace_get_link_type and trace_get_packet_buffer.
  • Removed unused extern variable "form" from libtrace_int.h
  • Fixed bug with filters in the pcap interface format which would result in "invalid BPF program" error message when filter was definitely legit.
  • Updated version number to 3.0.13
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/trace.c

    ree58d0d rc0506ea  
    103103
    104104static struct libtrace_format_t *formats_list = NULL;
     105
     106int libtrace_halt = 0;
    105107
    106108/* strncpy is not assured to copy the final \0, so we
     
    11841186 */
    11851187static int trace_bpf_compile(libtrace_filter_t *filter,
    1186                 const libtrace_packet_t *packet ) {
     1188                const libtrace_packet_t *packet,
     1189                void *linkptr,
     1190                libtrace_linktype_t linktype    ) {
    11871191#ifdef HAVE_BPF_FILTER
    1188         void *linkptr = 0;
    1189         libtrace_linktype_t linktype;
    11901192        assert(filter);
    11911193
    11921194        /* If this isn't a real packet, then fail */
    1193         linkptr = trace_get_packet_buffer(packet,&linktype,NULL);
    11941195        if (!linkptr) {
    11951196                trace_set_err(packet->trace,
     
    12441245        bool free_packet_needed = false;
    12451246        int ret;
     1247        libtrace_linktype_t linktype;
    12461248        libtrace_packet_t *packet_copy = (libtrace_packet_t*)packet;
    12471249
     
    12511253        /* Match all non-data packets as we probably want them to pass
    12521254         * through to the caller */
    1253         if (trace_get_link_type(packet) == TRACE_TYPE_NONDATA)
     1255        linktype = trace_get_link_type(packet);
     1256
     1257        if (linktype == TRACE_TYPE_NONDATA)
    12541258                return 1;       
    12551259
    1256         if (libtrace_to_pcap_dlt(trace_get_link_type(packet))==~0U) {
     1260        if (libtrace_to_pcap_dlt(linktype)==~0U) {
    12571261               
    12581262                /* If we cannot get a suitable DLT for the packet, it may
     
    12671271                free_packet_needed=true;
    12681272
    1269                 while (libtrace_to_pcap_dlt(trace_get_link_type(packet_copy))==
    1270                                 ~0U) {
     1273                while (libtrace_to_pcap_dlt(linktype) == ~0U) {
    12711274                        if (!demote_packet(packet_copy)) {
    12721275                                trace_set_err(packet->trace,
     
    12781281                                return -1;
    12791282                        }
    1280                 }
     1283                        linktype = trace_get_link_type(packet_copy);
     1284                }
     1285
    12811286        }
    12821287       
     
    12921297         * what the link type was
    12931298         */
    1294         if (trace_bpf_compile(filter,packet_copy)==-1) {
     1299        if (trace_bpf_compile(filter,packet_copy,linkptr,linktype)==-1) {
    12951300                if (free_packet_needed) {
    12961301                        trace_destroy_packet(packet_copy);
     
    18341839        packet->l4_remaining = 0;
    18351840
     1841}
     1842
     1843void trace_interrupt(void) {
     1844        libtrace_halt = 1;
    18361845}
    18371846
Note: See TracChangeset for help on using the changeset viewer.