Changes in / [5e5b6ca:b9af56e]
- Files:
-
- 4 added
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
AUTHORS
rc79c7fd r67fdca0 39 39 * Hendrik Leppelsack for reporting and fixing some errors in the tool manpages 40 40 * Jacob van Walraven for spending a summer doing various coding odd-jobs 41 * Mark Weiman for fixing an uninitialised memory bug that was upsetting 42 Valgrind. 41 43 * Jamie Curtis for fixing a couple of bugs many many years ago 42 44 * Brendon Jones for creating the original Windows DLLs and writing bits of -
lib/Makefile.am
r1668208 r977e0db 63 63 64 64 libtrace_la_SOURCES = trace.c trace_parallel.c common.h \ 65 format_ erf.c format_pcap.c format_legacy.c \65 format_pktmeta.c format_erf.c format_pcap.c format_legacy.c \ 66 66 format_rt.c format_helper.c format_helper.h format_pcapfile.c \ 67 67 format_duck.c format_tsh.c $(NATIVEFORMATS) $(BPFFORMATS) \ -
lib/dagformat.h
ree6e802 r4e5a51f 104 104 } PACKED dag_record_t; 105 105 106 typedef struct dag_section_header { 107 uint16_t type; 108 uint16_t len; 109 } PACKED dag_sec_t; 110 111 struct dag_opthdr { 112 uint16_t optcode; 113 uint16_t optlen; 114 } PACKED; 115 106 116 #ifdef WIN32 107 117 #pragma pack(pop) -
lib/format_atmhdr.c
r2193905 r254c926 209 209 NULL, /* get_timespec */ 210 210 NULL, /* get_seconds */ 211 NULL, /* get_meta_section */ 211 212 NULL, /* seek_erf */ 212 213 NULL, /* seek_timeval */ -
lib/format_bpf.c
r418c78d r254c926 632 632 NULL, /* get_timespec */ 633 633 NULL, /* get_seconds */ 634 NULL, /* get_meta_section */ 634 635 NULL, /* seek_erf */ 635 636 NULL, /* seek_timeval */ … … 683 684 NULL, /* get_timespec */ 684 685 NULL, /* get_seconds */ 686 NULL, /* get_meta_section */ 685 687 NULL, /* seek_erf */ 686 688 NULL, /* seek_timeval */ -
lib/format_dag24.c
r418c78d r254c926 542 542 NULL, /* seek_timeval */ 543 543 NULL, /* seek_seconds */ 544 NULL, /* get_meta_section */ 544 545 erf_get_capture_length, /* get_capture_length */ 545 546 erf_get_wire_length, /* get_wire_length */ -
lib/format_dag25.c
rfce4572 r254c926 1631 1631 NULL, /* get_seconds */ 1632 1632 NULL, /* get_timespec */ 1633 NULL, /* get_meta_section */ 1633 1634 NULL, /* seek_erf */ 1634 1635 NULL, /* seek_timeval */ -
lib/format_dpdk.c
r4d390c0 r254c926 2268 2268 NULL, /* seek_timeval */ 2269 2269 NULL, /* seek_seconds */ 2270 NULL, /* get_meta_section */ 2270 2271 dpdk_get_capture_length, /* get_capture_length */ 2271 2272 dpdk_get_wire_length, /* get_wire_length */ -
lib/format_dpdkndag.c
rfdf23b8 r254c926 749 749 NULL, /* seek_timeval */ 750 750 NULL, /* seek_seconds */ 751 NULL, /* get_meta_section */ 751 752 erf_get_capture_length, /* get_capture_length */ 752 753 erf_get_wire_length, /* get_wire_length */ -
lib/format_duck.c
r2193905 r254c926 363 363 NULL, /* get_timespec */ 364 364 NULL, /* get_seconds */ 365 NULL, /* get_meta_section */ 365 366 NULL, /* seek_erf */ 366 367 NULL, /* seek_timeval */ -
lib/format_erf.c
r2d16fc7 r4e5a51f 61 61 */ 62 62 63 #define ERF_META_TYPE 27 63 64 64 65 static struct libtrace_format_t erfformat; … … 86 87 /* Number of packets that were dropped during the capture */ 87 88 uint64_t drops; 89 90 bool discard_meta; 88 91 89 92 /* Config options for the input trace */ … … 260 263 DATA(libtrace)->drops = 0; 261 264 265 DATA(libtrace)->discard_meta = 0; 266 262 267 return 0; /* success */ 263 268 } … … 281 286 "Unsupported option"); 282 287 return -1; 288 case TRACE_OPTION_DISCARD_META: 289 if (*(int *)value > 0) { 290 DATA(libtrace)->discard_meta = true; 291 } else { 292 DATA(libtrace)->discard_meta = false; 293 } 294 return 0; 283 295 default: 284 296 /* Unknown option */ … … 539 551 unsigned int rlen; 540 552 uint32_t flags = 0; 541 542 553 libtrace_rt_types_t linktype; 554 int gotpacket = 0; 555 543 556 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 544 557 packet->buffer = malloc((size_t)LIBTRACE_PACKET_BUFSIZE); 545 558 if (!packet->buffer) { 546 trace_set_err(libtrace, errno, 547 "Cannot allocate memory"); 559 trace_set_err(libtrace, errno, "Cannot allocate memory"); 548 560 return -1; 549 561 } 550 562 } 551 563 552 flags |= TRACE_PREP_OWN_BUFFER; 553 554 if ((numbytes=wandio_read(libtrace->io, 555 packet->buffer, 556 (size_t)dag_record_size)) == -1) { 557 trace_set_err(libtrace,errno,"reading ERF file"); 558 return -1; 559 } 560 /* EOF */ 561 if (numbytes == 0) { 562 return 0; 563 } 564 565 if (numbytes < (int)dag_record_size) { 566 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Incomplete ERF header"); 567 return -1; 568 } 569 570 rlen = ntohs(((dag_record_t *)packet->buffer)->rlen); 571 buffer2 = (char*)packet->buffer + dag_record_size; 572 size = rlen - dag_record_size; 573 574 if (size >= LIBTRACE_PACKET_BUFSIZE) { 575 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 564 flags |= TRACE_PREP_OWN_BUFFER; 565 566 while (!gotpacket) { 567 568 if ((numbytes=wandio_read(libtrace->io, packet->buffer, 569 (size_t)dag_record_size)) == -1) { 570 571 trace_set_err(libtrace,errno,"reading ERF file"); 572 return -1; 573 } 574 575 /* EOF */ 576 if (numbytes == 0) { 577 return 0; 578 } 579 580 if (numbytes < (int)dag_record_size) { 581 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Incomplete ERF header"); 582 return -1; 583 } 584 585 rlen = ntohs(((dag_record_t *)packet->buffer)->rlen); 586 buffer2 = (char*)packet->buffer + dag_record_size; 587 size = rlen - dag_record_size; 588 589 if (size >= LIBTRACE_PACKET_BUFSIZE) { 590 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 576 591 "Packet size %u larger than supported by libtrace - packet is probably corrupt", 577 592 size); 578 return -1;579 }580 581 /* Unknown/corrupt */582 if ((((dag_record_t *)packet->buffer)->type & 0x7f) > ERF_TYPE_MAX) {583 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET,593 return -1; 594 } 595 596 /* Unknown/corrupt */ 597 if ((((dag_record_t *)packet->buffer)->type & 0x7f) > ERF_TYPE_MAX) { 598 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 584 599 "Corrupt or Unknown ERF type"); 585 return -1;586 }587 588 /* read in the rest of the packet */589 if ((numbytes=wandio_read(libtrace->io,590 buffer2,591 (size_t)size)) != (int)size) { 592 if (numbytes==-1) {593 trace_set_err(libtrace,errno, "read(%s)",600 return -1; 601 } 602 603 /* read in the rest of the packet */ 604 if ((numbytes=wandio_read(libtrace->io, buffer2, 605 (size_t)size)) != (int)size) { 606 607 if (numbytes==-1) { 608 trace_set_err(libtrace,errno, "read(%s)", 594 609 libtrace->uridata); 610 return -1; 611 } 612 613 trace_set_err(libtrace,EIO, 614 "Truncated packet (wanted %d, got %d)", size, numbytes); 615 616 /* Failed to read the full packet? must be EOF */ 595 617 return -1; 596 618 } 597 trace_set_err(libtrace,EIO, 598 "Truncated packet (wanted %d, got %d)", 599 size, numbytes); 600 /* Failed to read the full packet? must be EOF */ 601 return -1; 602 } 603 604 if (numbytes < (int)size) { 605 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Incomplete ERF record"); 606 return -1; 607 } 608 609 if (erf_prepare_packet(libtrace, packet, packet->buffer, 610 TRACE_RT_DATA_ERF, flags)) 611 return -1; 612 619 620 if (numbytes < (int)size) { 621 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Incomplete ERF record"); 622 return -1; 623 } 624 625 /* If a provenance packet make sure correct rt linktype is set. 626 * Only bits 0-6 are used for the type */ 627 if ((((dag_record_t *)packet->buffer)->type & 127) == ERF_META_TYPE) { 628 linktype = TRACE_RT_ERF_META; 629 } else { linktype = TRACE_RT_DATA_ERF; } 630 631 /* If this is a meta packet and TRACE_OPTION_DISCARD_META is set 632 * ignore this packet and get another */ 633 if ((linktype == TRACE_RT_ERF_META && !DATA(libtrace)->discard_meta) || 634 linktype == TRACE_RT_DATA_ERF) { 635 gotpacket = 1; 636 637 if (erf_prepare_packet(libtrace, packet, packet->buffer, linktype, flags)) { 638 return -1; 639 } 640 } 641 } 642 613 643 return rlen; 614 644 } … … 940 970 } 941 971 972 static char *erf_get_option_name(uint32_t option) { 973 switch(option) { 974 case (ERF_PROV_COMMENT): return "Comment"; 975 case (ERF_PROV_FCS_LEN): return "FCS Length"; 976 case (ERF_PROV_MASK_CIDR): return "Subnet CIDR"; 977 case (ERF_PROV_NAME): return "Interface Name"; 978 case (ERF_PROV_DESCR): return "Interface Description"; 979 case (ERF_PROV_APP_NAME): return "Application Name"; 980 case (ERF_PROV_HOSTNAME): return "Hostname"; 981 case (ERF_PROV_OS): return "Operating System"; 982 case (ERF_PROV_MODEL): return "Model"; 983 case (ERF_PROV_FW_VERSION): return "Firmware Version"; 984 case (ERF_PROV_SERIAL_NO): return "Serial Number"; 985 case (ERF_PROV_ORG_NAME): return "Organisation Name"; 986 case (ERF_PROV_SNAPLEN): return "Snap length"; 987 case (ERF_PROV_CARD_NUM): return "DAG Card Number"; 988 case (ERF_PROV_MODULE_NUM): return "DAG Module Number"; 989 case (ERF_PROV_LOC_NAME): return "Capture Location"; 990 case (ERF_PROV_FLOW_HASH_MODE): return "Flow Hash Mode"; 991 case (ERF_PROV_FILTER): return "Filter"; 992 case (ERF_PROV_TUNNELING_MODE): return "Tunneling Mode"; 993 case (ERF_PROV_ROTFILE_NAME): return "Rotfile Name"; 994 case (ERF_PROV_LOC_DESCR): return "Location Description"; 995 case (ERF_PROV_MEM): return "Stream Buffer Memory"; 996 case (ERF_PROV_DEV_NAME): return "DAG Device Name"; 997 case (ERF_PROV_DEV_PATH): return "DAG Device Path"; 998 case (ERF_PROV_APP_VERSION): return "Capture Application Version"; 999 case (ERF_PROV_CPU): return "CPU"; 1000 case (ERF_PROV_CPU_PHYS_CORES): return "CPU Cores"; 1001 case (ERF_PROV_CPU_NUMA_NODES): return "CPU NUMA Nodes"; 1002 case (ERF_PROV_DAG_VERSION): return "DAG Software Version"; 1003 case (ERF_PROV_IF_NUM): return "Interface Number"; 1004 case (ERF_PROV_IF_SPEED): return "Interface Speed"; 1005 case (ERF_PROV_IF_IPV4): return "Interface IPv4"; 1006 case (ERF_PROV_IF_IPV6): return "Interface IPv6"; 1007 case (ERF_PROV_IF_MAC): return "Interface MAC"; 1008 case (ERF_PROV_IF_SFP_TYPE): return "Transceiver Type"; 1009 case (ERF_PROV_IF_LINK_STATUS): return "Link Status"; 1010 case (ERF_PROV_IF_PHY_MODE): return "PHY Mode"; 1011 case (ERF_PROV_IF_PORT_TYPE): return "Port Type"; 1012 case (ERF_PROV_IF_RX_LATENCY): return "Latency"; 1013 case (ERF_PROV_IF_RX_POWER): return "Optical RX Power"; 1014 case (ERF_PROV_IF_TX_POWER): return "Optical TX Power"; 1015 case (ERF_PROV_CLK_SOURCE): return "CLK Source"; 1016 case (ERF_PROV_CLK_STATE): return "CLK State"; 1017 case (ERF_PROV_CLK_THRESHOLD): return "CLK Threshold"; 1018 case (ERF_PROV_CLK_CORRECTION): return "CLK Correction"; 1019 case (ERF_PROV_CLK_FAILURES): return "CLK Failures"; 1020 case (ERF_PROV_CLK_RESYNCS): return "CLK Resyncs"; 1021 case (ERF_PROV_CLK_PHASE_ERROR): return "CLK Phase Errors"; 1022 case (ERF_PROV_CLK_INPUT_PULSES): return "CLK Input Pulses"; 1023 case (ERF_PROV_CLK_REJECTED_PULSES): return "CLK Rejected Pulses"; 1024 case (ERF_PROV_CLK_PHC_INDEX): return "CLK PHC Index"; 1025 case (ERF_PROV_CLK_PHC_OFFSET): return "CLK PHC Offset"; 1026 case (ERF_PROV_CLK_TIMEBASE): return "CLK Timebase"; 1027 case (ERF_PROV_CLK_DESCR): return "CLK Description"; 1028 case (ERF_PROV_CLK_OUT_SOURCE): return "CLK Output Source" ; 1029 case (ERF_PROV_CLK_LINK_MODE): return "CLK Link Mode"; 1030 case (ERF_PROV_PTP_DOMAIN_NUM): return "PTP Domain Number"; 1031 case (ERF_PROV_PTP_STEPS_REMOVED): return "PTP Steps removed"; 1032 case (ERF_PROV_CLK_PORT_PROTO): return "CLK Port Protocol"; 1033 default: 1034 return "Unknown"; 1035 } 1036 return "duno"; 1037 } 1038 1039 static libtrace_meta_datatype_t erf_get_datatype(uint32_t option) { 1040 switch(option) { 1041 case (ERF_PROV_COMMENT): return TRACE_META_STRING; 1042 case (ERF_PROV_FCS_LEN): return TRACE_META_UINT32; 1043 case (ERF_PROV_MASK_CIDR): return TRACE_META_UINT32; 1044 case (ERF_PROV_NAME): return TRACE_META_STRING; 1045 case (ERF_PROV_DESCR): return TRACE_META_STRING; 1046 case (ERF_PROV_APP_NAME): return TRACE_META_STRING; 1047 case (ERF_PROV_HOSTNAME): return TRACE_META_STRING; 1048 case (ERF_PROV_OS): return TRACE_META_STRING; 1049 case (ERF_PROV_MODEL): return TRACE_META_STRING; 1050 case (ERF_PROV_FW_VERSION): return TRACE_META_STRING; 1051 case (ERF_PROV_SERIAL_NO): return TRACE_META_STRING; 1052 case (ERF_PROV_ORG_NAME): return TRACE_META_STRING; 1053 case (ERF_PROV_SNAPLEN): return TRACE_META_UINT32; 1054 case (ERF_PROV_CARD_NUM): return TRACE_META_UINT32; 1055 case (ERF_PROV_MODULE_NUM): return TRACE_META_UINT32; 1056 case (ERF_PROV_LOC_NAME): return TRACE_META_STRING; 1057 case (ERF_PROV_FILTER): return TRACE_META_STRING; 1058 case (ERF_PROV_FLOW_HASH_MODE): return TRACE_META_UINT32; 1059 case (ERF_PROV_TUNNELING_MODE): return TRACE_META_UINT32; 1060 case (ERF_PROV_ROTFILE_NAME): return TRACE_META_STRING; 1061 case (ERF_PROV_LOC_DESCR): return TRACE_META_STRING; 1062 case (ERF_PROV_MEM): return TRACE_META_UINT64; 1063 case (ERF_PROV_DEV_NAME): return TRACE_META_STRING; 1064 case (ERF_PROV_DEV_PATH): return TRACE_META_STRING; 1065 case (ERF_PROV_APP_VERSION): return TRACE_META_STRING; 1066 case (ERF_PROV_CPU): return TRACE_META_STRING; 1067 case (ERF_PROV_CPU_PHYS_CORES): return TRACE_META_UINT32; 1068 case (ERF_PROV_CPU_NUMA_NODES): return TRACE_META_UINT32; 1069 case (ERF_PROV_DAG_VERSION): return TRACE_META_STRING; 1070 case (ERF_PROV_IF_NUM): return TRACE_META_UINT32; 1071 case (ERF_PROV_IF_SPEED): return TRACE_META_UINT64; 1072 case (ERF_PROV_IF_IPV4): return TRACE_META_IPV4; 1073 case (ERF_PROV_IF_IPV6): return TRACE_META_IPV6; 1074 case (ERF_PROV_IF_MAC): return TRACE_META_MAC; 1075 case (ERF_PROV_IF_SFP_TYPE): return TRACE_META_STRING; 1076 case (ERF_PROV_IF_LINK_STATUS): return TRACE_META_UINT32; 1077 case (ERF_PROV_IF_PHY_MODE): return TRACE_META_STRING; 1078 case (ERF_PROV_IF_PORT_TYPE): return TRACE_META_UINT32; 1079 /* this is a ts_rel, need to double check */ 1080 case (ERF_PROV_IF_RX_LATENCY): return TRACE_META_UINT64; 1081 case (ERF_PROV_IF_RX_POWER): return TRACE_META_UINT32; 1082 case (ERF_PROV_IF_TX_POWER): return TRACE_META_UINT32; 1083 case (ERF_PROV_CLK_SOURCE): return TRACE_META_UINT32; 1084 case (ERF_PROV_CLK_STATE): return TRACE_META_UINT32; 1085 /* this is a ts_rel, need to double check */ 1086 case (ERF_PROV_CLK_THRESHOLD): return TRACE_META_UINT64; 1087 /* this is a ts_rel, need to double check */ 1088 case (ERF_PROV_CLK_CORRECTION): return TRACE_META_UINT64; 1089 case (ERF_PROV_CLK_FAILURES): return TRACE_META_UINT32; 1090 case (ERF_PROV_CLK_RESYNCS): return TRACE_META_UINT32; 1091 /* this is a ts_rel, need to double check */ 1092 case (ERF_PROV_CLK_PHASE_ERROR): return TRACE_META_UINT64; 1093 case (ERF_PROV_CLK_INPUT_PULSES): return TRACE_META_UINT32; 1094 case (ERF_PROV_CLK_REJECTED_PULSES): return TRACE_META_UINT32; 1095 case (ERF_PROV_CLK_PHC_INDEX): return TRACE_META_UINT32; 1096 /* this is a ts_rel, need to double check */ 1097 case (ERF_PROV_CLK_PHC_OFFSET): return TRACE_META_UINT64; 1098 case (ERF_PROV_CLK_TIMEBASE): return TRACE_META_STRING; 1099 case (ERF_PROV_CLK_DESCR): return TRACE_META_STRING; 1100 case (ERF_PROV_CLK_OUT_SOURCE): return TRACE_META_UINT32; 1101 case (ERF_PROV_CLK_LINK_MODE): return TRACE_META_UINT32; 1102 case (ERF_PROV_PTP_DOMAIN_NUM): return TRACE_META_UINT32; 1103 case (ERF_PROV_PTP_STEPS_REMOVED): return TRACE_META_UINT32; 1104 case (ERF_PROV_CLK_PORT_PROTO): return TRACE_META_UINT32; 1105 default: 1106 return TRACE_META_UNKNOWN; 1107 } 1108 } 1109 1110 /* An ERF provenance packet can contain multiple sections of the same type per packet */ 1111 void *erf_get_meta_section(libtrace_packet_t *packet, uint32_t section) { 1112 1113 void *ptr; 1114 dag_record_t *hdr; 1115 dag_sec_t *sec; 1116 uint16_t tmp; 1117 uint16_t remaining; 1118 uint16_t curr_sec = 0; 1119 1120 if (packet == NULL) { 1121 fprintf(stderr, "NULL packet passed into erf_get_meta_section()\n"); 1122 return NULL; 1123 } 1124 if (packet->buffer == NULL) { return NULL; } 1125 1126 hdr = (dag_record_t *)packet->buffer; 1127 ptr = packet->payload; 1128 1129 /* ensure this packet is a meta packet */ 1130 if ((hdr->type & 127) != ERF_META_TYPE) { return NULL; } 1131 /* set remaining to size of packet minus header length */ 1132 remaining = ntohs(hdr->rlen) - 24; 1133 1134 /* setup structure to hold the result */ 1135 libtrace_meta_t *result = malloc(sizeof(libtrace_meta_t)); 1136 result->section = section; 1137 result->num = 0; 1138 1139 while (remaining > sizeof(dag_sec_t)) { 1140 1141 /* Get the current section/option header */ 1142 sec = (dag_sec_t *)ptr; 1143 1144 if (ntohs(sec->type) == ERF_PROV_SECTION_CAPTURE 1145 || ntohs(sec->type) == ERF_PROV_SECTION_HOST 1146 || ntohs(sec->type) == ERF_PROV_SECTION_MODULE 1147 || ntohs(sec->type) == ERF_PROV_SECTION_INTERFACE) { 1148 1149 curr_sec = ntohs(sec->type); 1150 } 1151 1152 /* If the current section the requested one and this is not 1153 * a section header */ 1154 if (section == curr_sec && 1155 ntohs(sec->type) != ERF_PROV_SECTION_CAPTURE 1156 && ntohs(sec->type) != ERF_PROV_SECTION_HOST 1157 && ntohs(sec->type) != ERF_PROV_SECTION_MODULE 1158 && ntohs(sec->type) != ERF_PROV_SECTION_INTERFACE) { 1159 1160 result->num += 1; 1161 if (result->num == 1) { 1162 result->items = malloc(sizeof(libtrace_meta_item_t)); 1163 } else { 1164 result->items = realloc(result->items, 1165 result->num*sizeof(libtrace_meta_item_t)); 1166 } 1167 result->items[result->num-1].option = ntohs(sec->type); 1168 result->items[result->num-1].option_name = 1169 erf_get_option_name(ntohs(sec->type)); 1170 1171 result->items[result->num-1].len = ntohs(sec->len); 1172 result->items[result->num-1].datatype = 1173 erf_get_datatype(ntohs(sec->type)); 1174 1175 /* If the datatype is a string allow for a null terminator */ 1176 if (result->items[result->num-1].datatype == TRACE_META_STRING) { 1177 result->items[result->num-1].data = 1178 calloc(1, ntohs(sec->len)+1); 1179 ((char *)result->items[result->num-1].data)[ntohs(sec->len)] = '\0'; 1180 /* and copy the utf8 string */ 1181 memcpy(result->items[result->num-1].data, 1182 ptr+sizeof(struct dag_opthdr), ntohs(sec->len)); 1183 } else { 1184 result->items[result->num-1].data = 1185 calloc(1, ntohs(sec->len)); 1186 /* depending on the datatype we need to ensure the data is 1187 * in host byte ordering */ 1188 if (result->items[result->num-1].datatype == TRACE_META_UINT32) { 1189 uint32_t t = *(uint32_t *)(ptr+sizeof(struct dag_opthdr)); 1190 t = ntohl(t); 1191 memcpy(result->items[result->num-1].data, 1192 &t, sizeof(uint32_t)); 1193 } else if(result->items[result->num-1].datatype == TRACE_META_UINT64) { 1194 uint64_t t = *(uint64_t *)(ptr+sizeof(struct dag_opthdr)); 1195 t = bswap_be_to_host64(t); 1196 memcpy(result->items[result->num-1].data, 1197 &t, sizeof(uint64_t)); 1198 } else { 1199 memcpy(result->items[result->num-1].data, 1200 ptr+sizeof(struct dag_opthdr), ntohs(sec->len)); 1201 } 1202 } 1203 } 1204 1205 /* Update remaining and ptr. Also account for any padding */ 1206 if ((ntohs(sec->len) % 4) != 0) { 1207 tmp = ntohs(sec->len) + (4 - (ntohs(sec->len) % 4)) + sizeof(dag_sec_t); 1208 } else { 1209 tmp = ntohs(sec->len) + sizeof(dag_sec_t); 1210 } 1211 remaining -= tmp; 1212 ptr += tmp; 1213 } 1214 1215 /* If the result num > 0 matches were found */ 1216 if (result->num > 0) { 1217 return (void *)result; 1218 } else { 1219 free(result); 1220 return NULL; 1221 } 1222 } 1223 942 1224 static void erf_help(void) { 943 1225 printf("erf format module: $Revision: 1752 $\n"); … … 958 1240 printf("\n"); 959 1241 960 1242 961 1243 } 962 1244 … … 967 1249 NULL, /* probe filename */ 968 1250 erf_probe_magic, /* probe magic */ 969 erf_init_input, /* init_input */ 1251 erf_init_input, /* init_input */ 970 1252 erf_config_input, /* config_input */ 971 1253 erf_start_input, /* start_input */ … … 988 1270 NULL, /* get_timespec */ 989 1271 NULL, /* get_seconds */ 1272 erf_get_meta_section, /* get_meta_section */ 990 1273 erf_seek_erf, /* seek_erf */ 991 1274 NULL, /* seek_timeval */ … … 1012 1295 NULL, /* probe filename */ 1013 1296 NULL, /* probe magic */ 1014 erf_init_input, /* init_input */ 1297 erf_init_input, /* init_input */ 1015 1298 erf_config_input, /* config_input */ 1016 1299 rawerf_start_input, /* start_input */ … … 1033 1316 NULL, /* get_timespec */ 1034 1317 NULL, /* get_seconds */ 1318 erf_get_meta_section, /* get_meta_section */ 1035 1319 erf_seek_erf, /* seek_erf */ 1036 1320 NULL, /* seek_timeval */ -
lib/format_erf.h
ra857389 r0af3a4e 29 29 #include "libtrace.h" 30 30 31 /* ERF Section codes */ 32 #define ERF_PROV_SECTION_CAPTURE 0xFF00 33 #define ERF_PROV_SECTION_HOST 0xFF01 34 #define ERF_PROV_SECTION_MODULE 0xFF02 35 #define ERF_PROV_SECTION_INTERFACE 0xFF03 36 37 /* ERF Provenance record tag type codes */ 38 #define ERF_PROV_COMMENT 1 39 #define ERF_PROV_FCS_LEN 8 40 #define ERF_PROV_MASK_CIDR 10 41 #define ERF_PROV_NAME 12 42 #define ERF_PROV_DESCR 13 43 #define ERF_PROV_APP_NAME 16 44 #define ERF_PROV_HOSTNAME 18 45 #define ERF_PROV_OS 17 46 #define ERF_PROV_MODEL 20 47 #define ERF_PROV_FW_VERSION 21 48 #define ERF_PROV_SERIAL_NO 22 49 #define ERF_PROV_ORG_NAME 11 50 #define ERF_PROV_SNAPLEN 29 51 #define ERF_PROV_CARD_NUM 30 52 #define ERF_PROV_MODULE_NUM 31 53 #define ERF_PROV_LOC_NAME 34 54 #define ERF_PROV_FILTER 36 55 #define ERF_PROV_FLOW_HASH_MODE 37 56 #define ERF_PROV_TUNNELING_MODE 38 57 #define ERF_PROV_ROTFILE_NAME 43 58 #define ERF_PROV_LOC_DESCR 46 59 #define ERF_PROV_APP_VERSION 47 60 #define ERF_PROV_MEM 40 61 #define ERF_PROV_DEV_NAME 44 62 #define ERF_PROV_DEV_PATH 45 63 #define ERF_PROV_CPU 49 64 #define ERF_PROV_CPU_PHYS_CORES 50 65 #define ERF_PROV_CPU_NUMA_NODES 51 66 #define ERF_PROV_DAG_VERSION 53 67 #define ERF_PROV_IF_NUM 64 68 #define ERF_PROV_IF_SPEED 66 69 #define ERF_PROV_IF_IPV4 67 70 #define ERF_PROV_IF_IPV6 68 71 #define ERF_PROV_IF_MAC 69 72 #define ERF_PROV_IF_SFP_TYPE 78 73 #define ERF_PROV_IF_LINK_STATUS 81 74 #define ERF_PROV_IF_PHY_MODE 82 75 #define ERF_PROV_IF_PORT_TYPE 83 76 #define ERF_PROV_IF_RX_LATENCY 84 77 #define ERF_PROV_IF_RX_POWER 79 78 #define ERF_PROV_IF_TX_POWER 80 79 #define ERF_PROV_CLK_SOURCE 384 80 #define ERF_PROV_CLK_STATE 385 81 #define ERF_PROV_CLK_THRESHOLD 386 82 #define ERF_PROV_CLK_CORRECTION 387 83 #define ERF_PROV_CLK_FAILURES 388 84 #define ERF_PROV_CLK_RESYNCS 389 85 #define ERF_PROV_CLK_PHASE_ERROR 390 86 #define ERF_PROV_CLK_INPUT_PULSES 391 87 #define ERF_PROV_CLK_REJECTED_PULSES 392 88 #define ERF_PROV_CLK_PHC_INDEX 393 89 #define ERF_PROV_CLK_PHC_OFFSET 394 90 #define ERF_PROV_CLK_TIMEBASE 395 91 #define ERF_PROV_CLK_DESCR 396 92 #define ERF_PROV_CLK_OUT_SOURCE 397 93 #define ERF_PROV_CLK_LINK_MODE 398 94 #define ERF_PROV_PTP_DOMAIN_NUM 399 95 #define ERF_PROV_PTP_STEPS_REMOVED 400 96 #define ERF_PROV_CLK_PORT_PROTO 414 97 31 98 /** @file 32 99 * … … 55 122 int erf_is_color_type(uint8_t erf_type); 56 123 124 void *erf_get_meta_section(libtrace_packet_t *packet, uint32_t section); 125 void *erf_get_meta_section_option(libtrace_packet_t *packet, uint32_t section, 126 uint16_t option); 127 57 128 #endif -
lib/format_etsilive.c
rb359a11 r254c926 691 691 NULL, /* get_timespec */ 692 692 NULL, /* get_seconds */ 693 NULL, /* get_meta_section */ 693 694 NULL, /* seek_erf */ 694 695 NULL, /* seek_timeval */ -
lib/format_legacy.c
r2193905 r254c926 536 536 NULL, /* get_timespec */ 537 537 NULL, /* get_seconds */ 538 NULL, /* get_meta_section */ 538 539 NULL, /* seek_erf */ 539 540 NULL, /* seek_timeval */ … … 581 582 NULL, /* get_timespec */ 582 583 NULL, /* get_seconds */ 584 NULL, /* get_meta_section */ 583 585 NULL, /* seek_erf */ 584 586 NULL, /* seek_timeval */ … … 626 628 NULL, /* get_timespec */ 627 629 NULL, /* get_seconds */ 630 NULL, /* get_meta_section */ 628 631 NULL, /* seek_erf */ 629 632 NULL, /* seek_timeval */ … … 671 674 NULL, /* get_timespec */ 672 675 NULL, /* get_seconds */ 676 NULL, /* get_meta_section */ 673 677 NULL, /* seek_erf */ 674 678 NULL, /* seek_timeval */ -
lib/format_linux_common.c
r5fe998b rd4eed70 172 172 case TRACE_OPTION_CONSTANT_ERF_FRAMING: 173 173 break; 174 case TRACE_OPTION_DISCARD_META: 175 break; 174 176 /* Avoid default: so that future options will cause a warning 175 177 * here to remind us to implement it, or flag it as -
lib/format_linux_int.c
re9fe6ac r254c926 529 529 linuxnative_get_timespec, /* get_timespec */ 530 530 NULL, /* get_seconds */ 531 NULL, /* get_meta_section */ 531 532 NULL, /* seek_erf */ 532 533 NULL, /* seek_timeval */ … … 590 591 linuxnative_get_timespec, /* get_timespec */ 591 592 NULL, /* get_seconds */ 593 NULL, /* get_meta_section */ 592 594 NULL, /* seek_erf */ 593 595 NULL, /* seek_timeval */ -
lib/format_linux_ring.c
rfce4572 r254c926 849 849 linuxring_get_timespec, /* get_timespec */ 850 850 NULL, /* get_seconds */ 851 NULL, /* get_meta_section */ 851 852 NULL, /* seek_erf */ 852 853 NULL, /* seek_timeval */ … … 912 913 linuxring_get_timespec, /* get_timespec */ 913 914 NULL, /* get_seconds */ 915 NULL, /* get_meta_section */ 914 916 NULL, /* seek_erf */ 915 917 NULL, /* seek_timeval */ -
lib/format_ndag.c
r6514097 r254c926 1524 1524 NULL, /* get_seconds */ 1525 1525 NULL, /* get_timespec */ 1526 NULL, /* get_meta_section */ 1526 1527 NULL, /* seek_erf */ 1527 1528 NULL, /* seek_timeval */ -
lib/format_pcap.c
r9a6bdbc r254c926 869 869 NULL, /* get_seconds */ 870 870 NULL, /* get_timespec */ 871 NULL, /* get_meta_section */ 871 872 NULL, /* seek_erf */ 872 873 NULL, /* seek_timeval */ … … 914 915 NULL, /* get_seconds */ 915 916 NULL, /* get_timespec */ 917 NULL, /* get_meta_section */ 916 918 NULL, /* seek_erf */ 917 919 NULL, /* seek_timeval */ -
lib/format_pcapfile.c
r5460603 r254c926 286 286 /* All these are either unsupported or handled 287 287 * by trace_config */ 288 break; 289 case TRACE_OPTION_DISCARD_META: 288 290 break; 289 291 } … … 799 801 pcapfile_get_timespec, /* get_timespec */ 800 802 NULL, /* get_seconds */ 803 NULL, /* get_meta_section */ 801 804 NULL, /* seek_erf */ 802 805 NULL, /* seek_timeval */ -
lib/format_pcapng.c
r063d5dd r4e5a51f 29 29 #include "libtrace_int.h" 30 30 #include "format_helper.h" 31 #include "format_pcapng.h" 31 32 32 33 #include <sys/stat.h> … … 38 39 #include <stdbool.h> 39 40 #include <math.h> 40 41 #define PCAPNG_SECTION_TYPE 0x0A0D0D0A42 #define PCAPNG_INTERFACE_TYPE 0x0000000143 #define PCAPNG_OLD_PACKET_TYPE 0x0000000244 #define PCAPNG_SIMPLE_PACKET_TYPE 0x0000000345 #define PCAPNG_NAME_RESOLUTION_TYPE 0x0000000446 #define PCAPNG_INTERFACE_STATS_TYPE 0x0000000547 #define PCAPNG_ENHANCED_PACKET_TYPE 0x0000000648 #define PCAPNG_CUSTOM_TYPE 0x00000BAD49 #define PCAPNG_CUSTOM_NONCOPY_TYPE 0x40000BAD50 #define PCAPNG_DECRYPTION_SECRETS_TYPE 0x0000000A51 52 #define PCAPNG_NRB_RECORD_END 0x000053 #define PCAPNG_NRB_RECORD_IP4 0x000154 #define PCAPNG_NRB_RECORD_IP6 0x000255 56 #define PCAPNG_CUSTOM_OPTION_UTF8 0xBAC57 #define PCAPNG_CUSTOM_OPTION_BIN 0xBAD58 #define PCAPNG_CUSTOM_OPTION_UTF8_NONCOPY 0x4BAC59 #define PCAPNG_CUSTOM_OPTION_BIN_NONCOPY 0x4BAD60 61 #define PCAPNG_OPTION_END 0x000062 63 #define PACKET_IS_ENHANCED (pcapng_get_record_type(packet) == PCAPNG_ENHANCED_PACKET_TYPE)64 65 #define PACKET_IS_SIMPLE (pcapng_get_record_type(packet) == PCAPNG_SIMPLE_PACKET_TYPE)66 67 #define PACKET_IS_OLD (pcapng_get_record_type(packet) == PCAPNG_OLD_PACKET_TYPE)68 69 #define PCAPNG_IFOPT_TSRESOL 970 71 #define PCAPNG_PKTOPT_DROPCOUNT 472 73 #define PCAPNG_STATOPT_START 274 #define PCAPNG_STATOPT_END 375 #define PCAPNG_STATOPT_IFRECV 476 #define PCAPNG_STATOPT_IFDROP 577 #define PCAPNG_STATOPT_FILTERACCEPT 678 #define PCAPNG_STATOPT_OSDROP 779 #define PCAPNG_STATOPT_USRDELIV 880 81 typedef struct pcagng_section_header_t {82 uint32_t blocktype;83 uint32_t blocklen;84 uint32_t ordering;85 uint16_t majorversion;86 uint16_t minorversion;87 uint64_t sectionlen;88 } pcapng_sec_t;89 90 typedef struct pcapng_interface_header_t {91 uint32_t blocktype;92 uint32_t blocklen;93 uint16_t linktype;94 uint16_t reserved;95 uint32_t snaplen;96 } pcapng_int_t;97 98 typedef struct pcapng_nrb_header_t {99 uint32_t blocktype;100 uint32_t blocklen;101 } pcapng_nrb_t;102 103 typedef struct pcapng_enhanced_packet_t {104 uint32_t blocktype;105 uint32_t blocklen;106 uint32_t interfaceid;107 uint32_t timestamp_high;108 uint32_t timestamp_low;109 uint32_t caplen;110 uint32_t wlen;111 } pcapng_epkt_t;112 113 typedef struct pcapng_simple_packet_t {114 uint32_t blocktype;115 uint32_t blocklen;116 uint32_t wlen;117 } pcapng_spkt_t;118 119 typedef struct pcapng_old_packet_t {120 uint32_t blocktype;121 uint32_t blocklen;122 uint16_t interfaceid;123 uint16_t drops;124 uint32_t timestamp_high;125 uint32_t timestamp_low;126 uint32_t caplen;127 uint32_t wlen;128 } pcapng_opkt_t;129 130 typedef struct pcapng_stats_header_t {131 uint32_t blocktype;132 uint32_t blocklen;133 uint32_t interfaceid;134 uint32_t timestamp_high;135 uint32_t timestamp_low;136 } pcapng_stats_t;137 138 typedef struct pcapng_custom_header_t {139 uint32_t blocktype;140 uint32_t blocklen;141 uint32_t pen;142 } pcapng_custom_t;143 144 typedef struct pcapng_interface_t pcapng_interface_t;145 146 struct pcapng_timestamp {147 uint32_t timehigh;148 uint32_t timelow;149 };150 151 struct pcapng_interface_t {152 153 uint16_t id;154 libtrace_dlt_t linktype;155 uint32_t snaplen;156 uint32_t tsresol;157 158 uint64_t received;159 uint64_t dropped; /* as reported by interface stats */160 uint64_t dropcounter; /* as reported by packet records */161 uint64_t accepted;162 uint64_t osdropped;163 uint64_t laststats;164 165 };166 167 struct pcapng_format_data_t {168 bool started;169 bool realtime;170 171 /* Section data */172 bool byteswapped;173 174 /* Interface data */175 pcapng_interface_t **interfaces;176 uint16_t allocatedinterfaces;177 uint16_t nextintid;178 179 };180 181 struct pcapng_format_data_out_t {182 iow_t *file;183 int compress_level;184 int compress_type;185 int flag;186 187 /* Section data */188 uint16_t sechdr_count;189 bool byteswapped;190 191 /* Interface data */192 uint16_t nextintid;193 libtrace_linktype_t lastdlt;194 };195 196 struct pcapng_optheader {197 uint16_t optcode;198 uint16_t optlen;199 };200 201 struct pcapng_custom_optheader {202 uint16_t optcode;203 uint16_t optlen;204 uint32_t pen;205 };206 struct pcapng_nrb_record {207 uint16_t recordtype;208 uint16_t recordlen;209 };210 struct pcapng_peeker {211 uint32_t blocktype;212 uint32_t blocklen;213 };214 215 typedef struct pcapng_peeker pcapng_hdr_t;216 217 #define DATA(x) ((struct pcapng_format_data_t *)((x)->format_data))218 #define DATAOUT(x) ((struct pcapng_format_data_out_t*)((x)->format_data))219 41 220 42 static char *pcapng_parse_next_option(libtrace_t *libtrace, char **pktbuf, … … 656 478 } 657 479 480 static void pcapng_create_output_sectionheader_packet(libtrace_out_t *libtrace) { 481 /* Create section block */ 482 pcapng_sec_t sechdr; 483 sechdr.blocktype = pcapng_swap32(libtrace, PCAPNG_SECTION_TYPE); 484 sechdr.blocklen = pcapng_swap32(libtrace, 28); 485 sechdr.ordering = pcapng_swap32(libtrace, 0x1A2B3C4D); 486 sechdr.majorversion = pcapng_swap16(libtrace, 1); 487 sechdr.minorversion = 0; 488 sechdr.sectionlen = 0xFFFFFFFFFFFFFFFF; 489 490 wandio_wwrite(DATAOUT(libtrace)->file, &sechdr, sizeof(sechdr)); 491 wandio_wwrite(DATAOUT(libtrace)->file, &sechdr.blocklen, sizeof(sechdr.blocklen)); 492 493 DATAOUT(libtrace)->sechdr_count += 1; 494 } 495 496 static void pcapng_create_output_interface_packet(libtrace_out_t *libtrace, libtrace_linktype_t linktype) { 497 /* Create interface block*/ 498 pcapng_int_t inthdr; 499 inthdr.blocktype = pcapng_swap32(libtrace, PCAPNG_INTERFACE_TYPE); 500 inthdr.blocklen = pcapng_swap32(libtrace, 20); 501 inthdr.linktype = pcapng_swap16(libtrace, libtrace_to_pcap_dlt(linktype)); 502 inthdr.reserved = 0; 503 inthdr.snaplen = 0; 504 505 wandio_wwrite(DATAOUT(libtrace)->file, &inthdr, sizeof(inthdr)); 506 wandio_wwrite(DATAOUT(libtrace)->file, &inthdr.blocklen, sizeof(inthdr.blocklen)); 507 508 /* increment the interface counter */ 509 DATAOUT(libtrace)->nextintid += 1; 510 /* update the last linktype */ 511 DATAOUT(libtrace)->lastdlt = linktype; 512 } 513 658 514 static int pcapng_probe_magic(io_t *io) { 659 515 … … 694 550 DATA(libtrace)->started = false; 695 551 DATA(libtrace)->realtime = false; 552 DATA(libtrace)->discard_meta = false; 696 553 DATA(libtrace)->byteswapped = true; 697 554 DATA(libtrace)->interfaces = (pcapng_interface_t **)calloc(10, \ … … 754 611 case TRACE_OPTION_CONSTANT_ERF_FRAMING: 755 612 break; 613 case TRACE_OPTION_DISCARD_META: 614 if (*(int *)data > 0) { 615 DATA(libtrace)->discard_meta = true; 616 } else { 617 DATA(libtrace)->discard_meta = false; 618 } 619 return 0; 756 620 } 757 621 … … 886 750 static int pcapng_get_framing_length(const libtrace_packet_t *packet) { 887 751 888 752 switch(pcapng_get_record_type(packet)) { 889 753 case PCAPNG_SECTION_TYPE: 890 754 return sizeof(pcapng_sec_t); … … 902 766 return sizeof(pcapng_nrb_t); 903 767 case PCAPNG_CUSTOM_TYPE: 768 return sizeof(pcapng_custom_t); 904 769 case PCAPNG_CUSTOM_NONCOPY_TYPE: 905 770 return sizeof(pcapng_custom_t); 906 } 771 case PCAPNG_DECRYPTION_SECRETS_TYPE: 772 return sizeof(pcapng_secrets_t); 773 } 907 774 908 775 /* If we get here, we aren't a valid pcapng packet */ … … 1003 870 } 1004 871 case PCAPNG_SIMPLE_PACKET_TYPE: { 872 /* If no section header or interface packets have been received create and 873 * output them. This can occur when discard meta is enabled and the input 874 * format is also pcapng */ 875 if (DATAOUT(libtrace)->sechdr_count == 0) { 876 pcapng_create_output_sectionheader_packet(libtrace); 877 } 1005 878 if (DATAOUT(libtrace)->nextintid == 0) { 1006 trace_set_err_out(libtrace, TRACE_ERR_BAD_PACKET, 1007 "Cannot output simple packet before a interface " 1008 "block has been output in pcapng_write_packet()\n"); 1009 return -1; 879 pcapng_create_output_interface_packet(libtrace, linktype); 1010 880 } 1011 881 return pcapng_output_simple_packet(libtrace, packet); … … 1015 885 } 1016 886 case PCAPNG_INTERFACE_STATS_TYPE: { 1017 if (DATAOUT(libtrace)->nextintid == 0) { 1018 trace_set_err_out(libtrace, TRACE_ERR_BAD_PACKET, 1019 "Cannot output a interface statistics block before a " 1020 "interface block has been output in pcapng_write_packet()\n"); 1021 return -1; 1022 } 887 /* If no section header or interface packets have been received create and 888 * output them. This can occur when discard meta is enabled and the input 889 * format is also pcapng */ 890 if (DATAOUT(libtrace)->sechdr_count == 0) { 891 pcapng_create_output_sectionheader_packet(libtrace); 892 } 893 if (DATAOUT(libtrace)->nextintid == 0) { 894 pcapng_create_output_interface_packet(libtrace, linktype); 895 } 1023 896 return pcapng_output_interfacestats_packet(libtrace, packet); 1024 897 } 1025 898 case PCAPNG_ENHANCED_PACKET_TYPE: { 1026 if (DATAOUT(libtrace)->nextintid == 0) { 1027 trace_set_err_out(libtrace, TRACE_ERR_BAD_PACKET, 1028 "Cannot output enhanced packet before a interface " 1029 "block has been output in pcapng_write_packet()\n"); 1030 return -1; 1031 } 899 /* If no section header or interface packets have been received create and 900 * output them. This can occur when discard meta is enabled and the input 901 * format is also pcapng */ 902 if (DATAOUT(libtrace)->sechdr_count == 0) { 903 pcapng_create_output_sectionheader_packet(libtrace); 904 } 905 if (DATAOUT(libtrace)->nextintid == 0) { 906 pcapng_create_output_interface_packet(libtrace, linktype); 907 } 1032 908 return pcapng_output_enhanced_packet(libtrace, packet); 1033 909 } … … 1044 920 default: { 1045 921 1046 /* create section header if not already*/922 /* create and output section header if none have occured yet */ 1047 923 if (DATAOUT(libtrace)->sechdr_count == 0) { 1048 /* Create section block */ 1049 pcapng_sec_t sechdr; 1050 sechdr.blocktype = pcapng_swap32(libtrace, PCAPNG_SECTION_TYPE); 1051 sechdr.blocklen = pcapng_swap32(libtrace, 28); 1052 sechdr.ordering = pcapng_swap32(libtrace, 0x1A2B3C4D); 1053 sechdr.majorversion = pcapng_swap16(libtrace, 1); 1054 sechdr.minorversion = 0; 1055 sechdr.sectionlen = 0xFFFFFFFFFFFFFFFF; 1056 1057 wandio_wwrite(DATAOUT(libtrace)->file, &sechdr, sizeof(sechdr)); 1058 wandio_wwrite(DATAOUT(libtrace)->file, &sechdr.blocklen, sizeof(sechdr.blocklen)); 1059 1060 DATAOUT(libtrace)->sechdr_count += 1; 924 pcapng_create_output_sectionheader_packet(libtrace); 1061 925 } 1062 926 1063 /* create interface header if not already or if the linktype has changed */ 927 /* create and output interface header if not already or if the 928 * linktype has changed */ 1064 929 if (DATAOUT(libtrace)->nextintid == 0 1065 930 || DATAOUT(libtrace)->lastdlt != linktype) { 1066 /* Create interface block*/ 1067 pcapng_int_t inthdr; 1068 inthdr.blocktype = pcapng_swap32(libtrace, PCAPNG_INTERFACE_TYPE); 1069 inthdr.blocklen = pcapng_swap32(libtrace, 20); 1070 inthdr.linktype = pcapng_swap16(libtrace, libtrace_to_pcap_dlt(linktype)); 1071 inthdr.reserved = 0; 1072 inthdr.snaplen = 0; 1073 1074 wandio_wwrite(DATAOUT(libtrace)->file, &inthdr, sizeof(inthdr)); 1075 wandio_wwrite(DATAOUT(libtrace)->file, &inthdr.blocklen, sizeof(inthdr.blocklen)); 1076 1077 /* increment the interface counter */ 1078 DATAOUT(libtrace)->nextintid += 1; 1079 /* update the last linktype */ 1080 DATAOUT(libtrace)->lastdlt = linktype; 931 932 pcapng_create_output_interface_packet(libtrace, linktype); 1081 933 } 1082 934 … … 1769 1621 /* Section Header */ 1770 1622 case PCAPNG_SECTION_TYPE: 1771 err = pcapng_read_section(libtrace, packet, flags); 1772 gotpacket = 1; 1623 /* Section header packets are required for PCAPNG so even if discard_meta 1624 * option is set it still needs to be processed. Not setting gotpacket will 1625 * prevent triggering the meta callback */ 1626 err = pcapng_read_section(libtrace, packet, flags); 1627 if (!DATA(libtrace)->discard_meta) { 1628 gotpacket = 1; 1629 } 1630 1773 1631 break; 1774 1632 1775 1633 /* Interface Header */ 1776 1634 case PCAPNG_INTERFACE_TYPE: 1635 /* Same applies here for Interface packets */ 1777 1636 err = pcapng_read_interface(libtrace, packet, to_read, flags); 1778 gotpacket = 1; 1637 if (!DATA(libtrace)->discard_meta) { 1638 gotpacket = 1; 1639 } 1779 1640 break; 1780 1641 … … 1792 1653 1793 1654 case PCAPNG_INTERFACE_STATS_TYPE: 1794 err = pcapng_read_stats(libtrace, packet, to_read, flags); 1795 gotpacket = 1; 1655 /* If discard_meta is set ignore this packet type */ 1656 if (!DATA(libtrace)->discard_meta) { 1657 err = pcapng_read_stats(libtrace, packet, to_read, flags); 1658 gotpacket = 1; 1659 } 1796 1660 break; 1797 1661 1798 1662 case PCAPNG_NAME_RESOLUTION_TYPE: 1799 err = pcapng_read_nrb(libtrace, packet, to_read, flags); 1800 gotpacket = 1; 1663 /* If discard meta is set ignore this packet type */ 1664 if (!DATA(libtrace)->discard_meta) { 1665 err = pcapng_read_nrb(libtrace, packet, to_read, flags); 1666 gotpacket = 1; 1667 } 1801 1668 break; 1802 1669 1803 1670 case PCAPNG_CUSTOM_TYPE: 1804 1671 case PCAPNG_CUSTOM_NONCOPY_TYPE: 1805 err = pcapng_read_custom(libtrace, packet, to_read, flags); 1806 gotpacket = 1; 1672 /* If discard meta is set ignore this packet type */ 1673 if (!DATA(libtrace)->discard_meta) { 1674 err = pcapng_read_custom(libtrace, packet, to_read, flags); 1675 gotpacket = 1; 1676 } 1807 1677 break; 1808 1678 … … 1838 1708 static libtrace_direction_t pcapng_get_direction(const libtrace_packet_t 1839 1709 *packet) { 1710 libtrace_direction_t direction = -1; 1840 1711 1841 1712 /* Defined in format_helper.c */ 1842 return pcap_get_direction(packet); 1713 if (PACKET_IS_ENHANCED || PACKET_IS_SIMPLE || PACKET_IS_OLD) { 1714 direction = pcap_get_direction(packet); 1715 } 1716 1717 return direction; 1843 1718 } 1844 1719 … … 1942 1817 return ohdr->wlen; 1943 1818 } 1944 } 1819 } else if (PACKET_IS_SECTION || PACKET_IS_INTERFACE || PACKET_IS_NAME_RESOLUTION 1820 || PACKET_IS_INTERFACE_STATS || PACKET_IS_CUSTOM || 1821 PACKET_IS_CUSTOM_NONCOPY || PACKET_IS_DECRYPTION_SECRETS) { 1822 /* meta packet are not transmitted on the wire hence the 0 wirelen */ 1823 return 0; 1824 } 1945 1825 1946 1826 /* If we get here, we aren't a valid pcapng packet */ … … 1958 1838 if (baselen == -1) 1959 1839 return -1; 1840 1841 /* if packet was a meta packet baselen should be zero so return it */ 1842 if (baselen == 0) { 1843 return 0; 1844 } 1960 1845 1961 1846 /* Then, account for the vagaries of different DLTs */ … … 2023 1908 return ohdr->caplen; 2024 1909 } 2025 } 1910 } else if (PACKET_IS_SECTION || PACKET_IS_INTERFACE || PACKET_IS_NAME_RESOLUTION 1911 || PACKET_IS_INTERFACE_STATS || PACKET_IS_CUSTOM || 1912 PACKET_IS_CUSTOM_NONCOPY || PACKET_IS_DECRYPTION_SECRETS) { 1913 1914 struct pcapng_peeker *hdr = (struct pcapng_peeker *)packet->header; 1915 if (DATA(packet->trace)->byteswapped) { 1916 return byteswap32(hdr->blocklen) - trace_get_framing_length(packet); 1917 } else { 1918 return hdr->blocklen - trace_get_framing_length(packet); 1919 } 1920 } 2026 1921 2027 1922 /* If we get here, we aren't a valid pcapng packet */ … … 2152 2047 stat->captured_valid = 1; 2153 2048 2049 2050 } 2051 2052 static libtrace_meta_datatype_t pcapng_get_datatype(uint32_t section, uint32_t option) { 2053 switch(section) { 2054 case(PCAPNG_SECTION_TYPE): 2055 return TRACE_META_STRING; 2056 case(PCAPNG_INTERFACE_TYPE): 2057 switch(option) { 2058 case(PCAPNG_META_IF_NAME): return TRACE_META_STRING; 2059 case(PCAPNG_META_IF_DESCR): return TRACE_META_STRING; 2060 case(PCAPNG_META_IF_IP4): return TRACE_META_IPV4; 2061 case(PCAPNG_META_IF_IP6): return TRACE_META_IPV6; 2062 case(PCAPNG_META_IF_MAC): return TRACE_META_MAC; 2063 case(PCAPNG_META_IF_EUI): return TRACE_META_UINT64; 2064 case(PCAPNG_META_IF_SPEED): return PCAPNG_META_IF_SPEED; 2065 case(PCAPNG_META_IF_TSRESOL): return TRACE_META_UINT8; 2066 case(PCAPNG_META_IF_TZONE): return TRACE_META_UINT32; 2067 case(PCAPNG_META_IF_FILTER): return TRACE_META_STRING; 2068 case(PCAPNG_META_IF_OS): return TRACE_META_STRING; 2069 case(PCAPNG_META_IF_FCSLEN): return TRACE_META_UINT8; 2070 case(PCAPNG_META_IF_TSOFFSET): return TRACE_META_UINT64; 2071 case(PCAPNG_META_IF_HARDWARE): return TRACE_META_STRING; 2072 } 2073 case(PCAPNG_OLD_PACKET_TYPE): 2074 switch(option) { 2075 case(PCAPNG_META_OLD_FLAGS): return TRACE_META_UINT32; 2076 case(PCAPNG_META_OLD_HASH): return TRACE_META_STRING; 2077 } 2078 case(PCAPNG_SIMPLE_PACKET_TYPE): 2079 /* simple packets should not contain any options */ 2080 return TRACE_META_UNKNOWN; 2081 case(PCAPNG_NAME_RESOLUTION_TYPE): 2082 /* todo - needs to handle name resolution options along with 2083 * normal options */ 2084 return TRACE_META_UNKNOWN; 2085 case(PCAPNG_INTERFACE_STATS_TYPE): 2086 return TRACE_META_UINT64; 2087 case(PCAPNG_ENHANCED_PACKET_TYPE): 2088 switch(option) { 2089 case(PCAPNG_META_EPB_FLAGS): return TRACE_META_UINT32; 2090 case(PCAPNG_META_EPB_HASH): return TRACE_META_STRING; 2091 case(PCAPNG_META_EPB_DROPCOUNT): return TRACE_META_UINT64; 2092 } 2093 case(PCAPNG_DECRYPTION_SECRETS_TYPE): 2094 /* todo - needs to handle decryption secrets options along with 2095 * normal options */ 2096 return TRACE_META_UNKNOWN; 2097 default: 2098 return TRACE_META_UNKNOWN; 2099 } 2100 } 2101 2102 static void *pcapng_jump_to_options(libtrace_packet_t *packet) { 2103 2104 struct pcapng_peeker *hdr = (struct pcapng_peeker *)packet->buffer; 2105 void *ptr = packet->buffer; 2106 uint32_t blocktype; 2107 2108 if (DATA(packet->trace)->byteswapped) { 2109 blocktype = byteswap32(hdr->blocktype); 2110 } else { 2111 blocktype = hdr->blocktype; 2112 } 2113 2114 /* Skip x bytes to the options depending on what kind of packet this is */ 2115 if (blocktype == PCAPNG_SECTION_TYPE) { ptr += sizeof(pcapng_sec_t); } 2116 else if (blocktype == PCAPNG_INTERFACE_TYPE) { ptr += sizeof(pcapng_int_t); } 2117 else if (blocktype == PCAPNG_OLD_PACKET_TYPE) { ptr += sizeof(pcapng_opkt_t); } 2118 else if (blocktype == PCAPNG_NAME_RESOLUTION_TYPE) { ptr += sizeof(pcapng_nrb_t); } 2119 else if (blocktype == PCAPNG_INTERFACE_STATS_TYPE) { ptr += sizeof(pcapng_stats_t); } 2120 else if (blocktype == PCAPNG_ENHANCED_PACKET_TYPE) { 2121 /* jump over the the enchanced packet header and data to the options */ 2122 pcapng_epkt_t *epkthdr = (pcapng_epkt_t *)ptr; 2123 uint32_t seclen; 2124 if (DATA(packet->trace)->byteswapped) { 2125 seclen = byteswap32(epkthdr->caplen); 2126 } else { 2127 seclen = epkthdr->caplen; 2128 } 2129 if ((seclen % 4) != 0) { 2130 ptr += seclen + (4 -(seclen % 4)) + sizeof(pcapng_secrets_t); 2131 } else { 2132 ptr += seclen + sizeof(pcapng_secrets_t); 2133 } 2134 } 2135 else if (blocktype == PCAPNG_DECRYPTION_SECRETS_TYPE) { 2136 /* jump over the decryption secrets header and data to the options */ 2137 pcapng_secrets_t *sechdr = (pcapng_secrets_t *)ptr; 2138 uint32_t seclen; 2139 if (DATA(packet->trace)->byteswapped) { 2140 seclen = byteswap32(sechdr->secrets_len); 2141 } else { 2142 seclen = sechdr->secrets_len; 2143 } 2144 if ((seclen % 4) != 0) { 2145 ptr += seclen + (4 -(seclen % 4)) + sizeof(pcapng_secrets_t); 2146 } else { 2147 ptr += seclen + sizeof(pcapng_secrets_t); 2148 } 2149 } 2150 else { return NULL; } 2151 2152 return ptr; 2153 } 2154 2155 void *pcapng_get_meta_section(libtrace_packet_t *packet, uint32_t section) { 2156 2157 struct pcapng_peeker *hdr; 2158 uint32_t remaining; 2159 void *ptr; 2160 uint32_t blocktype; 2161 uint16_t optcode; 2162 uint16_t len; 2163 uint16_t tmp; 2164 2165 if (packet == NULL) { 2166 fprintf(stderr, "NULL packet passed into pcapng_get_meta_section()\n"); 2167 return NULL; 2168 } 2169 if (packet->buffer == NULL) { return NULL; } 2170 2171 hdr = (struct pcapng_peeker *)packet->buffer; 2172 ptr = pcapng_jump_to_options(packet); 2173 2174 if (DATA(packet->trace)->byteswapped) { 2175 blocktype = byteswap32(hdr->blocktype); 2176 remaining = byteswap32(hdr->blocklen); 2177 } else { 2178 blocktype = hdr->blocktype; 2179 remaining = hdr->blocklen; 2180 } 2181 2182 /* If the data we want is not within this blocktype */ 2183 if (blocktype != section) { 2184 return NULL; 2185 } 2186 2187 /* update remaining to account for header and any payload */ 2188 remaining -= (ptr - packet->buffer); 2189 2190 struct pcapng_optheader *opthdr = ptr; 2191 if (DATA(packet->trace)->byteswapped) { 2192 optcode = byteswap16(opthdr->optcode); 2193 len = byteswap16(opthdr->optlen); 2194 } else { 2195 optcode = opthdr->optcode; 2196 len = opthdr->optlen; 2197 } 2198 2199 /* setup structure to hold the result */ 2200 libtrace_meta_t *result = malloc(sizeof(libtrace_meta_t)); 2201 result->section = section; 2202 result->num = 0; 2203 2204 while (optcode != PCAPNG_OPTION_END && remaining > sizeof(struct pcapng_optheader)) { 2205 2206 result->num += 1; 2207 if (result->num == 1) { 2208 result->items = malloc(sizeof(libtrace_meta_item_t)); 2209 } else { 2210 result->items = realloc(result->items, 2211 result->num*sizeof(libtrace_meta_item_t)); 2212 } 2213 result->items[result->num-1].option = optcode; 2214 result->items[result->num-1].len = len; 2215 result->items[result->num-1].datatype = 2216 pcapng_get_datatype(section, optcode); 2217 2218 /* If the datatype is a string allow for a null terminator */ 2219 if (result->items[result->num-1].datatype == TRACE_META_STRING) { 2220 result->items[result->num-1].data = 2221 calloc(1, len+1); 2222 ((char *)result->items[result->num-1].data)[len] = '\0'; 2223 /* and copy the utf8 string */ 2224 memcpy(result->items[result->num-1].data, 2225 ptr+sizeof(struct pcapng_optheader), len); 2226 } else { 2227 result->items[result->num-1].data = 2228 calloc(1, len); 2229 /* depending on the datatype we need to ensure the data is 2230 * in host byte ordering */ 2231 if (result->items[result->num-1].datatype == TRACE_META_UINT32) { 2232 uint32_t t = *(uint32_t *)(ptr+sizeof(struct pcapng_optheader)); 2233 t = ntohl(t); 2234 memcpy(result->items[result->num-1].data, 2235 &t, sizeof(uint32_t)); 2236 } else if(result->items[result->num-1].datatype == TRACE_META_UINT64) { 2237 uint64_t t = *(uint64_t *)(ptr+sizeof(struct pcapng_optheader)); 2238 t = bswap_be_to_host64(t); 2239 memcpy(result->items[result->num-1].data, 2240 &t, sizeof(uint64_t)); 2241 } else { 2242 memcpy(result->items[result->num-1].data, 2243 ptr+sizeof(struct pcapng_optheader), len); 2244 } 2245 2246 } 2247 2248 /* work out any padding */ 2249 if ((len % 4) != 0) { 2250 tmp = len + (4 - (len % 4)) + sizeof(struct pcapng_optheader); 2251 } else { 2252 tmp = len + sizeof(struct pcapng_optheader); 2253 } 2254 ptr += tmp; 2255 remaining -= tmp; 2256 2257 /* get the next option */ 2258 opthdr = (struct pcapng_optheader *)ptr; 2259 if (DATA(packet->trace)->byteswapped) { 2260 optcode = byteswap16(opthdr->optcode); 2261 len = byteswap16(opthdr->optlen); 2262 } else { 2263 optcode = opthdr->optcode; 2264 len = opthdr->optlen; 2265 } 2266 } 2267 2268 /* if any data was found result->num will be greater than 0 */ 2269 if (result->num > 0) { 2270 return (void *)result; 2271 } else { 2272 free(result); 2273 return NULL; 2274 } 2154 2275 2155 2276 } … … 2192 2313 pcapng_get_timespec, /* get_timespec */ 2193 2314 NULL, /* get_seconds */ 2315 pcapng_get_meta_section, /* get_meta_section */ 2194 2316 NULL, /* seek_erf */ 2195 2317 NULL, /* seek_timeval */ -
lib/format_rt.c
r2193905 r254c926 863 863 NULL, /* get_timespec */ 864 864 NULL, /* get_seconds */ 865 NULL, /* get_meta_section */ 865 866 NULL, /* seek_erf */ 866 867 NULL, /* seek_timeval */ -
lib/format_tsh.c
r2193905 r254c926 252 252 NULL, /* get_timespec */ 253 253 NULL, /* get_seconds */ 254 NULL, /* get_meta_section */ 254 255 NULL, /* seek_erf */ 255 256 NULL, /* seek_timeval */ … … 302 303 NULL, /* get_timespec */ 303 304 NULL, /* get_seconds */ 305 NULL, /* get_meta_section */ 304 306 NULL, /* seek_erf */ 305 307 NULL, /* seek_timeval */ -
lib/libtrace.h.in
rdb919d5 r58c226e 471 471 TRACE_RT_DUCK_5_0 =19,/**< Dag 5.0 Duck */ 472 472 TRACE_RT_PCAPNG_META =20,/**< Metadata for a PCAP NG input source */ 473 TRACE_RT_ERF_META =21,/**< Metadata for a ERF input source */ 473 474 474 475 /** Not actually used - all DATA types begin from this value */ … … 613 614 }; 614 615 616 /** Enumeration of datatype returned inside libtrace_meta_item_t structure */ 617 typedef enum { 618 TRACE_META_UINT8 = 1, 619 TRACE_META_UINT32 = 2, 620 TRACE_META_UINT64 = 3, 621 TRACE_META_STRING = 4, 622 TRACE_META_UNKNOWN = 5, 623 TRACE_META_IPV4 = 6, 624 TRACE_META_IPV6 = 7, 625 TRACE_META_MAC = 8, 626 } libtrace_meta_datatype_t; 627 628 typedef struct libtrace_meta_item { 629 uint16_t option; 630 char *option_name; 631 uint16_t len; 632 libtrace_meta_datatype_t datatype; 633 void *data; 634 } libtrace_meta_item_t; 635 636 typedef struct libtrace_meta_section { 637 uint16_t section; 638 uint16_t num; 639 libtrace_meta_item_t *items; 640 } libtrace_meta_t; 641 615 642 typedef struct libtrace_packet_cache { 616 643 int capture_length; /**< Cached capture length */ … … 649 676 int refcount; /**< Reference counter */ 650 677 int which_trace_start; /**< Used to match packet to a started instance of the parent trace */ 651 652 678 } libtrace_packet_t; 653 679 … … 1410 1436 * trying to calculate it from the packet type. */ 1411 1437 TRACE_OPTION_CONSTANT_ERF_FRAMING, 1438 1439 /** If enabled all meta packet will be discarded */ 1440 TRACE_OPTION_DISCARD_META, 1412 1441 } trace_option_t; 1413 1442 … … 3775 3804 /*@}*/ 3776 3805 3806 /* Destroy libtrace_meta_t structure 3807 * 3808 * @params libtrace_meta_t structure 3809 * returns 1 on success, -1 on failure 3810 */ 3811 DLLEXPORT int trace_destroy_meta(libtrace_meta_t *result); 3812 3813 /* Get the interface name/s for a meta packet. 3814 * Must be destroyed with trace_destroy_meta(). 3815 * 3816 * @params libtrace_packet_t meta packet. 3817 * @returns Pointer to libtrace_meta_t structure containing all found interface names 3818 * or NULL. 3819 */ 3820 DLLEXPORT libtrace_meta_t *trace_get_interface_name_meta(libtrace_packet_t *packet); 3821 3822 /* Get the interface name for a meta packet. 3823 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to 3824 * specify the interface index. 3825 * 3826 * @params libtrace_packet_t meta packet to extract the interface name from. 3827 * @params A pointer to a character buffer to store the interface name in. 3828 * @params The size of the buffer passed in. 3829 * @params The interface index within the meta packet. 3830 * @returns Pointer to the character buffer containing the interface name or NULL. 3831 */ 3832 DLLEXPORT char *trace_get_interface_name(libtrace_packet_t *packet, char *space, int spacelen, 3833 int index); 3834 3835 /* Get the interface MAC address/s for a meta packet. 3836 * Must be destroyed with trace_destroy_meta(). 3837 * 3838 * @params libtrace_packet_t meta packet. 3839 * @returns Pointer to libtrace_meta_t structure containing all found interface mac 3840 * addresses or NULL. 3841 */ 3842 DLLEXPORT libtrace_meta_t *trace_get_interface_mac_meta(libtrace_packet_t *packet); 3843 3844 /* Get the interface MAC address for a meta packet. 3845 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to 3846 * specify the interface index. 3847 * 3848 * @params libtrace_packet_t meta packet to extract the MAC address from. 3849 * @params A pointer to a character buffer to store the MAC address in. 3850 * @params The size of the buffer passed in. 3851 * @params The interface index within the meta packet. 3852 * @returns Pointer to the character buffer containing the MAC address or NULL. 3853 */ 3854 DLLEXPORT char *trace_get_interface_mac(libtrace_packet_t *packet, char *space, int spacelen, 3855 int index); 3856 3857 /* Get the interface speed/s from a meta packet. 3858 * Must be destroyed with trace_destroy_meta(). 3859 * 3860 * @params libtrace_packet_t packet. 3861 * @returns Pointer to libtrace_meta_t structure containing all found interface 3862 * speeds or NULL. 3863 */ 3864 DLLEXPORT libtrace_meta_t *trace_get_interface_speed_meta(libtrace_packet_t *packet); 3865 3866 /* Get the interface speed for a meta packet. 3867 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to 3868 * specify the interface index. 3869 * 3870 * @params libtrace_packet_t meta packet to extract the interface speed from. 3871 * @params The interface index within the meta packet. 3872 * @returns uint64_t interface speed or NULL. 3873 */ 3874 DLLEXPORT uint64_t trace_get_interface_speed(libtrace_packet_t *packet, int index); 3875 3876 /* Get the interface ipv4 address/s for a meta packet. 3877 * Must be destroyed with trace_destroy_meta(). 3878 * 3879 * @params libtrace_packet_t meta packet. 3880 * @returns Pointer to libtrace_meta_t structure containing all found ipv4 addresses 3881 * or NULL 3882 */ 3883 DLLEXPORT libtrace_meta_t *trace_get_interface_ipv4_meta(libtrace_packet_t *packet); 3884 3885 /* Get the interface ipv4 address for a meta packet. 3886 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to 3887 * specify the interface index. 3888 * 3889 * @params libtrace_packet_t meta packet to extract the ipv4 address from. 3890 * @params The interface index within the meta packet. 3891 * @returns uint32_t ipv4 address or 0. 3892 */ 3893 DLLEXPORT uint32_t trace_get_interface_ipv4(libtrace_packet_t *packet, int index); 3894 3895 /* Get the interface ipv4 address string for a meta packet. 3896 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to 3897 * specify the interface index. 3898 * 3899 * @params libtrace_packet_t meta packet to extract the ipv4 address from. 3900 * @params A pointer to a character buffer to store the ipv4 address string in. 3901 * @params The size of the buffer passed in. 3902 * @params The interface index within the meta packet. 3903 * @returns Pointer to the character buffer containing the ipv4 address string or NULL. 3904 */ 3905 DLLEXPORT char *trace_get_interface_ipv4_string(libtrace_packet_t *packet, char* space, int spacelen, 3906 int index); 3907 3908 /* Get the interface ipv6 address/s for a meta packet. 3909 * Must be destroyed with trace_destroy_meta(). 3910 * 3911 * @params libtrace_packet_t meta packet. 3912 * @returns Pointer to libtrace_meta_t structure containing all found ipv6 addresses 3913 * or NULL. 3914 */ 3915 DLLEXPORT libtrace_meta_t *trace_get_interface_ipv6_meta(libtrace_packet_t *packet); 3916 3917 /* Get the interface ipv6 address for a meta packet. 3918 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to 3919 * specify the interface index. 3920 * 3921 * @params libtrace_packet_t meta packet to extract the ipv6 address from. 3922 * @params A pointer to a character buffer to store the ipv6 address in. 3923 * @params The size of the buffer passed in. 3924 * @params The interface index within the meta packet. 3925 * @returns Pointer to the buffer containing the ipv6 address or NULL. 3926 */ 3927 DLLEXPORT void *trace_get_interface_ipv6(libtrace_packet_t *packet, void *space, int spacelen, 3928 int index); 3929 3930 /* Get the interface ipv6 address string for a meta packet. 3931 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to 3932 * specify the interface index. 3933 * 3934 * @params libtrace_packet_t meta packet to extract the ipv6 address from. 3935 * @params A pointer to a character buffer to store the ipv6 address in. 3936 * @params The size of the buffer passed in. 3937 * @params The interface index within the meta packet. 3938 * @returns Pointer to the character buffer containing the ipv6 address string or NULL. 3939 */ 3940 DLLEXPORT char *trace_get_interface_ipv6_string(libtrace_packet_t *packet, char *space, int spacelen, 3941 int index); 3942 3943 /* Get the interface description/s for a meta packet. 3944 * Must be destroyed with trace_destroy_meta(). 3945 * 3946 * @params libtrace_packet_t meta packet. 3947 * @returns Pointer to libtrace_meta_t structure containing all found interface 3948 * descriptions or NULL. 3949 */ 3950 DLLEXPORT libtrace_meta_t *trace_get_interface_description_meta(libtrace_packet_t *packet); 3951 3952 /* Get the interface description for a meta packet. 3953 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to 3954 * specify the interface index. 3955 * 3956 * @params libtrace_packet_t meta packet to extract the interface description from. 3957 * @params A pointer to a character buffer to store the interface description in. 3958 * @params The size of the buffer passed in. 3959 * @params The interface index within the meta packet. 3960 * @returns Pointer to the character buffer containing the interface description or NULL. 3961 */ 3962 DLLEXPORT char *trace_get_interface_description(libtrace_packet_t *packet, char *space, int spacelen, 3963 int index); 3964 3965 /* Get the host OS for a meta packet. 3966 * Must be destroyed with trace_destroy_meta(). 3967 * 3968 * @params libtrace_packet_t meta packet. 3969 * @returns Pointer to libtrace_meta_t structure containing the host OS or NULL. 3970 */ 3971 DLLEXPORT libtrace_meta_t *trace_get_host_os_meta(libtrace_packet_t *packet); 3972 3973 /* Get the host OS for a meta packet. 3974 * 3975 * @params libtrace_packet_t meta packet to extract the host OS from. 3976 * @params A pointer to a character buffer to store the host OS in. 3977 * @params The size of the buffer passed in. 3978 * @returns Pointer to the character buffer containing the host OS or NULL. 3979 */ 3980 DLLEXPORT char *trace_get_host_os(libtrace_packet_t *packet, char *space, int spacelen); 3981 3982 /* Get the interface frame check sequence length for a meta packet. 3983 * Must be destroyed with trace_destroy_meta(). 3984 * 3985 * @params libtrace_packet_t meta packet. 3986 * @returns Pointer to libtrace_meta_t structure containing all found frame check 3987 * sequence lengths or NULL. 3988 */ 3989 DLLEXPORT libtrace_meta_t *trace_get_interface_fcslen_meta(libtrace_packet_t *packet); 3990 3991 /* Get the interface frame check sequence length for a meta packet. 3992 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to 3993 * specify the interface index. 3994 * 3995 * @params libtrace_packet_t meta packet to extract the interface fcslen from. 3996 * @params The interface index within the meta packet. 3997 * @returns uint32_t frame check sequence length or 0. 3998 */ 3999 DLLEXPORT uint32_t trace_get_interface_fcslen(libtrace_packet_t *packet, int index); 4000 4001 /* Get any interface comments for a meta packet 4002 * Must be destroyed with trace_destroy_meta() 4003 * 4004 * @params libtrace_packet_t packet 4005 * @returns Pointer to libtrace_meta_t structure or NULL 4006 */ 4007 DLLEXPORT libtrace_meta_t *trace_get_interface_comment_meta(libtrace_packet_t *packet); 4008 4009 /* Get the interface comment for a meta packet. 4010 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to 4011 * specify the interface ID. 4012 * 4013 * @params libtrace_packet_t meta packet to extract the interface comment from. 4014 * @params A pointer to a character buffer to store the interface description in. 4015 * @params The size of the buffer passed in. 4016 * @params The interface number within the meta packet. 4017 * @returns Pointer to the character buffer containing the hardware description or NULL. 4018 */ 4019 DLLEXPORT char *trace_get_interface_comment(libtrace_packet_t *packet, char *space, int spacelen, 4020 int index); 4021 4022 /* Get the capture application for a meta packet 4023 * Must be destroyed with trace_destroy_meta() 4024 * 4025 * @params libtrace_packet_t packet 4026 * @returns Pointer to libtrace_meta_t structure or NULL 4027 */ 4028 DLLEXPORT libtrace_meta_t *trace_get_capture_application_meta(libtrace_packet_t *packet); 4029 4030 /* Get the capture application for a meta packet. 4031 * 4032 * @params libtrace_packet_t meta packet to extract the application name from. 4033 * @params A pointer to a character buffer to store the application name in. 4034 * @params The size of the buffer passed in. 4035 * @returns Pointer to the character buffer containing the application name or NULL. 4036 */ 4037 DLLEXPORT char *trace_get_capture_application(libtrace_packet_t *packet, char *space, int spacelen); 4038 4039 /* Get a meta section option from a meta packet 4040 * Must be destroyed with trace_destroy_meta() 4041 * 4042 * @params libtrace_packet_t packet 4043 * @params Section code 4044 * @params Option code 4045 * @returns Pointer to libtrace_meta_t structure or NULL 4046 */ 4047 DLLEXPORT libtrace_meta_t *trace_get_section_option(libtrace_packet_t *packet, uint32_t section_code, 4048 uint16_t option_code); 4049 4050 /* Get a section from a meta packet 4051 * Must be destroyed with trace_destroy_meta() 4052 * 4053 * @params libtrace_packet_t packet 4054 * @params Section code 4055 * @returns Pointer to libtrace_meta_t structure or NULL 4056 */ 4057 DLLEXPORT libtrace_meta_t *trace_get_section(libtrace_packet_t *packet, uint32_t section_code); 4058 4059 /* Get the DAG card model from a meta packet. 4060 * 4061 * @params libtrace_packet_t meta packet to extract the DAG model from. 4062 * @params A pointer to a character buffer to store the DAG model in. 4063 * @params The size of the buffer passed in. 4064 * @returns Pointer to the character buffer containing the DAG model or NULL. 4065 */ 4066 DLLEXPORT char *trace_get_erf_dag_card_model(libtrace_packet_t *packet, char *space, 4067 int spacelen); 4068 4069 /* Get the host DAG software version for a meta packet. 4070 * 4071 * @params libtrace_packet_t meta packet to extract the hosts DAG verion from. 4072 * @params A pointer to a character buffer to store the DAG version in. 4073 * @params The size of the buffer passed in. 4074 * @returns Pointer to the character buffer containing the DAG version or NULL. 4075 */ 4076 DLLEXPORT char *trace_get_erf_dag_version(libtrace_packet_t *packet, char *space, 4077 int spacelen); 4078 4079 /* Get the firmware version for a DAG module from a meta packet. 4080 * 4081 * @params libtrace_packet_t meta packet to extract the FW version from. 4082 * @params A pointer to a character buffer to store the FW version in. 4083 * @params The size of the buffer passed in. 4084 * @returns Pointer to the character buffer containing the FW version or NULL. 4085 */ 4086 DLLEXPORT char *trace_get_erf_dag_fw_version(libtrace_packet_t *packet, char *space, 4087 int spacelen); 4088 3777 4089 #ifdef __cplusplus 3778 4090 } /* extern "C" */ 3779 4091 #endif /* #ifdef __cplusplus */ 4092 3780 4093 #endif /* LIBTRACE_H_ */ -
lib/libtrace_int.h
r37ee856 r254c926 294 294 fn_cb_dataless message_pausing; 295 295 fn_cb_packet message_packet; 296 fn_cb_packet message_meta_packet; 296 297 fn_cb_result message_result; 297 298 fn_cb_first_packet message_first_packet; … … 722 723 double (*get_seconds)(const libtrace_packet_t *packet); 723 724 725 /** 726 */ 727 void *(*get_meta_section)(libtrace_packet_t *packet, uint32_t section); 728 724 729 /** Moves the read pointer to a certain ERF timestamp within an input 725 730 * trace file. … … 1200 1205 DLLEXPORT void *trace_get_payload_from_atm(void *link, uint8_t *type, 1201 1206 uint32_t *remaining); 1202 1203 1207 1204 1208 #ifdef HAVE_BPF -
lib/libtrace_parallel.h
rc22a4bb r62b2d97 135 135 */ 136 136 MESSAGE_PACKET, 137 138 /** A libtrace meta packet is ready, this will trigger the meta packet 139 * callback for the processing threads. 140 */ 141 MESSAGE_META_PACKET, 137 142 138 143 /** A libtrace result is ready, this will trigger the result callback … … 519 524 520 525 /** 526 * A callback function triggered when a processing thread receives a meta packet. 527 * 528 * @param libtrace The parallel trace. 529 * @param t The thread that is running 530 * @param global The global storage. 531 * @param tls The thread local storage. 532 * @param packet The packet to be processed. 533 * 534 * @return either the packet itself if it is not being published as a result 535 * or NULL otherwise. If returning NULL, it is the user's responsibility 536 * to ensure the packet is freed when the reporter thread is finished with it. 537 */ 538 typedef libtrace_packet_t* (*fn_cb_meta_packet)(libtrace_t *libtrace, 539 libtrace_thread_t *t, 540 void *global, 541 void *tls, 542 libtrace_packet_t *packet); 543 544 /** 521 545 * Callback for handling a result message. Should only be required by the 522 546 * reporter thread. … … 599 623 DLLEXPORT int trace_set_packet_cb(libtrace_callback_set_t *cbset, 600 624 fn_cb_packet handler); 625 626 /** 627 * Registers a meta packet callback against a callback set. 628 * 629 * @param cbset The callback set. 630 * @param handler The meta packet callback funtion. 631 * @return 0 if successful, -1 otherwise. 632 */ 633 DLLEXPORT int trace_set_meta_packet_cb(libtrace_callback_set_t *cbset, 634 fn_cb_meta_packet handler); 601 635 602 636 /** -
lib/trace.c
rd0941cc rd0f25d4 685 685 return -1; 686 686 687 687 case TRACE_OPTION_DISCARD_META: 688 if (!trace_is_err(libtrace)) { 689 trace_set_err(libtrace, TRACE_ERR_OPTION_UNAVAIL, 690 "Libtrace does not support meta packets for this format"); 691 } 692 return -1; 688 693 } 689 694 if (!trace_is_err(libtrace)) { -
lib/trace_parallel.c
r6d2a120 r8a6910b 242 242 case MESSAGE_PACKET: 243 243 return; 244 } 245 244 case MESSAGE_META_PACKET: 245 return; 246 } 246 247 if (fn) 247 248 (*fn)(trace, thread, trace->global_blob, thread->user_data); … … 496 497 t->accepted_packets++; 497 498 } 498 if (trace->perpkt_cbs->message_packet) 499 *packet = (*trace->perpkt_cbs->message_packet)(trace, t, trace->global_blob, t->user_data, *packet); 499 500 /* If packet is meta call the meta callback */ 501 if (IS_LIBTRACE_META_PACKET((*packet))) { 502 /* Pass to meta callback if defined else pass to packet callback */ 503 if (trace->perpkt_cbs->message_meta_packet) { 504 *packet = (*trace->perpkt_cbs->message_meta_packet)(trace, t, 505 trace->global_blob, t->user_data, *packet); 506 } else if (trace->perpkt_cbs->message_packet) { 507 *packet = (*trace->perpkt_cbs->message_packet)(trace, t, 508 trace->global_blob, t->user_data, *packet); 509 } 510 } else { 511 if (trace->perpkt_cbs->message_packet) { 512 *packet = (*trace->perpkt_cbs->message_packet)(trace, t, 513 trace->global_blob, t->user_data, *packet); 514 } 515 } 500 516 trace_fin_packet(*packet); 501 517 } else { … … 2038 2054 } 2039 2055 2056 DLLEXPORT int trace_set_meta_packet_cb(libtrace_callback_set_t *cbset, 2057 fn_cb_meta_packet handler) { 2058 cbset->message_meta_packet = handler; 2059 return 0; 2060 } 2061 2040 2062 DLLEXPORT int trace_set_first_packet_cb(libtrace_callback_set_t *cbset, 2041 2063 fn_cb_first_packet handler) { … … 2448 2470 DLLEXPORT int trace_post_reporter(libtrace_t *libtrace) 2449 2471 { 2450 libtrace_message_t message = {0, {.uint64=0}, NULL}; 2451 message.code = MESSAGE_POST_REPORTER; 2472 libtrace_message_t message; 2473 memset(&message, 0, sizeof(libtrace_message_t)); 2474 message.code = MESSAGE_POST_REPORTER; 2475 message.data.uint64 = 0; 2476 message.sender = NULL; 2452 2477 return trace_message_reporter(libtrace, (void *) &message); 2453 2478 } -
libpacketdump/Makefile.am
r055a2c9 rd0f25d4 61 61 TXT_PROTOCOLS+=link_17.protocol 62 62 63 #22: ERF META 64 BIN_PROTOCOLS+=link_21.la 65 63 66 # 22: ETSI LI 64 67 if HAVE_WANDDER 65 68 BIN_PROTOCOLS+=link_22.la 66 69 endif 70 71 #23: PCAPNG 72 BIN_PROTOCOLS+=link_23.la 67 73 68 74 # Decoders for various ethertypes (in decimal) … … 140 146 link_11_la_LDFLAGS=$(modflags) 141 147 link_15_la_LDFLAGS=$(modflags) 148 link_21_la_LDFLAGS=$(modflags) 142 149 if HAVE_WANDDER 143 150 link_22_la_LDFLAGS=$(modflags) 144 151 endif 152 link_23_la_LDFLAGS=$(modflags) 145 153 eth_0_la_LDFLAGS=$(modflags) 146 154 eth_2048_la_LDFLAGS=$(modflags) -
libpacketdump/libpacketdump.cc
r8b49230 r23741ec5 41 41 #ifdef HAVE_NETINET_IF_ETHER_H 42 42 # include <netinet/if_ether.h> 43 #endif 43 #endif 44 44 #include <dlfcn.h> 45 45 #include <map> … … 57 57 58 58 typedef void (*decode_norm_t)(uint16_t type,const char *packet,int len); 59 typedef void (*decode_norm_meta)(uint16_t type,const char *packet,int len,libtrace_packet_t *p); 59 60 typedef void (*decode_parser_t)(uint16_t type,const char *packet,int len, element_t* el); 61 62 libtrace_packet_t *p; 60 63 61 64 typedef union decode_funcs { 62 65 decode_norm_t decode_n; 66 decode_norm_meta decode_meta; 63 67 decode_parser_t decode_p; 64 68 } decode_funcs_t; … … 130 134 (int)trace_get_wire_length(packet), 131 135 (int)trace_get_direction(packet)); 132 133 136 134 137 formatted_hexdump(pkt_ptr, (int)length); … … 138 141 void trace_dump_packet(struct libtrace_packet_t *packet) 139 142 { 143 p = packet; 144 140 145 time_t sec = (time_t)trace_get_seconds(packet); 141 146 libtrace_linktype_t linktype; 142 147 uint32_t length; 143 148 const char *link=(char *)trace_get_packet_buffer(packet,&linktype,NULL); 144 149 145 150 length = trace_get_capture_length(packet); 146 147 151 printf("\n%s",ctime(&sec)); 148 152 printf(" Capture: Packet Length: %i/%i Direction Value: %i\n", … … 150 154 (int)trace_get_wire_length(packet), 151 155 (int)trace_get_direction(packet)); 156 152 157 if (!link) 153 158 printf(" [No link layer available]\n"); 154 159 else 155 decode_next(link,length, "link", 156 linktype); 160 decode_next(link,length, "link", linktype); 157 161 } 158 162 … … 223 227 hdl = open_so_decoder(sname.c_str(),type); 224 228 if (hdl) { 225 void *s=dlsym(hdl,"decode"); 229 230 /* PCAPNG format requires the libtrace_packet_t structure in order 231 * to determine the byte ordering */ 232 void *s; 233 if (type == TRACE_TYPE_PCAPNG_META || type == TRACE_TYPE_ERF_META) { 234 s=dlsym(hdl,"decode_meta"); 235 if (s) { func->decode_meta = (decode_norm_meta)s; } 236 } else { 237 s=dlsym(hdl,"decode"); 238 if (s) { func->decode_n = (decode_norm_t)s; } 239 } 240 226 241 if (s) { 227 // use the shared library228 func->decode_n = (decode_norm_t)s;229 242 dec.style = DECODE_NORMAL; 230 243 dec.el = NULL; … … 294 307 { 295 308 case DECODE_NORMAL: 296 decoders[sname][type].func->decode_n(type,packet,len); 309 /* If this is a pcapng packet call the correct function and pass the 310 * libtrace_packet_t structure. We need this to determine the byte ordering */ 311 if (type == TRACE_TYPE_PCAPNG_META || type == TRACE_TYPE_ERF_META) { 312 decoders[sname][type].func->decode_meta(type,packet,len,p); 313 } else { 314 decoders[sname][type].func->decode_n(type,packet,len); 315 } 297 316 break; 298 317 -
libpacketdump/libpacketdump.h
r6654714 rd0f25d4 55 55 56 56 void decode(int link_type, const char *pkt, unsigned len); 57 void decode_meta(int link_type, const char *pkt, unsigned len, libtrace_packet_t *p); 57 58 58 59 #ifdef __cplusplus -
tools/tracepktdump/tracepktdump.cc
rf35a853 r69394f0 110 110 if (filter && !trace_apply_filter(filter,packet)) 111 111 continue; 112 if (packet->type < TRACE_RT_DATA_SIMPLE) 112 if (packet->type < TRACE_RT_DATA_SIMPLE && 113 packet->type != TRACE_RT_PCAPNG_META && 114 packet->type != TRACE_RT_ERF_META) 113 115 /* Ignore RT messages */ 114 116 continue;
Note: See TracChangeset
for help on using the changeset viewer.