* const-ify parameters
authorBernd Petrovitsch <bernd@firmix.at>
Thu, 2 Aug 2007 21:57:06 +0000 (21:57 +0000)
committerBernd Petrovitsch <bernd@firmix.at>
Thu, 2 Aug 2007 21:57:06 +0000 (21:57 +0000)
* pave the way to add -Wshadow

src/neighbor_table.c
src/neighbor_table.h
src/routing_table.c
src/routing_table.h

index f2e4a06..085731e 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: neighbor_table.c,v 1.32 2007/04/25 22:08:09 bernd67 Exp $
+ * $Id: neighbor_table.c,v 1.33 2007/08/02 21:57:06 bernd67 Exp $
  */
 
 
@@ -89,8 +89,7 @@ olsr_delete_neighbor_2_pointer(struct neighbor_entry *neighbor, union olsr_ip_ad
   entry = neighbor->neighbor_2_list.next;
 
   while(entry != &neighbor->neighbor_2_list)
-    {
-      
+    {      
       if(COMP_IP(&entry->neighbor_2->neighbor_2_addr, address))
        {
          /* Dequeue */
@@ -117,9 +116,8 @@ olsr_delete_neighbor_2_pointer(struct neighbor_entry *neighbor, union olsr_ip_ad
  *representing the two hop neighbor if found. NULL if not found.
  */
 struct neighbor_2_list_entry *
-olsr_lookup_my_neighbors(struct neighbor_entry *neighbor, union olsr_ip_addr *neighbor_main_address)
+olsr_lookup_my_neighbors(const struct neighbor_entry *neighbor, const union olsr_ip_addr *neighbor_main_address)
 {
-  
   struct neighbor_2_list_entry *entry;
   
   for(entry = neighbor->neighbor_2_list.next;
@@ -147,7 +145,7 @@ olsr_lookup_my_neighbors(struct neighbor_entry *neighbor, union olsr_ip_addr *ne
  */
 
 int
-olsr_delete_neighbor_table(union olsr_ip_addr *neighbor_addr)
+olsr_delete_neighbor_table(const union olsr_ip_addr *neighbor_addr)
 {  
   struct  neighbor_2_list_entry *two_hop_list, *two_hop_to_delete;
   olsr_u32_t                    hash;
@@ -178,9 +176,7 @@ olsr_delete_neighbor_table(union olsr_ip_addr *neighbor_addr)
 
   while(two_hop_list != &entry->neighbor_2_list)
     {
-      struct  neighbor_2_entry *two_hop_entry;
-
-      two_hop_entry = two_hop_list->neighbor_2;
+      struct neighbor_2_entry *two_hop_entry = two_hop_list->neighbor_2;
       
       two_hop_entry->neighbor_2_pointer--;
 
@@ -223,7 +219,7 @@ olsr_delete_neighbor_table(union olsr_ip_addr *neighbor_addr)
  *@return 0 if neighbor already exists 1 if inserted
  */
 struct neighbor_entry *
-olsr_insert_neighbor_table(union olsr_ip_addr *main_addr)
+olsr_insert_neighbor_table(const union olsr_ip_addr *main_addr)
 {
   olsr_u32_t             hash;
   struct neighbor_entry  *new_neigh;
@@ -273,35 +269,15 @@ olsr_insert_neighbor_table(union olsr_ip_addr *main_addr)
  *address. NULL if not found.
  */
 struct neighbor_entry *
-olsr_lookup_neighbor_table(union olsr_ip_addr *dst)
+olsr_lookup_neighbor_table(const union olsr_ip_addr *dst)
 {
-  struct neighbor_entry  *entry;
-  olsr_u32_t             hash;
-  union olsr_ip_addr     *tmp_ip;
-
   /*
    *Find main address of node
    */
-  if((tmp_ip = mid_lookup_main_addr(dst)) != NULL)
+  union olsr_ip_addr *tmp_ip = mid_lookup_main_addr(dst);
+  if(tmp_ip != NULL)
     dst = tmp_ip;
-  
-  hash = olsr_hashing(dst);
-
-  
-  //printf("\nLookup %s\n", olsr_ip_to_string(dst));
-  for(entry = neighbortable[hash].next;
-      entry != &neighbortable[hash];
-      entry = entry->next)
-    {
-      //printf("Checking %s\n", olsr_ip_to_string(&neighbor_table_tmp->neighbor_main_addr));
-      if(COMP_IP(&entry->neighbor_main_addr, dst))
-       return entry;
-      
-    }
-  //printf("NOPE\n\n");
-
-  return NULL;
-
+  return olsr_lookup_neighbor_table_alias(dst);
 }
 
 
@@ -314,13 +290,10 @@ olsr_lookup_neighbor_table(union olsr_ip_addr *dst)
  *address. NULL if not found.
  */
 struct neighbor_entry *
-olsr_lookup_neighbor_table_alias(union olsr_ip_addr *dst)
+olsr_lookup_neighbor_table_alias(const union olsr_ip_addr *dst)
 {
   struct neighbor_entry  *entry;
-  olsr_u32_t             hash;
-  
-  hash = olsr_hashing(dst);
-
+  olsr_u32_t             hash = olsr_hashing(dst);
   
   //printf("\nLookup %s\n", olsr_ip_to_string(dst));
   for(entry = neighbortable[hash].next;
@@ -341,13 +314,13 @@ olsr_lookup_neighbor_table_alias(union olsr_ip_addr *dst)
 
 
 int
-update_neighbor_status(struct neighbor_entry *entry, int link)
+update_neighbor_status(struct neighbor_entry *entry, int lnk)
 {
   /*
    * Update neighbor entry
    */
  
-  if(link == SYM_LINK)
+  if(lnk == SYM_LINK)
     {
       /* N_status is set to SYM */
       if(entry->status == NOT_SYM)
@@ -397,9 +370,7 @@ update_neighbor_status(struct neighbor_entry *entry, int link)
 void
 olsr_time_out_two_hop_neighbors(struct neighbor_entry  *neighbor)
 {
-  struct neighbor_2_list_entry *two_hop_list;
-
-  two_hop_list = neighbor->neighbor_2_list.next;
+  struct neighbor_2_list_entry *two_hop_list = neighbor->neighbor_2_list.next;
 
   while(two_hop_list != &neighbor->neighbor_2_list)
     {
@@ -414,7 +385,7 @@ olsr_time_out_two_hop_neighbors(struct neighbor_entry  *neighbor)
          if(two_hop_entry->neighbor_2_pointer < 1)
            {
              DEQUEUE_ELEM(two_hop_entry);
-             free((void *)two_hop_entry);
+             free(two_hop_entry);
            }
          
          two_hop_to_delete = two_hop_list;
@@ -439,12 +410,12 @@ olsr_time_out_two_hop_neighbors(struct neighbor_entry  *neighbor)
 void
 olsr_time_out_neighborhood_tables(void)
 {
-  olsr_u8_t index;
+  int idx;
   
-  for(index=0;index<HASHSIZE;index++)
+  for(idx=0;idx<HASHSIZE;idx++)
     {
       struct neighbor_entry *entry;
-      for(entry = neighbortable[index].next; entry != &neighbortable[index]; entry = entry->next)
+      for(entry = neighbortable[idx].next; entry != &neighbortable[idx]; entry = entry->next)
        {         
          olsr_time_out_two_hop_neighbors(entry);
        }
@@ -485,11 +456,11 @@ olsr_print_neighbor_table(void)
       struct neighbor_entry *neigh;
       for(neigh = neighbortable[i].next; neigh != &neighbortable[i]; neigh = neigh->next)
        {
-         struct link_entry *link = get_best_link_to_neighbor(&neigh->neighbor_main_addr);
-         if(link)
+         struct link_entry *lnk = get_best_link_to_neighbor(&neigh->neighbor_main_addr);
+         if(lnk)
             {
-              double best_lq = link->neigh_link_quality;
-              double inv_best_lq = link->loss_link_quality;
+              const double best_lq = lnk->neigh_link_quality;
+              const double inv_best_lq = lnk->loss_link_quality;
 
               OLSR_PRINTF(1, fstr, olsr_ip_to_string(&neigh->neighbor_main_addr),
                           inv_best_lq, best_lq,
@@ -501,13 +472,3 @@ olsr_print_neighbor_table(void)
         }
     }
 }
-
-
-
-
-
-
-
-
-
-
index c6d1165..3a1983c 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: neighbor_table.h,v 1.14 2005/05/29 12:47:45 br1 Exp $
+ * $Id: neighbor_table.h,v 1.15 2007/08/02 21:57:06 bernd67 Exp $
  */
 
 
@@ -86,19 +86,19 @@ int
 olsr_delete_neighbor_2_pointer(struct neighbor_entry *, union olsr_ip_addr *);
 
 struct neighbor_2_list_entry *
-olsr_lookup_my_neighbors(struct neighbor_entry *, union olsr_ip_addr *);
+olsr_lookup_my_neighbors(const struct neighbor_entry *, const union olsr_ip_addr *);
 
 int
-olsr_delete_neighbor_table(union olsr_ip_addr *);
+olsr_delete_neighbor_table(const union olsr_ip_addr *);
 
 struct neighbor_entry *
-olsr_insert_neighbor_table(union olsr_ip_addr *);
+olsr_insert_neighbor_table(const union olsr_ip_addr *);
 
 struct neighbor_entry *
-olsr_lookup_neighbor_table(union olsr_ip_addr *);
+olsr_lookup_neighbor_table(const union olsr_ip_addr *);
 
 struct neighbor_entry *
-olsr_lookup_neighbor_table_alias(union olsr_ip_addr *);
+olsr_lookup_neighbor_table_alias(const union olsr_ip_addr *);
 
 void
 olsr_time_out_two_hop_neighbors(struct neighbor_entry  *);
index b8aeb93..84d4316 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: routing_table.c,v 1.27 2007/04/25 22:08:14 bernd67 Exp $
+ * $Id: routing_table.c,v 1.28 2007/08/02 21:54:54 bernd67 Exp $
  */
 
 
@@ -85,7 +85,7 @@ two_hop_neighbor_reachable(struct neighbor_2_list_entry *);
 int
 olsr_init_routing_table(void)
 {
-  int index;
+  int idx;
   /*
    *The hna routes hash will almost always
    *be indexed to 0
@@ -93,12 +93,12 @@ olsr_init_routing_table(void)
    *with the functions used on the regular
    *routing table
    */
-  for(index=0;index<HASHSIZE;index++)
+  for(idx=0;idx<HASHSIZE;idx++)
     {
-      routingtable[index].next = &routingtable[index];
-      routingtable[index].prev = &routingtable[index];
-      hna_routes[index].next = &hna_routes[index];
-      hna_routes[index].prev = &hna_routes[index];
+      routingtable[idx].next = &routingtable[idx];
+      routingtable[idx].prev = &routingtable[idx];
+      hna_routes[idx].next = &hna_routes[idx];
+      hna_routes[idx].prev = &hna_routes[idx];
     }
   return 1;
 }
@@ -164,13 +164,13 @@ olsr_lookup_hna_routing_table(union olsr_ip_addr *dst)
 void
 olsr_free_routing_table(struct rt_entry *table)
 {
-  olsr_u8_t       index;
+  int idx;
   
-  for(index=0;index<HASHSIZE;index++)
+  for(idx=0;idx<HASHSIZE;idx++)
     {
-      struct rt_entry *destination = table[index].next;
+      struct rt_entry *destination = table[idx].next;
 
-      while(destination != &table[index])
+      while(destination != &table[idx])
        {
          struct rt_entry *dst_to_delete = destination;
          destination = destination->next;
@@ -192,18 +192,14 @@ olsr_free_routing_table(struct rt_entry *table)
  */
 struct rt_entry *
 olsr_insert_routing_table(union olsr_ip_addr *dst, 
-                         union olsr_ip_addr *router, 
+                         const union olsr_ip_addr *router, 
                          struct interface *iface, 
                          int metric,
                          float etx)
 {
-  struct rt_entry *new_route_entry, *rt_list;
-  olsr_u32_t       hash;
-
-  hash = olsr_hashing(dst);
-  rt_list = &routingtable[hash];
-
-  new_route_entry = olsr_malloc(sizeof(struct rt_entry), "Insert routing table");
+  const olsr_u32_t hash = olsr_hashing(dst);
+  struct rt_entry *rt_list = &routingtable[hash];
+  struct rt_entry *new_route_entry = olsr_malloc(sizeof(struct rt_entry), "Insert routing table");
 
   COPY_IP(&new_route_entry->rt_dst, dst);
   COPY_IP(&new_route_entry->rt_router, router);
@@ -249,17 +245,17 @@ olsr_insert_routing_table(union olsr_ip_addr *dst,
 static int
 olsr_fill_routing_table_with_neighbors(void)
 {
-  int index;
+  int idx;
 
 #ifdef DEBUG
   OLSR_PRINTF(7, "FILL ROUTING TABLE WITH NEIGHBORS\n");
 #endif
 
-  for(index=0;index<HASHSIZE;index++)
+  for(idx=0;idx<HASHSIZE;idx++)
     {
       struct neighbor_entry *neighbor;
-      for(neighbor = neighbortable[index].next;
-         neighbor != &neighbortable[index];
+      for(neighbor = neighbortable[idx].next;
+         neighbor != &neighbortable[idx];
          neighbor=neighbor->next)     
        {
          if(neighbor->status == SYM)
@@ -276,18 +272,18 @@ olsr_fill_routing_table_with_neighbors(void)
 
              for(addrs2 = &addrs;addrs2!=NULL;addrs2 = addrs2->next_alias)
                {
-                 struct link_entry *link = get_best_link_to_neighbor(&addrs2->alias);
+                 const struct link_entry *lnk = get_best_link_to_neighbor(&addrs2->alias);
 #ifdef DEBUG
                  OLSR_PRINTF(7, "(ROUTE)Adding neighbor %s\n", olsr_ip_to_string(&addrs.alias));
 #endif
-                 if(link)
+                 if(lnk)
                    {
-                     struct interface *iface = link->if_name ? if_ifwithname(link->if_name) :
-                                               if_ifwithaddr(&link->local_iface_addr);
+                     struct interface *iface = lnk->if_name ? if_ifwithname(lnk->if_name) :
+                                               if_ifwithaddr(&lnk->local_iface_addr);
                      if(iface)
                        {
                          olsr_insert_routing_table(&addrs2->alias, 
-                                                   &link->neighbor_iface_addr,
+                                                   &lnk->neighbor_iface_addr,
                                                    iface,
                                                    1,
                                                    -1.0);
@@ -336,16 +332,16 @@ static struct destination_n *
 olsr_fill_routing_table_with_two_hop_neighbors(void)
 {
   struct destination_n *list_destination_n=NULL;
-  int            index;
+  int            idx;
 
   //printf("FILL ROUTING TABLE WITH TWO HOP NEIGHBORS\n");
 
-  for(index=0;index<HASHSIZE;index++)
+  for(idx=0;idx<HASHSIZE;idx++)
     {
       struct neighbor_entry *neighbor;
 
-      for(neighbor = neighbortable[index].next;
-         neighbor != &neighbortable[index];
+      for(neighbor = neighbortable[idx].next;
+         neighbor != &neighbortable[idx];
          neighbor=neighbor->next)     
        {
          struct neighbor_2_list_entry *neigh_2_list; 
@@ -386,19 +382,19 @@ olsr_fill_routing_table_with_two_hop_neighbors(void)
 
              for(addrsp = &addrs; addrsp; addrsp = addrsp->next_alias)
                {
-                 struct link_entry *link = get_best_link_to_neighbor(&neighbor->neighbor_main_addr);
+                 const struct link_entry * const lnk = get_best_link_to_neighbor(&neighbor->neighbor_main_addr);
 #ifdef DEBUG
                  OLSR_PRINTF(7, "(ROUTE)Adding neighbor %s\n", olsr_ip_to_string(&addrsp->alias));
 #endif
-                 if(link)
+                 if(lnk)
                    {
-                      struct interface *iface = link->if_name ? if_ifwithname(link->if_name) :
-                                               if_ifwithaddr(&link->local_iface_addr);
+                      struct interface *iface = lnk->if_name ? if_ifwithname(lnk->if_name) :
+                                               if_ifwithaddr(&lnk->local_iface_addr);
                      if(iface)
                        {
                          struct rt_entry *new_route_entry = 
                            olsr_insert_routing_table(&addrsp->alias, 
-                                                     &link->neighbor_iface_addr,
+                                                     &lnk->neighbor_iface_addr,
                                                      iface,
                                                      2,
                                                      -1.0);
@@ -550,14 +546,14 @@ olsr_calculate_routing_table(void)
 static struct rt_entry *
 olsr_check_for_higher_quality(struct rt_entry *routes, struct hna_net *net, float etx)
 {
-  int index;
+  int idx;
 
-  for(index=0;index<HASHSIZE;index++)
+  for(idx=0;idx<HASHSIZE;idx++)
     {
       struct rt_entry *tmp_routes;
       /* All entries */
-      for(tmp_routes = routes[index].next;
-         tmp_routes != &routes[index];
+      for(tmp_routes = routes[idx].next;
+         tmp_routes != &routes[idx];
          tmp_routes = tmp_routes->next)
        {
          if(COMP_IP(&tmp_routes->rt_dst, &net->A_network_addr) &&
@@ -590,14 +586,14 @@ olsr_check_for_higher_quality(struct rt_entry *routes, struct hna_net *net, floa
 struct rt_entry *
 olsr_check_for_lower_quality(struct rt_entry *routes, struct hna_net *net, float etx)
 {
-  int index;
+  int idx;
 
-  for(index=0;index<HASHSIZE;index++)
+  for(idx=0;idx<HASHSIZE;idx++)
     {
       struct rt_entry *tmp_routes;
       /* All entries */
-      for(tmp_routes = routes[index].next;
-         tmp_routes != &routes[index];
+      for(tmp_routes = routes[idx].next;
+         tmp_routes != &routes[idx];
          tmp_routes = tmp_routes->next)
        {
          if(COMP_IP(&tmp_routes->rt_dst, &net->A_network_addr) &&
@@ -627,7 +623,7 @@ olsr_check_for_lower_quality(struct rt_entry *routes, struct hna_net *net, float
 void
 olsr_calculate_hna_routes(void)
 {
-  int index;
+  int idx;
 
 #ifdef DEBUG
   OLSR_PRINTF(3, "Calculating HNA routes\n");
@@ -635,12 +631,12 @@ olsr_calculate_hna_routes(void)
 
   olsr_move_route_table(hna_routes, old_hna);
 
-  for(index=0;index<HASHSIZE;index++)
+  for(idx=0;idx<HASHSIZE;idx++)
     {
       struct hna_entry *tmp_hna;
       /* All entries */
-      for(tmp_hna = hna_set[index].next;
-         tmp_hna != &hna_set[index];
+      for(tmp_hna = hna_set[idx].next;
+         tmp_hna != &hna_set[idx];
          tmp_hna = tmp_hna->next)
        {
          struct hna_net *tmp_net;
@@ -735,15 +731,15 @@ olsr_calculate_hna_routes(void)
 void
 olsr_print_routing_table(struct rt_entry *table)
 {
-  int index;
+  int idx;
 
   printf("ROUTING TABLE\n");
   printf("DESTINATION\tNEXT HOP\tHOPCNT\tINTERFACE\n");
-  for(index = 0; index < HASHSIZE; index++)
+  for(idx = 0; idx < HASHSIZE; idx++)
     {
       struct rt_entry *destination;
-      for(destination = table[index].next;
-         destination != &table[index];
+      for(destination = table[idx].next;
+         destination != &table[idx];
          destination = destination->next)
        {
          printf("%s\t", olsr_ip_to_string(&destination->rt_dst));
index 26a43f1..2a26569 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: routing_table.h,v 1.17 2005/11/16 23:55:54 tlopatic Exp $
+ * $Id: routing_table.h,v 1.18 2007/08/02 21:54:54 bernd67 Exp $
  */
 
 #ifndef _OLSR_ROUTING_TABLE
@@ -107,7 +107,7 @@ void
 olsr_print_routing_table(struct rt_entry *);
 
 struct rt_entry *
-olsr_insert_routing_table(union olsr_ip_addr *, union olsr_ip_addr *, struct interface *, int, float);
+olsr_insert_routing_table(union olsr_ip_addr *, const union olsr_ip_addr *, struct interface *, int, float);
 
 struct rt_entry *
 olsr_lookup_routing_table(union olsr_ip_addr *);