00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "module.h"
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 struct nf_hook_ops input_filter;
00041 struct nf_hook_ops output_filter;
00042 struct nf_hook_ops forward_filter;
00043 struct nf_hook_ops post_routing_filter;
00044
00045
00046 struct route_table_entry *g_my_entry;
00047 u_int32_t g_my_ip;
00048 u_int32_t g_broadcast_ip;
00049 u_int8_t use_lo;
00050
00051 struct flood_id_queue_entry *rreq_id_queue;
00052
00053
00054 static struct proc_dir_entry *aodv_dir, *route_table_proc, *rreq_id_proc, *timer_queue_proc, *monitor_proc, *stats_proc;
00055
00056 #ifdef AODV_MULTICAST
00057 static struct proc_dir_entry *multicast_id_proc;
00058 #endif
00059
00060 #ifdef AODV_SIGNAL
00061 static struct proc_dir_entry *signal_proc;
00062 #endif
00063
00064
00065 #ifdef AODV_GATEWAY
00066 char *block_dev;
00067 char *aodv_dev;
00068 char *aodv_subnet;
00069 MODULE_PARM(aodv_dev,"s");
00070 MODULE_PARM(aodv_subnet,"s");
00071 MODULE_PARM(block_dev, "s");
00072 #endif
00073
00074 MODULE_PARM(use_lo,"i");
00075 MODULE_LICENSE("GPL");
00076 MODULE_AUTHOR("Luke Klein-Berndt");
00077 MODULE_DESCRIPTION("A AODV ad-hoc routing kernel module");
00078
00079 u_int8_t USE_LO;
00080 struct metric monitor;
00081 char g_block_dev[8];
00082 char g_aodv_dev[8];
00083 u_int32_t g_aodv_subnet;
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 int init_module(void)
00094 {
00095 int result;
00096
00097 if (use_lo==0)
00098 USE_LO=0;
00099 else
00100 USE_LO=1;
00101
00102
00103 #ifdef AODV_GATEWAY
00104 if (block_dev==NULL)
00105 strcpy(g_block_dev,"");
00106 else
00107 strcpy(g_block_dev,block_dev);
00108
00109 if (aodv_dev==NULL)
00110 strcpy(g_aodv_dev,"");
00111 else
00112 strcpy(g_aodv_dev,aodv_dev);
00113
00114 if (aodv_subnet==NULL)
00115 g_aodv_subnet=0;
00116 else
00117 {
00118 inet_aton(aodv_subnet, &g_aodv_subnet);
00119 }
00120 #endif
00121
00122 inet_aton("255.255.255.255",&g_broadcast_ip);
00123 printk("\n-=: Kernel AODV v2.1 :=-\nLuke Klein-Berndt\nWireless Communications Technologies Group\nNational Institue of Standards and Technology\n");
00124 printk("---------------------------------------------\n");
00125
00126
00127
00128
00129 input_filter.list.next = NULL;
00130 input_filter.list.prev = NULL;
00131 input_filter.hook = input_handler;
00132 input_filter.pf = PF_INET;
00133 input_filter.hooknum = NF_IP_PRE_ROUTING;
00134
00135
00136 output_filter.list.next = NULL;
00137 output_filter.list.prev = NULL;
00138 output_filter.hook = output_handler;
00139 output_filter.pf = PF_INET;
00140 output_filter.hooknum = NF_IP_LOCAL_OUT;
00141
00142
00143 forward_filter.list.next = NULL;
00144 forward_filter.list.prev = NULL;
00145 forward_filter.hook = output_handler;
00146 forward_filter.pf = PF_INET;
00147 forward_filter.hooknum = NF_IP_FORWARD;
00148
00149
00150
00151
00152
00153
00154
00155
00156 monitor.bytes=0;
00157 monitor.packets=0;
00158 monitor.routing_packets=0;
00159 monitor.rreq=0;
00160 monitor.rrep=0;
00161 monitor.rrer=0;
00162 monitor.last_read=getcurrtime();
00163
00164 init_check();
00165 init_route_table();
00166 init_event_queue();
00167 init_timer_queue();
00168 init_flood_id_queue();
00169 init_neighbor_list();
00170
00171 #ifdef AODV_MULTICAST
00172 init_rebroadcast_queue();
00173 init_multicast_sock();
00174 #endif
00175
00176 init_interface_list();
00177
00178 #ifdef AODV_SIGNAL
00179 init_iw_sock();
00180 #endif
00181
00182 init_packet_queue();
00183 startup_aodv();
00184
00185
00186 result = nf_register_hook(&output_filter);
00187 if (result)
00188 goto hook_failed;
00189
00190 #ifdef TRACE
00191 printk("Kernel_AODV: Output filter registered!\n");
00192 #endif
00193
00194
00195 result = nf_register_hook(&input_filter);
00196 if (result)
00197 goto hook_failed;
00198
00199 #ifdef TRACE
00200 printk("Kernel_AODV: Input filter registered!\n");
00201 #endif
00202
00203 result = nf_register_hook(&forward_filter);
00204 if (result)
00205 goto hook_failed;
00206
00207
00208 #ifdef TRACE
00209 printk("Kernel_AODV: Output filter registered!\n");
00210 #endif
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 #ifdef MESSAGES
00223 printk("Kernel_AODV: Principal IP address - %s\n",inet_ntoa(g_my_ip));
00224 #endif
00225
00226
00227 insert_timer_queue_entry(getcurrtime() + ACTIVE_ROUTE_TIMEOUT, NULL,0,g_my_ip,0,0, EVENT_CLEANUP);
00228
00229 update_timer_queue();
00230
00231
00232 aodv_dir=proc_mkdir("aodv",NULL);
00233 aodv_dir->owner=THIS_MODULE;
00234
00235
00236 stats_proc=create_proc_read_entry("aodv/stats", 0, NULL, read_stats_proc, NULL);
00237 stats_proc->owner=THIS_MODULE;
00238 route_table_proc=create_proc_read_entry("aodv/route_table", 0, NULL, read_route_table_proc, NULL);
00239 route_table_proc->owner=THIS_MODULE;
00240 rreq_id_proc=create_proc_read_entry("aodv/rreq_id_queue", 0, NULL, read_rreq_id_proc, NULL);
00241 rreq_id_proc->owner=THIS_MODULE;
00242 timer_queue_proc=create_proc_read_entry("aodv/timer_queue", 0, NULL, read_timer_queue_proc, NULL);
00243 timer_queue_proc->owner=THIS_MODULE;
00244 monitor_proc=create_proc_read_entry("aodv/monitor", 0, NULL, read_monitor_proc, NULL);
00245 monitor_proc->owner=THIS_MODULE;
00246
00247 #ifdef AODV_SIGNAL
00248 signal_proc=create_proc_read_entry("aodv/signal", 0, NULL, read_signal_proc, NULL);
00249 signal_proc->owner=THIS_MODULE;
00250 #endif
00251
00252
00253
00254 return 0;
00255
00256 hook_failed:
00257 #ifndef NO_ERROR
00258 printk(KERN_INFO "Kernel_AODV: error registering hook (%d)", result);
00259 #endif
00260
00261 return 1;
00262
00263 }
00264
00265
00266
00267
00268
00269
00270
00271
00272 void cleanup_module(void)
00273 {
00274
00275
00276 #ifdef AODV_SIGNAL
00277 remove_proc_entry("aodv/signal",NULL);
00278 #endif
00279
00280 remove_proc_entry("aodv/stats",NULL);
00281 remove_proc_entry("aodv/monitor",NULL);
00282 remove_proc_entry("aodv/route_table",NULL);
00283 remove_proc_entry("aodv/rreq_id_queue", NULL);
00284 remove_proc_entry("aodv/timer_queue", NULL);
00285
00286 remove_proc_entry("aodv", NULL);
00287
00288
00289
00290
00291 #ifdef MESSAGES
00292 printk("Kernel_AODV: Shutting down...\n");
00293 #endif
00294 kill_rebroadcast_thread();
00295
00296 nf_unregister_hook(&input_filter);
00297 nf_unregister_hook(&output_filter);
00298 nf_unregister_hook(&forward_filter);
00299
00300
00301
00302 #ifdef MESSAGES
00303 printk("Kernel_AODV: Unregistered NetFilter hooks...\n");
00304 #endif
00305
00306 cleanup_packet_queue();
00307 cleanup_event_queue();
00308
00309 cleanup_flood_id_queue(rreq_id_queue);
00310
00311
00312
00313 #ifdef MESSAGES
00314 printk("Kernel_AODV: Cleaned up AODV Queues...\n");
00315 #endif
00316
00317 kill_aodv();
00318
00319 #ifdef MESSAGES
00320 printk("Kernel_AODV: Killed router thread...\n");
00321 #endif
00322
00323 del_timer(&aodv_timer);
00324
00325 #ifdef MESSAGES
00326 printk("Kernel_AODV: Removed timer...\n");
00327 #endif
00328
00329 cleanup_route_table();
00330
00331 #ifdef MESSAGES
00332 printk("Kernel_AODV: Cleaned up Route Table...\n");
00333 #endif
00334
00335 close_sock();
00336
00337 #ifdef AODV_SIGNAL
00338 close_iw_sock();
00339 #endif
00340
00341 #ifdef MESSAGES
00342 printk("Kernel_AODV: Closed sockets...\n");
00343 #endif
00344
00345 #ifdef MESSAGES
00346 printk("Kernel_AODV: Shutdown complete!\n");
00347 #endif
00348 }