Changes in / [314239a:97d0351]
- Files:
-
- 4 added
- 45 edited
Legend:
- Unmodified
- Added
- Removed
-
AUTHORS
r92db9e4 r35de364 36 36 * Anthony Coddington for adding ERF provenance support and fixing a number 37 37 of other ERF/DAG issues 38 * Tim Dawson for fixing issues with building against musl libc 39 * Hendrik Leppelsack for reporting and fixing some errors in the tool manpages 38 40 * Jamie Curtis for fixing a couple of bugs many many years ago 39 41 * Brendon Jones for creating the original Windows DLLs and writing bits of -
README
r0e8f8cb r096851a 1 libtrace 4.0. 31 libtrace 4.0.4 2 2 3 3 --------------------------------------------------------------------------- -
configure.in
r0e8f8cb rb6579db 4 4 # and in the README 5 5 6 AC_INIT([libtrace],[4.0. 3],[contact@wand.net.nz],[libtrace])6 AC_INIT([libtrace],[4.0.4],[contact@wand.net.nz],[libtrace]) 7 7 8 8 LIBTRACE_MAJOR=4 9 9 LIBTRACE_MID=0 10 LIBTRACE_MINOR= 310 LIBTRACE_MINOR=4 11 11 12 12 # OpenSolaris hides libraries like libncurses in /usr/gnu/lib, which is not … … 87 87 AC_FUNC_REALLOC 88 88 89 # *BSD doesn't have strndup. Currently provide our own.90 AC_REPLACE_FUNCS(strndup)91 92 93 89 # Checks for typedefs, structures, and compiler characteristics. 94 90 AC_C_CONST … … 126 122 127 123 # Fail if any of these functions are missing 128 AC_CHECK_ FUNCS(socket strdup strlcpy strcasecmp strncasecmp snprintf vsnprintf recvmmsg)124 AC_CHECK_DECLS([socket, strdup, strlcpy, strcasecmp, strncasecmp, snprintf, vsnprintf, recvmmsg, strndup]) 129 125 130 126 AC_CHECK_SIZEOF([long int]) … … 202 198 203 199 # Check for libwandio (no longer bundled with libtrace) 204 AC_CHECK_LIB(wandio,wandio_ create,wandiofound=1,wandiofound=0)200 AC_CHECK_LIB(wandio,wandio_wflush,wandiofound=1,wandiofound=0) 205 201 if test "$wandiofound" = 0; then 206 AC_MSG_ERROR(libwandio is required to compile libtrace. If you have installed itin a non-standard location please use LDFLAGS to specify the location of the library. WANDIO can be obtained from http://research.wand.net.nz/software/libwandio.php)202 AC_MSG_ERROR(libwandio 1.0.5 or better is required to compile this version of libtrace. If you have installed libwandio in a non-standard location please use LDFLAGS to specify the location of the library. WANDIO can be obtained from http://research.wand.net.nz/software/libwandio.php) 207 203 else 208 204 LIBTRACE_LIBS="$LIBTRACE_LIBS -lwandio" … … 212 208 213 209 AC_CHECK_LIB(crypto, EVP_EncryptInit_ex, cryptofound=1, cryptofound=0) 210 if test "$cryptofound" = 1; then 211 AC_CHECK_HEADER(openssl/evp.h, cryptofound=1, cryptofound=0) 212 fi 213 AC_CHECK_LIB(tasn1, asn1_array2tree, asn1found=1, asn1found=0) 214 214 215 215 # Check for libpcap … … 455 455 AC_CHECK_LIB(numa, numa_node_to_cpus, have_numa=1, have_numa=0) 456 456 457 # Need libwandder for ETSI live decoding 458 AC_CHECK_LIB(wandder, init_wandder_decoder, have_wandder=1, have_wandder=0) 459 457 460 # Checks for various "optional" libraries 458 461 AC_CHECK_LIB(pthread, pthread_create, have_pthread=1, have_pthread=0) … … 482 485 with_numa=yes 483 486 else 484 AC_DEFINE(HAVE_LIBNUMA, 0, [Set to 1 if libnuma is supported])485 487 with_numa=no 488 fi 489 490 if test "$have_wandder" = 1; then 491 LIBTRACE_LIBS="$LIBTRACE_LIBS -lwandder" 492 AC_DEFINE(HAVE_WANDDER, 1, [Set to 1 if libwandder is available]) 493 wandder_avail=yes 494 else 495 wandder_avail=no 486 496 fi 487 497 … … 533 543 with_clock_gettime=yes 534 544 else 535 AC_DEFINE(HAVE_CLOCK_GETTIME, 0, [Set to 1 if clock_gettime is supported])536 545 with_clock_gettime=no 537 546 fi 538 547 548 549 have_memfd_create=no 550 AC_RUN_IFELSE([AC_LANG_PROGRAM([ 551 #include <sys/syscall.h> 552 ],[ 553 #ifndef __NR_memfd_create 554 exit(1) 555 #endif 556 ])], [have_memfd_create=yes]) 557 558 if test "$have_memfd_create" = "yes"; then 559 AC_DEFINE(HAVE_MEMFD_CREATE, 1, [Set to 1 if kernel supports memfd_create syscall]) 560 fi 539 561 540 562 # Stupid AC_SEARCH_LIB appends stuff to LIBS even when I don't want it to, so … … 611 633 AM_CONDITIONAL([HAVE_DAG], [test "$libtrace_dag" = true]) 612 634 AM_CONDITIONAL([HAVE_DPDK], [test "$libtrace_dpdk" = true]) 635 AM_CONDITIONAL([HAVE_WANDDER], [test "x$wandder_avail" = "xyes"]) 613 636 AM_CONDITIONAL([DAG2_4], [test "$libtrace_dag_version" = 24]) 614 637 AM_CONDITIONAL([DAG2_5], [test "$libtrace_dag_version" = 25]) … … 692 715 fi 693 716 reportopt "Compiled with LLVM BPF JIT support" $JIT 717 reportopt "Compiled with live ETSI LI support (requires libwandder)" $wandder_avail 694 718 reportopt "Building man pages/documentation" $libtrace_doxygen 695 719 reportopt "Building tracetop (requires libncurses)" $with_ncurses 696 reportopt "Building traceanon with CryptoPan (requires libcrypto )" $have_crypto720 reportopt "Building traceanon with CryptoPan (requires libcrypto and openssl/evp.h)" $have_crypto 697 721 698 722 # Report any errors relating to missing bison, flex, etc. -
lib/Makefile.am
r49969f2 r823d8e1 7 7 data-struct/deque.h data-struct/linked_list.h \ 8 8 data-struct/buckets.h data-struct/sliding_window.h \ 9 data-struct/message_queue.h hash_toeplitz.h 9 data-struct/message_queue.h hash_toeplitz.h \ 10 data-struct/simple_circular_buffer.h 10 11 11 12 AM_CFLAGS=@LIBCFLAGS@ @CFLAG_VISIBILITY@ -pthread … … 51 52 endif 52 53 54 if HAVE_WANDDER 55 ETSISOURCES=format_etsilive.c 56 else 57 ETSISOURCES= 58 endif 59 53 60 libtrace_la_SOURCES = trace.c trace_parallel.c common.h \ 54 61 format_erf.c format_pcap.c format_legacy.c \ … … 63 70 protocols_application.c \ 64 71 $(DAGSOURCE) format_erf.h format_ndag.c format_ndag.h \ 65 $(BPFJITSOURCE) \72 $(BPFJITSOURCE) $(ETSISOURCES) \ 66 73 libtrace_arphrd.h \ 67 74 data-struct/ring_buffer.c data-struct/vector.c \ … … 69 76 data-struct/sliding_window.c data-struct/object_cache.c \ 70 77 data-struct/linked_list.c hash_toeplitz.c combiner_ordered.c \ 71 data-struct/buckets.c \78 data-struct/buckets.c data-struct/simple_circular_buffer.c \ 72 79 combiner_sorted.c combiner_unordered.c \ 73 pthread_spinlock.c pthread_spinlock.h 80 pthread_spinlock.c pthread_spinlock.h \ 81 strndup.c 74 82 75 83 if DAG2_4 -
lib/format_atmhdr.c
r2c457ec r32ee9b2 202 202 NULL, /* fin_packet */ 203 203 NULL, /* write_packet */ 204 NULL, /* flush_output */ 204 205 atmhdr_get_link_type, /* get_link_type */ 205 206 NULL, /* get_direction */ -
lib/format_bpf.c
r5e3f16c ra0f031b 371 371 /* TODO investigate hashing in BSD? */ 372 372 break; 373 373 case TRACE_OPTION_REPLAY_SPEEDUP: 374 break; 374 375 /* Avoid default: so that future options will cause a warning 375 376 * here to remind us to implement it, or flag it as … … 616 617 NULL, /* fin_packet */ 617 618 NULL, /* write_packet */ 619 NULL, /* flush_output */ 618 620 bpf_get_link_type, /* get_link_type */ 619 621 bpf_get_direction, /* get_direction */ … … 666 668 NULL, /* fin_packet */ 667 669 NULL, /* write_packet */ 670 NULL, /* flush_output */ 668 671 bpf_get_link_type, /* get_link_type */ 669 672 bpf_get_direction, /* get_direction */ -
lib/format_dag24.c
ree6e802 r32ee9b2 529 529 NULL, /* fin_packet */ 530 530 NULL, /* write_packet */ 531 NULL, /* flush_output */ 531 532 erf_get_link_type, /* get_link_type */ 532 533 erf_get_direction, /* get_direction */ -
lib/format_dag25.c
ra857389 r32ee9b2 608 608 return -1; 609 609 case TRACE_OPTION_EVENT_REALTIME: 610 case TRACE_OPTION_REPLAY_SPEEDUP: 610 611 /* Live capture is always going to be realtime */ 611 612 return -1; … … 1563 1564 NULL, /* fin_packet */ 1564 1565 dag_write_packet, /* write_packet */ 1566 NULL, /* flush_output */ 1565 1567 erf_get_link_type, /* get_link_type */ 1566 1568 erf_get_direction, /* get_direction */ -
lib/format_dpdk.c
r8ed07df r3b94ef2 57 57 #include <math.h> 58 58 59 #if HAVE_LIBNUMA59 #ifdef HAVE_LIBNUMA 60 60 #include <numa.h> 61 61 #endif … … 90 90 struct dpdk_format_data_t { 91 91 int8_t promisc; /* promiscuous mode - RX only */ 92 uint8_t port; /* Always 0 we only whitelist a single port - Shared TX & RX */93 uint8_t nb_ports; /* Total number of usable ports on system should be 1 */94 92 uint8_t paused; /* See paused_state */ 93 portid_t port; /* Always 0 we only whitelist a single port - Shared TX & RX */ 94 portid_t nb_ports; /* Total number of usable ports on system should be 1 */ 95 95 uint16_t link_speed; /* Link speed 10,100,1000,10000 etc. */ 96 96 int snaplen; /* The snap length for the capture - RX only */ … … 214 214 int matches; 215 215 assert(str); 216 #if RTE_VERSION >= RTE_VERSION_NUM(17, 8, 0, 1) 216 217 matches = sscanf(str, "%8"SCNx32":%2"SCNx8":%2"SCNx8".%2"SCNx8"-%ld", 217 218 &addr->domain, &addr->bus, &addr->devid, 218 219 &addr->function, core); 220 #else 221 matches = sscanf(str, "%4"SCNx16":%2"SCNx8":%2"SCNx8".%2"SCNx8"-%ld", 222 &addr->domain, &addr->bus, &addr->devid, 223 &addr->function, core); 224 #endif 219 225 if (matches >= 4) { 220 226 return 0; … … 454 460 } 455 461 456 #if HAVE_LIBNUMA462 #ifdef HAVE_LIBNUMA 457 463 format_data->nic_numa_node = pci_to_numa(&use_addr); 458 464 if (my_cpu < 0) { … … 696 702 case TRACE_OPTION_META_FREQ: 697 703 case TRACE_OPTION_EVENT_REALTIME: 704 case TRACE_OPTION_REPLAY_SPEEDUP: 698 705 break; 699 706 /* Avoid default: so that future options will cause a warning … … 816 823 * @param cb_arg The dpdk_format_data_t structure associated with the format 817 824 */ 818 static int dpdk_lsc_callback(uint16_t port, enum rte_eth_event_type event, 825 #if RTE_VERSION >= RTE_VERSION_NUM(17, 8, 0, 1) 826 static int dpdk_lsc_callback(portid_t port, enum rte_eth_event_type event, 819 827 void *cb_arg, void *retparam UNUSED) { 828 #else 829 static void dpdk_lsc_callback(portid_t port, enum rte_eth_event_type event, 830 void *cb_arg) { 831 #endif 820 832 struct dpdk_format_data_t * format_data = cb_arg; 821 833 struct rte_eth_link link_info; … … 852 864 } 853 865 #endif 866 #if RTE_VERSION >= RTE_VERSION_NUM(17, 8, 0, 1) 854 867 return 0; 868 #endif 855 869 } 856 870 … … 878 892 * these to any particular physical core */ 879 893 if (real) { 880 #if HAVE_LIBNUMA894 #ifdef HAVE_LIBNUMA 881 895 for (i = 0; i < RTE_MAX_LCORE; ++i) { 882 896 if (!rte_lcore_is_enabled(i) && numa_node_of_cpu(i) == socket) { … … 1171 1185 if (ret < 0) { 1172 1186 snprintf(err, errlen, "Intel DPDK - Cannot configure TX queue" 1173 " on port % "PRIu8" : %s",format_data->port,1187 " on port %d : %s", (int)format_data->port, 1174 1188 strerror(-ret)); 1175 1189 return -1; … … 1220 1234 if (ret < 0) { 1221 1235 snprintf(err, errlen, "Intel DPDK - Cannot configure" 1222 " RX queue on port % "PRIu8": %s",1223 format_data->port,1236 " RX queue on port %d : %s", 1237 (int)format_data->port, 1224 1238 strerror(-ret)); 1225 1239 return -1; … … 1290 1304 } 1291 1305 1292 static inline size_t dpdk_get_max_rx_queues ( uint8_t port_id) {1306 static inline size_t dpdk_get_max_rx_queues (portid_t port_id) { 1293 1307 struct rte_eth_dev_info dev_info; 1294 1308 rte_eth_dev_info_get(port_id, &dev_info); … … 1511 1525 memcpy(rte_pktmbuf_append(m_buff[0], caplen), packet->payload, caplen); 1512 1526 do { 1513 ret = rte_eth_tx_burst( 0 /*queue TODO*/, FORMAT(trace)->port, m_buff, 1);1527 ret = rte_eth_tx_burst(FORMAT(trace)->port, 0 /*queue TODO*/, m_buff, 1); 1514 1528 } while (ret != 1); 1515 1529 } … … 2146 2160 dpdk_fin_packet, /* fin_packet */ 2147 2161 dpdk_write_packet, /* write_packet */ 2162 NULL, /* flush_output */ 2148 2163 dpdk_get_link_type, /* get_link_type */ 2149 2164 dpdk_get_direction, /* get_direction */ -
lib/format_dpdk.h
r8efa986 r6d17620 113 113 #define rte_mempool_in_use_count rte_mempool_free_count 114 114 #endif 115 116 /* 17.05-rc1 deprecated, 17.08 removed 117 * rte_set_log_level -> rte_log_set_global_level 118 */ 119 #if RTE_VERSION < RTE_VERSION_NUM(17, 5, 0, 1) 120 #define rte_log_set_global_level rte_set_log_level 121 #endif 122 123 /* 17.11-rc1 increases port size from 8 to 16bits 124 */ 125 #if RTE_VERSION >= RTE_VERSION_NUM(17, 11, 0, 1) 126 typedef uint16_t portid_t; 127 #else 128 typedef uint8_t portid_t; 129 #endif 130 115 131 116 132 #include <rte_per_lcore.h> -
lib/format_dpdkndag.c
re54bd5f r32ee9b2 733 733 NULL, /* fin_packet */ 734 734 NULL, /* write_packet */ 735 NULL, /* flush_output */ 735 736 erf_get_link_type, /* get_link_type */ 736 737 erf_get_direction, /* get_direction */ -
lib/format_duck.c
ree6e802 r32ee9b2 337 337 NULL, /* fin_packet */ 338 338 duck_write_packet, /* write_packet */ 339 NULL, /* flush_output */ 339 340 duck_get_link_type, /* get_link_type */ 340 341 NULL, /* get_direction */ -
lib/format_erf.c
r207e288 r32ee9b2 597 597 } 598 598 return numbytes + framinglen; 599 } 600 601 static int erf_flush_output(libtrace_out_t *libtrace) { 602 return wandio_wflush(OUTPUT->file); 599 603 } 600 604 … … 868 872 NULL, /* fin_packet */ 869 873 erf_write_packet, /* write_packet */ 874 erf_flush_output, /* flush_output */ 870 875 erf_get_link_type, /* get_link_type */ 871 876 erf_get_direction, /* get_direction */ … … 912 917 NULL, /* fin_packet */ 913 918 erf_write_packet, /* write_packet */ 919 erf_flush_output, /* flush_output */ 914 920 erf_get_link_type, /* get_link_type */ 915 921 erf_get_direction, /* get_direction */ -
lib/format_helper.c
r633339d rde060a8 127 127 double ts; 128 128 double now; 129 double sincebeginnow = 0; 130 double sincebegintrace = 0; 131 129 132 #ifdef WIN32 130 133 struct __timeb64 tstruct; … … 182 185 183 186 184 if (fabs(trace->event. tdelta)>1e-9) {185 /* Subtract the tdelta from the walltimeto get a suitable187 if (fabs(trace->event.first_ts)>1e-9) { 188 /* Subtract the tdelta from the starting times to get a suitable 186 189 * "relative" time */ 187 now -= trace->event.tdelta; 190 sincebeginnow = (now - trace->event.first_now); 191 sincebegintrace = (ts - trace->event.first_ts); 188 192 189 193 /* If the trace timestamp is still in the future, return a 190 194 * SLEEP event, otherwise return the packet */ 191 if (ts > now) { 192 event.seconds = ts - 193 trace->event.trace_last_ts; 194 trace->event.trace_last_ts = ts; 195 if (sincebeginnow <= sincebegintrace / (double)trace->replayspeedup) { 196 event.seconds = ((sincebegintrace / (double)trace->replayspeedup) - sincebeginnow); 195 197 event.type = TRACE_EVENT_SLEEP; 196 198 trace->event.waiting = true; … … 204 206 * trace file. 205 207 */ 206 trace->event.tdelta = now - ts; 208 trace->event.first_now = (double)now; 209 trace->event.first_ts = (double)ts; 207 210 } 208 211 … … 219 222 event.type = TRACE_EVENT_PACKET; 220 223 221 trace->event.trace_last_ts = ts;222 224 trace->event.waiting = false; 223 225 -
lib/format_legacy.c
r2c457ec r32ee9b2 523 523 NULL, /* fin_packet */ 524 524 NULL, /* write_packet */ 525 NULL, /* flush_output */ 525 526 legacyatm_get_link_type, /* get_link_type */ 526 527 NULL, /* get_direction */ … … 567 568 NULL, /* fin_packet */ 568 569 NULL, /* write_packet */ 570 NULL, /* flush_output */ 569 571 legacyeth_get_link_type, /* get_link_type */ 570 572 NULL, /* get_direction */ … … 611 613 NULL, /* fin_packet */ 612 614 NULL, /* write_packet */ 615 NULL, /* flush_output */ 613 616 legacypos_get_link_type, /* get_link_type */ 614 617 NULL, /* get_direction */ … … 655 658 NULL, /* fin_packet */ 656 659 NULL, /* write_packet */ 660 NULL, /* flush_output */ 657 661 legacynzix_get_link_type, /* get_link_type */ 658 662 NULL, /* get_direction */ -
lib/format_linux_common.c
rd47ca18 r47d4f8c 49 49 50 50 #include "format_linux_common.h" 51 52 unsigned int rand_seedp = 0; 51 53 52 54 #ifdef HAVE_NETPACKET_PACKET_H … … 85 87 sock = socket(PF_INET, SOCK_STREAM, 0); 86 88 memset(&ifr, 0, sizeof(struct ifreq)); 87 strncpy(ifr.ifr_name, libtrace->uridata, IF_NAMESIZE );89 strncpy(ifr.ifr_name, libtrace->uridata, IF_NAMESIZE - 1); 88 90 if (ioctl(sock, SIOCGIFHWADDR, &ifr) != 0) { 89 91 perror("Can't get HWADDR for interface"); … … 164 166 /* Live captures are always going to be in trace time */ 165 167 break; 168 case TRACE_OPTION_REPLAY_SPEEDUP: 169 break; 166 170 /* Avoid default: so that future options will cause a warning 167 171 * here to remind us to implement it, or flag it as … … 199 203 /* Some examples use pid for the group however that would limit a single 200 204 * application to use only int/ring format, instead using rand */ 201 FORMAT_DATA->fanout_group = (uint16_t) rand();205 FORMAT_DATA->fanout_group = (uint16_t) (rand_r(&rand_seedp) % 65536); 202 206 return 0; 203 207 } -
lib/format_linux_common.h
r4697684 rf9df20e 421 421 struct linux_per_stream_t *stream) 422 422 { 423 int fanout_opt = ((int)FORMAT_DATA->fanout_flags << 16) | 424 (int)FORMAT_DATA->fanout_group; 425 if (setsockopt(stream->fd, SOL_PACKET, PACKET_FANOUT, 426 &fanout_opt, sizeof(fanout_opt)) == -1) { 427 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, 423 int fanout_opt; 424 int attempts = 0; 425 while (attempts < 5) { 426 fanout_opt = ((int)FORMAT_DATA->fanout_flags << 16) | 427 (int)FORMAT_DATA->fanout_group; 428 429 if (setsockopt(stream->fd, SOL_PACKET, PACKET_FANOUT, 430 &fanout_opt, sizeof(fanout_opt)) == -1) { 431 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, 428 432 "Converting the fd to a socket fanout failed %s", 429 433 libtrace->uridata); 430 return -1; 434 FORMAT_DATA->fanout_group ++; 435 attempts ++; 436 continue; 437 } 438 return 0; 431 439 } 432 return 0;440 return -1; 433 441 } 434 442 #endif /* HAVE_NETPACKET_PACKET_H */ -
lib/format_linux_int.c
rdb84bb2 r32ee9b2 496 496 NULL, /* fin_packet */ 497 497 linuxnative_write_packet, /* write_packet */ 498 NULL, /* flush_output */ 498 499 linuxnative_get_link_type, /* get_link_type */ 499 500 linuxnative_get_direction, /* get_direction */ … … 556 557 NULL, /* fin_packet */ 557 558 NULL, /* write_packet */ 559 NULL, /* flush_output */ 558 560 linuxnative_get_link_type, /* get_link_type */ 559 561 linuxnative_get_direction, /* get_direction */ -
lib/format_linux_ring.c
rdb84bb2 r8a63abd 61 61 ((mac) > (hdrend) && (mac) < (net) ? (mac) : (net)) 62 62 63 static pthread_mutex_t pagesize_mutex; 63 64 #ifdef HAVE_NETPACKET_PACKET_H 64 65 /* Get current frame in the ring buffer*/ … … 70 71 /* Cached page size, the page size shouldn't be changing */ 71 72 static int pagesize = 0; 73 72 74 73 75 /* … … 88 90 struct ifreq ifr; 89 91 unsigned max_frame = LIBTRACE_PACKET_BUFSIZE; 90 pagesize = getpagesize(); 92 pthread_mutex_lock(&pagesize_mutex); 93 if (pagesize == 0) { 94 pagesize = getpagesize(); 95 } 96 pthread_mutex_unlock(&pagesize_mutex); 91 97 92 98 strcpy(ifr.ifr_name, uri); … … 461 467 struct pollfd pollset[2]; 462 468 463 ring_release_frame(libtrace, packet);464 465 469 packet->buf_control = TRACE_CTRL_EXTERNAL; 466 470 packet->type = TRACE_RT_DATA_LINUX_RING; … … 547 551 548 552 stream->last_timestamp = packet->order; 549 550 553 551 554 /* We just need to get prepare_packet to set all our packet pointers … … 745 748 linuxring_fin_packet, /* fin_packet */ 746 749 linuxring_write_packet, /* write_packet */ 750 NULL, /* flush_output */ 747 751 linuxring_get_link_type, /* get_link_type */ 748 752 linuxring_get_direction, /* get_direction */ … … 807 811 NULL, /* fin_packet */ 808 812 NULL, /* write_packet */ 813 NULL, /* flush_output */ 809 814 linuxring_get_link_type, /* get_link_type */ 810 815 linuxring_get_direction, /* get_direction */ … … 837 842 void linuxring_constructor(void) 838 843 { 844 pthread_mutex_init(&pagesize_mutex, NULL); 839 845 register_format(&linuxring); 840 846 } -
lib/format_ndag.c
r3004d6c r32ee9b2 114 114 uint64_t received_packets; 115 115 116 fd_set allsocks;117 116 int maxfd; 118 117 } recvstream_t; … … 488 487 FORMAT_DATA->receivers[i].received_packets = 0; 489 488 FORMAT_DATA->receivers[i].missing_records = 0; 490 FD_ZERO(&(FORMAT_DATA->receivers[i].allsocks));491 489 FORMAT_DATA->receivers[i].maxfd = -1; 492 490 … … 771 769 ssock->recordcount = 0; 772 770 rt->sourcecount += 1; 773 FD_SET(ssock->sock, &(rt->allsocks));774 771 if (ssock->sock > rt->maxfd) { 775 772 rt->maxfd = ssock->sock; … … 881 878 fprintf(stderr, "Received invalid record on the channel for %s:%u.\n", 882 879 ssock->groupaddr, ssock->port); 883 FD_CLR(ssock->sock, &(rt->allsocks));884 880 close(ssock->sock); 885 881 ssock->sock = -1; … … 943 939 #if HAVE_RECVMMSG 944 940 int i; 945 #endif946 947 if (ssock->sock == -1) {948 return 0;949 }950 951 #if HAVE_RECVMMSG952 /* Plenty of full buffers, just use the packets in those */953 if (ssock->bufavail < RECV_BATCH_SIZE / 2) {954 return 1;955 }956 #else957 if (ssock->bufavail == 0) {958 return 1;959 }960 941 #endif 961 942 … … 987 968 ssock->port); 988 969 989 FD_CLR(ssock->sock, &(rt->allsocks));990 970 close(ssock->sock); 991 971 ssock->sock = -1; … … 997 977 ssock->groupaddr, ssock->port, 998 978 strerror(errno)); 999 FD_CLR(ssock->sock, &(rt->allsocks));1000 979 close(ssock->sock); 1001 980 ssock->sock = -1; … … 1035 1014 struct timeval tv; 1036 1015 fd_set fds; 1016 int maxfd = 0; 1037 1017 struct timeval zerotv; 1038 1018 … … 1040 1020 gottime = 0; 1041 1021 1042 fds = rt->allsocks;1022 FD_ZERO(&fds); 1043 1023 1044 1024 if (rt->maxfd == -1) { … … 1049 1029 zerotv.tv_usec = 0; 1050 1030 1051 if (select(rt->maxfd + 1, &fds, NULL, NULL, &zerotv) == -1) { 1031 for (i = 0; i < rt->sourcecount; i++) { 1032 if (rt->sources[i].sock == -1) { 1033 continue; 1034 } 1035 1036 #if HAVE_RECVMMSG 1037 /* Plenty of full buffers, just use the packets in those */ 1038 if (rt->sources[i].bufavail < RECV_BATCH_SIZE / 2) { 1039 readybufs ++; 1040 continue; 1041 } 1042 #else 1043 if (rt->sources[i].bufavail == 0) { 1044 readybufs ++; 1045 continue; 1046 } 1047 #endif 1048 FD_SET(rt->sources[i].sock, &fds); 1049 if (maxfd < rt->sources[i].sock) { 1050 maxfd = rt->sources[i].sock; 1051 } 1052 } 1053 1054 1055 if (maxfd <= 0) { 1056 return readybufs; 1057 } 1058 1059 if (select(maxfd + 1, &fds, NULL, NULL, &zerotv) == -1) { 1052 1060 /* log the error? XXX */ 1053 1061 return -1; … … 1056 1064 for (i = 0; i < rt->sourcecount; i++) { 1057 1065 if (!FD_ISSET(rt->sources[i].sock, &fds)) { 1066 if (rt->sources[i].bufavail < ENCAP_BUFFERS) { 1067 readybufs ++; 1068 } 1058 1069 continue; 1059 1070 } … … 1423 1434 NULL, /* fin_packet */ 1424 1435 NULL, /* write_packet */ 1436 NULL, /* flush_output */ 1425 1437 erf_get_link_type, /* get_link_type */ 1426 1438 erf_get_direction, /* get_direction */ -
lib/format_pcap.c
r5a70a80 r32ee9b2 583 583 } 584 584 585 static int pcap_flush_output(libtrace_out_t *libtrace) { 586 return pcap_dump_flush(OUTPUT.trace.dump); 587 } 588 585 589 static int pcapint_write_packet(libtrace_out_t *libtrace, 586 590 libtrace_packet_t *packet) … … 779 783 NULL, /* fin_packet */ 780 784 pcap_write_packet, /* write_packet */ 785 pcap_flush_output, /* flush_output */ 781 786 pcap_get_link_type, /* get_link_type */ 782 787 pcapint_get_direction, /* get_direction */ … … 823 828 NULL, /* fin_packet */ 824 829 pcapint_write_packet, /* write_packet */ 830 NULL, /* flush_output */ 825 831 pcap_get_link_type, /* get_link_type */ 826 832 pcapint_get_direction, /* get_direction */ -
lib/format_pcapfile.c
r5a70a80 r32ee9b2 257 257 case TRACE_OPTION_FILTER: 258 258 case TRACE_OPTION_HASHER: 259 case TRACE_OPTION_REPLAY_SPEEDUP: 259 260 /* All these are either unsupported or handled 260 261 * by trace_config */ … … 531 532 532 533 return numbytes+ret; 534 } 535 536 static int pcapfile_flush_output(libtrace_out_t *out) { 537 538 return wandio_wflush(DATAOUT(out)->file); 533 539 } 534 540 … … 695 701 NULL, /* fin_packet */ 696 702 pcapfile_write_packet, /* write_packet */ 703 pcapfile_flush_output, /* flush_output */ 697 704 pcapfile_get_link_type, /* get_link_type */ 698 705 pcapfile_get_direction, /* get_direction */ -
lib/format_pcapng.c
r2c457ec re9da777 173 173 }; 174 174 175 typedef struct pcapng_peeker pcapng_hdr_t; 176 175 177 176 178 #define DATA(x) ((struct pcapng_format_data_t *)((x)->format_data)) … … 260 262 case TRACE_OPTION_FILTER: 261 263 case TRACE_OPTION_HASHER: 264 case TRACE_OPTION_REPLAY_SPEEDUP: 262 265 break; 263 266 } … … 286 289 287 290 static char *pcapng_parse_next_option(libtrace_t *libtrace, char **pktbuf, 288 uint16_t *code, uint16_t *length ) {291 uint16_t *code, uint16_t *length, pcapng_hdr_t *blockhdr) { 289 292 290 293 struct pcapng_optheader *opthdr = (struct pcapng_optheader *)*pktbuf; 291 294 int to_skip; 292 295 int padding = 0; 296 char *eob; //end of block 293 297 char *optval; 298 if (DATA(libtrace)->byteswapped) { 299 eob = ((char *) blockhdr) + byteswap32(blockhdr->blocklen); 300 } else { 301 eob = ((char *) blockhdr) + blockhdr->blocklen; 302 } 303 304 assert((char *)blockhdr < *pktbuf); 305 // Check if we have reached the end of the block, +4 for trailing block-size 306 // We cannot assume a endofopt, so we add one 307 if (eob == (*pktbuf) + 4) { 308 *code = 0; 309 *length = 0; 310 return *pktbuf; 311 } 312 // If there is not enough space for another header we've encountered an error 313 if (eob < (*pktbuf) + 4 + sizeof(struct pcapng_optheader)) { 314 return NULL; 315 } 294 316 295 317 if (DATA(libtrace)->byteswapped) { … … 310 332 311 333 to_skip = (*length) + padding; 334 // Check the value we return is within the block length 335 if (eob < optval + to_skip + 4) { 336 return NULL; 337 } 312 338 *pktbuf = optval + to_skip; 313 339 314 340 return optval; 315 }316 317 static inline int skip_block(libtrace_t *libtrace, uint32_t toread) {318 int err;319 320 while (toread > 0) {321 char buf[4096];322 int nextread;323 324 if (toread < 4096) {325 nextread = toread;326 } else {327 nextread = 4096;328 }329 330 err = wandio_read(libtrace->io, buf, nextread);331 if (err < 0) {332 trace_set_err(libtrace, TRACE_ERR_WANDIO_FAILED,333 "Reading section header options");334 return -1;335 }336 if (err == 0) {337 return 0;338 }339 toread -= err;340 }341 342 return 1;343 344 341 } 345 342 … … 352 349 if (err < 0) { 353 350 trace_set_err(libtrace, TRACE_ERR_WANDIO_FAILED, 354 "Failed to read pcapng interface options");351 "Failed reading pcapng block"); 355 352 return err; 356 353 } … … 362 359 if (err < (int)to_read) { 363 360 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 364 "Incomplete pcapng interface headerblock");361 "Incomplete pcapng block"); 365 362 return -1; 366 363 } … … 453 450 } 454 451 455 if (err < (int)(sizeof( sechdr))) {452 if (err < (int)(sizeof(pcapng_sec_t))) { 456 453 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 457 454 "Incomplete pcapng section header block"); … … 490 487 /* Read all of the options etc. -- we don't need them for now, but 491 488 * we have to skip forward to the next useful header. */ 492 bodyptr = packet->buffer + sizeof(pcapng_sec_t);489 bodyptr = (char *) packet->buffer + sizeof(pcapng_sec_t); 493 490 err = pcapng_read_body(libtrace, bodyptr, to_read); 494 491 if (err <= 0) { … … 506 503 507 504 static int pcapng_read_interface(libtrace_t *libtrace, 508 libtrace_packet_t *packet, uint32_t flags) {505 libtrace_packet_t *packet, uint32_t blocklen, uint32_t flags) { 509 506 510 507 pcapng_int_t *inthdr; 511 int err;512 uint32_t to_read;513 508 pcapng_interface_t *newint; 514 509 uint16_t optcode, optlen; … … 516 511 char *bodyptr = NULL; 517 512 518 err = wandio_read(libtrace->io, packet->buffer, sizeof(pcapng_int_t)); 519 520 if (err < 0) { 521 trace_set_err(libtrace, TRACE_ERR_WANDIO_FAILED, 522 "Reading pcapng interface header block"); 523 return -1; 524 } 525 526 if (err == 0) { 527 return 0; 528 } 529 530 if (err < (int)sizeof(inthdr)) { 513 if (blocklen < sizeof(pcapng_int_t) + 4) { 531 514 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 532 515 "Incomplete pcapng interface header block"); … … 551 534 newint->snaplen = byteswap32(inthdr->snaplen); 552 535 newint->linktype = byteswap16(inthdr->linktype); 553 to_read = byteswap32(inthdr->blocklen) - sizeof(pcapng_int_t);554 536 } else { 555 537 assert(inthdr->blocktype == PCAPNG_INTERFACE_TYPE); 556 538 newint->snaplen = inthdr->snaplen; 557 539 newint->linktype = inthdr->linktype; 558 to_read = inthdr->blocklen - sizeof(pcapng_int_t);559 540 } 560 541 … … 565 546 DATA(libtrace)->allocatedinterfaces * sizeof( 566 547 pcapng_interface_t *)); 567 568 /* Could memset the new memory to zero, if required */ 548 memset(&DATA(libtrace)->interfaces[DATA(libtrace)->nextintid], 0, sizeof(void *) * 10); 569 549 } 570 550 … … 572 552 DATA(libtrace)->nextintid += 1; 573 553 574 bodyptr = packet->buffer + sizeof(pcapng_int_t); 575 err = pcapng_read_body(libtrace, bodyptr, to_read); 576 if (err <= 0) { 577 return err; 578 } 554 bodyptr = (char *) packet->buffer + sizeof(pcapng_int_t); 579 555 580 556 packet->type = TRACE_RT_PCAPNG_META; … … 587 563 do { 588 564 optval = pcapng_parse_next_option(libtrace, &bodyptr, 589 &optcode, &optlen );565 &optcode, &optlen, (pcapng_hdr_t *) packet->buffer); 590 566 if (optval == NULL) { 591 567 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, … … 607 583 } while (optcode != 0); 608 584 609 return 1;585 return (int) blocklen; 610 586 611 587 } 612 588 613 589 static int pcapng_read_nrb(libtrace_t *libtrace, libtrace_packet_t *packet, 614 uint32_t flags) {590 uint32_t blocklen, uint32_t flags) { 615 591 616 592 /* Just read the NR records and pass them off to the caller. If … … 619 595 */ 620 596 pcapng_nrb_t *hdr = NULL; 621 int err; 622 uint32_t to_read; 623 char *bodyptr; 624 625 err = wandio_read(libtrace->io, packet->buffer, sizeof(pcapng_nrb_t)); 626 627 if (err < 0) { 628 trace_set_err(libtrace, TRACE_ERR_WANDIO_FAILED, "reading pcapng name resolution block"); 629 return -1; 630 } 631 632 if (err == 0) { 633 return 0; 634 } 635 636 if (err < (int)sizeof(pcapng_nrb_t)) { 597 598 if (blocklen < sizeof(pcapng_nrb_t) + 4) { 637 599 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 638 600 "Incomplete pcapng name resolution block"); … … 645 607 if (DATA(libtrace)->byteswapped) { 646 608 assert(byteswap32(hdr->blocktype) == PCAPNG_NAME_RESOLUTION_TYPE); 647 to_read = byteswap32(hdr->blocklen) - sizeof(pcapng_nrb_t);648 609 } else { 649 610 assert(hdr->blocktype == PCAPNG_NAME_RESOLUTION_TYPE); 650 to_read = hdr->blocklen - sizeof(pcapng_nrb_t);651 }652 653 bodyptr = packet->buffer + sizeof(pcapng_nrb_t);654 err = pcapng_read_body(libtrace, bodyptr, to_read);655 if (err <= 0) {656 return err;657 611 } 658 612 … … 663 617 } 664 618 665 return sizeof(pcapng_nrb_t) + to_read;619 return (int) blocklen; 666 620 667 621 } 668 622 669 623 static int pcapng_read_custom(libtrace_t *libtrace, libtrace_packet_t *packet, 670 uint32_t flags) {624 uint32_t blocklen, uint32_t flags) { 671 625 672 626 /* Just read the custom records and pass them off to the caller. If … … 675 629 */ 676 630 pcapng_custom_t *hdr = NULL; 677 int err; 678 uint32_t to_read; 679 char *bodyptr; 680 681 err = wandio_read(libtrace->io, packet->buffer, sizeof(pcapng_custom_t)); 682 683 if (err < 0) { 684 trace_set_err(libtrace, TRACE_ERR_WANDIO_FAILED, "reading pcapng custom block"); 685 return -1; 686 } 687 688 if (err == 0) { 689 return 0; 690 } 691 692 if (err < (int)sizeof(pcapng_custom_t)) { 631 632 if (blocklen < sizeof(pcapng_custom_t) + 4) { 693 633 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 694 634 "Incomplete pcapng custom block"); … … 702 642 assert(byteswap32(hdr->blocktype) == PCAPNG_CUSTOM_TYPE || 703 643 byteswap32(hdr->blocktype) == PCAPNG_CUSTOM_NONCOPY_TYPE); 704 to_read = byteswap32(hdr->blocklen) - sizeof(pcapng_custom_t); 705 } else { 706 assert(hdr->blocktype == PCAPNG_NAME_RESOLUTION_TYPE || 644 } else { 645 assert(hdr->blocktype == PCAPNG_CUSTOM_TYPE || 707 646 hdr->blocktype == PCAPNG_CUSTOM_NONCOPY_TYPE); 708 to_read = hdr->blocklen - sizeof(pcapng_custom_t);709 }710 711 bodyptr = packet->buffer + sizeof(pcapng_custom_t);712 err = pcapng_read_body(libtrace, bodyptr, to_read);713 if (err <= 0) {714 return err;715 647 } 716 648 … … 721 653 } 722 654 723 return sizeof(pcapng_custom_t) + to_read;655 return (int) blocklen; 724 656 725 657 } 726 658 727 659 static int pcapng_read_stats(libtrace_t *libtrace, libtrace_packet_t *packet, 728 uint32_t flags) {660 uint32_t blocklen, uint32_t flags) { 729 661 pcapng_stats_t *hdr = NULL; 730 int err;731 uint32_t to_read;732 662 uint32_t ifaceid; 733 663 uint64_t timestamp; … … 737 667 char *bodyptr; 738 668 739 err = wandio_read(libtrace->io, packet->buffer, sizeof(pcapng_stats_t)); 740 741 if (err < 0) { 742 trace_set_err(libtrace, TRACE_ERR_WANDIO_FAILED, "reading pcapng interface stats"); 743 return -1; 744 } 745 746 if (err == 0) { 747 return 0; 748 } 749 750 if (err < (int)sizeof(pcapng_stats_t)) { 669 if (blocklen < sizeof(pcapng_stats_t) + 4) { 751 670 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 752 671 "Incomplete pcapng interface stats header"); … … 759 678 if (DATA(libtrace)->byteswapped) { 760 679 assert(byteswap32(hdr->blocktype) == PCAPNG_INTERFACE_STATS_TYPE); 761 to_read = byteswap32(hdr->blocklen) - sizeof(pcapng_stats_t);762 680 ifaceid = byteswap32(hdr->interfaceid); 763 681 timestamp = ((uint64_t)(byteswap32(hdr->timestamp_high)) << 32) + byteswap32(hdr->timestamp_low); 764 682 } else { 765 683 assert(hdr->blocktype == PCAPNG_INTERFACE_STATS_TYPE); 766 to_read = hdr->blocklen - sizeof(pcapng_stats_t);767 684 ifaceid = hdr->interfaceid; 768 685 timestamp = ((uint64_t)(hdr->timestamp_high) << 32) + 769 686 hdr->timestamp_low; 770 }771 772 bodyptr = packet->buffer + sizeof(pcapng_stats_t);773 err = pcapng_read_body(libtrace, bodyptr, to_read);774 if (err <= 0) {775 return err;776 687 } 777 688 … … 790 701 791 702 if (timestamp < interface->laststats) { 792 return sizeof(pcapng_stats_t) + to_read;703 return (int) blocklen; 793 704 } 794 705 … … 798 709 do { 799 710 optval = pcapng_parse_next_option(packet->trace, &bodyptr, 800 &optcode, &optlen );711 &optcode, &optlen, (pcapng_hdr_t *) packet->buffer); 801 712 if (optval == NULL) { 802 713 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 803 "Failed to read options for pcapng enhanced packet");714 "Failed to read options for pcapng interface stats"); 804 715 return -1; 805 716 } … … 844 755 interface->laststats = timestamp; 845 756 846 return sizeof(pcapng_stats_t) + to_read;757 return (int) blocklen; 847 758 848 759 } 849 760 850 761 static int pcapng_read_simple(libtrace_t *libtrace, libtrace_packet_t *packet, 851 uint32_t flags) { 852 853 int err; 854 uint32_t to_read; 762 uint32_t blocklen, uint32_t flags) { 763 855 764 uint32_t caplen; 856 765 pcapng_spkt_t *hdr = NULL; 857 766 pcapng_interface_t *interface; 858 char *bodyptr; 859 860 err = wandio_read(libtrace->io, packet->buffer, sizeof(pcapng_spkt_t)); 861 862 if (err < 0) { 863 trace_set_err(libtrace, TRACE_ERR_WANDIO_FAILED, "reading pcapng simple packet"); 864 return -1; 865 } 866 867 if (err == 0) { 868 return 0; 869 } 870 871 if (err < (int)sizeof(pcapng_spkt_t)) { 767 768 if (blocklen < sizeof(pcapng_spkt_t) + 4) { 872 769 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 873 770 "Incomplete pcapng simple packet header"); … … 880 777 if (DATA(libtrace)->byteswapped) { 881 778 assert(byteswap32(hdr->blocktype) == PCAPNG_SIMPLE_PACKET_TYPE); 882 to_read = byteswap32(hdr->blocklen) - sizeof(pcapng_spkt_t);883 caplen = to_read - 4;/* account for trailing length field */779 caplen = byteswap32(hdr->blocklen) - sizeof(pcapng_spkt_t) - 4; 780 /* account for trailing length field */ 884 781 } else { 885 782 assert(hdr->blocktype == PCAPNG_SIMPLE_PACKET_TYPE); 886 to_read = hdr->blocklen - sizeof(pcapng_spkt_t); 887 caplen = to_read - 4; /* account for trailing length field */ 888 } 889 890 bodyptr = packet->buffer + sizeof(pcapng_spkt_t); 891 err = pcapng_read_body(libtrace, bodyptr, to_read); 892 if (err <= 0) { 893 return err; 783 caplen = hdr->blocklen - sizeof(pcapng_spkt_t) - 4; 784 /* account for trailing length field */ 894 785 } 895 786 … … 911 802 return -1; 912 803 } 913 return sizeof(pcapng_spkt_t) + to_read;804 return (int) blocklen; 914 805 915 806 } 916 807 917 808 static int pcapng_read_enhanced(libtrace_t *libtrace, libtrace_packet_t *packet, 918 uint32_t flags) {809 uint32_t blocklen, uint32_t flags) { 919 810 pcapng_epkt_t *hdr = NULL; 920 int err;921 uint32_t to_read;922 811 uint32_t caplen; 923 812 uint32_t ifaceid; … … 927 816 char *bodyptr; 928 817 929 err = wandio_read(libtrace->io, packet->buffer, sizeof(pcapng_epkt_t)); 930 931 if (err < 0) { 932 trace_set_err(libtrace, TRACE_ERR_WANDIO_FAILED, "reading pcapng enhanced packet"); 933 return -1; 934 } 935 936 if (err == 0) { 937 return 0; 938 } 939 940 if (err < (int)sizeof(pcapng_epkt_t)) { 818 if (blocklen < (int)sizeof(pcapng_epkt_t) + 4) { 941 819 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 942 820 "Incomplete pcapng enhanced packet header"); … … 950 828 assert(byteswap32(hdr->blocktype) == PCAPNG_ENHANCED_PACKET_TYPE); 951 829 caplen = byteswap32(hdr->caplen); 952 to_read = byteswap32(hdr->blocklen) - sizeof(pcapng_epkt_t);953 830 ifaceid = byteswap32(hdr->interfaceid); 954 831 } else { 955 832 assert(hdr->blocktype == PCAPNG_ENHANCED_PACKET_TYPE); 956 833 caplen = hdr->caplen; 957 to_read = hdr->blocklen - sizeof(pcapng_epkt_t);958 834 ifaceid = hdr->interfaceid; 959 835 } 960 836 961 bodyptr = packet->buffer + sizeof(pcapng_epkt_t); 962 err = pcapng_read_body(libtrace, bodyptr, to_read); 963 if (err <= 0) { 964 return err; 965 } 837 bodyptr = (char *) packet->buffer + sizeof(pcapng_epkt_t); 966 838 967 839 /* Set packet type based on interface linktype */ … … 984 856 /* Make sure to parse any useful options */ 985 857 if ((caplen % 4) == 0) { 986 bodyptr = packet->payload + caplen; 987 } else { 988 bodyptr = packet->payload + caplen + (4 - (caplen % 4)); 858 bodyptr = (char *) packet->payload + caplen; 859 } else { 860 bodyptr = (char *) packet->payload + caplen + (4 - (caplen % 4)); 861 } 862 // Check the packet caplen actually fits within the block we read 863 if ((char *) packet->buffer + blocklen < bodyptr + 4) { 864 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 865 "Incomplete pcapng enhanced packet header"); 866 return -1; 989 867 } 990 868 991 869 do { 992 870 optval = pcapng_parse_next_option(packet->trace, &bodyptr, 993 &optcode, &optlen );871 &optcode, &optlen, (pcapng_hdr_t *) packet->buffer); 994 872 if (optval == NULL) { 995 873 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, … … 1008 886 1009 887 } while (optcode != 0); 1010 return sizeof(pcapng_epkt_t) + to_read;888 return (int) blocklen; 1011 889 1012 890 } … … 1052 930 } 1053 931 932 // Warning: the byteorder might not be set yet, the section header sets this 1054 933 if (DATA(libtrace)->byteswapped) { 1055 934 btype = byteswap32(peeker.blocktype); 935 to_read = byteswap32(peeker.blocklen); 1056 936 } else { 1057 937 btype = peeker.blocktype; 938 to_read = peeker.blocklen; 939 } 940 941 // Check we won't read off the end of the packet buffer. Assuming corruption. 942 // Exclude the SECTION header, as this is used to identify the byteorder 943 if (to_read > LIBTRACE_PACKET_BUFSIZE && btype != PCAPNG_SECTION_TYPE) { 944 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 945 "Oversized pcapng block found, is the trace corrupted?"); 946 return -1; 947 } 948 if (btype != PCAPNG_SECTION_TYPE) { 949 // Read the entire block, unless it is a section as our byte ordering has 950 // not been set yet. 951 err = pcapng_read_body(libtrace, packet->buffer, to_read); 952 if (err <= 0) { 953 return err; 954 } 955 if (*((uint32_t *)((char *)packet->buffer+to_read-4)) != peeker.blocklen) { 956 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 957 "Mismatched pcapng block sizes found, trace is invalid."); 958 return -1; 959 } 1058 960 } 1059 961 … … 1067 969 /* Interface Header */ 1068 970 case PCAPNG_INTERFACE_TYPE: 1069 err = pcapng_read_interface(libtrace, packet, flags);971 err = pcapng_read_interface(libtrace, packet, to_read, flags); 1070 972 gotpacket = 1; 1071 973 break; … … 1074 976 case PCAPNG_ENHANCED_PACKET_TYPE: 1075 977 err = pcapng_read_enhanced(libtrace, packet, 1076 flags);978 to_read, flags); 1077 979 gotpacket = 1; 1078 980 break; 1079 981 1080 982 case PCAPNG_SIMPLE_PACKET_TYPE: 1081 err = pcapng_read_simple(libtrace, packet, flags);983 err = pcapng_read_simple(libtrace, packet, to_read, flags); 1082 984 gotpacket = 1; 1083 985 break; 1084 986 1085 987 case PCAPNG_INTERFACE_STATS_TYPE: 1086 err = pcapng_read_stats(libtrace, packet, flags);988 err = pcapng_read_stats(libtrace, packet, to_read, flags); 1087 989 gotpacket = 1; 1088 990 break; 1089 991 1090 992 case PCAPNG_NAME_RESOLUTION_TYPE: 1091 err = pcapng_read_nrb(libtrace, packet, flags);993 err = pcapng_read_nrb(libtrace, packet, to_read, flags); 1092 994 gotpacket = 1; 1093 995 break; … … 1095 997 case PCAPNG_CUSTOM_TYPE: 1096 998 case PCAPNG_CUSTOM_NONCOPY_TYPE: 1097 err = pcapng_read_custom(libtrace, packet, flags);999 err = pcapng_read_custom(libtrace, packet, to_read, flags); 1098 1000 gotpacket = 1; 1099 1001 break; … … 1105 1007 /* Everything else -- don't care, skip it */ 1106 1008 default: 1107 if (DATA(libtrace)->byteswapped) {1108 to_read = byteswap32(peeker.blocklen);1109 } else {1110 to_read = peeker.blocklen;1111 }1112 err = skip_block(libtrace, to_read);1113 1009 break; 1114 1010 } … … 1194 1090 1195 1091 ts.tv_sec = (timestamp / interface->tsresol); 1196 ts.tv_nsec = (uint64_t)(timestamp - (ts.tv_sec * interface->tsresol)) / interface->tsresol * 1000000000; 1092 ts.tv_nsec = (uint64_t)(timestamp - (ts.tv_sec * interface->tsresol)) 1093 / ((double)interface->tsresol) * 1000000000; 1197 1094 1198 1095 return ts; … … 1468 1365 NULL, /* fin_packet */ 1469 1366 NULL, /* write_packet */ 1367 NULL, /* flush_output */ 1470 1368 pcapng_get_link_type, /* get_link_type */ 1471 1369 pcapng_get_direction, /* get_direction */ -
lib/format_rt.c
ree6e802 r32ee9b2 845 845 NULL, /* fin_packet */ 846 846 NULL, /* write_packet */ 847 NULL, /* flush_output */ 847 848 rt_get_link_type, /* get_link_type */ 848 849 NULL, /* get_direction */ -
lib/format_tsh.c
r2c457ec r32ee9b2 245 245 NULL, /* fin_packet */ 246 246 NULL, /* write_packet */ 247 NULL, /* flush_output */ 247 248 tsh_get_link_type, /* get_link_type */ 248 249 tsh_get_direction, /* get_direction */ … … 294 295 NULL, /* fin_packet */ 295 296 NULL, /* write_packet */ 297 NULL, /* flush_output */ 296 298 tsh_get_link_type, /* get_link_type */ 297 299 tsh_get_direction, /* get_direction */ -
lib/libtrace.h.in
r29cafc0 r47d4f8c 277 277 typedef struct trace_err_t{ 278 278 int err_num; /**< error code */ 279 char problem[ 255]; /**< the format, uri etc that caused the error for reporting purposes */279 char problem[1024]; /**< the format, uri etc that caused the error for reporting purposes */ 280 280 } libtrace_err_t; 281 281 … … 370 370 TRACE_TYPE_NONDATA = 19, /**< Not a data packet */ 371 371 TRACE_TYPE_OPENBSD_LOOP = 20, /**< OpenBSD loopback */ 372 TRACE_TYPE_ERF_META = 21 /**< ERF Provenance metadata record */ 372 TRACE_TYPE_ERF_META = 21, /**< ERF Provenance metadata record */ 373 TRACE_TYPE_ETSILI = 22 /**< ETSI Lawful Intercept */ 373 374 } libtrace_linktype_t; 374 375 … … 398 399 TRACE_FORMAT_NDAG =19, /**< DAG multicast over a network */ 399 400 TRACE_FORMAT_DPDK_NDAG =20, /**< DAG multicast over a network, received via DPDK */ 401 TRACE_FORMAT_ETSILIVE =21, /**< ETSI LI over a network */ 400 402 }; 401 403 … … 453 455 TRACE_RT_DATA_DPDK=TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_DPDK, 454 456 457 TRACE_RT_DATA_ETSILI = TRACE_RT_DATA_SIMPLE + TRACE_FORMAT_ETSILIVE, 458 455 459 /** As PCAP does not store the linktype with the packet, we need to 456 460 * create a separate RT type for each supported DLT, starting from … … 560 564 uint64_t internalid; /** Internal identifier for the pkt */ 561 565 void *srcbucket; 566 567 pthread_mutex_t ref_lock; /**< Lock for reference counter */ 568 int refcount; /**< Reference counter */ 569 562 570 } libtrace_packet_t; 563 571 … … 1312 1320 /** The hasher function for a parallel libtrace. It is recommended to 1313 1321 * access this option via trace_set_hasher(). */ 1314 TRACE_OPTION_HASHER 1322 TRACE_OPTION_HASHER, 1323 1324 /** Speed up trace file replays (via trace_event()) by this factor */ 1325 TRACE_OPTION_REPLAY_SPEEDUP, 1315 1326 } trace_option_t; 1316 1327 … … 1526 1537 DLLEXPORT void trace_destroy_output(libtrace_out_t *trace); 1527 1538 1539 /** Flush an output trace, forcing any buffered packets to be written 1540 * @param libtrace The output trace to be flushed 1541 */ 1542 DLLEXPORT int trace_flush_output(libtrace_out_t *libtrace); 1543 1528 1544 /** Check (and clear) the current error state of an input trace 1529 1545 * @param trace The input trace to check the error state on … … 1774 1790 */ 1775 1791 DLLEXPORT void trace_destroy_packet(libtrace_packet_t *packet); 1776 1777 1792 1778 1793 /** Read the next packet from an input trace -
lib/libtrace_int.h
re375e0f r823d8e1 99 99 #endif 100 100 101 #if ndef HAVE_STRNDUP101 #if !HAVE_DECL_STRNDUP 102 102 char *strndup(const char *s, size_t size); 103 103 #endif 104 104 105 #if ndef HAVE_STRNCASECMP105 #if !HAVE_DECL_STRNCASECMP 106 106 # ifndef HAVE__STRNICMP 107 107 /** A local implementation of strncasecmp (as some systems do not have it) */ … … 112 112 #endif 113 113 114 #if ndef HAVE_SNPRINTF114 #if !HAVE_DECL_SNPRINTF 115 115 # ifndef HAVE_SPRINTF_S 116 116 /** A local implementation of snprintf (as some systems do not have it) */ … … 152 152 //#define RP_BUFSIZE 65536U 153 153 154 #define LIBTRACE_MAX_REPLAY_SPEEDUP 1000 155 154 156 /** Data about the most recent event from a trace file */ 155 157 struct libtrace_event_status_t { 156 158 /** A libtrace packet to store the packet when a PACKET event occurs */ 157 159 libtrace_packet_t *packet; 158 /** Time between the timestamp for the current packet and the current 159 * walltime */ 160 double tdelta; 161 /** The timestamp of the previous PACKET event */ 162 double trace_last_ts; 160 161 /* The walltime when we processed the first packet from the trace */ 162 double first_now; 163 164 /* The tracetime of the first packet in the trace */ 165 double first_ts; 166 163 167 /** The size of the current PACKET event */ 164 168 int psize; … … 313 317 * used only if the capture format does not support snapping natively */ 314 318 size_t snaplen; 319 /** Speed up the packet rate when using trace_event() to process trace 320 * files by this factor. */ 321 int replayspeedup; 315 322 /** Count of the number of packets returned to the libtrace user */ 316 323 uint64_t accepted_packets; … … 617 624 */ 618 625 int (*write_packet)(libtrace_out_t *libtrace, libtrace_packet_t *packet); 626 627 /** Flush any buffered output for an output trace. 628 * 629 * @param libtrace The output trace to be flushed 630 */ 631 int (*flush_output)(libtrace_out_t *libtrace); 632 619 633 /** Returns the libtrace link type for a packet. 620 634 * … … 1242 1256 /** Constructor for the network DAG format module */ 1243 1257 void ndag_constructor(void); 1258 /** Constructor for the live ETSI over TCP format module */ 1259 void etsilive_constructor(void); 1244 1260 #ifdef HAVE_BPF 1245 1261 /** Constructor for the BPF format module */ -
lib/libtrace_parallel.h
r5c07bfe rc22a4bb 731 731 /** Set the maximum number of perpkt threads to use in a trace. 732 732 * 733 * Only valid on a new trace, that has not be started. Once started 734 * the number of threads cannot be changed without destroying the trace. 735 * 733 736 * @param[in] trace The parallel input trace 734 737 * @param[in] nb The number of threads to use. If set to 0, libtrace will … … 1271 1274 */ 1272 1275 DLLEXPORT void trace_free_packet(libtrace_t * libtrace, libtrace_packet_t * packet); 1276 1277 /** Increments the internal reference counter for a packet. 1278 * @param packet The packet opaque pointer 1279 * 1280 * You may wish to use this function (and its decrementing counterpart) 1281 * in situations where you are retaining multiple references to a packet 1282 * outside of the core packet processing function. This will ensure that 1283 * the packet is not released until there are no more outstanding references 1284 * to the packet anywhere in your program. 1285 */ 1286 DLLEXPORT void trace_increment_packet_refcount(libtrace_packet_t *packet); 1287 1288 /** Decrements the internal reference counter for a packet. 1289 * @param packet The packet opaque pointer 1290 * 1291 * If the reference counter goes below one, trace_fin_packet() will be 1292 * called on the packet. 1293 * 1294 * You may wish to use this function (and its incrementing counterpart) 1295 * in situations where you are retaining multiple references to a packet 1296 * outside of the core packet processing function. This will ensure that 1297 * the packet is not released until there are no more outstanding references 1298 * to the packet anywhere in your program. 1299 */ 1300 DLLEXPORT void trace_decrement_packet_refcount(libtrace_packet_t *packet); 1301 1273 1302 1274 1303 /** Provides some basic information about a trace based on its input format. -
lib/linktypes.c
ra857389 rb663d33 109 109 case TRACE_TYPE_METADATA: 110 110 case TRACE_TYPE_NONDATA: 111 case TRACE_TYPE_ETSILI: 111 112 break; 112 113 case TRACE_TYPE_UNKNOWN: … … 211 212 case TRACE_TYPE_NONDATA: 212 213 case TRACE_TYPE_OPENBSD_LOOP: 214 case TRACE_TYPE_ETSILI: 213 215 case TRACE_TYPE_UNKNOWN: 214 216 break; -
lib/protocols_l2.c
ra857389 rfa555ec 483 483 case TRACE_TYPE_PFLOG: 484 484 case TRACE_TYPE_ERF_META: 485 case TRACE_TYPE_ETSILI: 485 486 break; 486 487 case TRACE_TYPE_UNKNOWN: … … 519 520 case TRACE_TYPE_PFLOG: 520 521 case TRACE_TYPE_ERF_META: 522 case TRACE_TYPE_ETSILI: 521 523 break; 522 524 case TRACE_TYPE_UNKNOWN: … … 574 576 case TRACE_TYPE_PFLOG: 575 577 case TRACE_TYPE_LINUX_SLL: 578 case TRACE_TYPE_ETSILI: 576 579 return NULL; 577 580 … … 696 699 case TRACE_TYPE_80211_PRISM: 697 700 case TRACE_TYPE_80211_RADIO: 701 case TRACE_TYPE_ETSILI: 698 702 assert(!"Metadata headers should already be skipped"); 699 703 break; … … 746 750 case TRACE_TYPE_80211_PRISM: 747 751 case TRACE_TYPE_80211_RADIO: 752 case TRACE_TYPE_ETSILI: 748 753 assert(!"Metadata headers should already be skipped"); 749 754 break; -
lib/protocols_pktmeta.c
ra857389 r59b2ed8 28 28 #include "protocols.h" 29 29 #include <assert.h> 30 31 #ifdef HAVE_WANDDER 32 #include <libwandder_etsili.h> 33 #endif 30 34 31 35 /* This file contains all the protocol decoding functions for the meta-data … … 121 125 } 122 126 127 static void *trace_get_payload_from_etsili(const void *link, 128 libtrace_linktype_t *type, uint32_t *remaining) { 129 130 #ifdef HAVE_WANDDER 131 wandder_etsispec_t *dec; 132 uint8_t *ccptr; 133 134 /* XXX Bit annoying to be creating and freeing this every time */ 135 dec = wandder_create_etsili_decoder(); 136 wandder_attach_etsili_buffer(dec, (uint8_t *)link, *remaining, false); 137 ccptr = wandder_etsili_get_cc_contents(dec, remaining, NULL, 0); 138 /* Assuming all CCs are IP for now */ 139 *type = TRACE_TYPE_NONE; 140 wandder_free_etsili_decoder(dec); 141 return ccptr; 142 143 #else 144 (void)link; 145 (void)type; 146 *remaining = 0; 147 return NULL; 148 #endif 149 150 } 151 123 152 DLLEXPORT void *trace_get_packet_meta(const libtrace_packet_t *packet, 124 153 libtrace_linktype_t *linktype, … … 139 168 case TRACE_TYPE_80211_PRISM: 140 169 case TRACE_TYPE_ERF_META: 170 case TRACE_TYPE_ETSILI: 141 171 return pktbuf; 142 172 /* Non metadata packets */ … … 199 229 linktype, remaining); 200 230 return nexthdr; 231 case TRACE_TYPE_ETSILI: 232 nexthdr = trace_get_payload_from_etsili(meta, 233 linktype, remaining); 234 return nexthdr; 235 201 236 case TRACE_TYPE_HDLC_POS: 202 237 case TRACE_TYPE_ETH: -
lib/strndup.c
ree6e802 r823d8e1 24 24 * 25 25 */ 26 #ifndef HAVE_STRNDUP 26 #include "config.h" 27 #if !HAVE_DECL_STRNDUP 27 28 28 29 #include <stdlib.h> -
lib/trace.c
re375e0f r47d4f8c 107 107 * will use our own one that does 108 108 */ 109 static void xstrncpy(char *dest, const char *src, size_t n) 110 { 111 strncpy(dest,src,n); 112 dest[n]='\0'; 109 static inline void xstrncpy(char *dest, const char *src, size_t n, 110 size_t destlen) 111 { 112 size_t slen = destlen - 1; 113 if (n < slen) { 114 slen = n; 115 } 116 strncpy(dest,src,slen); 117 dest[slen]='\0'; 113 118 } 114 119 … … 120 125 exit(EXIT_FAILURE); 121 126 } 122 xstrncpy(ret,src,n );127 xstrncpy(ret,src,n,n+1); 123 128 return ret; 124 129 } … … 148 153 rt_constructor(); 149 154 ndag_constructor(); 155 #ifdef HAVE_WANDDER 156 etsilive_constructor(); 157 #endif 150 158 #ifdef HAVE_DAG 151 159 dag_constructor(); … … 248 256 libtrace->format=NULL; 249 257 250 libtrace->event.tdelta = 0.0;251 258 libtrace->event.packet = NULL; 252 259 libtrace->event.psize = 0; 253 libtrace->event.trace_last_ts = 0.0; 260 libtrace->event.first_ts = 0.0; 261 libtrace->event.first_now = 0.0; 254 262 libtrace->event.waiting = false; 255 263 libtrace->filter = NULL; 256 264 libtrace->snaplen = 0; 265 libtrace->replayspeedup = 1; 257 266 libtrace->started=false; 258 267 libtrace->uridata = NULL; … … 367 376 368 377 if((uridata = strchr(uri,':')) == NULL) { 369 xstrncpy(scan, uri, strlen(uri) );378 xstrncpy(scan, uri, strlen(uri), URI_PROTO_LINE); 370 379 } else { 371 xstrncpy(scan,uri, (size_t)(uridata - uri) );380 xstrncpy(scan,uri, (size_t)(uridata - uri), URI_PROTO_LINE); 372 381 } 373 382 … … 375 384 libtrace->format=NULL; 376 385 377 libtrace->event.tdelta = 0.0;378 386 libtrace->event.packet = NULL; 379 387 libtrace->event.psize = 0; 380 libtrace->event.trace_last_ts = 0.0; 388 libtrace->event.first_ts = 0; 389 libtrace->event.first_now = 0; 381 390 libtrace->filter = NULL; 382 391 libtrace->snaplen = 0; … … 592 601 * deal with some options itself, so give that a go */ 593 602 switch(option) { 603 case TRACE_OPTION_REPLAY_SPEEDUP: 604 /* Clear the error if there was one */ 605 if (trace_is_err(libtrace)) { 606 trace_get_err(libtrace); 607 } 608 if (*(int*)value<1 609 || *(int*)value>LIBTRACE_MAX_REPLAY_SPEEDUP) { 610 trace_set_err(libtrace,TRACE_ERR_BAD_STATE, 611 "Invalid replay speed"); 612 } 613 libtrace->replayspeedup=*(int*)value; 614 return 0; 615 594 616 case TRACE_OPTION_SNAPLEN: 595 617 /* Clear the error if there was one */ … … 724 746 libtrace_ocache_destroy(&libtrace->packet_freelist); 725 747 for (i = 0; i < libtrace->perpkt_thread_count; ++i) { 726 libtrace_message_queue_destroy(&libtrace->perpkt_threads[i].messages); 727 } 728 libtrace_message_queue_destroy(&libtrace->hasher_thread.messages); 729 libtrace_message_queue_destroy(&libtrace->keepalive_thread.messages); 730 libtrace_message_queue_destroy(&libtrace->reporter_thread.messages); 748 libtrace_message_queue_destroy(&libtrace->perpkt_threads[i].messages); 749 } 750 if (libtrace->hasher_thread.type == THREAD_HASHER) 751 libtrace_message_queue_destroy(&libtrace->hasher_thread.messages); 752 if (libtrace->keepalive_thread.type == THREAD_KEEPALIVE) 753 libtrace_message_queue_destroy(&libtrace->keepalive_thread.messages); 754 if (libtrace->reporter_thread.type == THREAD_REPORTER) 755 libtrace_message_queue_destroy(&libtrace->reporter_thread.messages); 731 756 732 757 … … 796 821 } 797 822 823 DLLEXPORT int trace_flush_output(libtrace_out_t *libtrace) { 824 if (!libtrace) { 825 return -1; 826 } 827 if (libtrace->format && libtrace->format->flush_output) { 828 return libtrace->format->flush_output(libtrace); 829 } 830 return 0; 831 } 832 798 833 DLLEXPORT libtrace_packet_t *trace_create_packet(void) 799 834 { … … 805 840 806 841 packet->buf_control=TRACE_CTRL_PACKET; 842 pthread_mutex_init(&(packet->ref_lock), NULL); 807 843 trace_clear_cache(packet); 808 844 return packet; … … 856 892 free(packet->buffer); 857 893 } 894 pthread_mutex_destroy(&(packet->ref_lock)); 858 895 packet->buf_control=(buf_control_t)'\0'; 859 896 /* A "bad" value to force an assert … … 1538 1575 trace_set_err(packet->trace, 1539 1576 TRACE_ERR_NO_CONVERSION, 1540 "pcap does not support this format");1577 "pcap does not support this linktype so cannot apply BPF filters"); 1541 1578 if (free_packet_needed) { 1542 1579 trace_destroy_packet(packet_copy); … … 2316 2353 packet->l3_remaining = 0; 2317 2354 packet->l4_remaining = 0; 2355 packet->refcount = 0; 2318 2356 2319 2357 } -
lib/trace_parallel.c
re375e0f rc95ef4a 690 690 if (!trace->pread) { 691 691 assert(packets[0]); 692 ASSERT_RET(pthread_mutex_lock(&trace->libtrace_lock), == 0);693 692 nb_packets = trace_read_packet(trace, packets[0]); 694 ASSERT_RET(pthread_mutex_unlock(&trace->libtrace_lock), == 0);695 693 packets[0]->error = nb_packets; 696 694 if (nb_packets > 0) … … 1048 1046 ASSERT_RET(pthread_spin_unlock(&libtrace->first_packets.lock), == 0); 1049 1047 1048 memset(&mesg, 0, sizeof(libtrace_message_t)); 1050 1049 mesg.code = MESSAGE_FIRST_PACKET; 1051 1050 trace_message_reporter(libtrace, &mesg); … … 1195 1194 1196 1195 gettimeofday(&prev, NULL); 1196 memset(&message, 0, sizeof(libtrace_message_t)); 1197 1197 message.code = MESSAGE_TICK_INTERVAL; 1198 1198 … … 1546 1546 const char *name) { 1547 1547 #ifdef __linux__ 1548 pthread_attr_t attrib;1549 1548 cpu_set_t cpus; 1550 1549 int i; … … 1564 1563 for (i = 0; i < get_nb_cores(); i++) 1565 1564 CPU_SET(i, &cpus); 1566 pthread_attr_init(&attrib); 1567 pthread_attr_setaffinity_np(&attrib, sizeof(cpus), &cpus); 1568 ret = pthread_create(&t->tid, &attrib, start_routine, (void *) trace); 1569 pthread_attr_destroy(&attrib); 1565 1566 ret = pthread_create(&t->tid, NULL, start_routine, (void *) trace); 1567 if( ret == 0 ) { 1568 ret = pthread_setaffinity_np(t->tid, sizeof(cpus), &cpus); 1569 } 1570 1570 1571 #else 1571 1572 ret = pthread_create(&t->tid, NULL, start_routine, (void *) trace); … … 2004 2005 } 2005 2006 if (!libtrace->started || libtrace->state != STATE_RUNNING) { 2007 ASSERT_RET(pthread_mutex_unlock(&libtrace->libtrace_lock), == 0); 2006 2008 trace_set_err(libtrace,TRACE_ERR_BAD_STATE, "You must call trace_start() before calling trace_ppause()"); 2007 2009 return -1; … … 2402 2404 2403 2405 DLLEXPORT int trace_set_perpkt_threads(libtrace_t *trace, int nb) { 2404 if (!trace_is_configurable(trace)) return -1; 2406 // Only supported on new traces not paused traces 2407 if (trace->state != STATE_NEW) return -1; 2405 2408 2406 2409 /* TODO consider allowing an offset from the total number of cores i.e. … … 2601 2604 } 2602 2605 2606 DLLEXPORT void trace_increment_packet_refcount(libtrace_packet_t *packet) { 2607 pthread_mutex_lock(&(packet->ref_lock)); 2608 if (packet->refcount < 0) { 2609 packet->refcount = 1; 2610 } else { 2611 packet->refcount ++; 2612 } 2613 pthread_mutex_unlock(&(packet->ref_lock)); 2614 } 2615 2616 DLLEXPORT void trace_decrement_packet_refcount(libtrace_packet_t *packet) { 2617 pthread_mutex_lock(&(packet->ref_lock)); 2618 packet->refcount --; 2619 2620 if (packet->refcount <= 0) { 2621 trace_free_packet(packet->trace, packet); 2622 } 2623 pthread_mutex_unlock(&(packet->ref_lock)); 2624 } 2625 2626 2603 2627 DLLEXPORT libtrace_info_t *trace_get_information(libtrace_t * libtrace) { 2604 2628 if (libtrace->format) -
libpacketdump/Makefile.am
r3a333e2 r055a2c9 60 60 # 17: PPP 61 61 TXT_PROTOCOLS+=link_17.protocol 62 63 # 22: ETSI LI 64 if HAVE_WANDDER 65 BIN_PROTOCOLS+=link_22.la 66 endif 62 67 63 68 # Decoders for various ethertypes (in decimal) … … 135 140 link_11_la_LDFLAGS=$(modflags) 136 141 link_15_la_LDFLAGS=$(modflags) 142 if HAVE_WANDDER 143 link_22_la_LDFLAGS=$(modflags) 144 endif 137 145 eth_0_la_LDFLAGS=$(modflags) 138 146 eth_2048_la_LDFLAGS=$(modflags) -
libpacketdump/eth_2054.c
ree6e802 r47d4f8c 47 47 static char *format_hrd(const struct arphdr *arp, const char *hrd) { 48 48 static char buffer[1024] = {0,}; 49 int i; 49 int i, ret; 50 size_t bufused; 50 51 51 52 if (!hrd) { … … 59 60 break; 60 61 default: 62 bufused = 0; 61 63 for (i=0;i<arp->ar_hln;i++) { 62 snprintf(buffer,sizeof(buffer),"%s %02x", 63 buffer,(unsigned char)hrd[i]); 64 if (bufused >= sizeof(buffer)) { 65 break; 66 } 67 ret = snprintf(buffer + bufused, 68 sizeof(buffer) - bufused, 69 "%02x ", 70 (unsigned char)hrd[i]); 71 if (ret > 0) { 72 bufused += ret; 73 } 64 74 } 65 75 break; … … 77 87 static char *format_pro(const struct arphdr *arp, const char *pro) { 78 88 static char buffer[1024] = {0,}; 79 int i; 89 int i, ret; 90 size_t bufused; 80 91 81 92 if (!pro) { … … 91 102 default: 92 103 snprintf(buffer, sizeof(buffer), "%s", " ("); 104 bufused = 2; 93 105 for (i=0;i<arp->ar_pln;i++) { 94 snprintf(buffer,sizeof(buffer),"%s %02x", 95 buffer,(unsigned char)pro[i]); 106 if (bufused >= sizeof(buffer)) { 107 break; 108 } 109 ret = snprintf(buffer + bufused, 110 sizeof(buffer) - bufused, 111 "%02x ", 112 (unsigned char)pro[i]); 113 if (ret > 0) { 114 bufused += ret; 115 } 96 116 } 97 strncat(buffer,")",sizeof(buffer) - strlen(buffer) - 1); 117 if (bufused < sizeof(buffer)) { 118 snprintf(buffer + bufused, 119 sizeof(buffer) - bufused, 120 ")"); 121 } 98 122 break; 99 123 } -
test/do-test-build-dpdk.sh
rcaf7841 r6d17620 23 23 } 24 24 25 # Versions to check25 # Old kernel version jessie 3.16 26 26 declare -a dpdk_versions=( 27 27 "dpdk-1.7.1.tar.gz" … … 31 31 "dpdk-2.2.0.tar.gz" 32 32 "dpdk-16.04.tar.gz" 33 "dpdk-16.07. tar.gz"34 "dpdk-16.11. tar.gz"33 "dpdk-16.07.2.tar.gz" 34 "dpdk-16.11.6.tar.gz" 35 35 ) 36 # Versions to check stretch linux 4.9 37 declare -a dpdk_versions=( 38 "dpdk-2.2.0.tar.gz" 39 "dpdk-16.04.tar.gz" 40 "dpdk-16.07.2.tar.gz" 41 "dpdk-16.11.6.tar.gz" 42 "dpdk-17.02.1.tar.gz" 43 "dpdk-17.05.2.tar.gz" 44 "dpdk-17.08.2.tar.gz" 45 "dpdk-17.11.2.tar.gz" 46 "dpdk-18.02.1.tar.gz" 47 ) 48 36 49 37 50 mkdir "$DOWNLOAD_DIR" > /dev/null 2>&1 … … 60 73 # Build the DPDK libraries 61 74 # We try to not overwrite these, so that a rebuild is faster 75 # We build DPDK without KNI, as most kernel dependent code is there 76 # - also excluding makes the build faster 77 # We also disable error on warning, to improve forwards compiler compatibility 62 78 cd "$DOWNLOAD_DIR" 63 79 for dpdk_build in $(ls -d */) … … 67 83 do_test make install T=x86_64-native-linuxapp-gcc \ 68 84 CONFIG_RTE_BUILD_COMBINE_LIBS=y \ 69 EXTRA_CFLAGS="-fPIC" -j $BUILD_THREADS \ 85 CONFIG_RTE_LIBRTE_KNI=n \ 86 CONFIG_RTE_KNI_KMOD=n \ 87 EXTRA_CFLAGS="-fPIC -w" -j $BUILD_THREADS \ 70 88 > build_stdout.txt 2> build_stderr.txt 71 89 cd .. -
tools/traceanon/traceanon.1
r5765044 r264f286c 101 101 .BI \-\^\-compress-type=method 102 102 compress the output trace using the compression algorithm "method". Possible 103 algorithms are "gz ip", "bzip2", "lzo", "xz" and "none". Default is "none".103 algorithms are "gz", "bz", "lzo", "xz" and "no". Default is "no". 104 104 105 105 .TP -
tools/tracemerge/tracemerge.1
r17f954f r264f286c 53 53 .BI \-\^\-compress-type method 54 54 Describes the compression algorithm to be used when writing the output trace. 55 Possible methods are "gz ip", "bzip2", "lzo", "xz" and "none". Defaults to56 "no ne".55 Possible methods are "gz", "bz", "lzo", "xz" and "no". Defaults to 56 "no". 57 57 58 58 -
tools/tracepktdump/tracepktdump.cc
ree6e802 rf35a853 113 113 /* Ignore RT messages */ 114 114 continue; 115 if (trace_is_err(trace)) { 116 break; 117 } 115 118 trace_dump_packet(packet); 116 119 -
tools/tracereplay/tracereplay.1
rd6dc0f6 r1e0a804 4 4 .SH SYNOPSIS 5 5 .B tracereplay 6 [\-b | \-\^\-broadcast] [-s \-\^\-snaplength [ snaplength] ] 7 [\-f | \-\^\-filter [ filter string ] ] 6 [\-b | \-\^\-broadcast] [-s \-\^\-snaplength [ snaplength] ] 7 [\-f | \-\^\-filter [ filter string ] ] [\-X | \-\^\-speedup [ factor] ] 8 8 inputuri outputuri 9 9 .SH DESCRPTION … … 23 23 .TP 24 24 .PD 0 25 .BI \-s [snaplength]25 .BI \-s " snaplength" 26 26 .TP 27 27 .PD 28 .BI \-\^\-snaplength [snaplength]28 .BI \-\^\-snaplength " snaplength" 29 29 Truncate the packets to the length specified. This only makes a difference 30 30 if the inputuri is a capture device. The value should be > 0. Inappropriate … … 33 33 .TP 34 34 .PD 0 35 .BI \-f [ filter string ]35 .BI \-f " filterstring" 36 36 .TP 37 37 .PD 38 .BI \-\^\-filter [ filter ]38 .BI \-\^\-filter " filterstring" 39 39 Apply a filter to the inputuri. 40 41 .TP 42 .PD 0 43 .BI \-X " factor" 44 .TP 45 .PD 46 .BI \-\^\-speedup " factor" 47 Decrease the gaps between packets by the specified factor. This will accelerate 48 the rate at which the replay is performed. By default, the factor is 1 (i.e. 49 no acceleration). 40 50 41 51 .SH LINKS -
tools/tracereplay/tracereplay.c
r8e11beb r1e0a804 98 98 if (IS_LIBTRACE_META_PACKET(packet)) 99 99 return NULL; 100 if (trace_get_wire_length(packet) == 0) 101 return NULL; 100 102 101 103 pkt_buffer = trace_get_packet_buffer(packet,&linktype,&remaining); … … 194 196 fprintf(stderr, " --broadcast\n"); 195 197 fprintf(stderr, "\t\tSend ethernet frames to broadcast address\n"); 198 fprintf(stderr, " -X\n"); 199 fprintf(stderr, " --speedup\n"); 200 fprintf(stderr, "\t\tSpeed up replay by a factor of <speedup>\n"); 196 201 197 202 } … … 207 212 libtrace_packet_t * new; 208 213 int snaplen = 0; 214 int speedup = 1; 209 215 210 216 … … 216 222 { "snaplen", 1, 0, 's'}, 217 223 { "broadcast", 0, 0, 'b'}, 224 { "speedup", 1, 0, 'X'}, 218 225 { NULL, 0, 0, 0} 219 226 }; 220 227 221 int c = getopt_long(argc, argv, "bhs:f: ",228 int c = getopt_long(argc, argv, "bhs:f:X:", 222 229 long_options, &option_index); 223 230 … … 232 239 snaplen = atoi(optarg); 233 240 break; 234 241 case 'X': 242 speedup = atoi(optarg); 243 break; 235 244 case 'b': 236 245 broadcast = 1; … … 257 266 } 258 267 268 if (speedup < 1) { 269 speedup = 1; 270 } 271 259 272 uri = strdup(argv[optind]); 260 273 … … 279 292 } 280 293 } 294 295 if (trace_config(trace, TRACE_OPTION_REPLAY_SPEEDUP, &speedup)) { 296 trace_perror(trace, "error setting replay speedup factor"); 297 return 1; 298 } 281 299 282 300 /* Starting the trace */ -
tools/tracereport/misc_report.c
r8e11beb r47d4f8c 67 67 { 68 68 static char ret[1024]; 69 char tmp[1 024];69 char tmp[128]; 70 70 ret[0]='\0'; 71 71 if (ts == 0) -
tools/tracesplit/tracesplit.1
r7affaae r264f286c 69 69 \fB-Z\fR compression-method 70 70 Compress the data using the specified compression algorithm. Accepted methods 71 are "gz ip", "bzip2", "lzo", "xz" or "none". Default value is noneunless a71 are "gz", "bz", "lzo", "xz" or "no". Default value is "no" unless a 72 72 compression level is specified, in which case gzip will be used. 73 73 -
tools/tracesplit/tracesplit.c
r92cf299 r47d4f8c 61 61 static char *strdupcat(char *str,char *app) 62 62 { 63 str=realloc(str,strlen(str)+strlen(app)+1); 64 strncat(str,app,strlen(str) + strlen(app)); 63 int newsize = strlen(str)+strlen(app)+1; 64 str=realloc(str,newsize); 65 strncat(str,app,newsize - strlen(str) - 1); 65 66 return str; 66 67 }
Note: See TracChangeset
for help on using the changeset viewer.