[Olsr-dev] [olsrd] [PATCH v1 01/29] gateway: reorder functions
Ferry Huberts
(spam-protected)
Tue Jul 24 18:08:50 CEST 2012
From: Ferry Huberts <(spam-protected)>
Signed-off-by: Ferry Huberts <(spam-protected)>
---
src/gateway_default_handler.c | 102 +++++++++++++++++++++++------------------
1 file changed, 57 insertions(+), 45 deletions(-)
diff --git a/src/gateway_default_handler.c b/src/gateway_default_handler.c
index ef68935..f314a6b 100644
--- a/src/gateway_default_handler.c
+++ b/src/gateway_default_handler.c
@@ -33,6 +33,10 @@ static struct olsr_gw_handler gw_def_handler = {
&gw_default_delete_handler
};
+/*
+ * Helper functions
+ */
+
/**
* Look through the gateway list and select the best gateway
* depending on the distance to this router
@@ -118,6 +122,51 @@ static void gw_default_timer(void *unused __attribute__ ((unused))) {
}
}
+/*
+ * Exported functions
+ */
+
+/**
+ * initialization of default gateway handler
+ */
+void olsr_gw_default_init(void) {
+ /* initialize values */
+ gw_def_timer = NULL;
+ gw_def_finished_ipv4 = false;
+ gw_def_finished_ipv6 = false;
+ gw_def_nodecount = 0;
+ gw_def_stablecount = 0;
+ gw_def_timer = NULL;
+
+ /* setup default handler */
+ olsr_set_inetgw_handler(&gw_def_handler);
+}
+
+/**
+ * Lookup a new gateway based on distance metric
+ *
+ * @param ipv4 lookup new v4 gateway
+ * @param ipv6 lookup new v6 gateway
+ */
+void olsr_gw_default_lookup_gateway(bool ipv4, bool ipv6) {
+ if (ipv4) {
+ /* get new ipv4 GW if we use OLSRv4 or NIIT */
+ gw_def_finished_ipv4 = !(olsr_cnf->ip_version == AF_INET || olsr_cnf->use_niit);
+ }
+ if (ipv6) {
+ /* get new ipv6 GW if we use OLSRv6 */
+ gw_def_finished_ipv6 = !(olsr_cnf->ip_version == AF_INET6);
+ }
+
+ if (!(gw_def_finished_ipv4 && gw_def_finished_ipv6)) {
+ gw_default_choose_gateway();
+ }
+}
+
+/*
+ * Handler functions
+ */
+
/* gateway handler callbacks */
static void gw_default_startup_handler(void) {
/* reset node count */
@@ -138,6 +187,14 @@ static void gw_default_startup_handler(void) {
olsr_set_timer(&gw_def_timer, olsr_cnf->smart_gw_period, 0, true, &gw_default_timer, NULL, 0);
}
+static void gw_default_choosegw_handler(bool ipv4, bool ipv6) {
+ olsr_gw_default_lookup_gateway(ipv4, ipv6);
+
+ if (!(gw_def_finished_ipv4 && gw_def_finished_ipv6)) {
+ gw_default_startup_handler();
+ }
+}
+
static void gw_default_update_handler(struct gateway_entry *gw) {
bool v4changed, v6changed;
@@ -160,49 +217,4 @@ static void gw_default_delete_handler(struct gateway_entry *gw) {
olsr_gw_default_lookup_gateway(isv4, isv6);
}
}
-
-static void gw_default_choosegw_handler(bool ipv4, bool ipv6) {
- olsr_gw_default_lookup_gateway(ipv4, ipv6);
-
- if (!(gw_def_finished_ipv4 && gw_def_finished_ipv6)) {
- gw_default_startup_handler();
- }
-}
-
-/**
- * initialization of default gateway handler
- */
-void olsr_gw_default_init(void) {
- /* initialize values */
- gw_def_timer = NULL;
- gw_def_finished_ipv4 = false;
- gw_def_finished_ipv6 = false;
- gw_def_nodecount = 0;
- gw_def_stablecount = 0;
- gw_def_timer = NULL;
-
- /* setup default handler */
- olsr_set_inetgw_handler(&gw_def_handler);
-}
-
-/**
- * Lookup a new gateway based on distance metric
- *
- * @param ipv4 lookup new v4 gateway
- * @param ipv6 lookup new v6 gateway
- */
-void olsr_gw_default_lookup_gateway(bool ipv4, bool ipv6) {
- if (ipv4) {
- /* get new ipv4 GW if we use OLSRv4 or NIIT */
- gw_def_finished_ipv4 = !(olsr_cnf->ip_version == AF_INET || olsr_cnf->use_niit);
- }
- if (ipv6) {
- /* get new ipv6 GW if we use OLSRv6 */
- gw_def_finished_ipv6 = !(olsr_cnf->ip_version == AF_INET6);
- }
-
- if (!(gw_def_finished_ipv4 && gw_def_finished_ipv6)) {
- gw_default_choose_gateway();
- }
-}
#endif
--
1.7.10.4
More information about the Olsr-dev
mailing list