[Olsr-cvs] olsrd-current/src/cfgparser cfgfile_gen.c, 1.12, 1.13 olsrd_conf.c, 1.62, 1.63 oparse.y, 1.39, 1.40 oscan.lex, 1.27, 1.28

Bernd Petrovitsch (spam-protected)
Thu Nov 29 01:49:42 CET 2007


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

Modified Files:
	cfgfile_gen.c olsrd_conf.c oparse.y oscan.lex 
Log Message:
Major Changes:
- renamed "struct local_hna_entry" to "struct ip_prefix_list" since
  it is exactly that. Renamed the functions in src/local_hna_set.{c,h}
  in the same way.
- each IPv4 and IPv6 function pairs in src/local_hna_set.{c,h} is
  called from the same place and have the same signature. So I
  condensed each of them.
- Since we have only 3 functions left in src/local_hna_set.{c,h}
  and they are used for the configuration, the .h file is now part
  of src/olsr_cfg.h and the ,c file of src/cfgparser/olsrd_conf.c.
- replaced "struct ipc_net" with "struct ip_prefix_list" since it
  serves the same purpose as the "struct ip_prefix_list"
- replaced "struct ipc_host" with "struct ip_prefix_list" since it
  serves the same purpose as the "struct ip_prefix_list" and is
  just a special case. No need to duplicate code etc.
- removed "union hna_netmask" from src/olsr_types since we use the
  prefix_len everywhere (and that is an olsr_u8_t in several other
  struct's).
  That implies changes and simplifications in the code handling
  them (since the IPv4 is similar to IPv6).
- the config file parser now understands for IPv4 addresses also
  "/$prefix".
- On the output side, the patch generates only "/$prefix" which
  kills code since it is the same as the IPv6 handling.
- There are some netmask conversions left (mainly in the plugins)
  but that be cleaned up afterwards.
- extracted ip{,4,6}{cmp,equal} and formatting functions from
  net_olsr.{c,h} into src/ipcalc.{c,h} since net_olsr.h became
  IMHO to much of a "put anything in there".
- renamed "sockaddr_to_string()" to "sockaddr4_to_string()"
  since it is exactly that (unless I'm missing something).

Minor Changes:
- lib/httpinfo/src/admin_html.h contained just some variable
  definitions so it is now integrated in the only user:
  admin_interface.c
- olsrd_dot_draw.c got rid of two indicator variables if
  a socket is valid or not. Since sockets may use "-1" as the
  "not open", "invalid" value, there is no need for two more
  ints.
- and the dot_draw plugin is somewhat smaller and easier to read.
- const'ified some functions


Index: cfgfile_gen.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/cfgparser/cfgfile_gen.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** cfgfile_gen.c	16 Nov 2007 22:56:54 -0000	1.12
--- cfgfile_gen.c	29 Nov 2007 00:49:40 -0000	1.13
***************
*** 40,43 ****
--- 40,46 ----
   */
  
+ #include "olsrd_conf.h"
+ #include "../ipcalc.h"
+ #include "../net_olsr.h"
  
  #include <stdio.h>
***************
*** 48,64 ****
  #include <arpa/inet.h>
  
- #include "olsrd_conf.h"
- #include "net_olsr.h"
- 
  
  int
  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;
    struct plugin_param      *pp;
!   struct ipc_host          *ih = cnf->ipc_hosts;
!   struct ipc_net           *ie = cnf->ipc_nets;
    struct olsr_lq_mult      *mult;
  
--- 51,63 ----
  #include <arpa/inet.h>
  
  
  int
  olsrd_write_cnf(struct olsrd_config *cnf, const char *fname)
  {
!   struct ip_prefix_list   *h  = cnf->hna_entries;
    struct olsr_if           *in = cnf->interfaces;
    struct plugin_entry      *pe = cnf->plugins;
    struct plugin_param      *pp;
!   struct ip_prefix_list    *ie = cnf->ipc_nets;
    struct olsr_lq_mult      *mult;
  
***************
*** 77,81 ****
    printf("Writing config to file \"%s\".... ", fname);
  
!   fprintf(fd, "#\n# Configuration file for olsr.org olsrd\n# automatically generated by olsrd-cnf %s\n#\n\n\n", PARSER_VERSION);
  
    /* Debug level */
--- 76,80 ----
    printf("Writing config to file \"%s\".... ", fname);
  
!   fprintf(fd, "#\n# Configuration file for s%s\n# automatically generated by olsrd-cnf parser v. %s\n#\n\n", olsrd_version, PARSER_VERSION);
  
    /* Debug level */
***************
*** 86,100 ****
  
    /* 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) {
!     struct ipaddr_str buf;
!     fprintf(fd, "    %s ", olsr_ip_to_string(&buf, &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(&buf, &ip_addr));
!     } else {
!       fprintf(fd, "%d\n", h->net.prefix_len);
!     }
      h = h->next;
    }
--- 85,92 ----
  
    /* HNA IPv4 */
!   fprintf(fd, "# HNA IPv%1$d routes\n# syntax: netaddr netmask\n\nHna1$d {\n", cnf->ip_version == AF_INET ? 4 : 6);
    while(h) {
!     struct ipaddr_str strbuf;
!     fprintf(fd, "    %s/%d", olsr_ip_to_string(&strbuf, &h->net.prefix), h->net.prefix_len);
      h = h->next;
    }
***************
*** 114,118 ****
    /* RtTable */
    fprintf(fd, "# Policy Routing Table to use. Default is 254\n\n");
!   fprintf(fd, "RtTable\t%d\n\n", cnf->rttable);
  
    /* Willingness */
--- 106,110 ----
    /* RtTable */
    fprintf(fd, "# Policy Routing Table to use. Default is 254\n\n");
!   fprintf(fd, "RtTable\t\t%d\n\n", cnf->rttable);
  
    /* Willingness */
***************
*** 121,140 ****
      fprintf(fd, "#Willingness\t4\n\n");
    else
!     fprintf(fd, "Willingness%d\n\n", cnf->willingness);
  
    /* IPC */
    fprintf(fd, "# Allow processes like the GUI front-end\n# to connect to the daemon.\n\n");
!   fprintf(fd, "IpcConnect\n{\n");
!   fprintf(fd, "   MaxConnections  %d\n", cnf->ipc_connections);
  
-   while(ih)
-     {
-       fprintf(fd, "   Host          %s\n", inet_ntoa(ih->host.v4));
-       ih = ih->next;
-     }
    while(ie)
      {
!       fprintf(fd, "   Net           %s ", inet_ntoa(ie->net.v4));
!       fprintf(fd, "%s\n", inet_ntoa(ie->mask.v4));
        ie = ie->next;
      }
--- 113,131 ----
      fprintf(fd, "#Willingness\t4\n\n");
    else
!     fprintf(fd, "Willingness\t%d\n\n", cnf->willingness);
  
    /* IPC */
    fprintf(fd, "# Allow processes like the GUI front-end\n# to connect to the daemon.\n\n");
!   fprintf(fd, "IpcConnect {\n");
!   fprintf(fd, "    MaxConnections\t%d\n", cnf->ipc_connections);
  
    while(ie)
      {
!       struct ipaddr_str strbuf;
!       if (ie->net.prefix_len == olsr_cnf->maxplen) {
!           fprintf(fd, "    Host\t\t%s\n", olsr_ip_to_string(&strbuf, &ie->net.prefix));
!       } else {
!           fprintf(fd, "    Net\t\t\t%s/%d\n", olsr_ip_to_string(&strbuf, &ie->net.prefix), ie->net.prefix_len);
!       }
        ie = ie->next;
      }
***************
*** 142,147 ****
    fprintf(fd, "}\n\n");
  
- 
- 
    /* Hysteresis */
    fprintf(fd, "# Hysteresis adds more robustness to the\n# link sensing.\n# Used by default. 'yes' or 'no'\n\n");
--- 133,136 ----
***************
*** 199,203 ****
        while(pe)
  	{
! 	  fprintf(fd, "LoadPlugin \"%s\"\n{\n", pe->name);
            pp = pe->params;
            while(pp)
--- 188,192 ----
        while(pe)
  	{
! 	  fprintf(fd, "LoadPlugin \"%s\" {\n", pe->name);
            pp = pe->params;
            while(pp)
***************
*** 222,226 ****
        while(in)
  	{
! 	  fprintf(fd, "Interface \"%s\"\n{\n", in->name);
  	  fprintf(fd, "\n");
        
--- 211,215 ----
        while(in)
  	{
! 	  fprintf(fd, "Interface \"%s\" {\n", in->name);
  	  fprintf(fd, "\n");
        
***************
*** 230,234 ****
  	  if(in->cnf->ipv4_broadcast.v4.s_addr)
  	    {
! 	      fprintf(fd, "    Ip4Broadcast\t %s\n\n", inet_ntoa(in->cnf->ipv4_broadcast.v4));
  	    }
  	  else
--- 219,223 ----
  	  if(in->cnf->ipv4_broadcast.v4.s_addr)
  	    {
! 	      fprintf(fd, "    Ip4Broadcast\t%s\n\n", inet_ntoa(in->cnf->ipv4_broadcast.v4));
  	    }
  	  else
***************
*** 357,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;
    struct plugin_param      *pp;
!   struct ipc_host          *ih = cnf->ipc_hosts;
!   struct ipc_net           *ie = cnf->ipc_nets;
    struct olsr_lq_mult      *mult;
  
--- 346,354 ----
  olsrd_write_cnf_buf(struct olsrd_config *cnf, char *buf, olsr_u32_t bufsize)
  {
!   struct ip_prefix_list   *h  = cnf->hna_entries;
    struct olsr_if           *in = cnf->interfaces;
    struct plugin_entry      *pe = cnf->plugins;
    struct plugin_param      *pp;
!   struct ip_prefix_list    *ie = cnf->ipc_nets;
    struct olsr_lq_mult      *mult;
  
***************
*** 385,389 ****
  
    /* HNA IPv4 and IPv6 */
!   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) {
      struct ipaddr_str strbuf;
--- 373,377 ----
  
    /* HNA IPv4 and IPv6 */
!   WRITE_TO_BUF("# HNA IPv%1$d routes\n# syntax: netaddr netmask\n\nHna%1$d {\n", cnf->ip_version == AF_INET ? 4 : 6);
    while(h) {
      struct ipaddr_str strbuf;
***************
*** 413,417 ****
    /* RtTable */
    WRITE_TO_BUF("# Policy Routing Tableto use. Default is 254\n\n");
!   WRITE_TO_BUF("RtTable\t%d\n\n", cnf->rttable);
  
    /* Willingness */
--- 401,405 ----
    /* RtTable */
    WRITE_TO_BUF("# Policy Routing Tableto use. Default is 254\n\n");
!   WRITE_TO_BUF("RtTable\t\t%d\n\n", cnf->rttable);
  
    /* Willingness */
***************
*** 420,439 ****
      WRITE_TO_BUF("#Willingness\t4\n\n");
    else
!     WRITE_TO_BUF("Willingness%d\n\n", cnf->willingness);
  
    /* IPC */
    WRITE_TO_BUF("# Allow processes like the GUI front-end\n# to connect to the daemon.\n\n");
!   WRITE_TO_BUF("IpcConnect\n{\n");
!   WRITE_TO_BUF("   MaxConnections  %d\n", cnf->ipc_connections);
! 
!   while(ih)
!     {
!       WRITE_TO_BUF("   Host          %s\n", inet_ntoa(ih->host.v4));
!       ih = ih->next;
!     }
    while(ie)
      {
!       WRITE_TO_BUF("   Net           %s ", inet_ntoa(ie->net.v4));
!       WRITE_TO_BUF("%s\n", inet_ntoa(ie->mask.v4));
        ie = ie->next;
      }
--- 408,425 ----
      WRITE_TO_BUF("#Willingness\t4\n\n");
    else
!     WRITE_TO_BUF("Willingness\t%d\n\n", cnf->willingness);
  
    /* IPC */
    WRITE_TO_BUF("# Allow processes like the GUI front-end\n# to connect to the daemon.\n\n");
!   WRITE_TO_BUF("IpcConnect {\n");
!   WRITE_TO_BUF("    MaxConnections\t%d\n", cnf->ipc_connections);
    while(ie)
      {
!       struct ipaddr_str strbuf;
!       if (ie->net.prefix_len == olsr_cnf->maxplen) {
!           WRITE_TO_BUF("    Host\t\t%s\n", olsr_ip_to_string(&strbuf, &ie->net.prefix));
!       } else {
!           WRITE_TO_BUF("    Net\t\t\t%s/%d\n", olsr_ip_to_string(&strbuf, &ie->net.prefix), ie->net.prefix_len);
!       }
        ie = ie->next;
      }
***************
*** 492,496 ****
        while(pe)
  	{
! 	  WRITE_TO_BUF("LoadPlugin \"%s\"\n{\n", pe->name);
            pp = pe->params;
            while(pp)
--- 478,482 ----
        while(pe)
  	{
! 	  WRITE_TO_BUF("LoadPlugin \"%s\" {\n", pe->name);
            pp = pe->params;
            while(pp)
***************
*** 517,521 ****
        while(in)
  	{
! 	  WRITE_TO_BUF("Interface \"%s\"\n{\n", in->name);
  
            if(first)
--- 503,507 ----
        while(in)
  	{
! 	  WRITE_TO_BUF("Interface \"%s\" {\n", in->name);
  
            if(first)
***************
*** 525,529 ****
  	  if(in->cnf->ipv4_broadcast.v4.s_addr)
  	    {
! 	      WRITE_TO_BUF("    Ip4Broadcast\t %s\n", inet_ntoa(in->cnf->ipv4_broadcast.v4));
  	    }
  	  else
--- 511,515 ----
  	  if(in->cnf->ipv4_broadcast.v4.s_addr)
  	    {
! 	      WRITE_TO_BUF("    Ip4Broadcast\t%s\n", inet_ntoa(in->cnf->ipv4_broadcast.v4));
  	    }
  	  else

Index: oscan.lex
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/cfgparser/oscan.lex,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** oscan.lex	10 Oct 2007 20:44:34 -0000	1.27
--- oscan.lex	29 Nov 2007 00:49:40 -0000	1.28
***************
*** 165,168 ****
--- 165,173 ----
  }
  
+ \/ {
+     yylval = NULL;
+     return TOK_SLASH;
+ }
+ 
  \{ {
      yylval = NULL;
***************
*** 200,204 ****
      return TOK_IP4_ADDR;
  }
- 
  {IPV6ADDR} {
      yylval = get_string_token(yytext, yyleng + 1);
--- 205,208 ----

Index: olsrd_conf.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/cfgparser/olsrd_conf.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -C2 -d -r1.62 -r1.63
*** olsrd_conf.c	22 Nov 2007 11:43:36 -0000	1.62
--- olsrd_conf.c	29 Nov 2007 00:49:40 -0000	1.63
***************
*** 41,44 ****
--- 41,51 ----
  
  
+ #include "olsrd_conf.h"
+ #include "ipcalc.h"
+ #include "olsr_cfg.h"
+ #include "defs.h"
+ #include "net_olsr.h"
+ #include "olsr.h"
+ 
  #include <stdio.h>
  #include <string.h>
***************
*** 50,58 ****
  #include <arpa/inet.h>
  
- #include "olsrd_conf.h"
- #include "olsr_cfg.h"
- #include "defs.h"
- #include "net_olsr.h"
- 
  
  extern FILE *yyin;
--- 57,60 ----
***************
*** 362,366 ****
  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;
--- 364,368 ----
  olsrd_free_cnf(struct olsrd_config *cnf)
  {
!   struct ip_prefix_list   *hd,   *h = cnf->hna_entries;
    struct olsr_if           *ind, *in = cnf->interfaces;
    struct plugin_entry      *ped, *pe = cnf->plugins;
***************
*** 517,525 ****
  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;
!   struct ipc_host          *ih = cnf->ipc_hosts;
!   struct ipc_net           *ie = cnf->ipc_nets;
    struct olsr_lq_mult      *mult;
    char ipv6_buf[100];             /* buffer for IPv6 inet_htop */
--- 519,526 ----
  olsrd_print_cnf(struct olsrd_config *cnf)
  {
!   struct ip_prefix_list   *h  = cnf->hna_entries;
    struct olsr_if           *in = cnf->interfaces;
    struct plugin_entry      *pe = cnf->plugins;
!   struct ip_prefix_list    *ie = cnf->ipc_nets;
    struct olsr_lq_mult      *mult;
    char ipv6_buf[100];             /* buffer for IPv6 inet_htop */
***************
*** 544,558 ****
  
    printf("IPC connections  : %d\n", cnf->ipc_connections);
- 
-   while(ih)
-     {
-       printf("\tHost %s\n", inet_ntoa(ih->host.v4));
-       ih = ih->next;
-     }
-   
    while(ie)
      {
!       printf("\tNet %s/", inet_ntoa(ie->net.v4));
!       printf("%s\n", inet_ntoa(ie->mask.v4));
        ie = ie->next;
      }
--- 545,556 ----
  
    printf("IPC connections  : %d\n", cnf->ipc_connections);
    while(ie)
      {
!       struct ipaddr_str strbuf;
!       if (ie->net.prefix_len == olsr_cnf->maxplen) {
!           printf("\tHost %s\n", olsr_ip_to_string(&strbuf, &ie->net.prefix));
!       } else {
!           printf("\tNet %s/%d\n", olsr_ip_to_string(&strbuf, &ie->net.prefix), ie->net.prefix_len);
!       }
        ie = ie->next;
      }
***************
*** 641,668 ****
    }
  
- #if 0
-   /* HNA IPv4 */
-   if(h4)
-     {
- 
-       printf("HNA4 entries:\n");
-       while(h4)
- 	{
- 	  printf("\t%s/", inet_ntoa(h4->net.v4));
- 	  printf("%s\n", inet_ntoa(h4->netmask.v4));
- 	  h4 = h4->next;
- 	}
-     }
- 
-   /* HNA IPv6 */
-   if(h6)
-     {
-       printf("HNA6 entries:\n");
-       while(h6)
- 	{
- 	  printf("\t%s/%d\n", inet_ntop(AF_INET6, &h6->net.v6, ipv6_buf, sizeof(ipv6_buf)), h6->prefix_len);
- 	  h6 = h6->next;
- 	}
- #else
    /* HNA IPv4 and IPv6 */
    if(h) {
--- 639,642 ----
***************
*** 679,683 ****
        }
        h = h->next;
- #endif
      }
    }
--- 653,656 ----
***************
*** 716,717 ****
--- 689,740 ----
  }
  #endif
+ 
+ void ip_prefix_list_add(struct ip_prefix_list **list,
+                         const union olsr_ip_addr *net,
+                         olsr_u8_t prefix_len)
+ {
+   struct ip_prefix_list *new_entry = olsr_malloc(sizeof(*new_entry), "Add local HNA entry");
+   
+   new_entry->net.prefix = *net;
+   new_entry->net.prefix_len = prefix_len;
+ 
+   /* Queue */
+   new_entry->next = *list;
+   *list = new_entry;
+ }
+ 
+ int ip_prefix_list_remove(struct ip_prefix_list **list,
+                           const union olsr_ip_addr *net,
+                           olsr_u8_t prefix_len)
+ {
+   struct ip_prefix_list *h = *list, *prev = NULL;
+ 
+   while (h != NULL) {
+     if (ipequal(net, &h->net.prefix) && h->net.prefix_len == prefix_len) {
+       /* Dequeue */
+       if (prev == NULL) {
+         *list = h->next;
+       } else {
+         prev->next = h->next;
+       }
+       free(h);
+       return 1;
+     }
+     prev = h;
+     h = h->next;
+   }
+   return 0;
+ }
+ 
+ struct ip_prefix_list *ip_prefix_list_find(struct ip_prefix_list *list,
+                                            const union olsr_ip_addr *net,
+                                            olsr_u8_t prefix_len)
+ {
+   struct ip_prefix_list *h;
+   for (h = list; h != NULL; h = h->next) {
+     if (prefix_len == h->net.prefix_len && ipequal(net, &h->net.prefix)) {
+       return h;
+     }
+   }
+   return NULL;
+ }

Index: oparse.y
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/cfgparser/oparse.y,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -d -r1.39 -r1.40
*** oparse.y	22 Nov 2007 11:43:36 -0000	1.39
--- oparse.y	29 Nov 2007 00:49:40 -0000	1.40
***************
*** 43,46 ****
--- 43,51 ----
  
  
+ #include "olsrd_conf.h"
+ #include "../defs.h"
+ #include "../ipcalc.h"
+ #include "../net_olsr.h"
+ 
  #include <stddef.h>
  #include <stdio.h>
***************
*** 52,59 ****
  #include <string.h>
  
- #include "olsrd_conf.h"
- #include "../defs.h"
- #include "../net_olsr.h"
- 
  #define PARSER_DEBUG 0
  
--- 57,60 ----
***************
*** 72,75 ****
--- 73,77 ----
  
  static int lq_mult_helper(YYSTYPE ip_addr_arg, YYSTYPE mult_arg);
+ static int add_ipv6_addr(YYSTYPE ipaddr_arg, YYSTYPE prefixlen_arg);
  
  static int lq_mult_helper(YYSTYPE ip_addr_arg, YYSTYPE mult_arg)
***************
*** 88,92 ****
  
    if (ip_addr_arg != NULL &&
!      inet_pton(olsr_cnf->ip_version, ip_addr_arg->string, &addr) < 0) {
      fprintf(stderr, "Cannot parse IP address %s.\n", ip_addr_arg->string);
      return -1;
--- 90,94 ----
  
    if (ip_addr_arg != NULL &&
!      inet_pton(olsr_cnf->ip_version, ip_addr_arg->string, &addr) <= 0) {
      fprintf(stderr, "Cannot parse IP address %s.\n", ip_addr_arg->string);
      return -1;
***************
*** 120,125 ****
--- 122,154 ----
    return 0;
  }
+ 
+ static int add_ipv6_addr(YYSTYPE ipaddr_arg, YYSTYPE prefixlen_arg)
+ {
+   union olsr_ip_addr ipaddr;
+   PARSER_DEBUG_PRINTF("HNA IPv6 entry: %s/%d\n", ipaddr_arg->string, prefixlen_arg->integer);
+ 
+   if(inet_pton(AF_INET6, ipaddr_arg->string, &ipaddr) <= 0) {
+     fprintf(stderr, "ihna6entry: Failed converting IP address %s\n", ipaddr_arg->string);
+     return 1;
+   }
+ 
+   if (prefixlen_arg->integer > 128) {
+     fprintf(stderr, "ihna6entry: Illegal IPv6 prefix length %d\n", prefixlen_arg->integer);
+     return 1;
+   }
+ 
+   /* Queue */
+   ip_prefix_list_add(&olsr_cnf->hna_entries, &ipaddr, prefixlen_arg->integer);
+ 
+   free(ipaddr_arg->string);
+   free(ipaddr_arg);
+   free(prefixlen_arg);
+ 
+   return 0;
+ }
+ 
  %}
  
+ %token TOK_SLASH
  %token TOK_OPEN
  %token TOK_CLOSE
***************
*** 302,321 ****
  ipchost: TOK_HOSTLABEL TOK_IP4_ADDR
  {
!   struct ipc_host *ipch = malloc(sizeof(struct ipc_host));
! 
    PARSER_DEBUG_PRINTF("\tIPC host: %s\n", $2->string);
    
!   if (inet_aton($2->string, &ipch->host.v4) == 0) {
      fprintf(stderr, "Failed converting IP address IPC %s\n", $2->string);
!     free(ipch);
!     return -1;
    }
  
!   ipch->next = olsr_cnf->ipc_hosts;
!   olsr_cnf->ipc_hosts = ipch;
  
    free($2->string);
    free($2);
- 
  }
  ;
--- 331,346 ----
  ipchost: TOK_HOSTLABEL TOK_IP4_ADDR
  {
!   union olsr_ip_addr ipaddr;
    PARSER_DEBUG_PRINTF("\tIPC host: %s\n", $2->string);
    
!   if (inet_aton($2->string, &ipaddr.v4) == 0) {
      fprintf(stderr, "Failed converting IP address IPC %s\n", $2->string);
!     YYABORT;
    }
  
!   ip_prefix_list_add(&olsr_cnf->ipc_nets, &ipaddr, olsr_cnf->maxplen);
  
    free($2->string);
    free($2);
  }
  ;
***************
*** 323,343 ****
  ipcnet: TOK_NETLABEL TOK_IP4_ADDR TOK_IP4_ADDR
  {
!   struct ipc_net *ipcn = malloc(sizeof(struct ipc_net));
    PARSER_DEBUG_PRINTF("\tIPC net: %s/%s\n", $2->string, $3->string);
    
!   if (inet_aton($2->string, &ipcn->net.v4) == 0) {
      fprintf(stderr, "Failed converting IP net IPC %s\n", $2->string);
!     free(ipcn);
!     return -1;
    }
  
!   if (inet_aton($3->string, &ipcn->mask.v4) == 0) {
      fprintf(stderr, "Failed converting IP mask IPC %s\n", $3->string);
!     free(ipcn);
!     return -1;
    }
  
!   ipcn->next = olsr_cnf->ipc_nets;
!   olsr_cnf->ipc_nets = ipcn;
  
    free($2->string);
--- 348,366 ----
  ipcnet: TOK_NETLABEL TOK_IP4_ADDR TOK_IP4_ADDR
  {
!   union olsr_ip_addr ipaddr, netmask;
! 
    PARSER_DEBUG_PRINTF("\tIPC net: %s/%s\n", $2->string, $3->string);
    
!   if (inet_pton(AF_INET, $2->string, &ipaddr.v4) == 0) {
      fprintf(stderr, "Failed converting IP net IPC %s\n", $2->string);
!     YYABORT;
    }
  
!   if (inet_pton(AF_INET, $3->string, &netmask.v4) == 0) {
      fprintf(stderr, "Failed converting IP mask IPC %s\n", $3->string);
!     YYABORT;
    }
  
!   ip_prefix_list_add(&olsr_cnf->ipc_nets, &ipaddr, olsr_netmask_to_prefix(&netmask));
  
    free($2->string);
***************
*** 345,349 ****
--- 368,393 ----
    free($3->string);
    free($3);
+ }
+         |       TOK_NETLABEL TOK_IP4_ADDR TOK_SLASH TOK_INTEGER
+ {
+   union olsr_ip_addr ipaddr;
+ 
+   PARSER_DEBUG_PRINTF("\tIPC net: %s/%s\n", $2->string, $3->string);
+   
+   if (inet_pton(AF_INET, $2->string, &ipaddr.v4) == 0) {
+     fprintf(stderr, "Failed converting IP net IPC %s\n", $2->string);
+     YYABORT;
+   }
  
+   if ($4->integer > olsr_cnf->maxplen) {
+     fprintf(stderr, "ipcnet: Prefix len %u > %d is not allowed!\n", $4->integer, olsr_cnf->maxplen);
+     YYABORT;
+   }
+ 
+   ip_prefix_list_add(&olsr_cnf->ipc_nets, &ipaddr, $4->integer);
+ 
+   free($2->string);
+   free($2);
+   free($4);
  }
  ;
***************
*** 378,382 ****
    if (inet_aton($2->string, &in) == 0) {
      fprintf(stderr, "isetip4br: Failed converting IP address %s\n", $2->string);
!     return -1;
    }
  
--- 422,426 ----
    if (inet_aton($2->string, &in) == 0) {
      fprintf(stderr, "isetip4br: Failed converting IP address %s\n", $2->string);
!     YYABORT;
    }
  
***************
*** 426,432 ****
    PARSER_DEBUG_PRINTF("\tIPv6 site-local multicast: %s\n", $2->string);
  
!   if (inet_pton(AF_INET6, $2->string, &in6) < 0) {
      fprintf(stderr, "isetip6mults: Failed converting IP address %s\n", $2->string);
!     return -1;
    }
  
--- 470,476 ----
    PARSER_DEBUG_PRINTF("\tIPv6 site-local multicast: %s\n", $2->string);
  
!   if (inet_pton(AF_INET6, $2->string, &in6) <= 0) {
      fprintf(stderr, "isetip6mults: Failed converting IP address %s\n", $2->string);
!     YYABORT;
    }
  
***************
*** 452,458 ****
    PARSER_DEBUG_PRINTF("\tIPv6 global multicast: %s\n", $2->string);
  
!   if (inet_pton(AF_INET6, $2->string, &in6) < 0) {
      fprintf(stderr, "isetip6multg: Failed converting IP address %s\n", $2->string);
!     return -1;
    }
  
--- 496,502 ----
    PARSER_DEBUG_PRINTF("\tIPv6 global multicast: %s\n", $2->string);
  
!   if (inet_pton(AF_INET6, $2->string, &in6) <= 0) {
      fprintf(stderr, "isetip6multg: Failed converting IP address %s\n", $2->string);
!     YYABORT;
    }
  
***************
*** 668,700 ****
  ;
  
- 
  ihna4entry:     TOK_IP4_ADDR TOK_IP4_ADDR
  {
!   struct local_hna_entry *h = malloc(sizeof(*h));
!   union olsr_ip_addr netmask;
  
    PARSER_DEBUG_PRINTF("HNA IPv4 entry: %s/%s\n", $1->string, $2->string);
  
!   if (h == NULL) {
!     fprintf(stderr, "Out of memory(HNA4)\n");
      YYABORT;
    }
! 
!   if (inet_aton($1->string, &h->net.prefix.v4) == 0) {
      fprintf(stderr, "ihna4entry: Failed converting IP address %s\n", $1->string);
!     free(h);
!     return -1;
    }
!   if (inet_aton($2->string, &netmask.v4) == 0) {
!     fprintf(stderr, "ihna4entry: Failed converting IP address %s\n", $1->string);
!     free(h);
!     return -1;
    }
-   h->net.prefix_len = olsr_netmask_to_prefix(&netmask);
-   h->net.prefix.v4.s_addr &= netmask.v4.s_addr;
  
    /* Queue */
!   h->next = olsr_cnf->hna_entries;
!   olsr_cnf->hna_entries = h;
  
    free($1->string);
--- 712,738 ----
  ;
  
  ihna4entry:     TOK_IP4_ADDR TOK_IP4_ADDR
  {
!   union olsr_ip_addr ipaddr, netmask;
  
    PARSER_DEBUG_PRINTF("HNA IPv4 entry: %s/%s\n", $1->string, $2->string);
  
!   if (inet_pton(AF_INET, $1->string, &ipaddr.v4) <= 0) {
!     fprintf(stderr, "ihna4entry: Failed converting IP address %s\n", $1->string);
      YYABORT;
    }
!   if (inet_pton(AF_INET, $2->string, &netmask.v4) <= 0) {
      fprintf(stderr, "ihna4entry: Failed converting IP address %s\n", $1->string);
!     YYABORT;
    }
! 
!   /* check that the given IP address is actually a network address */
!   if ((ipaddr.v4.s_addr & ~netmask.v4.s_addr) != 0) {
!     fprintf(stderr, "ihna4entry: The ipaddress \"%s\" is not a network address!\n", $1->string);
!     YYABORT;
    }
  
    /* Queue */
!   ip_prefix_list_add(&olsr_cnf->hna_entries, &ipaddr, olsr_netmask_to_prefix(&netmask));
  
    free($1->string);
***************
*** 702,742 ****
    free($2->string);
    free($2);
- 
  }
! ;
! 
! 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);
  
!   if (h == NULL) {
!     fprintf(stderr, "Out of memory(HNA6)\n");
      YYABORT;
    }
! 
!   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) {
!     fprintf(stderr, "ihna6entry: Illegal IPv6 prefix length %d\n", $2->integer);
!     free(h);
!     return -1;
    }
  
!   h->net.prefix_len = $2->integer;
  
    /* Queue */
!   h->next = olsr_cnf->hna_entries;
!   olsr_cnf->hna_entries = h;
  
    free($1->string);
    free($1);
!   free($2);
  
  }
  ;
--- 740,786 ----
    free($2->string);
    free($2);
  }
!         |       TOK_IP4_ADDR TOK_SLASH TOK_INTEGER
  {
!   union olsr_ip_addr ipaddr, netmask;
  
!   PARSER_DEBUG_PRINTF("HNA IPv4 entry: %s/%d\n", $1->string, $3->integer);
  
!   if (inet_pton(AF_INET, $1->string, &ipaddr.v4) <= 0) {
!     fprintf(stderr, "ihna4entry: Failed converting IP address %s\n", $1->string);
      YYABORT;
    }
!   if ($3->integer > olsr_cnf->maxplen) {
!     fprintf(stderr, "ihna4entry: Prefix len %u > %d is not allowed!\n", $3->integer, olsr_cnf->maxplen);
!     YYABORT;
    }
  
!   /* check that the given IP address is actually a network address */
!   olsr_prefix_to_netmask(&netmask, $3->integer);
!   if ((ipaddr.v4.s_addr & ~netmask.v4.s_addr) != 0) {
!     fprintf(stderr, "ihna4entry: The ipaddress \"%s\" is not a network address!\n", $1->string);
!     YYABORT;
!   }
  
    /* Queue */
!   ip_prefix_list_add(&olsr_cnf->hna_entries, &ipaddr, $3->integer);
  
    free($1->string);
    free($1);
!   free($3);
! }
! ;
  
+ ihna6entry:     TOK_IP6_ADDR TOK_INTEGER
+ {
+   if (add_ipv6_addr($1, $2)) {
+     YYABORT;
+   }
+ }
+         |       TOK_IP6_ADDR TOK_SLASH TOK_INTEGER
+ {
+   if (add_ipv6_addr($1, $3)) {
+     YYABORT;
+   }
  }
  ;





More information about the Olsr-cvs mailing list