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 #include "flood_id_queue.h"
00027
00028
00029
00030
00031
00032
00033
00034
00035 extern struct flood_id_queue_entry *rreq_id_queue;
00036 rwlock_t rreq_lock = RW_LOCK_UNLOCKED;
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 int init_flood_id_queue( void )
00047 {
00048 rreq_id_queue=NULL;
00049
00050 return 0;
00051 }
00052
00053 void flood_read_lock()
00054 {
00055 write_lock_bh(&rreq_lock);
00056 }
00057
00058 void flood_read_unlock()
00059 {
00060 write_unlock_bh(&rreq_lock);
00061 }
00062
00063 void flood_write_lock()
00064 {
00065 write_lock_bh(&rreq_lock);
00066 }
00067
00068 void flood_write_unlock()
00069 {
00070 write_unlock_bh(&rreq_lock);
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 struct flood_id_queue_entry *find_flood_id_queue_entry(u_int32_t src_ip, u_int32_t flood_id )
00082 {
00083 struct flood_id_queue_entry *tmp_entry;
00084
00085
00086 u_int64_t curr=getcurrtime();
00087
00088
00089
00090 flood_read_lock();
00091
00092 tmp_entry = rreq_id_queue;
00093
00094
00095 while (tmp_entry!=NULL)
00096 {
00097
00098 if(tmp_entry->lifetime<curr)
00099 {
00100
00101 flood_read_unlock();
00102
00103 return NULL;
00104 }
00105
00106
00107 if (src_ip == tmp_entry->src_ip && flood_id == tmp_entry->flood_id)
00108 {
00109
00110 flood_read_unlock();
00111
00112 return tmp_entry;
00113 }
00114
00115
00116
00117
00118 tmp_entry=tmp_entry->next;
00119
00120
00121
00122 }
00123
00124 flood_read_unlock();
00125
00126 return NULL;
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 int read_rreq_id_proc(char *buffer, char **buffer_location, off_t offset, int buffer_length,int *eof,void *data)
00138 {
00139 int len;
00140 static char *my_buffer;
00141 char temp_buffer[200];
00142 struct flood_id_queue_entry *tmp_entry;
00143 char tmp[16];
00144 u_int64_t tmp_time;
00145
00146
00147
00148 flood_read_lock();
00149
00150 tmp_entry=rreq_id_queue;
00151
00152 my_buffer=buffer;
00153 sprintf(my_buffer,"\nFlood Id Queue\n---------------------------------\n");
00154
00155 while (tmp_entry!=NULL)
00156 {
00157 tmp_time=tmp_entry->lifetime-getcurrtime();
00158 strcpy(tmp,inet_ntoa(tmp_entry->dst_ip));
00159 sprintf(temp_buffer,"Src IP: %-16s Dst IP: %-16s Flood ID: %-10u sec/msec: %lu/%lu \n", inet_ntoa(tmp_entry->src_ip),tmp,tmp_entry->flood_id,100,100);
00160 strcat(my_buffer,temp_buffer);
00161 tmp_entry=tmp_entry->next;
00162 }
00163
00164
00165 flood_read_unlock();
00166
00167 sprintf(temp_buffer,"\n---------------------------------\n");
00168 strcat(my_buffer,temp_buffer);
00169
00170 *buffer_location=my_buffer;
00171 len = strlen(my_buffer);
00172 if (len <= offset+buffer_length) *eof = 1;
00173 *buffer_location = my_buffer + offset;
00174 len -= offset;
00175 if (len>buffer_length) len = buffer_length;
00176 if (len<0) len = 0;
00177 return len;
00178
00179 }
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 void print_flood_id_queue()
00191 {
00192 struct flood_id_queue_entry *tmp_entry;
00193 char tmp[16];
00194 tmp_entry= rreq_id_queue;
00195
00196 printk(KERN_INFO "Flood ID list:\n");
00197 while (tmp_entry!=NULL)
00198 {
00199 strcpy(tmp,inet_ntoa(tmp_entry->dst_ip));
00200 printk(KERN_INFO "Src IP: %-16s Dst IP: %-16s Flood ID: %-10u \n", inet_ntoa(tmp_entry->src_ip),tmp,tmp_entry->flood_id);
00201 tmp_entry=tmp_entry->next;
00202 }
00203 }
00204
00205
00206
00207
00208
00209
00210
00211 void cleanup_flood_id_queue()
00212 {
00213 struct flood_id_queue_entry *tmp_entry,*dead_entry;
00214 int count=0;
00215
00216 tmp_entry=rreq_id_queue;
00217
00218 print_flood_id_queue();
00219
00220 while (tmp_entry!=NULL)
00221 {
00222 dead_entry=tmp_entry;
00223 tmp_entry=tmp_entry->next;
00224 kfree(dead_entry);
00225 count++;
00226 }
00227 rreq_id_queue=NULL;
00228
00229 printk(KERN_INFO "Removed %d Flood ID entries! \n",count);
00230 printk(KERN_INFO "---------------------------------------------\n");
00231
00232 }
00233
00234
00235
00236
00237
00238
00239
00240 int insert_flood_id_queue_entry(u_int32_t ip, u_int32_t dst_ip,u_int32_t id, u_int64_t lt)
00241 {
00242 struct flood_id_queue_entry *new_entry;
00243
00244
00245
00246 if ((new_entry = (struct flood_id_queue_entry*)kmalloc(sizeof(struct flood_id_queue_entry),GFP_ATOMIC)) == NULL)
00247 {
00248 printk(KERN_WARNING "AODV: Not enough memory to create Flood ID queue\n");
00249
00250
00251 return -ENOMEM;
00252 }
00253
00254
00255 new_entry->src_ip = ip;
00256 new_entry->dst_ip = dst_ip;
00257 new_entry->flood_id = id;
00258 new_entry->lifetime = lt;
00259
00260
00261
00262 flood_write_lock();
00263
00264
00265 new_entry->next = rreq_id_queue;
00266
00267 rreq_id_queue=new_entry;
00268
00269
00270 flood_write_unlock();
00271
00272 return 0;
00273 }
00274
00275
00276
00277
00278
00279
00280
00281
00282 int check_flood_id_queue_entry_lifetime(struct flood_id_queue_entry *tmp_entry)
00283 {
00284 u_int64_t curr_time = getcurrtime();
00285
00286
00287 if ((tmp_entry!=NULL )&&(curr_time > tmp_entry->lifetime))
00288 {
00289 return 1;
00290 }
00291
00292 if (tmp_entry==NULL)
00293 {
00294 printk(KERN_WARNING "AODV: check_flood_id_queue_lifetime passed a NULL\n");
00295 }
00296
00297 return 0;
00298 }
00299
00300
00301
00302
00303
00304
00305
00306
00307 int delete_old_flood_id_queue_entries( )
00308 {
00309 struct flood_id_queue_entry *tmp_entry,*prev_entry,*dead_entry;
00310
00311 u_int64_t curr_time = getcurrtime();
00312 int c=0;
00313
00314
00315
00316 flood_write_lock( );
00317
00318
00319 tmp_entry= rreq_id_queue;
00320 prev_entry=NULL;
00321
00322
00323 while(tmp_entry!=NULL)
00324 {
00325 c++;
00326
00327 if (curr_time > tmp_entry->lifetime)
00328 {
00329
00330
00331
00332 if(prev_entry==NULL)
00333 rreq_id_queue=tmp_entry->next;
00334 else
00335 prev_entry->next=tmp_entry->next;
00336
00337
00338 dead_entry=tmp_entry;
00339 tmp_entry=tmp_entry->next;
00340 kfree(dead_entry);
00341
00342 }
00343 else
00344 {
00345
00346
00347
00348 prev_entry=tmp_entry;
00349 tmp_entry=tmp_entry->next;
00350
00351
00352 }
00353 }
00354
00355
00356 flood_write_unlock( );
00357
00358 return c;
00359 }
00360
00361
00362
00363
00364
00365
00366
00367 int delete_flood_id_queue_entry(struct flood_id_queue_entry *dead_entry )
00368 {
00369 struct flood_id_queue_entry *tmp_entry, *prev_entry;
00370
00371 tmp_entry= rreq_id_queue;
00372 prev_entry=NULL;
00373
00374
00375
00376 while (tmp_entry!=NULL)
00377 {
00378
00379 if(tmp_entry==dead_entry)
00380 {
00381 if (prev_entry==NULL)
00382 rreq_id_queue=tmp_entry->next;
00383 else
00384 prev_entry->next=tmp_entry->next;
00385 kfree(tmp_entry);
00386 return 0;
00387 }
00388 tmp_entry=tmp_entry->next;
00389 }
00390 return 1;
00391 }
00392
00393
00394