📄 event_queue.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.*/#include "event_queue.h"/**************************************************** event_queue----------------------------------------------------This is a queue used to store events which haveto be dealt with. They are queued instead ofbeing acted on directly because a lot of theevents are recieved on interupts and you wantto limit the amount of work being done oninterupts!****************************************************/extern u_int32_t g_broadcast_ip;struct event_queue_entry *event_queue;struct event_queue_entry *end_queue;/**************************************************** insert_event_queue_entry----------------------------------------------------Inserts an event into the event queue. dev is thedevice the event was recieved on. data pointsto the event itself.****************************************************/int insert_event_queue_entry(u_int32_t src_ip, u_int32_t dst_ip, unsigned char *src_hw_addr,struct net_device* dev, int type, int size,void *data,u_int8_t ttl){ struct event_queue_entry *new_entry; struct interface_list_entry *tmp_interface; //create a new entry if ((new_entry = (struct event_queue_entry*)kmalloc(sizeof(struct event_queue_entry),GFP_ATOMIC)) == NULL) {#ifndef NO_ERROR printk("EVENT_QUEUE: Error allocating new event!\n");#endif return 1; } //If the event queue is empty start the ID at 1 if (event_queue==NULL) { end_queue=new_entry; new_entry->id = 1; } else { new_entry->id=event_queue->id+1; } //Set all the variables new_entry->src_ip = src_ip; new_entry->dst_ip = dst_ip; new_entry->dev = dev; new_entry->type = type; new_entry->size = size; new_entry->ttl=ttl; new_entry->time=getcurrtime(); if (src_hw_addr!=NULL) memcpy(&(new_entry->src_hw_addr),src_hw_addr,sizeof(unsigned char) * ETH_ALEN); //create space for the data and copy it there if ((new_entry->data = kmalloc(size,GFP_ATOMIC)) == NULL) {#ifndef NO_ERROR printk("EVENT_QUEUE: Error allocating data space!\n");#endif return 1; } memcpy(new_entry->data,data,size); new_entry->next=event_queue; event_queue=new_entry; //wake up the AODV thread kick_aodv(); return 0;}/**************************************************** get_first_event_queue_entry----------------------------------------------------Gets the first entry from the event queue****************************************************/struct event_queue_entry *get_first_event_queue_entry( void ){ return event_queue;}struct event_queue_entry *get_last_event_queue_entry( void ){ return end_queue;}/**************************************************** delete_event_queue_entry_by_id----------------------------------------------------deletes an event queue entry based upon anID****************************************************/int delete_event_queue_entry_by_id(int id){ struct event_queue_entry *prev_event; struct event_queue_entry *temp_event; prev_event=NULL; temp_event=event_queue; //go throught the whole list while(temp_event!=NULL) { //if the IDs match if (temp_event->id==id) { //Make sure the chain is not broken if (end_queue==temp_event) { if (prev_event!=NULL) end_queue=prev_event; else end_queue=NULL; } if (prev_event!=NULL) prev_event->next=temp_event->next; else event_queue=temp_event->next; //free the data kfree(temp_event->data); kfree(temp_event); return 0; } //head on to the next event prev_event=temp_event; temp_event=temp_event->next; } return 1;}/**************************************************** delete_first_event_queue_entry----------------------------------------------------Deletes the first event in the queue****************************************************/int delete_first_event_queue_entry(){ struct event_queue_entry *dead_event; //if there is actaully something in the queue if (event_queue!=NULL) { if (end_queue==event_queue) end_queue=NULL; dead_event = event_queue; kfree(dead_event->data);//,dead_event->size); event_queue=dead_event->next; kfree(dead_event); return 0; } else { return 1; }}/**************************************************** init_event_queue----------------------------------------------------Initalizes the event queue****************************************************/int init_event_queue( void ){ event_queue = NULL; end_queue = NULL; return 0;}/**************************************************** cleanup_event_queue----------------------------------------------------Deletes eveything in the event queue!****************************************************/int cleanup_event_queue(void ){ while (!delete_first_event_queue_entry()); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -