?? rebroadcast_list.c
字號:
/* Kernel AODV v2.1National Institute of Standards and Technology Luke Klein-Berndt----------------------------------------------------- Version 2.1 new features: * Much more stable! * Added locks around important areas * Multihop Internet gatewaying now works * Multicast hack added * 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.*//**************************************************** rebroadcast_list----------------------------------------------------Rebroadcast List keeps track of the packets whichhave been rebroadcasted. It makes sure that a packetdoes not get reboradcasted twice... duplicate packetsare bad! It does this by keep a list of the past Nsequence numbers. There is a seperate list for eachneighboring node. If a packet's seq num is belowthe lower bounds of the list then it is assumed thatthe packet is too old. If it falls in range of thelist, it is checked to see if it has been recievedprior, if not it is rebroadcast.****************************************************/#include "rebroadcast_list.h"#ifdef AODV_MULTICASTstruct ticket *ticket_roll[256];void init_check(){ int i; for (i=0;i<ROLL_SIZE;i++) { ticket_roll[i]=NULL; }}int check_check(u_int32_t ip, u_int16_t id){ u_int8_t target; int32_t amount; int point; int i; unsigned char *ucp = (unsigned char *)&ip; target=(ucp[3] & 0xff); if (ticket_roll[target]==NULL) { if ((ticket_roll[target] = (struct ticket*)kmalloc(sizeof(struct ticket),GFP_ATOMIC)) == NULL) { printk(KERN_WARNING "AODV: Not enough memory to create Flood ID queue\n"); /* Failed to allocate memory for new Flood ID queue */ return -ENOMEM; } memset(ticket_roll[target]->check,0,sizeof(u_int8_t)*LIST_SIZE); ticket_roll[target]->last_checked=0; ticket_roll[target]->current_check=0; ticket_roll[target]->check_amount=0; } amount=id-ticket_roll[target]->check_amount; if (amount < -LIST_SIZE) { if (getcurrtime()-ticket_roll[target]->last_checked>10000) { memset(ticket_roll[target]->check,0,sizeof(u_int8_t)*LIST_SIZE); ticket_roll[target]->last_checked=getcurrtime(); ticket_roll[target]->current_check=0; ticket_roll[target]->check_amount=id; printk("IP: %s ID: %u RESTARTED!!!!!!!!!!!!\n",inet_ntoa(ip),id); return 1; } printk(" %d ID: %u Amount %d Current %d been forever!\n",target,id,amount,ticket_roll[target]->check_amount); return 0; } //new_position=(LIST_SIZE+amount)%LIST_SIZE; if (amount>0) { amount=amount % LIST_SIZE; for (i=0;i<=amount;i++) { point=(i+ticket_roll[target]->current_check) % LIST_SIZE; ticket_roll[target]->check[point]=0; } ticket_roll[target]->last_checked=getcurrtime(); ticket_roll[target]->current_check=point;//(amount+ticket_roll[target]->current_check+LIST_SIZE) % LIST_SIZE; ticket_roll[target]->check_amount=id; // printk("IP: %s ID: %u New!\n",inet_ntoa(ip),id); ticket_roll[target]->check[point]=1; return 1; } point=(amount+ticket_roll[target]->current_check+LIST_SIZE) % LIST_SIZE; if (ticket_roll[target]->check[point]) { //printk("IP: %s ID: %u already recieved!\n",inet_ntoa(ip),id); return 0; } else { //printk("IP: %s ID: %u New!\n",inet_ntoa(ip),id); ticket_roll[target]->check[point]=1; return 1; }}#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -