Changeset d97778c
- Timestamp:
- 01/15/15 17:13:58 (6 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:
- 18bf317
- Parents:
- 97d170d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_dag25.c
r97d170d rd97778c 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; 163 170 … … 218 225 219 226 /* Initialises the DAG output data structure */ 220 static void dag_init_format_out_data(libtrace_out_t *libtrace) { 221 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)); 222 231 // no DUCK on output 223 232 FORMAT_DATA_OUT->stream_attached = 0; … … 229 238 230 239 /* Initialises the DAG input data structure */ 231 static void dag_init_format_data(libtrace_t *libtrace) { 240 static void dag_init_format_data(libtrace_t *libtrace) 241 { 232 242 libtrace->format_data = (struct dag_format_data_t *) 233 243 malloc(sizeof(struct dag_format_data_t)); 234 244 DUCK.last_duck = 0; 235 236 237 245 DUCK.duck_freq = 0; 246 DUCK.last_pkt = 0; 247 DUCK.dummy_duck = NULL; 238 248 FORMAT_DATA->stream_attached = 0; 239 249 FORMAT_DATA->drops = 0; … … 243 253 FORMAT_DATA->bottom = NULL; 244 254 FORMAT_DATA->top = NULL; 245 memset(FORMAT_DATA->seeninterface, 0, sizeof(FORMAT_DATA->seeninterface)); 255 memset(FORMAT_DATA->seeninterface, 0, 256 sizeof(FORMAT_DATA->seeninterface)); 246 257 } 247 258 … … 250 261 * 251 262 * NOTE: This function assumes the open_dag_mutex is held by the caller */ 252 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 { 253 265 struct dag_dev_t *dag_dev; 254 266 … … 261 273 dag_dev->ref_count ++; 262 274 return dag_dev; 263 264 275 } 265 276 dag_dev = dag_dev->next; 266 277 } 267 278 return NULL; 268 269 270 279 } 271 280 … … 276 285 * 277 286 * NOTE: This function assumes the open_dag_mutex is held by the caller */ 278 static void dag_close_device(struct dag_dev_t *dev) { 287 static void dag_close_device(struct dag_dev_t *dev) 288 { 279 289 /* Need to remove from the device list */ 280 281 290 assert(dev->ref_count == 0); 282 291 … … 301 310 * 302 311 * NOTE: this function should only be called when opening a DAG device for 303 * writing - there is little practical difference between this and the 312 * writing - there is little practical difference between this and the 304 313 * function below that covers the reading case, but we need the output trace 305 * object to report errors properly so the two functions take slightly 314 * object to report errors properly so the two functions take slightly 306 315 * different arguments. This is really lame and there should be a much better 307 316 * way of doing this. 308 317 * 309 * 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 310 319 */ 311 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 { 312 323 struct stat buf; 313 324 int fd; … … 318 329 trace_set_err_out(libtrace,errno,"stat(%s)",dev_name); 319 330 return NULL; 320 }331 } 321 332 322 333 /* Make sure it is the appropriate type of device */ … … 355 366 * 356 367 * NOTE: this function should only be called when opening a DAG device for 357 * reading - there is little practical difference between this and the 368 * reading - there is little practical difference between this and the 358 369 * function above that covers the writing case, but we need the input trace 359 * object to report errors properly so the two functions take slightly 370 * object to report errors properly so the two functions take slightly 360 371 * different arguments. This is really lame and there should be a much better 361 372 * way of doing this. … … 368 379 369 380 /* Make sure the device exists */ 370 371 372 373 381 if (stat(dev_name, &buf) == -1) { 382 trace_set_err(libtrace,errno,"stat(%s)",dev_name); 383 return NULL; 384 } 374 385 375 386 /* Make sure it is the appropriate type of device */ … … 377 388 /* Try opening the DAG device */ 378 389 if((fd = dag_open(dev_name)) < 0) { 379 380 381 382 390 trace_set_err(libtrace,errno,"Cannot open DAG %s", 391 dev_name); 392 return NULL; 393 } 383 394 } else { 384 395 trace_set_err(libtrace,errno,"Not a valid dag device: %s", 385 386 387 396 dev_name); 397 return NULL; 398 } 388 399 389 400 /* Add the device to our device list - it is just a doubly linked … … 406 417 407 418 /* Creates and initialises a DAG output trace */ 408 static int dag_init_output(libtrace_out_t *libtrace) { 419 static int dag_init_output(libtrace_out_t *libtrace) 420 { 409 421 char *dag_dev_name = NULL; 410 422 char *scan = NULL; 411 423 struct dag_dev_t *dag_device = NULL; 412 424 int stream = 1; 413 425 414 426 /* XXX I don't know if this is important or not, but this function 415 427 * isn't present in all of the driver releases that this code is … … 421 433 422 434 dag_init_format_out_data(libtrace); 423 /* 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 424 436 * list */ 425 437 pthread_mutex_lock(&open_dag_mutex); 426 438 427 439 /* Specific streams are signified using a comma in the libtrace URI, 428 440 * e.g. dag:/dev/dag0,1 refers to stream 1 on the dag0 device. … … 466 478 /* Creates and initialises a DAG input trace */ 467 479 static int dag_init_input(libtrace_t *libtrace) { 468 480 char *dag_dev_name = NULL; 469 481 char *scan = NULL; 470 482 int stream = 0, thread_count = 1; … … 472 484 473 485 dag_init_format_data(libtrace); 474 /* 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 475 487 * list */ 476 488 pthread_mutex_lock(&open_dag_mutex); … … 481 493 * e.g. dag:/dev/dag0,2 refers to stream 2 on the dag0 device. 482 494 * 483 * 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 484 497 */ 485 498 if ((scan = strchr(libtrace->uridata, ',')) == NULL) { 486 499 dag_dev_name = strdup(libtrace->uridata); 487 488 500 } else { 489 501 dag_dev_name = (char *)strndup(libtrace->uridata, 490 (size_t)(scan - libtrace->uridata)); 502 (size_t)(scan - 503 libtrace->uridata)); 491 504 stream = atoi(++scan); 492 505 } … … 517 530 FORMAT_DATA->device = dag_device; 518 531 519 /* See Config_Status_API_Programming_Guide.pdf from the Endace Dag Documentation */ 520 /* Check kBooleanAttributeActive is true -- no point capturing on an interface that's disabled 521 522 * The symptom of the port being disabled is that libtrace will appear to hang. 523 */ 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. */ 524 539 /* Check kBooleanAttributeFault is false */ 525 540 /* Check kBooleanAttributeLocalFault is false */ … … 527 542 /* Check kBooleanAttributePeerLink ? */ 528 543 529 /* Set kBooleanAttributePromisc/kBooleanPromiscuousMode based on libtrace promisc attribute?*/ 544 /* Set kBooleanAttributePromisc/kBooleanPromiscuousMode based 545 on libtrace promisc attribute?*/ 530 546 /* Set kUint32AttributeSnapLength to the snaplength */ 531 547 532 548 pthread_mutex_unlock(&open_dag_mutex); 533 549 return 0; 534 550 } 535 551 536 552 /* Configures a DAG input trace */ 537 553 static int dag_config_input(libtrace_t *libtrace, trace_option_t option, 538 void *data) { 539 char conf_str[4096]; 554 void *data) 555 { 556 char conf_str[4096]; 540 557 switch(option) { 541 case TRACE_OPTION_META_FREQ: 542 /* This option is used to specify the frequency of DUCK 543 * updates */ 544 DUCK.duck_freq = *(int *)data; 545 return 0; 546 case TRACE_OPTION_SNAPLEN: 547 /* Tell the card our new snap length */ 548 snprintf(conf_str, 4096, "varlen slen=%i", *(int *)data); 549 if (dag_configure(FORMAT_DATA->device->fd, 550 conf_str) != 0) { 551 trace_set_err(libtrace, errno, "Failed to configure snaplen on DAG card: %s", libtrace->uridata); 552 return -1; 553 } 554 return 0; 555 case TRACE_OPTION_PROMISC: 556 /* DAG already operates in a promisc fashion */ 557 return -1; 558 case TRACE_OPTION_FILTER: 559 /* We don't yet support pushing filters into DAG 560 * cards */ 561 return -1; 562 case TRACE_OPTION_EVENT_REALTIME: 563 /* 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); 564 571 return -1; 565 } 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 } 566 585 return -1; 567 586 } 568 587 569 588 /* Starts a DAG output trace */ 570 static int dag_start_output(libtrace_out_t *libtrace) { 589 static int dag_start_output(libtrace_out_t *libtrace) 590 { 571 591 struct timeval zero, nopoll; 572 592 … … 576 596 577 597 /* Attach and start the DAG stream */ 578 579 598 if (dag_attach_stream(FORMAT_DATA_OUT->device->fd, 580 599 FORMAT_DATA_OUT->dagstream, 0, 4 * 1024 * 1024) < 0) { … … 591 610 592 611 /* We don't want the dag card to do any sleeping */ 593 594 612 dag_set_stream_poll(FORMAT_DATA_OUT->device->fd, 595 613 FORMAT_DATA_OUT->dagstream, 0, &zero, … … 600 618 601 619 /* Starts a DAG input trace */ 602 static int dag_start_input(libtrace_t *libtrace) { 603 struct timeval zero, nopoll; 604 uint8_t *top, *bottom, *starttop; 620 static int dag_start_input(libtrace_t *libtrace) 621 { 622 struct timeval zero, nopoll; 623 uint8_t *top, *bottom, *starttop; 605 624 uint64_t diff = 0; 606 625 top = bottom = NULL; 607 626 608 627 zero.tv_sec = 0; 609 610 628 zero.tv_usec = 10000; 629 nopoll = zero; 611 630 612 631 /* Attach and start the DAG stream */ 613 632 if (dag_attach_stream(FORMAT_DATA->device->fd, 614 615 616 617 633 FORMAT_DATA->dagstream, 0, 0) < 0) { 634 trace_set_err(libtrace, errno, "Cannot attach DAG stream"); 635 return -1; 636 } 618 637 619 638 if (dag_start_stream(FORMAT_DATA->device->fd, 620 621 622 623 639 FORMAT_DATA->dagstream) < 0) { 640 trace_set_err(libtrace, errno, "Cannot start DAG stream"); 641 return -1; 642 } 624 643 FORMAT_DATA->stream_attached = 1; 625 644 626 645 /* We don't want the dag card to do any sleeping */ 627 628 629 646 dag_set_stream_poll(FORMAT_DATA->device->fd, 647 FORMAT_DATA->dagstream, 0, &zero, 648 &nopoll); 630 649 631 650 starttop = dag_advance_stream(FORMAT_DATA->device->fd, 632 633 651 FORMAT_DATA->dagstream, 652 &bottom); 634 653 635 654 /* Should probably flush the memory hole now */ … … 637 656 bottom += (starttop - bottom); 638 657 top = dag_advance_stream(FORMAT_DATA->device->fd, 639 FORMAT_DATA->dagstream,640 &bottom);658 FORMAT_DATA->dagstream, 659 &bottom); 641 660 } 642 661 FORMAT_DATA->top = top; … … 649 668 650 669 /* Pauses a DAG output trace */ 651 static int dag_pause_output(libtrace_out_t *libtrace) {652 670 static int dag_pause_output(libtrace_out_t *libtrace) 671 { 653 672 /* Stop and detach the stream */ 654 673 if (dag_stop_stream(FORMAT_DATA_OUT->device->fd, 655 FORMAT_DATA_OUT->dagstream) < 0) {674 FORMAT_DATA_OUT->dagstream) < 0) { 656 675 trace_set_err_out(libtrace, errno, "Could not stop DAG stream"); 657 676 return -1; 658 677 } 659 678 if (dag_detach_stream(FORMAT_DATA_OUT->device->fd, 660 FORMAT_DATA_OUT->dagstream) < 0) { 661 trace_set_err_out(libtrace, errno, "Could not detach DAG stream"); 679 FORMAT_DATA_OUT->dagstream) < 0) { 680 trace_set_err_out(libtrace, errno, 681 "Could not detach DAG stream"); 662 682 return -1; 663 683 } … … 667 687 668 688 /* Pauses a DAG input trace */ 669 static int dag_pause_input(libtrace_t *libtrace) {670 689 static int dag_pause_input(libtrace_t *libtrace) 690 { 671 691 /* Stop and detach the stream */ 672 692 if (dag_stop_stream(FORMAT_DATA->device->fd, 673 674 675 676 677 678 679 680 693 FORMAT_DATA->dagstream) < 0) { 694 trace_set_err(libtrace, errno, "Could not stop DAG stream"); 695 return -1; 696 } 697 if (dag_detach_stream(FORMAT_DATA->device->fd, 698 FORMAT_DATA->dagstream) < 0) { 699 trace_set_err(libtrace, errno, "Could not detach DAG stream"); 700 return -1; 681 701 } 682 702 FORMAT_DATA->stream_attached = 0; … … 685 705 686 706 /* Closes a DAG input trace */ 687 static int dag_fin_input(libtrace_t *libtrace) { 707 static int dag_fin_input(libtrace_t *libtrace) 708 { 688 709 /* Need the lock, since we're going to be handling the device list */ 689 710 pthread_mutex_lock(&open_dag_mutex); 690 711 691 712 /* Detach the stream if we are not paused */ 692 713 if (FORMAT_DATA->stream_attached) … … 701 722 free(libtrace->format_data); 702 723 pthread_mutex_unlock(&open_dag_mutex); 703 724 return 0; /* success */ 704 725 } 705 726 706 727 /* Closes a DAG output trace */ 707 static int dag_fin_output(libtrace_out_t *libtrace) { 708 728 static int dag_fin_output(libtrace_out_t *libtrace) 729 { 730 709 731 /* Commit any outstanding traffic in the txbuffer */ 710 732 if (FORMAT_DATA_OUT->waiting) { 711 dag_tx_stream_commit_bytes(FORMAT_DATA_OUT->device->fd, FORMAT_DATA_OUT->dagstream, 712 FORMAT_DATA_OUT->waiting ); 713 } 714 715 /* Wait until the buffer is nearly clear before exiting the program, 733 dag_tx_stream_commit_bytes(FORMAT_DATA_OUT->device->fd, 734 FORMAT_DATA_OUT->dagstream, 735 FORMAT_DATA_OUT->waiting ); 736 } 737 738 /* Wait until the buffer is nearly clear before exiting the program, 716 739 * as we will lose packets otherwise */ 717 dag_tx_get_stream_space (FORMAT_DATA_OUT->device->fd,718 FORMAT_DATA_OUT->dagstream,719 dag_get_stream_buffer_size(FORMAT_DATA_OUT->device->fd,720 FORMAT_DATA_OUT->dagstream) - 8721 );740 dag_tx_get_stream_space 741 (FORMAT_DATA_OUT->device->fd, 742 FORMAT_DATA_OUT->dagstream, 743 dag_get_stream_buffer_size(FORMAT_DATA_OUT->device->fd, 744 FORMAT_DATA_OUT->dagstream) - 8); 722 745 723 746 /* Need the lock, since we're going to be handling the device list */ … … 738 761 739 762 /* Extracts DUCK information from the DAG card and produces a DUCK packet */ 740 static int dag_get_duckinfo(libtrace_t *libtrace, 741 libtrace_packet_t *packet) { 742 763 static int dag_get_duckinfo(libtrace_t *libtrace, libtrace_packet_t *packet) 764 { 743 765 /* Allocate memory for the DUCK data */ 744 745 746 747 748 749 750 751 752 753 766 if (packet->buf_control == TRACE_CTRL_EXTERNAL || 767 !packet->buffer) { 768 packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); 769 packet->buf_control = TRACE_CTRL_PACKET; 770 if (!packet->buffer) { 771 trace_set_err(libtrace, errno, 772 "Cannot allocate packet buffer"); 773 return -1; 774 } 775 } 754 776 755 777 /* DUCK doesn't have a format header */ 756 757 758 759 760 761 762 763 764 765 766 767 778 packet->header = 0; 779 packet->payload = packet->buffer; 780 781 /* No need to check if we can get DUCK or not - we're modern 782 * enough so just grab the DUCK info */ 783 if ((ioctl(FORMAT_DATA->device->fd, DAGIOCDUCK, 784 (duckinf_t *)packet->payload) < 0)) { 785 trace_set_err(libtrace, errno, "Error using DAGIOCDUCK"); 786 return -1; 787 } 788 789 packet->type = TRACE_RT_DUCK_2_5; 768 790 769 791 /* Set the packet's tracce to point at a DUCK trace, so that the 770 792 * DUCK format functions will be called on the packet rather than the 771 793 * DAG ones */ 772 773 774 775 794 if (!DUCK.dummy_duck) 795 DUCK.dummy_duck = trace_create_dead("rt:localhost:3434"); 796 packet->trace = DUCK.dummy_duck; 797 return sizeof(duckinf_t); 776 798 } 777 799 778 800 /* Determines the amount of data available to read from the DAG card */ 779 static int dag_available(libtrace_t *libtrace) { 801 static int dag_available(libtrace_t *libtrace) 802 { 780 803 uint32_t diff = FORMAT_DATA->top - FORMAT_DATA->bottom; 781 804 … … 785 808 if (diff >= dag_record_size && FORMAT_DATA->processed < 4 * 1024 * 1024) 786 809 return diff; 787 810 788 811 /* Update the top and bottom pointers */ 789 812 FORMAT_DATA->top = dag_advance_stream(FORMAT_DATA->device->fd, 790 FORMAT_DATA->dagstream,791 &(FORMAT_DATA->bottom));792 813 FORMAT_DATA->dagstream, 814 &(FORMAT_DATA->bottom)); 815 793 816 if (FORMAT_DATA->top == NULL) { 794 817 trace_set_err(libtrace, errno, "dag_advance_stream failed!"); … … 801 824 802 825 /* Returns a pointer to the start of the next complete ERF record */ 803 static dag_record_t *dag_get_record(libtrace_t *libtrace) { 804 dag_record_t *erfptr = NULL; 805 uint16_t size; 826 static dag_record_t *dag_get_record(libtrace_t *libtrace) 827 { 828 dag_record_t *erfptr = NULL; 829 uint16_t size; 830 806 831 erfptr = (dag_record_t *)FORMAT_DATA->bottom; 807 832 if (!erfptr) 808 return NULL; 809 size = ntohs(erfptr->rlen); 810 assert( size >= dag_record_size ); 833 return NULL; 834 835 size = ntohs(erfptr->rlen); 836 assert( size >= dag_record_size ); 837 811 838 /* Make certain we have the full packet available */ 812 839 if (size > (FORMAT_DATA->top - FORMAT_DATA->bottom)) 813 840 return NULL; 841 814 842 FORMAT_DATA->bottom += size; 815 843 FORMAT_DATA->processed += size; … … 820 848 * libtrace packet */ 821 849 static int dag_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 822 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 823 850 void *buffer, libtrace_rt_types_t rt_type, 851 uint32_t flags) 852 { 824 853 dag_record_t *erfptr; 825 854 libtrace_thread_t *t; 826 855 827 856 /* If the packet previously owned a buffer that is not the buffer 828 829 857 * that contains the new packet data, we're going to need to free the 858 * old one to avoid memory leaks */ 830 859 if (packet->buffer != buffer && 831 860 packet->buf_control == TRACE_CTRL_PACKET) { … … 842 871 erfptr = (dag_record_t *)buffer; 843 872 packet->buffer = erfptr; 844 845 873 packet->header = erfptr; 874 packet->type = rt_type; 846 875 847 876 if (erfptr->flags.rxerror == 1) { 848 849 850 851 852 853 854 855 877 /* rxerror means the payload is corrupt - drop the payload 878 * by tweaking rlen */ 879 packet->payload = NULL; 880 erfptr->rlen = htons(erf_get_framing_length(packet)); 881 } else { 882 packet->payload = (char*)packet->buffer 883 + erf_get_framing_length(packet); 884 } 856 885 857 886 if (libtrace->format_data == NULL) { … … 860 889 861 890 /* Update the dropped packets counter */ 862 /* No loss counter for DSM coloured records - have to use 863 * some other API */ 864 /* Adding multithread support for this isn't actually that useful for the 865 * DAG7.5G2, as there's no way to use multiple receive streams without DSM */ 891 /* No loss counter for DSM coloured records - have to use some 892 * other API */ 866 893 if (erfptr->type == TYPE_DSM_COLOR_ETH) { 867 894 /* TODO */ … … 872 899 PERPKT_DATA(t)->drops += ntohs(erfptr->lctr); 873 900 } else { 874 if (FORMAT_DATA->seeninterface[erfptr->flags.iface] == 0) { 875 FORMAT_DATA->seeninterface[erfptr->flags.iface] = 1; 901 if (FORMAT_DATA->seeninterface[erfptr->flags.iface] 902 == 0) { 903 FORMAT_DATA->seeninterface[erfptr->flags.iface] 904 = 1; 876 905 } else { 877 906 FORMAT_DATA->drops += ntohs(erfptr->lctr); … … 879 908 } 880 909 } 881 882 910 883 911 return 0; … … 894 922 /* Pushes an ERF record onto the transmit stream */ 895 923 static int dag_dump_packet(libtrace_out_t *libtrace, 896 dag_record_t *erfptr, unsigned int pad, void *buffer) { 924 dag_record_t *erfptr, unsigned int pad, 925 void *buffer) 926 { 897 927 int size; 898 928 899 929 /* 900 * If we've got 0 bytes waiting in the txqueue, assume that we haven't901 * requested any space yet, and request some, storing the pointer at902 * FORMAT_DATA_OUT->txbuffer.930 * If we've got 0 bytes waiting in the txqueue, assume that we 931 * haven't requested any space yet, and request some, storing 932 * the pointer at FORMAT_DATA_OUT->txbuffer. 903 933 * 904 934 * The amount to request is slightly magical at the moment - it's … … 907 937 */ 908 938 if (FORMAT_DATA_OUT->waiting == 0) { 909 FORMAT_DATA_OUT->txbuffer = dag_tx_get_stream_space(FORMAT_DATA_OUT->device->fd, 910 FORMAT_DATA_OUT->dagstream, 16908288); 939 FORMAT_DATA_OUT->txbuffer = 940 dag_tx_get_stream_space(FORMAT_DATA_OUT->device->fd, 941 FORMAT_DATA_OUT->dagstream, 942 16908288); 911 943 } 912 944 … … 915 947 * are in contiguous memory 916 948 */ 917 memcpy(FORMAT_DATA_OUT->txbuffer + FORMAT_DATA_OUT->waiting,erfptr,(dag_record_size + pad)); 949 memcpy(FORMAT_DATA_OUT->txbuffer + FORMAT_DATA_OUT->waiting, erfptr, 950 (dag_record_size + pad)); 918 951 FORMAT_DATA_OUT->waiting += (dag_record_size + pad); 919 920 921 952 922 953 /* … … 925 956 */ 926 957 size = ntohs(erfptr->rlen)-(dag_record_size + pad); 927 memcpy(FORMAT_DATA_OUT->txbuffer + FORMAT_DATA_OUT->waiting,buffer,size); 958 memcpy(FORMAT_DATA_OUT->txbuffer + FORMAT_DATA_OUT->waiting, buffer, 959 size); 928 960 FORMAT_DATA_OUT->waiting += size; 929 961 … … 934 966 * case there is still data in the buffer at program exit. 935 967 */ 936 937 968 if (FORMAT_DATA_OUT->waiting >= 16*1024*1024) { 938 FORMAT_DATA_OUT->txbuffer = dag_tx_stream_commit_bytes(FORMAT_DATA_OUT->device->fd, FORMAT_DATA_OUT->dagstream, 939 FORMAT_DATA_OUT->waiting ); 969 FORMAT_DATA_OUT->txbuffer = 970 dag_tx_stream_commit_bytes(FORMAT_DATA_OUT->device->fd, 971 FORMAT_DATA_OUT->dagstream, 972 FORMAT_DATA_OUT->waiting); 940 973 FORMAT_DATA_OUT->waiting = 0; 941 974 } 942 975 943 976 return size + pad + dag_record_size; 944 945 977 } 946 978 … … 948 980 * if one is found, false otherwise */ 949 981 static bool find_compatible_linktype(libtrace_out_t *libtrace, 950 libtrace_packet_t *packet, char *type)951 { 952 //Keep trying to simplify the packet until we can find953 //something we can do with it982 libtrace_packet_t *packet, char *type) 983 { 984 /* Keep trying to simplify the packet until we can find 985 * something we can do with it */ 954 986 955 987 do { 956 *type =libtrace_to_erf_type(trace_get_link_type(packet));957 958 / / Success988 *type = libtrace_to_erf_type(trace_get_link_type(packet)); 989 990 /* Success */ 959 991 if (*type != (char)-1) 960 992 return true; … … 962 994 if (!demote_packet(packet)) { 963 995 trace_set_err_out(libtrace, 964 TRACE_ERR_NO_CONVERSION,965 "No erf type for packet (%i)",966 trace_get_link_type(packet));996 TRACE_ERR_NO_CONVERSION, 997 "No erf type for packet (%i)", 998 trace_get_link_type(packet)); 967 999 return false; 968 1000 } … … 974 1006 975 1007 /* Writes a packet to the provided DAG output trace */ 976 static int dag_write_packet(libtrace_out_t *libtrace, libtrace_packet_t *packet) {977 /* 978 * This is heavily borrowed from erf_write_packet(). Yes, CnP coding979 * sucks, sorry about that.1008 static int dag_write_packet(libtrace_out_t *libtrace, libtrace_packet_t *packet) 1009 { 1010 /* This is heavily borrowed from erf_write_packet(). Yes, CnP 1011 * coding sucks, sorry about that. 980 1012 */ 981 1013 unsigned int pad = 0; … … 986 1018 987 1019 if(!packet->header) { 988 /* No header, probably an RT packet. Lifted from 1020 /* No header, probably an RT packet. Lifted from 989 1021 * erf_write_packet(). */ 990 1022 return -1; … … 1005 1037 1006 1038 if (packet->type == TRACE_RT_DATA_ERF) { 1007 numbytes = dag_dump_packet(libtrace, 1008 header, 1009 pad, 1010 payload 1011 ); 1012 1039 numbytes = dag_dump_packet(libtrace, header, pad, payload); 1013 1040 } else { 1014 1041 /* Build up a new packet header from the existing header */ 1015 1042 1016 /* Simplify the packet first - if we can't do this, break 1043 /* Simplify the packet first - if we can't do this, break 1017 1044 * early */ 1018 1045 if (!find_compatible_linktype(libtrace,packet,&erf_type)) … … 1033 1060 1034 1061 /* Packet length (rlen includes format overhead) */ 1035 assert(trace_get_capture_length(packet)>0 1036 && trace_get_capture_length(packet)<=65536); 1037 assert(erf_get_framing_length(packet)>0 1038 && trace_get_framing_length(packet)<=65536); 1039 assert(trace_get_capture_length(packet)+erf_get_framing_length(packet)>0 1040 &&trace_get_capture_length(packet)+erf_get_framing_length(packet)<=65536); 1062 assert(trace_get_capture_length(packet) > 0 1063 && trace_get_capture_length(packet) <= 65536); 1064 assert(erf_get_framing_length(packet) > 0 1065 && trace_get_framing_length(packet) <= 65536); 1066 assert(trace_get_capture_length(packet) + 1067 erf_get_framing_length(packet) > 0 1068 && trace_get_capture_length(packet) + 1069 erf_get_framing_length(packet) <= 65536); 1041 1070 1042 1071 erfhdr.rlen = htons(trace_get_capture_length(packet) 1043 + erf_get_framing_length(packet));1072 + erf_get_framing_length(packet)); 1044 1073 1045 1074 … … 1050 1079 1051 1080 /* Write it out */ 1052 numbytes = dag_dump_packet(libtrace, 1053 &erfhdr, 1054 pad, 1055 payload); 1056 1081 numbytes = dag_dump_packet(libtrace, &erfhdr, pad, payload); 1057 1082 } 1058 1083 … … 1064 1089 * If DUCK reporting is enabled, the packet returned may be a DUCK update 1065 1090 */ 1066 static int dag_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 1067 int size = 0; 1068 struct timeval tv; 1069 dag_record_t *erfptr = NULL; 1091 static int dag_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) 1092 { 1093 int size = 0; 1094 struct timeval tv; 1095 dag_record_t *erfptr = NULL; 1070 1096 int numbytes = 0; 1071 1097 uint32_t flags = 0; … … 1078 1104 maxwait.tv_usec = 250000; 1079 1105 1080 1106 /* Check if we're due for a DUCK report */ 1081 1107 if (DUCK.last_pkt - DUCK.last_duck > DUCK.duck_freq && 1082 1083 1084 1085 1086 1087 1088 1089 1090 1108 DUCK.duck_freq != 0) { 1109 size = dag_get_duckinfo(libtrace, packet); 1110 DUCK.last_duck = DUCK.last_pkt; 1111 if (size != 0) { 1112 return size; 1113 } 1114 /* No DUCK support, so don't waste our time anymore */ 1115 DUCK.duck_freq = 0; 1116 } 1091 1117 1092 1118 /* Don't let anyone try to free our DAG memory hole! */ … … 1095 1121 /* If the packet buffer is currently owned by libtrace, free it so 1096 1122 * that we can set the packet to point into the DAG memory hole */ 1097 if (packet->buf_control == TRACE_CTRL_PACKET) { 1098 free(packet->buffer); 1099 packet->buffer = 0; 1100 } 1101 1102 if (dag_set_stream_poll(FORMAT_DATA->device->fd, 1103 FORMAT_DATA->dagstream, sizeof(dag_record_t), &maxwait, 1104 &pollwait) == -1) 1105 { 1123 if (packet->buf_control == TRACE_CTRL_PACKET) { 1124 free(packet->buffer); 1125 packet->buffer = 0; 1126 } 1127 1128 if (dag_set_stream_poll(FORMAT_DATA->device->fd, FORMAT_DATA->dagstream, 1129 sizeof(dag_record_t), &maxwait, 1130 &pollwait) == -1) { 1106 1131 trace_set_err(libtrace, errno, "dag_set_stream_poll"); 1107 1132 return -1; … … 1125 1150 /* Prepare the libtrace packet */ 1126 1151 if (dag_prepare_packet(libtrace, packet, erfptr, TRACE_RT_DATA_ERF, 1127 1152 flags)) 1128 1153 return -1; 1129 1154 1130 1155 /* Update the DUCK timer */ 1131 1156 tv = trace_get_timeval(packet); 1132 1157 DUCK.last_pkt = tv.tv_sec; 1133 1158 1134 1159 return packet->payload ? htons(erfptr->rlen) : 1135 1160 erf_get_framing_length(packet); 1136 1161 } 1137 1162 … … 1141 1166 */ 1142 1167 static libtrace_eventobj_t trace_event_dag(libtrace_t *libtrace, 1143 libtrace_packet_t *packet) { 1144 libtrace_eventobj_t event = {0,0,0.0,0}; 1168 libtrace_packet_t *packet) 1169 { 1170 libtrace_eventobj_t event = {0,0,0.0,0}; 1145 1171 dag_record_t *erfptr = NULL; 1146 1172 int numbytes; 1147 1173 uint32_t flags = 0; 1148 1174 struct timeval minwait; 1149 1175 1150 1176 minwait.tv_sec = 0; 1151 1177 minwait.tv_usec = 10000; 1152 1153 if (dag_set_stream_poll(FORMAT_DATA->device->fd, 1154 FORMAT_DATA->dagstream, 0, &minwait, 1155 &minwait) == -1) 1156 { 1178 1179 if (dag_set_stream_poll(FORMAT_DATA->device->fd, 1180 FORMAT_DATA->dagstream, 0, &minwait, 1181 &minwait) == -1) { 1157 1182 trace_set_err(libtrace, errno, "dag_set_stream_poll"); 1158 1183 event.type = TRACE_EVENT_TERMINATE; … … 1163 1188 erfptr = NULL; 1164 1189 numbytes = 0; 1165 1190 1166 1191 /* Need to call dag_available so that the top pointer will get 1167 1192 * updated, otherwise we'll never see any data! */ 1168 1193 numbytes = dag_available(libtrace); 1169 1194 1170 /* May as well not bother calling dag_get_record if 1195 /* May as well not bother calling dag_get_record if 1171 1196 * dag_available suggests that there's no data */ 1172 1197 if (numbytes != 0) … … 1176 1201 if (libtrace_halt) { 1177 1202 event.type = TRACE_EVENT_TERMINATE; 1178 } else { 1203 } else { 1179 1204 event.type = TRACE_EVENT_SLEEP; 1180 1205 event.seconds = 0.0001; … … 1182 1207 break; 1183 1208 } 1184 if (dag_prepare_packet(libtrace, packet, erfptr, 1185 1209 if (dag_prepare_packet(libtrace, packet, erfptr, 1210 TRACE_RT_DATA_ERF, flags)) { 1186 1211 event.type = TRACE_EVENT_TERMINATE; 1187 1212 break; … … 1189 1214 1190 1215 1191 event.size = trace_get_capture_length(packet) + 1192 1193 1216 event.size = trace_get_capture_length(packet) + 1217 trace_get_framing_length(packet); 1218 1194 1219 /* XXX trace_read_packet() normally applies the following 1195 1220 * config options for us, but this function is called via … … 1197 1222 1198 1223 if (libtrace->filter) { 1199 int filtret = trace_apply_filter(libtrace->filter, 1200 packet);1224 int filtret = trace_apply_filter(libtrace->filter, 1225 packet); 1201 1226 if (filtret == -1) { 1202 1227 trace_set_err(libtrace, TRACE_ERR_BAD_FILTER, 1203 1228 "Bad BPF Filter"); 1204 1229 event.type = TRACE_EVENT_TERMINATE; 1205 1230 break; … … 1212 1237 * a sleep event in this case, like we used to 1213 1238 * do! */ 1214 1239 libtrace->filtered_packets ++; 1215 1240 trace_clear_cache(packet); 1216 1241 continue; 1217 1242 } 1218 1243 1219 1244 event.type = TRACE_EVENT_PACKET; 1220 1245 } else { … … 1225 1250 trace_set_capture_length(packet, libtrace->snaplen); 1226 1251 } 1227 1252 libtrace->accepted_packets ++; 1228 1253 break; 1229 } while 1254 } while(1); 1230 1255 1231 1256 return event; … … 1233 1258 1234 1259 /* Gets the number of dropped packets */ 1235 static uint64_t dag_get_dropped_packets(libtrace_t *trace) { 1260 static uint64_t dag_get_dropped_packets(libtrace_t *trace) 1261 { 1236 1262 uint64_t sum = 0; 1237 1263 int i, tot; 1238 1264 1239 1265 if (trace->format_data == NULL) 1240 return (uint64_t) -1;1266 return (uint64_t) - 1; 1241 1267 1242 1268 if (DATA(trace)->per_thread) { … … 1245 1271 for (i = 0; i < tot; i++) { 1246 1272 printf("t%d: drops %" PRIu64 "\n", 1247 1273 DATA(trace)->per_thread[i].drops); 1248 1274 sum += DATA(trace)->per_thread[i].drops; 1249 1275 } … … 1257 1283 /* Prints some semi-useful help text about the DAG format module */ 1258 1284 static void dag_help(void) { 1259 printf("dag format module: $Revision: 1755 $\n"); 1260 printf("Supported input URIs:\n"); 1261 printf("\tdag:/dev/dagn\n"); 1262 printf("\n"); 1263 printf("\te.g.: dag:/dev/dag0\n"); 1264 printf("\n"); 1265 printf("Supported output URIs:\n"); 1266 printf("\tnone\n"); 1267 printf("\n"); 1268 } 1269 1270 static int dag_pstart_input(libtrace_t *libtrace) { 1285 printf("dag format module: $Revision: 1755 $\n"); 1286 printf("Supported input URIs:\n"); 1287 printf("\tdag:/dev/dagn\n"); 1288 printf("\n"); 1289 printf("\te.g.: dag:/dev/dag0\n"); 1290 printf("\n"); 1291 printf("Supported output URIs:\n"); 1292 printf("\tnone\n"); 1293 printf("\n"); 1294 } 1295 1296 static int dag_pstart_input(libtrace_t *libtrace) 1297 { 1271 1298 char *scan, *tok; 1272 1299 uint16_t stream_count = 0, max_streams; … … 1276 1303 int iserror = 0; 1277 1304 1278 /* Check we aren't trying to create more threads than the DAG card can 1305 /* Check we aren't trying to create more threads than the DAG card can 1279 1306 * handle */ 1280 1307 max_streams = dag_rx_get_stream_count(FORMAT_DATA->device->fd); 1281 1308 if (libtrace->perpkt_thread_count > max_streams) { 1282 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, "trying to create too " 1283 "many threads (max is %u)", max_streams); 1309 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, 1310 "trying to create too many threads (max is %u)", 1311 max_streams); 1284 1312 iserror = 1; 1285 1313 goto cleanup; … … 1288 1316 /* Create the thread structures */ 1289 1317 per_thread = calloc(libtrace->perpkt_thread_count, 1290 1318 sizeof(struct dag_per_thread_t)); 1291 1319 FORMAT_DATA->per_thread = per_thread; 1292 1320 1293 1321 /* Get the stream names from the uri */ 1294 1322 if ((scan = strchr(libtrace->uridata, ',')) == NULL) { 1295 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, "format uri doesn't "1296 "specify the DAG streams");1323 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, 1324 "format uri doesn't specify the DAG streams"); 1297 1325 iserror = 1; 1298 1326 goto cleanup; … … 1300 1328 1301 1329 scan++; 1302 1330 1303 1331 tok = strtok(scan, ","); 1304 1332 while (tok != NULL) { 1305 1333 /* Ensure we haven't specified too many streams */ 1306 1334 if (stream_count >= libtrace->perpkt_thread_count) { 1307 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, "format uri specifies too " 1308 "many streams. Max is %u", max_streams); 1335 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, 1336 "format uri specifies too many streams. " 1337 "Max is %u", max_streams); 1309 1338 iserror = 1; 1310 1339 goto cleanup; … … 1322 1351 /* Free the per_thread memory */ 1323 1352 free(per_thread); 1324 1325 1353 return -1; 1326 1354 } else { … … 1332 1360 1333 1361 /* TODO: Fold this into dag_available */ 1334 static int dag_pavailable(libtrace_t *libtrace, libtrace_thread_t *t) { 1362 static int dag_pavailable(libtrace_t *libtrace, libtrace_thread_t *t) 1363 { 1335 1364 uint32_t diff = PERPKT_DATA(t)->top - PERPKT_DATA(t)->bottom; 1336 1365 … … 1338 1367 * dag_advance_stream, then we should call it again to allow the 1339 1368 * space occupied by that 4MB to be released */ 1340 if (diff >= dag_record_size && PERPKT_DATA(t)->processed < 4 * 1024 * 1024) 1369 if (diff >= dag_record_size && PERPKT_DATA(t)->processed < 1370 4*1024*1024) 1341 1371 return diff; 1342 1372 1343 1373 /* Update top and bottom pointers */ 1344 1374 PERPKT_DATA(t)->top = dag_advance_stream(PERPKT_DATA(t)->device->fd, 1345 1346 1375 PERPKT_DATA(t)->stream, 1376 &(PERPKT_DATA(t)->bottom)); 1347 1377 1348 1378 if (PERPKT_DATA(t)->top == NULL) { … … 1358 1388 /* TODO: Fold this into dag_get_record */ 1359 1389 static dag_record_t *dag_pget_record(libtrace_t *libtrace, 1360 libtrace_thread_t *t) { 1390 libtrace_thread_t *t) 1391 { 1361 1392 dag_record_t *erfptr = NULL; 1362 1393 uint16_t size; … … 1375 1406 PERPKT_DATA(t)->bottom += size; 1376 1407 PERPKT_DATA(t)->processed += size; 1377 1408 1378 1409 return erfptr; 1379 1410 } 1380 1411 1381 1412 static int dag_pread_packet(libtrace_t *libtrace, libtrace_thread_t *t, 1382 libtrace_packet_t *packet) { 1413 libtrace_packet_t *packet) 1414 { 1383 1415 dag_record_t *erfptr = NULL; 1384 1416 int numbytes = 0; … … 1404 1436 1405 1437 /* Configure DAG card stream polling */ 1406 if (dag_set_stream_poll(PERPKT_DATA(t)->device->fd, PERPKT_DATA(t)->stream, 1407 sizeof(dag_record_t), &maxwait, &pollwait) < 0) { 1438 if (dag_set_stream_poll(PERPKT_DATA(t)->device->fd, 1439 PERPKT_DATA(t)->stream, sizeof(dag_record_t), 1440 &maxwait, &pollwait) < 0) { 1408 1441 trace_set_err(libtrace, errno, "dag_set_stream_poll"); 1409 1442 return -1; … … 1419 1452 return 0; 1420 1453 1421 /* Check message queue to see if we should abort early */ 1454 /* Check message queue to see if we should 1455 * abort early */ 1422 1456 if (libtrace_message_queue_count(&t->messages) > 0) 1423 1457 return -2; … … 1432 1466 /* Prepare the libtrace packet */ 1433 1467 if (dag_prepare_packet(libtrace, packet, erfptr, TRACE_RT_DATA_ERF, 1434 1468 flags)) 1435 1469 return -1; 1436 1470 … … 1441 1475 } 1442 1476 1443 static int dag_ppause_input(libtrace_t *libtrace) { 1477 static int dag_ppause_input(libtrace_t *libtrace) 1478 { 1444 1479 int i, tot = libtrace->perpkt_thread_count; 1445 1480 struct dag_per_thread_t *t_data; … … 1451 1486 1452 1487 if (dag_stop_stream(t_data->device->fd, 1453 t_data->stream) < 0) { 1454 trace_set_err(libtrace, errno, "can't stop DAG stream #%u", 1455 t_data->stream); 1488 t_data->stream) < 0) { 1489 trace_set_err(libtrace, errno, 1490 "can't stop DAG stream #%u", 1491 t_data->stream); 1456 1492 return -1; 1457 1493 } 1458 1494 1459 1495 if (dag_detach_stream(t_data->device->fd, 1460 t_data->stream) < 0) { 1461 trace_set_err(libtrace, errno, "can't detach DAG stream #%u", 1462 t_data->stream); 1496 t_data->stream) < 0) { 1497 trace_set_err(libtrace, errno, 1498 "can't detach DAG stream #%u", 1499 t_data->stream); 1463 1500 return -1; 1464 1501 } … … 1473 1510 1474 1511 static int dag_pconfig_input(libtrace_t *libtrace, 1475 trace_parallel_option_t option, void *value) {1476 1512 trace_parallel_option_t option, void *value) 1513 { 1477 1514 /* We don't support any of these! Normally you configure the DAG card 1478 1515 * externally. */ … … 1493 1530 1494 1531 static int dag_pregister_thread(libtrace_t *libtrace, libtrace_thread_t *t, 1495 bool reader) { 1532 bool reader) 1533 { 1496 1534 /* XXX: This function gets run sequentially for all 1497 1535 * threads. Should investigate making it parallel as draining the … … 1499 1537 */ 1500 1538 uint8_t *top, *bottom; 1501 uint8_t diff = 0; /* XXX: Investigate this type, as I would assume the value 1502 * could be larger than 255 */ 1539 /* XXX: Investigate this type, as I would assume the value 1540 * could be larger than 255 */ 1541 uint8_t diff = 0; 1503 1542 struct timeval zero, nopoll; 1504 1543 … … 1513 1552 if (t->type == THREAD_PERPKT) { 1514 1553 /* Pass the per thread data to the thread */ 1515 t->format_data = &FORMAT_DATA->per_thread[t->perpkt_num]; 1554 t->format_data = 1555 &FORMAT_DATA->per_thread[t->perpkt_num]; 1516 1556 1517 1557 /* Attach and start the DAG stream */ 1518 printf("t%u: starting and attaching stream #%u\n", t->perpkt_num,1519 1558 printf("t%u: starting and attaching stream #%u\n", 1559 t->perpkt_num, PERPKT_DATA(t)->stream); 1520 1560 if (dag_attach_stream(PERPKT_DATA(t)->device->fd, 1521 PERPKT_DATA(t)->stream, 0, 0) < 0) { 1522 trace_set_err(libtrace, errno, "can't attach DAG stream #%u", 1523 PERPKT_DATA(t)->stream); 1561 PERPKT_DATA(t)->stream, 0, 1562 0) < 0) { 1563 trace_set_err(libtrace, errno, 1564 "can't attach DAG stream #%u", 1565 PERPKT_DATA(t)->stream); 1524 1566 return -1; 1525 1567 } 1526 1568 if (dag_start_stream(PERPKT_DATA(t)->device->fd, 1527 PERPKT_DATA(t)->stream) < 0) { 1528 trace_set_err(libtrace, errno, "can't start DAG stream #%u", 1529 PERPKT_DATA(t)->stream); 1569 PERPKT_DATA(t)->stream) < 0) { 1570 trace_set_err(libtrace, errno, 1571 "can't start DAG stream #%u", 1572 PERPKT_DATA(t)->stream); 1530 1573 return -1; 1531 1574 } … … 1533 1576 /* Ensure that dag_advance_stream will return without blocking */ 1534 1577 if(dag_set_stream_poll(PERPKT_DATA(t)->device->fd, 1535 PERPKT_DATA(t)->stream, 0, &zero, 1536 &nopoll) < 0) { 1537 trace_set_err(libtrace, errno, "dag_set_stream_poll failed!"); 1578 PERPKT_DATA(t)->stream, 0, &zero, 1579 &nopoll) < 0) { 1580 trace_set_err(libtrace, errno, 1581 "dag_set_stream_poll failed!"); 1538 1582 return -1; 1539 1583 } … … 1541 1585 /* Clear all the data from the memory hole */ 1542 1586 do { 1543 top = dag_advance_stream(PERPKT_DATA(t)->device->fd, 1544 PERPKT_DATA(t)->stream, 1545 &bottom); 1587 top = dag_advance_stream(PERPKT_DATA(t)-> 1588 device->fd, 1589 PERPKT_DATA(t)->stream, 1590 &bottom); 1546 1591 1547 1592 assert(top && bottom); … … 1566 1611 1567 1612 static struct libtrace_format_t dag = { 1568 1569 1570 1613 "dag", 1614 "$Id$", 1615 TRACE_FORMAT_ERF, 1571 1616 dag_probe_filename, /* probe filename */ 1572 1617 NULL, /* probe magic */ 1573 1574 1575 1576 1618 dag_init_input, /* init_input */ 1619 dag_config_input, /* config_input */ 1620 dag_start_input, /* start_input */ 1621 dag_pause_input, /* pause_input */ 1577 1622 dag_init_output, /* init_output */ 1578 1623 NULL, /* config_output */ 1579 1624 dag_start_output, /* start_output */ 1580 1625 dag_fin_input, /* fin_input */ 1581 1626 dag_fin_output, /* fin_output */ 1582 1583 1627 dag_read_packet, /* read_packet */ 1628 dag_prepare_packet, /* prepare_packet */ 1584 1629 NULL, /* fin_packet */ 1585 1630 dag_write_packet, /* write_packet */ 1586 1587 1588 1589 1590 1591 1631 erf_get_link_type, /* get_link_type */ 1632 erf_get_direction, /* get_direction */ 1633 erf_set_direction, /* set_direction */ 1634 erf_get_erf_timestamp, /* get_erf_timestamp */ 1635 NULL, /* get_timeval */ 1636 NULL, /* get_seconds */ 1592 1637 NULL, /* get_timespec */ 1593 1594 1595 1596 1597 1598 1599 1638 NULL, /* seek_erf */ 1639 NULL, /* seek_timeval */ 1640 NULL, /* seek_seconds */ 1641 erf_get_capture_length, /* get_capture_length */ 1642 erf_get_wire_length, /* get_wire_length */ 1643 erf_get_framing_length, /* get_framing_length */ 1644 erf_set_capture_length, /* set_capture_length */ 1600 1645 NULL, /* get_received_packets */ 1601 1646 NULL, /* get_filtered_packets */ 1602 1647 dag_get_dropped_packets, /* get_dropped_packets */ 1603 1648 NULL, /* get_captured_packets */ 1604 1605 1606 1607 1649 NULL, /* get_fd */ 1650 trace_event_dag, /* trace_event */ 1651 dag_help, /* help */ 1652 NULL, /* next pointer */ 1608 1653 {true, 0}, /* live packet capture, thread limit TBD */ 1609 1654 dag_pstart_input, … … 1616 1661 }; 1617 1662 1618 void dag_constructor(void) { 1663 void dag_constructor(void) 1664 { 1619 1665 register_format(&dag); 1620 1666 }
Note: See TracChangeset
for help on using the changeset viewer.