[Olsr-cvs] olsrd-current/lib/dyn_gw/src olsrd_dyn_gw.c,1.26,1.27

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


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

Modified Files:
	olsrd_dyn_gw.c 
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: olsrd_dyn_gw.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/dyn_gw/src/olsrd_dyn_gw.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** olsrd_dyn_gw.c	8 Nov 2007 23:53:43 -0000	1.26
--- olsrd_dyn_gw.c	29 Nov 2007 00:49:40 -0000	1.27
***************
*** 42,46 ****
  
  /*
!  * -Threaded ping code added by Jens Nachitgall
   * -HNA4 checking by bjoern riemer
   */
--- 42,46 ----
  
  /*
!  * -Threaded ping code added by Jens Nachtigall
   * -HNA4 checking by bjoern riemer
   */
***************
*** 52,57 ****
  #include "scheduler.h"
  #include "olsr.h"
- #include "local_hna_set.h"
  #include "defs.h"
  
  #include <stdio.h>
--- 52,57 ----
  #include "scheduler.h"
  #include "olsr.h"
  #include "defs.h"
+ #include "ipcalc.h"
  
  #include <stdio.h>
***************
*** 106,110 ****
  struct hna_list {
    union olsr_ip_addr hna_net;
!   union olsr_ip_addr hna_netmask;
    struct ping_list *ping_hosts;
    int hna_added;
--- 106,110 ----
  struct hna_list {
    union olsr_ip_addr hna_net;
!   olsr_u8_t hna_prefixlen;
    struct ping_list *ping_hosts;
    int hna_added;
***************
*** 116,120 ****
  	add_to_hna_list(struct hna_list *,
  				union olsr_ip_addr *hna_net,
! 				union olsr_ip_addr *hna_netmask );
  
  struct hna_list *the_hna_list = NULL;
--- 116,120 ----
  	add_to_hna_list(struct hna_list *,
  				union olsr_ip_addr *hna_net,
! 				olsr_u8_t hna_prefixlen );
  
  struct hna_list *the_hna_list = NULL;
***************
*** 124,128 ****
  
  static int
! check_gw(union olsr_ip_addr *, union olsr_ip_addr *,struct ping_list *);
  
  static int
--- 124,128 ----
  
  static int
! check_gw(union olsr_ip_addr *, olsr_u8_t,struct ping_list *);
  
  static int
***************
*** 168,172 ****
          temp_net.v4.s_addr = INET_NET;
          temp_netmask.v4.s_addr = INET_PREFIX;
!         the_hna_list = add_to_hna_list(the_hna_list, &temp_net, &temp_netmask);
          if (the_hna_list == NULL) {
              return 1;
--- 168,172 ----
          temp_net.v4.s_addr = INET_NET;
          temp_netmask.v4.s_addr = INET_PREFIX;
!         the_hna_list = add_to_hna_list(the_hna_list, &temp_net, olsr_netmask_to_prefix(&temp_netmask));
          if (the_hna_list == NULL) {
              return 1;
***************
*** 205,209 ****
      //printf("/%s(%08x)\n",inet_ntoa(foo_addr),foo_addr.s_addr);
      //printf("%s():got->%s/%s\n",__func__,olsr_ip_to_string((union olsr_ip_addr *)&));
!     the_hna_list = add_to_hna_list(the_hna_list, &temp_net, &temp_netmask);
      if (the_hna_list != NULL) {
          return 1;
--- 205,209 ----
      //printf("/%s(%08x)\n",inet_ntoa(foo_addr),foo_addr.s_addr);
      //printf("%s():got->%s/%s\n",__func__,olsr_ip_to_string((union olsr_ip_addr *)&));
!     the_hna_list = add_to_hna_list(the_hna_list, &temp_net, olsr_netmask_to_prefix(&temp_netmask));
      if (the_hna_list != NULL) {
          return 1;
***************
*** 270,274 ****
    if (has_available_gw == 1 && gw_already_added == 0) {
      olsr_printf(1, "Adding OLSR local HNA entry for Internet\n");
!     add_local_hna4_entry(&gw_net, &gw_netmask);
      gw_already_added = 1;
    } else if ((has_available_gw == 0) && (gw_already_added == 1)) {
--- 270,274 ----
    if (has_available_gw == 1 && gw_already_added == 0) {
      olsr_printf(1, "Adding OLSR local HNA entry for Internet\n");
!     add_local_hna_entry(&gw_net, &gw_netmask);
      gw_already_added = 1;
    } else if ((has_available_gw == 0) && (gw_already_added == 1)) {
***************
*** 283,290 ****
  		if((li->probe_ok==1)&&(li->hna_added==0)){
  			olsr_printf(1, "Adding OLSR local HNA entry\n");
! 			add_local_hna4_entry(&li->hna_net, &li->hna_netmask);
  			li->hna_added=1;
  		}else if((li->probe_ok==0)&&(li->hna_added==1)){
! 			while(remove_local_hna4_entry(&li->hna_net, &li->hna_netmask)) {
  				olsr_printf(1, "Removing OLSR local HNA entry\n");
  			}
--- 283,290 ----
  		if((li->probe_ok==1)&&(li->hna_added==0)){
  			olsr_printf(1, "Adding OLSR local HNA entry\n");
! 			ip_prefix_list_add(&olsr_cnf->hna_entries, &li->hna_net, li->hna_prefixlen);
  			li->hna_added=1;
  		}else if((li->probe_ok==0)&&(li->hna_added==1)){
! 			while(ip_prefix_list_remove(&olsr_cnf->hna_entries, &li->hna_net, li->hna_prefixlen)) {
  				olsr_printf(1, "Removing OLSR local HNA entry\n");
  			}
***************
*** 312,316 ****
      for(li = the_hna_list; li; li = li->next){
        /* check for gw in table entry and if Ping IPs are given also do pings */
!       li->probe_ok = check_gw(&li->hna_net,&li->hna_netmask,li->ping_hosts);
        //has_available_gw = check_gw(&gw_net, &gw_netmask);
      }
--- 312,316 ----
      for(li = the_hna_list; li; li = li->next){
        /* check for gw in table entry and if Ping IPs are given also do pings */
!       li->probe_ok = check_gw(&li->hna_net,li->hna_prefixlen,li->ping_hosts);
        //has_available_gw = check_gw(&gw_net, &gw_netmask);
      }
***************
*** 325,329 ****
  
  static int
! check_gw(union olsr_ip_addr *net, union olsr_ip_addr *mask, struct ping_list *the_ping_list)
  {
      char buf[1024], iface[16];
--- 325,329 ----
  
  static int
! check_gw(union olsr_ip_addr *net, olsr_u8_t prefixlen, struct ping_list *the_ping_list)
  {
      char buf[1024], iface[16];
***************
*** 332,335 ****
--- 332,336 ----
      int metric, refcnt, use;
      int retval = 0;
+     union olsr_ip_addr mask;
  
      FILE *fp = fopen(PROCENTRY_ROUTE, "r");
***************
*** 341,344 ****
--- 342,346 ----
        }    
  
+     olsr_prefix_to_netmask(&mask, prefixlen);
      /*
      olsr_printf(1, "Genmask         Destination     Gateway         "
***************
*** 365,372 ****
          if( (iflags & RTF_UP) &&
              (metric == 0) &&
!             (netmask == mask->v4.s_addr) && 
              (dest_addr == net->v4.s_addr))
            {
!             if ( ((mask->v4.s_addr == INET_PREFIX)&&(net->v4.s_addr == INET_NET))&&(!(iflags & RTF_GATEWAY)))
                {
                  fclose(fp);  
--- 367,374 ----
          if( (iflags & RTF_UP) &&
              (metric == 0) &&
!             (netmask == mask.v4.s_addr) && 
              (dest_addr == net->v4.s_addr))
            {
!             if ( ((mask.v4.s_addr == INET_PREFIX)&&(net->v4.s_addr == INET_NET))&&(!(iflags & RTF_GATEWAY)))
                {
                  fclose(fp);  
***************
*** 390,394 ****
      if(retval == 0){
        /* And we cast here since we get warnings on Win32 */
!       olsr_printf(1, "HNA[%08x/%08x] is invalid\n", (unsigned int)net->v4.s_addr, (unsigned int)mask->v4.s_addr);
      }  
      return retval;
--- 392,396 ----
      if(retval == 0){
        /* And we cast here since we get warnings on Win32 */
!       olsr_printf(1, "HNA[%08x/%08x] is invalid\n", (unsigned int)net->v4.s_addr, (unsigned int)mask.v4.s_addr);
      }  
      return retval;
***************
*** 430,434 ****
  
  static struct hna_list *
! add_to_hna_list(struct hna_list * list_root, union olsr_ip_addr *hna_net, union olsr_ip_addr *hna_netmask )
  {
    struct hna_list *new = malloc(sizeof(struct hna_list));
--- 432,436 ----
  
  static struct hna_list *
! add_to_hna_list(struct hna_list * list_root, union olsr_ip_addr *hna_net, olsr_u8_t hna_prefixlen )
  {
    struct hna_list *new = malloc(sizeof(struct hna_list));
***************
*** 441,445 ****
    //memcpy(&new->hna_netmask,hna_netmask,sizeof(union hna_netmask));
    new->hna_net.v4=hna_net->v4;
!   new->hna_netmask.v4=hna_netmask->v4;
    new->hna_added=0;
    new->probe_ok=0;
--- 443,447 ----
    //memcpy(&new->hna_netmask,hna_netmask,sizeof(union hna_netmask));
    new->hna_net.v4=hna_net->v4;
!   new->hna_prefixlen=hna_prefixlen;
    new->hna_added=0;
    new->probe_ok=0;





More information about the Olsr-cvs mailing list