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_legacy.c

    rf3f3558 rf0fb38f  
    6969};
    7070
     71static void legacy_init_format_data(libtrace_t *libtrace) {
     72        libtrace->format_data = malloc(sizeof(struct legacy_format_data_t));
     73       
     74        DATA(libtrace)->input.file = NULL;
     75        DATA(libtrace)->ts_high = 0;
     76        DATA(libtrace)->ts_old = 0;
     77        DATA(libtrace)->starttime = 0;
     78}
     79
    7180static int legacyeth_get_framing_length(const libtrace_packet_t *packet UNUSED)
    7281{
     
    91100static int erf_init_input(libtrace_t *libtrace)
    92101{
    93         libtrace->format_data = malloc(sizeof(struct legacy_format_data_t));
    94 
    95         DATA(libtrace)->input.file = NULL;
     102        legacy_init_format_data(libtrace);
    96103
    97104        return 0;
     
    136143        regmatch_t match;
    137144
    138         libtrace->format_data = malloc(sizeof(struct legacy_format_data_t));
    139 
    140         DATA(libtrace)->input.file = NULL;
    141        
     145
     146        legacy_init_format_data(libtrace);     
    142147        if((retval = regcomp(&reg, "[0-9]{8}-[0-9]{6}", REG_EXTENDED)) != 0) {
    143148                trace_set_err(libtrace, errno, "Failed to compile regex");
     
    149154        }
    150155        DATA(libtrace)->starttime = trtime(&filename[match.rm_so]);
    151         DATA(libtrace)->ts_high = 0;
    152         DATA(libtrace)->ts_old = 0;
    153156        return 0;
    154157}
     
    173176}
    174177
     178static int legacy_prepare_packet(libtrace_t *libtrace,
     179                libtrace_packet_t *packet, void *buffer,
     180                libtrace_rt_types_t rt_type, uint32_t flags) {
     181
     182        if (packet->buffer != buffer &&
     183                        packet->buf_control == TRACE_CTRL_PACKET) {
     184                free(packet->buffer);
     185        }
     186
     187        if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) {
     188                packet->buf_control = TRACE_CTRL_PACKET;
     189        } else
     190                packet->buf_control = TRACE_CTRL_EXTERNAL;
     191
     192
     193        packet->buffer = buffer;
     194        packet->header = buffer;
     195        packet->type = rt_type;
     196        packet->payload = (void*)((char*)packet->buffer +
     197                libtrace->format->get_framing_length(packet));
     198
     199
     200        if (libtrace->format_data == NULL) {
     201                legacy_init_format_data(libtrace);
     202        }
     203        return 0;
     204}
     205
    175206static int legacy_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) {
    176207        int numbytes;
    177208        void *buffer;
    178 
     209        uint32_t flags = 0;
     210       
    179211        if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) {
    180                 packet->buf_control = TRACE_CTRL_PACKET;
    181212                packet->buffer=malloc((size_t)LIBTRACE_PACKET_BUFSIZE);
    182213        }
     214        flags |= TRACE_PREP_OWN_BUFFER;
    183215        buffer = packet->buffer;
    184216
     
    215247        }
    216248       
    217         packet->header = packet->buffer;
    218         packet->payload = (void*)((char*)packet->buffer +
    219                 libtrace->format->get_framing_length(packet));
     249        if (legacy_prepare_packet(libtrace, packet, packet->buffer,
     250                                packet->type, flags)) {
     251                return -1;
     252        }
    220253       
    221254        return 64;
     
    231264        void *buffer;
    232265        char *data_ptr;
     266        uint32_t flags = 0;
    233267       
    234268        if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) {
    235                 packet->buf_control = TRACE_CTRL_PACKET;
    236269                packet->buffer=malloc((size_t)LIBTRACE_PACKET_BUFSIZE);
    237270        }
     271        flags |= TRACE_PREP_OWN_BUFFER;
     272       
    238273        buffer = packet->buffer;
    239 
    240274        packet->type = TRACE_RT_DATA_LEGACY_NZIX;
    241275       
     
    263297        memmove(data_ptr + 2, data_ptr, 26);
    264298
    265         packet->header = packet->buffer;
    266         packet->payload = (void*)((char*)packet->buffer +
    267                         libtrace->format->get_framing_length(packet));
     299        if (legacy_prepare_packet(libtrace, packet, packet->buffer,
     300                                packet->type, flags)) {
     301                return -1;
     302        }
    268303        return 68;
    269304}
     
    432467        NULL,                           /* fin_output */
    433468        legacy_read_packet,             /* read_packet */
     469        legacy_prepare_packet,          /* prepare_packet */
    434470        NULL,                           /* fin_packet */
    435471        NULL,                           /* write_packet */
     
    471507        NULL,                           /* fin_output */
    472508        legacy_read_packet,             /* read_packet */
     509        legacy_prepare_packet,          /* prepare_packet */
    473510        NULL,                           /* fin_packet */
    474511        NULL,                           /* write_packet */
     
    510547        NULL,                           /* fin_output */
    511548        legacy_read_packet,             /* read_packet */
     549        legacy_prepare_packet,          /* prepare_packet */
    512550        NULL,                           /* fin_packet */
    513551        NULL,                           /* write_packet */
     
    549587        NULL,                           /* fin_output */
    550588        legacynzix_read_packet,         /* read_packet */
     589        legacy_prepare_packet,          /* prepare_packet */
    551590        NULL,                           /* fin_packet */
    552591        NULL,                           /* write_packet */
Note: See TracChangeset for help on using the changeset viewer.