Changeset b8d8186 for lib/format_linux.c


Ignore:
Timestamp:
08/07/14 11:21:10 (6 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, 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:
4649fea
Parents:
cd8efa6
Message:

Fix strangeness when using bogus filters on int:

Changes:

  • Make sure trace_start returns -1 for int: if the provided filter failed to compile, rather than falling through to using trace_apply_filter on the first packet (and failing). This is also more consistent with what pcapint: already does.
  • Check for -1 return value from trace_apply_filter, rather than treating -1 as a successful match.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_linux.c

    r53eb1aa rb8d8186  
    501501         */
    502502        if (filter != NULL) {
    503                 assert(filter->flag == 1);
    504                 if (setsockopt(FORMAT(libtrace->format_data)->fd,
     503                /* Check if the filter was successfully compiled. If not,
     504                 * it is probably a bad filter and we should return an error
     505                 * before the caller tries to read any packets */
     506                if (filter->flag == 0) {
     507                        return -1;
     508                }
     509               
     510                if (setsockopt(FORMAT(libtrace->format_data)->fd,
    505511                                        SOL_SOCKET,
    506512                                        SO_ATTACH_FILTER,
     
    746752
    747753                if (pcap_compile(pcap, &f->filter, f->filterstring, 0, 0) == -1) {
    748                         perror("PCAP failed to compile the filterstring");
    749                         return -1;
    750                 }
     754                        /* Filter didn't compile, set flag to 0 so we can
     755                         * detect this when trace_start() is called and
     756                         * produce a useful error
     757                         */
     758                        f->flag = 0;
     759                        trace_set_err(libtrace, TRACE_ERR_INIT_FAILED,
     760                                        "Failed to compile BPF filter (%s): %s",
     761                                        f->filterstring, pcap_geterr(pcap));
     762                } else {
     763                        /* Set the "flag" to indicate that the filterstring
     764                         * has been compiled
     765                         */
     766                        f->flag = 1;
     767                }
    751768
    752769                pcap_close(pcap);
    753770               
    754                 /* Set the "flag" to indicate that the filterstring has been
    755                  * compiled
    756                  */
    757                 f->flag = 1;
    758771        }
    759772       
Note: See TracChangeset for help on using the changeset viewer.