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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include "rebroadcast_list.h"
00045
00046 #ifdef AODV_MULTICAST
00047
00048 struct ticket *ticket_roll[256];
00049
00050
00051 void init_check()
00052 {
00053 int i;
00054 for (i=0;i<ROLL_SIZE;i++)
00055 {
00056 ticket_roll[i]=NULL;
00057 }
00058 }
00059
00060
00061
00062 int check_check(u_int32_t ip, u_int16_t id)
00063 {
00064 u_int8_t target;
00065 int32_t amount;
00066 int point;
00067 int i;
00068
00069 unsigned char *ucp = (unsigned char *)&ip;
00070 target=(ucp[3] & 0xff);
00071
00072 if (ticket_roll[target]==NULL)
00073 {
00074 if ((ticket_roll[target] = (struct ticket*)kmalloc(sizeof(struct ticket),GFP_ATOMIC)) == NULL)
00075 {
00076 printk(KERN_WARNING "AODV: Not enough memory to create Flood ID queue\n");
00077
00078
00079 return -ENOMEM;
00080 }
00081
00082
00083
00084
00085 memset(ticket_roll[target]->check,0,sizeof(u_int8_t)*LIST_SIZE);
00086 ticket_roll[target]->last_checked=0;
00087 ticket_roll[target]->current_check=0;
00088 ticket_roll[target]->check_amount=0;
00089 }
00090
00091
00092
00093 amount=id-ticket_roll[target]->check_amount;
00094
00095 if (amount < -LIST_SIZE)
00096 {
00097 if (getcurrtime()-ticket_roll[target]->last_checked>10000)
00098 {
00099 memset(ticket_roll[target]->check,0,sizeof(u_int8_t)*LIST_SIZE);
00100 ticket_roll[target]->last_checked=getcurrtime();
00101 ticket_roll[target]->current_check=0;
00102 ticket_roll[target]->check_amount=id;
00103 printk("IP: %s ID: %u RESTARTED!!!!!!!!!!!!\n",inet_ntoa(ip),id);
00104 return 1;
00105 }
00106
00107 printk(" %d ID: %u Amount %d Current %d been forever!\n",target,id,amount,ticket_roll[target]->check_amount);
00108 return 0;
00109 }
00110
00111
00112
00113
00114
00115 if (amount>0)
00116 {
00117 amount=amount % LIST_SIZE;
00118 for (i=0;i<=amount;i++)
00119 {
00120 point=(i+ticket_roll[target]->current_check) % LIST_SIZE;
00121 ticket_roll[target]->check[point]=0;
00122 }
00123 ticket_roll[target]->last_checked=getcurrtime();
00124 ticket_roll[target]->current_check=point;
00125 ticket_roll[target]->check_amount=id;
00126
00127 ticket_roll[target]->check[point]=1;
00128 return 1;
00129 }
00130 point=(amount+ticket_roll[target]->current_check+LIST_SIZE) % LIST_SIZE;
00131 if (ticket_roll[target]->check[point])
00132 {
00133
00134
00135 return 0;
00136 }
00137 else
00138 {
00139
00140 ticket_roll[target]->check[point]=1;
00141 return 1;
00142 }
00143 }
00144 #endif