* applied 102-olsrd-rt-refactoring-fixes.patch from Sven-Ola Tuecke <mail2news@comman...
authorBernd Petrovitsch <bernd@firmix.at>
Wed, 5 Sep 2007 16:17:36 +0000 (16:17 +0000)
committerBernd Petrovitsch <bernd@firmix.at>
Wed, 5 Sep 2007 16:17:36 +0000 (16:17 +0000)
14 files changed:
lib/httpinfo/src/olsrd_httpinfo.c
lib/quagga/src/quagga.c
lib/tas/src/plugin.c
lib/txtinfo/src/olsrd_txtinfo.c
src/bsd/kernel_routes.c
src/interfaces.c
src/interfaces.h
src/ipc_frontend.c
src/linux/kernel_routes.c
src/lq_route.c
src/process_routes.c
src/routing_table.c
src/routing_table.h
src/win32/kernel_routes.c

index 73af0a8..ae19fcc 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: olsrd_httpinfo.c,v 1.72 2007/09/05 16:11:10 bernd67 Exp $
+ * $Id: olsrd_httpinfo.c,v 1.73 2007/09/05 16:17:35 bernd67 Exp $
  */
 
 /*
@@ -752,7 +752,7 @@ static int build_route(char *buf, olsr_u32_t bufsize, const struct rt_entry * rt
   size += snprintf(&buf[size], bufsize-size, "<td align=\"center\">%.3f</td>",
                      rt->rt_best->rtp_metric.etx);
   size += snprintf(&buf[size], bufsize-size, "<td align=\"center\">%s</td></tr>\n",
-                   rt->rt_best->rtp_nexthop.iface->int_name);
+                   if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
   return size;
 }
 
index c5b0f58..fe09fd5 100644 (file)
@@ -743,7 +743,7 @@ int zebra_add_olsr_v4_route (struct rt_entry *r) {
     route.ind_num = 1;
     route.index = olsr_malloc (sizeof *route.index, 
                               "zebra_add_olsr_v4_route");
-    *route.index = htonl(r->rt_best->rtp_nexthop.iface->if_index);
+    *route.index = htonl(r->rt_best->rtp_nexthop.iif_index);
     route.nexthops = olsr_malloc (sizeof route.nexthops->type +
                                  sizeof route.nexthops->payload,
                                  "zebra_add_olsr_v4_route");
@@ -788,7 +788,7 @@ int zebra_del_olsr_v4_route (struct rt_entry *r) {
     route.ind_num = 1;
     route.index = olsr_malloc (sizeof *route.index, 
                               "zebra_add_olsr_v4_route");
-    *route.index = htonl (r->rt_best->rtp_nexthop.iface->if_index);
+    *route.index = htonl (r->rt_best->rtp_nexthop.iif_index);
     route.nexthops = olsr_malloc (sizeof route.nexthops->type +
                                  sizeof route.nexthops->payload,
                                  "zebra_add_olsr_v4_route");
index 2c30a14..29402cd 100644 (file)
@@ -37,7 +37,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: plugin.c,v 1.10 2007/09/05 16:11:10 bernd67 Exp $
+ * $Id: plugin.c,v 1.11 2007/09/05 16:17:35 bernd67 Exp $
  */
 
 #include <string.h>
@@ -228,7 +228,7 @@ int iterRouteTabNext(char *buff, int len)
   snprintf(buff, len, "destination~%s~gateway~%s~interface~%s~metric~%d~",
            rawIpAddrToString(&iterRouteTab->rt_dst.prefix, ipAddrLen),
            rawIpAddrToString(&iterRouteTab->rt_best->rtp_nexthop.gateway, ipAddrLen),
-           iterRouteTab->rt_best->rtp_nexthop.iface->int_name,
+           if_ifwithindex_name(iterRouteTab->rt_best->rtp_nexthop.iif_index),
            iterRouteTab->rt_best->rtp_metric.hops);
 
   rt_tree_node = avl_walk_next(&iterRouteTab->rt_tree_node);
index 6e6e667..014bf6d 100644 (file)
@@ -40,7 +40,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: olsrd_txtinfo.c,v 1.8 2007/09/05 16:11:10 bernd67 Exp $
+ * $Id: olsrd_txtinfo.c,v 1.9 2007/09/05 16:17:36 bernd67 Exp $
  */
 
 /*
@@ -327,7 +327,7 @@ static void ipc_print_routes(void)
                    olsr_ip_to_string(&rt->rt_best->rtp_nexthop.gateway),
                    rt->rt_best->rtp_metric.hops,
                    rt->rt_best->rtp_metric.etx,
-                   rt->rt_best->rtp_nexthop.iface->int_name);
+                   if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
 
     }
     ipc_sendf("\n");
index c5b9cc4..19661b6 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: kernel_routes.c,v 1.12 2007/09/05 16:11:11 bernd67 Exp $
+ * $Id: kernel_routes.c,v 1.13 2007/09/05 16:17:36 bernd67 Exp $
  */
 
 
@@ -128,12 +128,12 @@ static int add_del_route(struct rt_entry *rt, int add)
 
     for (awalker = addrs; awalker != NULL; awalker = awalker->ifa_next)
       if (awalker->ifa_addr->sa_family == AF_LINK &&
-          strcmp(awalker->ifa_name, nexthop->iface->int_name) == 0)
+          strcmp(awalker->ifa_name, if_ifwithindex_name(nexthop->iif_index)) == 0)
         break;
 
     if (awalker == NULL)
     {
-      fprintf(stderr, "interface %s not found\n", nexthop->iface->int_name);
+      fprintf(stderr, "interface %s not found\n", if_ifwithindex_name(nexthop->iif_index));
       freeifaddrs(addrs);
       return -1;
     }
@@ -231,7 +231,14 @@ static int add_del_route6(struct rt_entry *rt, int add)
 
   else
   {
-    memcpy(&sin6.sin6_addr.s6_addr, &nexthop->iface->int6_addr.sin6_addr.s6_addr,
+    // Sven-Ola: This looks really ugly (please compar to IPv4 above)
+    struct interface* iface = if_ifwithindex(nexthop->iif_index);
+    if (NULL == iface)
+    {
+      fprintf(stderr, "interface %s not found\n", if_ifwithindex_name(nexthop->iif_index));
+      return -1;
+    }
+    memcpy(&sin6.sin6_addr.s6_addr, &iface->int6_addr.sin6_addr.s6_addr,
       sizeof(struct in6_addr));
 
     memcpy(walker, &sin6, sizeof (sin6));
@@ -249,8 +256,8 @@ static int add_del_route6(struct rt_entry *rt, int add)
 
   if ((rtm->rtm_flags & RTF_GATEWAY) != 0)
   {
-    strcpy(&sdl.sdl_data[0], nexthop->iface->int_name);
-    sdl.sdl_nlen = (u_char)strlen(nexthop->iface->int_name);
+    strcpy(&sdl.sdl_data[0], if_ifwithindex_name(nexthop->iif_index));
+    sdl.sdl_nlen = (u_char)strlen((char*)&sdl.sdl_data[0]);
     memcpy(walker, &sdl, sizeof (sdl));
     walker += step_dl;
     rtm->rtm_addrs |= RTA_IFP;
index efbff9e..a77f5e8 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: interfaces.c,v 1.33 2007/08/02 21:51:40 bernd67 Exp $
+ * $Id: interfaces.c,v 1.34 2007/09/05 16:17:36 bernd67 Exp $
  */
 
 #include "defs.h"
@@ -309,6 +309,49 @@ if_ifwithname(const char *if_name)
 }
 
 
+/**
+ *Find the interface with a given interface index.
+ *
+ *@param iif_index of the interface to find.
+ *
+ *@return return the interface struct representing the interface
+ *that matched the iif_index.
+ */
+struct interface *
+if_ifwithindex(int if_index)
+{
+  struct interface *ifp = ifnet;
+  while (ifp) 
+    {
+      if (ifp->if_index == if_index)
+        return ifp;
+      ifp = ifp->int_next;
+    }
+  return NULL;
+}
+
+
+/**
+ *Get an interface name for a given interface index
+ *
+ *@param iif_index of the interface to find.
+ *
+ *@return "" or interface name.
+ */
+char *
+if_ifwithindex_name(int if_index)
+{
+  struct interface *ifp = ifnet;
+  while (ifp) 
+    {
+      if (ifp->if_index == if_index)
+        return ifp->int_name;
+      ifp = ifp->int_next;
+    }
+  return "void";
+}
+
+
 /**
  *Create a new interf_name struct using a given
  *name and insert it into the interface list.
index 95f0413..374f13d 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: interfaces.h,v 1.41 2007/08/02 21:51:40 bernd67 Exp $
+ * $Id: interfaces.h,v 1.42 2007/09/05 16:17:36 bernd67 Exp $
  */
 
 
@@ -211,6 +211,12 @@ if_ifwithaddr(const union olsr_ip_addr *);
 struct interface *
 if_ifwithname(const char *);
 
+struct interface *
+if_ifwithindex(int if_index);
+
+char *
+if_ifwithindex_name(int if_index);
+
 struct olsr_if *
 queue_if(char *, int);
 
index 1e57074..678c062 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: ipc_frontend.c,v 1.34 2007/09/05 16:11:10 bernd67 Exp $
+ * $Id: ipc_frontend.c,v 1.35 2007/09/05 16:17:36 bernd67 Exp $
  */
 
 /*
@@ -338,7 +338,6 @@ static int
 ipc_send_all_routes(int fd)
 {
   struct rt_entry  *rt;
-  struct interface *ifn;
   struct ipcmsg packet;
   char *tmp;
   
@@ -348,8 +347,6 @@ ipc_send_all_routes(int fd)
   
   OLSR_FOR_ALL_RT_ENTRIES(rt) {
 
-    ifn = rt->rt_nexthop.iface;
-         
     memset(&packet, 0, sizeof(struct ipcmsg));
     packet.size = htons(IPC_PACK_SIZE);
     packet.msgtype = ROUTE_IPC;
@@ -361,10 +358,7 @@ ipc_send_all_routes(int fd)
 
     COPY_IP(&packet.gateway_addr, &rt->rt_nexthop.gateway);
 
-    if(ifn)
-      memcpy(&packet.device[0], ifn->int_name, 4);
-    else
-      memset(&packet.device[0], 0, 4);
+    memcpy(&packet.device[0], if_ifwithindex_name(rt->rt_nexthop.iif_index), 4);
 
     tmp = (char *) &packet;
   
index 6191466..4709245 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: kernel_routes.c,v 1.24 2007/09/05 16:11:11 bernd67 Exp $
+ * $Id: kernel_routes.c,v 1.25 2007/09/05 16:17:36 bernd67 Exp $
  */
 
 
@@ -91,7 +91,7 @@ olsr_ioctl_add_route(struct rt_entry *rt)
   /*
    * Set interface
    */
-  kernel_route.rt_dev = rt->rt_best->rtp_nexthop.iface->int_name;
+  kernel_route.rt_dev = if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index);
 
   /* delete existing default route before ? */
   if((olsr_cnf->del_gws) &&
@@ -108,7 +108,7 @@ olsr_ioctl_add_route(struct rt_entry *rt)
      */
     ipc_route_send_rtentry(&rt->rt_dst.prefix, &rt->rt_best->rtp_nexthop.gateway,
                            rt->rt_best->rtp_metric.hops, 1,
-                           rt->rt_best->rtp_nexthop.iface->int_name);
+                           if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
   }
 
   return rslt;
@@ -144,7 +144,7 @@ olsr_ioctl_add_route6(struct rt_entry *rt)
   /*
    * set interface
    */
-  kernel_route.rtmsg_ifindex = rt->rt_best->rtp_nexthop.iface->if_index;
+  kernel_route.rtmsg_ifindex = rt->rt_best->rtp_nexthop.iif_index;
   
   /* XXX delete 0/0 route before ? */
 
@@ -155,7 +155,7 @@ olsr_ioctl_add_route6(struct rt_entry *rt)
      */
     ipc_route_send_rtentry(&rt->rt_dst.prefix, &rt->rt_best->rtp_nexthop.gateway, 
                            rt->rt_best->rtp_metric.hops, 1,
-                           rt->rt_best->rtp_nexthop.iface->int_name);
+                           if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
   }
 
   return rslt;
index 8e5b656..1c3fffd 100644 (file)
@@ -38,7 +38,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: lq_route.c,v 1.49 2007/09/05 16:11:10 bernd67 Exp $
+ * $Id: lq_route.c,v 1.50 2007/09/05 16:17:36 bernd67 Exp $
  */
 
 #include "defs.h"
@@ -604,7 +604,7 @@ olsr_calculate_routing_table (void)
 
       /* add a route to the main address of the destination node */
       olsr_insert_routing_table(&vert->addr, max_host_plen, &vert->addr,
-                                &link->neighbor_iface_addr, inter,
+                                &link->neighbor_iface_addr, inter->if_index,
                                 vert->hops, vert->path_etx);
 
       /* add routes to the remaining interfaces of the destination node */
@@ -613,7 +613,7 @@ olsr_calculate_routing_table (void)
            mid_walker = mid_walker->next_alias) {
 
         olsr_insert_routing_table(&mid_walker->alias, max_host_plen, &vert->addr,
-                                  &link->neighbor_iface_addr, inter,
+                                  &link->neighbor_iface_addr, inter->if_index,
                                   vert->hops, vert->path_etx);
       }
 
@@ -633,7 +633,7 @@ olsr_calculate_routing_table (void)
         plen = olsr_get_hna_prefix_len(hna);
         if (vert->path_etx != INFINITE_ETX)
         olsr_insert_routing_table(&hna->A_network_addr, plen, &vert->addr,
-                                  &link->neighbor_iface_addr, inter,
+                                  &link->neighbor_iface_addr, inter->if_index,
                                   vert->hops, vert->path_etx);
       }
     }
index 3240d85..1357a4f 100644 (file)
@@ -40,7 +40,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: process_routes.c,v 1.35 2007/09/05 16:11:11 bernd67 Exp $
+ * $Id: process_routes.c,v 1.36 2007/09/05 16:17:36 bernd67 Exp $
  */
 
 #include "defs.h"
@@ -507,9 +507,9 @@ olsr_update_kernel_routes(void)
     /* nexthop change ? */
     if (olsr_nh_change(&rt->rt_best->rtp_nexthop, &rt->rt_nexthop)) {
 
-      if (!rt->rt_nexthop.iface) {
+      if (0 > rt->rt_nexthop.iif_index) {
 
-        /* fresh routes do have NULL pointers in the nexthop fields. */
+        /* fresh routes do have an interface index of -1. */
         olsr_enqueue_rt(&add_kernel_list, rt);
       } else { 
 
index 01458ae..0b08fc0 100644 (file)
@@ -37,7 +37,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: routing_table.c,v 1.29 2007/09/05 16:11:11 bernd67 Exp $
+ * $Id: routing_table.c,v 1.30 2007/09/05 16:17:36 bernd67 Exp $
  */
 
 #include "defs.h"
@@ -188,7 +188,7 @@ olsr_lookup_routing_table(union olsr_ip_addr *dst)
  */
 static void
 olsr_update_routing_entry(struct rt_path *rtp, union olsr_ip_addr *gateway,
-                          struct interface *iface, int metric, float etx)
+                          int iif_index, int metric, float etx)
 {
 
   rtp->rtp_version = routingtree_version;
@@ -197,7 +197,7 @@ olsr_update_routing_entry(struct rt_path *rtp, union olsr_ip_addr *gateway,
   rtp->rtp_nexthop.gateway = *gateway;
 
   /* interface */
-  rtp->rtp_nexthop.iface = iface;
+  rtp->rtp_nexthop.iif_index = iif_index;
 
   /* etx */
   rtp->rtp_metric.hops = metric;
@@ -225,6 +225,9 @@ olsr_alloc_rt_entry(struct olsr_ip_prefix *prefix)
   }
 
   memset(rt, 0, sizeof(struct rt_entry));
+  
+  /* Mark this entry as fresh (see process_routes.c:512) */
+  rt->rt_nexthop.iif_index = -1;
 
   /* set key and backpointer prior to tree insertion */
   rt->rt_dst = *prefix;
@@ -279,7 +282,7 @@ olsr_bool
 olsr_nh_change(struct rt_nexthop *nh1, struct rt_nexthop *nh2)
 {
   if ((!COMP_IP(&nh1->gateway, &nh2->gateway)) ||
-      (nh1->iface != nh2->iface)) {
+      (nh1->iif_index != nh2->iif_index)) {
     return OLSR_TRUE;
   }
   return OLSR_FALSE;
@@ -400,7 +403,7 @@ olsr_insert_routing_table(union olsr_ip_addr *dst,
                           int plen,
                           union olsr_ip_addr *originator,
                          union olsr_ip_addr *gateway,
-                         struct interface *iface, 
+                         int iif_index,
                          int metric,
                          float etx)
 {
@@ -456,7 +459,7 @@ olsr_insert_routing_table(union olsr_ip_addr *dst,
   }
 
   /* update the version field and relevant parameters */
-  olsr_update_routing_entry(rtp, gateway, iface, metric, etx);
+  olsr_update_routing_entry(rtp, gateway, iif_index, metric, etx);
 
   return rtp;
 }
@@ -563,13 +566,13 @@ olsr_fill_routing_table_with_neighbors(void)
               olsr_insert_routing_table(&link->neighbor_iface_addr, max_host_plen,
                                         &link->neighbor->neighbor_main_addr,
                                         &link->neighbor_iface_addr,
-                                        iface, 1, etx);
+                                        iface->if_index, 1, etx);
 
               /* this is the nexthop route that all routes will be tracking */
               olsr_insert_routing_table(&addrs2->alias, max_host_plen,
                                         &link->neighbor->neighbor_main_addr,
                                         &link->neighbor_iface_addr,
-                                        iface, 1, etx);
+                                        iface->if_index, 1, etx);
             }
           }
         }
@@ -617,7 +620,7 @@ olsr_calculate_hna_routes(void)
         olsr_insert_routing_table(&tmp_net->A_network_addr, plen,
                                   &tmp_hna->A_gateway_addr,
                                   &rt->rt_best->rtp_nexthop.gateway,
-                                  rt->rt_best->rtp_nexthop.iface,
+                                  rt->rt_best->rtp_nexthop.iif_index,
                                   rt->rt_best->rtp_metric.hops,
                                   rt->rt_best->rtp_metric.etx);
 
@@ -668,7 +671,7 @@ olsr_print_routing_table(struct avl_tree *tree)
              rtp->rtp_metric.etx,
              rtp->rtp_metric.hops,
              olsr_ip_to_string(&rtp->rtp_nexthop.gateway),
-             rtp->rtp_nexthop.iface->int_name,
+             if_ifwithindex_name(rt->rt_nexthop.iif_index),
              rtp->rtp_version);
     
     }
index 397f7db..280304a 100644 (file)
@@ -37,7 +37,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: routing_table.h,v 1.19 2007/09/05 16:11:11 bernd67 Exp $
+ * $Id: routing_table.h,v 1.20 2007/09/05 16:17:36 bernd67 Exp $
  */
 
 #ifndef _OLSR_ROUTING_TABLE
@@ -65,12 +65,18 @@ struct rt_metric
 };
 
 /* a nexthop is a pointer to a gateway router plus an interface */
-struct rt_nexthop
+struct rt_nexthop_soll_weg
 {
   union olsr_ip_addr    gateway; /* gateway router */
   struct interface      *iface; /* outgoing interface */
 };
 
+struct rt_nexthop
+{
+  union olsr_ip_addr    gateway; /* gateway router */
+  int                   iif_index; /* outgoung interface index */
+};
+
 /*
  * Every prefix in our RIB needs a route entry that contains
  * the nexthop of the best path as installed in the kernel FIB.
@@ -168,7 +174,7 @@ struct rt_path *
 olsr_insert_routing_table(union olsr_ip_addr *, int,
                           union olsr_ip_addr *,
                           union olsr_ip_addr *,
-                          struct interface *, int, float);
+                          int, int, float);
 
 struct rt_entry *
 olsr_lookup_routing_table(union olsr_ip_addr *);
index 159be0f..3718395 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: kernel_routes.c,v 1.21 2007/09/05 16:11:11 bernd67 Exp $
+ * $Id: kernel_routes.c,v 1.22 2007/09/05 16:17:36 bernd67 Exp $
  */
 
 #include <stdio.h>
@@ -79,7 +79,7 @@ int olsr_ioctl_add_route(struct rt_entry *rt)
 
   Row.dwForwardPolicy = 0;
   Row.dwForwardNextHop = rt->rt_best->rtp_nexthop.gateway.v4;
-  Row.dwForwardIfIndex = rt->rt_best->rtp_nexthop.iface->if_index;
+  Row.dwForwardIfIndex = rt->rt_best->rtp_nexthop.iif_index;
   // MIB_IPROUTE_TYPE_DIRECT and MIB_IPROUTE_TYPE_INDIRECT
   Row.dwForwardType = (rt->rt_dst.prefix.v4 == rt->rt_best->rtp_nexthop.gateway.v4) ? 3 : 4;
   Row.dwForwardProto = 3; // MIB_IPPROTO_NETMGMT
@@ -118,7 +118,7 @@ int olsr_ioctl_add_route(struct rt_entry *rt)
   if(olsr_cnf->open_ipc) {
     ipc_route_send_rtentry(&rt->rt_dst.prefix, &rt->rt_best->rtp_nexthop.gateway,
         rt->rt_best->rtp_metric.hops, 1,
-        rt->rt_best->rtp_nexthop.iface->int_name);
+        if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_name));
   }
 
   return 0;
@@ -158,7 +158,7 @@ int olsr_ioctl_del_route(struct rt_entry *rt)
 
   Row.dwForwardPolicy = 0;
   Row.dwForwardNextHop = rt->rt_nexthop.gateway.v4;
-  Row.dwForwardIfIndex = rt->rt_nexthop.iface->if_index;
+  Row.dwForwardIfIndex = rt->rt_nexthop.iif_index;
   // MIB_IPROUTE_TYPE_DIRECT and MIB_IPROUTE_TYPE_INDIRECT
   Row.dwForwardType = (rt->rt_dst.prefix.v4 == rt->rt_nexthop.gateway.v4) ? 3 : 4;
   Row.dwForwardProto = 3; // MIB_IPPROTO_NETMGMT