forked from wujingbang/aodv-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfbaodv_protocol.c
More file actions
executable file
·394 lines (308 loc) · 10.7 KB
/
fbaodv_protocol.c
File metadata and controls
executable file
·394 lines (308 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/***************************************************************************
module.c - description
-------------------
begin : Wed Aug 20 2003
copyright : (C) 2003 by Luke Klein-Berndt
email : kleinb@nist.gov
***************************************************************************/
/***************************************************************************
Modified by Miguel Catalan Cid - miguel.catcid@gmail.com - Version: Mon Jan 1 2010
***************************************************************************/
#include "fbaodv_protocol.h"
//General definitions
//MESH
u_int32_t g_mesh_ip;
u_int32_t g_mesh_netmask;
u_int32_t g_broadcast_ip;
u_int8_t g_aodv_gateway;
u_int8_t g_routing_metric;
u_int32_t g_fixed_rate;
// KR: 08/23/05
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Miguel Catalan Cid");
MODULE_DESCRIPTION("A AODV ad-hoc routing kernel module: Flow-based and WCIM routing metric");
extern struct timer_list aodv_timer;
extern struct aodv_route *aodv_route_table;
struct nf_hook_ops input_filter;
struct nf_hook_ops output_filter;
char *mesh_dev;
char *aodv_subnet;
char *routing_metric;
int nominal_rate;
char *network_ip;
unsigned int aodv_gateway;
char g_aodv_dev[8];
u_int32_t g_null_ip;
static struct proc_dir_entry *aodv_dir, *route_table_proc, *neigh_proc,
*gw_proc, *timers_proc, *node_load_proc, *sources_proc,
*reliability_proc, *ett_proc,
*tos_proc;
module_param(mesh_dev, charp, 0);
module_param(aodv_gateway, uint, 0);
module_param(network_ip, charp, 0);
module_param(routing_metric, charp,0);
module_param(nominal_rate,uint,0);
/****************************************************
init_module
----------------------------------------------------
This is called by insmod when things get
started up!
****************************************************/
static int __init init_fbaodv_module(void) {
char *tmp_str = NULL;
inet_aton("0.0.0.0", &g_null_ip);
if (mesh_dev==NULL)
{
printk("You need to specify the mesh network device ie:\n");
printk(" insmod fbaodv_protocol mesh_dev=wlan0 \n");
return(-1);
}
strcpy(g_aodv_dev, mesh_dev);
if(aodv_gateway) {
g_aodv_gateway = (u_int8_t)aodv_gateway;
printk("\n\nSet as AODV-ST gateway\n");
} else
g_aodv_gateway = 0;
if (network_ip == NULL) {
printk("You need to specify aodv network ip range, ie: \n");
printk("network_ip=192.168.0.12/255.255.255.0\n");
return(-1);
}
inet_aton("255.255.255.255",&g_broadcast_ip);
printk("Miguel Catalan Cid\nImplementation built on top of aodv-st by Krishna Ramachandran, UC Santa Barbara\n");
printk("---------------------------------------------\n");
/*ROUTING METRICS*/
if (routing_metric == NULL || strcmp(routing_metric, "HOPS") == 0){
g_routing_metric = HOPS;
printk("Hop count routing\n\n");
}
else if (strcmp(routing_metric, "ETT") == 0) {
g_routing_metric = ETT;
printk("ETT routing: Expected Transmission Time\n\n");
if (nominal_rate && get_nominalrate(nominal_rate))
g_fixed_rate = nominal_rate;
if (!nominal_rate || g_fixed_rate == 0) {
g_fixed_rate = 0;
printk("Nominal rate estimation using packet-pair probe messages: ACTIVE\n\n");
}
else
printk("Nominal rate estimation using packet-pair probe messages: INACTIVE\n\n");
}
else if (strcmp(routing_metric, "WCIM") == 0) {
g_routing_metric = WCIM;
printk("WCIM routing: Weighted Contention and Interference Model\n\n");
if (nominal_rate && get_nominalrate(nominal_rate))
g_fixed_rate = nominal_rate;
if (!nominal_rate || g_fixed_rate == 0) {
g_fixed_rate = 0;
printk("Nominal rate estimation using packet-pair probe messages: ACTIVE\n\n");
}
else
printk("Nominal rate estimation using packet-pair probe messages: INACTIVE\n\n");
}
if (network_ip!=NULL)
{
tmp_str = strchr(network_ip,'/');
if (tmp_str)
{ (*tmp_str)='\0';
tmp_str++;
printk("* Network IP - %s/%s\n", network_ip, tmp_str);
inet_aton(network_ip, &g_mesh_ip);
inet_aton(tmp_str, &g_mesh_netmask);
}
}
if (init_packet_queue() < 0) {
printk("Netlink queue error!!!\n");
printk("Shutdown complete!\n");
return(-1);
}
init_aodv_route_table();
init_task_queue();
init_timer_queue();
init_aodv_neigh_list();
init_aodv_neigh_list_2h();
init_src_list();
init_gw_list();
init_flow_type_table();
printk("\n*Initialicing mesh device - %s\n", mesh_dev);
if (init_aodv_dev(mesh_dev))
goto out1;
startup_aodv();
if (g_aodv_gateway) {
printk("initiating st_rreq dissemination\n");
insert_timer_simple(TASK_ST, HELLO_INTERVAL, g_mesh_ip); // start first st_rreq immediately
}
//MCC 21/07/2008- UPDATE TIMER ahora en insert_timer
insert_timer_simple(TASK_HELLO, HELLO_INTERVAL,g_mesh_ip );
insert_timer_simple(TASK_GW_CLEANUP, ACTIVE_GWROUTE_TIMEOUT, g_mesh_ip);
insert_timer_simple(TASK_CLEANUP, HELLO_INTERVAL+HELLO_INTERVAL/2, g_mesh_ip);
update_timer_queue();
aodv_dir = proc_mkdir("fbaodv",NULL);
if (aodv_dir == NULL) {
goto out2;
}
///*
#ifdef KERNEL2_6_26
aodv_dir->owner = THIS_MODULE;
#endif
route_table_proc=create_proc_read_entry("routes", 0, aodv_dir, read_route_table_proc, NULL);
#ifdef KERNEL2_6_26
route_table_proc->owner=THIS_MODULE;
#endif
if (route_table_proc == NULL) goto out2;
neigh_proc=create_proc_read_entry("neigh", 0, aodv_dir, read_neigh_proc, NULL);
if (neigh_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
neigh_proc->owner=THIS_MODULE;
#endif
timers_proc=create_proc_read_entry("timers", 0, aodv_dir, read_timer_queue_proc, NULL);
if (timers_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
timers_proc->owner=THIS_MODULE;
#endif
reliability_proc=create_proc_read_entry("reliability", 0, aodv_dir, read_rel_list_proc, NULL);
if (reliability_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
reliability_proc->owner=THIS_MODULE;
#endif
ett_proc=create_proc_read_entry("bw_estimation", 0, aodv_dir, read_ett_list_proc, NULL);
if (ett_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
ett_proc->owner=THIS_MODULE;
#endif
sources_proc=create_proc_read_entry("sources", 0, aodv_dir, read_src_list_proc, NULL);
if (sources_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
sources_proc->owner=THIS_MODULE;
#endif
node_load_proc=create_proc_read_entry("node_load", 0, aodv_dir, read_node_load_proc, NULL);
if (node_load_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
node_load_proc->owner=THIS_MODULE;
#endif
gw_proc=create_proc_read_entry("gateways", 0, aodv_dir, read_gw_list, NULL);
if (gw_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
gw_proc->owner=THIS_MODULE;
#endif
tos_proc=create_proc_read_entry("tos_available", 0, aodv_dir, read_flow_type_table_proc, NULL);
if (ett_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
ett_proc->owner=THIS_MODULE;
#endif
//*/
//netfilter stuff
// input hook
input_filter.list.next = NULL;
input_filter.list.prev = NULL;
input_filter.hook = input_handler;
input_filter.pf = PF_INET; // IPv4
input_filter.hooknum = NF_INET_LOCAL_IN;
//MCC- output hook
output_filter.list.next = NULL;
output_filter.list.prev = NULL;
output_filter.hook = output_handler;
output_filter.pf = PF_INET; // IPv4
output_filter.hooknum = NF_INET_POST_ROUTING;
nf_register_hook(&output_filter);
nf_register_hook(&input_filter);
printk("\n\n****FBAODV_PROTO module initialization complete****\n\n");
return 0;
out1:
close_sock();
del_timer(&aodv_timer);
printk("Removed timer...\n");
cleanup_packet_queue();
printk("Cleaned up AODV Queues...\n");
if (aodv_route_table != NULL)
cleanup_aodv_route_table();
flush_src_list();
printk("Cleaned up Route and Rule Tables...\n");
printk("Shutdown complete!\n");
return(-1);
out2:
remove_proc_entry("fbaodv/routes",NULL);
remove_proc_entry("fbaodv/timers",NULL);
remove_proc_entry("fbaodv/neigh",NULL);
remove_proc_entry("fbaodv/reliability", NULL);
remove_proc_entry("fbaodv/sources", NULL);
remove_proc_entry("fbaodv/node_load", NULL);
remove_proc_entry("fbaodv/gateways", NULL);
remove_proc_entry("fbaodv/user_gateway", NULL);
remove_proc_entry("fbaodv/gateways_assigned", NULL);
remove_proc_entry("fbaodv/bw_estimation", NULL);
remove_proc_entry("fbaodv/tos_available", NULL);
remove_proc_entry("fbaodv", NULL);
printk("\n\nShutting down...\n");
printk("Unregistered NetFilter hooks...\n");
close_sock();
printk("Closed sockets...\n");
del_timer(&aodv_timer);
printk("Removed timer...\n");
kill_aodv();
printk("Killed router thread...\n");
cleanup_task_queue();
cleanup_packet_queue();
printk("Cleaned up AODV Queues...\n");
cleanup_neigh_routes();
cleanup_aodv_route_table();
flush_src_list();
printk("Cleaned up Route and Rule Tables...\n");
//Eliminando listas
delete_aodv_neigh_list();
delete_aodv_neigh_list_2h();
delete_gw_list();
flush_flow_type_table();
printk("Cleaned up Lists...\n");
printk("Shutdown complete!\n");
return(-1);
}
/****************************************************
cleanup_module
----------------------------------------------------
cleans up the module. called by rmmod
****************************************************/
static void __exit cleanup_fbaodv_module(void)
{
printk("\n\nShutting down fbaodv PROTOCOL\n");
remove_proc_entry("fbaodv/routes",NULL);
remove_proc_entry("fbaodv/timers",NULL);
remove_proc_entry("fbaodv/neigh",NULL);
remove_proc_entry("fbaodv/reliability", NULL);
remove_proc_entry("fbaodv/sources", NULL);
remove_proc_entry("fbaodv/node_load", NULL);
remove_proc_entry("fbaodv/gateways", NULL);
remove_proc_entry("fbaodv/user_gateway", NULL);
//remove_proc_entry("fbaodv/gateways_assigned", NULL);
remove_proc_entry("fbaodv/bw_estimation", NULL);
remove_proc_entry("fbaodv/tos_available", NULL);
remove_proc_entry("fbaodv", NULL);
nf_unregister_hook(&input_filter);
nf_unregister_hook(&output_filter);
printk("Unregistered NetFilter hooks...\n");
close_sock();
printk("Closed sockets...\n");
del_timer(&aodv_timer);
printk("Removed timer...\n");
kill_aodv();
printk("Killed router thread...\n");
cleanup_task_queue();
cleanup_packet_queue();
printk("Cleaned up AODV Queues...\n");
cleanup_neigh_routes();
cleanup_aodv_route_table();
flush_src_list();
printk("Cleaned up Route and Rule Tables...\n");
//Eliminando listas
delete_aodv_neigh_list();
delete_aodv_neigh_list_2h();
delete_gw_list();
flush_flow_type_table();
printk("Cleaned up Lists...\n");
printk("Shutdown complete!\n");
}
/*
* ADDED JL kernel 2.6:
* */
module_init(init_fbaodv_module);
module_exit(cleanup_fbaodv_module);