Changeset c5a22ec


Ignore:
Timestamp:
07/07/04 15:17:57 (17 years ago)
Author:
Daniel Lawson <dlawson@…>
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:
72429bd
Parents:
abde7b5
Message:

changed bpf routines to use an opaque pointer to a filter datastructure

Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/libtrace.h

    rc681e86 rc5a22ec  
    3838struct libtrace_t;
    3939       
     40/** Opaque structure holding information about a bpf filter */
     41
     42struct libtrace_filter_t;
    4043/** Structure for dealing with IP packets */
    4144struct libtrace_ip
     
    348351
    349352/** setup a BPF filter
    350  * @param libtrace the libtrace opaque pointer
    351353 * @param filterstring a char * containing the bpf filter string
    352  * @returns null
    353  * @author Daniel Lawson
    354  */
    355 void libtrace_bpf_setfilter(struct libtrace_t *trace, char *filterstring);
     354 * @returns opaque pointer pointer to a libtrace_filter_t object
     355 * @author Daniel Lawson
     356 */
     357struct libtrace_filter_t *libtrace_bpf_setfilter(const char *filterstring);
    356358
    357359/** apply a BPF filter
    358360 * @param libtrace the libtrace opaque pointer
     361 * @param filter the filter opaque pointer
    359362 * @param buffer a pointer to a filled buffer
    360363 * @param buflen the length of the buffer
     
    362365 * @author Daniel Lawson
    363366 */
    364 int libtrace_bpf_filter(struct libtrace_t *trace,
     367int libtrace_bpf_filter(struct libtrace_t *trace,
     368                        struct libtrace_filter_t *filter,
    365369                        void *buffer,
    366370                        int buflen);
  • lib/trace.c

    ra9d9fd6 rc5a22ec  
    4242
    4343typedef enum {ERF, PCAP, PCAPINT, DAG, RTCLIENT, WAG, WAGINT } format_t;
     44
     45struct libtrace_filter_t {
     46        struct bpf_insn *filter;
     47        char * filterstring;
     48};
    4449
    4550struct libtrace_t {
     
    6469                int size;
    6570        } packet;
    66         struct bpf_insn *filter;
    67         char * filterstring;
    6871        double last_ts;
    6972        double start_ts;
     
    10101013}
    10111014
     1015/** setup a BPF filter
     1016 * @param filterstring a char * containing the bpf filter string
     1017 * @returns opaque pointer pointer to a libtrace_filter_t object
     1018 * @author Daniel Lawson
     1019 */
     1020struct libtrace_filter_t *libtrace_bpf_setfilter(const char *filterstring) {
     1021        struct libtrace_filter_t *filter = malloc(sizeof(struct libtrace_filter_t));
     1022        filter->filterstring = strdup(filterstring);
     1023        return filter;
     1024}
     1025
    10121026/** apply a BPF filter
    10131027 * @param libtrace the libtrace opaque pointer
    1014  * @param filterstring a char * containing the bpf filter string
    1015  * @returns null
    1016  *
    1017  * @author Daniel Lawson
    1018  */
    1019 void libtrace_bpf_setfilter(struct libtrace_t *trace, char *filterstring) {
    1020         trace->filterstring = strdup(filterstring);
    1021 }
    1022 
    1023 /** apply a BPF filter
    1024  * @param libtrace the libtrace opaque pointer
     1028 * @param filter the filter opaque pointer
    10251029 * @param buffer a pointer to a filled buffer
    10261030 * @param buflen the length of the buffer
     
    10291033 */
    10301034int libtrace_bpf_filter(struct libtrace_t *trace,
     1035                        struct libtrace_filter_t *filter,
    10311036                        void *buffer,
    10321037                        int buflen) {
     
    10351040        void *linkptr = get_link(trace,buffer,buflen); 
    10361041        int clen = get_capture_length(trace,buffer,buflen);
    1037 
    1038         if (trace->filterstring && ! trace->filter) {
     1042        assert(trace);
     1043        assert(filter);
     1044        assert(buffer);
     1045       
     1046
     1047        if (filter->filterstring && ! filter->filter) {
    10391048                pcap_t *pcap;
    10401049                struct bpf_program bpfprog;
     
    10501059
    10511060                // build filter
    1052                 if (pcap_compile( pcap, &bpfprog, trace->filterstring, 1, 0)) {
     1061                if (pcap_compile( pcap, &bpfprog, filter->filterstring, 1, 0)) {
    10531062                        printf("bpf compilation error: %s\n",
    10541063                                pcap_geterr(pcap));
     
    10561065                }
    10571066                pcap_close(pcap);
    1058                 trace->filter = bpfprog.bf_insns;       
     1067                filter->filter = bpfprog.bf_insns;     
    10591068        }
    10601069
    1061         return bpf_filter(trace->filter, linkptr, clen, clen);
    1062 }
    1063 
    1064 
     1070        return bpf_filter(filter->filter, linkptr, clen, clen);
     1071}
     1072
     1073
Note: See TracChangeset for help on using the changeset viewer.