Changeset 7ca2c7d for lib/trace.c


Ignore:
Timestamp:
11/01/06 13:09:03 (15 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:
a31b4c7
Parents:
2f3a25e
Message:

Fixed trace_apply_filter to operate on a copy of the packet, which should eliminate the problem where the packet is corrupted

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/trace.c

    r76eeca0 r7ca2c7d  
    998998        assert(filter);
    999999        assert(packet);
    1000 
     1000        libtrace_packet_t *packet_copy = packet;
     1001
     1002       
    10011003        if (libtrace_to_pcap_dlt(trace_get_link_type(packet))==~0) {
    10021004                /* Copy the packet, as we don't want to trash the one we
    10031005                 * were passed in
    10041006                 */
    1005                 packet=trace_copy_packet(packet);
     1007                packet_copy=trace_copy_packet(packet);
    10061008                free_packet_needed=true;
    1007                 while (libtrace_to_pcap_dlt(trace_get_link_type(packet))==~0) {
    1008                         if (!demote_packet(packet)) {
     1009                while (libtrace_to_pcap_dlt(trace_get_link_type(packet_copy))==
     1010                                ~0) {
     1011                        if (!demote_packet(packet_copy)) {
    10091012                                trace_set_err_out(packet->trace,
    10101013                                                TRACE_ERR_NO_CONVERSION,
    10111014                                                "pcap does not support this format");
    10121015                                if (free_packet_needed) {
    1013                                         trace_destroy_packet(packet);
     1016                                        trace_destroy_packet(packet_copy);
    10141017                                }
    10151018                                return -1;
     
    10181021        }
    10191022       
    1020         linkptr = trace_get_link(packet);
     1023        linkptr = trace_get_link(packet_copy);
    10211024        if (!linkptr) {
    10221025                if (free_packet_needed) {
    1023                         trace_destroy_packet(packet);
     1026                        trace_destroy_packet(packet_copy);
    10241027                }
    10251028                return 0;
     
    10291032         * link type was
    10301033         */
    1031         if (trace_bpf_compile(filter,packet)==-1) {
     1034        if (trace_bpf_compile(filter,packet_copy)==-1) {
    10321035                if (free_packet_needed) {
    1033                         trace_destroy_packet(packet);
     1036                        trace_destroy_packet(packet_copy);
    10341037                }
    10351038                return -1;
    10361039        }
    10371040
    1038         clen = trace_get_capture_length(packet);
     1041        clen = trace_get_capture_length(packet_copy);
    10391042
    10401043        assert(filter->flag);
    10411044        ret=bpf_filter(filter->filter.bf_insns,(u_char*)linkptr,clen,clen);
    10421045        if (free_packet_needed) {
    1043                 trace_destroy_packet(packet);
     1046                trace_destroy_packet(packet_copy);
    10441047        }
    10451048        return ret;
Note: See TracChangeset for help on using the changeset viewer.