defines.h.in 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #ifndef __DEFINES_H__
  2. #define __DEFINES_H__
  3. #include "config.h"
  4. /* should packet counters be 32 or 64 bit? --enable-64bit */
  5. #ifdef ENABLE_64BITS
  6. #define COUNTER u_int64_t
  7. #define COUNTER_SPEC "%llu"
  8. #else
  9. #define COUNTER u_int32_t
  10. #define COUNTER_SPEC "%lu"
  11. #endif
  12. #include "lib/strlcpy.h"
  13. #include "common/list.h"
  14. #include "common/cidr.h"
  15. #include "@LNETINC@"
  16. #ifdef INCLUDE_PCAP_BPF_H_FILE
  17. #include "@PCAP_BPF_H_FILE@"
  18. #define PCAP_DONT_INCLUDE_PCAP_BPF_H /* don't re-include it in pcap.h */
  19. #endif
  20. #include "@LPCAPINC@"
  21. #ifdef HAVE_LIBNIDS
  22. #include "@LNIDSINC@"
  23. #endif
  24. /* Map libnet 1.1 structs to shorter names for internal use */
  25. #define LIBNET_IP_H LIBNET_IPV4_H
  26. #define LIBNET_ICMP_H LIBNET_ICMPV4_H
  27. /* The release version of libnet 1.1.1 changed DNS */
  28. #ifdef LIBNET_DNSV4_H
  29. #define LIBNET_DNS_H LIBNET_DNSV4_H
  30. #else
  31. #define LIBNET_DNS_H LIBNET_UDP_DNSV4_H
  32. #endif
  33. /* standardize all common header typedefs */
  34. typedef struct libnet_ipv4_hdr ip_hdr_t;
  35. typedef struct libnet_dnsv4_hdr dns_hdr_t;
  36. typedef struct libnet_icmpv4_hdr icmp_hdr_t;
  37. typedef struct libnet_arp_hdr arp_hdr_t;
  38. typedef struct libnet_tcp_hdr tcp_hdr_t;
  39. typedef struct libnet_udp_hdr udp_hdr_t;
  40. typedef struct libnet_ethernet_hdr eth_hdr_t;
  41. typedef struct libnet_802_1q_hdr vlan_hdr_t;
  42. typedef struct sll_header sll_hdr_t;
  43. typedef struct cisco_hdlc_header_s hdlc_hdr_t;
  44. /* our custom typdefs/structs */
  45. typedef u_char macaddr_t[LIBNET_ETH_H];
  46. struct bpf_s {
  47. char *filter;
  48. int optimize;
  49. struct bpf_program program;
  50. };
  51. typedef struct bpf_s bpf_t;
  52. #define L2DATALEN 255 /* Max size of the L2 data file */
  53. struct l2_s {
  54. int enabled; /* are we rewritting the L2 header ? */
  55. int len; /* user data length */
  56. u_char data1[L2DATALEN];
  57. u_char data2[L2DATALEN];
  58. /*
  59. * we need to store the *new* linktype which we will then use to
  60. * select the correct union slice. set to LINKTYPE_USER to
  61. * use the user specified data (data1[] & data2[])
  62. * other valid options are LINKTYPE_VLAN and LINKTYPE_ETHER for
  63. * 802.1q and standard ethernet frames respectively.
  64. */
  65. int linktype;
  66. #define LINKTYPE_USER 1
  67. #define LINKTYPE_VLAN 2
  68. #define LINKTYPE_ETHER 3
  69. };
  70. typedef struct l2_s l2_t;
  71. struct xX_s {
  72. #define xX_MODE_INCLUDE 'x'
  73. #define xX_MODE_EXCLUDE 'X'
  74. int mode;
  75. list_t *list;
  76. cidr_t *cidr;
  77. #define xX_TYPE_LIST 1
  78. #define xX_TYPE_CIDR 2
  79. int type;
  80. };
  81. typedef struct xX_s xX_t;
  82. /* number of ports 0-65535 */
  83. #define NUM_PORTS 65536
  84. struct services_s {
  85. char tcp[NUM_PORTS];
  86. char udp[NUM_PORTS];
  87. };
  88. typedef struct services_s services_t;
  89. struct speed_s {
  90. /* speed modifiers */
  91. int mode;
  92. #define SPEED_MULTIPLIER 1
  93. #define SPEED_MBPSRATE 2
  94. #define SPEED_PACKETRATE 3
  95. #define SPEED_TOPSPEED 4
  96. #define SPEED_ONEATATIME 5
  97. float speed;
  98. };
  99. typedef struct speed_s speed_t;
  100. #define MAX_FILES 1024 /* Max number of files we can pass to tcpreplay */
  101. #define DEFAULT_MTU 1500 /* Max Transmission Unit of standard ethernet
  102. * don't forget *frames* are MTU + L2 header! */
  103. /* #define MAXPACKET 16436 MTU of Linux loopback */
  104. #define MAXPACKET 65535 /* maybe something is bigger then
  105. linux loopback */
  106. #define MAX_SNAPLEN 65535 /* tell libpcap to capture the entire packet */
  107. #define RESOLVE 0 /* disable dns lookups */
  108. #define BPF_OPTIMIZE 1 /* default is to optimize bpf program */
  109. #define PCAP_TIMEOUT 100 /* 100ms pcap_open_live timeout */
  110. #define TRUE 1
  111. #define FALSE 0
  112. #define EBUF_SIZE 1024 /* size of our error buffers */
  113. #define MAC_SIZE 7 /* size of the mac[] buffer */
  114. #define PAD_PACKET 1 /* values for the 'uflag' in tcpreplay */
  115. #define TRUNC_PACKET 2
  116. #define DNS_QUERY_FLAG 0x8000
  117. #define SERVER 1
  118. #define CLIENT 0
  119. #define UNKNOWN -1
  120. #define ANY 2
  121. #define CIDR_MODE 1 /* single pass, CIDR netblock */
  122. #define REGEX_MODE 2 /* single pass, Regex */
  123. #define AUTO_MODE 4 /* first pass through in auto mode */
  124. #define PORT_MODE 8 /* single pass, use src/dst ports to split */
  125. #define ROUTER_MODE 16 /* second pass through in router/auto mode */
  126. #define BRIDGE_MODE 32 /* second pass through in bridge/auto mode */
  127. #define SERVER_MODE 64 /* second pass through in client/auto mode */
  128. #define CLIENT_MODE 128 /* second pass through in server/auto mode */
  129. #define BROADCAST_MAC "\FF\FF\FF\FF\FF\FF"
  130. /* MAC macros for printf */
  131. #define MAC_FORMAT "%02X:%02X:%02X:%02X:%02X:%02X"
  132. #define MAC_STR(x) x[0], x[1], x[2], x[3], x[4], x[5]
  133. /* struct timeval print structs */
  134. #define TIMEVAL_FORMAT "%lu.%08lu"
  135. /* force a word or half-word swap on both Big and Little endian systems */
  136. #ifndef SWAPLONG
  137. #define SWAPLONG(y) \
  138. ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
  139. #endif
  140. #ifndef SWAPSHORT
  141. #define SWAPSHORT(y) \
  142. ( (((y)&0xff)<<8) | ((u_short)((y)&0xff00)>>8) )
  143. #endif
  144. /* converts a 64bit int to network byte order */
  145. #ifndef HAVE_NTOHLL
  146. #ifdef WORDS_BIGENDIAN
  147. #define ntohll(x) (x)
  148. #define htonll(x) (x)
  149. #else
  150. /* stolen from http://www.codeproject.com/cpp/endianness.asp */
  151. #define ntohll(x) (((u_int64_t)(ntohl((int)((x << 32) >> 32))) << 32) | \
  152. (unsigned int)ntohl(((int)(x >> 32))))
  153. #define htonll(x) ntohll(x)
  154. #endif /* WORDS_BIGENDIAN */
  155. #endif
  156. #define DEBUG_INFO 1 /* informational only, lessthan 1 line per packet */
  157. #define DEBUG_BASIC 2 /* limited debugging, one line per packet */
  158. #define DEBUG_DETAIL 3 /* more detailed, a few lines per packet */
  159. #define DEBUG_CODE 4 /* examines code & values, many lines per packet */
  160. #endif /* DEFINES */
  161. /*
  162. Local Variables:
  163. mode:c
  164. indent-tabs-mode:nil
  165. c-basic-offset:4
  166. End:
  167. */