Changeset 83695bf


Ignore:
Timestamp:
02/10/15 17:54:12 (6 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:
92d5f15
Parents:
ea602cd (diff), 47321fd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'develop'

Files:
3 added
20 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    r60f3c4c ra2ce0a6  
    2222        $(RM) -rf autom4te.cache/
    2323
    24 dist-hook:
    25         if which svnversion > /dev/null; then \
    26                 r=`svnversion -nc . | sed -e 's/^[^:]*://;s/[A-Za-z]//'` ;\
    27                 sed -i "s/SVN_REVISION.*/SVN_REVISION $$r/" $(distdir)/lib/libtrace.h.in; \
    28         fi
    29 
    3024if HAS_DOXYGEN
    3125docs/doxygen/man/man3/*.3: docs
  • lib/Makefile.am

    re5dedd5 r3fc3267  
    2121
    2222if HAVE_LLVM
    23 BPFJITSOURCE=bpf-jit/bpf-jit.cc 
     23BPFJITSOURCE=bpf-jit/bpf-jit.cc
    2424else
    2525BPFJITSOURCE=
     
    5454                protocols_pktmeta.c protocols_l2.c protocols_l3.c \
    5555                protocols_transport.c protocols.h protocols_ospf.c \
     56                protocols_application.c \
    5657                $(DAGSOURCE) format_erf.h \
    5758                $(BPFJITSOURCE) \
  • lib/format_dag25.c

    r51d1f64 rc5ac872  
    104104/* "Global" data that is stored for each DAG output trace */
    105105struct dag_format_data_out_t {
     106        /* String containing the DAG device name */
     107        char *device_name;
    106108        /* The DAG device being used for writing */
    107109        struct dag_dev_t *device;
     
    132134        } duck;
    133135
    134         /* The DAG device that we are reading from */
     136        /* String containing the DAG device name */
     137        char *device_name;
     138        /* The DAG device that we are reading from */
    135139        struct dag_dev_t *device;
    136140        /* The DAG stream that we are reading from */
     
    146150        /* The number of packets that have been dropped */
    147151        uint64_t drops;
     152
     153        uint8_t seeninterface[4];
    148154};
    149155
     
    206212        FORMAT_DATA_OUT->stream_attached = 0;
    207213        FORMAT_DATA_OUT->device = NULL;
     214        FORMAT_DATA_OUT->device_name = NULL;
    208215        FORMAT_DATA_OUT->dagstream = 0;
    209216        FORMAT_DATA_OUT->waiting = 0;
     
    221228        FORMAT_DATA->stream_attached = 0;
    222229        FORMAT_DATA->drops = 0;
     230        FORMAT_DATA->device_name = NULL;
    223231        FORMAT_DATA->device = NULL;
    224232        FORMAT_DATA->dagstream = 0;
     
    226234        FORMAT_DATA->bottom = NULL;
    227235        FORMAT_DATA->top = NULL;
     236        memset(FORMAT_DATA->seeninterface, 0, sizeof(FORMAT_DATA->seeninterface));
    228237}
    229238
     
    275284        dag_close(dev->fd);
    276285        if (dev->dev_name)
    277         free(dev->dev_name);
     286                free(dev->dev_name);
    278287        free(dev);
    279288}
     
    389398/* Creates and initialises a DAG output trace */
    390399static int dag_init_output(libtrace_out_t *libtrace) {
    391         char *dag_dev_name = NULL;
    392400        char *scan = NULL;
    393401        struct dag_dev_t *dag_device = NULL;
     
    412420         * If no stream is specified, we will write using stream 1 */
    413421        if ((scan = strchr(libtrace->uridata,',')) == NULL) {
    414                 dag_dev_name = strdup(libtrace->uridata);
     422                FORMAT_DATA_OUT->device_name = strdup(libtrace->uridata);
    415423        } else {
    416                 dag_dev_name = (char *)strndup(libtrace->uridata,
     424                FORMAT_DATA_OUT->device_name =
     425                                (char *)strndup(libtrace->uridata,
    417426                                (size_t)(scan - libtrace->uridata));
    418427                stream = atoi(++scan);
     
    421430
    422431        /* See if our DAG device is already open */
    423         dag_device = dag_find_open_device(dag_dev_name);
     432        dag_device = dag_find_open_device(FORMAT_DATA_OUT->device_name);
    424433
    425434        if (dag_device == NULL) {
    426435                /* Device not yet opened - open it ourselves */
    427                 dag_device = dag_open_output_device(libtrace, dag_dev_name);
    428         } else {
    429                 /* Otherwise, just use the existing one */
    430                 free(dag_dev_name);
    431                 dag_dev_name = NULL;
     436                dag_device = dag_open_output_device(libtrace,
     437                                FORMAT_DATA_OUT->device_name);
    432438        }
    433439
    434440        /* Make sure we have successfully opened a DAG device */
    435441        if (dag_device == NULL) {
    436                 if (dag_dev_name) {
    437                         free(dag_dev_name);
     442                if (FORMAT_DATA_OUT->device_name) {
     443                        free(FORMAT_DATA_OUT->device_name);
     444                        FORMAT_DATA_OUT->device_name = NULL;
    438445                }
    439446                pthread_mutex_unlock(&open_dag_mutex);
     
    448455/* Creates and initialises a DAG input trace */
    449456static int dag_init_input(libtrace_t *libtrace) {
    450         char *dag_dev_name = NULL;
    451457        char *scan = NULL;
    452458        int stream = 0;
     
    464470         * If no stream is specified, we will read from stream 0 */
    465471        if ((scan = strchr(libtrace->uridata,',')) == NULL) {
    466                 dag_dev_name = strdup(libtrace->uridata);
     472                FORMAT_DATA->device_name = strdup(libtrace->uridata);
    467473        } else {
    468                 dag_dev_name = (char *)strndup(libtrace->uridata,
     474                FORMAT_DATA->device_name = (char *)strndup(libtrace->uridata,
    469475                                (size_t)(scan - libtrace->uridata));
    470476                stream = atoi(++scan);
     
    474480
    475481        /* See if our DAG device is already open */
    476         dag_device = dag_find_open_device(dag_dev_name);
     482        dag_device = dag_find_open_device(FORMAT_DATA->device_name);
    477483
    478484        if (dag_device == NULL) {
    479485                /* Device not yet opened - open it ourselves */
    480                 dag_device = dag_open_device(libtrace, dag_dev_name);
    481         } else {
    482                 /* Otherwise, just use the existing one */
    483                 free(dag_dev_name);
    484                 dag_dev_name = NULL;
     486                dag_device=dag_open_device(libtrace, FORMAT_DATA->device_name);
    485487        }
    486488
    487489        /* Make sure we have successfully opened a DAG device */
    488490        if (dag_device == NULL) {
    489                 if (dag_dev_name)
    490                         free(dag_dev_name);
    491                 dag_dev_name = NULL;
     491                if (FORMAT_DATA->device_name)
     492                        free(FORMAT_DATA->device_name);
     493                FORMAT_DATA->device_name = NULL;
    492494                pthread_mutex_unlock(&open_dag_mutex);
    493495                return -1;
     
    521523                        /* This option is used to specify the frequency of DUCK
    522524                         * updates */
    523                         DUCK.duck_freq = *(int *)data;
     525                        DUCK.duck_freq = *(int *)data;
    524526                        return 0;
    525527                case TRACE_OPTION_SNAPLEN:
     
    557559
    558560        if (dag_attach_stream(FORMAT_DATA_OUT->device->fd,
    559                         FORMAT_DATA_OUT->dagstream, 0, 1048576) < 0) {
     561                        FORMAT_DATA_OUT->dagstream, 0, 4 * 1024 * 1024) < 0) {
    560562                trace_set_err_out(libtrace, errno, "Cannot attach DAG stream");
    561563                return -1;
     
    581583static int dag_start_input(libtrace_t *libtrace) {
    582584        struct timeval zero, nopoll;
    583         uint8_t *top, *bottom;
    584         uint8_t diff = 0;
     585        uint8_t *top, *bottom, *starttop;
    585586        top = bottom = NULL;
    586587
     
    608609                                &nopoll);
    609610
     611        starttop = dag_advance_stream(FORMAT_DATA->device->fd,
     612                                        FORMAT_DATA->dagstream,
     613                                        &bottom);
     614
    610615        /* Should probably flush the memory hole now */
    611         do {
     616        top = starttop;
     617        while (starttop - bottom > 0) {
     618                bottom += (starttop - bottom);
    612619                top = dag_advance_stream(FORMAT_DATA->device->fd,
    613620                                        FORMAT_DATA->dagstream,
    614621                                        &bottom);
    615                 assert(top && bottom);
    616                 diff = top - bottom;
    617                 bottom -= diff;
    618         } while (diff != 0);
    619         FORMAT_DATA->top = NULL;
    620         FORMAT_DATA->bottom = NULL;
     622        }
     623        FORMAT_DATA->top = top;
     624        FORMAT_DATA->bottom = bottom;
    621625        FORMAT_DATA->processed = 0;
    622626        FORMAT_DATA->drops = 0;
     
    676680        if (DUCK.dummy_duck)
    677681                trace_destroy_dead(DUCK.dummy_duck);
     682        if (FORMAT_DATA->device_name)
     683                free(FORMAT_DATA->device_name);
    678684        free(libtrace->format_data);
    679685        pthread_mutex_unlock(&open_dag_mutex);
     
    709715        if (FORMAT_DATA_OUT->device->ref_count == 0)
    710716                dag_close_device(FORMAT_DATA_OUT->device);
     717        if (FORMAT_DATA_OUT->device_name)
     718                free(FORMAT_DATA_OUT->device_name);
    711719        free(libtrace->format_data);
    712720        pthread_mutex_unlock(&open_dag_mutex);
     
    714722}
    715723
     724#ifdef DAGIOC_CARD_DUCK
     725#define LIBTRACE_DUCK_IOCTL DAGIOC_CARD_DUCK
     726#define LIBTRACE_DUCK_VERSION TRACE_RT_DUCK_5_0
     727#else
     728#ifdef DAGIOCDUCK
     729#define LIBTRACE_DUCK_IOCTL DAGIOCDUCK
     730#define LIBTRACE_DUCK_VERSION TRACE_RT_DUCK_2_5
     731#else
     732#warning "DAG appears to be missing DUCK support"
     733#endif
     734#endif
     735
    716736/* Extracts DUCK information from the DAG card and produces a DUCK packet */
    717737static int dag_get_duckinfo(libtrace_t *libtrace,
    718738                                libtrace_packet_t *packet) {
     739
     740        if (DUCK.duck_freq == 0)
     741                return 0;
     742
     743#ifndef LIBTRACE_DUCK_IOCTL
     744        trace_set_err(libtrace, errno,
     745                "Requested DUCK information but unable to determine the correct ioctl for DUCK");
     746        DUCK.duck_freq = 0;
     747        return -1;
     748#endif
     749
     750        if (DUCK.last_pkt - DUCK.last_duck < DUCK.duck_freq)
     751                return 0;
    719752
    720753        /* Allocate memory for the DUCK data */
     
    736769        /* No need to check if we can get DUCK or not - we're modern
    737770         * enough so just grab the DUCK info */
    738         if ((ioctl(FORMAT_DATA->device->fd, DAGIOCDUCK,
     771        if ((ioctl(FORMAT_DATA->device->fd, LIBTRACE_DUCK_IOCTL,
    739772                                        (duckinf_t *)packet->payload) < 0)) {
    740                 trace_set_err(libtrace, errno, "Error using DAGIOCDUCK");
     773                trace_set_err(libtrace, errno, "Error using DUCK ioctl");
     774                DUCK.duck_freq = 0;
    741775                return -1;
    742776        }
    743777
    744         packet->type = TRACE_RT_DUCK_2_5;
    745 
    746         /* Set the packet's tracce to point at a DUCK trace, so that the
     778        packet->type = LIBTRACE_DUCK_VERSION;
     779
     780        /* Set the packet's trace to point at a DUCK trace, so that the
    747781         * DUCK format functions will be called on the packet rather than the
    748782         * DAG ones */
    749783        if (!DUCK.dummy_duck)
    750                 DUCK.dummy_duck = trace_create_dead("rt:localhost:3434");
     784                DUCK.dummy_duck = trace_create_dead("duck:dummy");
    751785        packet->trace = DUCK.dummy_duck;
     786        DUCK.last_duck = DUCK.last_pkt;
    752787        return sizeof(duckinf_t);
    753788}
     
    843878        } else {
    844879                /* Use the ERF loss counter */
    845                 DATA(libtrace)->drops += ntohs(erfptr->lctr);
     880                if (FORMAT_DATA->seeninterface[erfptr->flags.iface] == 0) {
     881                        FORMAT_DATA->seeninterface[erfptr->flags.iface] = 1;
     882                } else {
     883                        FORMAT_DATA->drops += ntohs(erfptr->lctr);
     884                }
    846885        }
    847886
     
    10441083
    10451084        /* Check if we're due for a DUCK report */
    1046         if (DUCK.last_pkt - DUCK.last_duck > DUCK.duck_freq &&
    1047                         DUCK.duck_freq != 0) {
    1048                 size = dag_get_duckinfo(libtrace, packet);
    1049                 DUCK.last_duck = DUCK.last_pkt;
    1050                 if (size != 0) {
    1051                         return size;
    1052                 }
    1053                 /* No DUCK support, so don't waste our time anymore */
    1054                 DUCK.duck_freq = 0;
    1055         }
     1085        size = dag_get_duckinfo(libtrace, packet);
     1086
     1087        if (size != 0)
     1088                return size;
     1089
    10561090
    10571091        /* Don't let anyone try to free our DAG memory hole! */
     
    11111145        int numbytes;
    11121146        uint32_t flags = 0;
    1113         struct timeval minwait;
     1147        struct timeval minwait, tv;
    11141148       
    11151149        minwait.tv_sec = 0;
    11161150        minwait.tv_usec = 10000;
     1151
     1152        /* Check if we're meant to provide a DUCK update */
     1153        numbytes = dag_get_duckinfo(libtrace, packet);
     1154        if (numbytes < 0) {
     1155                event.type = TRACE_EVENT_TERMINATE;
     1156                return event;
     1157        } else if (numbytes > 0) {
     1158                event.type = TRACE_EVENT_PACKET;
     1159                return event;
     1160        }
    11171161       
    11181162        if (dag_set_stream_poll(FORMAT_DATA->device->fd,
     
    11871231                }
    11881232
     1233                /* Update the DUCK timer */
     1234                tv = trace_get_timeval(packet);
     1235                DUCK.last_pkt = tv.tv_sec;
     1236               
    11891237                if (libtrace->snaplen > 0) {
    11901238                        trace_set_capture_length(packet, libtrace->snaplen);
  • lib/format_dpdk.c

    r9f43919 r47321fd  
    8686/* 1.6.0r2 :
    8787 *      rte_eal_pci_set_blacklist() is removed
    88  *      device_list is renamed ot pci_device_list
     88 *      device_list is renamed to pci_device_list
     89 *      In the 1.7.0 release rte_eal_pci_probe is called by rte_eal_init
     90 *      as such we do apply the whitelist before rte_eal_init.
     91 *      This also works correctly with DPDK 1.6.0r2.
    8992 *
    9093 * Replaced by:
     
    329332#else /* DPDK_USE_BLACKLIST */
    330333#include <rte_devargs.h>
    331 static int blacklist_devices(struct dpdk_format_data_t *format_data UNUSED, struct rte_pci_addr *whitelist)
     334static int whitelist_device(struct dpdk_format_data_t *format_data UNUSED, struct rte_pci_addr *whitelist)
    332335{
    333336        char pci_str[20] = {0};
     
    353356 */
    354357static int parse_pciaddr(char * str, struct rte_pci_addr * addr, long * core) {
    355     char * wrkstr;
    356     char * pch;
     358    int matches;
    357359    assert(str);
    358     wrkstr = strdup(str);
    359    
    360     pch = strtok(wrkstr,":");
    361     if (pch == NULL || pch[0] == 0) {
    362         free(wrkstr); return -1;
    363     }
    364     addr->domain = (uint16_t) atoi(pch);
    365 
    366     pch = strtok(NULL,":");
    367     if (pch == NULL || pch[0] == 0) {
    368         free(wrkstr); return -1;
    369     }
    370     addr->bus = (uint8_t) atoi(pch);
    371 
    372     pch = strtok(NULL,".");
    373     if (pch == NULL || pch[0] == 0) {
    374         free(wrkstr); return -1;
    375     }
    376     addr->devid = (uint8_t) atoi(pch);
    377 
    378     pch = strtok(NULL,"-"); /* Might not find the '-' it's optional */
    379     if (pch == NULL || pch[0] == 0) {
    380         free(wrkstr); return -1;
    381     }
    382     addr->function = (uint8_t) atoi(pch);
    383 
    384     pch = strtok(NULL, ""); /* Find end of string */
    385    
    386     if (pch != NULL && pch[0] != 0) {
    387         *core = (long) atoi(pch);
    388     }
    389 
    390     free(wrkstr);
    391     return 0;
     360    matches = sscanf(str, "%4"SCNx16":%2"SCNx8":%2"SCNx8".%2"SCNx8"-%ld",
     361                     &addr->domain, &addr->bus, &addr->devid, &addr->function, core);
     362    if (matches >= 4) {
     363        return 0;
     364    } else {
     365        return -1;
     366    }
    392367}
    393368
     
    398373    struct rte_config * global_config;
    399374    long nb_cpu = sysconf(_SC_NPROCESSORS_ONLN);
    400    
     375
    401376    if (nb_cpu <= 0) {
    402377        perror("sysconf(_SC_NPROCESSORS_ONLN) failed. Falling back to the first core.");
     
    405380    if (nb_cpu > RTE_MAX_LCORE)
    406381        nb_cpu = RTE_MAX_LCORE;
    407    
     382
    408383    global_config = rte_eal_get_configuration();
    409    
     384
    410385    if (global_config != NULL) {
    411386        int i;
    412387        fprintf(stderr, "Intel DPDK setup\n"
    413                "---Version      : %"PRIu32"\n"
    414                "---Magic        : %"PRIu32"\n"
     388               "---Version      : %s\n"
    415389               "---Master LCore : %"PRIu32"\n"
    416390               "---LCore Count  : %"PRIu32"\n",
    417                global_config->version, global_config->magic,
     391               rte_version(),
    418392               global_config->master_lcore, global_config->lcore_count);
    419        
     393
    420394        for (i = 0 ; i < nb_cpu; i++) {
    421             fprintf(stderr, "   ---Core %d : %s\n", i, 
     395            fprintf(stderr, "   ---Core %d : %s\n", i,
    422396                   global_config->lcore_role[i] == ROLE_RTE ? "on" : "off");
    423397        }
    424        
     398
    425399        const char * proc_type;
    426400        switch (global_config->process_type) {
     
    442416        fprintf(stderr, "---Process Type : %s\n", proc_type);
    443417    }
    444    
     418
    445419}
    446420#endif
     
    543517    snprintf(cpu_number, sizeof(cpu_number), "%x", 0x1 << (my_cpu - 1));
    544518
     519#if !DPDK_USE_BLACKLIST
     520    /* Black list all ports besides the one that we want to use */
     521    if ((ret = whitelist_device(format_data, &use_addr)) < 0) {
     522        snprintf(err, errlen, "Intel DPDK - Whitelisting PCI device failed,"
     523                 " are you sure the address is correct?: %s", strerror(-ret));
     524        return -1;
     525    }
     526#endif
    545527
    546528        /* Give the memory map a unique name */
     
    572554#endif
    573555
     556#if DPDK_USE_BLACKLIST
    574557    /* Blacklist all ports besides the one that we want to use */
    575558        if ((ret = blacklist_devices(format_data, &use_addr)) < 0) {
     
    578561                return -1;
    579562        }
     563#endif
    580564
    581565    /* This loads DPDK drivers against all ports that are not blacklisted */
     
    845829                       8, sizeof(struct rte_pktmbuf_pool_private),
    846830                       rte_pktmbuf_pool_init, NULL, rte_pktmbuf_init, NULL,
    847                        0, MEMPOOL_F_SP_PUT | MEMPOOL_F_SC_GET);
     831                       rte_socket_id(), MEMPOOL_F_SP_PUT | MEMPOOL_F_SC_GET);
    848832
    849833        if (format_data->pktmbuf_pool == NULL) {
     
    876860     */
    877861    ret = rte_eth_tx_queue_setup(format_data->port, format_data->queue_id,
    878                         format_data->nb_tx_buf, SOCKET_ID_ANY, &tx_conf);
     862                        format_data->nb_tx_buf, rte_socket_id(), &tx_conf);
    879863    if (ret < 0) {
    880864        snprintf(err, errlen, "Intel DPDK - Cannot configure TX queue on port"
     
    885869    /* Initialise the RX queue with some packets from memory */
    886870    ret = rte_eth_rx_queue_setup(format_data->port, format_data->queue_id,
    887                             format_data->nb_rx_buf, SOCKET_ID_ANY,
     871                            format_data->nb_rx_buf, rte_socket_id(),
    888872                            &rx_conf, format_data->pktmbuf_pool);
    889873    if (ret < 0) {
     
    12941278        /* Poll for a single packet */
    12951279        nb_rx = rte_eth_rx_burst(FORMAT(libtrace)->port,
    1296                             FORMAT(libtrace)->queue_id, pkts_burst, 1);       
     1280                            FORMAT(libtrace)->queue_id, pkts_burst, 1);
    12971281        if (nb_rx > 0) { /* Got a packet - otherwise we keep spining */
    12981282            return dpdk_ready_pkt(libtrace, packet, pkts_burst[0]);
     1283        }
     1284        if (libtrace_halt) {
     1285            return 0;
    12991286        }
    13001287    }
  • lib/format_duck.c

    r9b097ea rc5ac872  
    216216                duck_size = sizeof(duck2_5_t);
    217217                packet->type = TRACE_RT_DUCK_2_5;
     218        } else if (DATA(libtrace)->dag_version == TRACE_RT_DUCK_5_0) {
     219                duck_size = sizeof(duck5_0_t);
     220                packet->type = TRACE_RT_DUCK_5_0;
    218221        } else {
    219222                trace_set_err(libtrace, TRACE_ERR_BAD_PACKET,
     
    252255
    253256        if (packet->type != TRACE_RT_DUCK_2_4
    254                         && packet->type != TRACE_RT_DUCK_2_5) {
     257                        && packet->type != TRACE_RT_DUCK_2_5 &&
     258                        packet->type != TRACE_RT_DUCK_5_0) {
    255259                trace_set_err_out(libtrace, TRACE_ERR_BAD_PACKET,
    256260                                "Only DUCK packets may be written to a DUCK file");
     
    287291                case TRACE_RT_DUCK_2_5:
    288292                        return sizeof(duck2_5_t);
     293                case TRACE_RT_DUCK_5_0:
     294                        return sizeof(duck5_0_t);
    289295                default:
    290296                        trace_set_err(packet->trace,TRACE_ERR_BAD_PACKET,
  • lib/format_erf.c

    rc70f59f rc69aecb  
    480480                                        packet->buffer,
    481481                                        (size_t)dag_record_size)) == -1) {
    482                 trace_set_err(libtrace,errno,"read(%s)",
    483                                 libtrace->uridata);
     482                trace_set_err(libtrace,errno,"reading ERF file");
    484483                return -1;
    485484        }
     
    488487                return 0;
    489488        }
     489
     490        if (numbytes < (int)dag_record_size) {
     491                trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Incomplete ERF header");
     492                return -1;
     493        }
    490494
    491495        rlen = ntohs(((dag_record_t *)packet->buffer)->rlen);
     
    522526                return -1;
    523527        }
     528
     529        if (numbytes < (int)size) {
     530                trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Incomplete ERF record");
     531                return -1;
     532        }
    524533       
    525534        if (erf_prepare_packet(libtrace, packet, packet->buffer,
  • lib/format_linux.c

    r63af502 r1bad1e2  
    10781078        assert((((unsigned long) header) & (pagesize - 1)) == 0);
    10791079
    1080         while (1) {
     1080        /* TP_STATUS_USER means that we can read the frame.
     1081         * When a slot does not have this flag set, the frame is not
     1082         * ready for consumption.
     1083         */
     1084        while (!(header->tp_status & TP_STATUS_USER)) {
    10811085                pollset.fd = FORMAT(libtrace->format_data)->fd;
    10821086                pollset.events = POLLIN;
     
    10891093                        return -1;
    10901094                } else if (ret == 0) {
    1091                         /* Poll timed out - check if we should exit */
    1092                         if (libtrace_halt)
    1093                                 return 0;
    1094                         continue;
    1095                 }
    1096 
    1097                 /* TP_STATUS_USER means that we can use the frame.
    1098                  * When a slot does not have this flag set, the frame is not
    1099                  * ready for consumption.
    1100                  */
    1101                 if (header->tp_status & TP_STATUS_USER)
    1102                         break;
     1095                        /* Poll timed out - check if we should exit */
     1096                        if (libtrace_halt)
     1097                                return 0;
     1098                        continue;
     1099                }
    11031100        }
    11041101
  • lib/format_pcapfile.c

    rc70f59f rc69aecb  
    210210               
    211211                if (err<1) {
    212                         if (err == 0) {
    213                                 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED,
    214                                                 "Reading pcap file header\n");
    215                         }
     212                        trace_set_err(libtrace, TRACE_ERR_INIT_FAILED,
     213                                "Error while reading pcap file header\n");
    216214                        return -1;
    217215                }
    218                
     216       
     217                if (err != (int)sizeof(DATA(libtrace)->header)) {
     218                        trace_set_err(libtrace, TRACE_ERR_INIT_FAILED,
     219                                "Incomplete pcap file header");
     220                        return -1;
     221                }
     222               
    219223                if (!header_is_magic(&(DATA(libtrace)->header))) {
    220224                        trace_set_err(libtrace,TRACE_ERR_INIT_FAILED,
     
    359363                        packet->buffer,
    360364                        sizeof(libtrace_pcapfile_pkt_hdr_t));
    361 
    362365        if (err<0) {
    363366                trace_set_err(libtrace,errno,"reading packet");
     
    368371                return 0;
    369372        }
     373
     374        if (err < (int)sizeof(libtrace_pcapfile_pkt_hdr_t)) {
     375                trace_set_err(libtrace, errno, "Incomplete pcap packet header");
     376                return -1;
     377        }
    370378
    371379        bytes_to_read = swapl(libtrace,((libtrace_pcapfile_pkt_hdr_t*)packet->buffer)->caplen);
     
    391399                        );
    392400
    393        
    394401        if (err<0) {
    395402                trace_set_err(libtrace,errno,"reading packet");
     
    399406                return 0;
    400407        }
     408
     409        if (err < (int)bytes_to_read) {
     410                trace_set_err(libtrace, errno, "Incomplete pcap packet body");
     411                return -1;
     412        }
    401413
    402414        if (pcapfile_prepare_packet(libtrace, packet, packet->buffer,
  • lib/format_rt.c

    rc70f59f rc5ac872  
    430430                case TRACE_RT_DUCK_2_4:
    431431                case TRACE_RT_DUCK_2_5:
     432                case TRACE_RT_DUCK_5_0:
    432433                        if (!RT_INFO->dummy_duck) {
    433434                                RT_INFO->dummy_duck = trace_create_dead("duck:dummy");
  • lib/format_tsh.c

    rc909fad rc69aecb  
    147147                return 0;
    148148        }
     149
     150        if (numbytes < (int)sizeof(tsh_pkt_header_t)) {
     151                trace_set_err(libtrace, errno, "Incomplete TSH header");
     152                return -1;
     153        }
    149154
    150155        buffer2 = (char*)buffer2 + numbytes;
  • lib/libtrace.h.in

    r17f954f rc5ac872  
    109109            ((@LIBTRACE_MAJOR@<<16)|(@LIBTRACE_MID@<<8)|(@LIBTRACE_MINOR@))
    110110
    111 /** Replaced with the current SVN revision number when 'make dist' is invoked
    112  *  to create a distributable tarball */
    113 #define LIBTRACE_SVN_REVISION 0
     111/** This used to be replaced with the current SVN revision number when
     112 * 'make dist' was invoked to create a distributable tarball. We don't use
     113 * SVN anymore and there probably isn't any need to know the exact revision
     114 * number either these days. */
     115#define LIBTRACE_SVN_REVISION LIBTRACE_API_VERSION
    114116
    115117/** DAG driver version installed on the current system */
     
    381383        TRACE_RT_CLIENTDROP     =17,/**< Reliable client was lost */
    382384        TRACE_RT_METADATA       =18,/**< Packet contains server meta-data */
     385        TRACE_RT_DUCK_5_0       =19,/**< Dag 5.0 Duck */
    383386
    384387        /** Not actually used - all DATA types begin from this value */
     
    808811} PACKED libtrace_pppoe_t;
    809812
     813/** Libtrace local definition of GRE (Generalised Routing Protocol) header
     814 * RFC2890
     815 */
     816typedef struct libtrace_gre_t
     817{
     818    uint16_t flags;         /**< Flags and version */
     819    uint16_t ethertype;     /**< Payload ethertype */
     820    uint16_t checksum;      /**< Optional checksum */
     821    uint16_t reserved1;     /**< Optional reserved */
     822    uint16_t key;           /**< Optional key (or Tenant Network ID) */
     823    uint16_t seq;           /**< Optional sequence number */
     824} PACKED libtrace_gre_t;
     825
     826#define LIBTRACE_GRE_FLAG_CHECKSUM 0x8000
     827#define LIBTRACE_GRE_FLAG_KEY      0x2000
     828#define LIBTRACE_GRE_FLAG_SEQ      0x1000
     829#define LIBTRACE_GRE_FLAG_VERMASK  0x0007
     830
     831/** Libtrace local definition of VXLAN Header
     832 * (draft-mahalingam-dutt-dcops-vxlan)
     833 */
     834typedef struct libtrace_vxlan_t
     835{
     836    uint8_t flags;          /**< Flags */
     837    uint8_t reserved1[3];   /**< Reserved */
     838    uint8_t vni[3];         /**< VXLAN Network Identifier (VNI) */
     839    uint8_t reserved2;
     840} PACKED libtrace_vxlan_t;
     841
    810842/** 802.11 header */
    811843typedef struct libtrace_80211_t {
     
    20712103                uint32_t *remaining);
    20722104
     2105/** Gets a pointer to the payload following a GRE header
     2106 * @param         gre       A pointer to the beginning of the GRE header.
     2107 * @param[in,out] remaining Updated with the number of captured bytes remaining.
     2108 *
     2109 * @return A pointer to the GRE payload, or NULL if the GRE header is truncated.
     2110 *
     2111 * When calling this function, remaining must contain the number of captured
     2112 * bytes remaining in the packet starting from the GRE header (including the
     2113 * GRE header itself). remaining will be updated to contain the number of
     2114 * bytes remaining after the GRE header has been skipped.
     2115 *
     2116 * If the GRE header is complete but there are zero bytes of payload after
     2117 * the header, a pointer to where the payload would be is returned and
     2118 * remaining will be set to 0.  If the GRE header is incomplete, NULL will be
     2119 * returned and remaining will be set to 0. Therefore, it is important to check
     2120 * the value of remaining after calling this function.
     2121 */
     2122DLLEXPORT void *trace_get_payload_from_gre(libtrace_gre_t *gre,
     2123                uint32_t *remaining);
     2124
     2125/** Gets a pointer to the payload following a VXLAN header
     2126 * @param         udp       A pointer to the beginning of the UDP header.
     2127 * @param[in,out] remaining Updated with the number of captured bytes remaining.
     2128 *
     2129 * @return A pointer to the beginning of the VXLAN header, or NULL if the UDP
     2130 * header is truncated, or this is not a VXLAN packet.
     2131 *
     2132 */
     2133DLLEXPORT libtrace_vxlan_t *trace_get_vxlan_from_udp(libtrace_udp_t *udp,
     2134                uint32_t *remaining);
     2135
     2136/** Gets a pointer to the payload following a VXLAN header
     2137 * @param         vxlan       A pointer to the beginning of the VXLAN header.
     2138 * @param[in,out] remaining Updated with the number of captured bytes remaining.
     2139 *
     2140 * @return A pointer to the VXLAN payload, or NULL if the VXLAN header is
     2141 * truncated.
     2142 *
     2143 * When calling this function, remaining must contain the number of captured
     2144 * bytes remaining in the packet starting from the VXLAN header (including the
     2145 * VXLAN header itself). remaining will be updated to contain the number of
     2146 * bytes remaining after the VXLAN header has been skipped.
     2147 *
     2148 * If the VXLAN header is complete but there are zero bytes of payload after
     2149 * the header, a pointer to where the payload would be is returned and
     2150 * remaining will be set to 0.  If the VXLAN header is incomplete, NULL will be
     2151 * returned and remaining will be set to 0. Therefore, it is important to check
     2152 * the value of remaining after calling this function.
     2153 */
     2154DLLEXPORT void *trace_get_payload_from_vxlan(libtrace_vxlan_t *vxlan,
     2155                uint32_t *remaining);
     2156
    20732157/** Get a pointer to the TCP header (if present)
    20742158 * @param packet        The packet to get the TCP header from
  • lib/libtrace_int.h

    r10f924c r6fc1ae7  
    746746 * immediately
    747747 */
    748 extern int libtrace_halt;
     748extern volatile int libtrace_halt;
    749749
    750750/** Registers a new capture format module.
  • lib/protocols_transport.c

    re0bea4e5 r3fc3267  
    553553        return csum_ptr;
    554554}
     555
     556DLLEXPORT void *trace_get_payload_from_gre(libtrace_gre_t *gre,
     557        uint32_t *remaining)
     558{
     559    uint32_t size = 4; /* GRE is 4 bytes long by default */
     560    if (remaining && *remaining < size) {
     561        *remaining = 0;
     562        return NULL;
     563    }
     564
     565    if ((ntohs(gre->flags) & LIBTRACE_GRE_FLAG_CHECKSUM) != 0) {
     566        size += 4;  /* An extra 4 bytes. */
     567    }
     568
     569    if ((ntohs(gre->flags) & LIBTRACE_GRE_FLAG_KEY) != 0) {
     570        size += 4;  /* An extra 4 bytes. */
     571    }
     572
     573    if ((ntohs(gre->flags) & LIBTRACE_GRE_FLAG_SEQ) != 0) {
     574        size += 4;  /* An extra 4 bytes. */
     575    }
     576
     577    if (remaining) {
     578        if (*remaining < size) {
     579            *remaining = 0;
     580            return NULL;
     581        }
     582        *remaining -= size;
     583    }
     584    return (char*)gre+size;
     585}
  • lib/rt_protocol.h

    r81c0b9e rc5ac872  
    249249} PACKED duck2_5_t;
    250250
     251typedef struct duck5_0 {
     252        int64_t         Phase_Correction;
     253        uint64_t        Last_Ticks;
     254        uint64_t        Last_TSC;
     255        /* XXX Stat_Start and Stat_End are time_t in dagioctl.h, which means
     256         * they could in theory be 32 or 64 bit depending on the architecture
     257         * when capturing. I'm going to assume 5.0 era DAG captures are taking
     258         * place on a 64 bit arch, rather than have to deal with the varying
     259         * sizes (especially given nobody really uses DUCK these days).
     260         */
     261        uint64_t        Stat_Start, Stat_End;
     262        uint32_t        Crystal_Freq;
     263        uint32_t        Synth_Freq;
     264        uint32_t        Resyncs;
     265        uint32_t        Bad_Pulses;
     266        uint32_t        Worst_Freq_Err, Worst_Phase_Err;
     267        uint32_t        Health_Thresh;
     268        uint32_t        Pulses, Single_Pulses_Missing, Longest_Pulse_Missing;
     269        uint32_t        Health, Sickness;
     270        int32_t         Freq_Err, Phase_Err;
     271        uint32_t        Set_Duck_Field;
     272} PACKED duck5_0_t;
     273
    251274/*
    252275typedef struct rt_duck_2_4 {
  • lib/trace.c

    r7fda5c5 r6fc1ae7  
    105105static struct libtrace_format_t *formats_list = NULL;
    106106
    107 int libtrace_halt = 0;
     107volatile int libtrace_halt = 0;
    108108
    109109/* strncpy is not assured to copy the final \0, so we
  • libwandio/ior-zlib.c

    r60f3c4c r525d09d  
    5656        int outoffset;
    5757        enum err_t err;
     58        size_t sincelastend;
    5859};
    5960
     
    8384        DATA(io)->strm.opaque = NULL;
    8485        DATA(io)->err = ERR_OK;
     86        DATA(io)->sincelastend = 1;
    8587
    8688        inflateInit2(&DATA(io)->strm, 15 | 32);
     
    108110                                sizeof(DATA(io)->inbuff));
    109111                        if (bytes_read == 0) {
    110                                 /* EOF */
     112                                /* If we get EOF immediately after a
     113                                 * Z_STREAM_END, then we assume we've reached
     114                                 * the end of the file. If there was data
     115                                 * between the Z_STREAM_END and the EOF, the
     116                                 * file has more likely been truncated.
     117                                 */
     118                                if (DATA(io)->sincelastend > 0) {
     119                                        fprintf(stderr, "Unexpected EOF while reading compressed file -- file is probably incomplete\n");
     120                                        errno = EIO;
     121                                        DATA(io)->err = ERR_ERROR;
     122                                        return -1;
     123                                }
     124
     125                                /* EOF */
    111126                                if (DATA(io)->strm.avail_out == (uint32_t)len) {
    112                                         DATA(io)->err = ERR_EOF;
     127                                        DATA(io)->err = ERR_EOF;
    113128                                        return 0;
    114129                                }
     
    128143                        DATA(io)->strm.next_in = DATA(io)->inbuff;
    129144                        DATA(io)->strm.avail_in = bytes_read;
     145                        DATA(io)->sincelastend += bytes_read;
    130146                }
    131147                /* Decompress some data into the output buffer */
     
    144160                                inflateInit2(&DATA(io)->strm, 15 | 32);
    145161                                DATA(io)->err = ERR_OK;
     162                                DATA(io)->sincelastend = 0;
    146163                                break;
    147164                        default:
  • test/Makefile

    r262a093 r3fc3267  
    99CFLAGS += $(INCLUDE)
    1010libdir = $(PREFIX)/lib/.libs:$(PREFIX)/libpacketdump/.libs
    11 LDLIBS = -L$(PREFIX)/lib/.libs -L$(PREFIX)/libpacketdump/.libs -ltrace -lpacketdump 
     11LDLIBS = -L$(PREFIX)/lib/.libs -L$(PREFIX)/libpacketdump/.libs -ltrace -lpacketdump
    1212
    1313BINS = test-pcap-bpf test-event test-time test-dir test-wireless test-errors \
    14         test-plen test-autodetect test-ports test-fragment test-live test-live-snaplen
     14        test-plen test-autodetect test-ports test-fragment test-live \
     15        test-live-snaplen test-vxlan
    1516
    1617.PHONY: all clean distclean install depend test
  • test/do-tests.sh

    r95b6218 r3fc3267  
    230230do_test ./test-autodetect traces/5_packets.erf.xz
    231231
     232echo " * VXLan decode"
     233do_test ./test-vxlan
     234
    232235echo
    233236echo "Tests passed: $OK"
  • tools/tracestats/tracestats.c

    rc0ccccd r3c54095  
    157157
    158158        if (trace_is_err(trace))
    159                 trace_perror(trace,"%s",uri);
     159                trace_perror(trace,"Processing trace");
    160160
    161161        trace_destroy(trace);
  • tools/tracestats/tracesummary

    r3bfeb7d r065cab9  
    1818                --filter 'port domain' \
    1919                --filter 'icmp[icmptype]=icmp-echoreply' \
    20                 $@
     20                "$@"
Note: See TracChangeset for help on using the changeset viewer.