[Olsr-dev] [PATCH v1 2/3] sgw: implement HNA expiry

Ferry Huberts (spam-protected)
Fri May 8 14:22:47 CEST 2015


From: Ferry Huberts <(spam-protected)>

HNA expiry wasn't implemented, making sgw in a dynamic
environment "rather" problematic.

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 src/gateway.c | 31 ++++++++++++++++++++++++++++++-
 src/gateway.h |  3 ++-
 src/hna_set.c |  2 +-
 3 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/src/gateway.c b/src/gateway.c
index 88092de..56ec469 100644
--- a/src/gateway.c
+++ b/src/gateway.c
@@ -553,6 +553,20 @@ static void smartgw_tunnel_monitor(int if_index, struct interface_olsr *ifh, enu
 }
 
 /**
+ * Timer callback to expire a gateway entry
+ *
+ * @param ptr a pointer to the smart gateway HNA to expire (struct gateway_entry*)
+ */
+static void expire_gateway_handler(void *ptr) {
+  struct gateway_entry *gw = ptr;
+
+  assert(gw);
+
+  /* remove gateway entry */
+  olsr_delete_gateway_entry(&gw->originator, gw->external_prefix.prefix_len, false);
+}
+
+/**
  * Timer callback to remove and cleanup a gateway entry
  *
  * @param ptr
@@ -1074,8 +1088,9 @@ bool olsr_is_smart_gateway(struct olsr_ip_prefix *prefix, union olsr_ip_addr *ma
  * @param mask netmask of the HNA
  * @param prefixlen of the HNA
  * @param seqno the sequence number of the HNA
+ * @param vtime the validity time of the HNA
  */
-void olsr_update_gateway_entry(union olsr_ip_addr *originator, union olsr_ip_addr *mask, int prefixlen, uint16_t seqno) {
+void olsr_update_gateway_entry(union olsr_ip_addr *originator, union olsr_ip_addr *mask, int prefixlen, uint16_t seqno, olsr_reltime vtime) {
   struct gw_container_entry * new_gw_in_list;
   uint8_t *ptr;
   int64_t prev_path_cost = 0;
@@ -1124,6 +1139,14 @@ void olsr_update_gateway_entry(union olsr_ip_addr *originator, union olsr_ip_add
     }
   }
 
+  if (!gw->expire_timer) {
+    /* start expire timer */
+    olsr_set_timer(&gw->expire_timer, vtime, 0, false, expire_gateway_handler, gw, NULL);
+  } else {
+    /* restart expire timer */
+    olsr_change_timer(gw->expire_timer, vtime, 0, false);
+  }
+
   /* stop cleanup timer if necessary */
   if (gw->cleanup_timer) {
     olsr_stop_timer(gw->cleanup_timer);
@@ -1193,6 +1216,12 @@ static void olsr_delete_gateway_tree_entry(struct gateway_entry * gw, uint8_t pr
     return;
   }
 
+  if (gw->expire_timer) {
+    /* stop expire timer */
+    olsr_stop_timer(gw->expire_timer);
+    gw->expire_timer = NULL;
+  }
+
   if (immediate && gw->cleanup_timer) {
     /* stop timer if we have to remove immediately */
     olsr_stop_timer(gw->cleanup_timer);
diff --git a/src/gateway.h b/src/gateway.h
index 4354018..f547896 100644
--- a/src/gateway.h
+++ b/src/gateway.h
@@ -67,6 +67,7 @@ struct gateway_entry {
     bool ipv4nat;
     bool ipv6;
 
+    struct timer_entry *expire_timer;
     struct timer_entry *cleanup_timer;
     uint16_t seqno;
 };
@@ -198,7 +199,7 @@ void refresh_smartgw_netmask(void);
  */
 
 bool olsr_is_smart_gateway(struct olsr_ip_prefix *prefix, union olsr_ip_addr *net);
-void olsr_update_gateway_entry(union olsr_ip_addr *originator, union olsr_ip_addr *mask, int prefixlen, uint16_t seqno);
+void olsr_update_gateway_entry(union olsr_ip_addr *originator, union olsr_ip_addr *mask, int prefixlen, uint16_t seqno, olsr_reltime vtime);
 void olsr_delete_gateway_entry(union olsr_ip_addr *originator, uint8_t prefixlen, bool immediate);
 void olsr_trigger_gatewayloss_check(void);
 
diff --git a/src/hna_set.c b/src/hna_set.c
index 72310d9..47dd897 100644
--- a/src/hna_set.c
+++ b/src/hna_set.c
@@ -443,7 +443,7 @@ olsr_input_hna(union olsr_message *m, struct interface_olsr *in_if __attribute__
 
 #ifdef __linux__
     if (olsr_cnf->smart_gw_active && olsr_is_smart_gateway(&prefix, &mask)) {
-      olsr_update_gateway_entry(&originator, &mask, prefix.prefix_len, msg_seq_number);
+      olsr_update_gateway_entry(&originator, &mask, prefix.prefix_len, msg_seq_number, vtime);
       continue;
     }
 #endif /* __linux__ */
-- 
2.1.0





More information about the Olsr-dev mailing list