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

Bernd Petrovitsch (spam-protected)
Thu May 17 22:30:12 CEST 2007


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

Modified Files:
	kernel_routes.c 
Log Message:
* avoid lots of superflous malloc() and free()

Index: kernel_routes.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/linux/kernel_routes.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** kernel_routes.c	25 Apr 2007 22:08:17 -0000	1.22
--- kernel_routes.c	17 May 2007 20:30:09 -0000	1.23
***************
*** 66,77 ****
    struct rtentry kernel_route;
    int tmp;
!   char dst_str[16], mask_str[16], router_str[16];
! 
!   inet_ntop(AF_INET, &destination->rt_dst.v4, dst_str, 16);
!   inet_ntop(AF_INET, &destination->rt_mask.v4, mask_str, 16);
!   inet_ntop(AF_INET, &destination->rt_router.v4, router_str, 16);
  
    OLSR_PRINTF(1, "(ioctl)Adding route with metric %d to %s/%s via %s/%s.\n",
!               destination->rt_metric, dst_str, mask_str, router_str,
                destination->rt_if->int_name);
    
--- 66,76 ----
    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);
    
***************
*** 105,116 ****
     * Set interface
     */
!   if((kernel_route.rt_dev = malloc(strlen(destination->rt_if->int_name) + 1)) == 0)
!     {
!       fprintf(stderr, "Out of memory!\n%s\n", strerror(errno));
!       olsr_exit(__func__, EXIT_FAILURE);
!     }
! 
!   strcpy(kernel_route.rt_dev, destination->rt_if->int_name);
! 
    
    //printf("Inserting route entry on device %s\n\n", kernel_route.rt_dev);
--- 104,108 ----
     * Set interface
     */
!   kernel_route.rt_dev = destination->rt_if->int_name;
    
    //printf("Inserting route entry on device %s\n\n", kernel_route.rt_dev);
***************
*** 141,151 ****
        }
    
-   
-   if (ifnet && kernel_route.rt_dev)
-     {
-       free(kernel_route.rt_dev);
-     }
-   
-   
    return tmp;
  }
--- 133,136 ----
***************
*** 235,246 ****
    struct rtentry kernel_route;
    int tmp;
!   char dst_str[16], mask_str[16], router_str[16];
! 
!   inet_ntop(AF_INET, &destination->rt_dst.v4, dst_str, 16);
!   inet_ntop(AF_INET, &destination->rt_mask.v4, mask_str, 16);
!   inet_ntop(AF_INET, &destination->rt_router.v4, router_str, 16);
  
    OLSR_PRINTF(1, "(ioctl)Deleting route with metric %d to %s/%s via %s.\n",
!               destination->rt_metric, dst_str, mask_str, router_str);
    
    memset(&kernel_route,0,sizeof(struct rtentry));
--- 220,230 ----
    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));
***************
*** 375,379 ****
    ifr = ifc.ifc_req;
    cplim = buf + ifc.ifc_len; /*skip over if's with big ifr_addr's */
!   for (cp = buf; cp < cplim;cp += sizeof (ifr->ifr_name) + sizeof(ifr->ifr_addr)) 
      {
        struct rtentry kernel_route;
--- 359,363 ----
    ifr = ifc.ifc_req;
    cplim = buf + ifc.ifc_len; /*skip over if's with big ifr_addr's */
!   for (cp = buf; cp < cplim; cp += sizeof (ifr->ifr_name) + sizeof(ifr->ifr_addr)) 
      {
        struct rtentry kernel_route;
***************
*** 407,417 ****
  	   
  	   
!       if((kernel_route.rt_dev = malloc(6)) == 0)
! 	{
! 	  fprintf(stderr, "Out of memory!\n%s\n", strerror(errno));
! 	  olsr_exit(__func__, EXIT_FAILURE);
! 	}
! 	   
!       strncpy(kernel_route.rt_dev, ifr->ifr_ifrn.ifrn_name, 6);
  
    
--- 391,395 ----
  	   
  	   
!       kernel_route.rt_dev = ifr->ifr_ifrn.ifrn_name;
  
    
***************
*** 422,433 ****
        else
           OLSR_PRINTF(1, "YES\n");
! 
! 
!       free(kernel_route.rt_dev);
!       
!     }
!   
    close(s);
-   
    return 0;
         
--- 400,405 ----
        else
           OLSR_PRINTF(1, "YES\n");
!     }  
    close(s);
    return 0;
         





More information about the Olsr-cvs mailing list