- Timestamp:
- 06/23/17 14:24:23 (4 years ago)
- Branches:
- cachetimestamps, develop, dpdk-ndag, etsilive, master, ndag_format, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance
- Children:
- fdf1f7b
- Parents:
- f398c61
- Location:
- lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_helper.c
ree6e802 r633339d 323 323 va_end(va); 324 324 } 325 326 /** Attempts to determine the direction for a pcap (or pcapng) packet. 327 * 328 * @param packet The packet in question. 329 * @return A valid libtrace_direction_t describing the direction that the 330 * packet was travelling, if direction can be determined. Otherwise 331 * returns TRACE_DIR_UNKNOWN. 332 * @internal 333 * 334 * Note that we can determine the direction for only certain types of packets 335 * if they are captured using pcap/pcapng, specifically SLL and PFLOG captures. 336 */ 337 libtrace_direction_t pcap_get_direction(const libtrace_packet_t *packet) { 338 libtrace_direction_t direction = -1; 339 switch(pcap_linktype_to_libtrace(rt_to_pcap_linktype(packet->type))) { 340 /* We can only get the direction for PCAP packets that have 341 * been encapsulated in Linux SLL or PFLOG */ 342 case TRACE_TYPE_LINUX_SLL: 343 { 344 libtrace_sll_header_t *sll; 345 libtrace_linktype_t linktype; 346 347 sll = (libtrace_sll_header_t*)trace_get_packet_buffer( 348 packet, 349 &linktype, 350 NULL); 351 if (!sll) { 352 trace_set_err(packet->trace, 353 TRACE_ERR_BAD_PACKET, 354 "Bad or missing packet"); 355 return -1; 356 } 357 /* 0 == LINUX_SLL_HOST */ 358 /* the Waikato Capture point defines "packets 359 * originating locally" (ie, outbound), with a 360 * direction of 0, and "packets destined locally" 361 * (ie, inbound), with a direction of 1. 362 * This is kind-of-opposite to LINUX_SLL. 363 * We return consistent values here, however 364 * 365 * Note that in recent versions of pcap, you can 366 * use "inbound" and "outbound" on ppp in linux 367 */ 368 if (ntohs(sll->pkttype == 0)) { 369 direction = TRACE_DIR_INCOMING; 370 } else { 371 direction = TRACE_DIR_OUTGOING; 372 } 373 break; 374 375 } 376 case TRACE_TYPE_PFLOG: 377 { 378 libtrace_pflog_header_t *pflog; 379 libtrace_linktype_t linktype; 380 381 pflog=(libtrace_pflog_header_t*)trace_get_packet_buffer( 382 packet,&linktype,NULL); 383 if (!pflog) { 384 trace_set_err(packet->trace, 385 TRACE_ERR_BAD_PACKET, 386 "Bad or missing packet"); 387 return -1; 388 } 389 /* enum { PF_IN=0, PF_OUT=1 }; */ 390 if (ntohs(pflog->dir==0)) { 391 392 direction = TRACE_DIR_INCOMING; 393 } 394 else { 395 direction = TRACE_DIR_OUTGOING; 396 } 397 break; 398 } 399 default: 400 break; 401 } 402 return direction; 403 } 404 405 -
lib/format_helper.h
ree6e802 r633339d 87 87 int level, 88 88 int filemode); 89 90 91 /** Attempts to determine the direction for a pcap (or pcapng) packet. 92 * 93 * @param packet The packet in question. 94 * @return A valid libtrace_direction_t describing the direction that the 95 * packet was travelling, if direction can be determined. Otherwise 96 * returns TRACE_DIR_UNKNOWN. 97 * 98 * Note that we can determine the direction for only certain types of packets 99 * if they are captured using pcap/pcapng, specifically SLL and PFLOG captures. 100 */ 101 libtrace_direction_t pcap_get_direction(const libtrace_packet_t *packet); 102 103 104 89 105 #endif /* FORMAT_HELPER_H */ -
lib/format_pcap.c
r5e3f16c r633339d 628 628 } 629 629 630 static libtrace_direction_t pcap_get_direction(const libtrace_packet_t *packet) { 631 libtrace_direction_t direction = -1; 632 switch(pcap_get_link_type(packet)) { 633 /* Only packets encapsulated in Linux SLL or PFLOG have any 634 * direction information */ 635 636 case TRACE_TYPE_LINUX_SLL: 637 { 638 libtrace_sll_header_t *sll; 639 sll = trace_get_packet_buffer(packet, NULL, NULL); 640 /* TODO: should check remaining>=sizeof(*sll) */ 641 if (!sll) { 642 trace_set_err(packet->trace, 643 TRACE_ERR_BAD_PACKET, 644 "Bad or missing packet"); 645 return -1; 646 } 647 /* 0 == LINUX_SLL_HOST */ 648 /* the Waikato Capture point defines "packets 649 * originating locally" (ie, outbound), with a 650 * direction of 0, and "packets destined locally" 651 * (ie, inbound), with a direction of 1. 652 * This is kind-of-opposite to LINUX_SLL. 653 * We return consistent values here, however 654 * 655 * Note that in recent versions of pcap, you can 656 * use "inbound" and "outbound" on ppp in linux 657 */ 658 if (sll->pkttype == TRACE_SLL_OUTGOING) { 659 direction = TRACE_DIR_OUTGOING; 660 } else { 661 direction = TRACE_DIR_INCOMING; 662 } 663 break; 664 665 } 666 case TRACE_TYPE_PFLOG: 667 { 668 libtrace_pflog_header_t *pflog; 669 pflog = trace_get_packet_buffer(packet, NULL, NULL); 670 /* TODO: should check remaining >= sizeof(*pflog) */ 671 if (!pflog) { 672 trace_set_err(packet->trace, 673 TRACE_ERR_BAD_PACKET, 674 "Bad or missing packet"); 675 return -1; 676 } 677 /* enum { PF_IN=0, PF_OUT=1 }; */ 678 if (ntohs(pflog->dir==0)) { 679 680 direction = TRACE_DIR_INCOMING; 681 } 682 else { 683 direction = TRACE_DIR_OUTGOING; 684 } 685 break; 686 } 687 default: 688 break; 689 } 690 return direction; 630 static libtrace_direction_t pcapint_get_direction(const libtrace_packet_t *packet) { 631 /* This function is defined in format_helper.c */ 632 return pcap_get_direction(packet); 691 633 } 692 634 … … 816 758 pcap_write_packet, /* write_packet */ 817 759 pcap_get_link_type, /* get_link_type */ 818 pcap _get_direction, /* get_direction */760 pcapint_get_direction, /* get_direction */ 819 761 pcap_set_direction, /* set_direction */ 820 762 NULL, /* get_erf_timestamp */ … … 860 802 pcapint_write_packet, /* write_packet */ 861 803 pcap_get_link_type, /* get_link_type */ 862 pcap _get_direction, /* get_direction */804 pcapint_get_direction, /* get_direction */ 863 805 pcap_set_direction, /* set_direction */ 864 806 NULL, /* get_erf_timestamp */ -
lib/format_pcapfile.c
ree6e802 r633339d 541 541 static libtrace_direction_t pcapfile_get_direction(const libtrace_packet_t *packet) 542 542 { 543 libtrace_direction_t direction = -1; 544 switch(pcapfile_get_link_type(packet)) { 545 /* We can only get the direction for PCAP packets that have 546 * been encapsulated in Linux SLL or PFLOG */ 547 case TRACE_TYPE_LINUX_SLL: 548 { 549 libtrace_sll_header_t *sll; 550 libtrace_linktype_t linktype; 551 552 sll = (libtrace_sll_header_t*)trace_get_packet_buffer( 553 packet, 554 &linktype, 555 NULL); 556 if (!sll) { 557 trace_set_err(packet->trace, 558 TRACE_ERR_BAD_PACKET, 559 "Bad or missing packet"); 560 return -1; 561 } 562 /* 0 == LINUX_SLL_HOST */ 563 /* the Waikato Capture point defines "packets 564 * originating locally" (ie, outbound), with a 565 * direction of 0, and "packets destined locally" 566 * (ie, inbound), with a direction of 1. 567 * This is kind-of-opposite to LINUX_SLL. 568 * We return consistent values here, however 569 * 570 * Note that in recent versions of pcap, you can 571 * use "inbound" and "outbound" on ppp in linux 572 */ 573 if (ntohs(sll->pkttype == 0)) { 574 direction = TRACE_DIR_INCOMING; 575 } else { 576 direction = TRACE_DIR_OUTGOING; 577 } 578 break; 579 580 } 581 case TRACE_TYPE_PFLOG: 582 { 583 libtrace_pflog_header_t *pflog; 584 libtrace_linktype_t linktype; 585 586 pflog=(libtrace_pflog_header_t*)trace_get_packet_buffer( 587 packet,&linktype,NULL); 588 if (!pflog) { 589 trace_set_err(packet->trace, 590 TRACE_ERR_BAD_PACKET, 591 "Bad or missing packet"); 592 return -1; 593 } 594 /* enum { PF_IN=0, PF_OUT=1 }; */ 595 if (ntohs(pflog->dir==0)) { 596 597 direction = TRACE_DIR_INCOMING; 598 } 599 else { 600 direction = TRACE_DIR_OUTGOING; 601 } 602 break; 603 } 604 default: 605 break; 606 } 607 return direction; 543 /* This function can be found in format_helper.c */ 544 return pcap_get_direction(packet); 608 545 } 609 546
Note: See TracChangeset
for help on using the changeset viewer.