rebroadcast_list.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 
00027 /****************************************************
00028 
00029    rebroadcast_list
00030 ----------------------------------------------------
00031 Rebroadcast List keeps track of the packets which
00032 have been rebroadcasted. It makes sure that a packet
00033 does not get reboradcasted twice... duplicate packets
00034 are bad! It does this by keep a list of the past N
00035 sequence numbers. There is a seperate list for each
00036 neighboring node. If a packet's seq num is below
00037 the lower bounds of the list then it is assumed that
00038 the packet is too old. If it falls in range of the
00039 list, it is checked to see if it has been recieved
00040 prior, if not it is rebroadcast.
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           /* Failed to allocate memory for new Flood ID queue */
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   //new_position=(LIST_SIZE+amount)%LIST_SIZE;
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;//(amount+ticket_roll[target]->current_check+LIST_SIZE) % LIST_SIZE;
00125       ticket_roll[target]->check_amount=id;
00126       //        printk("IP: %s ID: %u New!\n",inet_ntoa(ip),id);
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         //printk("IP: %s ID: %u already recieved!\n",inet_ntoa(ip),id);
00134 
00135         return 0;
00136       }
00137     else
00138       {
00139         //printk("IP: %s ID: %u New!\n",inet_ntoa(ip),id);
00140         ticket_roll[target]->check[point]=1;
00141         return 1;
00142       }
00143 }
00144 #endif

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