state.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * ZMap Copyright 2013 Regents of the University of Michigan
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy
  6. * of the License at http://www.apache.org/licenses/LICENSE-2.0
  7. */
  8. #ifndef STATE_H
  9. #define STATE_H
  10. #include <stdio.h>
  11. #include <stdint.h>
  12. #include "../lib/includes.h"
  13. #ifdef PFRING
  14. #include <pfring_zc.h>
  15. #endif
  16. #include "aesrand.h"
  17. #include "fieldset.h"
  18. #include "filter.h"
  19. #include "types.h"
  20. #define MAX_PACKET_SIZE 4096
  21. #define MAC_ADDR_LEN_BYTES 6
  22. struct probe_module;
  23. struct output_module;
  24. struct fieldset_conf {
  25. fielddefset_t defs;
  26. fielddefset_t outdefs;
  27. translation_t translation;
  28. int success_index;
  29. int app_success_index;
  30. int classification_index;
  31. };
  32. // global configuration
  33. struct state_conf {
  34. uint32_t marker_encoding;
  35. uint32_t use_markervalue;
  36. uint32_t markervalue;
  37. uint32_t markerbits_value;
  38. uint32_t markerbits_checksum;
  39. uint32_t marker_encoding_dst_small;
  40. int disable_monitor;
  41. int log_level;
  42. port_h_t target_port;
  43. port_h_t source_port_first;
  44. port_h_t source_port_last;
  45. // maximum number of packets that the scanner will send before terminating
  46. uint32_t max_targets;
  47. // maximum number of seconds that scanner will run before terminating
  48. uint32_t max_runtime;
  49. // maximum number of results before terminating
  50. uint32_t max_results;
  51. // name of network interface that
  52. // will be utilized for sending/receiving
  53. char *iface;
  54. // rate in packets per second
  55. // that the sender will maintain
  56. int rate;
  57. // rate in bits per second
  58. uint64_t bandwidth;
  59. // how many seconds after the termination of the sender will the receiver
  60. // continue to process responses
  61. int cooldown_secs;
  62. // number of sending threads
  63. uint8_t senders;
  64. uint32_t pin_cores_len;
  65. uint32_t *pin_cores;
  66. // should use CLI provided randomization seed instead of generating
  67. // a random seed.
  68. int use_seed;
  69. uint64_t seed;
  70. aesrand_t *aes;
  71. // generator of the cyclic multiplicative group that is utilized for
  72. // address generation
  73. uint32_t generator;
  74. // sharding options
  75. uint8_t shard_num;
  76. uint8_t total_shards;
  77. int packet_streams;
  78. struct probe_module *probe_module;
  79. struct output_module *output_module;
  80. char *probe_args;
  81. char *output_args;
  82. macaddr_t gw_mac[MAC_ADDR_LEN_BYTES];
  83. macaddr_t hw_mac[MAC_ADDR_LEN_BYTES];
  84. uint32_t gw_ip;
  85. int gw_mac_set;
  86. int hw_mac_set;
  87. int send_ip_pkts;
  88. char *source_ip_first;
  89. char *source_ip_last;
  90. char *output_filename;
  91. char *blacklist_filename;
  92. char *whitelist_filename;
  93. #ifdef JSON
  94. char *metadata_filename;
  95. FILE *metadata_file;
  96. char *notes;
  97. char *custom_metadata_str;
  98. #endif
  99. char **destination_cidrs;
  100. int destination_cidrs_len;
  101. char *raw_output_fields;
  102. char **output_fields;
  103. struct output_filter filter;
  104. char *output_filter_str;
  105. struct fieldset_conf fsconf;
  106. int output_fields_len;
  107. char *log_file;
  108. char *log_directory;
  109. char *status_updates_file;
  110. int dryrun;
  111. int quiet;
  112. int ignore_invalid_hosts;
  113. int syslog;
  114. int filter_duplicates;
  115. int filter_unsuccessful;
  116. int recv_ready;
  117. int num_retries;
  118. uint64_t total_allowed;
  119. uint64_t total_disallowed;
  120. int max_sendto_failures;
  121. float min_hitrate;
  122. #ifdef PFRING
  123. struct {
  124. pfring_zc_cluster *cluster;
  125. pfring_zc_queue *send;
  126. pfring_zc_queue *recv;
  127. pfring_zc_queue **queues;
  128. pfring_zc_pkt_buff **buffers;
  129. pfring_zc_buffer_pool *prefetches;
  130. } pf;
  131. #endif
  132. };
  133. extern struct state_conf zconf;
  134. // global sender stats
  135. struct state_send {
  136. double start;
  137. double finish;
  138. uint32_t sent;
  139. uint32_t blacklisted;
  140. uint32_t whitelisted;
  141. int warmup;
  142. int complete;
  143. uint32_t first_scanned;
  144. uint32_t targets;
  145. uint32_t sendto_failures;
  146. uint32_t max_index;
  147. };
  148. extern struct state_send zsend;
  149. // global receiver stats
  150. struct state_recv {
  151. // valid responses classified as "success"
  152. uint32_t success_total;
  153. // unique IPs that sent valid responses classified as "success"
  154. uint32_t success_unique;
  155. // valid responses classified as "success"
  156. uint32_t app_success_total;
  157. // unique IPs that sent valid responses classified as "success"
  158. uint32_t app_success_unique;
  159. // valid responses classified as "success" received during cooldown
  160. uint32_t cooldown_total;
  161. // unique IPs that first sent valid "success"es during cooldown
  162. uint32_t cooldown_unique;
  163. // valid responses NOT classified as "success"
  164. uint32_t failure_total;
  165. int complete; // has the scanner finished sending?
  166. double start; // timestamp of when recv started
  167. double finish; // timestamp of when recv terminated
  168. // number of packets captured by pcap filter
  169. uint32_t pcap_recv;
  170. // number of packets dropped because there was no room in
  171. // the operating system's buffer when they arrived, because
  172. // packets weren't being read fast enough
  173. uint32_t pcap_drop;
  174. // number of packets dropped by the network interface or its driver.
  175. uint32_t pcap_ifdrop;
  176. };
  177. extern struct state_recv zrecv;
  178. #endif // _STATE_H