Changeset 50bbce8 for lib/format_bpf.c


Ignore:
Timestamp:
11/30/07 08:57:55 (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:
25a9201
Parents:
b282cf8
Message:

First pass implementation of loss recording framework.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_bpf.c

    rf2fae49 r50bbce8  
    6262        int remaining;
    6363        unsigned int linktype;
     64        struct bpf_stat stats;
     65        int stats_valid;
    6466};
    6567
     
    7577        FORMATIN(libtrace)->promisc = 0;
    7678        FORMATIN(libtrace)->snaplen = 65536;
     79        FORMATIN(libtrace)->stats_valid = 0;
    7780
    7881        return 0;
     
    193196        }
    194197
     198        FORMATIN(libtrace)->stats_valid = 0;
     199
    195200        /* TODO: we should always set a bpf filter for snapping */
    196201
    197202        /* We're done! */
    198203        return 0;
     204}
     205
     206static uint64_t bpf_get_received_packets(libtrace_t *trace)
     207{
     208        /* If we're called with stats_valid == 0, or we're called again
     209         * then refresh the stats.  Don't refresh the stats if we're called
     210         * immediately after get_dropped_packets
     211         */
     212        if (FORMATIN(trace)->stats_valid != 2) {
     213                ioctl(FORMATIN(trace)->fd, BIOCGSTATS, &FORMATIN(trace)->stats);
     214                FORMATIN(trace)->stats_valid = 1;
     215        }
     216
     217        return FORMATIN(trace)->stats.bs_recv;
     218}
     219
     220static uint64_t bpf_get_dropped_packets(libtrace_t *trace)
     221{
     222        /* If we're called with stats_valid == 0, or we're called again
     223         * then refresh the stats.  Don't refresh the stats if we're called
     224         * immediately after get_received_packets
     225         */
     226        if (!FORMATIN(trace)->stats_valid != 1) {
     227                ioctl(FORMATIN(trace)->fd, BIOCGSTATS, &FORMATIN(trace)->stats);
     228                FORMATIN(trace)->stats_valid = 2;
     229        }
     230
     231        return FORMATIN(trace)->stats.bs_drop;
    199232}
    200233
     
    369402        bpf_get_framing_length, /* get_framing_length */
    370403        NULL,                   /* set_capture_length */
    371         NULL,                   /* get_received_packets */
     404        bpf_get_received_packets,/* get_received_packets */
    372405        NULL,                   /* get_filtered_packets */
    373         NULL,                   /* get_dropped_packets */
     406        bpf_get_dropped_packets,/* get_dropped_packets */
    374407        NULL,                   /* get_captured_packets */
    375408        bpf_get_fd,             /* get_fd */
Note: See TracChangeset for help on using the changeset viewer.