sgw: track the up status of an egress interface
authorFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 29 Oct 2014 13:00:41 +0000 (14:00 +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/egressTypes.h
src/gateway.c

index 0be8a84..3744988 100644 (file)
@@ -635,7 +635,7 @@ static bool readEgressFile(char * fileName) {
     }
 
     if (!uplink || !downlink) {
-      egressBwClear(&egress_if->bwCurrent, false);
+      egressBwClear(&egress_if->bwCurrent, egress_if->upCurrent);
     } else {
       egress_if->bwCurrent.egressUk = uplink;
       egress_if->bwCurrent.egressDk = downlink;
@@ -646,7 +646,7 @@ static bool readEgressFile(char * fileName) {
       egress_if->bwCurrent.networkSet = networkSet;
       egress_if->bwCurrent.gatewaySet = gatewaySet;
 
-      egressBwCalculateCosts(&egress_if->bwCurrent, true);
+      egressBwCalculateCosts(&egress_if->bwCurrent, egress_if->upCurrent);
     }
 
     egress_if->inEgressFile = true;
@@ -664,7 +664,7 @@ static bool readEgressFile(char * fileName) {
     struct sgw_egress_if * egress_if = olsr_cnf->smart_gw_egress_interfaces;
     while (egress_if) {
       if (!egress_if->inEgressFile) {
-        egressBwClear(&egress_if->bwCurrent, false);
+        egressBwClear(&egress_if->bwCurrent, egress_if->upCurrent);
       }
 
       egress_if->bwCostsChanged = egressBwCostsChanged(egress_if);
index 7d72a5d..70170b8 100644 (file)
@@ -41,6 +41,11 @@ struct sgw_egress_if {
   uint8_t ruleNr; /**< IP rule number */
   uint8_t bypassRuleNr; /**< bypass IP rule number */
 
+  /* updated through smartgw_tunnel_monitor */
+  bool upPrevious;
+  bool upCurrent;
+  bool upChanged;
+
   /* configured through the readEgressFile function */
   struct egress_if_bw bwPrevious;
   struct egress_if_bw bwCurrent;
index a6d551b..20f8d70 100644 (file)
@@ -663,8 +663,11 @@ int olsr_startup_gateways(void) {
     while (egress_if) {
       egress_if->if_index = if_nametoindex(egress_if->name);
 
-      egressBwClear(&egress_if->bwPrevious, false);
-      egressBwClear(&egress_if->bwCurrent, false);
+      egress_if->upPrevious = egress_if->upCurrent = olsr_if_isup(egress_if->name);
+      egress_if->upChanged = (egress_if->upPrevious != egress_if->upCurrent);
+
+      egressBwClear(&egress_if->bwPrevious, egress_if->upPrevious);
+      egressBwClear(&egress_if->bwCurrent, egress_if->upCurrent);
       egress_if->bwCostsChanged = egressBwCostsChanged(egress_if);
       egress_if->bwNetworkChanged = egressBwNetworkChanged(egress_if);
       egress_if->bwGatewayChanged = egressBwGatewayChanged(egress_if);
@@ -721,8 +724,12 @@ void olsr_shutdown_gateways(void) {
   {
     struct sgw_egress_if * egress_if = olsr_cnf->smart_gw_egress_interfaces;
     while (egress_if) {
+      egress_if->upPrevious = egress_if->upCurrent;
+      egress_if->upCurrent = false;
+      egress_if->upChanged = (egress_if->upPrevious != egress_if->upCurrent);
+
       egress_if->bwPrevious = egress_if->bwCurrent;
-      egressBwClear(&egress_if->bwCurrent, false);
+      egressBwClear(&egress_if->bwCurrent, egress_if->upCurrent);
       egress_if->bwCostsChanged = egressBwCostsChanged(egress_if);
       egress_if->bwNetworkChanged = egressBwNetworkChanged(egress_if);
       egress_if->bwGatewayChanged = egressBwGatewayChanged(egress_if);