The Netsukuku Project  0.0.9
An Alternative routing method
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
request.h
Go to the documentation of this file.
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 
19 #ifndef REQUEST_H
20 #define REQUEST_H
21 
22 #include "misc.h"
23 
24 #define REQUEST_TIMEOUT 300 /* The timeout in seconds for all the
25  requests */
26 #ifdef DEBUG
27 #undef REQUEST_TIMEOUT
28 #define REQUEST_TIMEOUT 20
29 #endif
30 
31 /*
32  * In this enum there are all the requests/replies op used by netsukuku
33  */
34 enum pkt_op
35 {
36  ECHO_ME, /*The node requests to be echoed by the dst_node*/
37  ECHO_REPLY, /*Yep, this isn't really a reply*/
38  GET_FREE_NODES, /*it means: <<Get the list of free ips in your gnode, plz>>*/
39  GET_QSPN_ROUND, /*<<Yo, Gimme the qspn ids and qspn times>>*/
40 
41  GET_INTERNET_GWS, /*Get Internet Gateways */
42  SET_FOREIGN_ROUTE, /* Set the route in the foreign groupnode */
44  NEW_BACKROUTE, /*Tells the dst_node to use a different route to reply*/
45  DELAYED_BROADCAST, /*Broadcast packet to be spread only in the dst groupnode*/
46  SPLIT_ROUTE, /*This pkt advices the src_node to split the socket in two route*/
47  SET_NO_IDENTITY, /*Pkt that specify to the last node in the route to change
48  the src ip of the future incoming pkts*/
49 
50  QSPN_CLOSE, /*The qspn_pkt used to trace the entire g_node*/
51  QSPN_OPEN, /*The qspn_pkt sent by the extreme nodes*/
52  QSPN_RFR, /*RequestForRoute: This is used to get additional routes*/
53  GET_DNODEBLOCK , /* Not used. */
54  GET_DNODEIP, /* Not used. */
55  TRACER_PKT, /*A tracer pkt. This pkt is used mainly to send only a tracer pkt.
56  Normally a bcast pkt is marked with the BCAST_TRACER_PKT flag.*/
57  TRACER_PKT_CONNECT, /*This is the tracer_pkt used to connect to the dst_node.
58  In the first entry of the tcr_pkt there's the src node, in the
59  second the dst_node, the remaining are as usual*/
60 
61  DEL_SNODE, /* Not used. */
62  DEL_GNODE, /* Not used. */
63 
67 
69  ANDNA_CHECK_COUNTER, /* Check request for the counter node */
75  ANDNA_SPREAD_SACACHE, /* Spread single andna_cache */
77 
78  /* * * Replies * * */
79  PUT_FREE_NODES, /*it means: "Here it is the list of free ips in your gnode, cya"*/
93 
94  /*Acks*/
95  ACK_AFFERMATIVE, /*Ack affermative. Everything is fine.*/
96  ACK_NEGATIVE /*The request is rejected. The error is in the pkt's body.*/
97 };
98 
99 /*
100  * WARNING* Keep it up to date!! *WARNING *
101  */
102 #define TOTAL_OPS (ACK_NEGATIVE+1)
103 #define TOTAL_REQUESTS (ANDNA_GET_COUNT_CACHE+1)
104 #define TOTAL_REPLIES (TOTAL_OPS-TOTAL_REQUESTS)
105 
106 enum errors
107 {
108  /*Request errors*/
116 
124 
126 };
127 #define TOTAL_ERRORS (E_TOO_MANY_CONN+1)
128 
129 /*
130  * Request_table: It prevents requests flood and it is used in each connection.
131  * Each element of the "rq" array corresponds to a request; it (the element)
132  * keeps the number of requests served. If this number is equal
133  * to [REQUEST]_MAXRQ, the maximum of simultaneous requests is reached.
134  *
135  * Each element in rq_wait corresponds to a single request so it is formed by:
136  * { [REQUEST 0]_MAXRQ elements | [REQUEST 1]_MAXRQ elements | ... };
137  * rq_wait_idx keeps track of this but it must be initialized once with
138  * rq_wait_idx_init().
139  * Each element of rq_wait keeps the time when that request arrived.
140  * When the current time is >= [REQUEST]_WAIT+rq_wait, a new request is
141  * available and the corresponding request counter in "rq" is decremented.
142  */
143 
144 #define TOTAL_MAXRQ 31
146 {
149 };
150 typedef struct request_tbl rq_tbl;
151 
153 
155 
156 /*
157  * Each bit of this array corresponds to a request or a reply. If the bit is
158  * set, the request or reply will be dropped, otherwise it will be executed by
159  * pkts.c/pkt_exec().
160  */
162 #define OP_FILTER_DROP 1
163 #define OP_FILTER_ALLOW 0
164 #define op_filter_set(op) SET_BIT(filtered_op, (op))
165 #define op_filter_clr(op) CLR_BIT(filtered_op, (op))
166 #define op_filter_test(op) TEST_BIT(filtered_op, (op))
167 #define op_filter_reset(bit) memset(filtered_op, (bit), sizeof(filtered_op))
168 
169 
170 /*
171  * Functions declaration starts here
172  */
173 void rq_wait_idx_init(int *rq_wait_idx);
174 const u_char *rq_strerror(int err);
175 #define re_strerror(err) (rq_strerror((err)))
176 const u_char *re_to_str(u_char re);
177 const u_char *rq_to_str(u_char rq);
178 int op_verify(u_char );
179 int rq_verify(u_char );
180 int re_verify(u_char );
181 void update_rq_tbl(rq_tbl *);
182 int is_rq_full(u_char , rq_tbl *);
183 int find_free_rq_wait(u_char , rq_tbl *);
184 int add_rq(u_char , rq_tbl *);
185 
186 void op_filter_reset_re(int bit);
187 void op_filter_reset_rq(int bit);
188 
189 #endif /*REQUEST_H*/
Definition: request.h:118
Definition: request.h:46
Definition: request.h:111
Definition: request.h:62
Definition: request.h:38
Definition: request.h:89
Definition: request.h:110
u_char rq[(ANDNA_GET_COUNT_CACHE+1)]
Definition: request.h:147
#define TOTAL_REQUESTS
Definition: request.h:103
Definition: request.h:42
int op_verify(u_char)
Definition: request.c:240
Definition: request.h:123
Definition: request.h:112
int find_free_rq_wait(u_char, rq_tbl *)
Definition: request.c:323
Definition: request.h:87
Definition: request.h:145
Definition: request.h:52
Definition: request.h:68
Definition: request.h:54
Definition: request.h:57
Definition: request.h:119
void rq_wait_idx_init(int *rq_wait_idx)
Definition: request.c:230
Definition: request.h:73
void update_rq_tbl(rq_tbl *)
Definition: request.c:281
int rq_verify(u_char)
Definition: request.c:245
const u_char * rq_to_str(u_char rq)
Definition: request.c:267
Definition: request.h:61
Definition: request.h:39
Definition: request.h:36
void op_filter_reset_re(int bit)
Definition: request.c:360
Definition: request.h:120
Definition: request.h:82
Definition: request.h:86
Definition: request.h:71
void op_filter_reset_rq(int bit)
Definition: request.c:373
#define TOTAL_OPS
Definition: request.h:102
Definition: request.h:45
int rq_wait_idx[(ANDNA_GET_COUNT_CACHE+1)]
Definition: request.h:152
Definition: request.h:50
int re_verify(u_char)
Definition: request.c:250
int update_rq_tbl_mutex
Definition: request.h:154
Definition: request.h:55
#define TOTAL_MAXRQ
Definition: request.h:144
Definition: request.h:41
Definition: request.h:47
Definition: request.h:69
pkt_op
Definition: request.h:34
Definition: request.h:117
Definition: request.h:90
Definition: request.h:79
Definition: request.h:72
Definition: request.h:74
Definition: request.h:113
Definition: request.h:65
const u_char * re_to_str(u_char re)
Definition: request.c:274
time_t rq_wait[31]
Definition: request.h:148
const u_char * rq_strerror(int err)
Definition: request.c:260
Definition: request.h:85
Definition: request.h:75
int add_rq(u_char, rq_tbl *)
Definition: request.c:336
int is_rq_full(u_char, rq_tbl *)
Definition: request.c:306
Definition: request.h:64
Definition: request.h:76
Definition: request.h:91
Definition: request.h:51
char filtered_op[(ACK_NEGATIVE+1) >>3]
Definition: request.h:161
Definition: request.h:83
Definition: request.h:66
Definition: request.h:37
Definition: request.h:109
Definition: request.h:92
Definition: request.h:81
Definition: request.h:122
Definition: request.h:95
Definition: request.h:80
Definition: request.h:88
Definition: request.h:114
Definition: request.h:84
Definition: request.h:121
Definition: request.h:70
Definition: request.h:125
errors
Definition: request.h:106
Definition: request.h:43
Definition: request.h:44
Definition: request.h:96
Definition: request.h:53
Definition: request.h:115