Changeset 509ee47 for lib


Ignore:
Timestamp:
12/10/18 14:52:43 (22 months 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.

Location:
lib
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • lib/format_erf.c

    rc337c9f9 r509ee47  
    254254                        IN_OPTIONS.real_time = *(int *)value;
    255255                        return 0;
     256                case TRACE_OPTION_CONSTANT_ERF_FRAMING:
     257                        trace_set_err(libtrace, TRACE_ERR_OPTION_UNAVAIL,
     258                                        "Setting constant framing length is not supported for %s:", libtrace->format->name);
     259                        return -1;
    256260                case TRACE_OPTION_SNAPLEN:
    257261                case TRACE_OPTION_PROMISC:
     
    667671{
    668672        int numbytes = 0;
    669         unsigned int pad = 0;
    670673        dag_record_t *dag_hdr = (dag_record_t *)packet->header;
    671674        void *payload = packet->payload;
     
    684687        }
    685688       
    686         pad = erf_get_padding(packet);
    687689
    688690        /* If we've had an rxerror, we have no payload to write - fix
     
    692694         * a way to write out the payload even if it is gibberish -- Perry */
    693695        if (payload == NULL) {
     696                unsigned int pad = 0;
     697                pad = erf_get_padding(packet);
    694698                dag_hdr->rlen = htons(dag_record_size + pad);
    695699               
     
    720724
    721725                payload=packet->payload;
    722                 pad = erf_get_padding(packet);
    723726
    724727                erfhdr.type = libtrace_to_erf_type(trace_get_link_type(packet));
  • lib/format_linux_common.c

    r2193905 r509ee47  
    167167                case TRACE_OPTION_REPLAY_SPEEDUP:
    168168                        break;
     169                case TRACE_OPTION_CONSTANT_ERF_FRAMING:
     170                        break;
    169171                /* Avoid default: so that future options will cause a warning
    170172                 * here to remind us to implement it, or flag it as
  • 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 */
  • lib/format_pcapfile.c

    r2193905 r509ee47  
    267267                case TRACE_OPTION_HASHER:
    268268                case TRACE_OPTION_REPLAY_SPEEDUP:
     269                case TRACE_OPTION_CONSTANT_ERF_FRAMING:
    269270                        /* All these are either unsupported or handled
    270271                         * by trace_config */
  • lib/format_pcapng.c

    r2193905 r509ee47  
    263263                case TRACE_OPTION_HASHER:
    264264                case TRACE_OPTION_REPLAY_SPEEDUP:
     265                case TRACE_OPTION_CONSTANT_ERF_FRAMING:
    265266                        break;
    266267        }
  • lib/libtrace.h.in

    rf6f3ae5 r509ee47  
    13661366        /** Speed up trace file replays (via trace_event()) by this factor */
    13671367        TRACE_OPTION_REPLAY_SPEEDUP,
     1368
     1369        /** Always assume ERF framing length is the given value, rather than
     1370         *  trying to calculate it from the packet type. */
     1371        TRACE_OPTION_CONSTANT_ERF_FRAMING,
    13681372} trace_option_t;
    13691373
  • lib/trace.c

    r9c86dee r509ee47  
    674674                        /* Dealt with earlier */
    675675                        return -1;
     676                case TRACE_OPTION_CONSTANT_ERF_FRAMING:
     677                        if (!trace_is_err(libtrace)) {
     678                                trace_set_err(libtrace,
     679                                                TRACE_ERR_OPTION_UNAVAIL,
     680                                                "This format does not feature an ERF header or does not support bypassing the framing length calculation");
     681                        }
     682                        return -1;
     683
    676684
    677685        }
Note: See TracChangeset for help on using the changeset viewer.