Changeset 509ee47 for lib/format_ndag.c


Ignore:
Timestamp:
12/10/18 14:52:43 (2 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
develop
Children:
418c78d
Parents:
54ef438
Message:

Add option to allow users to specify a constant ERF framing length.

This can be useful for situations where

a) the input uses ERF (or some derivative thereof)
b) the link type and ERF record type are constant for the

duration of the capture

c) performance is critical

This option allows users to simply tell libtrace what the ERF
framing length on every packet is going to be, so libtrace
doesn't have to repeatedly derive the framing length for each
packet it processes. At high packet rates, the time taken to
do this calculation can really add up and it makes no sense
to risk dropping packets because you're busy calculating a value
that is always a single constant value.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_ndag.c

    r54ef438 r509ee47  
    125125        pthread_t controlthread;
    126126        libtrace_message_queue_t controlqueue;
     127        int consterfframing;
    127128} ndag_format_data_t;
    128129
     
    296297        FORMAT_DATA->nextthreadid = 0;
    297298        FORMAT_DATA->receivers = NULL;
     299        FORMAT_DATA->consterfframing = -1;
    298300
    299301        scan = strchr(libtrace->uridata, ',');
     
    316318                FORMAT_DATA->portstr = strdup(scan + 1);
    317319        }
     320        return 0;
     321}
     322
     323static int ndag_config_input(libtrace_t *libtrace, trace_option_t option,
     324                void *value) {
     325
     326        switch(option) {
     327                case TRACE_OPTION_CONSTANT_ERF_FRAMING:
     328                        FORMAT_DATA->consterfframing = *(int *)value;
     329                        break;
     330                case TRACE_OPTION_EVENT_REALTIME:
     331                case TRACE_OPTION_SNAPLEN:
     332                case TRACE_OPTION_PROMISC:
     333                case TRACE_OPTION_FILTER:
     334                case TRACE_OPTION_META_FREQ:
     335                default:
     336                        trace_set_err(libtrace, TRACE_ERR_OPTION_UNAVAIL,
     337                                        "Unsupported option");
     338                        return -1;
     339        }
     340
    318341        return 0;
    319342}
     
    597620}
    598621
    599 static int ndag_prepare_packet_stream(libtrace_t *libtrace,
    600                 recvstream_t *rt,
    601                 streamsock_t *ssock, libtrace_packet_t *packet,
    602                 uint32_t flags) {
     622static int ndag_get_framing_length(const libtrace_packet_t *packet) {
     623
     624        libtrace_t *libtrace = packet->trace;
     625
     626        if (FORMAT_DATA->consterfframing >= 0) {
     627                return FORMAT_DATA->consterfframing;
     628        }
     629        return erf_get_framing_length(packet);
     630}
     631
     632static int ndag_prepare_packet_stream(libtrace_t *restrict libtrace,
     633                recvstream_t *restrict rt,
     634                streamsock_t *restrict ssock,
     635                libtrace_packet_t *restrict packet,
     636                uint32_t flags UNUSED) {
     637
     638        /* XXX flags is constant, so we can tell the compiler to not
     639         * bother copying over the parameter
     640         */
    603641
    604642        dag_record_t *erfptr;
     
    608646        uint16_t rlen;
    609647
     648        /*
    610649        if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) {
    611650                packet->buf_control = TRACE_CTRL_PACKET;
     
    613652                packet->buf_control = TRACE_CTRL_EXTERNAL;
    614653        }
     654        */
     655        packet->buf_control = TRACE_CTRL_EXTERNAL;
    615656
    616657        packet->trace = libtrace;
     
    623664        if (erfptr->flags.rxerror == 1) {
    624665                packet->payload = NULL;
    625                 erfptr->rlen = htons(erf_get_framing_length(packet));
     666                if (FORMAT_DATA->consterfframing >= 0) {
     667                        erfptr->rlen = htons(FORMAT_DATA->consterfframing & 0xffff);
     668                } else {
     669                        erfptr->rlen = htons(erf_get_framing_length(packet));
     670                }
    626671        } else {
    627                 packet->payload = (char *)packet->buffer +
     672                if (FORMAT_DATA->consterfframing >= 0) {
     673                        packet->payload = (char *)packet->buffer +
     674                                FORMAT_DATA->consterfframing;
     675                } else {
     676                        packet->payload = (char *)packet->buffer +
    628677                                erf_get_framing_length(packet);
     678                }
    629679        }
    630680
     
    14531503        NULL,                   /* probe magic */
    14541504        ndag_init_input,        /* init_input */
    1455         NULL,                   /* config_input */
     1505        ndag_config_input,      /* config_input */
    14561506        ndag_start_input,       /* start_input */
    14571507        ndag_pause_input,       /* pause_input */
     
    14781528        erf_get_capture_length, /* get_capture_length */
    14791529        erf_get_wire_length,    /* get_wire_length */
    1480         erf_get_framing_length, /* get_framing_length */
     1530        ndag_get_framing_length, /* get_framing_length */
    14811531        erf_set_capture_length, /* set_capture_length */
    14821532        NULL,                   /* get_received_packets */
Note: See TracChangeset for help on using the changeset viewer.