Changeset b3dca4d


Ignore:
Timestamp:
09/14/15 11:25:29 (5 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, 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:
a6b44a7
Parents:
322c516
Message:

Don't rely on rlen for determining write sizes for ERF packets

Sometimes rlen is greater than the capture + framing length for a packet, e.g.
in cases where the wlen is less than the rlen. Basing our arithmetic off
rlen can mean that we try to write too much data (especially if the packet
buffer has been sized to perfectly fit the packet according to
trace_get_capture_length and trace_get_framing_length). This will happen
if the ERF packets have been received via RT, for instance.

Also replace use of "dag_record_size + pad" with trace_get_framing_length() in
the same arithmetic, so that our write sizes are correct in the presence of
ERF extension headers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_erf.c

    r7c17e4a rb3dca4d  
    559559
    560560static int erf_dump_packet(libtrace_out_t *libtrace,
    561                 dag_record_t *erfptr, unsigned int pad, void *buffer) {
     561                dag_record_t *erfptr, int framinglen, void *buffer,
     562                int caplen) {
    562563        int numbytes = 0;
    563564        int size;
     
    566567                wandio_wwrite(OUTPUT->file,
    567568                                erfptr,
    568                                 (size_t)(dag_record_size + pad)))
    569                         != (int)(dag_record_size+pad)) {
     569                                (size_t)(framinglen)))
     570                        != (int)(framinglen)) {
    570571                trace_set_err_out(libtrace,errno,
    571572                                "write(%s)",libtrace->uridata);
     
    573574        }
    574575
    575         size=ntohs(erfptr->rlen)-(dag_record_size+pad);
    576         numbytes=wandio_wwrite(OUTPUT->file, buffer, (size_t)size);
     576        size=caplen-(framinglen);
     577        numbytes=wandio_wwrite(OUTPUT->file, buffer, (size_t)size);
    577578        if (numbytes != size) {
    578579                trace_set_err_out(libtrace,errno,
     
    580581                return -1;
    581582        }
    582         return numbytes + pad + dag_record_size;
     583        return numbytes + framinglen;
    583584}
    584585
     
    653654                        numbytes = erf_dump_packet(libtrace,
    654655                                (dag_record_t *)packet->header,
    655                                 pad,
    656                                 payload
     656                                trace_get_framing_length(packet),
     657                                payload,
     658                                trace_get_capture_length(packet)
    657659                                );
    658660        } else {
     
    698700                numbytes = erf_dump_packet(libtrace,
    699701                                &erfhdr,
    700                                 pad,
    701                                 payload);
     702                                framing,
     703                                payload,
     704                                trace_get_capture_length(packet));
    702705        }
    703706        return numbytes;
Note: See TracChangeset for help on using the changeset viewer.