You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

request.h 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* This file is part of Netsukuku
  2. * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
  3. *
  4. * This source code is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as published
  6. * by the Free Software Foundation; either version 2 of the License,
  7. * or (at your option) any later version.
  8. *
  9. * This source code is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. * Please refer to the GNU Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Public License along with
  15. * this source code; if not, write to:
  16. * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #ifndef REQUEST_H
  19. #define REQUEST_H
  20. #include "misc.h"
  21. #define REQUEST_TIMEOUT 300 /* The timeout in seconds for all the
  22. requests */
  23. #ifdef DEBUG
  24. #undef REQUEST_TIMEOUT
  25. #define REQUEST_TIMEOUT 20
  26. #endif
  27. /*
  28. * In this enum there are all the requests/replies op used by netsukuku
  29. */
  30. enum pkt_op {
  31. ECHO_ME, /*The node requests to be echoed by the dst_node */
  32. ECHO_REPLY, /*Yep, this isn't really a reply */
  33. GET_FREE_NODES, /*it means: <<Get the list of free ips in your gnode, plz>> */
  34. GET_QSPN_ROUND, /*<<Yo, Gimme the qspn ids and qspn times>> */
  35. GET_INTERNET_GWS, /*Get Internet Gateways */
  36. SET_FOREIGN_ROUTE, /* Set the route in the foreign groupnode */
  37. DEL_FOREIGN_ROUTE,
  38. NEW_BACKROUTE, /*Tells the dst_node to use a different route to reply */
  39. DELAYED_BROADCAST, /*Broadcast packet to be spread only in the dst groupnode */
  40. SPLIT_ROUTE, /*This pkt advices the src_node to split the socket in two route */
  41. SET_NO_IDENTITY, /*Pkt that specify to the last node in the route to change
  42. the src ip of the future incoming pkts */
  43. QSPN_CLOSE, /*The qspn_pkt used to trace the entire g_node */
  44. QSPN_OPEN, /*The qspn_pkt sent by the extreme nodes */
  45. QSPN_RFR, /*RequestForRoute: This is used to get additional routes */
  46. GET_DNODEBLOCK, /* Not used. */
  47. GET_DNODEIP, /* Not used. */
  48. TRACER_PKT, /*A tracer pkt. This pkt is used mainly to send only a tracer pkt.
  49. Normally a bcast pkt is marked with the BCAST_TRACER_PKT flag. */
  50. TRACER_PKT_CONNECT, /*This is the tracer_pkt used to connect to the dst_node.
  51. In the first entry of the tcr_pkt there's the src node, in the
  52. second the dst_node, the remaining are as usual */
  53. DEL_SNODE, /* Not used. */
  54. DEL_GNODE, /* Not used. */
  55. GET_INT_MAP,
  56. GET_EXT_MAP,
  57. GET_BNODE_MAP,
  58. ANDNA_REGISTER_HNAME,
  59. ANDNA_CHECK_COUNTER, /* Check request for the counter node */
  60. ANDNA_RESOLVE_HNAME,
  61. ANDNA_RESOLVE_IP,
  62. ANDNA_RESOLVE_MX,
  63. ANDNA_GET_ANDNA_CACHE,
  64. ANDNA_GET_SINGLE_ACACHE,
  65. ANDNA_SPREAD_SACACHE, /* Spread single andna_cache */
  66. ANDNA_GET_COUNT_CACHE,
  67. /* * * Replies * * */
  68. PUT_FREE_NODES, /*it means: "Here it is the list of free ips in your gnode, cya" */
  69. PUT_QSPN_ROUND,
  70. PUT_INTERNET_GWS,
  71. PUT_DNODEIP,
  72. EMPTY_REPLY_SLOT,
  73. EMPTY_REPLY_SLOT1,
  74. PUT_INT_MAP,
  75. PUT_EXT_MAP,
  76. PUT_BNODE_MAP,
  77. ANDNA_RESOLVE_REPLY,
  78. ANDNA_REV_RESOLVE_REPLY,
  79. ANDNA_MX_RESOLVE_REPLY,
  80. ANDNA_PUT_COUNT_CACHE,
  81. ANDNA_PUT_ANDNA_CACHE,
  82. /*Acks */
  83. ACK_AFFERMATIVE, /*Ack affermative. Everything is fine. */
  84. ACK_NEGATIVE /*The request is rejected. The error is in the pkt's body. */
  85. };
  86. /*
  87. * WARNING* Keep it up to date!! *WARNING *
  88. */
  89. #define TOTAL_OPS (ACK_NEGATIVE+1)
  90. #define TOTAL_REQUESTS (ANDNA_GET_COUNT_CACHE+1)
  91. #define TOTAL_REPLIES (TOTAL_OPS-TOTAL_REQUESTS)
  92. enum errors {
  93. /*Request errors */
  94. E_INVALID_REQUEST,
  95. E_ACCEPT_TBL_FULL,
  96. E_REQUEST_TBL_FULL,
  97. E_QGROUP_FULL,
  98. E_NTK_FULL,
  99. E_INVALID_SIGNATURE,
  100. E_CANNOT_FORWARD,
  101. E_ANDNA_WRONG_HASH_GNODE,
  102. E_ANDNA_QUEUE_FULL,
  103. E_ANDNA_UPDATE_TOO_EARLY,
  104. E_ANDNA_TOO_MANY_HNAME,
  105. E_ANDNA_HUPDATE_MISMATCH,
  106. E_ANDNA_NO_HNAME,
  107. E_ANDNA_CHECK_COUNTER,
  108. E_TOO_MANY_CONN
  109. };
  110. #define TOTAL_ERRORS (E_TOO_MANY_CONN+1)
  111. /*
  112. * Request_table: It prevents requests flood and it is used in each connection.
  113. * Each element of the "rq" array corresponds to a request; it (the element)
  114. * keeps the number of requests served. If this number is equal
  115. * to [REQUEST]_MAXRQ, the maximum of simultaneous requests is reached.
  116. *
  117. * Each element in rq_wait corresponds to a single request so it is formed by:
  118. * { [REQUEST 0]_MAXRQ elements | [REQUEST 1]_MAXRQ elements | ... };
  119. * rq_wait_idx keeps track of this but it must be initialized once with
  120. * rq_wait_idx_init().
  121. * Each element of rq_wait keeps the time when that request arrived.
  122. * When the current time is >= [REQUEST]_WAIT+rq_wait, a new request is
  123. * available and the corresponding request counter in "rq" is decremented.
  124. */
  125. #define TOTAL_MAXRQ 31
  126. struct request_tbl {
  127. u_char rq[TOTAL_REQUESTS];
  128. time_t rq_wait[TOTAL_MAXRQ];
  129. };
  130. typedef struct request_tbl rq_tbl;
  131. int rq_wait_idx[TOTAL_REQUESTS];
  132. int update_rq_tbl_mutex;
  133. /*
  134. * Each bit of this array corresponds to a request or a reply. If the bit is
  135. * set, the request or reply will be dropped, otherwise it will be executed by
  136. * pkts.c/pkt_exec().
  137. */
  138. char filtered_op[TOTAL_OPS >> 3];
  139. #define OP_FILTER_DROP 1
  140. #define OP_FILTER_ALLOW 0
  141. #define op_filter_set(op) SET_BIT(filtered_op, (op))
  142. #define op_filter_clr(op) CLR_BIT(filtered_op, (op))
  143. #define op_filter_test(op) TEST_BIT(filtered_op, (op))
  144. #define op_filter_reset(bit) memset(filtered_op, (bit), sizeof(filtered_op))
  145. /*
  146. * Functions declaration starts here
  147. */
  148. void rq_wait_idx_init(int *rq_wait_idx);
  149. const u_char *rq_strerror(int err);
  150. #define re_strerror(err) (rq_strerror((err)))
  151. const u_char *re_to_str(u_char re);
  152. const u_char *rq_to_str(u_char rq);
  153. int op_verify(u_char);
  154. int rq_verify(u_char);
  155. int re_verify(u_char);
  156. void update_rq_tbl(rq_tbl *);
  157. int is_rq_full(u_char, rq_tbl *);
  158. int find_free_rq_wait(u_char, rq_tbl *);
  159. int add_rq(u_char, rq_tbl *);
  160. void op_filter_reset_re(int bit);
  161. void op_filter_reset_rq(int bit);
  162. #endif /*REQUEST_H */