📄 hna_table.c
字号:
/* * Copyright (c) 2004 Ying Ge, Communication Research Center Canada. * * Copyright (c) 2002, 2003 Maoyu Wang, Communication Research Center Canada. * * By Ying Ge: * 1. Change the OLSR packet format and message processing procedure based * on the OLSR RFC. * 2. Add support of multiple interfaces to OLSR, including MID message * creating and processing procedure as specified in the OLSR RFC. * 3. Add QoS Support to OLSR * * By Maoyu Wang: * 1. Ported OLSR from IPv4 to IPv6. * 2. Added the Host and Network Association (HNA) functionality into OLSR. * 3. Added the default gateway functionality into OLSR by extending the HNA * message usage. The default gateway functionality supported the mobility * by cooperating with Mobile IPv6 for a mobile node as well as supported * Internet access for MANET nodes. * * DISTRIBUTED WITH NO WARRANTY, EXPRESS OR IMPLIED. * See the GNU Library General Public License (file COPYING in the distribution) * for conditions of use and redistribution *//* This software is available with usual "research" terms * with the aim of retain credits of the software. * Permission to use, copy, modify and distribute this software for any * purpose and without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies, * and the name of INRIA, or any contributor not be used in advertising * or publicity pertaining to this material without the prior explicit * permission. The software is provided "as is" without any * warranties, support or liabilities of any kind. * This product includes software developed by the University of * California, Berkeley and its contributors protected by copyrights. *//* * host and associated network table management daemon */char hna_table_rcsid[] = "$Id: hna_table.c,v 1.2 2002/12/06 10:36:12 prima Exp $";#include "defs.h"struct hna_host_hash hnahosttable[HASHSIZE];struct hna_subnet_hash hnasubnettable[HASHSIZE];/*-----------------------------------------------------------------------*/voidolsr_delete_list_of_host(struct hna_host_entry *host_entry,struct olsr_ip_addr *subaddr){ struct subnet_list *subnet_list; struct subnet_list *subnet_list_tmp; subnet_list=host_entry->hna_list_of_subnet; host_entry->hna_list_of_subnet=NULL; while(subnet_list!=NULL) { if(0==memcmp(&subnet_list->subnet->hna_subnet_addr,subaddr,sizeof(structolsr_ip_addr))) { subnet_list_tmp=subnet_list; subnet_list=subnet_list->next; free(subnet_list_tmp); } else { subnet_list_tmp=subnet_list; subnet_list=subnet_list->next; subnet_list_tmp->next=host_entry->hna_list_of_subnet; host_entry->hna_list_of_subnet=subnet_list_tmp; } }}/*------------------------------------------------------------------------*/voidolsr_delete_hna_subnet_table(struct hna_subnet_entry *subnet_entry){ struct host_list *list_of_host; struct hna_host_entry *host_entry; list_of_host=subnet_entry->hna_list_of_host; while(list_of_host!=NULL) { host_entry=list_of_host->host; olsr_delete_list_of_host(host_entry,&subnet_entry->hna_subnet_addr); subnet_entry->hna_list_of_host=list_of_host->next; free(list_of_host); list_of_host=subnet_entry->hna_list_of_host; }olsr_remque((struct olsr_qelem *)subnet_entry);free((void *)subnet_entry);}/*------------------------------------------------------------------------*/voidolsr_delete_list_of_subnet(struct hna_subnet_entry *subnet_entry,struct olsr_ip_addr *hostaddr){ struct host_list *list_of_host; struct host_list *list_of_host_tmp; list_of_host=subnet_entry->hna_list_of_host; subnet_entry->hna_list_of_host=NULL; while(list_of_host!=NULL) { if(0==memcmp(&list_of_host->host->hna_host_addr,hostaddr,sizeof(struct olsr_ip_addr))) { list_of_host_tmp=list_of_host; list_of_host=list_of_host->next; free(list_of_host_tmp); } else { list_of_host_tmp=list_of_host; list_of_host=list_of_host->next; list_of_host_tmp->next=subnet_entry->hna_list_of_host; subnet_entry->hna_list_of_host=list_of_host_tmp; } } if(subnet_entry->hna_list_of_host==NULL) { olsr_remque((struct olsr_qelem *)subnet_entry); free((void *)subnet_entry); }}/*------------------------------------------------------------------------*/voidolsr_delete_hna_host_table(struct hna_host_entry *host_entry){ struct subnet_list *list_of_subnet; struct hna_subnet_entry *subnet_entry; list_of_subnet=host_entry->hna_list_of_subnet; while(list_of_subnet!=NULL) { subnet_entry=list_of_subnet->subnet; olsr_delete_list_of_subnet(subnet_entry,&host_entry->hna_host_addr); host_entry->hna_list_of_subnet=list_of_subnet->next; free(list_of_subnet); list_of_subnet=host_entry->hna_list_of_subnet; } olsr_remque((struct olsr_qelem *)host_entry); free((void *)host_entry);}/*------------------------------------------------------------------------*/voidolsr_insert_hna_host_table(struct hna_host_entry *host_entry,struct hna_message *message){ olsr_u32_t hash; struct hna_host_hash *host_hash_hna; olsr_hashing(&message->originator,&hash); host_hash_hna=&hnahosttable[hash & HASHMASK]; memcpy(&host_entry->hna_host_addr,&message->originator,sizeof(struct olsr_ip_addr)); host_entry->hna_list_of_subnet=NULL; host_entry->hna_host_hash_value=hash; host_entry->hna_host_seq=message->packet_seq_number; timeradd(&now,&hold_time_hna,&host_entry->hna_host_timer); olsr_insque((struct olsr_qelem *)host_entry, (struct olsr_qelem *)host_hash_hna);}/*------------------------------------------------------------------------*/voidolsr_insert_hna_subnet_table(struct hna_subnet_entry *subnet_entry,struct hna_net_addr *netaddr){ olsr_u32_t hash; struct hna_subnet_hash *subnet_hash_hna; olsr_hashing(&netaddr->net_addr,&hash); subnet_hash_hna=&hnasubnettable[hash & HASHMASK]; memcpy(&subnet_entry->hna_subnet_addr,&netaddr->net_addr,sizeof(struct olsr_ip_addr)); subnet_entry->hna_subnet_prefix=netaddr->prefix; subnet_entry->hna_subnet_hash_value=hash; subnet_entry->hna_list_of_host=NULL; olsr_insque((struct olsr_qelem *)subnet_entry, (struct olsr_qelem *)subnet_hash_hna);}/*------------------------------------------------------------------------*/struct hna_host_entry *olsr_lookup_hna_host_table(struct olsr_ip_addr *hostaddr){ struct hna_host_entry *hna_host; struct hna_host_hash *host_hash_hna; olsr_u32_t hash; olsr_hashing(hostaddr,&hash); host_hash_hna=&hnahosttable[hash & HASHMASK]; for(hna_host=host_hash_hna->hna_host_forw;hna_host!=(struct hna_host_entry *)host_hash_hna;hna_host=hna_host->hna_host_forw) { if(hna_host->hna_host_hash_value!=hash) continue; if(0==memcmp(&hna_host->hna_host_addr, hostaddr,sizeof(struct olsr_ip_addr))) return(hna_host); } return (NULL);}/*------------------------------------------------------------------------*/struct hna_subnet_entry*olsr_lookup_hna_subnet_table(struct hna_net_addr *subnetaddr){ struct hna_subnet_entry *hna_subnet; struct hna_subnet_hash *subnet_hash_hna; olsr_u32_t hash; olsr_hashing(&(subnetaddr->net_addr),&hash); subnet_hash_hna=&hnasubnettable[hash & HASHMASK]; for(hna_subnet=subnet_hash_hna->hna_subnet_forw;hna_subnet!=(struct hna_subnet_entry *)subnet_hash_hna;hna_subnet=hna_subnet->hna_subnet_forw) { if(hna_subnet->hna_subnet_hash_value!=hash) continue; if ((0==memcmp(&hna_subnet->hna_subnet_addr,&(subnetaddr->net_addr),sizeof(struct olsr_ip_addr))) &&(hna_subnet->hna_subnet_prefix==subnetaddr->prefix)) return(hna_subnet); } return (NULL);}/*------------------------------------------------------------------------*/struct subnet_list *olsr_in_list_hna_host(struct hna_host_entry *host_entry,struct olsr_ip_addr *subnetaddr){ struct subnet_list *list_of_subnet; list_of_subnet=host_entry->hna_list_of_subnet; while(list_of_subnet!=NULL) { if(0==(memcmp(&list_of_subnet->subnet->hna_subnet_addr,subnetaddr,sizeof(structolsr_ip_addr)))) /*if(1==olsr_prefix_compare(&list_of_subnet->subnet->hna_subnet_addr,subnetaddr,subnetprefix))*/ return(list_of_subnet); list_of_subnet=list_of_subnet->next; } return(NULL);}/*------------------------------------------------------------------------*/struct hna_net_addr*olsr_subnet_existing_in_hnainfo(struct olsr_ip_addr* subnetaddr){ struct hna_net_addr *netaddr; for(netaddr=hnainfo.hna_net_addrs;netaddr!=NULL;netaddr=netaddr->next) { if(!memcmp(subnetaddr,&(netaddr->net_addr),sizeof(struct olsr_ip_addr))) return (netaddr); /*if(1==olsr_prefix_compare(&(netaddr->net_addr),subnetaddr,subnetprefix)) return (netaddr);*/ } return(NULL);}/*--------------------------------------------------------------------------*/struct host_list *olsr_insert_host_in_order_list(struct hna_host_entry *host_entry, struct hna_subnet_entry *subnet_entry){ olsr_u32_t host_hash; olsr_u32_t host_hash_tmp; struct host_list *hna_host_ptr; struct host_list *hna_host_pre; struct host_list *hna_host_cur; hna_host_ptr=(struct host_list*)malloc(sizeof(struct host_list)); if(subnet_entry->hna_list_of_host==NULL) { hna_host_ptr->next=subnet_entry->hna_list_of_host; subnet_entry->hna_list_of_host=hna_host_ptr; } else { olsr_hashing(&(host_entry->hna_host_addr),&host_hash); hna_host_pre=subnet_entry->hna_list_of_host; hna_host_cur=hna_host_pre; while(hna_host_cur!=NULL) { olsr_hashing(&(hna_host_cur->host->hna_host_addr),&host_hash_tmp); if(hna_host_cur==subnet_entry->hna_list_of_host) { if(host_hash<=host_hash_tmp) { hna_host_ptr->next=subnet_entry->hna_list_of_host; subnet_entry->hna_list_of_host=hna_host_ptr; changes_net=UP; break; } else { hna_host_cur=hna_host_pre->next; } } else { if(host_hash<=host_hash_tmp) { hna_host_ptr->next=hna_host_pre->next; hna_host_pre->next=hna_host_ptr; break; } else { hna_host_pre=hna_host_cur; hna_host_cur=hna_host_cur->next; } } } olsr_hashing(&(hna_host_pre->host->hna_host_addr),&host_hash_tmp); if((hna_host_cur==NULL)&&(host_hash>host_hash_tmp)) { hna_host_ptr->next=hna_host_pre->next; hna_host_pre->next=hna_host_ptr; } } return hna_host_ptr;}/*------------------------------------------------------------------------*/voidolsr_update_hna_host_table(struct hna_host_entry *host_entry,struct hna_message *message){ /* This function updates the time out for the existant pointed by t_last and creates new entries for the new destinations */ struct hna_net_addr *netaddr; struct subnet_list *hna_subnet; struct hna_subnet_entry *subnet_entry; struct host_list *hna_host; char str[46]; struct timeval hold_time_tmp; //added by Y.Ge float rcvd_vtime; //added by Y.Ge netaddr=message->hna_net_addrs; //timeradd(&now,&hold_time_hna,&host_entry->hna_host_timer); //commented by Y.Ge /*********** added by Y.Ge ************/ rcvd_vtime = olsr_compute_time_from_vtime(message->v_time); olsr_init_timer(rcvd_vtime*1000, &hold_time_tmp); timeradd(&now, &hold_time_tmp, &host_entry->hna_host_timer); /*********** end of revision ********/ while(netaddr!=NULL) { //CRC HNA modified //if(0!=memcmp(&netaddr->net_addr,&addr_manet,sizeof(struct olsr_ip_addr))) //commented by Y.Ge if (olsr_lookup_my_own_address(&netaddr->net_addr)==0) //added by Y.Ge, the netaddr is not one of my interface addresses { if(NULL==(hna_subnet=olsr_in_list_hna_host(host_entry,&netaddr->net_addr))) { if(NULL==olsr_subnet_existing_in_hnainfo(&netaddr->net_addr)) { if(NULL==(subnet_entry=olsr_lookup_hna_subnet_table(netaddr))) { subnet_entry=(struct hna_subnet_entry * )malloc(sizeof(struct hna_subnet_entry)); olsr_insert_hna_subnet_table(subnet_entry,netaddr); changes_net=UP; } /* creating the structure for the linkage*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -