- Timestamp:
- 01/07/19 10:35:07 (2 years ago)
- Branches:
- develop
- Children:
- 51276bd
- Parents:
- 979ab1a0
- git-author:
- Jacob Van Walraven <jcv9@…> (12/14/18 09:31:48)
- git-committer:
- Jacob Van Walraven <jcv9@…> (01/07/19 10:35:07)
- Location:
- lib
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_dag25.c
r8c5c550 r9a6bdbc 174 174 * many times or close a device that we're still using */ 175 175 struct dag_dev_t *open_dags = NULL; 176 177 static bool dag_can_write(libtrace_packet_t *packet) { 178 /* Get the linktype */ 179 libtrace_linktype_t ltype = trace_get_link_type(packet); 180 181 if (ltype == TRACE_TYPE_ERF_META 182 || ltype == TRACE_TYPE_NONDATA) { 183 184 return false; 185 } 186 187 return true; 188 } 176 189 177 190 /* Returns the amount of padding between the ERF header and the start of the … … 1186 1199 static int dag_write_packet(libtrace_out_t *libtrace, libtrace_packet_t *packet) 1187 1200 { 1201 /* Check dag can write this type of packet */ 1202 if (!dag_can_write(packet)) { 1203 return 0; 1204 } 1205 1188 1206 /* This is heavily borrowed from erf_write_packet(). Yes, CnP 1189 1207 * coding sucks, sorry about that. … … 1200 1218 return -1; 1201 1219 } 1202 1203 if (trace_get_link_type(packet) == TRACE_TYPE_NONDATA)1204 return 0;1205 1220 1206 1221 pad = dag_get_padding(packet); -
lib/format_dpdk.c
r10fd24b r9a6bdbc 144 144 uint32_t cap_len; /* The size to say the capture is */ 145 145 }; 146 147 static bool dpdk_can_write(libtrace_packet_t *packet) { 148 return true; 149 } 146 150 147 151 /** … … 1557 1561 static int dpdk_write_packet(libtrace_out_t *trace, 1558 1562 libtrace_packet_t *packet){ 1563 1564 /* Check dpdk can write this type of packet */ 1565 if (!dpdk_can_write(packet)) { 1566 return 0; 1567 } 1568 1559 1569 struct rte_mbuf* m_buff[1]; 1560 1570 -
lib/format_erf.c
rd439067 r9a6bdbc 119 119 } erf_index_t; 120 120 121 static bool erf_can_write(libtrace_packet_t *packet) { 122 /* Get the linktype */ 123 libtrace_linktype_t ltype = trace_get_link_type(packet); 124 125 if (ltype == TRACE_TYPE_PCAPNG_META 126 || ltype == TRACE_TYPE_NONDATA) { 127 128 return false; 129 } 130 131 return true; 132 } 133 121 134 /* Ethernet packets have a 2 byte padding before the packet 122 135 * so that the IP header is aligned on a 32 bit boundary. … … 670 683 libtrace_packet_t *packet) 671 684 { 685 686 /* Check erf can write this type of packet */ 687 if (!erf_can_write(packet)) { 688 return 0; 689 } 690 672 691 int numbytes = 0; 673 692 dag_record_t *dag_hdr = (dag_record_t *)packet->header; … … 679 698 return -1; 680 699 } 681 682 if (trace_get_link_type(packet) == TRACE_TYPE_NONDATA)683 return 0;684 700 685 701 if (!packet->header) { -
lib/format_linux_int.c
rd439067 r9a6bdbc 56 56 #ifdef HAVE_NETPACKET_PACKET_H 57 57 58 static bool linuxnative_can_write(libtrace_packet_t *packet) { 59 /* Get the linktype */ 60 libtrace_linktype_t ltype = trace_get_link_type(packet); 61 62 if (ltype == TRACE_TYPE_NONDATA) { 63 return false; 64 } 65 66 return true; 67 } 58 68 59 69 static int linuxnative_start_input(libtrace_t *libtrace) … … 336 346 libtrace_packet_t *packet) 337 347 { 348 /* Check linuxnative can write this type of packet */ 349 if (!linuxnative_can_write(packet)) { 350 return 0; 351 } 352 338 353 struct sockaddr_ll hdr; 339 354 int ret = 0; 340 341 if (trace_get_link_type(packet) == TRACE_TYPE_NONDATA)342 return 0;343 355 344 356 hdr.sll_family = AF_PACKET; -
lib/format_linux_ring.c
rd439067 r9a6bdbc 71 71 static int pagesize = 0; 72 72 73 static bool linuxring_can_write(libtrace_packet_t *packet) { 74 /* Get the linktype */ 75 libtrace_linktype_t ltype = trace_get_link_type(packet); 76 77 if (ltype == TRACE_TYPE_NONDATA) { 78 return false; 79 } 80 81 return true; 82 } 73 83 74 84 /* … … 709 719 libtrace_packet_t *packet) 710 720 { 721 /* Check linuxring can write this type of packet */ 722 if (!linuxring_can_write(packet)) { 723 return 0; 724 } 725 711 726 struct tpacket2_hdr *header; 712 727 struct pollfd pollset; … … 715 730 unsigned max_size; 716 731 void * off; 717 718 if (trace_get_link_type(packet) == TRACE_TYPE_NONDATA)719 return 0;720 732 721 733 max_size = FORMAT_DATA_OUT->req.tp_frame_size - -
lib/format_pcap.c
rd439067 r9a6bdbc 97 97 } output; 98 98 }; 99 100 static bool pcap_can_write(libtrace_packet_t *packet) { 101 /* Get the linktype */ 102 libtrace_linktype_t ltype = trace_get_link_type(packet); 103 104 if (ltype == TRACE_TYPE_PCAPNG_META 105 || ltype == TRACE_TYPE_CONTENT_INVALID 106 || ltype == TRACE_TYPE_UNKNOWN 107 || ltype == TRACE_TYPE_ERF_META 108 || ltype == TRACE_TYPE_NONDATA) { 109 110 return false; 111 } 112 113 return true; 114 } 99 115 100 116 static int pcap_init_input(libtrace_t *libtrace) { … … 521 537 { 522 538 539 /* Check pcap can write this type of packet */ 540 if (!pcap_can_write(packet)) { 541 return 0; 542 } 543 523 544 if (!libtrace) { 524 545 fprintf(stderr, "NULL trace passed into pcap_write_packet()\n"); … … 536 557 537 558 link = trace_get_packet_buffer(packet,&linktype,&remaining); 538 539 /* Silently discard RT metadata packets and packets with an540 * unknown linktype. */541 if (linktype == TRACE_TYPE_NONDATA || linktype == TRACE_TYPE_UNKNOWN || linktype == TRACE_TYPE_ERF_META || linktype == TRACE_TYPE_CONTENT_INVALID) {542 return 0;543 }544 559 545 560 /* We may have to convert this packet into a suitable PCAP packet */ -
lib/format_pcapfile.c
rd439067 r9a6bdbc 68 68 #define MAGIC2_REV 0x4d3cb2a1 69 69 70 static bool pcapfile_can_write(libtrace_packet_t *packet) { 71 /* Get the linktype */ 72 libtrace_linktype_t ltype = trace_get_link_type(packet); 73 74 if (ltype == TRACE_TYPE_PCAPNG_META 75 || ltype == TRACE_TYPE_CONTENT_INVALID 76 || ltype == TRACE_TYPE_UNKNOWN 77 || ltype == TRACE_TYPE_ERF_META 78 || ltype == TRACE_TYPE_NONDATA) { 79 80 return false; 81 } 82 83 return true; 84 } 85 70 86 static inline int header_is_backwards_magic(pcapfile_header_t *header) { 71 87 return (header->magic_number == MAGIC1_REV || header->magic_number == MAGIC2_REV); … … 175 191 if (!DATA(libtrace)) 176 192 return num; 177 193 178 194 /* We can use the PCAP magic number to determine the byte order */ 179 195 if (header_is_backwards_magic(&(DATA(libtrace)->header))) … … 371 387 packet->buffer, 372 388 sizeof(libtrace_pcapfile_pkt_hdr_t)); 389 373 390 if (err<0) { 374 391 trace_set_err(libtrace,TRACE_ERR_WANDIO_FAILED,"reading packet"); … … 432 449 libtrace_packet_t *packet) 433 450 { 451 452 /* Check pcapfile can write this type of packet */ 453 if (!pcapfile_can_write(packet)) { 454 return 0; 455 } 456 434 457 struct libtrace_pcapfile_pkt_hdr_t hdr; 435 458 struct timeval tv = trace_get_timeval(packet); … … 441 464 442 465 ptr = trace_get_packet_buffer(packet,&linktype,&remaining); 443 444 /* Silently discard RT metadata packets and packets with an445 * unknown linktype. */446 if (linktype == TRACE_TYPE_NONDATA || linktype == TRACE_TYPE_UNKNOWN || linktype == TRACE_TYPE_ERF_META || linktype == TRACE_TYPE_CONTENT_INVALID) {447 return 0;448 }449 466 450 467 /* If this packet cannot be converted to a pcap linktype then -
lib/format_pcapng.c
r979ab1a0 r9a6bdbc 198 198 #define DATAOUT(x) ((struct pcapng_format_data_out_t*)((x)->format_data)) 199 199 200 static bool pcapng_can_write(libtrace_packet_t *packet) { 201 /* Get the linktype */ 202 libtrace_linktype_t ltype = trace_get_link_type(packet); 203 204 if (ltype == TRACE_TYPE_CONTENT_INVALID 205 || ltype == TRACE_TYPE_UNKNOWN 206 || ltype == TRACE_TYPE_ERF_META 207 || ltype == TRACE_TYPE_NONDATA) { 208 209 return false; 210 } 211 212 return true; 213 } 214 200 215 static pcapng_interface_t *lookup_interface(libtrace_t *libtrace, 201 216 uint32_t intid) { … … 224 239 /* Section blocks, interface blocks, name resolution blocks, stats blocks and 225 240 * Custom blocks are all of type trace_type_pcapng_meta */ 226 if (trace_get_link_type(packet) == TRACE_TYPE_PCAPNG_META) { 227 if (DATAOUT(packet->trace)->byteswapped) { 228 return byteswap32(*type); 229 } else { 230 return *type; 231 } 232 /* Only check for enhanced or simple packet blocks */ 233 } else { 234 if (DATAOUT(packet->trace)->byteswapped) { 235 *type = byteswap32(*type); 236 } 237 if (*type == 0x00000006 || *type == 0x00000003) { 238 return *type; 239 } 241 if (packet->type == TRACE_RT_PCAPNG_META) { 242 return *type; 243 } 244 245 if (packet->type == 0x00000006 || packet->type == 0x00000003) { 246 return *type; 240 247 } 241 248 /* not a pcapng header type */ … … 269 276 270 277 static struct pcapng_timestamp pcapng_get_timestamp(libtrace_packet_t *packet) { 271 struct time spec ts = trace_get_timespec(packet);272 uint64_t time = (( (uint64_t) ts.tv_sec) * 1000000LL) + ts.tv_nsec / 1000;278 struct timeval tv = trace_get_timeval(packet); 279 uint64_t time = ((uint64_t)tv.tv_sec * (uint64_t)1000000) + tv.tv_usec; 273 280 274 281 struct pcapng_timestamp timestamp; … … 555 562 } 556 563 557 libtrace_linktype_t linktype; 558 559 linktype = trace_get_link_type(packet); 560 /* discard meta packets from other capture types and unknown packets 561 * could try to convert erf meta packets? */ 562 if (linktype == TRACE_TYPE_NONDATA || linktype == TRACE_TYPE_UNKNOWN 563 || linktype == TRACE_TYPE_ERF_META || linktype == TRACE_TYPE_CONTENT_INVALID) { 564 return 0; 565 } 564 /* Check pcapng can write this type of packet */ 565 if (!pcapng_can_write(packet)) { 566 return 0; 567 } 568 569 libtrace_linktype_t linktype = trace_get_link_type(packet); 566 570 567 571 /* If the file is not open, open it */ … … 572 576 DATAOUT(libtrace)->flag); 573 577 } 574 fprintf(stderr, "switch\n"); 578 575 579 /* If the packet is already encapsulated in a pcapng frame just output it */ 576 580 switch (pcapng_get_header_type(packet)) { … … 693 697 DATAOUT(libtrace)->lastdlt = linktype; 694 698 } 699 695 700 break; 696 701 } … … 711 716 epkthdr.caplen = trace_get_capture_length(packet); 712 717 718 /* trace_get_wirelength includes FCS, while pcapng doesn't */ 719 if (trace_get_link_type(packet)==TRACE_TYPE_ETH) { 720 if (epkthdr.wlen >= 4) { 721 epkthdr.wlen -= 4; 722 } else { 723 epkthdr.wlen = 0; 724 } 725 } 713 726 /* capture length should always be less than the wirelength */ 714 727 if (epkthdr.caplen > epkthdr.wlen) { … … 819 832 } 820 833 821 packet->type = pcapng_linktype_to_rt(TRACE_RT_PCAPNG_META);834 packet->type = TRACE_RT_PCAPNG_META; 822 835 if (pcapng_prepare_packet(libtrace, packet, packet->buffer, 823 836 packet->type, flags)) { … … 886 899 bodyptr = (char *) packet->buffer + sizeof(pcapng_int_t); 887 900 888 packet->type = pcapng_linktype_to_rt(TRACE_RT_PCAPNG_META);901 packet->type = TRACE_RT_PCAPNG_META; 889 902 890 903 if (pcapng_prepare_packet(libtrace, packet, packet->buffer, … … 951 964 } 952 965 953 packet->type = pcapng_linktype_to_rt(TRACE_RT_PCAPNG_META);966 packet->type = TRACE_RT_PCAPNG_META; 954 967 if (pcapng_prepare_packet(libtrace, packet, packet->buffer, 955 968 packet->type, flags)) { … … 995 1008 } 996 1009 997 packet->type = pcapng_linktype_to_rt(TRACE_RT_PCAPNG_META);1010 packet->type = TRACE_RT_PCAPNG_META; 998 1011 if (pcapng_prepare_packet(libtrace, packet, packet->buffer, 999 1012 packet->type, flags)) { … … 1414 1427 static libtrace_linktype_t pcapng_get_link_type(const libtrace_packet_t *packet) { 1415 1428 1416 struct pcapng_peeker *hdr = (struct pcapng_peeker *)packet->buffer; 1417 1418 if (hdr->blocktype == PCAPNG_SECTION_TYPE 1419 || hdr->blocktype == PCAPNG_INTERFACE_TYPE 1420 || hdr->blocktype == PCAPNG_NAME_RESOLUTION_TYPE 1421 || hdr->blocktype == PCAPNG_INTERFACE_STATS_TYPE 1422 || hdr->blocktype == PCAPNG_CUSTOM_TYPE) { 1429 if (packet->type == TRACE_RT_PCAPNG_META) { 1423 1430 return TRACE_TYPE_PCAPNG_META; 1424 1431 } -
lib/trace.c
rd439067 r9a6bdbc 1718 1718 linktype = trace_get_link_type(packet); 1719 1719 1720 if (linktype == TRACE_TYPE_NONDATA || linktype == TRACE_TYPE_ERF_META) 1720 if (linktype == TRACE_TYPE_NONDATA || linktype == TRACE_TYPE_ERF_META 1721 || linktype == TRACE_TYPE_PCAPNG_META) 1721 1722 return 1; 1722 1723
Note: See TracChangeset
for help on using the changeset viewer.