- Timestamp:
- 09/19/14 15:40:01 (8 years ago)
- 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:
- 11cf9b1
- Parents:
- d994324 (diff), ea602cd (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. - Location:
- lib
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/Makefile.am
r2498008 r9e429e8 18 18 DAGSOURCE= 19 19 endif 20 EXTRA_DIST=format_dag24.c format_dag25.c 20 EXTRA_DIST=format_dag24.c format_dag25.c dpdk_libtrace.mk 21 21 22 22 if HAVE_LLVM -
lib/format_bpf.c
r10e183f r9e429e8 422 422 packet->payload=(char *)buffer + BPFHDR(packet)->bh_hdrlen; 423 423 424 /*425 if (libtrace->format_data == NULL) {426 if (bpf_init_input(libtrace))427 return -1;428 }429 */430 431 424 return 0; 432 425 } … … 439 432 { 440 433 uint32_t flags = 0; 434 fd_set readfds; 435 struct timeval tout; 436 int ret; 441 437 442 438 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 } 443 481 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 467 482 /* We do NOT want anything trying to free the memory the packet is 468 483 * stored in */ -
lib/format_dag24.c
rb13b939 r9e429e8 473 473 } else { 474 474 /* Do not sleep - try to read another packet */ 475 trace->filtered_packets ++; 475 476 continue; 476 477 } … … 483 484 trace_set_capture_length(packet, trace->snaplen); 484 485 } 485 486 trace->accepted_packets ++; 486 487 return event; 487 488 } while (1); -
lib/format_dag25.c
rb13b939 r9e429e8 586 586 587 587 zero.tv_sec = 0; 588 zero.tv_usec = 0;588 zero.tv_usec = 10000; 589 589 nopoll = zero; 590 590 … … 992 992 /* Flags. Can't do this */ 993 993 memset(&erfhdr.flags,1,sizeof(erfhdr.flags)); 994 if (trace_get_direction(packet)!= ~0U)994 if (trace_get_direction(packet)!=(int)~0U) 995 995 erfhdr.flags.iface = trace_get_direction(packet); 996 996 … … 1035 1035 int numbytes = 0; 1036 1036 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; 1037 1044 1038 1045 /* Check if we're due for a DUCK report */ … … 1057 1064 packet->buffer = 0; 1058 1065 } 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 1059 1075 1060 1076 /* Grab a full ERF record */ … … 1063 1079 if (numbytes < 0) 1064 1080 return numbytes; 1065 if (numbytes < dag_record_size) 1081 if (numbytes < dag_record_size) { 1082 if (libtrace_halt) 1083 return 0; 1066 1084 /* Block until we see a packet */ 1067 1085 continue; 1086 } 1068 1087 erfptr = dag_get_record(libtrace); 1069 1088 } while (erfptr == NULL); … … 1086 1105 * return a SLEEP event (as we cannot select on the DAG file descriptor). 1087 1106 */ 1088 static libtrace_eventobj_t trace_event_dag(libtrace_t * trace,1107 static libtrace_eventobj_t trace_event_dag(libtrace_t *libtrace, 1089 1108 libtrace_packet_t *packet) { 1090 1109 libtrace_eventobj_t event = {0,0,0.0,0}; … … 1092 1111 int numbytes; 1093 1112 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 } 1094 1126 1095 1127 do { … … 1099 1131 /* Need to call dag_available so that the top pointer will get 1100 1132 * updated, otherwise we'll never see any data! */ 1101 numbytes = dag_available( trace);1133 numbytes = dag_available(libtrace); 1102 1134 1103 1135 /* May as well not bother calling dag_get_record if 1104 1136 * dag_available suggests that there's no data */ 1105 1137 if (numbytes != 0) 1106 erfptr = dag_get_record( trace);1138 erfptr = dag_get_record(libtrace); 1107 1139 if (erfptr == NULL) { 1108 1140 /* 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 } 1111 1147 break; 1112 1148 } 1113 if (dag_prepare_packet( trace, packet, erfptr,1149 if (dag_prepare_packet(libtrace, packet, erfptr, 1114 1150 TRACE_RT_DATA_ERF, flags)) { 1115 1151 event.type = TRACE_EVENT_TERMINATE; … … 1125 1161 * trace_event() so we have to do it ourselves */ 1126 1162 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) { 1131 1174 /* This packet isn't useful so we want to 1132 1175 * immediately see if there is another suitable … … 1134 1177 * a sleep event in this case, like we used to 1135 1178 * do! */ 1179 libtrace->filtered_packets ++; 1136 1180 trace_clear_cache(packet); 1137 1181 continue; 1138 1182 } 1183 1184 event.type = TRACE_EVENT_PACKET; 1139 1185 } else { 1140 1186 event.type = TRACE_EVENT_PACKET; 1141 1187 } 1142 1188 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); 1145 1191 } 1192 libtrace->accepted_packets ++; 1146 1193 break; 1147 1194 } while (1); -
lib/format_dpdk.c
r50ce607 r9e429e8 60 60 #include <unistd.h> 61 61 #include <endian.h> 62 #include <string.h> 63 64 /* We can deal with any minor differences by checking the RTE VERSION 65 * Typically DPDK backports some fixes (typically for building against 66 * newer kernels) to the older version of DPDK. 67 * 68 * These get released with the rX suffix. The following macros where added 69 * in these new releases. 70 * 71 * Below this is a log of version that required changes to the libtrace 72 * code (that we still attempt to support). 73 * 74 * Currently 1.5 to 1.7 is supported. 75 */ 62 76 #include <rte_eal.h> 77 #include <rte_version.h> 78 #ifndef RTE_VERSION_NUM 79 # define RTE_VERSION_NUM(a,b,c,d) ((a) << 24 | (b) << 16 | (c) << 8 | (d)) 80 #endif 81 #ifndef RTE_VER_PATCH_RELEASE 82 # define RTE_VER_PATCH_RELEASE 0 83 #endif 84 #ifndef RTE_VERSION 85 # define RTE_VERSION RTE_VERSION_NUM(RTE_VER_MAJOR,RTE_VER_MINOR, \ 86 RTE_VER_PATCH_LEVEL, RTE_VER_PATCH_RELEASE) 87 #endif 88 89 /* 1.6.0r2 : 90 * rte_eal_pci_set_blacklist() is removed 91 * device_list is renamed ot pci_device_list 92 * 93 * Replaced by: 94 * rte_devargs (we can simply whitelist) 95 */ 96 #if RTE_VERSION <= RTE_VERSION_NUM(1, 6, 0, 1) 97 # define DPDK_USE_BLACKLIST 1 98 #else 99 # define DPDK_USE_BLACKLIST 0 100 #endif 101 102 /* 103 * 1.7.0 : 104 * rte_pmd_init_all is removed 105 * 106 * Replaced by: 107 * Nothing, no longer needed 108 */ 109 #if RTE_VERSION < RTE_VERSION_NUM(1, 7, 0, 0) 110 # define DPDK_USE_PMD_INIT 1 111 #else 112 # define DPDK_USE_PMD_INIT 0 113 #endif 114 63 115 #include <rte_per_lcore.h> 64 116 #include <rte_debug.h> … … 207 259 int nb_tx_buf; /* The number of packet buffers in the tx ring */ 208 260 struct rte_mempool * pktmbuf_pool; /* Our packet memory pool */ 261 #if DPDK_USE_BLACKLIST 209 262 struct rte_pci_addr blacklist[BLACK_LIST_SIZE]; /* Holds our device blacklist */ 263 unsigned int nb_blacklist; /* Number of blacklist items in are valid */ 264 #endif 210 265 char mempool_name[MEMPOOL_NAME_LEN]; /* The name of the mempool that we are using */ 211 unsigned int nb_blacklist; /* Number of blacklist items in are valid */212 266 uint8_t rss_key[40]; // This is the RSS KEY 213 267 #if HAS_HW_TIMESTAMPS_82580 … … 262 316 * So blacklist all devices except the one that we wish to use so that 263 317 * the others can still be used as standard ethernet ports. 264 */ 265 static void blacklist_devices(struct dpdk_format_data_t *format_data, struct rte_pci_addr *whitelist) 318 * 319 * @return 0 if successful, otherwise -1 on error. 320 */ 321 #if DPDK_USE_BLACKLIST 322 static int blacklist_devices(struct dpdk_format_data_t *format_data, struct rte_pci_addr *whitelist) 266 323 { 267 324 struct rte_pci_device *dev = NULL; … … 287 344 288 345 rte_eal_pci_set_blacklist(format_data->blacklist, format_data->nb_blacklist); 289 } 346 return 0; 347 } 348 #else /* DPDK_USE_BLACKLIST */ 349 #include <rte_devargs.h> 350 static int blacklist_devices(struct dpdk_format_data_t *format_data UNUSED, struct rte_pci_addr *whitelist) 351 { 352 char pci_str[20] = {0}; 353 snprintf(pci_str, sizeof(pci_str), PCI_PRI_FMT, 354 whitelist->domain, 355 whitelist->bus, 356 whitelist->devid, 357 whitelist->function); 358 if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, pci_str) < 0) { 359 return -1; 360 } 361 return 0; 362 } 363 #endif 290 364 291 365 /** … … 441 515 442 516 443 static inline int dpdk_init_enviroment(char * uridata, struct dpdk_format_data_t * format_data, 517 /** 518 * XXX This is very bad XXX 519 * But we have to do something to allow getopts nesting 520 * Luckly normally the format is last so it doesn't matter 521 * DPDK only supports modern systems so hopefully this 522 * will continue to work 523 */ 524 struct saved_getopts { 525 char *optarg; 526 int optind; 527 int opterr; 528 int optopt; 529 }; 530 531 static void save_getopts(struct saved_getopts *opts) { 532 opts->optarg = optarg; 533 opts->optind = optind; 534 opts->opterr = opterr; 535 opts->optopt = optopt; 536 } 537 538 static void restore_getopts(struct saved_getopts *opts) { 539 optarg = opts->optarg; 540 optind = opts->optind; 541 opterr = opts->opterr; 542 optopt = opts->optopt; 543 } 544 545 static inline int dpdk_init_environment(char * uridata, struct dpdk_format_data_t * format_data, 444 546 char * err, int errlen) { 445 547 int ret; /* Returned error codes */ … … 451 553 int i; 452 554 struct rte_config *cfg = rte_eal_get_configuration(); 555 struct saved_getopts save_opts; 453 556 454 557 #if DEBUG … … 457 560 rte_set_log_level(RTE_LOG_WARNING); 458 561 #endif 459 /* Using proc-type auto allows this to be either primary or secondary 460 * Secondary allows two instances of libtrace to be used on different 461 * ports. However current version of DPDK doesn't support this on the 462 * same card (My understanding is this should work with two separate 463 * cards). 562 /* 563 * Using unique file prefixes mean separate memory is used, unlinking 564 * the two processes. However be careful we still cannot access a 565 * port that already in use. 464 566 * 465 567 * Using unique file prefixes mean separate memory is used, unlinking … … 518 620 //snprintf(cpu_number, sizeof(cpu_number), "%x", 0x1 << (my_cpu - 1)); 519 621 520 /* Give this a name */ 622 623 /* Give the memory map a unique name */ 521 624 snprintf(mem_map, sizeof(mem_map), "libtrace-%d", (int) getpid()); 522 625 /* rte_eal_init it makes a call to getopt so we need to reset the 523 626 * global optind variable of getopt otherwise this fails */ 627 save_getopts(&save_opts); 524 628 optind = 1; 525 629 if ((ret = rte_eal_init(argc, argv)) < 0) { … … 528 632 return -1; 529 633 } 530 634 restore_getopts(&save_opts); 531 635 // These are still running but will never do anything with DPDK v1.7 we 532 636 // should remove this XXX in the future … … 545 649 dump_configuration(); 546 650 #endif 651 652 #if DPDK_USE_PMD_INIT 547 653 /* This registers all available NICs with Intel DPDK 548 654 * These are not loaded until rte_eal_pci_probe() is called. … … 553 659 return -1; 554 660 } 661 #endif 555 662 556 663 /* Black list all ports besides the one that we want to use */ 557 blacklist_devices(format_data, &use_addr); 664 if ((ret = blacklist_devices(format_data, &use_addr)) < 0) { 665 snprintf(err, errlen, "Intel DPDK - Whitelisting PCI device failed," 666 " are you sure the address is correct?: %s", strerror(-ret)); 667 return -1; 668 } 558 669 559 670 /* This loads DPDK drivers against all ports that are not blacklisted */ … … 595 706 FORMAT(libtrace)->promisc = -1; 596 707 FORMAT(libtrace)->pktmbuf_pool = NULL; 708 #if DPDK_USE_BLACKLIST 597 709 FORMAT(libtrace)->nb_blacklist = 0; 710 #endif 598 711 FORMAT(libtrace)->paused = DPDK_NEVER_STARTED; 599 712 FORMAT(libtrace)->mempool_name[0] = 0; … … 604 717 #endif 605 718 606 if (dpdk_init_enviro ment(libtrace->uridata, FORMAT(libtrace), err, sizeof(err)) != 0) {719 if (dpdk_init_environment(libtrace->uridata, FORMAT(libtrace), err, sizeof(err)) != 0) { 607 720 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "%s", err); 608 721 free(libtrace->format_data); … … 628 741 FORMAT(libtrace)->promisc = -1; 629 742 FORMAT(libtrace)->pktmbuf_pool = NULL; 743 #if DPDK_USE_BLACKLIST 630 744 FORMAT(libtrace)->nb_blacklist = 0; 745 #endif 631 746 FORMAT(libtrace)->paused = DPDK_NEVER_STARTED; 632 747 FORMAT(libtrace)->mempool_name[0] = 0; … … 637 752 #endif 638 753 639 if (dpdk_init_enviro ment(libtrace->uridata, FORMAT(libtrace), err, sizeof(err)) != 0) {754 if (dpdk_init_environment(libtrace->uridata, FORMAT(libtrace), err, sizeof(err)) != 0) { 640 755 trace_set_err_out(libtrace, TRACE_ERR_INIT_FAILED, "%s", err); 641 756 free(libtrace->format_data); … … 815 930 816 931 /* First time started we need to alloc our memory, doing this here 817 * rather than in enviro ment setup because we don't have snaplen then */932 * rather than in environment setup because we don't have snaplen then */ 818 933 if (format_data->paused == DPDK_NEVER_STARTED) { 819 934 if (format_data->snaplen == 0) { … … 1807 1922 if (!trace_apply_filter(trace->filter, packet)) { 1808 1923 /* Failed the filter so we loop for another packet */ 1924 trace->filtered_packets ++; 1809 1925 continue; 1810 1926 } 1811 1927 } 1928 trace->accepted_packets ++; 1812 1929 } else { 1813 1930 /* We only want to sleep for a very short time - we are non-blocking */ -
lib/format_erf.c
rb13b939 r9e429e8 746 746 * we just need to read and return the next packet in the trace */ 747 747 if (IN_OPTIONS.real_time) { 748 event.size = erf_read_packet(libtrace, packet);748 event.size = trace_read_packet(libtrace, packet); 749 749 if (event.size < 1) 750 750 event.type = TRACE_EVENT_TERMINATE; -
lib/format_helper.c
r74ecbc7 r4649fea 98 98 * solution. */ 99 99 100 100 do { 101 101 tv.tv_sec = 0; 102 102 tv.tv_usec = 0; … … 111 111 112 112 if (FD_ISSET(event.fd, &rfds_param)) { 113 event.size = trace_read_packet(trace,packet); 114 113 event.size = trace_read_packet(trace,packet); 115 114 if (event.size < 1) { 116 115 /* Covers error and EOF events - terminate rather -
lib/format_linux.c
r2498008 r9e429e8 546 546 */ 547 547 if (filter != NULL) { 548 assert(filter->flag == 1); 548 /* Check if the filter was successfully compiled. If not, 549 * it is probably a bad filter and we should return an error 550 * before the caller tries to read any packets */ 551 if (filter->flag == 0) { 552 return -1; 553 } 554 549 555 if (setsockopt(FORMAT(libtrace->format_data)->fd, 550 556 SOL_SOCKET, … … 902 908 903 909 if (pcap_compile(pcap, &f->filter, f->filterstring, 0, 0) == -1) { 904 perror("PCAP failed to compile the filterstring"); 905 return -1; 910 /* Filter didn't compile, set flag to 0 so we can 911 * detect this when trace_start() is called and 912 * produce a useful error 913 */ 914 f->flag = 0; 915 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, 916 "Failed to compile BPF filter (%s): %s", 917 f->filterstring, pcap_geterr(pcap)); 918 } else { 919 /* Set the "flag" to indicate that the filterstring 920 * has been compiled 921 */ 922 f->flag = 1; 906 923 } 907 924 908 925 pcap_close(pcap); 909 926 910 /* Set the "flag" to indicate that the filterstring has been911 * compiled912 */913 f->flag = 1;914 927 } 915 928 … … 1072 1085 1073 1086 uint32_t flags = 0; 1087 fd_set readfds; 1088 struct timeval tout; 1089 int ret; 1074 1090 1075 1091 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { … … 1118 1134 FD_SET(get_thread_table(libtrace)->messages.pipefd[0], &rfds); 1119 1135 int largestfd = fd > get_thread_table(libtrace)->messages.pipefd[0] ? fd : get_thread_table(libtrace)->messages.pipefd[0]; 1120 1121 1136 do { 1122 1137 ret = select(largestfd+1, &rfds, NULL, NULL, NULL); … … 1136 1151 } 1137 1152 } else { 1138 hdr->wirelen = recvmsg(fd, &msghdr, MSG_TRUNC); 1139 } 1153 /* Use select to allow us to time out occasionally to check if someone 1154 * has hit Ctrl-C or otherwise wants us to stop reading and return 1155 * so they can exit their program. 1156 */ 1157 1158 while (1) { 1159 tout.tv_sec = 0; 1160 tout.tv_usec = 500000; 1161 FD_ZERO(&readfds); 1162 FD_SET(FORMAT(libtrace->format_data)->fd, &readfds); 1163 1164 ret = select(FORMAT(libtrace->format_data)->fd + 1, &readfds, 1165 NULL, NULL, &tout); 1166 if (ret < 0 && errno != EINTR) { 1167 trace_set_err(libtrace, errno, "select"); 1168 return -1; 1169 } else if (ret < 0) { 1170 continue; 1171 } 1172 1173 if (FD_ISSET(FORMAT(libtrace->format_data)->fd, &readfds)) { 1174 /* There's something available for us to read */ 1175 break; 1176 } 1177 1178 1179 /* If we get here, we timed out -- check if we should halt */ 1180 if (libtrace_halt) 1181 return 0; 1182 } 1183 hdr->wirelen = recvmsg(FORMAT(libtrace->format_data)->fd, &msghdr, MSG_TRUNC); 1184 } 1185 1186 1187 1140 1188 1141 1189 if (hdr->wirelen==~0U) { … … 1288 1336 assert((((unsigned long) header) & (pagesize - 1)) == 0); 1289 1337 1290 /* TP_STATUS_USER means that we can use the frame. 1291 * When a slot does not have this flag set, the frame is not 1292 * ready for consumption. 1293 */ 1294 while (!(header->tp_status & TP_STATUS_USER)) { 1338 while (1) { 1295 1339 if (message) { 1296 1340 struct pollfd pollset[2]; … … 1318 1362 1319 1363 /* Wait for more data or a message*/ 1320 ret = poll(&pollset, 1, -1);1364 ret = poll(&pollset, 1, 500); 1321 1365 if (ret < 0) { 1322 1366 if (errno != EINTR) 1323 1367 trace_set_err(libtrace,errno,"poll()"); 1324 1368 return -1; 1325 } 1369 } else if (ret == 0) { 1370 /* Poll timed out - check if we should exit */ 1371 if (libtrace_halt) 1372 return 0; 1373 continue; 1374 } 1375 1376 /* TP_STATUS_USER means that we can use the frame. 1377 * When a slot does not have this flag set, the frame is not 1378 * ready for consumption. 1379 */ 1380 if (header->tp_status & TP_STATUS_USER) 1381 break; 1326 1382 } 1327 1383 } … … 1380 1436 if(header->tp_status & TP_STATUS_USER){ 1381 1437 /* We have a frame waiting */ 1382 event.size = linuxring_read_packet(libtrace, packet);1438 event.size = trace_read_packet(libtrace, packet); 1383 1439 event.type = TRACE_EVENT_PACKET; 1384 1440 } else { -
lib/format_pcap.c
r17c5749 r9e429e8 295 295 } 296 296 #endif 297 #ifdef HAVE_PCAP_SETNONBLOCK 298 pcap_setnonblock(INPUT.pcap,0,errbuf); 299 #endif 297 300 /* Set a filter if one is defined */ 298 301 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) { 300 307 pcap_compile(INPUT.pcap, 301 308 &DATA(libtrace)->filter->filter, … … 304 311 DATA(libtrace)->filter->flag = 1; 305 312 } 306 313 if (pcap_setfilter(INPUT.pcap,&DATA(libtrace)->filter->filter) 307 314 == -1) { 308 315 trace_set_err(libtrace,TRACE_ERR_INIT_FAILED,"%s", … … 310 317 return -1; /* failure */ 311 318 } 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 } 316 345 return 0; /* success */ 317 346 } … … 421 450 if (libtrace_halt) 422 451 return 0; 423 452 continue; /* timeout expired */ 424 453 case -1: 425 454 trace_set_err(libtrace,TRACE_ERR_BAD_PACKET, -
lib/format_pcapfile.c
rb13b939 r9e429e8 713 713 714 714 if (IN_OPTIONS.real_time) { 715 event.size = pcapfile_read_packet(libtrace, packet);715 event.size = trace_read_packet(libtrace, packet); 716 716 if (event.size < 1) 717 717 event.type = TRACE_EVENT_TERMINATE; -
lib/format_rt.c
rb13b939 r9e429e8 780 780 if (packet->type == TRACE_RT_END_DATA) 781 781 event.type = TRACE_EVENT_TERMINATE; 782 else 782 else { 783 783 /* Since several RT messages can have zero-byte 784 784 * length (once the framing is removed), an … … 786 786 * PACKET event */ 787 787 event.type = TRACE_EVENT_PACKET; 788 trace->accepted_packets ++; 789 } 788 790 789 791 } 790 792 else { 791 793 event.type = TRACE_EVENT_PACKET; 794 trace->accepted_packets ++; 792 795 } 793 796 … … 795 798 if (!trace_apply_filter(trace->filter, packet)) { 796 799 trace_clear_cache(packet); 797 continue; 800 trace->filtered_packets ++; 801 continue; 798 802 } 799 803 } -
lib/trace.c
rd994324 r9e429e8 825 825 do { 826 826 size_t ret; 827 int filtret; 827 828 /* Finalise the packet, freeing any resources the format module 828 829 * may have allocated it and zeroing all data associated with it. … … 840 841 * packet 841 842 */ 842 if (!trace_apply_filter(libtrace->filter,packet)){ 843 filtret = trace_apply_filter(libtrace->filter, packet); 844 if (filtret == -1) { 845 /* Error compiling filter, probably */ 846 return ~0U; 847 } 848 849 if (filtret == 0) { 843 850 ++libtrace->filtered_packets; 844 851 continue; … … 1220 1227 1221 1228 if (packet->trace->format->trace_event) { 1229 /* Note: incrementing accepted, filtered etc. packet 1230 * counters is handled by the format-specific 1231 * function so don't increment them here. 1232 */ 1222 1233 event=packet->trace->format->trace_event(trace,packet); 1223 if (event.type == TRACE_EVENT_PACKET) { 1224 ++trace->accepted_packets; 1225 } 1226 } 1234 } 1227 1235 return event; 1228 1236 … … 1948 1956 return trace->format->get_filtered_packets(trace)+ 1949 1957 trace->filtered_packets; 1950 }1951 if (trace->format->get_received_packets1952 && trace->format->get_dropped_packets) {1953 return1954 ((trace_get_received_packets(trace)1955 -trace_get_accepted_packets(trace))1956 -trace_get_dropped_packets(trace))1957 +trace->filtered_packets;1958 1958 } 1959 1959 return trace->filtered_packets;
Note: See TracChangeset
for help on using the changeset viewer.