[Olsr-dev] [PATCH v1 07/19] gateway: add init and cleanup hooks for gateway plugins

Ferry Huberts (spam-protected)
Thu Aug 23 15:12:31 CEST 2012


From: Ferry Huberts <(spam-protected)>

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 src/gateway.c                 | 22 ++++------------------
 src/gateway.h                 |  3 ++-
 src/gateway_default_handler.c | 21 ++++++++++++++-------
 src/gateway_default_handler.h |  2 +-
 4 files changed, 21 insertions(+), 27 deletions(-)

diff --git a/src/gateway.c b/src/gateway.c
index abdc85f..183956f 100644
--- a/src/gateway.c
+++ b/src/gateway.c
@@ -190,12 +190,9 @@ int olsr_init_gateways(void) {
 
   olsr_add_ifchange_handler(smartgw_tunnel_monitor);
 
-  /*
-   * initialize default gateway handler,
-   * can be overwritten with olsr_set_inetgw_handler
-   */
-  olsr_gw_default_init();
-  assert(gw_handler);
+  /* initialize default gateway handler */
+  gw_handler = &gw_def_handler;
+  gw_handler->init_gw_plugin();
 
   return 0;
 }
@@ -214,6 +211,7 @@ void olsr_cleanup_gateways(void) {
   olsr_remove_ifchange_handler(smartgw_tunnel_monitor);
 
   assert(gw_handler);
+  gw_handler->cleanup_gw_plugin();
   gw_handler = NULL;
 
   olsr_os_cleanup_iptunnel(olsr_cnf->ip_version == AF_INET ? TUNNEL_ENDPOINT_IF : TUNNEL_ENDPOINT_IF6);
@@ -489,18 +487,6 @@ void olsr_trigger_gatewayloss_check(void) {
  */
 
 /**
- * Set a new gateway handler.
- * Only call this once: during startup (from a plugin to override the default
- * handler)
- *
- * @param h pointer to gateway handler struct
- */
-void olsr_set_inetgw_handler(struct olsr_gw_handler *h) {
-  assert(h);
-  gw_handler = h;
-}
-
-/**
  * Sets a new internet gateway.
  *
  * @param originator ip address of the node with the new gateway
diff --git a/src/gateway.h b/src/gateway.h
index 91e8d45..6d11f26 100644
--- a/src/gateway.h
+++ b/src/gateway.h
@@ -87,6 +87,8 @@ extern struct avl_tree gateway_tree;
  * The callback list for a gateway plugin
  */
 struct olsr_gw_handler {
+    void (*init_gw_plugin)(void); /**< the init callback */
+    void (*cleanup_gw_plugin)(void); /**< the cleanup callback */
     void (*handle_startup)(void); /**< the startup callback */
     void (*select_gateway)(bool ipv4, bool ipv6); /**< the gateway selection callback */
     void (*handle_update_gw)(struct gateway_entry *); /**< the gateway update callback */
@@ -127,7 +129,6 @@ void olsr_trigger_gatewayloss_check(void);
  * Gateway Plugin Functions
  */
 
-void olsr_set_inetgw_handler(struct olsr_gw_handler *l);
 bool olsr_set_inet_gateway(union olsr_ip_addr *originator, bool ipv4, bool ipv6);
 struct gateway_entry *olsr_get_ipv4_inet_gateway(void);
 struct gateway_entry *olsr_get_ipv6_inet_gateway(void);
diff --git a/src/gateway_default_handler.c b/src/gateway_default_handler.c
index 35462a7..e246cf5 100644
--- a/src/gateway_default_handler.c
+++ b/src/gateway_default_handler.c
@@ -19,6 +19,8 @@ static bool gw_def_finished_ipv6;
 static struct timer_entry *gw_def_timer;
 
 /* forward declarations */
+static void gw_default_init(void);
+static void gw_default_cleanup(void);
 static void gw_default_startup_handler(void);
 static void gw_default_choosegw_handler(bool ipv4, bool ipv6);
 static void gw_default_update_handler(struct gateway_entry *);
@@ -27,7 +29,9 @@ static void gw_default_delete_handler(struct gateway_entry *);
 /**
  * Callback list for the gateway (default) handler
  */
-static struct olsr_gw_handler gw_def_handler = {
+struct olsr_gw_handler gw_def_handler = {
+    &gw_default_init,
+    &gw_default_cleanup,
     &gw_default_startup_handler,
     &gw_default_choosegw_handler,
     &gw_default_update_handler,
@@ -294,24 +298,27 @@ static void olsr_gw_default_lookup_gateway(bool ipv4, bool ipv6) {
  * Exported functions
  */
 
+/*
+ * Handler functions
+ */
+
 /**
  * initialization of default gateway handler
  */
-void olsr_gw_default_init(void) {
+static void gw_default_init(void) {
   /* initialize values */
   gw_def_nodecount = 0;
   gw_def_stablecount = 0;
   gw_def_finished_ipv4 = false;
   gw_def_finished_ipv6 = false;
   gw_def_timer = NULL;
-
-  /* setup default handler */
-  olsr_set_inetgw_handler(&gw_def_handler);
 }
 
-/*
- * Handler functions
+/**
+ * Cleanup default gateway handler
  */
+static void gw_default_cleanup(void) {
+}
 
 /**
  * Handle gateway startup
diff --git a/src/gateway_default_handler.h b/src/gateway_default_handler.h
index 32e1f14..9cbf029 100644
--- a/src/gateway_default_handler.h
+++ b/src/gateway_default_handler.h
@@ -10,7 +10,7 @@
 
 #ifdef linux
 
-void olsr_gw_default_init(void);
+extern struct olsr_gw_handler gw_def_handler;
 
 #endif /* linux */
 #endif /* GATEWAY_DEFAULT_HANDLER_H_ */
-- 
1.7.11.4





More information about the Olsr-dev mailing list