Changeset 3b8a5ef
- Timestamp:
- 11/30/05 15:43:30 (15 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:
- 2adf051
- Parents:
- 08594b8
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/Makefile.am
r14d8a63 r3b8a5ef 2 2 include_HEADERS = libtrace.h dagformat.h wag.h lt_inttypes.h daglegacy.h 3 3 4 libtrace_la_SOURCES = trace.c fifo.c fifo.h common.h format_template.c format_erf.c format_pcap.c format_wag.c format_helper.c format_helper.h parse_cmd.c parse_cmd.h libtrace_int.h lt_inttypes.h 4 extra_DIST = format_template.c 5 libtrace_la_SOURCES = trace.c fifo.c fifo.h common.h format_erf.c format_pcap.c format_wag.c format_helper.c format_helper.h parse_cmd.c parse_cmd.h libtrace_int.h lt_inttypes.h 5 6 if DAG2_4 6 7 nodist_libtrace_la_SOURCES = dagopts.c dagapi.c -
lib/daglegacy.h
rd91dd4e r3b8a5ef 5 5 uint64_t ts; 6 6 uint32_t crc; 7 } legacy_cell_t;7 } __attribute__ ((packed)) legacy_cell_t; 8 8 9 9 typedef struct legacy_ether { 10 10 uint64_t ts; 11 11 uint16_t wlen; 12 } legacy_ether_t;12 } __attribute__ ((packed)) legacy_ether_t; 13 13 14 14 typedef struct legacy_pos { … … 16 16 uint32_t slen; 17 17 uint32_t wlen; 18 } legacy_pos_t;18 } __attribute__ ((packed)) legacy_pos_t; 19 19 20 20 #endif -
lib/format_erf.c
r14d8a63 r3b8a5ef 200 200 } 201 201 202 static int legacyeth_get_framing_length(const struct libtrace_packet_t *packet )202 static int legacyeth_get_framing_length(const struct libtrace_packet_t *packet UNUSED) 203 203 { 204 /* the legacy ethernet format consists of:205 * uint64_t ts;206 * uint16_t wlen;207 * The legacy ethernet framing is therefore five (5) octets;208 */209 204 return sizeof(legacy_ether_t); 210 205 } 211 206 212 static int legacypos_get_framing_length(const struct libtrace_packet_t *packet )207 static int legacypos_get_framing_length(const struct libtrace_packet_t *packet UNUSED) 213 208 { 214 /* the legacy POS format consists of:215 * uint64_t ts;216 * uint32_t slen;217 * uint32_t wlen;218 * The legacy pos framing is therefore eight (8) octets;219 */220 209 return sizeof(legacy_pos_t); 221 210 } 222 211 223 static int legacyatm_get_framing_length(const struct libtrace_packet_t *packet )212 static int legacyatm_get_framing_length(const struct libtrace_packet_t *packet UNUSED) 224 213 { 225 /* the legacy ATM format consists of:226 * uint64_t ts;227 * uint32_t crc;228 * The legacy atm framing is therefore six (6) octets;229 */230 214 return sizeof(legacy_cell_t); 231 215 } … … 241 225 // STDIN 242 226 libtrace->sourcetype = STDIN; 243 if ((INPUT.file = LIBTRACE_FDOPEN(fileno(stdin), "r")) < 0) { 244 perror("libtrace_fdopen:"); 245 return 0; 246 } 227 INPUT.file = LIBTRACE_FDOPEN(fileno(stdin), "r"); 247 228 248 229 … … 507 488 static int legacy_read_packet(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) { 508 489 int numbytes; 509 int size;510 490 void *buffer = packet->buffer; 511 void *buffer2 = buffer;512 int rlen;513 514 if (packet->buf_control == EXTERNAL) {515 packet->buf_control = PACKET;516 packet = malloc(LIBTRACE_PACKET_BUFSIZE);517 }518 491 519 492 if ((numbytes=LIBTRACE_READ(INPUT.file, 520 493 buffer, 521 dag_record_size)) == -1) {494 64)) == -1) { 522 495 perror("libtrace_read"); 523 496 return -1; 524 497 } 525 if (numbytes == 0) {526 return 0;527 }528 529 // legacy - 64byte captures530 // type is TYPE_LEGACY531 rlen = 64;532 size = rlen - dag_record_size;533 buffer2 = buffer + dag_record_size;534 535 if ((numbytes=LIBTRACE_READ(INPUT.file,536 buffer2,537 size)) == -1) {538 perror("libtrace_read");539 return -1;540 }541 498 packet->status.type = RT_DATA; 542 499 packet->status.message = 0; 500 packet->size = 64; 543 501 544 502 packet->header = packet->buffer; 545 packet->payload = packet-> trace->format->get_link(packet);546 547 packet->size = rlen;548 return rlen;503 packet->payload = packet->buffer + 504 packet->trace->format->get_framing_length(packet); 505 506 return 64; 549 507 550 508 } … … 634 592 static int rtclient_read_packet(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) { 635 593 int numbytes = 0; 636 int size = 0;637 594 char buf[RP_BUFSIZE]; 638 595 int read_required = 0; … … 790 747 static void *legacypos_get_link(const struct libtrace_packet_t *packet) { 791 748 return (void *)packet->payload; 792 /* 793 const void *posptr = 0; 794 posptr = ((uint8_t *)packet-> + 795 legacypos_get_framing_length(packet)); 796 return (void *)posptr; 797 */ 798 } 799 800 static libtrace_linktype_t legacypos_get_link_type(const struct libtrace_packet_t *packet) { 749 } 750 751 static libtrace_linktype_t legacypos_get_link_type(const struct libtrace_packet_t *packet UNUSED) { 801 752 return TRACE_TYPE_LEGACY_POS; 802 753 } … … 804 755 static void *legacyatm_get_link(const struct libtrace_packet_t *packet) { 805 756 return (void *)packet->payload; 806 /* 807 const void *atmptr = 0; 808 atmptr = ((uint8_t *)packet->buffer + 809 legacyatm_get_framing_length(packet)); 810 return (void *)atmptr; 811 */ 812 } 813 814 static libtrace_linktype_t legacyatm_get_link_type(const struct libtrace_packet_t *packet) { 757 } 758 759 static libtrace_linktype_t legacyatm_get_link_type(const struct libtrace_packet_t *packet UNUSED) { 815 760 return TRACE_TYPE_LEGACY_ATM; 816 761 } … … 818 763 static void *legacyeth_get_link(const struct libtrace_packet_t *packet) { 819 764 return (void *)packet->payload; 820 /* 821 const void *ethptr = 0; 822 ethptr = ((uint8_t *)packet->buffer + 823 legacyeth_get_framing_length(packet)); 824 return (void *)ethptr; 825 */ 826 } 827 828 static libtrace_linktype_t legacyeth_get_link_type(const struct libtrace_packet_t *packet) { 765 } 766 767 static libtrace_linktype_t legacyeth_get_link_type(const struct libtrace_packet_t *packet UNUSED) { 829 768 return TRACE_TYPE_LEGACY_ETH; 830 769 } … … 834 773 static void *erf_get_link(const struct libtrace_packet_t *packet) { 835 774 return (void *)packet->payload; 836 /* const void *ethptr = 0;837 dag_record_t *erfptr = 0;838 erfptr = (dag_record_t *)packet->header;839 840 if (erfptr->flags.rxerror == 1) {841 return NULL;842 }843 ethptr = ((uint8_t *)packet->buffer +844 erf_get_framing_length(packet));845 return (void *)ethptr;846 */847 848 775 } 849 776 … … 890 817 } 891 818 892 static int legacyatm_get_wire_length(const struct libtrace_packet_t *packet ) {819 static int legacyatm_get_wire_length(const struct libtrace_packet_t *packet UNUSED) { 893 820 return 53; 894 821 } -
lib/format_pcap.c
r14d8a63 r3b8a5ef 207 207 static void trace_pcap_handler(u_char *user, const struct pcap_pkthdr *pcaphdr, const u_char *pcappkt) { 208 208 struct libtrace_packet_t *packet = (struct libtrace_packet_t *)user; 209 void *buffer = packet->buffer;210 209 int numbytes = 0; 211 212 // This is ugly, but seems to be needed. We want both the 213 // header and the payload in the same block of memory (packet->buffer) 214 //memcpy(buffer,pcaphdr,sizeof(struct pcap_pkthdr)); 210 211 // pcap provides us with the right bits, in it's own buffers. 212 // We hijack them. 215 213 numbytes = pcaphdr->len; 216 //memcpy(buffer + sizeof(struct pcap_pkthdr),pcappkt,numbytes); 217 218 //packet->header = packet->buffer; 219 //packet->payload = packet->header + sizeof(struct pcap_pkthdr); 214 220 215 packet->header = (void *)pcaphdr; 221 216 packet->payload = (void *)pcappkt; … … 379 374 } 380 375 381 static int pcap_get_framing_length(const struct libtrace_packet_t *packet ) {376 static int pcap_get_framing_length(const struct libtrace_packet_t *packet UNUSED) { 382 377 return sizeof(struct pcap_pkthdr); 383 378 } -
lib/format_wag.c
r3840760 r3b8a5ef 386 386 } 387 387 388 static int wag_get_framing_length(const struct libtrace_packet_t *packet ) {388 static int wag_get_framing_length(const struct libtrace_packet_t *packet UNUSED) { 389 389 return sizeof(struct wag_data_frame); 390 390 } -
lib/libtrace.h
r14d8a63 r3b8a5ef 59 59 #include <netinet/in.h> 60 60 /** API version as 2 byte hex digits, eg 0xXXYYZZ */ 61 #define LIBTRACE_API_VERSION 0x0 20018 /* 2.0.24*/61 #define LIBTRACE_API_VERSION 0x030000 /* 3.0.00 */ 62 62 63 63 #ifdef __cplusplus … … 70 70 #if __GNUC__ >= 3 71 71 # define SIMPLE_FUNCTION __attribute__((pure)) 72 # define UNUSED __attribute__((unused)) 72 73 #else 73 74 # define SIMPLE_FUNCTION 75 # define UNUSED 74 76 #endif 75 77 … … 205 207 } __attribute__ ((packed)) libtrace_icmp_t; 206 208 209 /** LLC/SNAP header */ 210 typedef struct libtrace_llcsnap 211 { 212 u_int8_t dsap; 213 u_int8_t ssap; 214 u_int8_t control; 215 u_int32_t oui:24; 216 u_int16_t type; 217 } __attribute__ ((packed)) libtrace_llcsnap_t; 218 207 219 /** 802.3 frame */ 208 220 typedef struct libtrace_ether … … 234 246 u_int8_t clp:1; 235 247 u_int8_t hec; 236 u_int16_t ether_type;237 248 } __attribute__ ((packed)) libtrace_atm_cell; 238 249 -
lib/trace.c
r08594b8 r3b8a5ef 567 567 void *trace_get_link(const struct libtrace_packet_t *packet) { 568 568 return (void *)packet->payload; 569 } 570 569 571 /* 570 const void *ethptr = 0;571 572 assert(packet->size>0 && packet->size<65536);573 574 if (packet->trace->format->get_link) {575 ethptr = packet->trace->format->get_link(packet);576 }577 return (void *)ethptr;578 */579 }580 581 572 typedef struct legacy_framing { 582 573 uint64_t ts; 583 574 uint32_t crc; 584 575 uint32_t header; 585 uint32_t data[12]; / * pad to 64 bytes */576 uint32_t data[12]; // pad to 64 bytes 586 577 } legacy_framing_t; 578 */ 587 579 588 580 /* get a pointer to the IP header (if any) … … 612 604 ipptr = NULL; 613 605 614 if (eth->type == 0x0008) { 615 ipptr=(void*)eth->data; 616 } else if (eth->type == 0x0081) { 617 // VLAN 618 if ((*(uint16_t *)(eth + 16)) == 0x0008) { 619 ipptr = (void*)eth->data + 4; 620 } 606 if (ntohs(eth->type) == 0x0800) { 607 ipptr=((void*)eth) + sizeof(*eth); 608 } else if (ntohs(eth->type) == 0x8100) { 609 struct libtrace_8021q *vlanhdr = 610 (struct libtrace_8021q *)eth; 611 if (ntohs(vlanhdr->vlan_ether_type) 612 == 0x0800) { 613 ipptr=((void*)eth) + 614 sizeof(*vlanhdr); 615 } 621 616 } 622 617 } … … 634 629 ipptr = NULL; 635 630 636 if ( eth->ether_type==0x0008) {637 ipptr = ((void *)eth) + 14;638 } else if ( eth->ether_type == 0x0081) {631 if (ntohs(eth->ether_type)==0x0800) { 632 ipptr = ((void *)eth) + sizeof(*eth); 633 } else if (ntohs(eth->ether_type) == 0x8100) { 639 634 struct libtrace_8021q *vlanhdr = 640 635 (struct libtrace_8021q *)eth; 641 if (vlanhdr->vlan_ether_type == 0x0008) { 642 ipptr = ((void *)eth) + 18; 636 if (ntohs(vlanhdr->vlan_ether_type) 637 == 0x0800) { 638 ipptr = ((void *)eth) + 639 sizeof(*vlanhdr); 643 640 } 644 641 } … … 697 694 { 698 695 // 64 byte capture. 699 struct libtrace_ atm_cell *cell =696 struct libtrace_llcsnap *llc = 700 697 trace_get_link(packet); 701 if (ntohs(cell->ether_type) == 0x0800) { 702 ipptr = ((void *)cell) + sizeof(*cell); 698 699 // advance the llc ptr +4 into the link layer. 700 // need to check what is in these 4 bytes. 701 // don't have time! 702 llc = (void *)llc + 4; 703 if (ntohs(llc->type) == 0x0800) { 704 ipptr = ((void *)llc) + sizeof(*llc); 703 705 } else { 704 706 ipptr = NULL; -
libpacketdump/libpacketdump.cc
r3840760 r3b8a5ef 64 64 65 65 printf("%s",ctime(&sec)); 66 decode_next(link,packet->size - trace_get_framing_length(packet),"link",trace_get_link_type(packet)); 66 decode_next(link,packet->size-trace_get_framing_length(packet), 67 "link", 68 trace_get_link_type(packet)); 67 69 } 68 70 -
libpacketdump/link_10.cc
r950d54a r3b8a5ef 6 6 #include <map> 7 7 #include "libpacketdump.h" 8 #include "libtrace.h" 8 9 9 10 extern "C" 10 11 void decode(int link_type,char *packet,int len) 11 12 { 12 printf(" Legacy ATM:"); 13 /* 14 if (len>=6) 15 printf(" %s",ether_ntoa((struct ether_addr*)packet)); 16 else { 17 printf("[|Truncated]\n"); 18 return; 19 } 20 if (len>=12) 21 printf(" %s",ether_ntoa((struct ether_addr*)(packet+6))); 22 else { 23 printf("[|Truncated]\n"); 24 return; 25 } 26 */ 27 if (len>=24) { 28 uint16_t type = htons(*(uint16_t*)(packet+22)); 13 // ATM 14 printf(" Legacy Framing:"); 15 if (len>=12) { 16 uint16_t type = htons(*(uint16_t*)(packet+sizeof(libtrace_atm_cell)+4)); 29 17 printf(" %04x\n",type); 30 decode_next(packet+24,len-24,"eth",type); 18 decode_next(packet+sizeof(libtrace_atm_cell) + 4, 19 len-sizeof(libtrace_atm_cell) -4, 20 "eth",type); 31 21 } 32 22 else { -
libpacketdump/link_11.cc
r950d54a r3b8a5ef 11 11 void decode(int link_type,char *packet,int len) 12 12 { 13 printf(" Legacy Framing: "); 13 // Ethernet - just raw ethernet frames 14 printf(" Legacy: "); 14 15 if (len>=10) { 15 decode_next(packet +10,len-10,"link",2);16 decode_next(packet,len,"link",2); 16 17 } 17 18 else { -
libpacketdump/link_9.cc
r950d54a r3b8a5ef 10 10 void decode(int link_type,char *packet,int len) 11 11 { 12 printf(" Legacy POS:"); 13 /* 14 if (len>=6) 15 printf(" %s",ether_ntoa((struct ether_addr*)packet)); 16 else { 17 printf("[|Truncated]\n"); 18 return; 19 } 20 if (len>=12) 21 printf(" %s",ether_ntoa((struct ether_addr*)(packet+6))); 22 else { 23 printf("[|Truncated]\n"); 24 return; 25 } 26 */ 27 if (len>=20) { 28 uint16_t type = htons(*(uint16_t*)(packet+18)); 12 // POS 13 printf(" Legacy Framing:"); 14 // take into account llc 15 if (len>=4) { 16 uint16_t type = htons( 17 ((libtrace_pos *)packet)->ether_type); 29 18 printf(" %04x\n",type); 30 decode_next(packet+20,len-20,"eth",type); 19 decode_next(packet+sizeof(libtrace_pos), 20 len-sizeof(libtrace_pos), 21 "eth",type); 31 22 } 32 23 else { -
tools/tracestats/Makefile.am
rbded5dc r3b8a5ef 6 6 7 7 include ../Makefile.tools 8 trace merge_SOURCES = tracestats.c8 tracestats_SOURCES = tracestats.c
Note: See TracChangeset
for help on using the changeset viewer.