[Olsr-cvs] olsrd-current/lib/nameservice/src nameservice.c, 1.15, 1.16

Andreas T�nnesen (spam-protected)
Tue Dec 12 11:54:54 CET 2006


Update of /cvsroot/olsrd/olsrd-current/lib/nameservice/src
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv9270/lib/nameservice/src

Modified Files:
	nameservice.c 
Log Message:
Added patch from John Hay. Due to diff from last release to HEAD this had to be done partially manually. Hopefully I got everything right...

Index: nameservice.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/nameservice/src/nameservice.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** nameservice.c	7 Jan 2006 08:17:43 -0000	1.15
--- nameservice.c	12 Dec 2006 10:54:52 -0000	1.16
***************
*** 72,75 ****
--- 72,77 ----
  olsr_bool name_table_changed = OLSR_TRUE;
  
+ static void free_routing_table_list(struct rt_entry **list) ;
+ static struct rt_entry *host_lookup_routing_table(union olsr_ip_addr *);
  
  /**
***************
*** 140,144 ****
  	}
  	else if(!strcmp(key, "dns-server")) {
! 		struct in_addr ip;
  		if (strlen(value) == 0) {
  			// set dns server ip to main address
--- 142,146 ----
  	}
  	else if(!strcmp(key, "dns-server")) {
! 		union olsr_ip_addr ip;
  		if (strlen(value) == 0) {
  			// set dns server ip to main address
***************
*** 146,151 ****
  			have_dns_server = OLSR_TRUE;
  		}
! 		else if (inet_aton(value, &ip)) {
! 			my_dns_server.v4 = ip.s_addr;
  			have_dns_server = OLSR_TRUE;
  		}
--- 148,153 ----
  			have_dns_server = OLSR_TRUE;
  		}
! 		else if (inet_pton(olsr_cnf->ip_version, value, &ip) == 1) {
! 			memcpy(&my_dns_server, &ip, olsr_cnf->ipsize);
  			have_dns_server = OLSR_TRUE;
  		}
***************
*** 170,176 ****
  	else {
  		// assume this is an IP address and hostname
! 		struct in_addr ip;
  		
! 		if (inet_aton(key, &ip)) {
  			// the IP is validated later
  			struct name_entry *tmp;
--- 172,178 ----
  	else {
  		// assume this is an IP address and hostname
! 		union olsr_ip_addr ip;
  		
! 		if (inet_pton(olsr_cnf->ip_version, key, &ip) == 1) {
  			// the IP is validated later
  			struct name_entry *tmp;
***************
*** 179,183 ****
  			tmp->len = strlen( tmp->name );
  			tmp->type = NAME_HOST;
! 			tmp->ip.v4 = ip.s_addr;
  			tmp->next = my_names;
  			my_names = tmp;
--- 181,185 ----
  			tmp->len = strlen( tmp->name );
  			tmp->type = NAME_HOST;
! 			memcpy(&tmp->ip, &ip, olsr_cnf->ipsize);
  			tmp->next = my_names;
  			my_names = tmp;
***************
*** 212,219 ****
  	struct name_entry *name;
  	struct name_entry *prev=NULL;
  
  	/* fixup names and IP addresses */
  	for (name = my_names; name != NULL; name = name->next) {
! 		if (name->ip.v4 == 0) {
  			// insert main_addr
  			memcpy(&name->ip, &olsr_cnf->main_addr, olsr_cnf->ipsize);
--- 214,224 ----
  	struct name_entry *name;
  	struct name_entry *prev=NULL;
+ 	union olsr_ip_addr ipz;
+ 
+ 	memset(&ipz, 0, sizeof(ipz));
  
  	/* fixup names and IP addresses */
  	for (name = my_names; name != NULL; name = name->next) {
! 		if (memcmp(&name->ip, &ipz, olsr_cnf->ipsize) == 0) {
  			// insert main_addr
  			memcpy(&name->ip, &olsr_cnf->main_addr, olsr_cnf->ipsize);
***************
*** 239,243 ****
  		
  	if (have_dns_server) {
! 		if (my_dns_server.v4 == 0) {
  			memcpy(&my_dns_server, &olsr_cnf->main_addr, olsr_cnf->ipsize);
  			printf("\nNAME PLUGIN: announcing upstream DNS server: %s\n", 
--- 244,248 ----
  		
  	if (have_dns_server) {
! 		if (memcmp(&my_dns_server, &ipz, olsr_cnf->ipsize) == 0) {
  			memcpy(&my_dns_server, &olsr_cnf->main_addr, olsr_cnf->ipsize);
  			printf("\nNAME PLUGIN: announcing upstream DNS server: %s\n", 
***************
*** 402,408 ****
  	double vtime;
  	int size;
  
  	/* Fetch the originator of the messsage */
! 	memcpy(&originator, &m->v4.originator, olsr_cnf->ipsize);
  		
  	/* Fetch the message based on IP version */
--- 407,420 ----
  	double vtime;
  	int size;
+  	olsr_u16_t seqno;
  
  	/* Fetch the originator of the messsage */
! 	if(olsr_cnf->ip_version == AF_INET) {
! 		memcpy(&originator, &m->v4.originator, olsr_cnf->ipsize);
! 		seqno = ntohs(m->v4.seqno);
! 	} else {
! 		memcpy(&originator, &m->v6.originator, olsr_cnf->ipsize);
! 		seqno = ntohs(m->v6.seqno);
! 	}
  		
  	/* Fetch the message based on IP version */
***************
*** 415,419 ****
  		vtime = ME_TO_DOUBLE(m->v6.olsr_vtime);
  		size = ntohs(m->v6.olsr_msgsize);
! 		namemessage = (struct namemsg*)&m->v4.message;
  	}
  
--- 427,431 ----
  		vtime = ME_TO_DOUBLE(m->v6.olsr_vtime);
  		size = ntohs(m->v6.olsr_msgsize);
! 		namemessage = (struct namemsg*)&m->v6.message;
  	}
  
***************
*** 434,438 ****
  	* processed if nessecary
  	*/
! 	if(!olsr_check_dup_table_proc(&originator, ntohs(m->v4.seqno))) {
  		/* If so - do not process */
  		goto forward;
--- 446,450 ----
  	* processed if nessecary
  	*/
! 	if(!olsr_check_dup_table_proc(&originator, seqno)) {
  		/* If so - do not process */
  		goto forward;
***************
*** 444,448 ****
  	/* Forward the message if nessecary
  	* default_fwd does all the work for us! */
! 	olsr_forward_message(m, &originator, ntohs(m->v4.seqno), in_if, in_addr);
  }
  
--- 456,460 ----
  	/* Forward the message if nessecary
  	* default_fwd does all the work for us! */
! 	olsr_forward_message(m, &originator, seqno, in_if, in_addr);
  }
  
***************
*** 632,636 ****
  	fprintf(hosts, "### do not edit\n\n");
  
! 	fprintf(hosts, "127.0.0.1\tlocalhost\n\n");
  	
  	// copy content from additional hosts filename
--- 644,649 ----
  	fprintf(hosts, "### do not edit\n\n");
  
! 	fprintf(hosts, "127.0.0.1\tlocalhost\n");
! 	fprintf(hosts, "::1\t\tlocalhost\n\n");
  	
  	// copy content from additional hosts filename
***************
*** 689,696 ****
  {
  	int hash;
! 	struct name_entry *name;
  	struct db_entry *entry;
  	struct rt_entry *best_routes = NULL;
! 	struct rt_entry *route, *tmp, *last;
  	FILE* resolv;
  	int i=0;
--- 702,709 ----
  {
  	int hash;
! 	struct name_entry *name, *tmp_dns, *last_dns, *dnslist = NULL;
  	struct db_entry *entry;
  	struct rt_entry *best_routes = NULL;
! 	struct rt_entry *route, *tmp = NULL, *last;
  	FILE* resolv;
  	int i=0;
***************
*** 714,718 ****
  				
  				/* find the nearest one */
! 				route = olsr_lookup_routing_table(&name->ip);
  				if (route==NULL) // it's possible that route is not present yet
  					continue;
--- 727,731 ----
  				
  				/* find the nearest one */
! 				route = host_lookup_routing_table(&name->ip);
  				if (route==NULL) // it's possible that route is not present yet
  					continue;
***************
*** 720,724 ****
  				if (best_routes == NULL || route->rt_etx < best_routes->rt_etx) {
  					olsr_printf(6, "NAME PLUGIN: best nameserver %s\n",
! 						olsr_ip_to_string(&route->rt_dst));
  					if (best_routes!=NULL)
  						olsr_printf(6, "NAME PLUGIN: better than %f (%s)\n",
--- 733,737 ----
  				if (best_routes == NULL || route->rt_etx < best_routes->rt_etx) {
  					olsr_printf(6, "NAME PLUGIN: best nameserver %s\n",
! 						olsr_ip_to_string(&name->ip));
  					if (best_routes!=NULL)
  						olsr_printf(6, "NAME PLUGIN: better than %f (%s)\n",
***************
*** 731,741 ****
--- 744,763 ----
  					tmp->next = best_routes;
  					best_routes = tmp;
+ 					tmp_dns = olsr_malloc(sizeof(struct name_entry), "write_resolv name_entry");
+ 					COPY_IP(&tmp_dns->ip, &name->ip);
+ 					tmp_dns->type = name->type;
+ 					tmp_dns->len = 0;
+ 					tmp_dns->name = NULL;
+ 					tmp_dns->next = dnslist;
+ 					dnslist = tmp_dns;
  				} else {
  					// queue in etx order
  					last = best_routes;
+ 					last_dns = dnslist;
  					while ( last->next!=NULL && i<3 ) {
  						if (last->next->rt_etx > route->rt_etx)
  							break;
  						last = last->next;
+ 						last_dns = last_dns->next;
  						i++;
  					}
***************
*** 743,749 ****
  						olsr_printf(6, "NAME PLUGIN: queue %f (%s)",
  							route->rt_etx,
! 							olsr_ip_to_string(&route->rt_dst));
  						olsr_printf(6, " after %f (%s)\n", 
! 							last->rt_etx, olsr_ip_to_string(&last->rt_dst));
  						
  						tmp = olsr_malloc(sizeof(struct rt_entry), "new rt_entry");
--- 765,771 ----
  						olsr_printf(6, "NAME PLUGIN: queue %f (%s)",
  							route->rt_etx,
! 							olsr_ip_to_string(&name->ip));
  						olsr_printf(6, " after %f (%s)\n", 
!   							last->rt_etx, olsr_ip_to_string(&last_dns->ip));
  						
  						tmp = olsr_malloc(sizeof(struct rt_entry), "new rt_entry");
***************
*** 752,755 ****
--- 774,785 ----
  						tmp->next = last->next;
  						last->next = tmp;
+ 
+ 						tmp_dns = olsr_malloc(sizeof(struct name_entry), "write_resolv name_entry");
+ 						COPY_IP(&tmp_dns->ip, &name->ip);
+ 						tmp_dns->type = name->type;
+ 						tmp_dns->len = 0;
+ 						tmp_dns->name = NULL;
+ 						tmp_dns->next = last_dns->next;
+ 						last_dns->next = tmp_dns;
  					} else {
  						olsr_printf(6, "NAME PLUGIN: don't need more than 3 nameservers\n");
***************
*** 769,777 ****
  	}
  	i=0;
! 	for (tmp=best_routes; tmp!=NULL && i<3; tmp=tmp->next) {
! 		olsr_printf(6, "NAME PLUGIN: nameserver %s\n", olsr_ip_to_string(&tmp->rt_dst));
! 		fprintf(resolv, "nameserver %s\n", olsr_ip_to_string(&tmp->rt_dst));
  		i++;
  	}
  	fclose(resolv);
  }
--- 799,811 ----
  	}
  	i=0;
! 	for (tmp_dns=dnslist; tmp_dns!=NULL && i<3; tmp_dns=tmp_dns->next) {
! 		olsr_printf(6, "NAME PLUGIN: nameserver %s\n", olsr_ip_to_string(&tmp_dns->ip));
! 		fprintf(resolv, "nameserver %s\n", olsr_ip_to_string(&tmp_dns->ip));
  		i++;
  	}
+ 	free_name_entry_list(&dnslist);
+         if(tmp != NULL) {
+             free_routing_table_list(&tmp);
+         }
  	fclose(resolv);
  }
***************
*** 797,800 ****
--- 831,851 ----
  
  /**
+  * completely free a list of rt_entries
+  */
+ static void 
+ free_routing_table_list(struct rt_entry **list) 
+ {
+ 	struct rt_entry **tmp = list;
+ 	struct rt_entry *to_delete;
+ 	while (*tmp != NULL) {
+ 		to_delete = *tmp;
+ 		*tmp = (*tmp)->next;
+ 		free( to_delete );
+ 		to_delete = NULL;
+ 	}
+ }
+ 
+ 
+ /**
   * we only allow names for IP addresses which we are
   * responsible for: 
***************
*** 806,810 ****
--- 857,863 ----
  {
  	struct hna4_entry *hna4;
+ 	struct hna6_entry *hna6;
  	struct interface *iface;
+ 	union olsr_ip_addr tmp_ip, tmp_msk;
  	
  	olsr_printf(6, "checking %s\n", olsr_ip_to_string(addr));
***************
*** 819,833 ****
  	}
  	
! 	for (hna4 = olsr_cnf->hna4_entries; hna4; hna4 = hna4->next)
! 	{
! 		olsr_printf(6, "HNA %s/%s\n", 
! 			olsr_ip_to_string(&hna4->net),
! 			olsr_ip_to_string(&hna4->netmask));
  	
! 		if ( hna4->netmask.v4 != 0 && (addr->v4 & hna4->netmask.v4) == hna4->net.v4 ) {
! 			olsr_printf(6, "MATCHED\n");
! 			return OLSR_TRUE;
  		}
  	}
  	return OLSR_FALSE;
  }
--- 872,954 ----
  	}
  	
! 	if (olsr_cnf->ip_version == AF_INET) {
! 		for (hna4 = olsr_cnf->hna4_entries; hna4; hna4 = hna4->next)
! 		{
! 			olsr_printf(6, "HNA %s/%s\n", 
! 				olsr_ip_to_string(&hna4->net),
! 				olsr_ip_to_string(&hna4->netmask));
  	
! 			if ( hna4->netmask.v4 != 0 &&
! 			    (addr->v4 & hna4->netmask.v4) == hna4->net.v4 ) {
! 				olsr_printf(6, "MATCHED\n");
! 				return OLSR_TRUE;
! 			}
! 		}
! 	} else {
! 		int i;
! 
! 		for (hna6 = olsr_cnf->hna6_entries; hna6; hna6 = hna6->next)
! 		{
! 			olsr_printf(6, "HNA %s/%d\n", 
! 				olsr_ip_to_string(&hna6->net),
! 				hna6->prefix_len);
! 			if ( hna6->prefix_len == 0 )
! 				continue;
! 			olsr_prefix_to_netmask(&tmp_msk, hna6->prefix_len);
! 			for (i = 0; i < 16; i++) {
! 				tmp_ip.v6.s6_addr[i] = addr->v6.s6_addr[i] &
! 					tmp_msk.v6.s6_addr[i];
! 			}
! 			if (COMP_IP(&tmp_ip, &hna6->net)) {
! 				olsr_printf(6, "MATCHED\n");
! 				return OLSR_TRUE;
! 			}
  		}
  	}
  	return OLSR_FALSE;
  }
+ 
+ static struct rt_entry *
+ host_lookup_routing_table(union olsr_ip_addr *dst)
+ {
+ 	olsr_u32_t index;
+ 	union olsr_ip_addr tmp_ip, tmp_msk;
+ 	struct rt_entry *walker;
+   
+ 	walker = olsr_lookup_routing_table(dst);
+ 	if (walker != NULL)
+ 		return walker;
+ 
+ 	for (index = 0; index < HASHSIZE; index++) {
+ 		for (walker = hna_routes[index].next;
+ 		    walker != &hna_routes[index]; walker = walker->next) {
+ 			if (COMP_IP(&walker->rt_dst, dst))
+ 				return walker;
+ 			if (olsr_cnf->ip_version == AF_INET) {
+ 				if ( walker->rt_mask.v4 != 0 &&
+ 				    (dst->v4 & walker->rt_mask.v4) ==
+ 				    walker->rt_dst.v4 ) {
+ 					olsr_printf(6, "MATCHED\n");
+ 					return walker;
+ 				}
+ 			} else {
+ 				int i;
+ 
+ 				if ( walker->rt_mask.v6 == 0 )
+ 					continue;
+ 				olsr_prefix_to_netmask(&tmp_msk,
+ 				    walker->rt_mask.v6);
+ 				for (i = 0; i < 16; i++) {
+ 					tmp_ip.v6.s6_addr[i] =
+ 					    dst->v6.s6_addr[i] &
+ 					    tmp_msk.v6.s6_addr[i];
+ 				}
+ 				if (COMP_IP(&tmp_ip, &walker->rt_dst)) {
+ 					olsr_printf(6, "MATCHED\n");
+ 					return walker;
+ 				}
+ 			}
+ 		}
+ 	}
+         return NULL;
+ }





More information about the Olsr-cvs mailing list