/* Kernel AODV v2.1 National 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 not sure how much of it is left anymore, but MadHoc proved to be a great starting point. MadHoc was written by - Fredrik Lilieblad, Oskar Mattsson, Petra Nylund, Dan Ouchterlony and Anders Roxenhag Mail: mad-hoc@flyinglinux.net This software is Open Source under the GNU General Public Licence. */ #include "neighbor_list.h" /**************************************************** neighbor_list ---------------------------------------------------- This is a list of the neighboring nodes ****************************************************/ struct neighbor_list_entry *neighbor_list; extern u_int32_t g_broadcast_ip; /**************************************************** init_interface_list ---------------------------------------------------- Discover the available interfaces and add them to the list ****************************************************/ int init_neighbor_list() { neighbor_list=NULL; return 0; } /**************************************************** find_interface_by_dev ---------------------------------------------------- Finds an interface by matching up the dev to the dev in the interface list ****************************************************/ struct neighbor_list_entry *find_neighbor_list_entry(u_int32_t ip) { struct neighbor_list_entry *tmp_entry=neighbor_list; //search the interface list for a device with the same ip while (tmp_entry!=NULL) { if (tmp_entry->ip==ip) return tmp_entry; tmp_entry=tmp_entry->next; } return NULL; } struct neighbor_list_entry *find_neighbor_list_entry_by_hw(char *hw_addr) { struct neighbor_list_entry *tmp_entry=neighbor_list; //search the interface list for a device with the same ip while (tmp_entry!=NULL) { if (!memcmp(&(tmp_entry->hw_addr), hw_addr, ETH_ALEN)) return tmp_entry; tmp_entry=tmp_entry->next; } return NULL; } #ifdef AODV_SIGNAL void update_link_by_hw(char *hw_addr,u_int8_t link) { struct neighbor_list_entry *tmp_entry=neighbor_list; struct route_table_entry *tmp_route; u_int8_t link_temp; //search the interface list for a device with the same ip while (tmp_entry!=NULL) { if (!memcmp(&(tmp_entry->hw_addr), hw_addr, ETH_ALEN)) { tmp_entry->link=link; tmp_route=find_route_table_entry(tmp_entry->ip); if (tmp_route!=NULL) tmp_route->link=link; } tmp_entry=tmp_entry->next; } } #endif struct neighbor_list_entry *find_first_neighbor_list_entry() { return neighbor_list; } int delete_neighbor_list_entry(u_int32_t ip) { struct neighbor_list_entry *tmp_entry=neighbor_list; struct neighbor_list_entry *prev_entry=NULL; //search the interface list for a device with the same ip while (tmp_entry!=NULL) { if (tmp_entry->ip==ip) { if (prev_entry!=NULL) prev_entry->next=tmp_entry->next; else neighbor_list=tmp_entry->next; kfree(tmp_entry); delete_timer_queue_entry_of_id(ip, EVENT_NEIGHBOR); update_timer_queue(); return 0; } prev_entry=tmp_entry; tmp_entry=tmp_entry->next; } return -ENODATA; } struct neighbor_list_entry *create_neighbor_list_entry(u_int32_t ip) { struct neighbor_list_entry *tmp_entry; int i; if ((tmp_entry = kmalloc(sizeof(struct neighbor_list_entry),GFP_ATOMIC)) == NULL) { printk(KERN_WARNING "NEIGHBOR_LIST: Can't allocate new entry\n"); return NULL; } tmp_entry->next=neighbor_list; tmp_entry->ip=ip; tmp_entry->lifetime=0; tmp_entry->route_entry=NULL; #ifdef AODV_SIGNAL tmp_entry->link=255; #endif neighbor_list=tmp_entry; return tmp_entry; }