Changeset eb27e8e
- Timestamp:
- 12/18/06 16:24:42 (16 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, 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:
- 8cecc7c
- Parents:
- 92a37b0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_erf.c
r92a37b0 reb27e8e 108 108 struct { 109 109 void *buf; 110 unsigned bottom; 111 unsigned top; 112 unsigned diff; 113 unsigned curr; 114 unsigned offset; 110 uint32_t diff; 111 uint32_t offset; 112 #ifdef DAG_VERSION_2_4 113 uint32_t bottom; 114 uint32_t top; 115 #else 116 uint8_t *bottom; 117 uint8_t *top; 115 118 unsigned int dagstream; 119 #endif 116 120 } dag; 117 121 #endif … … 164 168 return -1; 165 169 } 166 170 #ifdef DAG_VERSION_2_4 171 DAG.top = 0; 172 DAG.bottom = 0; 173 #else 174 DAG.top = NULL; 175 DAG.bottom = NULL; 167 176 DAG.dagstream = 0; 168 177 #endif 169 178 if (S_ISCHR(buf.st_mode)) { 170 179 /* DEVICE */ … … 519 528 #endif 520 529 521 static int dag_ read(libtrace_t *libtrace, int block_flag) {530 static int dag_available(libtrace_t *libtrace) { 522 531 523 532 if (DAG.diff != 0) … … 525 534 526 535 DAG.bottom = DAG.top; 527 536 #ifdef DAG_VERSION_2_4 528 537 DAG.top = dag_offset( 529 538 INPUT.fd, 530 539 &(DAG.bottom), 531 block_flag); 532 540 DAGF_NONBLOCK); 541 542 #else 543 DAG.top = dag_advance_stream(INPUT.fd, DAG.dagstream, &(DAG.bottom)); 544 #endif 533 545 DAG.diff = DAG.top - DAG.bottom; 534 546 … … 537 549 } 538 550 539 /* FIXME: dag_read_packet shouldn't update the pointers, dag_fin_packet 540 * should do that. 541 */ 542 static int dag_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 543 int numbytes; 544 int size; 545 struct timeval tv; 551 dag_record_t *dag_get_record(libtrace_t *libtrace) { 546 552 dag_record_t *erfptr; 547 char *next_record = NULL; 548 549 if (DUCK.last_pkt - DUCK.last_duck > DUCK.duck_freq && 550 DUCK.duck_freq != 0) { 551 size = dag_get_duckinfo(libtrace, packet); 552 DUCK.last_duck = DUCK.last_pkt; 553 if (size != 0) { 554 return size; 555 } 556 /* No DUCK support, so don't waste our time anymore */ 557 DUCK.duck_freq = 0; 558 } 559 560 if (packet->buf_control == TRACE_CTRL_PACKET) { 561 packet->buf_control = TRACE_CTRL_EXTERNAL; 562 free(packet->buffer); 563 packet->buffer = 0; 564 } 565 566 packet->type = TRACE_RT_DATA_ERF; 553 uint16_t size; 567 554 #ifdef DAG_VERSION_2_4 568 if ((numbytes = dag_read(libtrace,0)) < 0) 569 return numbytes; 570 assert(numbytes>0); 571 572 /*DAG always gives us whole packets */ 573 erfptr = (dag_record_t *) ((char *)DAG.buf + 574 (DAG.bottom + DAG.offset)); 555 erfptr = (dag_record_t *) ((char *)DAG.buf + (DAG.bottom + DAG.offset)); 575 556 #else 576 next_record = (char *)dag_rx_stream_next_record(INPUT.fd, 0); 577 erfptr = (dag_record_t *)next_record; 557 erfptr = (dag_record_t *) DAG.bottom; 578 558 #endif 579 559 size = ntohs(erfptr->rlen); 580 560 assert( size >= dag_record_size ); 581 assert( size < LIBTRACE_PACKET_BUFSIZE); 582 561 DAG.offset += size; 562 DAG.diff -= size; 563 return erfptr; 564 } 565 566 void dag_form_packet(dag_record_t *erfptr, libtrace_packet_t *packet) { 583 567 packet->buffer = erfptr; 584 568 packet->header = erfptr; 585 if ( ((dag_record_t *)packet->buffer)->flags.rxerror == 1) {569 if (erfptr->flags.rxerror == 1) { 586 570 /* rxerror means the payload is corrupt - drop it 587 571 * by tweaking rlen */ … … 593 577 } 594 578 595 #ifdef DAG_VERSION_2_4 596 DAG.offset += size; 597 DAG.diff -= size; 598 #endif 579 } 580 581 /* FIXME: dag_read_packet shouldn't update the pointers, dag_fin_packet 582 * should do that. 583 */ 584 static int dag_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 585 int numbytes; 586 int size = 0; 587 struct timeval tv; 588 dag_record_t *erfptr; 589 590 if (DUCK.last_pkt - DUCK.last_duck > DUCK.duck_freq && 591 DUCK.duck_freq != 0) { 592 size = dag_get_duckinfo(libtrace, packet); 593 DUCK.last_duck = DUCK.last_pkt; 594 if (size != 0) { 595 return size; 596 } 597 /* No DUCK support, so don't waste our time anymore */ 598 DUCK.duck_freq = 0; 599 } 600 601 if (packet->buf_control == TRACE_CTRL_PACKET) { 602 packet->buf_control = TRACE_CTRL_EXTERNAL; 603 free(packet->buffer); 604 packet->buffer = 0; 605 } 606 607 packet->type = TRACE_RT_DATA_ERF; 608 609 do { 610 numbytes = dag_available(libtrace); 611 if (numbytes < 0) 612 return numbytes; 613 } while (numbytes == 0); 614 615 erfptr = dag_get_record(libtrace); 616 dag_form_packet(erfptr, packet); 617 599 618 tv = trace_get_timeval(packet); 600 619 DUCK.last_pkt = tv.tv_sec; 601 602 return packet->payload ? size : erf_get_framing_length(packet); 620 return packet->payload ? ntohs(erfptr->rlen) : erf_get_framing_length(packet); 603 621 } 604 622 605 623 static int dag_start_input(libtrace_t *libtrace) { 624 struct timeval zero, nopoll; 625 zero.tv_sec = 0; 626 zero.tv_usec = 0; 627 nopoll = zero; 628 606 629 #ifdef DAG_VERSION_2_4 607 630 if(dag_start(INPUT.fd) < 0) { … … 619 642 return -1; 620 643 } 644 dag_set_stream_poll(INPUT.fd, DAG.dagstream, 0, &zero, &nopoll); 621 645 #endif 622 646 /* dags appear to have a bug where if you call dag_start after … … 624 648 * happen. flush the memory hole 625 649 */ 626 while(dag_ read(libtrace,DAGF_NONBLOCK)!=0)650 while(dag_available(libtrace)!=0) 627 651 DAG.diff=0; 628 652 return 0; … … 903 927 } 904 928 905 data = dag_ read(trace, DAGF_NONBLOCK);929 data = dag_available(trace); 906 930 907 931 if (data > 0) { 908 932 event.size = dag_read_packet(trace,packet); 909 DATA(trace)->dag.diff -= event.size;933 //DATA(trace)->dag.diff -= event.size; 910 934 if (trace->filter) { 911 935 if (trace_apply_filter(trace->filter, packet)) {
Note: See TracChangeset
for help on using the changeset viewer.