sgw: track the interface index of an egress interface
authorFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 29 Oct 2014 12:52:38 +0000 (13:52 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 12 Nov 2014 10:45:25 +0000 (11:45 +0100)
We need this later.

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
src/egressFile.c
src/egressFile.h
src/egressTypes.h
src/gateway.c

index daee98d..0be8a84 100644 (file)
@@ -258,6 +258,26 @@ struct sgw_egress_if * findEgressInterface(char * name) {
   return NULL ;
 }
 
+/**
+ * Find an egress interface in the configuration by if_index
+ *
+ * @param if_index the index of the egress interface
+ * @return the pointer to the egress interface, NULL when not found
+ */
+struct sgw_egress_if * findEgressInterfaceByIndex(int if_index) {
+  if (if_index > 0) {
+    struct sgw_egress_if * egress_if = olsr_cnf->smart_gw_egress_interfaces;
+    while (egress_if) {
+      if (egress_if->if_index == if_index) {
+        return egress_if;
+      }
+      egress_if = egress_if->next;
+    }
+  }
+
+  return NULL ;
+}
+
 /**
  * Calculate the costs from the bandwidth parameters
  *
index 56b8810..bdef983 100644 (file)
@@ -20,6 +20,7 @@ bool startEgressFile(void);
 void stopEgressFile(void);
 
 struct sgw_egress_if * findEgressInterface(char * name);
+struct sgw_egress_if * findEgressInterfaceByIndex(int if_index);
 
 bool egressBwCalculateCosts(struct egress_if_bw * bw, bool up);
 void egressBwClear(struct egress_if_bw * egress_if, bool up);
index 11652bf..7d72a5d 100644 (file)
@@ -33,12 +33,14 @@ struct sgw_egress_if {
   /* configured through the SmartGatewayEgressInterfaces configuration parameter */
   char *name;
 
+  /* updated through the smartgw_tunnel_monitor function */
+  int if_index;
+
   /* configured through the SmartGatewayTablesOffset and SmartGatewayRulesOffset configuration parameters */
   uint8_t tableNr; /**< routing table number */
   uint8_t ruleNr; /**< IP rule number */
   uint8_t bypassRuleNr; /**< bypass IP rule number */
 
-
   /* configured through the readEgressFile function */
   struct egress_if_bw bwPrevious;
   struct egress_if_bw bwCurrent;
index e89f7ab..a6d551b 100644 (file)
@@ -661,6 +661,8 @@ int olsr_startup_gateways(void) {
   {
     struct sgw_egress_if * egress_if = olsr_cnf->smart_gw_egress_interfaces;
     while (egress_if) {
+      egress_if->if_index = if_nametoindex(egress_if->name);
+
       egressBwClear(&egress_if->bwPrevious, false);
       egressBwClear(&egress_if->bwCurrent, false);
       egress_if->bwCostsChanged = egressBwCostsChanged(egress_if);