📄 aodv_thread.c
字号:
/* Kernel AODV v2.0National Institute of Standards and Technology Luke Klein-Berndt----------------------------------------------------- Version 2.0 new features: * Updated to AODV draft version 11 * Managed internet gatewaying * Monitor wireles signal strength * Many bug fixes!-----------------------------------------------------Originally based upon MadHoc code. I am notsure how much of it is left anymore, but MadHocproved to be a great starting point.MadHoc was written by - Fredrik Lilieblad,Oskar Mattsson, Petra Nylund, Dan Ouchterlonyand Anders Roxenhag Mail: mad-hoc@flyinglinux.netThis software is Open Source under the GNU General Public Licence.*//**************************************************** aodv_thread----------------------------------------------------This is the main thread which handles theprocessing of packets which are placed in itsqueue. After netfilter calls packet_in on aninteruppt, packet_in takes the packet and if itis an AODV packet it places into the eventqueue. It then kicks aodv_thread. Aodv_threadprocesses the event and pass it along tothe correct function.****************************************************/#include "aodv_thread.h"static int aodv_pid;static wait_queue_head_t aodv_wait;static atomic_t kill_thread;static atomic_t aodv_is_dead;/**************************************************** kick_aodv----------------------------------------------------Wakes up the aodv_thread. You call this afteryou have placed something on the event queue.****************************************************/void kick_aodv(){ //We are trying to wake up AODV!!!#ifdef TRACE printk("We are trying to wake up AODV!!!\n");#endif //AODV thread is an interupptible sleep state.... this interupts it wake_up_interruptible(&aodv_wait);}/**************************************************** kill_aodv----------------------------------------------------This will kill the AODV Thread. It sets the killflag and then wakes up AODV thread. If itdoes not get confirmation that AODV is deadit will try again!****************************************************/void kill_aodv(){ wait_queue_head_t queue; int count=0; //starts a wait queue init_waitqueue_head(&queue); //sets a flag letting the thread know it should die //wait for the thread to set flag saying it is dead while ((atomic_read(&aodv_is_dead)==0) && (count<5)) { //lower semaphore for the thread atomic_set(&kill_thread,1); wake_up_interruptible(&aodv_wait); interruptible_sleep_on_timeout(&queue,HZ);#ifdef TRACE printk("KILL_KROUTE_THREAD: Sent kill signal to thread... waiting for it to die...\n");#endif //sleep for a bit and then check on the thread again count++; } if (count>4)#ifdef MESSAGES printk("AODV_THREAD: Tried to kill AODV Thread, but failed. It may have crashed. \n");#endif}/**************************************************** aodv----------------------------------------------------This is the main section of the thread. The mainloop! The big enchilada! It is a big loop whichwill handle everything in the Event queue andthen goto sleep.****************************************************/void aodv(){ //The queue holding all the events to be dealt with struct event_queue_entry *working_event; //Initalize the variables init_waitqueue_head(&aodv_wait); atomic_set(&kill_thread,0); atomic_set(&aodv_is_dead,0); //Name our thread lock_kernel(); sprintf(current->comm,"kernel-aodv"); exit_mm(current); unlock_kernel();#ifdef TRACE printk("AODV_THREAD: Initalized... service started \n");#endif //why would I ever want to stop ? :) for (;;) { //should the thread exit? if (atomic_read(&kill_thread)) { #ifdef TRACE printk("AODV_THREAD: Got kill signal... stopping service\n"); #endif goto exit; } //goto sleep until we recieve an interupt interruptible_sleep_on(&aodv_wait); //should the thread exit? if (atomic_read(&kill_thread)) { #ifdef TRACE printk("AODV_THREAD: Got kill signal... stopping service\n"); #endif goto exit; }#ifdef TRACE printk("AODV_THREAD: woke up\n");#endif //While the buffer is not empty while((working_event=get_last_event_queue_entry())!=NULL) { //takes a different action depending on what type of event is recieved switch (working_event->type) { //RREQ case EVENT_RREQ: recv_rreq(working_event); break; //RREP case EVENT_RREP: recv_rrep(working_event); break; case EVENT_RREP_ACK: recv_rrep_ack(working_event); break; //RERR case EVENT_RERR: recv_rerr(working_event); break; //Cleanup the Route Table and Flood ID queue case EVENT_CLEANUP: find_inactive_route_table_entries(); delete_old_rreq_id_queue_entries(); break; default: break; } //Remove the event from the queue because you have finished with it delete_event_queue_entry_by_id(working_event->id); }#ifdef TRACE printk("AODV_ROUTER: back to sleep\n");#endif }exit: //Set the flag that shows you are dead atomic_set(&aodv_is_dead,1);}/**************************************************** startup_aodv----------------------------------------------------Creates AODV thread and tells it to start in thefunction aodv()****************************************************/void startup_aodv(){ //start the thread and have it start in the aodv function aodv_pid=kernel_thread((void *) &aodv,NULL,0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -