Changeset ea602cd


Ignore:
Timestamp:
09/09/14 11:09:48 (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:
6d082e6, 83695bf, 9e429e8
Parents:
faf16af (diff), 092a09c (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:
5 added
18 edited
1 moved

Legend:

Unmodified
Added
Removed
  • INSTALL

    r17094b2 r0ae5feb  
    1313Installing libtrace:
    1414
     15./bootstrap.sh (only if you've cloned the source from GitHub)
    1516./configure
    1617make
     
    3637
    3738A. You need to install the development version of the pcap library.
    38 For example, Ubuntu/Debian users will need to install the libpcap0.8-dev package
    39 in addition to the libpcap0.8 package.
     39For example, Ubuntu/Debian users will need to install the libpcap0.8-dev
     40package in addition to the libpcap0.8 package.
     41
    4042
    4143----------------------------------
  • README

    r9ad7a35 ra7c8f4a  
    1 libtrace 3.0.20
     1libtrace 3.0.21
    22
    33---------------------------------------------------------------------------
     
    99---------------------------------------------------------------------------
    1010
     11See INSTALL for instructions on how to install libtrace.
    1112
    1213This directory contains source code for libtrace, a userspace library for
     
    2021Further information about libtrace see
    2122http://research.wand.net.nz/software/libtrace.php
    22 Bugs should be reported in trac at http://www.wand.net.nz/trac/libtrace
     23
     24Bugs should be reported by either emailing contact@wand.net.nz or filing
     25an issue at https://github.com/wanduow/libtrace
    2326
    2427It is licensed under the GNU General Public License (GPL) version 2. Please
     
    2629
    2730A detailed ChangeLog can be found on the libtrace wiki:
    28 https://secure.wand.net.nz/trac/libtrace/wiki/ChangeLog
     31https://github.com/wanduow/libtrace/wiki/ChangeLog
    2932
    3033Documentation, usage instructions and a detailed tutorial can also found
  • configure.in

    r457bf45 r092a09c  
    44# and in the README
    55
    6 AC_INIT([libtrace],[3.0.20],[contact@wand.net.nz],[libtrace])
     6AC_INIT([libtrace],[3.0.21],[contact@wand.net.nz],[libtrace])
    77
    88LIBTRACE_MAJOR=3
    99LIBTRACE_MID=0
    10 LIBTRACE_MINOR=20
     10LIBTRACE_MINOR=21
    1111
    1212# OpenSolaris hides libraries like libncurses in /usr/gnu/lib, which is not
     
    4141        examples/stats/Makefile examples/tutorial/Makefile
    4242        docs/libtrace.doxygen
    43         lib/libtrace.h libwandio/Makefile
     43        lib/libtrace.h libwandio/Makefile libwandio/tools/wandiocat/Makefile
    4444        ])
    4545
     
    386386        AC_SUBST([RTE_SDK])
    387387        # Force dpdk library to be statically linked to allow compiler optimisations
    388         LIBTRACE_LIBS="$LIBTRACE_LIBS -l:libintel_dpdk.a"
     388        LIBTRACE_LIBS="$LIBTRACE_LIBS -Wl,--whole-archive -Wl,-l:libintel_dpdk.a -Wl,--no-whole-archive -Wl,-lm"
    389389                AC_DEFINE(HAVE_DPDK,1,[conditional for building with DPDK live capture support])
    390390                libtrace_dpdk=true
  • lib/Makefile.am

    rbd119b3 re5dedd5  
    1818DAGSOURCE=
    1919endif
    20 EXTRA_DIST=format_dag24.c format_dag25.c
     20EXTRA_DIST=format_dag24.c format_dag25.c dpdk_libtrace.mk
    2121
    2222if HAVE_LLVM
     
    3333export RTE_SDK=@RTE_SDK@
    3434export RTE_TARGET=@RTE_TARGET@
     35export SAVED_CFLAGS:=$(CFLAGS)
     36export SAVED_CXXFLAGS:=$(CXXFLAGS)
    3537include $(RTE_SDK)/mk/rte.vars.mk
    3638# We need to add -Wl before the linker otherwise this breaks our build
     
    3840export DPDK_LIBTRACE_MK=dpdk_libtrace.mk
    3941include $(DPDK_LIBTRACE_MK)
     42export CFLAGS += $(SAVED_CFLAGS)
     43export CXXFLAGS += $(SAVED_CXXFLAGS)
    4044endif
    4145
  • lib/format_bpf.c

    r19b44c8 r08f5060  
    422422        packet->payload=(char *)buffer + BPFHDR(packet)->bh_hdrlen;
    423423
    424         /*
    425         if (libtrace->format_data == NULL) {
    426                 if (bpf_init_input(libtrace))
    427                         return -1;
    428         }
    429         */
    430 
    431424        return 0;
    432425}
     
    439432{
    440433        uint32_t flags = 0;
     434        fd_set readfds;
     435        struct timeval tout;
     436        int ret;
    441437
    442438        packet->type = bpf_linktype_to_rt(FORMATIN(libtrace)->linktype);
     439
     440        while (FORMATIN(libtrace)->remaining <= 0) {
     441                tout.tv_sec = 0;
     442                tout.tv_usec = 500000;
     443                FD_ZERO(&readfds);
     444                FD_SET(FORMATIN(libtrace)->fd, &readfds);
     445
     446                ret = select(FORMATIN(libtrace)->fd + 1, &readfds, NULL,
     447                                NULL, &tout);
     448                if (ret < 0 && errno != EINTR) {
     449                        trace_set_err(libtrace, errno, "select");
     450                        return -1;
     451                } else if (ret < 0) {
     452                        continue;
     453                }
     454
     455                if (FD_ISSET(FORMATIN(libtrace)->fd, &readfds)) {
     456                        /* Packets are available, read into buffer */
     457                        ret=read(FORMATIN(libtrace)->fd,
     458                                FORMATIN(libtrace)->buffer,
     459                                FORMATIN(libtrace)->buffersize);
     460
     461                        if (ret == -1) {
     462                                trace_set_err(libtrace,errno,"Failed to read");
     463                                return -1;
     464                        }
     465
     466                        if (ret == 0) {
     467                                /* EOF */
     468                                return 0;
     469                        }
     470
     471                        FORMATIN(libtrace)->remaining=ret;
     472                        FORMATIN(libtrace)->bufptr=
     473                                        FORMATIN(libtrace)->buffer;
     474                        break;
     475                }
     476
     477                /* Timed out -- check if we should halt */
     478                if (libtrace_halt)
     479                        return 0;
     480        }
    443481       
    444         /* Read from the BPF interface into our capture buffer */
    445         if (FORMATIN(libtrace)->remaining<=0) {
    446                 int ret;
    447 
    448                 ret=read(FORMATIN(libtrace)->fd,
    449                         FORMATIN(libtrace)->buffer,
    450                         FORMATIN(libtrace)->buffersize);
    451 
    452                 if (ret == -1) {
    453                         trace_set_err(libtrace,errno,"Failed to read");
    454                         return -1;
    455                 }
    456 
    457                 if (ret == 0) {
    458                         /* EOF */
    459                         return 0;
    460                 }
    461 
    462                 FORMATIN(libtrace)->remaining=ret;
    463                 FORMATIN(libtrace)->bufptr=
    464                                 FORMATIN(libtrace)->buffer;
    465         }
    466 
    467482        /* We do NOT want anything trying to free the memory the packet is
    468483         * stored in */
  • lib/format_dag24.c

    rc909fad rc70f59f  
    473473                        } else {
    474474                                /* Do not sleep - try to read another packet */
     475                                trace->filtered_packets ++;
    475476                                continue;
    476477                        }
     
    483484                        trace_set_capture_length(packet, trace->snaplen);
    484485                }
    485 
     486                trace->accepted_packets ++;
    486487                return event;
    487488        } while (1);
  • lib/format_dag25.c

    rc909fad r51d1f64  
    586586
    587587        zero.tv_sec = 0;
    588         zero.tv_usec = 0;
     588        zero.tv_usec = 10000;
    589589        nopoll = zero;
    590590
     
    992992                /* Flags. Can't do this */
    993993                memset(&erfhdr.flags,1,sizeof(erfhdr.flags));
    994                 if (trace_get_direction(packet)!=~0U)
     994                if (trace_get_direction(packet)!=(int)~0U)
    995995                        erfhdr.flags.iface = trace_get_direction(packet);
    996996
     
    10351035        int numbytes = 0;
    10361036        uint32_t flags = 0;
     1037        struct timeval maxwait;
     1038        struct timeval pollwait;
     1039
     1040        pollwait.tv_sec = 0;
     1041        pollwait.tv_usec = 10000;
     1042        maxwait.tv_sec = 0;
     1043        maxwait.tv_usec = 250000;
    10371044
    10381045        /* Check if we're due for a DUCK report */
     
    10571064                packet->buffer = 0;
    10581065        }
     1066       
     1067        if (dag_set_stream_poll(FORMAT_DATA->device->fd,
     1068                        FORMAT_DATA->dagstream, sizeof(dag_record_t), &maxwait,
     1069                        &pollwait) == -1)
     1070        {
     1071                trace_set_err(libtrace, errno, "dag_set_stream_poll");
     1072                return -1;
     1073        }
     1074
    10591075
    10601076        /* Grab a full ERF record */
     
    10631079                if (numbytes < 0)
    10641080                        return numbytes;
    1065                 if (numbytes < dag_record_size)
     1081                if (numbytes < dag_record_size) {
     1082                        if (libtrace_halt)
     1083                                return 0;
    10661084                        /* Block until we see a packet */
    10671085                        continue;
     1086                }
    10681087                erfptr = dag_get_record(libtrace);
    10691088        } while (erfptr == NULL);
     
    10861105 * return a SLEEP event (as we cannot select on the DAG file descriptor).
    10871106 */
    1088 static libtrace_eventobj_t trace_event_dag(libtrace_t *trace,
     1107static libtrace_eventobj_t trace_event_dag(libtrace_t *libtrace,
    10891108                                        libtrace_packet_t *packet) {
    10901109        libtrace_eventobj_t event = {0,0,0.0,0};
     
    10921111        int numbytes;
    10931112        uint32_t flags = 0;
     1113        struct timeval minwait;
     1114       
     1115        minwait.tv_sec = 0;
     1116        minwait.tv_usec = 10000;
     1117       
     1118        if (dag_set_stream_poll(FORMAT_DATA->device->fd,
     1119                        FORMAT_DATA->dagstream, 0, &minwait,
     1120                        &minwait) == -1)
     1121        {
     1122                trace_set_err(libtrace, errno, "dag_set_stream_poll");
     1123                event.type = TRACE_EVENT_TERMINATE;
     1124                return event;
     1125        }
    10941126
    10951127        do {
     
    10991131                /* Need to call dag_available so that the top pointer will get
    11001132                 * updated, otherwise we'll never see any data! */
    1101                 numbytes = dag_available(trace);
     1133                numbytes = dag_available(libtrace);
    11021134
    11031135                /* May as well not bother calling dag_get_record if
    11041136                 * dag_available suggests that there's no data */
    11051137                if (numbytes != 0)
    1106                         erfptr = dag_get_record(trace);
     1138                        erfptr = dag_get_record(libtrace);
    11071139                if (erfptr == NULL) {
    11081140                        /* No packet available - sleep for a very short time */
    1109                         event.type = TRACE_EVENT_SLEEP;
    1110                         event.seconds = 0.0001;
     1141                        if (libtrace_halt) {
     1142                                event.type = TRACE_EVENT_TERMINATE;
     1143                        } else {                       
     1144                                event.type = TRACE_EVENT_SLEEP;
     1145                                event.seconds = 0.0001;
     1146                        }
    11111147                        break;
    11121148                }
    1113                 if (dag_prepare_packet(trace, packet, erfptr,
     1149                if (dag_prepare_packet(libtrace, packet, erfptr,
    11141150                                        TRACE_RT_DATA_ERF, flags)) {
    11151151                        event.type = TRACE_EVENT_TERMINATE;
     
    11251161                 * trace_event() so we have to do it ourselves */
    11261162
    1127                 if (trace->filter) {
    1128                         if (trace_apply_filter(trace->filter, packet)) {
    1129                                 event.type = TRACE_EVENT_PACKET;
    1130                         } else {
     1163                if (libtrace->filter) {
     1164                        int filtret = trace_apply_filter(libtrace->filter,
     1165                                        packet);
     1166                        if (filtret == -1) {
     1167                                trace_set_err(libtrace, TRACE_ERR_BAD_FILTER,
     1168                                                "Bad BPF Filter");
     1169                                event.type = TRACE_EVENT_TERMINATE;
     1170                                break;
     1171                        }
     1172
     1173                        if (filtret == 0) {
    11311174                                /* This packet isn't useful so we want to
    11321175                                 * immediately see if there is another suitable
     
    11341177                                 * a sleep event in this case, like we used to
    11351178                                 * do! */
     1179                                libtrace->filtered_packets ++;
    11361180                                trace_clear_cache(packet);
    11371181                                continue;
    11381182                        }
     1183                               
     1184                        event.type = TRACE_EVENT_PACKET;
    11391185                } else {
    11401186                        event.type = TRACE_EVENT_PACKET;
    11411187                }
    11421188
    1143                 if (trace->snaplen > 0) {
    1144                         trace_set_capture_length(packet, trace->snaplen);
     1189                if (libtrace->snaplen > 0) {
     1190                        trace_set_capture_length(packet, libtrace->snaplen);
    11451191                }
     1192                libtrace->accepted_packets ++;
    11461193                break;
    11471194        } while (1);
  • lib/format_dpdk.c

    r2138553 r9f43919  
    5757#include <unistd.h>
    5858#include <endian.h>
     59#include <string.h>
     60
     61/* We can deal with any minor differences by checking the RTE VERSION
     62 * Typically DPDK backports some fixes (typically for building against
     63 * newer kernels) to the older version of DPDK.
     64 *
     65 * These get released with the rX suffix. The following macros where added
     66 * in these new releases.
     67 *
     68 * Below this is a log of version that required changes to the libtrace
     69 * code (that we still attempt to support).
     70 *
     71 * Currently 1.5 to 1.7 is supported.
     72 */
    5973#include <rte_eal.h>
     74#include <rte_version.h>
     75#ifndef RTE_VERSION_NUM
     76#       define RTE_VERSION_NUM(a,b,c,d) ((a) << 24 | (b) << 16 | (c) << 8 | (d))
     77#endif
     78#ifndef RTE_VER_PATCH_RELEASE
     79#       define RTE_VER_PATCH_RELEASE 0
     80#endif
     81#ifndef RTE_VERSION
     82#       define RTE_VERSION RTE_VERSION_NUM(RTE_VER_MAJOR,RTE_VER_MINOR, \
     83        RTE_VER_PATCH_LEVEL, RTE_VER_PATCH_RELEASE)
     84#endif
     85
     86/* 1.6.0r2 :
     87 *      rte_eal_pci_set_blacklist() is removed
     88 *      device_list is renamed ot pci_device_list
     89 *
     90 * Replaced by:
     91 *      rte_devargs (we can simply whitelist)
     92 */
     93#if RTE_VERSION <= RTE_VERSION_NUM(1, 6, 0, 1)
     94#       define DPDK_USE_BLACKLIST 1
     95#else
     96#       define DPDK_USE_BLACKLIST 0
     97#endif
     98
     99/*
     100 * 1.7.0 :
     101 *      rte_pmd_init_all is removed
     102 *
     103 * Replaced by:
     104 *      Nothing, no longer needed
     105 */
     106#if RTE_VERSION < RTE_VERSION_NUM(1, 7, 0, 0)
     107#       define DPDK_USE_PMD_INIT 1
     108#else
     109#       define DPDK_USE_PMD_INIT 0
     110#endif
     111
    60112#include <rte_per_lcore.h>
    61113#include <rte_debug.h>
     
    191243    int nb_tx_buf; /* The number of packet buffers in the tx ring */
    192244    struct rte_mempool * pktmbuf_pool; /* Our packet memory pool */
     245#if DPDK_USE_BLACKLIST
    193246    struct rte_pci_addr blacklist[BLACK_LIST_SIZE]; /* Holds our device blacklist */
     247        unsigned int nb_blacklist; /* Number of blacklist items in are valid */
     248#endif
    194249    char mempool_name[MEMPOOL_NAME_LEN]; /* The name of the mempool that we are using */
    195     unsigned int nb_blacklist; /* Number of blacklist items in are valid */
    196250#if HAS_HW_TIMESTAMPS_82580
    197251    /* Timestamping only relevent to RX */
     
    243297 * So blacklist all devices except the one that we wish to use so that
    244298 * the others can still be used as standard ethernet ports.
    245  */
    246 static void blacklist_devices(struct dpdk_format_data_t *format_data, struct rte_pci_addr *whitelist)
     299 *
     300 * @return 0 if successful, otherwise -1 on error.
     301 */
     302#if DPDK_USE_BLACKLIST
     303static int blacklist_devices(struct dpdk_format_data_t *format_data, struct rte_pci_addr *whitelist)
    247304{
    248305        struct rte_pci_device *dev = NULL;
     
    268325
    269326        rte_eal_pci_set_blacklist(format_data->blacklist, format_data->nb_blacklist);
    270 }
     327        return 0;
     328}
     329#else /* DPDK_USE_BLACKLIST */
     330#include <rte_devargs.h>
     331static int blacklist_devices(struct dpdk_format_data_t *format_data UNUSED, struct rte_pci_addr *whitelist)
     332{
     333        char pci_str[20] = {0};
     334        snprintf(pci_str, sizeof(pci_str), PCI_PRI_FMT,
     335                 whitelist->domain,
     336                 whitelist->bus,
     337                 whitelist->devid,
     338                 whitelist->function);
     339        if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, pci_str) < 0) {
     340                return -1;
     341        }
     342        return 0;
     343}
     344#endif
    271345
    272346/**
     
    336410    if (global_config != NULL) {
    337411        int i;
    338         printf("Intel DPDK setup\n"
     412        fprintf(stderr, "Intel DPDK setup\n"
    339413               "---Version      : %"PRIu32"\n"
    340414               "---Magic        : %"PRIu32"\n"
     
    345419       
    346420        for (i = 0 ; i < nb_cpu; i++) {
    347             printf("   ---Core %d : %s\n", i,
     421            fprintf(stderr, "   ---Core %d : %s\n", i,
    348422                   global_config->lcore_role[i] == ROLE_RTE ? "on" : "off");
    349423        }
     
    366440                proc_type = "something worse than invalid!!";
    367441        }
    368         printf("---Process Type : %s\n", proc_type);
    369     }
    370    
    371 }
    372 #endif
    373 
    374 static inline int dpdk_init_enviroment(char * uridata, struct dpdk_format_data_t * format_data,
     442        fprintf(stderr, "---Process Type : %s\n", proc_type);
     443    }
     444   
     445}
     446#endif
     447
     448/**
     449 * XXX This is very bad XXX
     450 * But we have to do something to allow getopts nesting
     451 * Luckly normally the format is last so it doesn't matter
     452 * DPDK only supports modern systems so hopefully this
     453 * will continue to work
     454 */
     455struct saved_getopts {
     456        char *optarg;
     457        int optind;
     458        int opterr;
     459        int optopt;
     460};
     461
     462static void save_getopts(struct saved_getopts *opts) {
     463        opts->optarg = optarg;
     464        opts->optind = optind;
     465        opts->opterr = opterr;
     466        opts->optopt = optopt;
     467}
     468
     469static void restore_getopts(struct saved_getopts *opts) {
     470        optarg = opts->optarg;
     471        optind = opts->optind;
     472        opterr = opts->opterr;
     473        optopt = opts->optopt;
     474}
     475
     476static inline int dpdk_init_environment(char * uridata, struct dpdk_format_data_t * format_data,
    375477                                        char * err, int errlen) {
    376478    int ret; /* Returned error codes */
    377     struct rte_pci_addr use_addr; /* The only address that we don't blacklist */   
     479    struct rte_pci_addr use_addr; /* The only address that we don't blacklist */
    378480    char cpu_number[10] = {0}; /* The CPU mask we want to bind to */
     481    char mem_map[20] = {0}; /* The memory name */
    379482    long nb_cpu; /* The number of CPUs in the system */
    380483    long my_cpu; /* The CPU number we want to bind to */
     484        struct saved_getopts save_opts;
    381485   
    382486#if DEBUG
     
    385489    rte_set_log_level(RTE_LOG_WARNING);
    386490#endif
    387     /* Using proc-type auto allows this to be either primary or secondary
    388      * Secondary allows two intances of libtrace to be used on different
    389      * ports. However current version of DPDK doesn't support this on the
    390      * same card (My understanding is this should work with two seperate
    391      * cards).
     491    /*
     492     * Using unique file prefixes mean separate memory is used, unlinking
     493     * the two processes. However be careful we still cannot access a
     494     * port that already in use.
    392495     */
    393     char* argv[] = {"libtrace", "-c", NULL, "-n", "1", "--proc-type", "auto", NULL};
     496    char* argv[] = {"libtrace", "-c", cpu_number, "-n", "1", "--proc-type", "auto",
     497                "--file-prefix", mem_map, "-m", "256", NULL};
    394498    int argc = sizeof(argv) / sizeof(argv[0]) - 1;
    395    
    396     /* This initilises the Enviroment Abstraction Layer (EAL)
     499
     500    /* This initialises the Environment Abstraction Layer (EAL)
    397501     * If we had slave workers these are put into WAITING state
    398502     *
    399503     * Basically binds this thread to a fixed core, which we choose as
    400504     * the last core on the machine (assuming fewer interrupts mapped here).
    401      * "-c" controls the cpu mask 0x1=1st core 0x2=2nd 0x4=3rd and so om
     505     * "-c" controls the cpu mask 0x1=1st core 0x2=2nd 0x4=3rd and so on
    402506     * "-n" the number of memory channels into the CPU (hardware specific)
    403507     *      - Most likely to be half the number of ram slots in your machine.
     
    438542    /* Make our mask */
    439543    snprintf(cpu_number, sizeof(cpu_number), "%x", 0x1 << (my_cpu - 1));
    440     argv[2] = cpu_number;
    441 
     544
     545
     546        /* Give the memory map a unique name */
     547        snprintf(mem_map, sizeof(mem_map), "libtrace-%d", (int) getpid());
    442548    /* rte_eal_init it makes a call to getopt so we need to reset the
    443549     * global optind variable of getopt otherwise this fails */
     550        save_getopts(&save_opts);
    444551    optind = 1;
    445552    if ((ret = rte_eal_init(argc, argv)) < 0) {
     
    448555        return -1;
    449556    }
     557        restore_getopts(&save_opts);
     558
    450559#if DEBUG
    451560    dump_configuration();
    452561#endif
     562
     563#if DPDK_USE_PMD_INIT
    453564    /* This registers all available NICs with Intel DPDK
    454565     * These are not loaded until rte_eal_pci_probe() is called.
     
    459570        return -1;
    460571    }
    461 
    462     /* Black list all ports besides the one that we want to use */
    463     blacklist_devices(format_data, &use_addr);
     572#endif
     573
     574    /* Blacklist all ports besides the one that we want to use */
     575        if ((ret = blacklist_devices(format_data, &use_addr)) < 0) {
     576                snprintf(err, errlen, "Intel DPDK - Whitelisting PCI device failed,"
     577                         " are you sure the address is correct?: %s", strerror(-ret));
     578                return -1;
     579        }
    464580
    465581    /* This loads DPDK drivers against all ports that are not blacklisted */
     
    496612    FORMAT(libtrace)->promisc = -1;
    497613    FORMAT(libtrace)->pktmbuf_pool = NULL;
     614#if DPDK_USE_BLACKLIST
    498615    FORMAT(libtrace)->nb_blacklist = 0;
     616#endif
    499617    FORMAT(libtrace)->paused = DPDK_NEVER_STARTED;
    500618    FORMAT(libtrace)->mempool_name[0] = 0;
     
    505623#endif
    506624
    507     if (dpdk_init_enviroment(libtrace->uridata, FORMAT(libtrace), err, sizeof(err)) != 0) {
     625    if (dpdk_init_environment(libtrace->uridata, FORMAT(libtrace), err, sizeof(err)) != 0) {
    508626        trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "%s", err);
    509627        free(libtrace->format_data);
     
    529647    FORMAT(libtrace)->promisc = -1;
    530648    FORMAT(libtrace)->pktmbuf_pool = NULL;
     649#if DPDK_USE_BLACKLIST
    531650    FORMAT(libtrace)->nb_blacklist = 0;
     651#endif
    532652    FORMAT(libtrace)->paused = DPDK_NEVER_STARTED;
    533653    FORMAT(libtrace)->mempool_name[0] = 0;
     
    538658#endif
    539659
    540     if (dpdk_init_enviroment(libtrace->uridata, FORMAT(libtrace), err, sizeof(err)) != 0) {
     660    if (dpdk_init_environment(libtrace->uridata, FORMAT(libtrace), err, sizeof(err)) != 0) {
    541661        trace_set_err_out(libtrace, TRACE_ERR_INIT_FAILED, "%s", err);
    542662        free(libtrace->format_data);
     
    634754static const struct rte_eth_txconf tx_conf = {
    635755        .tx_thresh = {
    636                 .pthresh = 36,/* TX_PTHRESH prefetch */
    637                 .hthresh = 0,/* TX_HTHRESH host */
    638                 .wthresh = 4,/* TX_WTHRESH writeback */
     756        /**
     757         * TX_PTHRESH prefetch
     758         * Set on the NIC, if the number of unprocessed descriptors to queued on
     759         * the card fall below this try grab at least hthresh more unprocessed
     760         * descriptors.
     761         */
     762                .pthresh = 36,
     763
     764        /* TX_HTHRESH host
     765         * Set on the NIC, the batch size to prefetch unprocessed tx descriptors.
     766         */
     767                .hthresh = 0,
     768       
     769        /* TX_WTHRESH writeback
     770         * Set on the NIC, the number of sent descriptors before writing back
     771         * status to confirm the transmission. This is done more efficiently as
     772         * a bulk DMA-transfer rather than writing one at a time.
     773         * Similar to tx_free_thresh however this is applied to the NIC, where
     774         * as tx_free_thresh is when DPDK will check these. This is extended
     775         * upon by tx_rs_thresh (10Gbit cards) which doesn't write all
     776         * descriptors rather only every n'th item, reducing DMA memory bandwidth.
     777         */
     778                .wthresh = 4,
    639779        },
    640         .tx_free_thresh = 0, /* Use PMD default values */
    641         .tx_rs_thresh = 0, /* Use PMD default values */
     780
     781    /* Used internally by DPDK rather than passed to the NIC. The number of
     782     * packet descriptors to send before checking for any responses written
     783     * back (to confirm the transmission). Default = 32 if set to 0)
     784     */
     785        .tx_free_thresh = 0,
     786
     787    /* This is the Report Status threshold, used by 10Gbit cards,
     788     * This signals the card to only write back status (such as
     789     * transmission successful) after this minimum number of transmit
     790     * descriptors are seen. The default is 32 (if set to 0) however if set
     791     * to greater than 1 TX wthresh must be set to zero, because this is kindof
     792     * a replacement. See the dpdk programmers guide for more restrictions.
     793     */
     794        .tx_rs_thresh = 1,
    642795};
    643796
     
    653806
    654807    /* First time started we need to alloc our memory, doing this here
    655      * rather than in enviroment setup because we don't have snaplen then */
     808     * rather than in environment setup because we don't have snaplen then */
    656809    if (format_data->paused == DPDK_NEVER_STARTED) {
    657810        if (format_data->snaplen == 0) {
     
    683836         */
    684837#if DEBUG
    685     printf("Creating mempool named %s\n", format_data->mempool_name);
     838    fprintf(stderr, "Creating mempool named %s\n", format_data->mempool_name);
    686839#endif
    687840        format_data->pktmbuf_pool =
     
    719872        return -1;
    720873    }
    721     /* Initilise the TX queue a minimum value if using this port for
     874    /* Initialise the TX queue a minimum value if using this port for
    722875     * receiving. Otherwise a larger size if writing packets.
    723876     */
     
    730883        return -1;
    731884    }
    732     /* Initilise the RX queue with some packets from memory */
     885    /* Initialise the RX queue with some packets from memory */
    733886    ret = rte_eth_rx_queue_setup(format_data->port, format_data->queue_id,
    734887                            format_data->nb_rx_buf, SOCKET_ID_ANY,
     
    761914    rte_eth_link_get(format_data->port, &link_info);
    762915#if DEBUG
    763     printf("Link status is %d %d %d\n", (int) link_info.link_status,
     916    fprintf(stderr, "Link status is %d %d %d\n", (int) link_info.link_status,
    764917            (int) link_info.link_duplex, (int) link_info.link_speed);
    765918#endif
    766919
    767     /* We have now successfully started/unpased */
     920    /* We have now successfully started/unpaused */
    768921    format_data->paused = DPDK_RUNNING;
    769922   
     
    802955    if (FORMAT(libtrace)->paused == DPDK_RUNNING) {
    803956#if DEBUG     
    804         printf("Pausing port\n");
     957        fprintf(stderr, "Pausing port\n");
    805958#endif
    806959        rte_eth_dev_stop(FORMAT(libtrace)->port);
     
    12721425                if (!trace_apply_filter(trace->filter, packet)) {
    12731426                    /* Failed the filter so we loop for another packet */
     1427                    trace->filtered_packets ++;
    12741428                    continue;
    12751429                }
    12761430            }
     1431            trace->accepted_packets ++;
    12771432        } else {
    12781433            /* We only want to sleep for a very short time - we are non-blocking */
  • lib/format_erf.c

    rf7bcbfb rc70f59f  
    746746         * we just need to read and return the next packet in the trace */
    747747        if (IN_OPTIONS.real_time) {
    748                 event.size = erf_read_packet(libtrace, packet);
     748                event.size = trace_read_packet(libtrace, packet);
    749749                if (event.size < 1)
    750750                        event.type = TRACE_EVENT_TERMINATE;
  • lib/format_helper.c

    r74ecbc7 r4649fea  
    9898         * solution. */
    9999
    100         do {
     100        do {
    101101                tv.tv_sec = 0;
    102102                tv.tv_usec = 0;
     
    111111
    112112        if (FD_ISSET(event.fd, &rfds_param)) {
    113                 event.size = trace_read_packet(trace,packet);
    114                
     113                event.size = trace_read_packet(trace,packet);
    115114                if (event.size < 1) {
    116115                        /* Covers error and EOF events - terminate rather
  • lib/format_linux.c

    rd1af45d r63af502  
    501501         */
    502502        if (filter != NULL) {
    503                 assert(filter->flag == 1);
    504                 if (setsockopt(FORMAT(libtrace->format_data)->fd,
     503                /* Check if the filter was successfully compiled. If not,
     504                 * it is probably a bad filter and we should return an error
     505                 * before the caller tries to read any packets */
     506                if (filter->flag == 0) {
     507                        return -1;
     508                }
     509               
     510                if (setsockopt(FORMAT(libtrace->format_data)->fd,
    505511                                        SOL_SOCKET,
    506512                                        SO_ATTACH_FILTER,
     
    746752
    747753                if (pcap_compile(pcap, &f->filter, f->filterstring, 0, 0) == -1) {
    748                         perror("PCAP failed to compile the filterstring");
    749                         return -1;
    750                 }
     754                        /* Filter didn't compile, set flag to 0 so we can
     755                         * detect this when trace_start() is called and
     756                         * produce a useful error
     757                         */
     758                        f->flag = 0;
     759                        trace_set_err(libtrace, TRACE_ERR_INIT_FAILED,
     760                                        "Failed to compile BPF filter (%s): %s",
     761                                        f->filterstring, pcap_geterr(pcap));
     762                } else {
     763                        /* Set the "flag" to indicate that the filterstring
     764                         * has been compiled
     765                         */
     766                        f->flag = 1;
     767                }
    751768
    752769                pcap_close(pcap);
    753770               
    754                 /* Set the "flag" to indicate that the filterstring has been
    755                  * compiled
    756                  */
    757                 f->flag = 1;
    758771        }
    759772       
     
    880893        int snaplen;
    881894        uint32_t flags = 0;
     895        fd_set readfds;
     896        struct timeval tout;
     897        int ret;
    882898       
    883899        if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) {
     
    915931        iovec.iov_len = snaplen;
    916932
    917         hdr->wirelen = recvmsg(FORMAT(libtrace->format_data)->fd, &msghdr, 0);
     933        /* Use select to allow us to time out occasionally to check if someone
     934         * has hit Ctrl-C or otherwise wants us to stop reading and return
     935         * so they can exit their program.
     936         */
     937
     938        while (1) {
     939                tout.tv_sec = 0;
     940                tout.tv_usec = 500000;
     941                FD_ZERO(&readfds);
     942                FD_SET(FORMAT(libtrace->format_data)->fd, &readfds);
     943
     944                ret = select(FORMAT(libtrace->format_data)->fd + 1, &readfds,
     945                                NULL, NULL, &tout);
     946                if (ret < 0 && errno != EINTR) {
     947                        trace_set_err(libtrace, errno, "select");
     948                        return -1;
     949                } else if (ret < 0) {
     950                        continue;
     951                }
     952               
     953                if (FD_ISSET(FORMAT(libtrace->format_data)->fd, &readfds)) {
     954                        /* There's something available for us to read */
     955                        break;
     956                }
     957
     958               
     959                /* If we get here, we timed out -- check if we should halt */
     960                if (libtrace_halt)
     961                        return 0;
     962        }
     963
     964        hdr->wirelen = recvmsg(FORMAT(libtrace->format_data)->fd, &msghdr, MSG_TRUNC);
    918965
    919966        if (hdr->wirelen==~0U) {
     
    10311078        assert((((unsigned long) header) & (pagesize - 1)) == 0);
    10321079
    1033         /* TP_STATUS_USER means that we can use the frame.
    1034          * When a slot does not have this flag set, the frame is not
    1035          * ready for consumption.
    1036          */
    1037         while (!(header->tp_status & TP_STATUS_USER)) {
     1080        while (1) {
    10381081                pollset.fd = FORMAT(libtrace->format_data)->fd;
    10391082                pollset.events = POLLIN;
    10401083                pollset.revents = 0;
    10411084                /* Wait for more data */
    1042                 ret = poll(&pollset, 1, -1);
     1085                ret = poll(&pollset, 1, 500);
    10431086                if (ret < 0) {
    10441087                        if (errno != EINTR)
    10451088                                trace_set_err(libtrace,errno,"poll()");
    10461089                        return -1;
    1047                 }
     1090                } 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;
    10481103        }
    10491104
     
    10861141        if(header->tp_status & TP_STATUS_USER){
    10871142                /* We have a frame waiting */
    1088                 event.size = linuxring_read_packet(libtrace, packet);
     1143                event.size = trace_read_packet(libtrace, packet);
    10891144                event.type = TRACE_EVENT_PACKET;
    10901145        } else {
  • lib/format_pcap.c

    rf7bcbfb r4649fea  
    295295        }
    296296#endif
     297#ifdef HAVE_PCAP_SETNONBLOCK
     298        pcap_setnonblock(INPUT.pcap,0,errbuf);
     299#endif
    297300        /* Set a filter if one is defined */
    298301        if (DATA(libtrace)->filter) {
    299                 if (DATA(libtrace)->filter->flag == 0) {
     302                struct pcap_pkthdr *pcap_hdr = NULL;
     303                u_char *pcap_payload = NULL;
     304                int pcapret;
     305               
     306                if (DATA(libtrace)->filter->flag == 0) {
    300307                        pcap_compile(INPUT.pcap,
    301308                                        &DATA(libtrace)->filter->filter,
     
    304311                        DATA(libtrace)->filter->flag = 1;
    305312                }
    306                 if (pcap_setfilter(INPUT.pcap,&DATA(libtrace)->filter->filter)
     313                if (pcap_setfilter(INPUT.pcap,&DATA(libtrace)->filter->filter)
    307314                        == -1) {
    308315                        trace_set_err(libtrace,TRACE_ERR_INIT_FAILED,"%s",
     
    310317                        return -1; /* failure */
    311318                }
    312         }
    313 #ifdef HAVE_PCAP_SETNONBLOCK
    314         pcap_setnonblock(INPUT.pcap,0,errbuf);
    315 #endif
     319
     320                /* Consume the first packet in the queue, as this may not
     321                 * have had the filter applied to it.
     322                 *
     323                 * Otherwise we can get problems with the event API, where
     324                 * select tells us that there is a packet available but
     325                 * calling trace_read_packet will block forever because the
     326                 * packet in the queue didn't match the filter so
     327                 * pcap_next_ex returns "timed out".
     328                 *
     329                 * This does mean we may consume a legitimate packet, but
     330                 * that's a pretty small downside compared with trace_event
     331                 * getting stuck in an infinite loop because of pcap
     332                 * wackiness.
     333                 *
     334                 * For some reason, we only need to consume one packet for
     335                 * this to work, so let's hope that holds in the future.
     336                 */
     337                do {
     338                        pcapret = pcap_next_ex(INPUT.pcap, &pcap_hdr,
     339                                (const u_char **)&pcap_payload);
     340                } while (0);
     341
     342                if (pcapret < 0)
     343                        return -1;
     344        }
    316345        return 0; /* success */
    317346}
     
    421450                                if (libtrace_halt)
    422451                                        return 0;
    423                                 continue; /* timeout expired */
     452                                continue; /* timeout expired */
    424453                        case -1:
    425454                                trace_set_err(libtrace,TRACE_ERR_BAD_PACKET,
     
    578607static libtrace_direction_t pcap_set_direction(libtrace_packet_t *packet,
    579608                libtrace_direction_t dir) {
    580        
     609
     610        /* We only support tagging with IN or OUT return error for any others */
     611        if(!(dir == TRACE_DIR_OUTGOING || dir == TRACE_DIR_INCOMING))
     612                return -1;
     613
    581614        /* PCAP doesn't have a direction field in the header, so we need to
    582615         * promote to Linux SLL to tag it properly */
  • lib/format_pcapfile.c

    rf7bcbfb rc70f59f  
    713713
    714714        if (IN_OPTIONS.real_time) {
    715                 event.size = pcapfile_read_packet(libtrace, packet);
     715                event.size = trace_read_packet(libtrace, packet);
    716716                if (event.size < 1)
    717717                        event.type = TRACE_EVENT_TERMINATE;
  • lib/format_rt.c

    r90e8d92 rc70f59f  
    780780                        if (packet->type == TRACE_RT_END_DATA)
    781781                                event.type = TRACE_EVENT_TERMINATE;
    782                         else
     782                        else {
    783783                                /* Since several RT messages can have zero-byte
    784784                                 * length (once the framing is removed), an
     
    786786                                 * PACKET event */
    787787                                event.type = TRACE_EVENT_PACKET;
     788                                trace->accepted_packets ++;
     789                        }
    788790
    789791                }       
    790792                else {
    791793                        event.type = TRACE_EVENT_PACKET;
     794                        trace->accepted_packets ++;
    792795                }
    793796
     
    795798                        if (!trace_apply_filter(trace->filter, packet)) {
    796799                                trace_clear_cache(packet);
    797                                 continue;
     800                                trace->filtered_packets ++;
     801                                continue;
    798802                        }
    799803                }
  • lib/trace.c

    rf7bcbfb r7fda5c5  
    723723                do {
    724724                        size_t ret;
     725                        int filtret;
    725726                        /* Clear the packet cache */
    726727                        trace_clear_cache(packet);
     
    733734                                 * packet
    734735                                 */
    735                                 if (!trace_apply_filter(libtrace->filter,packet)){
     736                                filtret = trace_apply_filter(libtrace->filter, packet);
     737                                if (filtret == -1) {
     738                                        /* Error compiling filter, probably */
     739                                        return ~0U;
     740                                }
     741                               
     742                                if (filtret == 0) {
    736743                                        ++libtrace->filtered_packets;
    737744                                        continue;
     
    11121119
    11131120        if (packet->trace->format->trace_event) {
    1114                 event=packet->trace->format->trace_event(trace,packet);
    1115                 if (event.type == TRACE_EVENT_PACKET) {
    1116                         ++trace->accepted_packets;
    1117                 }
     1121                /* Note: incrementing accepted, filtered etc. packet
     1122                 * counters is handled by the format-specific
     1123                 * function so don't increment them here.
     1124                 */
     1125                event=packet->trace->format->trace_event(trace,packet);
    11181126        }
    11191127        return event;
     
    18091817                return trace->format->get_filtered_packets(trace)+
    18101818                        trace->filtered_packets;
    1811         }
    1812         if (trace->format->get_received_packets
    1813                 && trace->format->get_dropped_packets) {
    1814                 return
    1815                         ((trace_get_received_packets(trace)
    1816                         -trace_get_accepted_packets(trace))
    1817                         -trace_get_dropped_packets(trace))
    1818                         +trace->filtered_packets;
    18191819        }
    18201820        return trace->filtered_packets;
  • libwandio/Makefile.am

    r3b6e0cf rcd8efa6  
     1SUBDIRS = . tools/wandiocat
     2
    13lib_LTLIBRARIES=libwandio.la
    24
     
    3941libwandio_la_LDFLAGS=-version-info 1:1:0 @ADD_LDFLAGS@
    4042
    41 bin_PROGRAMS = wandiocat
    42 wandiocat_SOURCES = wcat.c
    43 wandiocat_CFLAGS = -I"$(top_srcdir)/libwandio"
    44 wandiocat_CXXFLAGS = -I"$(top_srcdir)/libwandio"
    45 wandiocat_LDFLAGS = -L"$(top_srcdir)/libwandio" -lwandio
  • libwandio/ior-peek.c

    rf7bcbfb rce7153d  
    6262        io_t *child;
    6363        char *buffer;
    64         int length; /* Length of buffer */
    65         int offset; /* Offset into buffer */
     64        off_t length; /* Length of buffer */
     65        off_t offset; /* Offset into buffer */
    6666};
    6767
  • test/Makefile

    rfb20640 r262a093  
    1212
    1313BINS = test-pcap-bpf test-event test-time test-dir test-wireless test-errors \
    14         test-plen test-autodetect test-ports test-fragment
     14        test-plen test-autodetect test-ports test-fragment test-live test-live-snaplen
    1515
    1616.PHONY: all clean distclean install depend test
Note: See TracChangeset for help on using the changeset viewer.