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 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. {
  32. ECHO_ME, /*The node requests to be echoed by the dst_node*/
  33. ECHO_REPLY, /*Yep, this isn't really a reply*/
  34. GET_FREE_NODES, /*it means: <<Get the list of free ips in your gnode, plz>>*/
  35. GET_QSPN_ROUND, /*<<Yo, Gimme the qspn ids and qspn times>>*/
  36. GET_INTERNET_GWS, /*Get Internet Gateways */
  37. SET_FOREIGN_ROUTE, /* Set the route in the foreign groupnode */
  38. DEL_FOREIGN_ROUTE,
  39. NEW_BACKROUTE, /*Tells the dst_node to use a different route to reply*/
  40. DELAYED_BROADCAST, /*Broadcast packet to be spread only in the dst groupnode*/
  41. SPLIT_ROUTE, /*This pkt advices the src_node to split the socket in two route*/
  42. SET_NO_IDENTITY, /*Pkt that specify to the last node in the route to change
  43. the src ip of the future incoming pkts*/
  44. QSPN_CLOSE, /*The qspn_pkt used to trace the entire g_node*/
  45. QSPN_OPEN, /*The qspn_pkt sent by the extreme nodes*/
  46. QSPN_RFR, /*RequestForRoute: This is used to get additional routes*/
  47. GET_DNODEBLOCK , /* Not used. */
  48. GET_DNODEIP, /* Not used. */
  49. TRACER_PKT, /*A tracer pkt. This pkt is used mainly to send only a tracer pkt.
  50. Normally a bcast pkt is marked with the BCAST_TRACER_PKT flag.*/
  51. TRACER_PKT_CONNECT, /*This is the tracer_pkt used to connect to the dst_node.
  52. In the first entry of the tcr_pkt there's the src node, in the
  53. second the dst_node, the remaining are as usual*/
  54. DEL_SNODE, /* Not used. */
  55. DEL_GNODE, /* Not used. */
  56. GET_INT_MAP,
  57. GET_EXT_MAP,
  58. GET_BNODE_MAP,
  59. ANDNA_REGISTER_HNAME,
  60. ANDNA_CHECK_COUNTER, /* Check request for the counter node */
  61. ANDNA_RESOLVE_HNAME,
  62. ANDNA_RESOLVE_IP,
  63. ANDNA_RESOLVE_MX,
  64. ANDNA_GET_ANDNA_CACHE,
  65. ANDNA_GET_SINGLE_ACACHE,
  66. ANDNA_SPREAD_SACACHE, /* Spread single andna_cache */
  67. ANDNA_GET_COUNT_CACHE,
  68. /* * * Replies * * */
  69. PUT_FREE_NODES, /*it means: "Here it is the list of free ips in your gnode, cya"*/
  70. PUT_QSPN_ROUND,
  71. PUT_INTERNET_GWS,
  72. PUT_DNODEIP,
  73. EMPTY_REPLY_SLOT,
  74. EMPTY_REPLY_SLOT1,
  75. PUT_INT_MAP,
  76. PUT_EXT_MAP,
  77. PUT_BNODE_MAP,
  78. ANDNA_RESOLVE_REPLY,
  79. ANDNA_REV_RESOLVE_REPLY,
  80. ANDNA_MX_RESOLVE_REPLY,
  81. ANDNA_PUT_COUNT_CACHE,
  82. ANDNA_PUT_ANDNA_CACHE,
  83. /*Acks*/
  84. ACK_AFFERMATIVE, /*Ack affermative. Everything is fine.*/
  85. ACK_NEGATIVE /*The request is rejected. The error is in the pkt's body.*/
  86. };
  87. /*
  88. * WARNING* Keep it up to date!! *WARNING *
  89. */
  90. #define TOTAL_OPS (ACK_NEGATIVE+1)
  91. #define TOTAL_REQUESTS (ANDNA_GET_COUNT_CACHE+1)
  92. #define TOTAL_REPLIES (TOTAL_OPS-TOTAL_REQUESTS)
  93. enum errors
  94. {
  95. /*Request errors*/
  96. E_INVALID_REQUEST,
  97. E_ACCEPT_TBL_FULL,
  98. E_REQUEST_TBL_FULL,
  99. E_QGROUP_FULL,
  100. E_NTK_FULL,
  101. E_INVALID_SIGNATURE,
  102. E_CANNOT_FORWARD,
  103. E_ANDNA_WRONG_HASH_GNODE,
  104. E_ANDNA_QUEUE_FULL,
  105. E_ANDNA_UPDATE_TOO_EARLY,
  106. E_ANDNA_TOO_MANY_HNAME,
  107. E_ANDNA_HUPDATE_MISMATCH,
  108. E_ANDNA_NO_HNAME,
  109. E_ANDNA_CHECK_COUNTER,
  110. E_TOO_MANY_CONN
  111. };
  112. #define TOTAL_ERRORS (E_TOO_MANY_CONN+1)
  113. /*
  114. * Request_table: It prevents requests flood and it is used in each connection.
  115. * Each element of the "rq" array corresponds to a request; it (the element)
  116. * keeps the number of requests served. If this number is equal
  117. * to [REQUEST]_MAXRQ, the maximum of simultaneous requests is reached.
  118. *
  119. * Each element in rq_wait corresponds to a single request so it is formed by:
  120. * { [REQUEST 0]_MAXRQ elements | [REQUEST 1]_MAXRQ elements | ... };
  121. * rq_wait_idx keeps track of this but it must be initialized once with
  122. * rq_wait_idx_init().
  123. * Each element of rq_wait keeps the time when that request arrived.
  124. * When the current time is >= [REQUEST]_WAIT+rq_wait, a new request is
  125. * available and the corresponding request counter in "rq" is decremented.
  126. */
  127. #define TOTAL_MAXRQ 31
  128. struct request_tbl
  129. {
  130. u_char rq[TOTAL_REQUESTS];
  131. time_t rq_wait[TOTAL_MAXRQ];
  132. };
  133. typedef struct request_tbl rq_tbl;
  134. int rq_wait_idx[TOTAL_REQUESTS];
  135. int update_rq_tbl_mutex;
  136. /*
  137. * Each bit of this array corresponds to a request or a reply. If the bit is
  138. * set, the request or reply will be dropped, otherwise it will be executed by
  139. * pkts.c/pkt_exec().
  140. */
  141. char filtered_op[TOTAL_OPS>>3];
  142. #define OP_FILTER_DROP 1
  143. #define OP_FILTER_ALLOW 0
  144. #define op_filter_set(op) SET_BIT(filtered_op, (op))
  145. #define op_filter_clr(op) CLR_BIT(filtered_op, (op))
  146. #define op_filter_test(op) TEST_BIT(filtered_op, (op))
  147. #define op_filter_reset(bit) memset(filtered_op, (bit), sizeof(filtered_op))
  148. /*
  149. * Functions declaration starts here
  150. */
  151. void rq_wait_idx_init(int *rq_wait_idx);
  152. const u_char *rq_strerror(int err);
  153. #define re_strerror(err) (rq_strerror((err)))
  154. const u_char *re_to_str(u_char re);
  155. const u_char *rq_to_str(u_char rq);
  156. int op_verify(u_char );
  157. int rq_verify(u_char );
  158. int re_verify(u_char );
  159. void update_rq_tbl(rq_tbl *);
  160. int is_rq_full(u_char , rq_tbl *);
  161. int find_free_rq_wait(u_char , rq_tbl *);
  162. int add_rq(u_char , rq_tbl *);
  163. void op_filter_reset_re(int bit);
  164. void op_filter_reset_rq(int bit);
  165. #endif /*REQUEST_H*/