event_queue.c

説明を見る。
00001 /*
00002                Kernel AODV  v2.1
00003 National Institute of Standards and Technology
00004                Luke Klein-Berndt
00005 -----------------------------------------------------
00006   Version 2.1 new features:
00007      * Much more stable!
00008      * Added locks around important areas
00009      * Multihop Internet gatewaying now works
00010      * Multicast hack added
00011      * Many bug fixes!
00012 -----------------------------------------------------
00013 
00014 Originally based upon MadHoc code. I am not
00015 sure how much of it is left anymore, but MadHoc
00016 proved to be a great starting point.
00017 
00018 MadHoc was written by - Fredrik Lilieblad,
00019 Oskar Mattsson, Petra Nylund, Dan Ouchterlony
00020 and Anders Roxenhag Mail: mad-hoc@flyinglinux.net
00021 
00022 This software is Open Source under the GNU General Public Licence.
00023 
00024 */
00025 
00026 #include "event_queue.h"
00027 /****************************************************
00028 
00029    event_queue
00030 ----------------------------------------------------
00031 This is a queue used to store events which have
00032 to be dealt with. They are queued instead of
00033 being acted on directly because a lot of the
00034 events are recieved on interupts and you want
00035 to limit the amount of work being done on
00036 interupts!
00037 ****************************************************/
00038 
00039 extern u_int32_t g_broadcast_ip;
00040 struct event_queue_entry *event_queue;
00041 struct event_queue_entry *end_event_queue;
00042 spinlock_t event_lock = SPIN_LOCK_UNLOCKED;
00043 
00044 
00045 void lock_event()
00046 {
00047   spin_lock_bh(&event_lock);
00048 }
00049 
00050 void unlock_event()
00051 {
00052   spin_unlock_bh(&event_lock);
00053 }
00054 
00055 
00056 /****************************************************
00057 
00058    insert_event_queue_entry
00059 ----------------------------------------------------
00060 Inserts an event into the event queue. dev is the
00061 device the event was recieved on. data points
00062 to the event itself.
00063 ****************************************************/
00064 
00065 int insert_event_queue_entry(int type,struct sk_buff *packet)
00066 {
00067   struct event_queue_entry *new_entry;
00068   struct interface_list_entry *tmp_interface;
00069   struct iphdr *ip;
00070 
00071   int start_point=sizeof(struct udphdr)+sizeof(struct iphdr);
00072 
00073 
00074 
00075   if ((new_entry = (struct event_queue_entry*)kmalloc(sizeof(struct event_queue_entry),GFP_ATOMIC)) == NULL)
00076     {
00077       printk(KERN_WARNING "AODV: Not enough memory to create Event Queue Entry\n");
00078       return -ENOMEM;
00079     }
00080 
00081 
00082   new_entry->time = getcurrtime();
00083   new_entry->type = type;
00084   new_entry->prev = NULL;
00085 
00086   if (type<100)
00087     {
00088       ip  = packet->nh.iph;
00089       new_entry->src_ip = ip->saddr;
00090       new_entry->dst_ip = ip->daddr;
00091       new_entry->ttl = ip->ttl;
00092       new_entry->dev = packet->dev;
00093       new_entry->size = packet->len-start_point;
00094       
00095       //create space for the data and copy it there
00096       if ((new_entry->data = kmalloc(new_entry->size,GFP_ATOMIC)) ==  NULL)
00097         {
00098           kfree(new_entry);
00099           printk(KERN_WARNING "AODV: Not enough memory to create Event Queue Data Entry\n");
00100           return -ENOMEM;
00101         }
00102 
00103       memcpy(new_entry->data,packet->data+start_point,new_entry->size);
00104     }
00105   
00106 
00107 
00108   switch (type)
00109     {
00110       //RREP
00111     case EVENT_RREP:
00112       memcpy(&(new_entry->src_hw_addr),&(packet->mac.ethernet->h_source),sizeof(unsigned char)*ETH_ALEN);
00113       break;
00114       
00115     default:
00116       break;
00117     }
00118 
00119  /*lock table*/
00120     lock_event();
00121   
00122   //Set all the variables
00123   new_entry->next=event_queue;
00124 
00125   if (event_queue==NULL)
00126       end_event_queue=new_entry;
00127   else
00128       event_queue->prev=new_entry;
00129 
00130   
00131   event_queue=new_entry;
00132   
00133   
00134   /*unlock table*/
00135   unlock_event();
00136 
00137   //wake up the AODV thread
00138   kick_aodv();
00139   
00140   return 0;
00141 
00142 }
00143 
00144 /****************************************************
00145 
00146    get_last_event_queue_entry
00147 ----------------------------------------------------
00148 Gets the last entry from the event queue
00149 ****************************************************/
00150 
00151 struct event_queue_entry *get_next_event_queue_entry( void )
00152 {
00153   struct event_queue_entry *temp_entry=NULL;
00154 
00155   /*lock table*/
00156   lock_event();
00157   
00158   if (end_event_queue!=NULL)
00159     {
00160       temp_entry=end_event_queue;
00161       if (temp_entry->prev==NULL)
00162         {
00163           end_event_queue=NULL;
00164           event_queue=NULL;
00165         }
00166       else
00167         {
00168           end_event_queue=temp_entry->prev;
00169           end_event_queue->next=NULL;
00170         }
00171     }
00172 
00173   /*unlock table*/
00174   unlock_event();
00175 
00176   return temp_entry;
00177   
00178 }
00179 
00180 /****************************************************
00181 
00182    init_event_queue
00183 ----------------------------------------------------
00184 Initalizes the event queue
00185 ****************************************************/
00186 int init_event_queue( void )
00187 {
00188     event_queue = NULL;
00189     end_event_queue = NULL;
00190     return 0;
00191 }
00192 
00193 
00194 /****************************************************
00195 
00196    cleanup_event_queue
00197 ----------------------------------------------------
00198 Deletes eveything in the event queue!
00199 ****************************************************/
00200 int cleanup_event_queue(void )
00201 {
00202   struct event_queue_entry *temp_entry=NULL;
00203 
00204   while ((temp_entry=get_next_event_queue_entry())!=NULL)
00205     {
00206       kfree(temp_entry->data);
00207       kfree(temp_entry);
00208     }
00209 
00210  return 0;
00211 }
00212 
00213 
00214 
00215 

kernel_aodvmに対してThu Nov 10 18:53:11 2005に生成されました。  doxygen 1.4.5