[Olsr-cvs] olsrd-current/src/linux kernel_routes.c,1.23,1.24

Bernd Petrovitsch (spam-protected)
Wed Sep 5 18:11:13 CEST 2007


Update of /cvsroot/olsrd/olsrd-current/src/linux
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv18959/src/linux

Modified Files:
	kernel_routes.c 
Log Message:
* applied rt-refactoring-6.diff from Hannes Gredler <(spam-protected)>

Index: kernel_routes.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/linux/kernel_routes.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** kernel_routes.c	17 May 2007 20:30:09 -0000	1.23
--- kernel_routes.c	5 Sep 2007 16:11:11 -0000	1.24
***************
*** 51,78 ****
  
  
- 
- static struct sockaddr_in6 null_addr6; /* Address used as Originator Address IPv6 */
- 
  /**
!  *Insert a route in the kernel routing table
   *
!  *@param destination the route to add
   *
!  *@return negative on error
   */
  int
! olsr_ioctl_add_route(struct rt_entry *destination)
  {
    struct rtentry kernel_route;
!   int tmp;
!   char dst_str[INET_ADDRSTRLEN], mask_str[INET_ADDRSTRLEN], router_str[INET_ADDRSTRLEN];
  
-   OLSR_PRINTF(1, "(ioctl)Adding route with metric %d to %s/%s via %s/%s.\n",
-               destination->rt_metric,
-               inet_ntop(AF_INET, &destination->rt_dst.v4, dst_str, sizeof(dst_str)),
-               inet_ntop(AF_INET, &destination->rt_mask.v4, mask_str, sizeof(mask_str)),
-               inet_ntop(AF_INET, &destination->rt_router.v4, router_str, sizeof(router_str)),
-               destination->rt_if->int_name);
-   
    memset(&kernel_route, 0, sizeof(struct rtentry));
  
--- 51,70 ----
  
  
  /**
!  * Insert a route in the kernel routing table
   *
!  * @param destination the route to add
   *
!  * @return negative on error
   */
  int
! olsr_ioctl_add_route(struct rt_entry *rt)
  {
    struct rtentry kernel_route;
!   union olsr_ip_addr mask;
!   int rslt;
! 
!   OLSR_PRINTF(2, "KERN: Adding %s\n", olsr_rtp_to_string(rt->rt_best));
  
    memset(&kernel_route, 0, sizeof(struct rtentry));
  
***************
*** 81,140 ****
    ((struct sockaddr_in*)&kernel_route.rt_genmask)->sin_family = AF_INET;
  
!   ((struct sockaddr_in *)&kernel_route.rt_dst)->sin_addr.s_addr = destination->rt_dst.v4;
!   ((struct sockaddr_in *)&kernel_route.rt_genmask)->sin_addr.s_addr = destination->rt_mask.v4;
  
!   if(destination->rt_dst.v4 != destination->rt_router.v4)
!     {
!       ((struct sockaddr_in *)&kernel_route.rt_gateway)->sin_addr.s_addr=destination->rt_router.v4;
!     }
  
!   kernel_route.rt_flags = destination->rt_flags;
!   
!   kernel_route.rt_metric = destination->rt_metric + 1;
  
!   if((olsr_cnf->del_gws) &&
!      (destination->rt_dst.v4 == INADDR_ANY) &&
!      (destination->rt_dst.v4 == INADDR_ANY))
!     {
!       delete_all_inet_gws();
!       olsr_cnf->del_gws = OLSR_FALSE;
!     }
  
    /*
     * Set interface
     */
!   kernel_route.rt_dev = destination->rt_if->int_name;
!   
!   //printf("Inserting route entry on device %s\n\n", kernel_route.rt_dev);
!   
!   /*
!   printf("Adding route:\n\tdest: %s\n", olsr_ip_to_string(&destination->rt_dst));    
!   printf("\trouter: %s\n", olsr_ip_to_string(&destination->rt_router));    
!   printf("\tmask: %s\n", olsr_ip_to_string((union olsr_ip_addr *)&destination->rt_mask));    
!   printf("\tmetric: %d\n", destination->rt_metric);    
!   */
  
!   //printf("\tiface: %s\n", kernel_route.rt_dev);    
!   
!   tmp = ioctl(olsr_cnf->ioctl_s,SIOCADDRT,&kernel_route);
!   /*  kernel_route.rt_dev=*/
  
!   /*
!    *Send IPC route update message
!    */
!   
!   if(olsr_cnf->open_ipc)
!       {
! 	ipc_route_send_rtentry(&destination->rt_dst, 
! 			       &destination->rt_router, 
! 			       destination->rt_metric, 
! 			       1,
! 			       destination->rt_if->int_name); /* Send interface name */
!       }
!   
!   return tmp;
! }
  
  
  
  
--- 73,117 ----
    ((struct sockaddr_in*)&kernel_route.rt_genmask)->sin_family = AF_INET;
  
!   ((struct sockaddr_in *)&kernel_route.rt_dst)->sin_addr.s_addr =
!     rt->rt_dst.prefix.v4;
  
!   if (!olsr_prefix_to_netmask(&mask, rt->rt_dst.prefix_len)) {
!     return -1;
!   }
!   ((struct sockaddr_in *)&kernel_route.rt_genmask)->sin_addr.s_addr = mask.v4;
  
!   if (rt->rt_dst.prefix.v4 != rt->rt_best->rtp_nexthop.gateway.v4) {
!     ((struct sockaddr_in *)&kernel_route.rt_gateway)->sin_addr.s_addr =
!       rt->rt_best->rtp_nexthop.gateway.v4;
!   }
  
!   kernel_route.rt_flags = olsr_rt_flags(rt);
!   kernel_route.rt_metric = RT_METRIC_DEFAULT;
  
    /*
     * Set interface
     */
!   kernel_route.rt_dev = rt->rt_best->rtp_nexthop.iface->int_name;
  
!   /* delete existing default route before ? */
!   if((olsr_cnf->del_gws) &&
!      (rt->rt_dst.prefix.v4 == INADDR_ANY) &&
!      (rt->rt_dst.prefix_len == INADDR_ANY)) {
!     delete_all_inet_gws();
!     olsr_cnf->del_gws = OLSR_FALSE;
!   }
  
!   if ((rslt = ioctl(olsr_cnf->ioctl_s, SIOCADDRT, &kernel_route)) >= 0) {
  
+     /*
+      * Send IPC route update message
+      */
+     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);
+   }
  
+   return rslt;
+ }
  
  
***************
*** 147,209 ****
   */
  int
! olsr_ioctl_add_route6(struct rt_entry *destination)
  {
  
    struct in6_rtmsg kernel_route;
!   int tmp;
!   struct in6_addr zeroaddr;
! 
!   OLSR_PRINTF(2, "(ioctl)Adding route: %s(hopc %d)\n", 
! 	      olsr_ip_to_string(&destination->rt_dst), 
! 	      destination->rt_metric + 1);
!   
! 
!   memset(&zeroaddr, 0, olsr_cnf->ipsize); /* Use for comparision */
  
  
    memset(&kernel_route, 0, sizeof(struct in6_rtmsg));
  
!   COPY_IP(&kernel_route.rtmsg_dst, &destination->rt_dst);
! 
!   kernel_route.rtmsg_flags = destination->rt_flags;
!   kernel_route.rtmsg_metric = destination->rt_metric;
!   
!   kernel_route.rtmsg_dst_len = destination->rt_mask.v6;
! 
!   if(memcmp(&destination->rt_dst, &destination->rt_router, olsr_cnf->ipsize) != 0)
!     {
!       COPY_IP(&kernel_route.rtmsg_gateway, &destination->rt_router);
!     }
!   else
!     {
!       COPY_IP(&kernel_route.rtmsg_gateway, &destination->rt_dst);
!     }
! 
!       /*
!        * set interface
!        */
!   kernel_route.rtmsg_ifindex = destination->rt_if->if_index;
  
  
    
!   //OLSR_PRINTF(3, "Adding route to %s using gw ", olsr_ip_to_string((union olsr_ip_addr *)&kernel_route.rtmsg_dst));
!   //OLSR_PRINTF(3, "%s\n", olsr_ip_to_string((union olsr_ip_addr *)&kernel_route.rtmsg_gateway));
  
!   if((tmp = ioctl(olsr_cnf->ioctl_s, SIOCADDRT, &kernel_route)) >= 0)
!     {
!       if(olsr_cnf->open_ipc)
! 	{
! 	  if(memcmp(&destination->rt_router, &null_addr6, olsr_cnf->ipsize) != 0)
! 	    ipc_route_send_rtentry(&destination->rt_dst, 
! 				   &destination->rt_router, 
! 				   destination->rt_metric, 
! 				   1,
! 				   destination->rt_if->int_name); /* Send interface name */
  
! 	}
!     }
!     return(tmp);
! }
  
  
  
--- 124,164 ----
   */
  int
! olsr_ioctl_add_route6(struct rt_entry *rt)
  {
  
    struct in6_rtmsg kernel_route;
!   int rslt;
  
+   OLSR_PRINTF(2, "KERN: Adding %s\n", olsr_rtp_to_string(rt->rt_best));
  
    memset(&kernel_route, 0, sizeof(struct in6_rtmsg));
  
!   COPY_IP(&kernel_route.rtmsg_dst, &rt->rt_dst.prefix);
!   kernel_route.rtmsg_dst_len = rt->rt_dst.prefix_len;
  
+   COPY_IP(&kernel_route.rtmsg_gateway, &rt->rt_best->rtp_nexthop.gateway);
  
+   kernel_route.rtmsg_flags = olsr_rt_flags(rt);
+   kernel_route.rtmsg_metric = RT_METRIC_DEFAULT;
    
!   /*
!    * set interface
!    */
!   kernel_route.rtmsg_ifindex = rt->rt_best->rtp_nexthop.iface->if_index;
!   
!   /* XXX delete 0/0 route before ? */
  
!   if((rslt = ioctl(olsr_cnf->ioctl_s, SIOCADDRT, &kernel_route)) >= 0) {
  
!     /*
!      * Send IPC route update message
!      */
!     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);
!   }
  
+   return rslt;
+ }
  
  
***************
*** 216,231 ****
   */
  int
! olsr_ioctl_del_route(struct rt_entry *destination)
  {
    struct rtentry kernel_route;
!   int tmp;
!   char dst_str[INET_ADDRSTRLEN], mask_str[INET_ADDRSTRLEN], router_str[INET_ADDRSTRLEN];
  
-   OLSR_PRINTF(1, "(ioctl)Deleting route with metric %d to %s/%s via %s.\n",
-               destination->rt_metric,
-               inet_ntop(AF_INET, &destination->rt_dst.v4, dst_str, sizeof(dst_str)),
-               inet_ntop(AF_INET, &destination->rt_mask.v4, mask_str, sizeof(mask_str)),
-               inet_ntop(AF_INET, &destination->rt_router.v4, router_str, sizeof(router_str)));
-   
    memset(&kernel_route,0,sizeof(struct rtentry));
  
--- 171,182 ----
   */
  int
! olsr_ioctl_del_route(struct rt_entry *rt)
  {
    struct rtentry kernel_route;
!   union olsr_ip_addr mask;
!   int rslt;
! 
!   OLSR_PRINTF(2, "KERN: Deleting %s\n", olsr_rt_to_string(rt));
  
    memset(&kernel_route,0,sizeof(struct rtentry));
  
***************
*** 234,279 ****
    ((struct sockaddr_in*)&kernel_route.rt_genmask)->sin_family = AF_INET;
  
!   ((struct sockaddr_in *)&kernel_route.rt_dst)->sin_addr.s_addr = destination->rt_dst.v4;
!   if(destination->rt_dst.v4 != destination->rt_router.v4)
!     ((struct sockaddr_in *)&kernel_route.rt_gateway)->sin_addr.s_addr = destination->rt_router.v4;
!   ((struct sockaddr_in *)&kernel_route.rt_genmask)->sin_addr.s_addr = destination->rt_mask.v4;
  
  
!   kernel_route.rt_dev = NULL;
  
!   kernel_route.rt_flags = destination->rt_flags;
!   
!   kernel_route.rt_metric = destination->rt_metric + 1;
  
    /*
!   printf("Deleteing route:\n\tdest: %s\n", olsr_ip_to_string(&destination->rt_dst));    
!   printf("\trouter: %s\n", olsr_ip_to_string(&destination->rt_router));    
!   printf("\tmask: %s\n", olsr_ip_to_string((union olsr_ip_addr *)&destination->rt_mask));    
!   printf("\tmetric: %d\n", destination->rt_metric);    
!   //printf("\tiface: %s\n", kernel_route.rt_dev);    
!   */
! 
!   tmp = ioctl(olsr_cnf->ioctl_s, SIOCDELRT, &kernel_route);
  
  
      /*
!      *Send IPC route update message
       */
  
!   if(olsr_cnf->open_ipc)
!     ipc_route_send_rtentry(&destination->rt_dst, 
! 			   NULL, 
! 			   destination->rt_metric, 
! 			   0,
! 			   NULL); /* Send interface name */
! 
!   return tmp;
  }
  
  
- 
- 
- 
- 
  /**
   *Remove a route from the kernel
--- 185,222 ----
    ((struct sockaddr_in*)&kernel_route.rt_genmask)->sin_family = AF_INET;
  
!   ((struct sockaddr_in *)&kernel_route.rt_dst)->sin_addr.s_addr =
!     rt->rt_dst.prefix.v4;
  
+   if (rt->rt_dst.prefix.v4 != rt->rt_nexthop.gateway.v4) {
+     ((struct sockaddr_in *)&kernel_route.rt_gateway)->sin_addr.s_addr =
+       rt->rt_nexthop.gateway.v4;
+   }
  
!   if (!olsr_prefix_to_netmask(&mask, rt->rt_dst.prefix_len)) {
!     return -1;
!   } else {
!     ((struct sockaddr_in *)&kernel_route.rt_genmask)->sin_addr.s_addr = mask.v4;
!   }
  
!   kernel_route.rt_flags = olsr_rt_flags(rt);
!   kernel_route.rt_metric = RT_METRIC_DEFAULT;
  
    /*
!    * Set interface
!    */
!   kernel_route.rt_dev = NULL;
  
+   if ((rslt = ioctl(olsr_cnf->ioctl_s, SIOCDELRT, &kernel_route)) >= 0) {
  
      /*
!      * Send IPC route update message
       */
+     ipc_route_send_rtentry(&rt->rt_dst.prefix, NULL, 0, 0, NULL);
+   }
  
!   return rslt;
  }
  
  
  /**
   *Remove a route from the kernel
***************
*** 284,329 ****
   */
  int
! olsr_ioctl_del_route6(struct rt_entry *destination)
  {
  
    struct in6_rtmsg kernel_route;
!   int tmp;
! 
!   union olsr_ip_addr tmp_addr = destination->rt_dst;
! 
!   OLSR_PRINTF(2, "(ioctl)Deleting route: %s(hopc %d)\n", 
! 	      olsr_ip_to_string(&destination->rt_dst), 
! 	      destination->rt_metric);
! 
  
!   OLSR_PRINTF(1, "Deleting route: %s\n", olsr_ip_to_string(&tmp_addr));
  
    memset(&kernel_route,0,sizeof(struct in6_rtmsg));
  
-   kernel_route.rtmsg_dst_len = destination->rt_mask.v6;
  
!   memcpy(&kernel_route.rtmsg_dst, &destination->rt_dst, olsr_cnf->ipsize);
! 
!   memcpy(&kernel_route.rtmsg_gateway, &destination->rt_router, olsr_cnf->ipsize);
! 
!   kernel_route.rtmsg_flags = destination->rt_flags;
!   kernel_route.rtmsg_metric = destination->rt_metric;
  
  
!   tmp = ioctl(olsr_cnf->ioctl_s, SIOCDELRT,&kernel_route);
  
  
      /*
!      *Send IPC route update message
       */
  
!   if(olsr_cnf->open_ipc)
!     ipc_route_send_rtentry(&destination->rt_dst, 
! 			   NULL, 
! 			   destination->rt_metric, 
! 			   0,
! 			   NULL); /* Send interface name */
! 
!   return tmp;
  }
  
--- 227,258 ----
   */
  int
! olsr_ioctl_del_route6(struct rt_entry *rt)
  {
  
    struct in6_rtmsg kernel_route;
!   int rslt;
  
!   OLSR_PRINTF(2, "KERN: Deleting %s\n", olsr_rt_to_string(rt));
  
    memset(&kernel_route,0,sizeof(struct in6_rtmsg));
  
  
!   COPY_IP(&kernel_route.rtmsg_dst, &rt->rt_dst.prefix);
!   kernel_route.rtmsg_dst_len = rt->rt_dst.prefix_len;
  
+   COPY_IP(&kernel_route.rtmsg_gateway, &rt->rt_best->rtp_nexthop.gateway);
  
!   kernel_route.rtmsg_flags = olsr_rt_flags(rt);
!   kernel_route.rtmsg_metric = RT_METRIC_DEFAULT;
  
+   if ((rslt = ioctl(olsr_cnf->ioctl_s, SIOCDELRT, &kernel_route) >= 0)) {
  
      /*
!      * Send IPC route update message
       */
+     ipc_route_send_rtentry(&rt->rt_dst.prefix, NULL, 0, 0, NULL);
+   }
  
!   return rslt;
  }
  
***************
*** 384,399 ****
        ((struct sockaddr_in *)&kernel_route.rt_gateway)->sin_family=AF_INET;
        
!       //memcpy(&kernel_route.rt_gateway, gw, olsr_cnf->ipsize);
!       
! 	   
! 	   
        kernel_route.rt_flags = RTF_UP | RTF_GATEWAY;
  	   
- 	   
        kernel_route.rt_dev = ifr->ifr_ifrn.ifrn_name;
  
-   
-       //printf("Inserting route entry on device %s\n\n", kernel_route.rt_dev);
-       
        if((ioctl(s, SIOCDELRT, &kernel_route)) < 0)
           OLSR_PRINTF(1, "NO\n");
--- 313,321 ----
        ((struct sockaddr_in *)&kernel_route.rt_gateway)->sin_family=AF_INET;
        
! 
        kernel_route.rt_flags = RTF_UP | RTF_GATEWAY;
  	   
        kernel_route.rt_dev = ifr->ifr_ifrn.ifrn_name;
  
        if((ioctl(s, SIOCDELRT, &kernel_route)) < 0)
           OLSR_PRINTF(1, "NO\n");
***************
*** 405,406 ****
--- 327,334 ----
         
  }
+ 
+ /*
+  * Local Variables:
+  * c-basic-offset: 2
+  * End:
+  */





More information about the Olsr-cvs mailing list