Changeset 14d8a63 for lib


Ignore:
Timestamp:
11/25/05 16:12:39 (16 years ago)
Author:
Daniel Lawson <dlawson@…>
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:
3840760
Parents:
e9fa643
Message:

update to version 3.0.0
zero-copy patch - trace.c updated with new trace_create_packet() etc
format_*.c updated with zero-copy codepath

Location:
lib
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • lib/Makefile.am

    r14e6840c r14d8a63  
    99INCLUDES = @ADD_INCLS@
    1010libtrace_la_LIBADD = @ADD_LIBS@ @LTLIBOBJS@
    11 libtrace_la_LDFLAGS=-version-info 2:25:0 @ADD_LDFLAGS@
     11libtrace_la_LDFLAGS=-version-info 3:0:0 @ADD_LDFLAGS@
    1212
    1313dagapi.c:
  • lib/format_erf.c

    r79dbcef r14d8a63  
    6363#include <stdlib.h>
    6464
    65 /*
    66  gzread (gzFile, buf, len)
    67  gzdopen(path, mode)
    68  gzopen(path, mode)
    69  gzclose(gzFile)
    70  gzwrite(gzFile, buf, len)
    71 
    72  fread(ptr, size, num, FILE)
    73  fdopen(filedes,mode)
    74  fopen(path, mode)
    75  fclose(FILE)
    76  fwrite(ptr, size, num, FILE)
    77 */
    78 /*
    79 #if HAVE_ZLIB
    80 #  include <zlib.h>
    81 #  define LIBTRACE_READ(file,buf,len) gzread(file,buf,len)
    82 #  define LIBTRACE_FDOPEN(fd,mode) gzdopen(fd,mode)
    83 #  define LIBTRACE_OPEN(path,mode) gzopen(path,mode)
    84 #  define LIBTRACE_CLOSE(file) gzclose(file)
    85 #  define LIBTRACE_WRITE(file,buf,len) gzwrite(file,buf,len)
    86 #else
    87 #  define LIBTRACE_READ(file,buf,len) fread(buf,len,1,file)
    88 #  define LIBTRACE_FDOPEN(fd,mode) fdopen(fd,mode)
    89 #  define LIBTRACE_OPEN(path,mode) fopen(path,mode)
    90 #  define LIBTRACE_CLOSE(file) fclose(file)
    91 #  define LIBTRACE_WRITE(file,buf,len) fwrite(buf,len,1,file)
    92 #endif
    93 */
     65
    9466#define COLLECTOR_PORT 3435
    9567
     
    491463        void *buffer2 = buffer;
    492464        int rlen;
    493        
     465
     466        if (packet->buf_control == PACKET) {
     467                packet->buf_control = EXTERNAL;
     468                free(packet->buffer);
     469                packet->buffer = 0;
     470        }
     471   
    494472        if (DAG.diff == 0) {
    495473                if ((numbytes = dag_read(libtrace,buf,RP_BUFSIZE)) <= 0)
     
    505483                assert( size < LIBTRACE_PACKET_BUFSIZE);
    506484        }
    507 
    508         // have to copy it out of the memory hole at this stage:
    509         memcpy(packet->buffer, erfptr, size);
     485       
     486        packet->buffer = erfptr;
     487        packet->header = erfptr;
     488        if (((dag_record_t *)buffer)->flags.rxerror == 1) {
     489                packet->payload = NULL;
     490        } else {
     491                packet->payload = packet->buffer + erf_get_framing_length(packet);
     492        }
     493
    510494       
    511495        packet->status.type = RT_DATA;
     
    528512        int rlen;
    529513
     514        if (packet->buf_control == EXTERNAL) {
     515                packet->buf_control = PACKET;
     516                packet = malloc(LIBTRACE_PACKET_BUFSIZE);
     517        }
     518       
    530519        if ((numbytes=LIBTRACE_READ(INPUT.file,
    531520                                        buffer,
     
    552541        packet->status.type = RT_DATA;
    553542        packet->status.message = 0;
     543       
     544        packet->header = packet->buffer;
     545        packet->payload = packet->trace->format->get_link(packet);
     546       
    554547        packet->size = rlen;
    555548        return rlen;
     549       
    556550}
    557551static int erf_read_packet(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) {
     
    561555        void *buffer2 = buffer;
    562556        int rlen;
     557        if (packet->buf_control == EXTERNAL) {
     558                packet->buf_control = PACKET;
     559                packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE);
     560        }
     561        buffer = packet->buffer;
     562        packet->header = packet->buffer;
     563
     564
    563565        if ((numbytes=LIBTRACE_READ(INPUT.file,
    564566                                        buffer,
     
    595597        packet->status.message = 0;
    596598        packet->size = rlen;
     599        if (((dag_record_t *)buffer)->flags.rxerror == 1) {
     600                packet->payload = NULL;
     601        } else {
     602                packet->payload = packet->buffer + erf_get_framing_length(packet);
     603        }
    597604        return rlen;
    598605}
     
    634641
    635642        packet->trace = libtrace;
     643
     644        if (packet->buf_control == EXTERNAL) {
     645                packet->buf_control = PACKET;
     646                packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE);
     647        }
     648
    636649        buffer = packet->buffer;
     650        packet->header = packet->buffer;
    637651
    638652       
     
    698712
    699713                //packet->size = numbytes;
     714                if (((dag_record_t *)buffer)->flags.rxerror == 1) {
     715                        packet->payload = NULL;
     716                } else {
     717                        packet->payload = packet->buffer + erf_get_framing_length(packet);
     718                }
    700719                return numbytes;
    701720        } while(1);
     
    724743        dag_record_t erfhdr;
    725744        int pad = 0;
    726         dag_record_t *dag_hdr = (dag_record_t *)packet->buffer;
    727         void *payload = (void *)trace_get_link(packet);
     745        dag_record_t *dag_hdr = (dag_record_t *)packet->header;
     746        void *payload = packet->payload;
    728747
    729748        pad = erf_get_padding(packet);
     
    769788}
    770789
    771 
    772790static void *legacypos_get_link(const struct libtrace_packet_t *packet) {
     791        return (void *)packet->payload;
     792        /*
    773793        const void *posptr = 0;
    774         posptr = ((uint8_t *)packet->buffer +
     794        posptr = ((uint8_t *)packet-> +
    775795                        legacypos_get_framing_length(packet));
    776796        return (void *)posptr;
     797        */
    777798}
    778799
     
    782803
    783804static void *legacyatm_get_link(const struct libtrace_packet_t *packet) {
     805        return (void *)packet->payload;
     806        /*
    784807        const void *atmptr = 0;
    785808        atmptr = ((uint8_t *)packet->buffer +
    786809                        legacyatm_get_framing_length(packet));
    787810        return (void *)atmptr;
     811        */
    788812}
    789813
     
    793817
    794818static void *legacyeth_get_link(const struct libtrace_packet_t *packet) {
     819        return (void *)packet->payload;
     820        /*
    795821        const void *ethptr = 0;
    796822        ethptr = ((uint8_t *)packet->buffer +
    797823                        legacyeth_get_framing_length(packet));
    798824        return (void *)ethptr;
     825        */
    799826}
    800827
     
    806833
    807834static void *erf_get_link(const struct libtrace_packet_t *packet) {
    808         const void *ethptr = 0;
     835        return (void *)packet->payload;
     836/*        const void *ethptr = 0;
    809837        dag_record_t *erfptr = 0;
    810         erfptr = (dag_record_t *)packet->buffer;
     838        erfptr = (dag_record_t *)packet->header;
    811839       
    812840        if (erfptr->flags.rxerror == 1) {
     
    816844                        erf_get_framing_length(packet));
    817845        return (void *)ethptr;
     846*/
     847
    818848}
    819849
    820850static libtrace_linktype_t erf_get_link_type(const struct libtrace_packet_t *packet) {
    821851        dag_record_t *erfptr = 0;
    822         erfptr = (dag_record_t *)packet->buffer;
     852        erfptr = (dag_record_t *)packet->header;
    823853        switch (erfptr->type) {
    824854                case TYPE_LEGACY:       return TRACE_TYPE_LEGACY;
     
    834864static int8_t erf_get_direction(const struct libtrace_packet_t *packet) {
    835865        dag_record_t *erfptr = 0;
    836         erfptr = (dag_record_t *)packet->buffer;
     866        erfptr = (dag_record_t *)packet->header;
    837867        return erfptr->flags.iface;
    838868}
     
    840870static int8_t erf_set_direction(const struct libtrace_packet_t *packet, int8_t direction) {
    841871        dag_record_t *erfptr = 0;
    842         erfptr = (dag_record_t *)packet->buffer;
     872        erfptr = (dag_record_t *)packet->header;
    843873        erfptr->flags.iface = direction;
    844874        return erfptr->flags.iface;
     
    847877static uint64_t erf_get_erf_timestamp(const struct libtrace_packet_t *packet) {
    848878        dag_record_t *erfptr = 0;
    849         erfptr = (dag_record_t *)packet->buffer;
     879        erfptr = (dag_record_t *)packet->header;
    850880        return erfptr->ts;
    851881}
     
    856886
    857887static int legacypos_get_wire_length(const struct libtrace_packet_t *packet) {
    858         legacy_pos_t *lpos = (legacy_pos_t *)packet->buffer;
     888        legacy_pos_t *lpos = (legacy_pos_t *)packet->header;
    859889        return ntohs(lpos->wlen);
    860890}
     
    865895
    866896static int legacyeth_get_wire_length(const struct libtrace_packet_t *packet) {
    867         legacy_ether_t *leth = (legacy_ether_t *)packet->buffer;
     897        legacy_ether_t *leth = (legacy_ether_t *)packet->header;
    868898        return ntohs(leth->wlen);
    869899}
    870900static int erf_get_capture_length(const struct libtrace_packet_t *packet) {
    871901        dag_record_t *erfptr = 0;
    872         erfptr = (dag_record_t *)packet->buffer;
     902        erfptr = (dag_record_t *)packet->header;
    873903        return (ntohs(erfptr->rlen) - erf_get_framing_length(packet));
    874904}
     
    876906static int erf_get_wire_length(const struct libtrace_packet_t *packet) {
    877907        dag_record_t *erfptr = 0;
    878         erfptr = (dag_record_t *)packet->buffer;
     908        erfptr = (dag_record_t *)packet->header;
    879909        return ntohs(erfptr->wlen);
    880910}
     
    887917                return (packet->size - erf_get_framing_length(packet));
    888918        }
    889         erfptr = (dag_record_t *)packet->buffer;
     919        erfptr = (dag_record_t *)packet->header;
    890920        erfptr->rlen = htons(size + erf_get_framing_length(packet));
    891921        packet->size = size + erf_get_framing_length(packet);
    892         return size;
     922        return packet->size;
    893923}
    894924
  • lib/format_pcap.c

    r187a6d6 r14d8a63  
    210210        int numbytes = 0;
    211211       
    212         memcpy(buffer,pcaphdr,sizeof(struct pcap_pkthdr));
     212        // This is ugly, but seems to be needed. We want both the
     213        // header and the payload in the same block of memory (packet->buffer)
     214        //memcpy(buffer,pcaphdr,sizeof(struct pcap_pkthdr));
    213215        numbytes = pcaphdr->len;
    214         memcpy(buffer + sizeof(struct pcap_pkthdr),pcappkt,numbytes);
     216        //memcpy(buffer + sizeof(struct pcap_pkthdr),pcappkt,numbytes);
     217
     218        //packet->header = packet->buffer;
     219        //packet->payload = packet->header + sizeof(struct pcap_pkthdr);
     220        packet->header = (void *)pcaphdr;
     221        packet->payload = (void *)pcappkt;
     222
    215223
    216224        packet->size = numbytes + sizeof(struct pcap_pkthdr);
     
    235243static int pcap_write_packet(struct libtrace_out_t *libtrace, const struct libtrace_packet_t *packet) {
    236244        struct pcap_pkthdr pcap_pkt_hdr;
    237         void *link = trace_get_link(packet);
    238245
    239246        if (!OUTPUT.trace.pcap) {
     
    247254                        packet->trace->format == &pcapint) {
    248255               
    249                 pcap_dump((u_char*)OUTPUT.trace.dump,(struct pcap_pkthdr *)packet->buffer,link);
     256                pcap_dump((u_char*)OUTPUT.trace.dump,(struct pcap_pkthdr *)packet->header,packet->payload);
    250257        } else {
    251258                // Leave the manual copy as it is, as it gets around
     
    257264                pcap_pkt_hdr.len = trace_get_wire_length(packet);
    258265
    259                 pcap_dump((u_char*)OUTPUT.trace.dump, &pcap_pkt_hdr, link);
     266                pcap_dump((u_char*)OUTPUT.trace.dump, &pcap_pkt_hdr, packet->payload);
    260267        }
    261268        return 0;
     
    269276
    270277static void *pcap_get_link(const struct libtrace_packet_t *packet) {
    271         return (void *) (packet->buffer + sizeof(struct pcap_pkthdr));
     278        return (void *) packet->payload;
    272279}
    273280
     
    275282        struct pcap_pkthdr *pcapptr = 0;
    276283        int linktype = 0;
    277         pcapptr = (struct pcap_pkthdr *)packet->buffer;
     284        pcapptr = (struct pcap_pkthdr *)packet->header;
    278285        linktype = pcap_datalink(packet->trace->format_data->input.pcap);
    279286        switch(linktype) {
     
    352359
    353360static struct timeval pcap_get_timeval(const struct libtrace_packet_t *packet) {
    354         struct pcap_pkthdr *pcapptr = (struct pcap_pkthdr *)packet->buffer;
     361        struct pcap_pkthdr *pcapptr = (struct pcap_pkthdr *)packet->header;
    355362        struct timeval ts;
    356363        ts.tv_sec = pcapptr->ts.tv_sec;
     
    362369static int pcap_get_capture_length(const struct libtrace_packet_t *packet) {
    363370        struct pcap_pkthdr *pcapptr = 0;
    364         pcapptr = (struct pcap_pkthdr *)packet->buffer;
     371        pcapptr = (struct pcap_pkthdr *)packet->header;
    365372        return pcapptr->caplen;
    366373}
     
    368375static int pcap_get_wire_length(const struct libtrace_packet_t *packet) {
    369376        struct pcap_pkthdr *pcapptr = 0;
    370         pcapptr = (struct pcap_pkthdr *)packet->buffer;
     377        pcapptr = (struct pcap_pkthdr *)packet->header;
    371378        return ntohs(pcapptr->len);
    372379}
     
    383390                return (packet->size - sizeof(struct pcap_pkthdr));
    384391        }
    385         pcapptr = (struct pcap_pkthdr *)packet->buffer;
     392        pcapptr = (struct pcap_pkthdr *)packet->header;
    386393        pcapptr->caplen = size;
    387394        packet->size = size + sizeof(struct pcap_pkthdr);
    388         return size;
     395        return packet->size;
    389396}
    390397
  • lib/format_wag.c

    r79dbcef r14d8a63  
    276276        void *buffer = 0;
    277277
     278        if (packet->buf_control == EXTERNAL) {
     279                packet->buf_control = PACKET;
     280                packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE);
     281        }
    278282        packet->trace = libtrace;
    279283        buffer = packet->buffer;
     
    318322                packet->status.type = RT_DATA;
    319323                packet->status.message = 0;
     324                packet->header = packet->buffer;
     325                packet->payload = packet->buffer + pcap_get_framing_length(packet);
    320326                packet->size = numbytes;
    321327                return numbytes;
     
    338344
    339345static void *wag_get_link(const struct libtrace_packet_t *packet) {
     346        return (void *)packet->payload;
     347        /*
    340348        struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->buffer;
    341349        void *payload = wagptr->data;
    342350        return (void*)payload;
     351        */
    343352}
    344353
     
    348357
    349358static int8_t wag_get_direction(const struct libtrace_packet_t *packet) {
    350         struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->buffer;
     359        struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->header;
    351360        if (wagptr->hdr.type == 0) {
    352361                return wagptr->hdr.subtype;
     
    356365
    357366static uint64_t wag_get_erf_timestamp(const struct libtrace_packet_t *packet) {
    358         struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->buffer;
     367        struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->header;
    359368        uint64_t timestamp = 0;
    360369        timestamp = wagptr->ts.subsecs;
     
    366375
    367376static int wag_get_capture_length(const struct libtrace_packet_t *packet) {
    368         struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->buffer;
     377        struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->header;
    369378        //return (wagptr->hdr.size);
    370379        return ntohs(wagptr->hdr.size);
     
    372381
    373382static int wag_get_wire_length(const struct libtrace_packet_t *packet) {
    374         struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->buffer;
     383        struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->header;
    375384        //return (wagptr->hdr.size);
    376385        return ntohs(wagptr->hdr.size);
  • lib/libtrace.h

    r3b8338b r14d8a63  
    9595} libtrace_packet_status_t;
    9696
     97typedef enum {PACKET, EXTERNAL } buf_control_t;
    9798/** Structure holding information about a packet */
    9899#define LIBTRACE_PACKET_BUFSIZE 65536
    99100typedef struct libtrace_packet_t {
    100         struct libtrace_t *trace;
    101         //void *buffer;
    102         char buffer[LIBTRACE_PACKET_BUFSIZE];
     101        struct libtrace_t *trace;
     102        void *header;
     103        void *payload;
     104        void *buffer;
    103105        size_t size;
    104106        libtrace_packet_status_t status;
     107        buf_control_t buf_control;
    105108} __attribute__ ((packed)) libtrace_packet_t;
    106109                     
     
    344347void trace_output_destroy(struct libtrace_out_t *trace);
    345348
     349/** Create a new packet object
     350 *
     351 * @return a pointer to an initialised libtrace_packet_t object
     352 */
     353struct libtrace_packet_t *trace_packet_create();
     354
     355/** Destroy a packet object
     356 *
     357 * sideeffect: sets packet to NULL
     358 */
     359void trace_packet_destroy(struct libtrace_packet_t **packet);
     360
     361
    346362/** Read one packet from the trace into buffer
    347363 *
  • lib/trace.c

    rf3ed52a r14d8a63  
    488488}
    489489
     490/** Create a new packet object
     491 *
     492 * @ return a pointer to an initialised libtrace_packet_t structure
     493 */
     494struct libtrace_packet_t *trace_packet_create() {
     495        struct libtrace_packet_t *packet = calloc(1,sizeof(struct libtrace_packet_t));
     496        packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE);
     497        packet->buf_control = PACKET;
     498        return packet;
     499}
     500
     501/** Destroy a packet object
     502 *
     503 * sideeffect: sets packet to NULL
     504 */
     505void trace_packet_destroy(struct libtrace_packet_t **packet) {
     506        if ((*packet)->buf_control) {
     507                free((*packet)->buffer);
     508        }
     509        free((*packet));
     510        packet = NULL;
     511}       
     512
    490513/* Read one packet from the trace into buffer
    491514 *
     
    543566 */
    544567void *trace_get_link(const struct libtrace_packet_t *packet) {
     568        return (void *)packet->payload;
     569/*
    545570        const void *ethptr = 0;
    546571
     
    551576        }
    552577        return (void *)ethptr;
     578*/
    553579}
    554580
Note: See TracChangeset for help on using the changeset viewer.