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.

radar.h 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* This file is part of Netsukuku
  2. * (c) Copyright 2004 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 RADAR_H
  19. #define RADAR_H
  20. #define MAX_RADAR_SCANS 16
  21. #define MAX_RADAR_WAIT 5 /*How much we wait to store the received
  22. ECHO_REPLY pkts and then to close the
  23. current radar session */
  24. #define RTT_DELTA 1000 /*If the change delta of the new rtt is
  25. >= RTT_DELTA, the qspn_q.send_qspn
  26. will be set. (It's in millisec) */
  27. #ifdef DEBUG
  28. #undef MAX_RADAR_WAIT
  29. #define MAX_RADAR_WAIT 3
  30. #endif
  31. int max_radar_wait;
  32. int radar_wait_counter; /* During the scan, it is incremented
  33. every 500 ms */
  34. int radar_scans[MAX_INTERFACES]; /* How many ECHO_ME pkts we sent on
  35. each interface */
  36. int total_radar_scans; /* The sum of all the values of the
  37. `radar_scans' array */
  38. int radar_scan_mutex; /* A flag to see if we are already
  39. doing a scan */
  40. int my_echo_id;
  41. u_char send_qspn_now[MAX_LEVELS]; /* Shall we send the qspn in level?
  42. If yes send_qspn_now[level] is
  43. != 0 */
  44. int hook_retry; /* If we've seen, while hooking, a
  45. node who was trying to hook before
  46. us, `hook_retry' is set to 1. */
  47. int radar_daemon_ctl; /* If it is set to 0 the radar_daemon
  48. will stop until it becomes again 1 */
  49. int total_radars; /* Stupid statistic */
  50. #define RADQ_VOID_RNODE 0
  51. #define RADQ_EXT_RNODE 1
  52. struct radar_queue {
  53. LLIST_HDR(struct radar_queue);
  54. inet_prefix ip; /*Node's ip */
  55. interface *dev[MAX_INTERFACES]; /*The pointers to the interface structs, present
  56. in me.cur_ifs, of the device where we got the
  57. node's pongs */
  58. int dev_n; /* Number of devices */
  59. map_node *node; /*The node we are pinging */
  60. quadro_group quadg; /*Node's data for the ext_map */
  61. u_short flags;
  62. char pings; /*The total ECHO_ME pkts received from this node */
  63. char pongs; /*The total pongs (ECHO_REPLY) received from this node */
  64. struct timeval rtt[MAX_RADAR_SCANS]; /*The round rtt of each pong */
  65. struct timeval final_rtt; /*When all the rtt is filled, or when MAX_RADAR_WAIT
  66. is expired, final_rtt will keep the average of all
  67. the rtts */
  68. };
  69. struct radar_queue *radar_q; /*the start of the linked list of radar_queue */
  70. int radar_q_counter;
  71. struct timeval scan_start; /*the start of the scan */
  72. /*
  73. * rnode_list keeps the list of all the rnodes. It is used to know on what
  74. * interface can be reached a wanted rnode.
  75. */
  76. struct rnode_list {
  77. LLIST_HDR(struct rnode_list);
  78. map_node *node; /* The node which is pointed by this
  79. rnode */
  80. interface *dev[MAX_INTERFACES]; /* The pointers to the interface structs
  81. (in me.cur_ifs), which cointains the
  82. devices which links ourself with this rnode. */
  83. int dev_n;
  84. int tcp_sk; /* The direct tcp connection to this rnode uses
  85. this socket. */
  86. };
  87. struct rnode_list *rlist;
  88. int rlist_counter;
  89. /*
  90. * When this list isn't empty, the radar will receive only the ECHO_REPLY sent
  91. * from rnodes which are in the allowed_rnode list.
  92. */
  93. struct allowed_rnode {
  94. LLIST_HDR(struct allowed_rnode);
  95. /*
  96. * In order to see if the rnode X is part of this list we compare all
  97. * its gids in the range of gids[min_level] and gids[tot_level-1] with
  98. * the allowed_rnode.gid array.
  99. */
  100. u_char min_level;
  101. u_char tot_level;
  102. u_int gid[MAX_LEVELS];
  103. };
  104. struct allowed_rnode *alwd_rnodes;
  105. int alwd_rnodes_counter;
  106. /*
  107. * The ECHO_ME pkt:
  108. * It is just a normal pkt which contains in the body (pkt.msg) one
  109. * u_char echo_scans_count, var. This is the number of scans sent.
  110. */
  111. /*
  112. * During the hooking the ECHO_REPLY body pkt is one u_char which is set to 0
  113. * if we already finished our scans.
  114. */
  115. /* * * Functions declaration * * */
  116. void first_init_radar(void);
  117. void last_close_radar(void);
  118. void init_radar(void);
  119. void close_radar(void);
  120. void reset_radar(void);
  121. void free_new_node(void);
  122. struct radar_queue *find_node_radar_q(map_node * node);
  123. struct radar_queue *find_ip_radar_q(inet_prefix * ip);
  124. int count_hooking_nodes(void);
  125. void rnl_reset(struct rnode_list **rnlist, int *rnlist_counter);
  126. interface **rnl_get_dev(struct rnode_list *rnlist, map_node * node);
  127. interface *rnl_get_rand_dev(struct rnode_list *rnlist, map_node * node);
  128. int rnl_get_sk(struct rnode_list *rnlist, map_node * node);
  129. void rnl_close_all_sk(struct rnode_list *rnlist);
  130. int rnl_fill_rq(map_node * rnode, PACKET * pkt);
  131. int rnl_send_rq(map_node * rnode,
  132. PACKET * pkt, int pkt_flags, u_char rq, int rq_id,
  133. u_char re, int check_ack, PACKET * rpkt);
  134. void new_rnode_allowed(struct allowed_rnode **alr, int *alr_counter,
  135. int *gid, int min_lvl, int max_lvl);
  136. void reset_rnode_allowed(struct allowed_rnode **alr, int *alr_counter);
  137. void final_radar_queue(void);
  138. void radar_update_map(void);
  139. struct radar_queue *add_radar_q(PACKET pkt);
  140. int radar_exec_reply(PACKET pkt);
  141. int radar_scan(int activate_qspn);
  142. int radard(PACKET rpkt);
  143. int radar_recv_reply(PACKET pkt);
  144. void *radar_daemon(void *null);
  145. void radar_wait_new_scan(void);
  146. int refresh_hook_root_node(void);
  147. #endif /*RADAR_H */