The Netsukuku Project  0.0.9
An Alternative routing method
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
igs.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 IGS_H
20 #define IGS_H
21 
22 #include "route.h"
23 
24 
25 /*
26  * The IGS_MULTI_GW feature relies heavily on netfilter and the linux advanced
27  * routing.
28  */
29 #ifdef GNU_LINUX
30 #define IGS_MULTI_GW
31 #endif
32 
33 /*\
34  * * Bandwidth notes *
35  *
36  * When we talk of `bandwidth' we mean the average of the download and
37  * upload bandwidth of a particular node.
38  * The bandwidth of a gnode is the average of all the bandwidths of the nodes
39  * belonging to that gnode.
40  *
41  * Internally we save the `bandwidth' as a u_char variable using the
42  * `bandwidth_in_8bit' function (see igs.c)
43 \*/
44 
45 /* Minum bandwidth necessary to share an internet connection */
46 #define MIN_CONN_BANDWIDTH 3 /* 16 Kb/s */
47 
48 #define MAX_INTERNET_HNAMES 10
49 #define MAX_INTERNET_HNAME_SZ 64
50 #define INET_HOST_PING_TIMEOUT 3
51 #define IGW_HOST_PING_TIMEOUT 10
52 #define INET_NEXT_PING_WAIT 10
53 
54 #define IGW_BW_DELTA 1 /* If the difference between the old and the new
55  igw->bandwidth is >= IGW_BW_DELTA, then
56  me.igws is reordered and the routing table
57  updated */
58 #define MAXIGWS MAXGROUPNODE /* max number of internet
59  gateways in each level */
60 
61 #define RTTABLE_IGW 221 /* Routing tables from 221 to 244 */
62 #define RTTABLE_ALISHIELD 245 /* Anti Loop multi-Igw Shield
63  (what a damn long name, read the Ntk_IGS
64  RFC) */
65 #define FWMARK_ALISHIELD 25
66 
67 #ifdef DEBUG
68 #undef INET_NEXT_PING_WAIT
69 #define INET_NEXT_PING_WAIT 5
70 #endif
71 
72 /*
73  * inet_gw flags
74  */
75 #define IGW_TUNNELED 1
76 #define IGW_ACTIVE (1<<1) /* This gw is being used in the
77  routing table */
78 #define IGW_RTRULE (1<<2) /* The relative routing rule is already
79  present */
80 
81 /*
82  * internet_gateway
83  *
84  * This struct points to a particular (g)node which is sharing its Internet
85  * connection
86  */
88 {
90 
91  u_int ip[MAX_IP_INT];
92  u_char gid;
94 
95  char flags;
96  u_char bandwidth; /* Its Internet bandwidth */
97 };
98 typedef struct internet_gateway inet_gw;
99 
100 /* We pack only `gid' and `bandwidth' */
101 #define INET_GW_PACK_SZ (sizeof(u_char)*2 + MAX_IP_SZ)
102 
104 {
105  int16_t gws[MAX_LEVELS];/* Number of inet_gws there are in the
106  pack, for each level */
107  u_char levels;
108 }_PACKED_;
110 
111 /*
112  * The inet_gw_pack_body is:
113  * inet_gw_pack igw[hdr.gws[i]] for all the i that goes from 0 to
114  * hdr.levels
115  */
116 #define IGWS_PACK_SZ(hdr) \
117 ({ \
118  size_t _sz; int _pi; \
119  _sz=sizeof(struct inet_gw_pack_hdr); \
120  for(_pi=0; _pi<(hdr)->levels; _pi++) \
121  _sz+=INET_GW_PACK_SZ*((hdr)->gws[_pi]); \
122  _sz; \
123 })
124 
125 #define MAX_IGWS_PACK_SZ(levels) (sizeof(struct inet_gw_pack_hdr) + \
126  INET_GW_PACK_SZ*MAXIGWS*(levels))
127 
128 
129 /*\
130  *
131  * * * Multi Internet Gateways * * *
132  *
133 \*/
134 
135 /*
136  * igw_nexthop
137  *
138  * The multigw allows the simultaneus use of multiple internet gateways.
139  * The multigw requires one routing table and one tunnel for each
140  * nexthop in the default multipath route. With an array of `igw_nexthop' we
141  * keep track of them.
142  */
145 
146  u_char flags; /* inet_gw flags */
147 
148  u_char table;
149  u_char tunl; /* `tunl' is the number of the tunnel
150  we are using to reach this igw.
151  (tunl = 4 means we are using the
152  "tunl4" device) */
153 };
155 
156 
157 /*\
158  * Notes on the IGW packed in a qspn pkt
159  *
160  * The simplest way to tell the other nodes that we are sharing our Internet
161  * connection or that in our gnode there is an available gw is to use the
162  * bnode block included in the qspn packets.
163  * We consider an Internet gw as a bnode connected to a virtual gnode (the
164  * Internet), therefore in the relative bnode_chunk we set:
165  * bchunk.gnode = 0; this value has no meaning
166  * bchunk.level = GET_LEVELS(my_family) + 1;
167  * bchunk.rtt = the bandwidth of the internet connection of the gw.
168  * It is in the bandwidth_in_8bit() format.
169 \*/
170 
171 #define MAX_IGW_PER_QSPN_CHUNK 16 /* Maximum number of IGWs
172  contained in a single
173  QSPN chunk */
174 
175 
176 /*\
177  *
178  * * * Globals * * *
179  *
180 \*/
181 
184 
185 
186 /*\
187  *
188  * * * Functions declaration * *
189  *
190 \*/
191 
192 u_char bandwidth_in_8bit(u_int x);
193 int str_to_inet_gw(char *str, inet_prefix *gw, char **dev);
194 char **parse_internet_hosts(char *str, int *hosts);
195 void free_internet_hosts(char **hnames, int hosts);
196 
197 void init_my_igw(void);
198 void init_igws(inet_gw ***igws, int **igws_counter, int levels);
199 void reset_igws(inet_gw **igws, int *igws_counter, int levels);
200 void free_igws(inet_gw **igws, int *igws_counter, int levels);
201 void init_my_igws(inet_gw **igws, int *igws_counter,
202  inet_gw ***my_new_igws, u_char my_bandwidth,
203  map_node *cur_node, quadro_group *qg);
204 void free_my_igws(inet_gw ***my_igs);
207 inet_gw *igw_add_node(inet_gw **igws, int *igws_counter, int level,
208  int gid, map_node *node, int ip[MAX_IP_INT], u_char bandwidth);
209 int igw_del(inet_gw **igws, int *igws_counter, inet_gw *igw, int level);
210 inet_gw *igw_find_node(inet_gw **igws, int level, map_node *node);
211 inet_gw *igw_find_ip(inet_gw **igws, int level, u_int ip[MAX_IP_INT]);
212 int igw_del_node(inet_gw **, int *, int, map_node *);
213 void igw_update_gnode_bw(int *, inet_gw **, inet_gw *, int, int, int);
214 void igw_order(inet_gw **igws, int *igws_counter, inet_gw **my_igws, int level);
215 
216 int igw_check_inet_conn(void);
217 void *igw_check_inet_conn_t(void *null);
218 void *igw_monitor_igws_t(void *null);
219 
220 int igw_exec_masquerade_sh(char *script, int stop);
221 int igw_exec_tcshaper_sh(char *script, int stop,
222  char *dev, int upload_bw, int dnload_bw);
223 void reset_igw_nexthop(igw_nexthop *igwn);
224 void reset_igw_rules(void);
225 int igw_replace_def_igws(inet_gw **igws, int *igws_counter,
226  inet_gw **my_igws, int max_levels, int family);
227 
228 char *igw_build_bentry(u_char level, size_t *pack_sz, int *new_bblocks);
229 int igw_store_bblock(bnode_hdr *bblock_hdr, bnode_chunk *bchunk, u_char level);
230 char *pack_igws(inet_gw **igws, int *igws_counter, int levels, int *pack_sz);
231 int unpack_igws(char *pack, size_t pack_sz,
232  map_node *int_map, map_gnode **ext_map, int levels,
233  inet_gw ***new_igws, int **new_igws_counter);
234 
235 #endif /*IGS_H*/
void igw_update_gnode_bw(int *, inet_gw **, inet_gw *, int, int, int)
Definition: igs.c:588
#define INT_TYPE_16BIT
Definition: endianness.h:36
u_char bandwidth
Definition: igs.h:96
u_int ip[4]
Definition: igs.h:91
int igw_del(inet_gw **igws, int *igws_counter, inet_gw *igw, int level)
Definition: igs.c:527
int16_t gws[(14+(1+1))]
Definition: igs.h:105
#define MAX_MULTIPATH_ROUTES
Definition: route.h:26
Definition: map.h:125
static const int_info inet_gw_pack_hdr_iinfo
Definition: igs.h:109
int igw_exec_masquerade_sh(char *script, int stop)
Definition: igs.c:853
int igw_store_bblock(bnode_hdr *bblock_hdr, bnode_chunk *bchunk, u_char level)
Definition: igs.c:1276
inet_gw * igw_find_node(inet_gw **igws, int level, map_node *node)
Definition: igs.c:546
void reset_igws(inet_gw **igws, int *igws_counter, int levels)
Definition: igs.c:195
#define MAX_LEVELS
Definition: gmap.h:107
Definition: inet.h:73
Definition: gmap.h:127
u_char gid
Definition: igs.h:92
inet_gw * igw_add_node(inet_gw **igws, int *igws_counter, int level, int gid, map_node *node, int ip[4], u_char bandwidth)
Definition: igs.c:509
int igw_replace_def_igws(inet_gw **igws, int *igws_counter, inet_gw **my_igws, int max_levels, int family)
Definition: igs.c:968
void free_internet_hosts(char **hnames, int hosts)
Definition: igs.c:149
int igw_exec_tcshaper_sh(char *script, int stop, char *dev, int upload_bw, int dnload_bw)
Definition: igs.c:872
int igw_del_node(inet_gw **, int *, int, map_node *)
Definition: igs.c:572
Definition: igs.h:103
Definition: igs.h:143
int active_gws
Definition: igs.h:182
void free_my_igws(inet_gw ***my_igs)
Definition: igs.c:266
u_char flags
Definition: igs.h:146
#define MAX_IP_INT
Definition: inet.h:24
void * igw_monitor_igws_t(void *null)
Definition: igs.c:795
void init_my_igws(inet_gw **igws, int *igws_counter, inet_gw ***my_new_igws, u_char my_bandwidth, map_node *cur_node, quadro_group *qg)
Definition: igs.c:231
void init_internet_gateway_search(void)
Definition: igs.c:277
u_char levels
Definition: igs.h:107
map_node * int_map
Definition: qspn-empiric.h:122
inet_gw * igw_find_ip(inet_gw **igws, int level, u_int ip[4])
Definition: igs.c:557
void close_internet_gateway_search(void)
Definition: igs.c:473
int unpack_igws(char *pack, size_t pack_sz, map_node *int_map, map_gnode **ext_map, int levels, inet_gw ***new_igws, int **new_igws_counter)
Definition: igs.c:1433
void igw_order(inet_gw **igws, int *igws_counter, inet_gw **my_igws, int level)
Definition: igs.c:656
igw_nexthop multigw_nh[24]
Definition: igs.h:183
char ** parse_internet_hosts(char *str, int *hosts)
Definition: igs.c:140
#define INT_INFO
Definition: endianness.h:90
void reset_igw_nexthop(igw_nexthop *igwn)
Definition: igs.c:943
struct inet_gw_pack_hdr _PACKED_
map_node * node
Definition: igs.h:93
char * igw_build_bentry(u_char level, size_t *pack_sz, int *new_bblocks)
Definition: igs.c:1181
void init_my_igw(void)
void init_igws(inet_gw ***igws, int **igws_counter, int levels)
Definition: igs.c:187
u_char table
Definition: igs.h:148
void * igw_check_inet_conn_t(void *null)
Definition: igs.c:714
void free_igws(inet_gw **igws, int *igws_counter, int levels)
Definition: igs.c:209
#define LLIST_HDR(_struct)
Definition: llist.c:44
void reset_igw_rules(void)
Definition: igs.c:951
int family
Definition: if.c:34
inet_prefix nexthop
Definition: igs.h:144
int igw_check_inet_conn(void)
Definition: igs.c:694
int str_to_inet_gw(char *str, inet_prefix *gw, char **dev)
Definition: igs.c:104
char * pack_igws(inet_gw **igws, int *igws_counter, int levels, int *pack_sz)
Definition: igs.c:1388
char flags
Definition: igs.h:95
Definition: gmap.h:37
u_char tunl
Definition: igs.h:149
u_char bandwidth_in_8bit(u_int x)
Definition: igs.c:61
Definition: igs.h:87