Changeset f0fb38f for lib/format_bpf.c


Ignore:
Timestamp:
03/26/08 10:45:36 (13 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:
f52bcdd
Parents:
e632f2f
Message:
  • Added prepare_packet functions to all formats, primarily to support translating RT packets into the appropriate format. These functions are all used internally as well, as most formats still need to "prepare" packets that have been read by setting pointers, updating loss counters etc.
  • Also added a trace_prepare_packet function, but this is not made available externally at this stage
  • Added init_format_data functions to some formats to initialise format data structures in cases where the init_trace function does more than just that
  • Refactored rt packet reading code to use the new trace_prepare_packet functionality - also did a lot of tidying of the code
  • Added missing RT type for BPF format
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_bpf.c

    r95fee28 rf0fb38f  
    206206static uint64_t bpf_get_received_packets(libtrace_t *trace)
    207207{
     208        if (trace->format_data == NULL)
     209                return (uint64_t)-1;
     210
     211        if (FORMATIN(trace)->fd == -1) {
     212                /* Almost certainly a 'dead' trace so there is no socket
     213                 * for us to query */
     214                return (uint64_t) -1;
     215        }
    208216        /* If we're called with stats_valid == 0, or we're called again
    209217         * then refresh the stats.  Don't refresh the stats if we're called
     
    221229static uint64_t bpf_get_dropped_packets(libtrace_t *trace)
    222230{
     231        if (trace->format_data == NULL)
     232                return (uint64_t)-1;
     233
     234        if (FORMATIN(trace)->fd == -1) {
     235                /* Almost certainly a 'dead' trace so there is no socket
     236                 * for us to query */
     237                return (uint64_t) -1;
     238        }
    223239        /* If we're called with stats_valid == 0, or we're called again
    224240         * then refresh the stats.  Don't refresh the stats if we're called
     
    282298}
    283299
     300static int bpf_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet,
     301                void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) {
     302        if (packet->buffer != buffer &&
     303                        packet->buf_control == TRACE_CTRL_PACKET) {
     304                free(packet->buffer);
     305        }
     306
     307        if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) {
     308                packet->buf_control = TRACE_CTRL_PACKET;
     309        } else
     310                packet->buf_control = TRACE_CTRL_EXTERNAL;
     311
     312
     313        packet->buffer = buffer;
     314        packet->header = buffer;
     315        packet->type = rt_type;
     316
     317        /* Find the payload */
     318        /* TODO: Pcap deals with a padded FDDI linktype here */
     319        packet->payload=(char *)buffer + BPFHDR(packet)->bh_hdrlen;
     320
     321        if (libtrace->format_data == NULL) {
     322                if (bpf_init_input(libtrace))
     323                        return -1;
     324        }
     325
     326        return 0;
     327}
     328       
    284329static int bpf_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet)
    285330{
     331        uint32_t flags = 0;
     332       
    286333        /* Fill the buffer */
    287334        if (FORMATIN(libtrace)->remaining<=0) {
     
    311358        if (packet->buf_control == TRACE_CTRL_PACKET)
    312359                free(packet->buffer);
    313         packet->buf_control = TRACE_CTRL_EXTERNAL;
    314 
    315         /* Find the bpf header */
    316         packet->header=FORMATIN(libtrace)->bufptr;
    317 
    318         /* Find the payload */
    319         /* TODO: Pcap deals with a padded FDDI linktype here */
    320         packet->payload=FORMATIN(libtrace)->bufptr+BPFHDR(packet)->bh_hdrlen;
     360
     361        if (bpf_prepare_packet(libtrace, packet, FORMATIN(libtrace)->bufptr,
     362                TRACE_RT_DATA_BPF, flags)) {
     363                return -1;
     364        }
     365       
    321366
    322367        /* Now deal with any padding */
     
    389434        NULL,                   /* fin_output */
    390435        bpf_read_packet,        /* read_packet */
     436        bpf_prepare_packet,     /* prepare_packet */
    391437        NULL,                   /* fin_packet */
    392438        NULL,                   /* write_packet */
Note: See TracChangeset for help on using the changeset viewer.