Changeset f0fb38f for lib/format_linux.c


Ignore:
Timestamp:
03/26/08 10:45:36 (14 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_linux.c

    r95fee28 rf0fb38f  
    331331}
    332332
     333static int linuxnative_prepare_packet(libtrace_t *libtrace,
     334                libtrace_packet_t *packet, void *buffer,
     335                libtrace_rt_types_t rt_type, uint32_t flags) {
     336
     337        if (packet->buffer != buffer &&
     338                        packet->buf_control == TRACE_CTRL_PACKET) {
     339                free(packet->buffer);
     340        }
     341
     342        if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) {
     343                packet->buf_control = TRACE_CTRL_PACKET;
     344        } else
     345                packet->buf_control = TRACE_CTRL_EXTERNAL;
     346
     347
     348        packet->buffer = buffer;
     349        packet->header = buffer;
     350        packet->payload = (char *)buffer +
     351                sizeof(struct libtrace_linuxnative_header);
     352        packet->type = rt_type;
     353
     354        if (libtrace->format_data == NULL) {
     355                if (linuxnative_init_input(libtrace))
     356                        return -1;
     357        }
     358        return 0;
     359       
     360}
     361
    333362#define LIBTRACE_MIN(a,b) ((a)<(b) ? (a) : (b))
    334363
     
    344373        socklen_t socklen;
    345374        int snaplen;
    346 
     375        uint32_t flags = 0;
     376       
    347377        if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) {
    348378                packet->buffer = malloc((size_t)LIBTRACE_PACKET_BUFSIZE);
    349                 packet->buf_control = TRACE_CTRL_PACKET;
    350         }
    351 
    352         packet->header = packet->buffer;
     379        }
     380
     381        flags |= TRACE_PREP_OWN_BUFFER;
     382       
    353383        packet->type = TRACE_RT_DATA_LINUX_NATIVE;
    354         packet->payload = (char*)packet->buffer+sizeof(*hdr);
    355384
    356385        hdr=(struct libtrace_linuxnative_header*)packet->buffer;
     
    398427                perror("ioctl(SIOCGSTAMP)");
    399428
     429        if (linuxnative_prepare_packet(libtrace, packet, packet->buffer,
     430                                packet->type, flags))
     431                return -1;
     432       
    400433        return hdr->wirelen+sizeof(*hdr);
    401434}
     
    490523
    491524static int linuxnative_get_fd(const libtrace_t *trace) {
     525        if (trace->format_data == NULL)
     526                return -1;
    492527        return FORMAT(trace->format_data)->fd;
    493528}
     
    506541/* Number of packets that past filtering */
    507542static uint64_t linuxnative_get_captured_packets(libtrace_t *trace) {
     543        if (trace->format_data == NULL)
     544                return UINT64_MAX;
     545        if (FORMAT(trace->format_data)->fd == -1) {
     546                /* This is probably a 'dead' trace so obviously we can't query
     547                 * the socket for capture counts, can we? */
     548                return UINT64_MAX;
     549        }
     550       
    508551        if ((FORMAT(trace->format_data)->stats_valid & 1)
    509552                        || FORMAT(trace->format_data)->stats_valid == 0) {
     
    524567 */
    525568static uint64_t linuxnative_get_dropped_packets(libtrace_t *trace) {
     569        if (trace->format_data == NULL)
     570                return UINT64_MAX;
     571        if (FORMAT(trace->format_data)->fd == -1) {
     572                /* This is probably a 'dead' trace so obviously we can't query
     573                 * the socket for drop counts, can we? */
     574                return UINT64_MAX;
     575        }
     576       
    526577        if ((FORMAT(trace->format_data)->stats_valid & 2)
    527578                        || (FORMAT(trace->format_data)->stats_valid==0)) {
     
    562613        linuxnative_fin_output,         /* fin_output */
    563614        linuxnative_read_packet,        /* read_packet */
     615        linuxnative_prepare_packet,     /* prepare_packet */
    564616        NULL,                           /* fin_packet */
    565617        linuxnative_write_packet,       /* write_packet */
Note: See TracChangeset for help on using the changeset viewer.