[Olsr-cvs] olsrd-current/src/cfgparser oparse.y, 1.35, 1.36 olsrd_conf.c, 1.59, 1.60 cfgfile_gen.c, 1.9, 1.10

Bernd Petrovitsch (spam-protected)
Mon Nov 5 16:32:57 CET 2007


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

Modified Files:
	oparse.y olsrd_conf.c cfgfile_gen.c 
Log Message:
Cleanup:
* Merged "struct hna4_entry" and "struct hna6_entry" into
  "struct local_hna_entry" (as "struct hna_entry" is a different thing)
  Both have almost the same data (IP address + netmask/prefix) so we use
  the quite new "struct olsr_ip_prefix" to store it.
  Also merged the "hna4" and "hna6" pointer in "struct olsr_config" -
  look at the global "olsr_cnf->ip_version".
* const'ified here and there
* added a olsr_ip_prefix_to_string() function


Index: oparse.y
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/cfgparser/oparse.y,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -d -r1.35 -r1.36
*** oparse.y	3 Nov 2007 23:21:27 -0000	1.35
--- oparse.y	5 Nov 2007 15:32:54 -0000	1.36
***************
*** 12,16 ****
   * * Redistributions of source code must retain the above copyright 
   *   notice, this list of conditions and the following disclaimer.
!  * * Redistributions in binary form must reproduce the above copyright 
   *   notice, this list of conditions and the following disclaimer in 
   *   the documentation and/or other materials provided with the 
--- 12,16 ----
   * * Redistributions of source code must retain the above copyright 
   *   notice, this list of conditions and the following disclaimer.
!  * * Redistributions in binary form must reproduce the above copyright
   *   notice, this list of conditions and the following disclaimer in 
   *   the documentation and/or other materials provided with the 
***************
*** 24,28 ****
   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
   * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
!  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
   * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
--- 24,28 ----
   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
   * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
!  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
   * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
***************
*** 698,703 ****
  ihna4entry:     TOK_IP4_ADDR TOK_IP4_ADDR
  {
!   struct hna4_entry *h = malloc(sizeof(*h));
    struct in_addr in;
  
    PARSER_DEBUG_PRINTF("HNA IPv4 entry: %s/%s\n", $1->string, $2->string);
--- 698,704 ----
  ihna4entry:     TOK_IP4_ADDR TOK_IP4_ADDR
  {
!   struct local_hna_entry *h = malloc(sizeof(*h));
    struct in_addr in;
+   union olsr_ip_addr ip_addr;
  
    PARSER_DEBUG_PRINTF("HNA IPv4 entry: %s/%s\n", $1->string, $2->string);
***************
*** 714,728 ****
        return -1;
      }
!   h->net.v4 = in.s_addr;
    if(inet_aton($2->string, &in) == 0)
      {
!       fprintf(stderr, "ihna4entry: Failed converting IP address %s\n", $1->string);
        return -1;
      }
!   h->netmask.v4 = in.s_addr;
!   h->net.v4 &= h->netmask.v4;
    /* Queue */
!   h->next = olsr_cnf->hna4_entries;
!   olsr_cnf->hna4_entries = h;
  
    free($1->string);
--- 715,732 ----
        return -1;
      }
!   h->net.prefix.v4 = in.s_addr;
    if(inet_aton($2->string, &in) == 0)
      {
!       fprintf(stderr, "ihna4entry: Failed converting IP netmask %s\n", $2->string);
        return -1;
      }
!   ip_addr.v4 = in.s_addr;
!   h->net.prefix_len = olsr_netmask_to_prefix(&ip_addr);
!   /* Do we really want to following? */
!   h->net.prefix.v4 &= in.s_addr;
! 
    /* Queue */
!   h->next = olsr_cnf->hna_entries;
!   olsr_cnf->hna_entries = h;
  
    free($1->string);
***************
*** 736,741 ****
  ihna6entry:     TOK_IP6_ADDR TOK_INTEGER
  {
!   struct hna6_entry *h = malloc(sizeof(*h));
!   struct in6_addr in6;
  
    PARSER_DEBUG_PRINTF("HNA IPv6 entry: %s/%d\n", $1->string, $2->integer);
--- 740,744 ----
  ihna6entry:     TOK_IP6_ADDR TOK_INTEGER
  {
!   struct local_hna_entry *h = malloc(sizeof(*h));
  
    PARSER_DEBUG_PRINTF("HNA IPv6 entry: %s/%d\n", $1->string, $2->integer);
***************
*** 747,756 ****
      }
  
!   if(inet_pton(AF_INET6, $1->string, &in6) < 0)
      {
        fprintf(stderr, "ihna6entry: Failed converting IP address %s\n", $1->string);
        return -1;
      }
-   h->net.v6 = in6;
  
    if($2->integer > 128)
--- 750,758 ----
      }
  
!   if(inet_pton(AF_INET6, $1->string, &h->net.prefix.v6) < 0)
      {
        fprintf(stderr, "ihna6entry: Failed converting IP address %s\n", $1->string);
        return -1;
      }
  
    if($2->integer > 128)
***************
*** 760,767 ****
      }
  
!   h->prefix_len = $2->integer;
    /* Queue */
!   h->next = olsr_cnf->hna6_entries;
!   olsr_cnf->hna6_entries = h;
  
    free($1->string);
--- 762,770 ----
      }
  
!   h->net.prefix_len = $2->integer;
! 
    /* Queue */
!   h->next = olsr_cnf->hna_entries;
!   olsr_cnf->hna_entries = h;
  
    free($1->string);

Index: olsrd_conf.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/cfgparser/olsrd_conf.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -C2 -d -r1.59 -r1.60
*** olsrd_conf.c	3 Nov 2007 23:21:27 -0000	1.59
--- olsrd_conf.c	5 Nov 2007 15:32:54 -0000	1.60
***************
*** 361,382 ****
  olsrd_free_cnf(struct olsrd_config *cnf)
  {
!   struct hna4_entry        *h4d, *h4 = cnf->hna4_entries;
!   struct hna6_entry        *h6d, *h6 = cnf->hna6_entries;
    struct olsr_if           *ind, *in = cnf->interfaces;
    struct plugin_entry      *ped, *pe = cnf->plugins;
    struct olsr_lq_mult      *mult, *next_mult;
    
!   while(h4)
!     {
!       h4d = h4;
!       h4 = h4->next;
!       free(h4d);
!     }
! 
!   while(h6)
      {
!       h6d = h6;
!       h6 = h6->next;
!       free(h6d);
      }
  
--- 361,374 ----
  olsrd_free_cnf(struct olsrd_config *cnf)
  {
!   struct local_hna_entry   *hd,   *h = cnf->hna_entries;
    struct olsr_if           *ind, *in = cnf->interfaces;
    struct plugin_entry      *ped, *pe = cnf->plugins;
    struct olsr_lq_mult      *mult, *next_mult;
    
!   while(h)
      {
!       hd = h;
!       h = h->next;
!       free(hd);
      }
  
***************
*** 522,527 ****
  olsrd_print_cnf(struct olsrd_config *cnf)
  {
!   struct hna4_entry        *h4 = cnf->hna4_entries;
!   struct hna6_entry        *h6 = cnf->hna6_entries;
    struct olsr_if           *in = cnf->interfaces;
    struct plugin_entry      *pe = cnf->plugins;
--- 514,518 ----
  olsrd_print_cnf(struct olsrd_config *cnf)
  {
!   struct local_hna_entry   *h  = cnf->hna_entries;
    struct olsr_if           *in = cnf->interfaces;
    struct plugin_entry      *pe = cnf->plugins;
***************
*** 648,686 ****
  
    /* Hysteresis */
!   if(cnf->use_hysteresis)
!     {
!       printf("Using hysteresis:\n");
!       printf("\tScaling      : %0.2f\n", cnf->hysteresis_param.scaling);
!       printf("\tThr high/low : %0.2f/%0.2f\n", cnf->hysteresis_param.thr_high, cnf->hysteresis_param.thr_low);
!     }
!   else
      printf("Not using hysteresis\n");
  
!   /* HNA IPv4 */
!   if(h4)
!     {
! 
!       printf("HNA4 entries:\n");
!       while(h4)
! 	{
! 	  in4.s_addr = h4->net.v4;
! 	  printf("\t%s/", inet_ntoa(in4));
! 	  in4.s_addr = h4->netmask.v4;
! 	  printf("%s\n", inet_ntoa(in4));
! 
! 	  h4 = h4->next;
! 	}
!     }
! 
!   /* HNA IPv6 */
!   if(h6)
!     {
!       printf("HNA6 entries:\n");
!       while(h6)
! 	{
! 	  printf("\t%s/%d\n", (char *)inet_ntop(AF_INET6, &h6->net.v6, ipv6_buf, sizeof(ipv6_buf)), h6->prefix_len);
! 	  h6 = h6->next;
! 	}
      }
  }
  
--- 639,665 ----
  
    /* Hysteresis */
!   if(cnf->use_hysteresis) {
!     printf("Using hysteresis:\n");
!     printf("\tScaling      : %0.2f\n", cnf->hysteresis_param.scaling);
!     printf("\tThr high/low : %0.2f/%0.2f\n", cnf->hysteresis_param.thr_high, cnf->hysteresis_param.thr_low);
!   } else {
      printf("Not using hysteresis\n");
+   }
  
!   /* HNA IPv4 and IPv6 */
!   if(h) {
!     printf("HNA%d entries:\n", cnf->ip_version == AF_INET ? 4 : 6);
!     while(h) {
!       printf("\t%s/", olsr_ip_to_string(&h->net.prefix));
!       if (cnf->ip_version == AF_INET) {
!         union olsr_ip_addr ip;
!         olsr_prefix_to_netmask(&ip, h->net.prefix_len);
!         printf("%s\n", olsr_ip_to_string(&ip));
!       } else {
!         printf("%d\n", h->net.prefix_len);
!       }
!       h = h->next;
      }
+   }
  }
  

Index: cfgfile_gen.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/cfgparser/cfgfile_gen.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** cfgfile_gen.c	15 Oct 2007 21:01:17 -0000	1.9
--- cfgfile_gen.c	5 Nov 2007 15:32:54 -0000	1.10
***************
*** 49,52 ****
--- 49,53 ----
  
  #include "olsrd_conf.h"
+ #include "net_olsr.h"
  
  
***************
*** 54,59 ****
  olsrd_write_cnf(struct olsrd_config *cnf, const char *fname)
  {
!   struct hna4_entry        *h4 = cnf->hna4_entries;
!   struct hna6_entry        *h6 = cnf->hna6_entries;
    struct olsr_if           *in = cnf->interfaces;
    struct plugin_entry      *pe = cnf->plugins;
--- 55,59 ----
  olsrd_write_cnf(struct olsrd_config *cnf, const char *fname)
  {
!   struct local_hna_entry   *h  = cnf->hna_entries;
    struct olsr_if           *in = cnf->interfaces;
    struct plugin_entry      *pe = cnf->plugins;
***************
*** 84,114 ****
  
    /* IP version */
!   if(cnf->ip_version == AF_INET6)
!     fprintf(fd, "# IP version to use (4 or 6)\n\nIpVersion\t6\n\n");
!   else
!     fprintf(fd, "# IP version to use (4 or 6)\n\nIpVersion\t4\n\n");
! 
  
    /* HNA IPv4 */
!   fprintf(fd, "# HNA IPv4 routes\n# syntax: netaddr netmask\n\nHna4\n{\n");
!   while(h4)
!     {
!       in4.s_addr = h4->net.v4;
!       fprintf(fd, "    %s ", inet_ntoa(in4));
!       in4.s_addr = h4->netmask.v4;
!       fprintf(fd, "%s\n", inet_ntoa(in4));
!       h4 = h4->next;
!     }
!   fprintf(fd, "}\n\n");
! 
! 
!   /* HNA IPv6 */
!   fprintf(fd, "# HNA IPv6 routes\n# syntax: netaddr prefix\n\nHna6\n{\n");
!   while(h6)
      {
!       fprintf(fd, "    %s/%d\n", (char *)inet_ntop(AF_INET6, &h6->net.v6, ipv6_buf, sizeof(ipv6_buf)), h6->prefix_len);
!       h6 = h6->next;
      }
- 
    fprintf(fd, "}\n\n");
  
--- 84,103 ----
  
    /* IP version */
!   fprintf(fd, "# IP version to use (4 or 6)\n\nIpVersion\t%d\n\n", cnf->ip_version == AF_INET ? 4 : 6);
  
    /* HNA IPv4 */
!   fprintf(fd, "# HNA IPv%1$d routes\n# syntax: netaddr netmask\n\nHna1$d\n{\n", cnf->ip_version == AF_INET ? 4 : 6);
!   while(h)
      {
!       fprintf(fd, "    %s ", olsr_ip_to_string(&h->net.prefix));
!       if (cnf->ip_version == AF_INET) {
!           union olsr_ip_addr ip_addr;
!           olsr_prefix_to_netmask(&ip_addr, h->net.prefix_len);
!           fprintf(fd, "%s\n", olsr_ip_to_string(&ip_addr));
!       } else {
!           fprintf(fd, "%d\n", h->net.prefix_len);
!       }
!       h = h->next;
      }
    fprintf(fd, "}\n\n");
  
***************
*** 373,378 ****
  olsrd_write_cnf_buf(struct olsrd_config *cnf, char *buf, olsr_u32_t bufsize)
  {
!   struct hna4_entry        *h4 = cnf->hna4_entries;
!   struct hna6_entry        *h6 = cnf->hna6_entries;
    struct olsr_if           *in = cnf->interfaces;
    struct plugin_entry      *pe = cnf->plugins;
--- 362,366 ----
  olsrd_write_cnf_buf(struct olsrd_config *cnf, char *buf, olsr_u32_t bufsize)
  {
!   struct local_hna_entry   *h  = cnf->hna_entries;
    struct olsr_if           *in = cnf->interfaces;
    struct plugin_entry      *pe = cnf->plugins;
***************
*** 401,430 ****
  
    /* IP version */
!   if(cnf->ip_version == AF_INET6)
!       WRITE_TO_BUF("# IP version to use (4 or 6)\n\nIpVersion\t6\n\n");
!   else
!       WRITE_TO_BUF("# IP version to use (4 or 6)\n\nIpVersion\t4\n\n");
  
    /* HNA IPv4 */
!   WRITE_TO_BUF("# HNA IPv4 routes\n# syntax: netaddr netmask\n\nHna4\n{\n");
!   while(h4)
!     {
!       in4.s_addr = h4->net.v4;
!       WRITE_TO_BUF("    %s ", inet_ntoa(in4));
!       in4.s_addr = h4->netmask.v4;
!       WRITE_TO_BUF("%s\n", inet_ntoa(in4));
!       h4 = h4->next;
!     }
!   WRITE_TO_BUF("}\n\n");
! 
! 
!   /* HNA IPv6 */
!   WRITE_TO_BUF("# HNA IPv6 routes\n# syntax: netaddr prefix\n\nHna6\n{\n");
!   while(h6)
      {
!       WRITE_TO_BUF("    %s/%d\n", (char *)inet_ntop(AF_INET6, &h6->net.v6, ipv6_buf, sizeof(ipv6_buf)), h6->prefix_len);
!       h6 = h6->next;
      }
- 
    WRITE_TO_BUF("}\n\n");
  
--- 389,408 ----
  
    /* IP version */
!   WRITE_TO_BUF("# IP version to use (4 or 6)\n\nIpVersion\t%d\n\n", cnf->ip_version == AF_INET ? 4 : 6);
  
    /* HNA IPv4 */
!   WRITE_TO_BUF("# HNA IPv%1$d routes\n# syntax: netaddr netmask\n\nHna%1$d\n{\n", cnf->ip_version == AF_INET ? 4 : 6);
!   while(h)
      {
!       WRITE_TO_BUF("    %s ", olsr_ip_to_string(&h->net.prefix));
!       if (cnf->ip_version == AF_INET) {
!           union olsr_ip_addr ip_addr;
!           olsr_prefix_to_netmask(&ip_addr, h->net.prefix_len);
!           WRITE_TO_BUF("%s\n", olsr_ip_to_string(&ip_addr));
!       } else {
!           WRITE_TO_BUF("%d\n", h->net.prefix_len);
!       }
!       h = h->next;
      }
    WRITE_TO_BUF("}\n\n");
  





More information about the Olsr-cvs mailing list