[Olsr-cvs] olsrd-current/lib/dyn_gw/src olsrd_dyn_gw.c, 1.21, 1.22 olsrd_dyn_gw.h, 1.12, 1.13 olsrd_plugin.c, 1.14, 1.15

Bernd Petrovitsch (spam-protected)
Thu Sep 13 17:41:14 CEST 2007


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

Modified Files:
	olsrd_dyn_gw.c olsrd_dyn_gw.h olsrd_plugin.c 
Log Message:
* converted to plugin interface version 5

Index: olsrd_dyn_gw.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/dyn_gw/src/olsrd_dyn_gw.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** olsrd_dyn_gw.c	8 May 2007 23:49:00 -0000	1.21
--- olsrd_dyn_gw.c	13 Sep 2007 15:41:12 -0000	1.22
***************
*** 53,56 ****
--- 53,57 ----
  #include "olsr.h"
  #include "local_hna_set.h"
+ #include "defs.h"
  
  #include <stdio.h>
***************
*** 101,105 ****
  
  static struct ping_list *
! add_to_ping_list(char *, struct ping_list *);
  
  struct hna_list {
--- 102,106 ----
  
  static struct ping_list *
! add_to_ping_list(const char *, struct ping_list *);
  
  struct hna_list {
***************
*** 134,189 ****
  /**
   * read config file parameters
!  */  
! int
! olsrd_plugin_register_param(char *key, char *value)
  {
!   /* foo_addr is only used for call to inet_aton */ 
!   struct in_addr foo_addr;
!   int retval = -1;
!   int i;
!   union olsr_ip_addr temp_net;
!   union olsr_ip_addr temp_netmask;
!   char s_netaddr[16];
!   char s_mask[16];
!  
!   //printf("%s():%s->%s\n",__func__,key,value);
!   
!   if (!strcmp(key, "Interval")) {
!     if (sscanf(value, "%d", &check_interval) == 1) {
!       retval = 1;
      }
!   }else if (!strcmp(key, "Ping")) {
!     /* if value contains a valid IPaddr, then add it to the list */
!     //if (inet_aton(strdup(value), &foo_addr)) {
! 	if (inet_aton(value, &foo_addr)) {
! 	    /*if first ping without hna then assume inet gateway*/
! 		if (the_hna_list==NULL){
! 		    temp_net.v4 = INET_NET;
! 		    temp_netmask.v4 = INET_PREFIX;
! 		    if ((the_hna_list = add_to_hna_list(the_hna_list,&temp_net,&temp_netmask))==NULL)
! 			    return retval;
! 		}
! 		the_hna_list->ping_hosts=add_to_ping_list(value, the_hna_list->ping_hosts);
! 		retval = 1;
      }
!   }else if (!strcmp(key, "HNA")) {
! 	  //192.168.1.0  255.255.255.0
! 	  i=sscanf(value,"%15s %15s",s_netaddr,s_mask);
! 	  //printf("%s():i:%i; net:%s; mask:%s\n",__func__,i,s_netaddr,s_mask);
! 	  if (inet_aton(s_netaddr, &foo_addr)) {
! 		  temp_net.v4=foo_addr.s_addr;
! 		  //printf("GOT: %s(%08x)",inet_ntoa(foo_addr),foo_addr.s_addr);
! 		  if (inet_aton(s_mask, &foo_addr)) {
! 			  temp_netmask.v4=foo_addr.s_addr;
! 			  //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 *)&));
! 			  if ((the_hna_list = add_to_hna_list(the_hna_list,&temp_net,&temp_netmask))!=NULL)
! 				  retval = 1;
! 		  }
! 	  }
!   }
!   return retval;
  }
  
  
  /**
--- 135,226 ----
  /**
   * read config file parameters
!  */
! static int set_plugin_double(const char *value, void *data, unsigned int addon __attribute__((unused)))
  {
!     char *endptr;
!     const double d = strtod(value, &endptr);
!     if (*endptr != '\0' || endptr == value) {
!         OLSR_PRINTF(0, "Illegal double \"%s\"", value);
!         return 1;
      }
!     if (data != NULL) {
!         double *v = data;
!         *v = d;
!         OLSR_PRINTF(1, "%s double %lf\n", "Got", d);
!     } else {
!         OLSR_PRINTF(0, "%s double %lf\n", "Ignored", d);
      }
!     return 0;
  }
  
+ static int set_plugin_ping(const char *value, void *data __attribute__((unused)), unsigned int addon __attribute__((unused)))
+ {
+     union olsr_ip_addr foo_addr;
+ 
+     if (inet_pton(olsr_cnf->ip_version, value, &foo_addr) <= 0) {
+         OLSR_PRINTF(0, "Illegal IP address \"%s\"", value);
+         return 1;
+     }
+     /*if first ping without hna then assume inet gateway*/
+     if (the_hna_list == NULL){
+         union olsr_ip_addr temp_net;
+         union olsr_ip_addr temp_netmask;
+         temp_net.v4 = INET_NET;
+         temp_netmask.v4 = INET_PREFIX;
+         the_hna_list = add_to_hna_list(the_hna_list, &temp_net, &temp_netmask);
+         if (the_hna_list == NULL) {
+             return 1;
+         }
+     }
+     the_hna_list->ping_hosts = add_to_ping_list(value, the_hna_list->ping_hosts);
+     return 0;
+ }
+ 
+ static int set_plugin_hna(const char *value, void *data __attribute__((unused)), unsigned int addon __attribute__((unused)))
+ {
+     union olsr_ip_addr temp_net;
+     union olsr_ip_addr temp_netmask;
+     char s_netaddr[128];
+     char s_mask[128];
+ 
+     //192.168.1.0  255.255.255.0
+     int i = sscanf(value,"%128s %128s", s_netaddr, s_mask);
+     if (i != 2) {
+         OLSR_PRINTF(0, "Cannot get IP address and netmask from \"%s\"", value);
+         return 1;
+     }
+ 
+     //printf("%s():i:%i; net:%s; mask:%s\n",__func__,i,s_netaddr,s_mask);
+     if (inet_pton(olsr_cnf->ip_version, s_netaddr, &temp_net) <= 0) {
+         OLSR_PRINTF(0, "Illegal IP address \"%s\"", s_netaddr);
+         return 1;
+     }
+ 
+     //printf("GOT: %s(%08x)",inet_ntoa(foo_addr),foo_addr.s_addr);
+     if (inet_pton(olsr_cnf->ip_version, s_netaddr, &temp_netmask) <= 0) {
+         OLSR_PRINTF(0, "Illegal netmask \"%s\"", s_netaddr);
+         return 1;
+     }
+ 
+     //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;
+     }
+     return 0;
+ }
+ 
+ static const struct olsrd_plugin_parameters plugin_parameters[] = {
+     { .name = "interval", .set_plugin_parameter = &set_plugin_double, .data = &check_interval },
+     { .name = "ping",     .set_plugin_parameter = &set_plugin_ping,   .data = NULL },
+     { .name = "hna",      .set_plugin_parameter = &set_plugin_hna,    .data = NULL },
+ };
+ 
+ void olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
+ {
+     *params = plugin_parameters;
+     *size = sizeof(plugin_parameters)/sizeof(*plugin_parameters);
+ }
  
  /**
***************
*** 376,380 ****
  /* add the valid IPs to the head of the list */
  static struct ping_list *
! add_to_ping_list(char *ping_address, struct ping_list *the_ping_list)
  {
    struct ping_list *new = malloc(sizeof(struct ping_list));
--- 413,417 ----
  /* add the valid IPs to the head of the list */
  static struct ping_list *
! add_to_ping_list(const char *ping_address, struct ping_list *the_ping_list)
  {
    struct ping_list *new = malloc(sizeof(struct ping_list));

Index: olsrd_dyn_gw.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/dyn_gw/src/olsrd_dyn_gw.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** olsrd_dyn_gw.h	20 Apr 2007 14:06:18 -0000	1.12
--- olsrd_dyn_gw.h	13 Sep 2007 15:41:12 -0000	1.13
***************
*** 51,62 ****
  #define PROCENTRY_ROUTE "/proc/net/route"
  
! int
! olsrd_plugin_init(void);
  
! int 
! olsrd_plugin_interface_version(void);
  
! int
! olsrd_plugin_register_param(char *key, char *value);
  
  #endif
--- 51,59 ----
  #define PROCENTRY_ROUTE "/proc/net/route"
  
! int olsrd_plugin_init(void);
  
! int olsrd_plugin_interface_version(void);
  
! void olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size);
  
  #endif

Index: olsrd_plugin.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/dyn_gw/src/olsrd_plugin.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** olsrd_plugin.c	20 Apr 2007 14:19:44 -0000	1.14
--- olsrd_plugin.c	13 Sep 2007 15:41:12 -0000	1.15
***************
*** 49,53 ****
  #define PLUGIN_AUTHOR   "Various artists"
  #define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION " by " PLUGIN_AUTHOR
! #define PLUGIN_INTERFACE_VERSION 4
  
  
--- 49,53 ----
  #define PLUGIN_AUTHOR   "Various artists"
  #define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION " by " PLUGIN_AUTHOR
! #define PLUGIN_INTERFACE_VERSION 5
  
  
***************
*** 56,61 ****
   */
  
! static void __attribute__ ((constructor)) 
! my_init(void);
  
  
--- 56,60 ----
   */
  
! static void my_init(void) __attribute__ ((constructor));
  
  
***************
*** 80,84 ****
    /* Print plugin info to stdout */
    printf("%s\n", MOD_DESC);
- 
-   return;
  }
--- 79,81 ----





More information about the Olsr-cvs mailing list