The Netsukuku Project  0.0.9
An Alternative routing method
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
hook.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 HOOK_H
20 #define HOOK_H
21 
22 #include "qspn.h"
23 
24 #define MAX_FIRST_RADAR_SCANS 1 /* How many time we have to retry
25  the first radar_scan if we
26  didn't found anything */
27 #ifdef DEBUG
28 #undef MAX_FIRST_RADAR_SCANS
29 #define MAX_FIRST_RADAR_SCANS 1
30 #endif
31 
32 /* The IP class used during the hook */
33 #define HOOKING_IP_10 0xa000001 /* 10.0.0.1 */
34 #define HOOKING_IP_172 0xac100001 /* 172.16.0.1 */
35 #define HOOKING_IPV6 0xfec00000 /* fec0:: */
36 
37 #define HOOK_RQ_TIMEOUT 8 /* seconds */
38 
39 /*
40  * * * Global vars * * *
41  */
42 
43 /* How many times netsukuku_hook() was launched */
45 
46 /* Current join_rate */
48 u_int rnodes_rehooked; /* How many rnodes have rehooked with us */
49 
50 
51 /*
52  * * * Hook packets stuff * * *
53  */
54 
55 
56 /*
57  * The free_nodes pkt is used to send the list of all the free/not used
58  * nodes/gnodes present at level fn_hdr.level.
59  * If level is == 0 then the pkt contains the list of free nodes of the fn_hdr.gid
60  * gnode.
61  * If level is > 0 then it contains the list of free gnodes which are inside
62  * the gnode with `fn_hdr.gid' gid of the `fn_hdr.level'th level. So the free gnodes
63  * are part of the (fn_hdr.level - 1)th level.
64  */
66 {
67  u_char max_levels; /* How many levels we are managing */
68 
69  uint32_t ipstart[MAX_IP_INT]; /* The ipstart of the gnode */
70  u_char level; /* The level where the gnode belongs */
71  u_char gid; /* The gnode id */
72  u_char nodes; /* The number of free (g)nodes - 1 */
73  uint32_t join_rate; /* Join_rate of `level' */
74 }_PACKED_;
76  { sizeof(struct free_nodes_hdr)-sizeof(uint32_t) },
77  { 1 }
78  };
79 #define FREE_NODES_SZ(nodes) (sizeof(struct free_nodes_hdr) +\
80  (sizeof(u_char) * (nodes)))
81 
82 /*
83  * the free_nodes block is:
84  *
85  * u_char free_nodes[fn_hdr.nodes/8]; The bit x inside `free_nodes'
86  * tells if the node x, i.e.
87  * int_map[x], is up or not.
88  * If the bit is set to 1, it
89  * is.
90  *
91  * The free_nodes pkt is:
92  * fn_hdr;
93  * fn_block;
94  */
95 
96 /*
97  * the qspn_round pkt is:
98  * u_char max_levels;
99  * int qspn_id[max_levels]; the qspn_id of the last qspn_round for each
100  * fn_hdr.max_levels level
101  * struct timeval qtime[max_levels]; qspn round time: how many seconds passed away
102  * since the previous qspn round. There's a qtime
103  * for each fn_hdr.max_levels level
104  * u_int gcount[GCOUNT_LEVELS]; current qspn_gnode_count.
105  */
106 /* Note: for this int_info we are considering the timeval array as one int
107  * with `max_levels'*2 members */
109  { INT_TYPE_32BIT, INT_TYPE_32BIT, INT_TYPE_32BIT },
110  { sizeof(char), IINFO_DYNAMIC_VALUE, IINFO_DYNAMIC_VALUE },
112  };
113 
114 #define QSPN_ROUND_PKT_SZ(levels) (sizeof(u_char) + \
115  ((levels) * sizeof(int32_t)) + \
116  ((levels) * sizeof(struct timeval))+\
117  (GCOUNT_LEVELS * sizeof(u_int)))
118 
119 
120 /*
121  * * * Functions declaration * * *
122  */
123 
124 int put_free_nodes(PACKET rq_pkt);
125 int put_qspn_round(PACKET rq_pkt);
126 int put_ext_map(PACKET rq_pkt);
127 int put_int_map(PACKET rq_pkt);
128 int put_bnode_map(PACKET rq_pkt);
129 
130 int create_gnodes(inet_prefix *ip, int final_level);
131 void set_ip_and_def_gw(char *dev, inet_prefix ip);
132 
133 int hook_init(void);
134 int netsukuku_hook(map_gnode *hook_gnode, int hook_level);
135 
136 #endif /*HOOK_H*/
int put_int_map(PACKET rq_pkt)
Definition: hook.c:512
u_char max_levels
Definition: hook.h:67
int netsukuku_hook(map_gnode *hook_gnode, int hook_level)
Definition: hook.c:1549
int put_bnode_map(PACKET rq_pkt)
Definition: hook.c:583
void set_ip_and_def_gw(char *dev, inet_prefix ip)
int create_gnodes(inet_prefix *ip, int final_level)
Definition: hook.c:771
int put_free_nodes(PACKET rq_pkt)
Definition: hook.c:175
int hook_init(void)
Definition: hook.c:940
uint32_t join_rate
Definition: hook.h:73
int total_hooks
Definition: hook.h:44
#define IINFO_DYNAMIC_VALUE
Definition: endianness.h:25
Definition: inet.h:73
u_int rnodes_rehooked
Definition: hook.h:48
Definition: hook.h:65
#define GCOUNT_LEVELS
Definition: qspn.h:69
static const int_info qspn_round_pkt_iinfo
Definition: hook.h:108
u_char nodes
Definition: hook.h:72
#define MAX_IP_INT
Definition: inet.h:24
int put_ext_map(PACKET rq_pkt)
Definition: hook.c:446
uint32_t ipstart[4]
Definition: hook.h:69
#define INT_INFO
Definition: endianness.h:90
struct free_nodes_hdr _PACKED_
Definition: pkts.h:118
u_char level
Definition: hook.h:70
static const int_info free_nodes_hdr_iinfo
Definition: hook.h:75
#define INT_TYPE_32BIT
Definition: endianness.h:35
u_int hook_join_rate
Definition: hook.h:47
Definition: gmap.h:37
int put_qspn_round(PACKET rq_pkt)
Definition: hook.c:360
u_char gid
Definition: hook.h:71