sendpacket.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* $Id$ */
  2. /*
  3. * Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  4. * Copyright (c) 2013-2018 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  5. *
  6. * The Tcpreplay Suite of tools is free software: you can redistribute it
  7. * and/or modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or with the authors permission any later version.
  10. *
  11. * The Tcpreplay Suite is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with the Tcpreplay Suite. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "config.h"
  20. #include "defines.h"
  21. #include <sys/socket.h>
  22. #ifdef __NetBSD__
  23. #include <net/if_ether.h>
  24. #else
  25. #include <netinet/if_ether.h>
  26. #endif
  27. #if defined HAVE_NETMAP
  28. #include "common/netmap.h"
  29. #include <net/netmap.h>
  30. #endif
  31. #ifdef HAVE_PF_PACKET
  32. #include <netpacket/packet.h>
  33. #endif
  34. #ifdef HAVE_TX_RING
  35. #include "txring.h"
  36. #endif
  37. #ifdef HAVE_LIBDNET
  38. /* need to undef these which are pulled in via defines.h, prior to importing dnet.h */
  39. #undef icmp_id
  40. #undef icmp_seq
  41. #undef icmp_data
  42. #undef icmp_mask
  43. #ifdef HAVE_DNET_H
  44. #include <dnet.h>
  45. #endif
  46. #ifdef HAVE_DUMBNET_H
  47. #include <dumbnet.h>
  48. #endif
  49. #endif
  50. #ifndef _SENDPACKET_H_
  51. #define _SENDPACKET_H_
  52. typedef enum sendpacket_type_e {
  53. SP_TYPE_NONE,
  54. SP_TYPE_LIBNET,
  55. SP_TYPE_LIBDNET,
  56. SP_TYPE_LIBPCAP,
  57. SP_TYPE_BPF,
  58. SP_TYPE_PF_PACKET,
  59. SP_TYPE_TX_RING,
  60. SP_TYPE_KHIAL,
  61. SP_TYPE_NETMAP,
  62. SP_TYPE_TUNTAP
  63. } sendpacket_type_t;
  64. /* these are the file_operations ioctls */
  65. #define KHIAL_SET_DIRECTION (0x1)
  66. #define KHIAL_GET_DIRECTION (0x2)
  67. /* these are the directions */
  68. typedef enum khial_direction_e {
  69. KHIAL_DIRECTION_RX = 0,
  70. KHIAL_DIRECTION_TX,
  71. } khial_direction_t;
  72. union sendpacket_handle {
  73. pcap_t *pcap;
  74. int fd;
  75. #ifdef HAVE_LIBDNET
  76. eth_t *ldnet;
  77. #endif
  78. };
  79. #define SENDPACKET_ERRBUF_SIZE 1024
  80. #define MAX_IFNAMELEN 64
  81. struct sendpacket_s {
  82. tcpr_dir_t cache_dir;
  83. int open;
  84. char device[MAX_IFNAMELEN];
  85. char errbuf[SENDPACKET_ERRBUF_SIZE];
  86. COUNTER retry_enobufs;
  87. COUNTER retry_eagain;
  88. COUNTER failed;
  89. COUNTER trunc_packets;
  90. COUNTER sent;
  91. COUNTER bytes_sent;
  92. COUNTER attempt;
  93. COUNTER flow_non_flow_packets;
  94. COUNTER flows;
  95. COUNTER flow_packets;
  96. COUNTER flows_unique;
  97. COUNTER flows_expired;
  98. COUNTER flows_invalid_packets;
  99. sendpacket_type_t handle_type;
  100. union sendpacket_handle handle;
  101. struct tcpr_ether_addr ether;
  102. #if defined HAVE_NETMAP
  103. int first_packet;
  104. int netmap_delay;
  105. #endif
  106. #ifdef HAVE_NETMAP
  107. struct netmap_if *nm_if;
  108. nmreq_t nmr;
  109. void *mmap_addr;
  110. int mmap_size;
  111. uint32_t if_flags;
  112. uint32_t is_vale;
  113. int netmap_version;
  114. int tx_timeouts;
  115. uint16_t first_tx_ring, last_tx_ring, cur_tx_ring;
  116. #ifdef linux
  117. uint32_t data;
  118. uint32_t gso;
  119. uint32_t tso;
  120. uint32_t rxcsum;
  121. uint32_t txcsum;
  122. #endif /* linux */
  123. #endif /* HAVE_NETMAP */
  124. #ifdef HAVE_PF_PACKET
  125. struct sockaddr_ll sa;
  126. #ifdef HAVE_TX_RING
  127. txring_t * tx_ring;
  128. #endif
  129. #endif
  130. bool abort;
  131. };
  132. typedef struct sendpacket_s sendpacket_t;
  133. int sendpacket(sendpacket_t *, const u_char *, size_t, struct pcap_pkthdr *);
  134. void sendpacket_close(sendpacket_t *);
  135. char *sendpacket_geterr(sendpacket_t *);
  136. size_t sendpacket_getstat(sendpacket_t *, char *, size_t);
  137. sendpacket_t *sendpacket_open(const char *, char *, tcpr_dir_t, sendpacket_type_t, void *arg);
  138. struct tcpr_ether_addr *sendpacket_get_hwaddr(sendpacket_t *);
  139. int sendpacket_get_dlt(sendpacket_t *);
  140. const char *sendpacket_get_method(sendpacket_t *);
  141. void sendpacket_abort(sendpacket_t *);
  142. #endif /* _SENDPACKET_H_ */