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