Changeset d439067
- Timestamp:
- 12/10/18 15:59:45 (2 years ago)
- Branches:
- develop
- Children:
- 10fd24b
- Parents:
- 418c78d
- Location:
- lib
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_erf.c
r509ee47 rd439067 852 852 * wrong value here and subsequent get_capture_length() calls will 853 853 * return the wrong value. */ 854 packet->ca pture_length = -1;854 packet->cached.capture_length = -1; 855 855 erfptr->rlen = htons(size + trace_get_framing_length(packet)); 856 856 wlen = ntohs(erfptr->wlen); -
lib/format_linux_int.c
r2193905 rd439067 461 461 462 462 /* Reset the cached capture length */ 463 packet->ca pture_length = -1;463 packet->cached.capture_length = -1; 464 464 465 465 linux_hdr = (struct libtrace_linuxnative_header *)packet->header; -
lib/format_linux_ring.c
rc337c62f rd439067 468 468 469 469 /* Reset the cached capture length */ 470 packet->ca pture_length = -1;470 packet->cached.capture_length = -1; 471 471 472 472 TO_TP_HDR2(packet->buffer)->tp_snaplen = size; -
lib/format_pcap.c
rc434445 rd439067 765 765 } 766 766 /* Reset the cached capture length */ 767 packet->ca pture_length = -1;767 packet->cached.capture_length = -1; 768 768 pcapptr = (struct pcap_pkthdr *)packet->header; 769 769 pcapptr->caplen = size; -
lib/format_pcapfile.c
r509ee47 rd439067 425 425 /* We may as well cache this value now, seeing as we already had to 426 426 * look it up */ 427 packet->ca pture_length = bytes_to_read;427 packet->cached.capture_length = bytes_to_read; 428 428 return sizeof(libtrace_pcapfile_pkt_hdr_t) + bytes_to_read; 429 429 } … … 712 712 } 713 713 /* Reset the cached capture length */ 714 packet->ca pture_length = -1;714 packet->cached.capture_length = -1; 715 715 pcapptr = (libtrace_pcapfile_pkt_hdr_t *)packet->header; 716 716 pcapptr->caplen = swapl(packet->trace,(uint32_t)size); -
lib/format_pcapng.c
r509ee47 rd439067 840 840 /* May as well cache the capture length now, since we've 841 841 * already got it in the right byte order */ 842 packet->ca pture_length = caplen;842 packet->cached.capture_length = caplen; 843 843 844 844 if (pcapng_prepare_packet(libtrace, packet, packet->buffer, … … 899 899 /* May as well cache the capture length now, since we've 900 900 * already got it in the right byte order */ 901 packet->ca pture_length = caplen;901 packet->cached.capture_length = caplen; 902 902 903 903 if (pcapng_prepare_packet(libtrace, packet, packet->buffer, … … 1349 1349 } 1350 1350 } 1351 packet->ca pture_length = -1;1351 packet->cached.capture_length = -1; 1352 1352 return trace_get_capture_length(packet); 1353 1353 } -
lib/libtrace.h.in
r509ee47 rd439067 577 577 } libtrace_ethertype_t; 578 578 579 /** The libtrace packet structure. Applications shouldn't be 580 * meddling around in here 581 */ 582 typedef struct libtrace_packet_t { 583 struct libtrace_t *trace; /**< Pointer to the trace */ 584 void *header; /**< Pointer to the framing header */ 585 void *payload; /**< Pointer to the link layer */ 586 void *buffer; /**< Allocated buffer */ 587 libtrace_rt_types_t type; /**< RT protocol type for the packet */ 588 buf_control_t buf_control; /**< Describes memory ownership */ 579 typedef struct libtrace_packet_cache { 589 580 int capture_length; /**< Cached capture length */ 590 581 int wire_length; /**< Cached wire length */ … … 600 591 uint8_t transport_proto; /**< Cached transport protocol */ 601 592 uint32_t l4_remaining; /**< Cached transport remaining */ 593 } libtrace_packet_cache_t; 594 595 /** The libtrace packet structure. Applications shouldn't be 596 * meddling around in here 597 */ 598 typedef struct libtrace_packet_t { 599 struct libtrace_t *trace; /**< Pointer to the trace */ 600 void *header; /**< Pointer to the framing header */ 601 void *payload; /**< Pointer to the link layer */ 602 void *buffer; /**< Allocated buffer */ 603 libtrace_rt_types_t type; /**< RT protocol type for the packet */ 604 buf_control_t buf_control; /**< Describes memory ownership */ 605 libtrace_packet_cache_t cached; /**< Cached packet properties / headers */ 602 606 uint64_t order; /**< Notes the order of this packet in relation to the input */ 603 607 uint64_t hash; /**< A hash of the packet as supplied by the user */ -
lib/protocols_l2.c
r2193905 rd439067 181 181 (dest - (char *)packet->payload)); 182 182 packet->payload = nextpayload - (dest - (char *)packet->payload); 183 packet-> l2_header = NULL;183 packet->cached.l2_header = NULL; 184 184 } 185 185 … … 456 456 remaining = &dummyrem; 457 457 458 if (packet-> l2_header) {458 if (packet->cached.l2_header) { 459 459 /* Use cached values */ 460 *linktype = packet-> link_type;461 *remaining = packet-> l2_remaining;462 return packet-> l2_header;460 *linktype = packet->cached.link_type; 461 *remaining = packet->cached.l2_remaining; 462 return packet->cached.l2_header; 463 463 } 464 464 … … 487 487 case TRACE_TYPE_NONDATA: 488 488 case TRACE_TYPE_OPENBSD_LOOP: 489 ((libtrace_packet_t*)packet)-> l2_header = meta;490 ((libtrace_packet_t*)packet)-> l2_remaining = *remaining;489 ((libtrace_packet_t*)packet)->cached.l2_header = meta; 490 ((libtrace_packet_t*)packet)->cached.l2_remaining = *remaining; 491 491 return meta; 492 492 case TRACE_TYPE_LINUX_SLL: … … 525 525 case TRACE_TYPE_NONDATA: 526 526 case TRACE_TYPE_OPENBSD_LOOP: 527 ((libtrace_packet_t*)packet)-> l2_header = meta;528 ((libtrace_packet_t*)packet)-> l2_remaining = *remaining;527 ((libtrace_packet_t*)packet)->cached.l2_header = meta; 528 ((libtrace_packet_t*)packet)->cached.l2_remaining = *remaining; 529 529 return meta; 530 530 case TRACE_TYPE_LINUX_SLL: -
lib/protocols_l3.c
r2193905 rd439067 226 226 227 227 /* use l3 cache */ 228 if (packet-> l3_header)228 if (packet->cached.l3_header) 229 229 { 230 230 /* … … 235 235 */ 236 236 237 *ethertype = packet-> l3_ethertype;238 /* *remaining -= (packet-> l3_header - link); */239 *remaining = packet-> l3_remaining;240 241 return packet-> l3_header;242 } 243 244 if (packet-> l2_header) {245 link = packet-> l2_header;246 linktype = packet-> link_type;247 *remaining = packet-> l2_remaining;237 *ethertype = packet->cached.l3_ethertype; 238 /* *remaining -= (packet->cached.l3_header - link); */ 239 *remaining = packet->cached.l3_remaining; 240 241 return packet->cached.l3_header; 242 } 243 244 if (packet->cached.l2_header) { 245 link = packet->cached.l2_header; 246 linktype = packet->cached.link_type; 247 *remaining = packet->cached.l2_remaining; 248 248 } else { 249 249 link = trace_get_layer2(packet,&linktype,remaining); … … 288 288 /* Store values in the cache for later */ 289 289 /* Cast away constness, nasty, but this is just a cache */ 290 ((libtrace_packet_t*)packet)-> l3_ethertype = *ethertype;291 ((libtrace_packet_t*)packet)-> l3_header = iphdr;292 ((libtrace_packet_t*)packet)-> l3_remaining = *remaining;290 ((libtrace_packet_t*)packet)->cached.l3_ethertype = *ethertype; 291 ((libtrace_packet_t*)packet)->cached.l3_header = iphdr; 292 ((libtrace_packet_t*)packet)->cached.l3_remaining = *remaining; 293 293 294 294 return iphdr; -
lib/protocols_transport.c
r2193905 rd439067 64 64 65 65 /* Just use the cached length if we can */ 66 if (packet-> payload_length != -1)67 return packet-> payload_length;66 if (packet->cached.payload_length != -1) 67 return packet->cached.payload_length; 68 68 69 69 /* Set to zero so that we can return early without having to 70 70 * worry about forgetting to update the cached value */ 71 ((libtrace_packet_t *)packet)-> payload_length = 0;71 ((libtrace_packet_t *)packet)->cached.payload_length = 0; 72 72 layer = trace_get_layer3(packet, ðertype, &rem); 73 73 if (!layer) … … 162 162 } 163 163 164 ((libtrace_packet_t *)packet)-> payload_length = len;164 ((libtrace_packet_t *)packet)->cached.payload_length = len; 165 165 return len; 166 166 … … 181 181 if (!remaining) remaining=&dummy_remaining; 182 182 183 if (packet-> l4_header) {183 if (packet->cached.l4_header) { 184 184 /* 185 185 void *link; … … 189 189 return NULL; 190 190 */ 191 *proto = packet->transport_proto; 192 /* *remaining -= (packet->l4_header - link); */ 193 *remaining = packet->l4_remaining; 194 return packet->l4_header; 191 *proto = packet->cached.transport_proto; 192 *remaining = packet->cached.l4_remaining; 193 return packet->cached.l4_header; 195 194 } 196 195 … … 221 220 } 222 221 223 ((libtrace_packet_t *)packet)-> transport_proto = *proto;224 ((libtrace_packet_t *)packet)-> l4_header = transport;225 ((libtrace_packet_t *)packet)-> l4_remaining = *remaining;222 ((libtrace_packet_t *)packet)->cached.transport_proto = *proto; 223 ((libtrace_packet_t *)packet)->cached.l4_header = transport; 224 ((libtrace_packet_t *)packet)->cached.l4_remaining = *remaining; 226 225 227 226 -
lib/trace.c
r509ee47 rd439067 103 103 /* Set once pstart is called used for backwards compatibility reasons */ 104 104 int libtrace_parallel = 0; 105 106 static const libtrace_packet_cache_t clearcache = { 107 -1, -1, -1, -1, NULL, 0, 0, NULL, 0, 0, NULL, 0, 0}; 105 108 106 109 /* strncpy is not assured to copy the final \0, so we … … 1402 1405 return ~0U; 1403 1406 } 1404 if (packet->ca pture_length == -1) {1407 if (packet->cached.capture_length == -1) { 1405 1408 if (!packet->trace->format->get_capture_length) 1406 1409 return ~0U; 1407 1410 /* Cast away constness because this is "just" a cache */ 1408 ((libtrace_packet_t*)packet)->ca pture_length =1411 ((libtrace_packet_t*)packet)->cached.capture_length = 1409 1412 packet->trace->format->get_capture_length(packet); 1410 1413 } 1411 1414 1412 if (!(packet->ca pture_length < LIBTRACE_PACKET_BUFSIZE)) {1415 if (!(packet->cached.capture_length < LIBTRACE_PACKET_BUFSIZE)) { 1413 1416 fprintf(stderr, "Capture length is greater than the buffer size in trace_get_capture_length()\n"); 1414 1417 return 0; … … 1416 1419 } 1417 1420 1418 return packet->ca pture_length;1421 return packet->cached.capture_length; 1419 1422 } 1420 1423 … … 1432 1435 } 1433 1436 1434 if (packet-> wire_length == -1) {1437 if (packet->cached.wire_length == -1) { 1435 1438 if (!packet->trace->format->get_wire_length) 1436 1439 return ~0U; 1437 ((libtrace_packet_t *)packet)-> wire_length =1440 ((libtrace_packet_t *)packet)->cached.wire_length = 1438 1441 packet->trace->format->get_wire_length(packet); 1439 1442 } 1440 1443 1441 if (!(packet-> wire_length < LIBTRACE_PACKET_BUFSIZE)) {1444 if (!(packet->cached.wire_length < LIBTRACE_PACKET_BUFSIZE)) { 1442 1445 fprintf(stderr, "Wire length is greater than the buffer size in trace_get_wire_length()\n"); 1443 1446 return 0; 1444 1447 /* should we be returning ~OU here? */ 1445 1448 } 1446 return packet-> wire_length;1449 return packet->cached.wire_length; 1447 1450 1448 1451 } … … 1460 1463 } 1461 1464 1462 if (packet-> framing_length >= 0) {1463 return packet-> framing_length;1465 if (packet->cached.framing_length >= 0) { 1466 return packet->cached.framing_length; 1464 1467 } 1465 1468 1466 1469 if (packet->trace->format->get_framing_length) { 1467 ((libtrace_packet_t *)packet)-> framing_length =1470 ((libtrace_packet_t *)packet)->cached.framing_length = 1468 1471 packet->trace->format->get_framing_length(packet); 1469 return packet-> framing_length;1472 return packet->cached.framing_length; 1470 1473 } 1471 1474 return ~0U; … … 1483 1486 } 1484 1487 1485 if (packet-> link_type == 0) {1488 if (packet->cached.link_type == 0) { 1486 1489 if (!packet->trace->format->get_link_type) 1487 1490 return TRACE_TYPE_UNKNOWN; 1488 ((libtrace_packet_t *)packet)-> link_type =1491 ((libtrace_packet_t *)packet)->cached.link_type = 1489 1492 packet->trace->format->get_link_type(packet); 1490 1493 } 1491 1494 1492 return packet-> link_type;1495 return packet->cached.link_type; 1493 1496 } 1494 1497 … … 1976 1979 1977 1980 if (packet->trace->format->set_capture_length) { 1978 packet->ca pture_length = packet->trace->format->set_capture_length(packet,size);1979 return packet->ca pture_length;1981 packet->cached.capture_length = packet->trace->format->set_capture_length(packet,size); 1982 return packet->cached.capture_length; 1980 1983 } 1981 1984 … … 2570 2573 2571 2574 2572 void trace_clear_cache(libtrace_packet_t *packet) { 2573 2574 packet->l2_header = NULL; 2575 packet->l3_header = NULL; 2576 packet->l4_header = NULL; 2577 packet->link_type = 0; 2578 packet->l3_ethertype = 0; 2579 packet->transport_proto = 0; 2580 packet->capture_length = -1; 2581 packet->wire_length = -1; 2582 packet->framing_length = -1; 2583 packet->payload_length = -1; 2584 packet->l2_remaining = 0; 2585 packet->l3_remaining = 0; 2586 packet->l4_remaining = 0; 2587 packet->refcount = 0; 2575 inline void trace_clear_cache(libtrace_packet_t *packet) { 2576 2577 packet->cached = clearcache; 2588 2578 } 2589 2579
Note: See TracChangeset
for help on using the changeset viewer.