neighbor_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 #include "neighbor_list.h"
00028 
00029 /****************************************************
00030 
00031    neighbor_list
00032 ----------------------------------------------------
00033 This is a list of the neighboring nodes
00034 ****************************************************/
00035 
00036 struct neighbor_list_entry *neighbor_list;
00037 
00038 extern u_int32_t g_broadcast_ip;
00039 
00040 
00041 /****************************************************
00042 
00043    init_interface_list
00044 ----------------------------------------------------
00045 Discover the available interfaces and add them
00046 to the list
00047 ****************************************************/
00048 int init_neighbor_list()
00049 {
00050     neighbor_list=NULL;
00051     return 0;
00052 }
00053 
00054 /****************************************************
00055 
00056    find_interface_by_dev
00057 ----------------------------------------------------
00058 Finds an interface by matching up the dev to
00059 the dev in the interface list
00060 ****************************************************/
00061 struct neighbor_list_entry *find_neighbor_list_entry(u_int32_t ip)
00062 {
00063     struct neighbor_list_entry *tmp_entry=neighbor_list;
00064 
00065     //search the interface list for a device with the same ip
00066     while (tmp_entry!=NULL)
00067     {
00068         if (tmp_entry->ip==ip)
00069             return tmp_entry;
00070         tmp_entry=tmp_entry->next;
00071     }
00072 
00073     return NULL;
00074 }
00075 
00076 struct neighbor_list_entry *find_neighbor_list_entry_by_hw(char *hw_addr)
00077 {
00078     struct neighbor_list_entry *tmp_entry=neighbor_list;
00079 
00080     //search the interface list for a device with the same ip
00081     while (tmp_entry!=NULL)
00082     {
00083 
00084         if (!memcmp(&(tmp_entry->hw_addr), hw_addr, ETH_ALEN))
00085             return tmp_entry;
00086         tmp_entry=tmp_entry->next;
00087     }
00088 
00089     return NULL;
00090 }
00091 
00092 
00093 #ifdef AODV_SIGNAL
00094 void update_link_by_hw(char *hw_addr,u_int8_t link)
00095 {
00096 
00097     struct neighbor_list_entry *tmp_entry=neighbor_list;
00098     struct route_table_entry *tmp_route;
00099     u_int8_t link_temp;
00100 
00101     //search the interface list for a device with the same ip
00102     while (tmp_entry!=NULL)
00103     {
00104         if (!memcmp(&(tmp_entry->hw_addr), hw_addr, ETH_ALEN))
00105         {
00106             tmp_entry->link=link;
00107             tmp_route=find_route_table_entry(tmp_entry->ip);
00108 
00109             if (tmp_route!=NULL)
00110                 tmp_route->link=link;
00111         }
00112         tmp_entry=tmp_entry->next;
00113     }
00114 }
00115 #endif
00116 
00117 
00118 
00119 struct neighbor_list_entry *find_first_neighbor_list_entry()
00120 {
00121     return neighbor_list;
00122 }
00123 
00124 int delete_neighbor_list_entry(u_int32_t ip)
00125 {
00126     struct neighbor_list_entry *tmp_entry=neighbor_list;
00127     struct neighbor_list_entry *prev_entry=NULL;
00128 
00129     //search the interface list for a device with the same ip
00130     while (tmp_entry!=NULL)
00131     {
00132         if (tmp_entry->ip==ip)
00133         {
00134             if (prev_entry!=NULL)
00135                 prev_entry->next=tmp_entry->next;
00136             else
00137                 neighbor_list=tmp_entry->next;
00138             kfree(tmp_entry);
00139             delete_timer_queue_entry_of_id(ip, EVENT_NEIGHBOR);
00140             update_timer_queue();
00141             return 0;
00142         }
00143         prev_entry=tmp_entry;
00144         tmp_entry=tmp_entry->next;
00145     }
00146 
00147     return -ENODATA;
00148 }
00149 
00150 
00151 struct neighbor_list_entry *create_neighbor_list_entry(u_int32_t ip)
00152 {
00153     struct neighbor_list_entry *tmp_entry;
00154     int i;
00155     if ((tmp_entry = kmalloc(sizeof(struct neighbor_list_entry),GFP_ATOMIC)) == NULL)
00156     {
00157 
00158         printk(KERN_WARNING "NEIGHBOR_LIST: Can't allocate new entry\n");
00159 
00160         return NULL;
00161     }
00162 
00163 
00164     tmp_entry->next=neighbor_list;
00165     tmp_entry->ip=ip;
00166     tmp_entry->lifetime=0;
00167     tmp_entry->route_entry=NULL;
00168     
00169 #ifdef AODV_SIGNAL
00170     tmp_entry->link=255;
00171 #endif
00172     
00173     neighbor_list=tmp_entry;
00174     
00175 
00176     return tmp_entry;
00177 }
00178 

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