Changes in / [04bf7c5:fed9152]
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile.am
r60f3c4c ra2ce0a6 22 22 $(RM) -rf autom4te.cache/ 23 23 24 dist-hook:25 if which svnversion > /dev/null; then \26 r=`svnversion -nc . | sed -e 's/^[^:]*://;s/[A-Za-z]//'` ;\27 sed -i "s/SVN_REVISION.*/SVN_REVISION $$r/" $(distdir)/lib/libtrace.h.in; \28 fi29 30 24 if HAS_DOXYGEN 31 25 docs/doxygen/man/man3/*.3: docs -
lib/format_dag25.c
rc66a465 r68d3308 119 119 /* Data that is stored for each libtrace_thread_t */ 120 120 struct dag_per_thread_t { 121 struct dag_dev_t *device; /* DAG device */ 122 uint16_t stream; /* Stream number */ 123 uint8_t *top; /* Pointer to the last unread byte in the DAG memory */ 124 uint8_t *bottom; /* Pointer to the first unread byte in the DAG memory */ 125 uint32_t processed; /* Amount of data processed from the bottom pointer */ 126 uint64_t pkt_count; /* Number of packets seen by the thread */ 121 /* DAG device */ 122 struct dag_dev_t *device; 123 /* Stream number */ 124 uint16_t stream; 125 /* Pointer to the last unread byte in the DAG memory */ 126 uint8_t *top; 127 /* Pointer to the first unread byte in the DAG memory */ 128 uint8_t *bottom; 129 /* Amount of data processed from the bottom pointer */ 130 uint32_t processed; 131 /* Number of packets seen by the thread */ 132 uint64_t pkt_count; 133 /* Drop count for this particular thread */ 127 134 uint64_t drops; 128 135 }; … … 130 137 /* "Global" data that is stored for each DAG input trace */ 131 138 struct dag_format_data_t { 132 133 139 /* Data required for regular DUCK reporting */ 134 140 struct { … … 136 142 uint32_t last_duck; 137 143 /* The number of seconds between each DUCK report */ 138 144 uint32_t duck_freq; 139 145 /* Timestamp of the last packet read from the DAG card */ 140 146 uint32_t last_pkt; 141 147 /* Dummy trace to ensure DUCK packets are dealt with using the 142 148 * DUCK format functions */ 143 144 149 libtrace_t *dummy_duck; 150 } duck; 145 151 146 152 /* The DAG device that we are reading from */ … … 158 164 /* The number of packets that have been dropped */ 159 165 uint64_t drops; 160 /* When running in parallel mode this is malloc'd with an array of thread 161 * structures. Most of the stuff above doesn't get used in parallel mode. */ 166 /* When running in parallel mode this is malloc'd with an 167 * array of thread structures. Most of the stuff above doesn't 168 * get used in parallel mode. */ 162 169 struct dag_per_thread_t *per_thread; 170 171 uint8_t seeninterface[4]; 163 172 }; 164 173 … … 216 225 217 226 /* Initialises the DAG output data structure */ 218 static void dag_init_format_out_data(libtrace_out_t *libtrace) { 219 libtrace->format_data = (struct dag_format_data_out_t *) malloc(sizeof(struct dag_format_data_out_t)); 227 static void dag_init_format_out_data(libtrace_out_t *libtrace) 228 { 229 libtrace->format_data = (struct dag_format_data_out_t *) 230 malloc(sizeof(struct dag_format_data_out_t)); 220 231 // no DUCK on output 221 232 FORMAT_DATA_OUT->stream_attached = 0; … … 227 238 228 239 /* Initialises the DAG input data structure */ 229 static void dag_init_format_data(libtrace_t *libtrace) { 240 static void dag_init_format_data(libtrace_t *libtrace) 241 { 230 242 libtrace->format_data = (struct dag_format_data_t *) 231 243 malloc(sizeof(struct dag_format_data_t)); 232 244 DUCK.last_duck = 0; 233 234 235 245 DUCK.duck_freq = 0; 246 DUCK.last_pkt = 0; 247 DUCK.dummy_duck = NULL; 236 248 FORMAT_DATA->stream_attached = 0; 237 249 FORMAT_DATA->drops = 0; … … 241 253 FORMAT_DATA->bottom = NULL; 242 254 FORMAT_DATA->top = NULL; 255 memset(FORMAT_DATA->seeninterface, 0, 256 sizeof(FORMAT_DATA->seeninterface)); 243 257 } 244 258 … … 247 261 * 248 262 * NOTE: This function assumes the open_dag_mutex is held by the caller */ 249 static struct dag_dev_t *dag_find_open_device(char *dev_name) { 263 static struct dag_dev_t *dag_find_open_device(char *dev_name) 264 { 250 265 struct dag_dev_t *dag_dev; 251 266 … … 258 273 dag_dev->ref_count ++; 259 274 return dag_dev; 260 261 275 } 262 276 dag_dev = dag_dev->next; 263 277 } 264 278 return NULL; 265 266 267 279 } 268 280 … … 273 285 * 274 286 * NOTE: This function assumes the open_dag_mutex is held by the caller */ 275 static void dag_close_device(struct dag_dev_t *dev) { 287 static void dag_close_device(struct dag_dev_t *dev) 288 { 276 289 /* Need to remove from the device list */ 277 278 290 assert(dev->ref_count == 0); 279 291 … … 290 302 dag_close(dev->fd); 291 303 if (dev->dev_name) 292 free(dev->dev_name);304 free(dev->dev_name); 293 305 free(dev); 294 306 } … … 298 310 * 299 311 * NOTE: this function should only be called when opening a DAG device for 300 * writing - there is little practical difference between this and the 312 * writing - there is little practical difference between this and the 301 313 * function below that covers the reading case, but we need the output trace 302 * object to report errors properly so the two functions take slightly 314 * object to report errors properly so the two functions take slightly 303 315 * different arguments. This is really lame and there should be a much better 304 316 * way of doing this. 305 317 * 306 * NOTE: This function assumes the open_dag_mutex is held by the caller 318 * NOTE: This function assumes the open_dag_mutex is held by the caller 307 319 */ 308 static struct dag_dev_t *dag_open_output_device(libtrace_out_t *libtrace, char *dev_name) { 320 static struct dag_dev_t *dag_open_output_device(libtrace_out_t *libtrace, 321 char *dev_name) 322 { 309 323 struct stat buf; 310 324 int fd; … … 315 329 trace_set_err_out(libtrace,errno,"stat(%s)",dev_name); 316 330 return NULL; 317 }331 } 318 332 319 333 /* Make sure it is the appropriate type of device */ … … 352 366 * 353 367 * NOTE: this function should only be called when opening a DAG device for 354 * reading - there is little practical difference between this and the 368 * reading - there is little practical difference between this and the 355 369 * function above that covers the writing case, but we need the input trace 356 * object to report errors properly so the two functions take slightly 370 * object to report errors properly so the two functions take slightly 357 371 * different arguments. This is really lame and there should be a much better 358 372 * way of doing this. … … 365 379 366 380 /* Make sure the device exists */ 367 368 369 370 381 if (stat(dev_name, &buf) == -1) { 382 trace_set_err(libtrace,errno,"stat(%s)",dev_name); 383 return NULL; 384 } 371 385 372 386 /* Make sure it is the appropriate type of device */ … … 374 388 /* Try opening the DAG device */ 375 389 if((fd = dag_open(dev_name)) < 0) { 376 377 378 379 390 trace_set_err(libtrace,errno,"Cannot open DAG %s", 391 dev_name); 392 return NULL; 393 } 380 394 } else { 381 395 trace_set_err(libtrace,errno,"Not a valid dag device: %s", 382 383 384 396 dev_name); 397 return NULL; 398 } 385 399 386 400 /* Add the device to our device list - it is just a doubly linked … … 403 417 404 418 /* Creates and initialises a DAG output trace */ 405 static int dag_init_output(libtrace_out_t *libtrace) { 419 static int dag_init_output(libtrace_out_t *libtrace) 420 { 406 421 char *dag_dev_name = NULL; 407 422 char *scan = NULL; 408 423 struct dag_dev_t *dag_device = NULL; 409 424 int stream = 1; 410 425 411 426 /* XXX I don't know if this is important or not, but this function 412 427 * isn't present in all of the driver releases that this code is … … 418 433 419 434 dag_init_format_out_data(libtrace); 420 /* Grab the mutex while we're likely to be messing with the device 435 /* Grab the mutex while we're likely to be messing with the device 421 436 * list */ 422 437 pthread_mutex_lock(&open_dag_mutex); 423 438 424 439 /* Specific streams are signified using a comma in the libtrace URI, 425 440 * e.g. dag:/dev/dag0,1 refers to stream 1 on the dag0 device. … … 463 478 /* Creates and initialises a DAG input trace */ 464 479 static int dag_init_input(libtrace_t *libtrace) { 465 480 char *dag_dev_name = NULL; 466 481 char *scan = NULL; 467 482 int stream = 0, thread_count = 1; … … 469 484 470 485 dag_init_format_data(libtrace); 471 /* Grab the mutex while we're likely to be messing with the device 486 /* Grab the mutex while we're likely to be messing with the device 472 487 * list */ 473 488 pthread_mutex_lock(&open_dag_mutex); … … 478 493 * e.g. dag:/dev/dag0,2 refers to stream 2 on the dag0 device. 479 494 * 480 * If no stream is specified, we will read from stream 0 with one thread 495 * If no stream is specified, we will read from stream 0 with 496 * one thread 481 497 */ 482 498 if ((scan = strchr(libtrace->uridata, ',')) == NULL) { 483 499 dag_dev_name = strdup(libtrace->uridata); 484 485 500 } else { 486 501 dag_dev_name = (char *)strndup(libtrace->uridata, 487 (size_t)(scan - libtrace->uridata)); 502 (size_t)(scan - 503 libtrace->uridata)); 488 504 stream = atoi(++scan); 489 505 } … … 514 530 FORMAT_DATA->device = dag_device; 515 531 516 /* See Config_Status_API_Programming_Guide.pdf from the Endace Dag Documentation */ 517 /* Check kBooleanAttributeActive is true -- no point capturing on an interface that's disabled 518 519 * The symptom of the port being disabled is that libtrace will appear to hang. 520 */ 532 /* See Config_Status_API_Programming_Guide.pdf from the Endace 533 Dag Documentation */ 534 /* Check kBooleanAttributeActive is true -- no point capturing 535 * on an interface that's disabled 536 * 537 * The symptom of the port being disabled is that libtrace 538 * will appear to hang. */ 521 539 /* Check kBooleanAttributeFault is false */ 522 540 /* Check kBooleanAttributeLocalFault is false */ … … 524 542 /* Check kBooleanAttributePeerLink ? */ 525 543 526 /* Set kBooleanAttributePromisc/kBooleanPromiscuousMode based on libtrace promisc attribute?*/ 544 /* Set kBooleanAttributePromisc/kBooleanPromiscuousMode based 545 on libtrace promisc attribute?*/ 527 546 /* Set kUint32AttributeSnapLength to the snaplength */ 528 547 529 548 pthread_mutex_unlock(&open_dag_mutex); 530 549 return 0; 531 550 } 532 551 533 552 /* Configures a DAG input trace */ 534 553 static int dag_config_input(libtrace_t *libtrace, trace_option_t option, 535 void *data) { 536 char conf_str[4096]; 554 void *data) 555 { 556 char conf_str[4096]; 537 557 switch(option) { 538 case TRACE_OPTION_META_FREQ: 539 /* This option is used to specify the frequency of DUCK 540 * updates */ 541 DUCK.duck_freq = *(int *)data; 542 return 0; 543 case TRACE_OPTION_SNAPLEN: 544 /* Tell the card our new snap length */ 545 snprintf(conf_str, 4096, "varlen slen=%i", *(int *)data); 546 if (dag_configure(FORMAT_DATA->device->fd, 547 conf_str) != 0) { 548 trace_set_err(libtrace, errno, "Failed to configure snaplen on DAG card: %s", libtrace->uridata); 549 return -1; 550 } 551 return 0; 552 case TRACE_OPTION_PROMISC: 553 /* DAG already operates in a promisc fashion */ 554 return -1; 555 case TRACE_OPTION_FILTER: 556 /* We don't yet support pushing filters into DAG 557 * cards */ 558 return -1; 559 case TRACE_OPTION_EVENT_REALTIME: 560 /* Live capture is always going to be realtime */ 558 case TRACE_OPTION_META_FREQ: 559 /* This option is used to specify the frequency of DUCK 560 * updates */ 561 DUCK.duck_freq = *(int *)data; 562 return 0; 563 case TRACE_OPTION_SNAPLEN: 564 /* Tell the card our new snap length */ 565 snprintf(conf_str, 4096, "varlen slen=%i", *(int *)data); 566 if (dag_configure(FORMAT_DATA->device->fd, 567 conf_str) != 0) { 568 trace_set_err(libtrace, errno, "Failed to configure " 569 "snaplen on DAG card: %s", 570 libtrace->uridata); 561 571 return -1; 562 } 572 } 573 return 0; 574 case TRACE_OPTION_PROMISC: 575 /* DAG already operates in a promisc fashion */ 576 return -1; 577 case TRACE_OPTION_FILTER: 578 /* We don't yet support pushing filters into DAG 579 * cards */ 580 return -1; 581 case TRACE_OPTION_EVENT_REALTIME: 582 /* Live capture is always going to be realtime */ 583 return -1; 584 } 563 585 return -1; 564 586 } 565 587 566 588 /* Starts a DAG output trace */ 567 static int dag_start_output(libtrace_out_t *libtrace) { 589 static int dag_start_output(libtrace_out_t *libtrace) 590 { 568 591 struct timeval zero, nopoll; 569 592 … … 573 596 574 597 /* Attach and start the DAG stream */ 575 576 598 if (dag_attach_stream(FORMAT_DATA_OUT->device->fd, 577 FORMAT_DATA_OUT->dagstream, 0, 1048576) < 0) {599 FORMAT_DATA_OUT->dagstream, 0, 4 * 1024 * 1024) < 0) { 578 600 trace_set_err_out(libtrace, errno, "Cannot attach DAG stream"); 579 601 return -1; … … 588 610 589 611 /* We don't want the dag card to do any sleeping */ 590 591 612 dag_set_stream_poll(FORMAT_DATA_OUT->device->fd, 592 613 FORMAT_DATA_OUT->dagstream, 0, &zero, … … 597 618 598 619 /* Starts a DAG input trace */ 599 static int dag_start_input(libtrace_t *libtrace) { 600 struct timeval zero, nopoll; 601 uint8_t *top, *bottom; 602 uint8_t diff = 0; 620 static int dag_start_input(libtrace_t *libtrace) 621 { 622 struct timeval zero, nopoll; 623 uint8_t *top, *bottom, *starttop; 624 uint64_t diff = 0; 603 625 top = bottom = NULL; 604 626 605 627 zero.tv_sec = 0; 606 607 628 zero.tv_usec = 10000; 629 nopoll = zero; 608 630 609 631 /* Attach and start the DAG stream */ 610 632 if (dag_attach_stream(FORMAT_DATA->device->fd, 611 612 613 614 633 FORMAT_DATA->dagstream, 0, 0) < 0) { 634 trace_set_err(libtrace, errno, "Cannot attach DAG stream"); 635 return -1; 636 } 615 637 616 638 if (dag_start_stream(FORMAT_DATA->device->fd, 617 618 619 620 639 FORMAT_DATA->dagstream) < 0) { 640 trace_set_err(libtrace, errno, "Cannot start DAG stream"); 641 return -1; 642 } 621 643 FORMAT_DATA->stream_attached = 1; 622 644 623 645 /* We don't want the dag card to do any sleeping */ 624 dag_set_stream_poll(FORMAT_DATA->device->fd, 625 FORMAT_DATA->dagstream, 0, &zero, 626 &nopoll); 646 dag_set_stream_poll(FORMAT_DATA->device->fd, 647 FORMAT_DATA->dagstream, 0, &zero, 648 &nopoll); 649 650 starttop = dag_advance_stream(FORMAT_DATA->device->fd, 651 FORMAT_DATA->dagstream, 652 &bottom); 627 653 628 654 /* Should probably flush the memory hole now */ 629 do { 655 top = starttop; 656 while (starttop - bottom > 0) { 657 bottom += (starttop - bottom); 630 658 top = dag_advance_stream(FORMAT_DATA->device->fd, 631 FORMAT_DATA->dagstream, 632 &bottom); 633 assert(top && bottom); 634 diff = top - bottom; 635 bottom -= diff; 636 } while (diff != 0); 637 FORMAT_DATA->top = NULL; 638 FORMAT_DATA->bottom = NULL; 659 FORMAT_DATA->dagstream, 660 &bottom); 661 } 662 FORMAT_DATA->top = top; 663 FORMAT_DATA->bottom = bottom; 639 664 FORMAT_DATA->processed = 0; 640 665 FORMAT_DATA->drops = 0; … … 644 669 645 670 /* Pauses a DAG output trace */ 646 static int dag_pause_output(libtrace_out_t *libtrace) {647 671 static int dag_pause_output(libtrace_out_t *libtrace) 672 { 648 673 /* Stop and detach the stream */ 649 674 if (dag_stop_stream(FORMAT_DATA_OUT->device->fd, 650 FORMAT_DATA_OUT->dagstream) < 0) {675 FORMAT_DATA_OUT->dagstream) < 0) { 651 676 trace_set_err_out(libtrace, errno, "Could not stop DAG stream"); 652 677 return -1; 653 678 } 654 679 if (dag_detach_stream(FORMAT_DATA_OUT->device->fd, 655 FORMAT_DATA_OUT->dagstream) < 0) { 656 trace_set_err_out(libtrace, errno, "Could not detach DAG stream"); 680 FORMAT_DATA_OUT->dagstream) < 0) { 681 trace_set_err_out(libtrace, errno, 682 "Could not detach DAG stream"); 657 683 return -1; 658 684 } … … 662 688 663 689 /* Pauses a DAG input trace */ 664 static int dag_pause_input(libtrace_t *libtrace) {665 690 static int dag_pause_input(libtrace_t *libtrace) 691 { 666 692 /* Stop and detach the stream */ 667 693 if (dag_stop_stream(FORMAT_DATA->device->fd, 668 669 670 671 672 673 674 675 694 FORMAT_DATA->dagstream) < 0) { 695 trace_set_err(libtrace, errno, "Could not stop DAG stream"); 696 return -1; 697 } 698 if (dag_detach_stream(FORMAT_DATA->device->fd, 699 FORMAT_DATA->dagstream) < 0) { 700 trace_set_err(libtrace, errno, "Could not detach DAG stream"); 701 return -1; 676 702 } 677 703 FORMAT_DATA->stream_attached = 0; … … 680 706 681 707 /* Closes a DAG input trace */ 682 static int dag_fin_input(libtrace_t *libtrace) { 708 static int dag_fin_input(libtrace_t *libtrace) 709 { 683 710 /* Need the lock, since we're going to be handling the device list */ 684 711 pthread_mutex_lock(&open_dag_mutex); 685 712 686 713 /* Detach the stream if we are not paused */ 687 714 if (FORMAT_DATA->stream_attached) … … 696 723 free(libtrace->format_data); 697 724 pthread_mutex_unlock(&open_dag_mutex); 698 725 return 0; /* success */ 699 726 } 700 727 701 728 /* Closes a DAG output trace */ 702 static int dag_fin_output(libtrace_out_t *libtrace) { 703 729 static int dag_fin_output(libtrace_out_t *libtrace) 730 { 731 704 732 /* Commit any outstanding traffic in the txbuffer */ 705 733 if (FORMAT_DATA_OUT->waiting) { 706 dag_tx_stream_commit_bytes(FORMAT_DATA_OUT->device->fd, FORMAT_DATA_OUT->dagstream, 707 FORMAT_DATA_OUT->waiting ); 708 } 709 710 /* Wait until the buffer is nearly clear before exiting the program, 734 dag_tx_stream_commit_bytes(FORMAT_DATA_OUT->device->fd, 735 FORMAT_DATA_OUT->dagstream, 736 FORMAT_DATA_OUT->waiting ); 737 } 738 739 /* Wait until the buffer is nearly clear before exiting the program, 711 740 * as we will lose packets otherwise */ 712 dag_tx_get_stream_space (FORMAT_DATA_OUT->device->fd,713 FORMAT_DATA_OUT->dagstream,714 dag_get_stream_buffer_size(FORMAT_DATA_OUT->device->fd,715 FORMAT_DATA_OUT->dagstream) - 8716 );741 dag_tx_get_stream_space 742 (FORMAT_DATA_OUT->device->fd, 743 FORMAT_DATA_OUT->dagstream, 744 dag_get_stream_buffer_size(FORMAT_DATA_OUT->device->fd, 745 FORMAT_DATA_OUT->dagstream) - 8); 717 746 718 747 /* Need the lock, since we're going to be handling the device list */ … … 733 762 734 763 /* Extracts DUCK information from the DAG card and produces a DUCK packet */ 735 static int dag_get_duckinfo(libtrace_t *libtrace, 736 libtrace_packet_t *packet) { 737 764 static int dag_get_duckinfo(libtrace_t *libtrace, libtrace_packet_t *packet) 765 { 738 766 /* Allocate memory for the DUCK data */ 739 740 741 742 743 744 745 746 747 748 767 if (packet->buf_control == TRACE_CTRL_EXTERNAL || 768 !packet->buffer) { 769 packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); 770 packet->buf_control = TRACE_CTRL_PACKET; 771 if (!packet->buffer) { 772 trace_set_err(libtrace, errno, 773 "Cannot allocate packet buffer"); 774 return -1; 775 } 776 } 749 777 750 778 /* DUCK doesn't have a format header */ 751 752 753 754 755 756 757 758 759 760 761 762 779 packet->header = 0; 780 packet->payload = packet->buffer; 781 782 /* No need to check if we can get DUCK or not - we're modern 783 * enough so just grab the DUCK info */ 784 if ((ioctl(FORMAT_DATA->device->fd, DAGIOCDUCK, 785 (duckinf_t *)packet->payload) < 0)) { 786 trace_set_err(libtrace, errno, "Error using DAGIOCDUCK"); 787 return -1; 788 } 789 790 packet->type = TRACE_RT_DUCK_2_5; 763 791 764 792 /* Set the packet's tracce to point at a DUCK trace, so that the 765 793 * DUCK format functions will be called on the packet rather than the 766 794 * DAG ones */ 767 768 769 770 795 if (!DUCK.dummy_duck) 796 DUCK.dummy_duck = trace_create_dead("rt:localhost:3434"); 797 packet->trace = DUCK.dummy_duck; 798 return sizeof(duckinf_t); 771 799 } 772 800 773 801 /* Determines the amount of data available to read from the DAG card */ 774 static int dag_available(libtrace_t *libtrace) { 802 static int dag_available(libtrace_t *libtrace) 803 { 775 804 uint32_t diff = FORMAT_DATA->top - FORMAT_DATA->bottom; 776 805 … … 780 809 if (diff >= dag_record_size && FORMAT_DATA->processed < 4 * 1024 * 1024) 781 810 return diff; 782 811 783 812 /* Update the top and bottom pointers */ 784 813 FORMAT_DATA->top = dag_advance_stream(FORMAT_DATA->device->fd, 785 FORMAT_DATA->dagstream,786 &(FORMAT_DATA->bottom));787 814 FORMAT_DATA->dagstream, 815 &(FORMAT_DATA->bottom)); 816 788 817 if (FORMAT_DATA->top == NULL) { 789 818 trace_set_err(libtrace, errno, "dag_advance_stream failed!"); … … 796 825 797 826 /* Returns a pointer to the start of the next complete ERF record */ 798 static dag_record_t *dag_get_record(libtrace_t *libtrace) { 799 dag_record_t *erfptr = NULL; 800 uint16_t size; 827 static dag_record_t *dag_get_record(libtrace_t *libtrace) 828 { 829 dag_record_t *erfptr = NULL; 830 uint16_t size; 831 801 832 erfptr = (dag_record_t *)FORMAT_DATA->bottom; 802 833 if (!erfptr) 803 return NULL; 804 size = ntohs(erfptr->rlen); 805 assert( size >= dag_record_size ); 834 return NULL; 835 836 size = ntohs(erfptr->rlen); 837 assert( size >= dag_record_size ); 838 806 839 /* Make certain we have the full packet available */ 807 840 if (size > (FORMAT_DATA->top - FORMAT_DATA->bottom)) 808 841 return NULL; 842 809 843 FORMAT_DATA->bottom += size; 810 844 FORMAT_DATA->processed += size; … … 815 849 * libtrace packet */ 816 850 static int dag_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 817 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 818 851 void *buffer, libtrace_rt_types_t rt_type, 852 uint32_t flags) 853 { 819 854 dag_record_t *erfptr; 820 855 libtrace_thread_t *t; 821 856 822 857 /* If the packet previously owned a buffer that is not the buffer 823 824 858 * that contains the new packet data, we're going to need to free the 859 * old one to avoid memory leaks */ 825 860 if (packet->buffer != buffer && 826 861 packet->buf_control == TRACE_CTRL_PACKET) { … … 837 872 erfptr = (dag_record_t *)buffer; 838 873 packet->buffer = erfptr; 839 840 874 packet->header = erfptr; 875 packet->type = rt_type; 841 876 842 877 if (erfptr->flags.rxerror == 1) { 843 844 845 846 847 848 849 850 878 /* rxerror means the payload is corrupt - drop the payload 879 * by tweaking rlen */ 880 packet->payload = NULL; 881 erfptr->rlen = htons(erf_get_framing_length(packet)); 882 } else { 883 packet->payload = (char*)packet->buffer 884 + erf_get_framing_length(packet); 885 } 851 886 852 887 if (libtrace->format_data == NULL) { … … 855 890 856 891 /* Update the dropped packets counter */ 857 /* No loss counter for DSM coloured records - have to use 858 * some other API */ 859 /* Adding multithread support for this isn't actually that useful for the 860 * DAG7.5G2, as there's no way to use multiple receive streams without DSM */ 892 /* No loss counter for DSM coloured records - have to use some 893 * other API */ 861 894 if (erfptr->type == TYPE_DSM_COLOR_ETH) { 862 895 /* TODO */ … … 867 900 PERPKT_DATA(t)->drops += ntohs(erfptr->lctr); 868 901 } else { 869 printf("DROP!\n"); 870 DATA(libtrace)->drops += ntohs(erfptr->lctr); 871 } 872 } 873 902 if (FORMAT_DATA->seeninterface[erfptr->flags.iface] 903 == 0) { 904 FORMAT_DATA->seeninterface[erfptr->flags.iface] 905 = 1; 906 } else { 907 FORMAT_DATA->drops += ntohs(erfptr->lctr); 908 } 909 } 910 } 874 911 875 912 return 0; … … 886 923 /* Pushes an ERF record onto the transmit stream */ 887 924 static int dag_dump_packet(libtrace_out_t *libtrace, 888 dag_record_t *erfptr, unsigned int pad, void *buffer) { 925 dag_record_t *erfptr, unsigned int pad, 926 void *buffer) 927 { 889 928 int size; 890 929 891 930 /* 892 * If we've got 0 bytes waiting in the txqueue, assume that we haven't893 * requested any space yet, and request some, storing the pointer at894 * FORMAT_DATA_OUT->txbuffer.931 * If we've got 0 bytes waiting in the txqueue, assume that we 932 * haven't requested any space yet, and request some, storing 933 * the pointer at FORMAT_DATA_OUT->txbuffer. 895 934 * 896 935 * The amount to request is slightly magical at the moment - it's … … 899 938 */ 900 939 if (FORMAT_DATA_OUT->waiting == 0) { 901 FORMAT_DATA_OUT->txbuffer = dag_tx_get_stream_space(FORMAT_DATA_OUT->device->fd, 902 FORMAT_DATA_OUT->dagstream, 16908288); 940 FORMAT_DATA_OUT->txbuffer = 941 dag_tx_get_stream_space(FORMAT_DATA_OUT->device->fd, 942 FORMAT_DATA_OUT->dagstream, 943 16908288); 903 944 } 904 945 … … 907 948 * are in contiguous memory 908 949 */ 909 memcpy(FORMAT_DATA_OUT->txbuffer + FORMAT_DATA_OUT->waiting,erfptr,(dag_record_size + pad)); 950 memcpy(FORMAT_DATA_OUT->txbuffer + FORMAT_DATA_OUT->waiting, erfptr, 951 (dag_record_size + pad)); 910 952 FORMAT_DATA_OUT->waiting += (dag_record_size + pad); 911 912 913 953 914 954 /* … … 917 957 */ 918 958 size = ntohs(erfptr->rlen)-(dag_record_size + pad); 919 memcpy(FORMAT_DATA_OUT->txbuffer + FORMAT_DATA_OUT->waiting,buffer,size); 959 memcpy(FORMAT_DATA_OUT->txbuffer + FORMAT_DATA_OUT->waiting, buffer, 960 size); 920 961 FORMAT_DATA_OUT->waiting += size; 921 962 … … 926 967 * case there is still data in the buffer at program exit. 927 968 */ 928 929 969 if (FORMAT_DATA_OUT->waiting >= 16*1024*1024) { 930 FORMAT_DATA_OUT->txbuffer = dag_tx_stream_commit_bytes(FORMAT_DATA_OUT->device->fd, FORMAT_DATA_OUT->dagstream, 931 FORMAT_DATA_OUT->waiting ); 970 FORMAT_DATA_OUT->txbuffer = 971 dag_tx_stream_commit_bytes(FORMAT_DATA_OUT->device->fd, 972 FORMAT_DATA_OUT->dagstream, 973 FORMAT_DATA_OUT->waiting); 932 974 FORMAT_DATA_OUT->waiting = 0; 933 975 } 934 976 935 977 return size + pad + dag_record_size; 936 937 978 } 938 979 … … 940 981 * if one is found, false otherwise */ 941 982 static bool find_compatible_linktype(libtrace_out_t *libtrace, 942 libtrace_packet_t *packet, char *type)943 { 944 //Keep trying to simplify the packet until we can find945 //something we can do with it983 libtrace_packet_t *packet, char *type) 984 { 985 /* Keep trying to simplify the packet until we can find 986 * something we can do with it */ 946 987 947 988 do { 948 *type =libtrace_to_erf_type(trace_get_link_type(packet));949 950 / / Success989 *type = libtrace_to_erf_type(trace_get_link_type(packet)); 990 991 /* Success */ 951 992 if (*type != (char)-1) 952 993 return true; … … 954 995 if (!demote_packet(packet)) { 955 996 trace_set_err_out(libtrace, 956 TRACE_ERR_NO_CONVERSION,957 "No erf type for packet (%i)",958 trace_get_link_type(packet));997 TRACE_ERR_NO_CONVERSION, 998 "No erf type for packet (%i)", 999 trace_get_link_type(packet)); 959 1000 return false; 960 1001 } … … 966 1007 967 1008 /* Writes a packet to the provided DAG output trace */ 968 static int dag_write_packet(libtrace_out_t *libtrace, libtrace_packet_t *packet) {969 /* 970 * This is heavily borrowed from erf_write_packet(). Yes, CnP coding971 * sucks, sorry about that.1009 static int dag_write_packet(libtrace_out_t *libtrace, libtrace_packet_t *packet) 1010 { 1011 /* This is heavily borrowed from erf_write_packet(). Yes, CnP 1012 * coding sucks, sorry about that. 972 1013 */ 973 1014 unsigned int pad = 0; … … 978 1019 979 1020 if(!packet->header) { 980 /* No header, probably an RT packet. Lifted from 1021 /* No header, probably an RT packet. Lifted from 981 1022 * erf_write_packet(). */ 982 1023 return -1; … … 997 1038 998 1039 if (packet->type == TRACE_RT_DATA_ERF) { 999 numbytes = dag_dump_packet(libtrace, 1000 header, 1001 pad, 1002 payload 1003 ); 1004 1040 numbytes = dag_dump_packet(libtrace, header, pad, payload); 1005 1041 } else { 1006 1042 /* Build up a new packet header from the existing header */ 1007 1043 1008 /* Simplify the packet first - if we can't do this, break 1044 /* Simplify the packet first - if we can't do this, break 1009 1045 * early */ 1010 1046 if (!find_compatible_linktype(libtrace,packet,&erf_type)) … … 1025 1061 1026 1062 /* Packet length (rlen includes format overhead) */ 1027 assert(trace_get_capture_length(packet)>0 1028 && trace_get_capture_length(packet)<=65536); 1029 assert(erf_get_framing_length(packet)>0 1030 && trace_get_framing_length(packet)<=65536); 1031 assert(trace_get_capture_length(packet)+erf_get_framing_length(packet)>0 1032 &&trace_get_capture_length(packet)+erf_get_framing_length(packet)<=65536); 1063 assert(trace_get_capture_length(packet) > 0 1064 && trace_get_capture_length(packet) <= 65536); 1065 assert(erf_get_framing_length(packet) > 0 1066 && trace_get_framing_length(packet) <= 65536); 1067 assert(trace_get_capture_length(packet) + 1068 erf_get_framing_length(packet) > 0 1069 && trace_get_capture_length(packet) + 1070 erf_get_framing_length(packet) <= 65536); 1033 1071 1034 1072 erfhdr.rlen = htons(trace_get_capture_length(packet) 1035 + erf_get_framing_length(packet));1073 + erf_get_framing_length(packet)); 1036 1074 1037 1075 … … 1042 1080 1043 1081 /* Write it out */ 1044 numbytes = dag_dump_packet(libtrace, 1045 &erfhdr, 1046 pad, 1047 payload); 1048 1082 numbytes = dag_dump_packet(libtrace, &erfhdr, pad, payload); 1049 1083 } 1050 1084 … … 1056 1090 * If DUCK reporting is enabled, the packet returned may be a DUCK update 1057 1091 */ 1058 static int dag_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 1059 int size = 0; 1060 struct timeval tv; 1061 dag_record_t *erfptr = NULL; 1092 static int dag_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) 1093 { 1094 int size = 0; 1095 struct timeval tv; 1096 dag_record_t *erfptr = NULL; 1062 1097 int numbytes = 0; 1063 1098 uint32_t flags = 0; … … 1070 1105 maxwait.tv_usec = 250000; 1071 1106 1072 1107 /* Check if we're due for a DUCK report */ 1073 1108 if (DUCK.last_pkt - DUCK.last_duck > DUCK.duck_freq && 1074 1075 1076 1077 1078 1079 1080 1081 1082 1109 DUCK.duck_freq != 0) { 1110 size = dag_get_duckinfo(libtrace, packet); 1111 DUCK.last_duck = DUCK.last_pkt; 1112 if (size != 0) { 1113 return size; 1114 } 1115 /* No DUCK support, so don't waste our time anymore */ 1116 DUCK.duck_freq = 0; 1117 } 1083 1118 1084 1119 /* Don't let anyone try to free our DAG memory hole! */ … … 1087 1122 /* If the packet buffer is currently owned by libtrace, free it so 1088 1123 * that we can set the packet to point into the DAG memory hole */ 1089 if (packet->buf_control == TRACE_CTRL_PACKET) { 1090 free(packet->buffer); 1091 packet->buffer = 0; 1092 } 1093 1094 if (dag_set_stream_poll(FORMAT_DATA->device->fd, 1095 FORMAT_DATA->dagstream, sizeof(dag_record_t), &maxwait, 1096 &pollwait) == -1) 1097 { 1124 if (packet->buf_control == TRACE_CTRL_PACKET) { 1125 free(packet->buffer); 1126 packet->buffer = 0; 1127 } 1128 1129 if (dag_set_stream_poll(FORMAT_DATA->device->fd, FORMAT_DATA->dagstream, 1130 sizeof(dag_record_t), &maxwait, 1131 &pollwait) == -1) { 1098 1132 trace_set_err(libtrace, errno, "dag_set_stream_poll"); 1099 1133 return -1; … … 1117 1151 /* Prepare the libtrace packet */ 1118 1152 if (dag_prepare_packet(libtrace, packet, erfptr, TRACE_RT_DATA_ERF, 1119 1153 flags)) 1120 1154 return -1; 1121 1155 1122 1156 /* Update the DUCK timer */ 1123 1157 tv = trace_get_timeval(packet); 1124 1158 DUCK.last_pkt = tv.tv_sec; 1125 1159 1126 1160 return packet->payload ? htons(erfptr->rlen) : 1127 1161 erf_get_framing_length(packet); 1128 1162 } 1129 1163 … … 1133 1167 */ 1134 1168 static libtrace_eventobj_t trace_event_dag(libtrace_t *libtrace, 1135 libtrace_packet_t *packet) { 1136 libtrace_eventobj_t event = {0,0,0.0,0}; 1169 libtrace_packet_t *packet) 1170 { 1171 libtrace_eventobj_t event = {0,0,0.0,0}; 1137 1172 dag_record_t *erfptr = NULL; 1138 1173 int numbytes; 1139 1174 uint32_t flags = 0; 1140 1175 struct timeval minwait; 1141 1176 1142 1177 minwait.tv_sec = 0; 1143 1178 minwait.tv_usec = 10000; 1144 1145 if (dag_set_stream_poll(FORMAT_DATA->device->fd, 1146 FORMAT_DATA->dagstream, 0, &minwait, 1147 &minwait) == -1) 1148 { 1179 1180 if (dag_set_stream_poll(FORMAT_DATA->device->fd, 1181 FORMAT_DATA->dagstream, 0, &minwait, 1182 &minwait) == -1) { 1149 1183 trace_set_err(libtrace, errno, "dag_set_stream_poll"); 1150 1184 event.type = TRACE_EVENT_TERMINATE; … … 1155 1189 erfptr = NULL; 1156 1190 numbytes = 0; 1157 1191 1158 1192 /* Need to call dag_available so that the top pointer will get 1159 1193 * updated, otherwise we'll never see any data! */ 1160 1194 numbytes = dag_available(libtrace); 1161 1195 1162 /* May as well not bother calling dag_get_record if 1196 /* May as well not bother calling dag_get_record if 1163 1197 * dag_available suggests that there's no data */ 1164 1198 if (numbytes != 0) … … 1168 1202 if (libtrace_halt) { 1169 1203 event.type = TRACE_EVENT_TERMINATE; 1170 } else { 1204 } else { 1171 1205 event.type = TRACE_EVENT_SLEEP; 1172 1206 event.seconds = 0.0001; … … 1174 1208 break; 1175 1209 } 1176 if (dag_prepare_packet(libtrace, packet, erfptr, 1177 1210 if (dag_prepare_packet(libtrace, packet, erfptr, 1211 TRACE_RT_DATA_ERF, flags)) { 1178 1212 event.type = TRACE_EVENT_TERMINATE; 1179 1213 break; … … 1181 1215 1182 1216 1183 event.size = trace_get_capture_length(packet) + 1184 1185 1217 event.size = trace_get_capture_length(packet) + 1218 trace_get_framing_length(packet); 1219 1186 1220 /* XXX trace_read_packet() normally applies the following 1187 1221 * config options for us, but this function is called via … … 1189 1223 1190 1224 if (libtrace->filter) { 1191 int filtret = trace_apply_filter(libtrace->filter, 1192 packet);1225 int filtret = trace_apply_filter(libtrace->filter, 1226 packet); 1193 1227 if (filtret == -1) { 1194 1228 trace_set_err(libtrace, TRACE_ERR_BAD_FILTER, 1195 1229 "Bad BPF Filter"); 1196 1230 event.type = TRACE_EVENT_TERMINATE; 1197 1231 break; … … 1204 1238 * a sleep event in this case, like we used to 1205 1239 * do! */ 1206 1240 libtrace->filtered_packets ++; 1207 1241 trace_clear_cache(packet); 1208 1242 continue; 1209 1243 } 1210 1244 1211 1245 event.type = TRACE_EVENT_PACKET; 1212 1246 } else { … … 1217 1251 trace_set_capture_length(packet, libtrace->snaplen); 1218 1252 } 1219 1253 libtrace->accepted_packets ++; 1220 1254 break; 1221 } while 1255 } while(1); 1222 1256 1223 1257 return event; … … 1225 1259 1226 1260 /* Gets the number of dropped packets */ 1227 static uint64_t dag_get_dropped_packets(libtrace_t *trace) { 1261 static uint64_t dag_get_dropped_packets(libtrace_t *trace) 1262 { 1228 1263 uint64_t sum = 0; 1229 1264 int i, tot; 1230 1265 1231 1266 if (trace->format_data == NULL) 1232 return (uint64_t) -1;1267 return (uint64_t) - 1; 1233 1268 1234 1269 if (DATA(trace)->per_thread) { … … 1237 1272 for (i = 0; i < tot; i++) { 1238 1273 printf("t%d: drops %" PRIu64 "\n", 1239 1274 DATA(trace)->per_thread[i].drops); 1240 1275 sum += DATA(trace)->per_thread[i].drops; 1241 1276 } … … 1249 1284 /* Prints some semi-useful help text about the DAG format module */ 1250 1285 static void dag_help(void) { 1251 printf("dag format module: $Revision: 1755 $\n"); 1252 printf("Supported input URIs:\n"); 1253 printf("\tdag:/dev/dagn\n"); 1254 printf("\n"); 1255 printf("\te.g.: dag:/dev/dag0\n"); 1256 printf("\n"); 1257 printf("Supported output URIs:\n"); 1258 printf("\tnone\n"); 1259 printf("\n"); 1260 } 1261 1262 static int dag_pstart_input(libtrace_t *libtrace) { 1286 printf("dag format module: $Revision: 1755 $\n"); 1287 printf("Supported input URIs:\n"); 1288 printf("\tdag:/dev/dagn\n"); 1289 printf("\n"); 1290 printf("\te.g.: dag:/dev/dag0\n"); 1291 printf("\n"); 1292 printf("Supported output URIs:\n"); 1293 printf("\tnone\n"); 1294 printf("\n"); 1295 } 1296 1297 static int dag_pstart_input(libtrace_t *libtrace) 1298 { 1263 1299 char *scan, *tok; 1264 1300 uint16_t stream_count = 0, max_streams; … … 1268 1304 int iserror = 0; 1269 1305 1270 /* Check we aren't trying to create more threads than the DAG card can 1306 /* Check we aren't trying to create more threads than the DAG card can 1271 1307 * handle */ 1272 1308 max_streams = dag_rx_get_stream_count(FORMAT_DATA->device->fd); 1273 1309 if (libtrace->perpkt_thread_count > max_streams) { 1274 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, "trying to create too " 1275 "many threads (max is %u)", max_streams); 1310 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, 1311 "trying to create too many threads (max is %u)", 1312 max_streams); 1276 1313 iserror = 1; 1277 1314 goto cleanup; … … 1280 1317 /* Create the thread structures */ 1281 1318 per_thread = calloc(libtrace->perpkt_thread_count, 1282 1319 sizeof(struct dag_per_thread_t)); 1283 1320 FORMAT_DATA->per_thread = per_thread; 1284 1321 1285 1322 /* Get the stream names from the uri */ 1286 1323 if ((scan = strchr(libtrace->uridata, ',')) == NULL) { 1287 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, "format uri doesn't "1288 "specify the DAG streams");1324 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, 1325 "format uri doesn't specify the DAG streams"); 1289 1326 iserror = 1; 1290 1327 goto cleanup; … … 1292 1329 1293 1330 scan++; 1294 1331 1295 1332 tok = strtok(scan, ","); 1296 1333 while (tok != NULL) { 1297 1334 /* Ensure we haven't specified too many streams */ 1298 1335 if (stream_count >= libtrace->perpkt_thread_count) { 1299 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, "format uri specifies too " 1300 "many streams. Max is %u", max_streams); 1336 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, 1337 "format uri specifies too many streams. " 1338 "Max is %u", max_streams); 1301 1339 iserror = 1; 1302 1340 goto cleanup; … … 1314 1352 /* Free the per_thread memory */ 1315 1353 free(per_thread); 1316 1317 1354 return -1; 1318 1355 } else { … … 1324 1361 1325 1362 /* TODO: Fold this into dag_available */ 1326 static int dag_pavailable(libtrace_t *libtrace, libtrace_thread_t *t) { 1363 static int dag_pavailable(libtrace_t *libtrace, libtrace_thread_t *t) 1364 { 1327 1365 uint32_t diff = PERPKT_DATA(t)->top - PERPKT_DATA(t)->bottom; 1328 1366 … … 1330 1368 * dag_advance_stream, then we should call it again to allow the 1331 1369 * space occupied by that 4MB to be released */ 1332 if (diff >= dag_record_size && PERPKT_DATA(t)->processed < 4 * 1024 * 1024) 1370 if (diff >= dag_record_size && PERPKT_DATA(t)->processed < 1371 4*1024*1024) 1333 1372 return diff; 1334 1373 1335 1374 /* Update top and bottom pointers */ 1336 1375 PERPKT_DATA(t)->top = dag_advance_stream(PERPKT_DATA(t)->device->fd, 1337 1338 1376 PERPKT_DATA(t)->stream, 1377 &(PERPKT_DATA(t)->bottom)); 1339 1378 1340 1379 if (PERPKT_DATA(t)->top == NULL) { … … 1350 1389 /* TODO: Fold this into dag_get_record */ 1351 1390 static dag_record_t *dag_pget_record(libtrace_t *libtrace, 1352 libtrace_thread_t *t) { 1391 libtrace_thread_t *t) 1392 { 1353 1393 dag_record_t *erfptr = NULL; 1354 1394 uint16_t size; … … 1367 1407 PERPKT_DATA(t)->bottom += size; 1368 1408 PERPKT_DATA(t)->processed += size; 1369 1409 1370 1410 return erfptr; 1371 1411 } 1372 1412 1373 1413 static int dag_pread_packet(libtrace_t *libtrace, libtrace_thread_t *t, 1374 libtrace_packet_t *packet) { 1414 libtrace_packet_t *packet) 1415 { 1375 1416 dag_record_t *erfptr = NULL; 1376 1417 int numbytes = 0; … … 1396 1437 1397 1438 /* Configure DAG card stream polling */ 1398 if (dag_set_stream_poll(PERPKT_DATA(t)->device->fd, PERPKT_DATA(t)->stream, 1399 sizeof(dag_record_t), &maxwait, &pollwait) < 0) { 1439 if (dag_set_stream_poll(PERPKT_DATA(t)->device->fd, 1440 PERPKT_DATA(t)->stream, sizeof(dag_record_t), 1441 &maxwait, &pollwait) < 0) { 1400 1442 trace_set_err(libtrace, errno, "dag_set_stream_poll"); 1401 1443 return -1; … … 1411 1453 return 0; 1412 1454 1413 /* Check message queue to see if we should abort early */ 1455 /* Check message queue to see if we should 1456 * abort early */ 1414 1457 if (libtrace_message_queue_count(&t->messages) > 0) 1415 1458 return -2; … … 1424 1467 /* Prepare the libtrace packet */ 1425 1468 if (dag_prepare_packet(libtrace, packet, erfptr, TRACE_RT_DATA_ERF, 1426 1469 flags)) 1427 1470 return -1; 1428 1471 … … 1433 1476 } 1434 1477 1435 static int dag_ppause_input(libtrace_t *libtrace) { 1478 static int dag_ppause_input(libtrace_t *libtrace) 1479 { 1436 1480 int i, tot = libtrace->perpkt_thread_count; 1437 1481 struct dag_per_thread_t *t_data; … … 1443 1487 1444 1488 if (dag_stop_stream(t_data->device->fd, 1445 t_data->stream) < 0) { 1446 trace_set_err(libtrace, errno, "can't stop DAG stream #%u", 1447 t_data->stream); 1489 t_data->stream) < 0) { 1490 trace_set_err(libtrace, errno, 1491 "can't stop DAG stream #%u", 1492 t_data->stream); 1448 1493 return -1; 1449 1494 } 1450 1495 1451 1496 if (dag_detach_stream(t_data->device->fd, 1452 t_data->stream) < 0) { 1453 trace_set_err(libtrace, errno, "can't detach DAG stream #%u", 1454 t_data->stream); 1497 t_data->stream) < 0) { 1498 trace_set_err(libtrace, errno, 1499 "can't detach DAG stream #%u", 1500 t_data->stream); 1455 1501 return -1; 1456 1502 } … … 1465 1511 1466 1512 static int dag_pconfig_input(libtrace_t *libtrace, 1467 trace_parallel_option_t option, void *value) {1468 1513 trace_parallel_option_t option, void *value) 1514 { 1469 1515 /* We don't support any of these! Normally you configure the DAG card 1470 1516 * externally. */ … … 1485 1531 1486 1532 static int dag_pregister_thread(libtrace_t *libtrace, libtrace_thread_t *t, 1487 bool reader) { 1533 bool reader) 1534 { 1488 1535 /* XXX: This function gets run sequentially for all 1489 1536 * threads. Should investigate making it parallel as draining the … … 1491 1538 */ 1492 1539 uint8_t *top, *bottom; 1493 uint8_t diff = 0; /* XXX: Investigate this type, as I would assume the value 1494 * could be larger than 255 */ 1540 /* XXX: Investigate this type, as I would assume the value 1541 * could be larger than 255 */ 1542 uint8_t diff = 0; 1495 1543 struct timeval zero, nopoll; 1496 1544 … … 1505 1553 if (t->type == THREAD_PERPKT) { 1506 1554 /* Pass the per thread data to the thread */ 1507 t->format_data = &FORMAT_DATA->per_thread[t->perpkt_num]; 1555 t->format_data = 1556 &FORMAT_DATA->per_thread[t->perpkt_num]; 1508 1557 1509 1558 /* Attach and start the DAG stream */ 1510 printf("t%u: starting and attaching stream #%u\n", t->perpkt_num,1511 1559 printf("t%u: starting and attaching stream #%u\n", 1560 t->perpkt_num, PERPKT_DATA(t)->stream); 1512 1561 if (dag_attach_stream(PERPKT_DATA(t)->device->fd, 1513 PERPKT_DATA(t)->stream, 0, 0) < 0) { 1514 trace_set_err(libtrace, errno, "can't attach DAG stream #%u", 1515 PERPKT_DATA(t)->stream); 1562 PERPKT_DATA(t)->stream, 0, 1563 0) < 0) { 1564 trace_set_err(libtrace, errno, 1565 "can't attach DAG stream #%u", 1566 PERPKT_DATA(t)->stream); 1516 1567 return -1; 1517 1568 } 1518 1569 if (dag_start_stream(PERPKT_DATA(t)->device->fd, 1519 PERPKT_DATA(t)->stream) < 0) { 1520 trace_set_err(libtrace, errno, "can't start DAG stream #%u", 1521 PERPKT_DATA(t)->stream); 1570 PERPKT_DATA(t)->stream) < 0) { 1571 trace_set_err(libtrace, errno, 1572 "can't start DAG stream #%u", 1573 PERPKT_DATA(t)->stream); 1522 1574 return -1; 1523 1575 } … … 1525 1577 /* Ensure that dag_advance_stream will return without blocking */ 1526 1578 if(dag_set_stream_poll(PERPKT_DATA(t)->device->fd, 1527 PERPKT_DATA(t)->stream, 0, &zero, 1528 &nopoll) < 0) { 1529 trace_set_err(libtrace, errno, "dag_set_stream_poll failed!"); 1579 PERPKT_DATA(t)->stream, 0, &zero, 1580 &nopoll) < 0) { 1581 trace_set_err(libtrace, errno, 1582 "dag_set_stream_poll failed!"); 1530 1583 return -1; 1531 1584 } … … 1533 1586 /* Clear all the data from the memory hole */ 1534 1587 do { 1535 top = dag_advance_stream(PERPKT_DATA(t)->device->fd, 1536 PERPKT_DATA(t)->stream, 1537 &bottom); 1588 top = dag_advance_stream(PERPKT_DATA(t)-> 1589 device->fd, 1590 PERPKT_DATA(t)->stream, 1591 &bottom); 1538 1592 1539 1593 assert(top && bottom); … … 1558 1612 1559 1613 static struct libtrace_format_t dag = { 1560 1561 1562 1614 "dag", 1615 "$Id$", 1616 TRACE_FORMAT_ERF, 1563 1617 dag_probe_filename, /* probe filename */ 1564 1618 NULL, /* probe magic */ 1565 1566 1567 1568 1619 dag_init_input, /* init_input */ 1620 dag_config_input, /* config_input */ 1621 dag_start_input, /* start_input */ 1622 dag_pause_input, /* pause_input */ 1569 1623 dag_init_output, /* init_output */ 1570 1624 NULL, /* config_output */ 1571 1625 dag_start_output, /* start_output */ 1572 1626 dag_fin_input, /* fin_input */ 1573 1627 dag_fin_output, /* fin_output */ 1574 1575 1628 dag_read_packet, /* read_packet */ 1629 dag_prepare_packet, /* prepare_packet */ 1576 1630 NULL, /* fin_packet */ 1577 1631 dag_write_packet, /* write_packet */ 1578 1579 1580 1581 1582 1583 1632 erf_get_link_type, /* get_link_type */ 1633 erf_get_direction, /* get_direction */ 1634 erf_set_direction, /* set_direction */ 1635 erf_get_erf_timestamp, /* get_erf_timestamp */ 1636 NULL, /* get_timeval */ 1637 NULL, /* get_seconds */ 1584 1638 NULL, /* get_timespec */ 1585 1586 1587 1588 1589 1590 1591 1639 NULL, /* seek_erf */ 1640 NULL, /* seek_timeval */ 1641 NULL, /* seek_seconds */ 1642 erf_get_capture_length, /* get_capture_length */ 1643 erf_get_wire_length, /* get_wire_length */ 1644 erf_get_framing_length, /* get_framing_length */ 1645 erf_set_capture_length, /* set_capture_length */ 1592 1646 NULL, /* get_received_packets */ 1593 1647 NULL, /* get_filtered_packets */ 1594 1648 dag_get_dropped_packets, /* get_dropped_packets */ 1595 1649 NULL, /* get_captured_packets */ 1596 1597 1598 1599 1650 NULL, /* get_fd */ 1651 trace_event_dag, /* trace_event */ 1652 dag_help, /* help */ 1653 NULL, /* next pointer */ 1600 1654 {true, 0}, /* live packet capture, thread limit TBD */ 1601 1655 dag_pstart_input, … … 1608 1662 }; 1609 1663 1610 void dag_constructor(void) { 1664 void dag_constructor(void) 1665 { 1611 1666 register_format(&dag); 1612 1667 } -
lib/format_erf.c
rc70f59f rc69aecb 480 480 packet->buffer, 481 481 (size_t)dag_record_size)) == -1) { 482 trace_set_err(libtrace,errno,"read(%s)", 483 libtrace->uridata); 482 trace_set_err(libtrace,errno,"reading ERF file"); 484 483 return -1; 485 484 } … … 488 487 return 0; 489 488 } 489 490 if (numbytes < (int)dag_record_size) { 491 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Incomplete ERF header"); 492 return -1; 493 } 490 494 491 495 rlen = ntohs(((dag_record_t *)packet->buffer)->rlen); … … 522 526 return -1; 523 527 } 528 529 if (numbytes < (int)size) { 530 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Incomplete ERF record"); 531 return -1; 532 } 524 533 525 534 if (erf_prepare_packet(libtrace, packet, packet->buffer, -
lib/format_pcapfile.c
rc70f59f rc69aecb 210 210 211 211 if (err<1) { 212 if (err == 0) { 213 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, 214 "Reading pcap file header\n"); 215 } 212 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, 213 "Error while reading pcap file header\n"); 216 214 return -1; 217 215 } 218 216 217 if (err != (int)sizeof(DATA(libtrace)->header)) { 218 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, 219 "Incomplete pcap file header"); 220 return -1; 221 } 222 219 223 if (!header_is_magic(&(DATA(libtrace)->header))) { 220 224 trace_set_err(libtrace,TRACE_ERR_INIT_FAILED, … … 359 363 packet->buffer, 360 364 sizeof(libtrace_pcapfile_pkt_hdr_t)); 361 362 365 if (err<0) { 363 366 trace_set_err(libtrace,errno,"reading packet"); … … 368 371 return 0; 369 372 } 373 374 if (err < (int)sizeof(libtrace_pcapfile_pkt_hdr_t)) { 375 trace_set_err(libtrace, errno, "Incomplete pcap packet header"); 376 return -1; 377 } 370 378 371 379 bytes_to_read = swapl(libtrace,((libtrace_pcapfile_pkt_hdr_t*)packet->buffer)->caplen); … … 391 399 ); 392 400 393 394 401 if (err<0) { 395 402 trace_set_err(libtrace,errno,"reading packet"); … … 399 406 return 0; 400 407 } 408 409 if (err < (int)bytes_to_read) { 410 trace_set_err(libtrace, errno, "Incomplete pcap packet body"); 411 return -1; 412 } 401 413 402 414 if (pcapfile_prepare_packet(libtrace, packet, packet->buffer, -
lib/format_tsh.c
rb13b939 rc69aecb 147 147 return 0; 148 148 } 149 150 if (numbytes < (int)sizeof(tsh_pkt_header_t)) { 151 trace_set_err(libtrace, errno, "Incomplete TSH header"); 152 return -1; 153 } 149 154 150 155 buffer2 = (char*)buffer2 + numbytes; -
lib/libtrace.h.in
rd994324 ra2ce0a6 109 109 ((@LIBTRACE_MAJOR@<<16)|(@LIBTRACE_MID@<<8)|(@LIBTRACE_MINOR@)) 110 110 111 /** Replaced with the current SVN revision number when 'make dist' is invoked 112 * to create a distributable tarball */ 113 #define LIBTRACE_SVN_REVISION 0 111 /** This used to be replaced with the current SVN revision number when 112 * 'make dist' was invoked to create a distributable tarball. We don't use 113 * SVN anymore and there probably isn't any need to know the exact revision 114 * number either these days. */ 115 #define LIBTRACE_SVN_REVISION LIBTRACE_API_VERSION 114 116 115 117 /** DAG driver version installed on the current system */ -
libwandio/ior-zlib.c
r60f3c4c r525d09d 56 56 int outoffset; 57 57 enum err_t err; 58 size_t sincelastend; 58 59 }; 59 60 … … 83 84 DATA(io)->strm.opaque = NULL; 84 85 DATA(io)->err = ERR_OK; 86 DATA(io)->sincelastend = 1; 85 87 86 88 inflateInit2(&DATA(io)->strm, 15 | 32); … … 108 110 sizeof(DATA(io)->inbuff)); 109 111 if (bytes_read == 0) { 110 /* EOF */ 112 /* If we get EOF immediately after a 113 * Z_STREAM_END, then we assume we've reached 114 * the end of the file. If there was data 115 * between the Z_STREAM_END and the EOF, the 116 * file has more likely been truncated. 117 */ 118 if (DATA(io)->sincelastend > 0) { 119 fprintf(stderr, "Unexpected EOF while reading compressed file -- file is probably incomplete\n"); 120 errno = EIO; 121 DATA(io)->err = ERR_ERROR; 122 return -1; 123 } 124 125 /* EOF */ 111 126 if (DATA(io)->strm.avail_out == (uint32_t)len) { 112 127 DATA(io)->err = ERR_EOF; 113 128 return 0; 114 129 } … … 128 143 DATA(io)->strm.next_in = DATA(io)->inbuff; 129 144 DATA(io)->strm.avail_in = bytes_read; 145 DATA(io)->sincelastend += bytes_read; 130 146 } 131 147 /* Decompress some data into the output buffer */ … … 144 160 inflateInit2(&DATA(io)->strm, 15 | 32); 145 161 DATA(io)->err = ERR_OK; 162 DATA(io)->sincelastend = 0; 146 163 break; 147 164 default: -
tools/tracestats/tracestats.c
rc0ccccd r3c54095 157 157 158 158 if (trace_is_err(trace)) 159 trace_perror(trace," %s",uri);159 trace_perror(trace,"Processing trace"); 160 160 161 161 trace_destroy(trace);
Note: See TracChangeset
for help on using the changeset viewer.