[Olsr-dev] [PATCH v1 15/23] gateway: add SmartGatewayMarkOffset{Egress, Tunnels} configuration parameters

Ferry Huberts (spam-protected)
Tue Dec 4 16:17:22 CET 2012


From: Ferry Huberts <(spam-protected)>

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 README-Olsr-Extensions              | 15 +++++++++-----
 files/olsrd.conf.default.full       | 16 +++++++++++++++
 files/olsrd.conf.default.lq         | 16 +++++++++++++++
 files/olsrd.conf.default.lq-fisheye | 16 +++++++++++++++
 lib/jsoninfo/src/olsrd_jsoninfo.c   |  2 ++
 src/cfgparser/cfgfile_gen.c         | 22 +++++++++++++++++++++
 src/cfgparser/olsrd_conf.c          | 39 +++++++++++++++++++++++++++++++++++++
 src/cfgparser/oparse.y              | 20 +++++++++++++++++++
 src/cfgparser/oscan.lex             | 10 ++++++++++
 src/olsr_cfg.h                      |  4 ++++
 10 files changed, 155 insertions(+), 5 deletions(-)

diff --git a/README-Olsr-Extensions b/README-Olsr-Extensions
index 50b5b28..35b5160 100644
--- a/README-Olsr-Extensions
+++ b/README-Olsr-Extensions
@@ -261,20 +261,25 @@ All other parameters will be ignored if SmartGateway is set to "no"
    SmartGatewayUseCount is larger than 1 (in which case it must be explicitly
    set).
    The default setting is 'not set'.
-3- SmartGatewayAllowNAT controls whether you want to allow the selection
+3- SmartGatewayMarkOffsetEgress and SmartGatewayMarkOffsetTunnels determine
+   the ranges of policy routing rule markings that are used in a multi-gateway
+   setup. The ranges are not allowed to overlap. Both settings are only
+   relevant when a multi-gateway setup is used.
+   The default settings are 91 and 101 respectively.
+4- SmartGatewayAllowNAT controls whether you want to allow the selection
    of an outgoing ipv4 gateway with NAT (Network Address Translation).
    The default setting is "yes".
-4- SmartGatewayPeriod determines the period (in milliseconds) on which
+5- SmartGatewayPeriod determines the period (in milliseconds) on which
    a new smart gateway selection is performed.
    The default setting is 10000 milliseconds.
-5- SmartGatewayStableCount determines the number of times the link state
+6- SmartGatewayStableCount determines the number of times the link state
    database must be stable before a new smart gateway is selected.
    The default setting is 6.
-6- SmartGatewayThreshold controls whether you want to allow re-selection
+7- SmartGatewayThreshold controls whether you want to allow re-selection
    of a new outgoing gateway if its routing cost is lower or equal to the
    configured percentage of the routing cost of the current gateway.
    The default setting is 0, which disables it.
-7- SmartGatewayWeightExitLinkUp, SmartGatewayWeightExitLinkDown,
+8- SmartGatewayWeightExitLinkUp, SmartGatewayWeightExitLinkDown,
    SmartGatewayWeightEtx and SmartGatewayDividerEtx control the weighing
    of gateway bandwidth and ETX costs.
 
diff --git a/files/olsrd.conf.default.full b/files/olsrd.conf.default.full
index 549b562..a99894c 100644
--- a/files/olsrd.conf.default.full
+++ b/files/olsrd.conf.default.full
@@ -158,6 +158,22 @@
 
 # SmartGatewayEgressInterfaces ""
 
+# Determines the offset of the smart gateway egress interfaces mark that are
+# used in the policy routing rules in a multi-gateway setup. Only relevant
+# when a multi-gateway setup is used.
+# (default is 91)
+
+# SmartGatewayMarkOffsetEgress 91
+
+# Determines the offset of the smart gateway tunnel interfaces mark that are
+# used in the policy routing rules in a multi-gateway setup. Only relevant
+# when a multi-gateway setup is used.
+# The ranges [egress offset, egress offset + egress count] and
+# [tunnel offset, tunnel offset + use count] are not allowed to overlap.
+# (default is 101)
+
+# SmartGatewayMarkOffsetTunnels 101
+
 # Allows the selection of a smartgateway with NAT (only for IPv4)
 # (default is "yes")
 
diff --git a/files/olsrd.conf.default.lq b/files/olsrd.conf.default.lq
index 2946d96..51c09d5 100644
--- a/files/olsrd.conf.default.lq
+++ b/files/olsrd.conf.default.lq
@@ -95,6 +95,22 @@
 
 # SmartGatewayEgressInterfaces ""
 
+# Determines the offset of the smart gateway egress interfaces mark that are
+# used in the policy routing rules in a multi-gateway setup. Only relevant
+# when a multi-gateway setup is used.
+# (default is 91)
+
+# SmartGatewayMarkOffsetEgress 91
+
+# Determines the offset of the smart gateway tunnel interfaces mark that are
+# used in the policy routing rules in a multi-gateway setup. Only relevant
+# when a multi-gateway setup is used.
+# The ranges [egress offset, egress offset + egress count] and
+# [tunnel offset, tunnel offset + use count] are not allowed to overlap.
+# (default is 101)
+
+# SmartGatewayMarkOffsetTunnels 101
+
 # Allows the selection of a smartgateway with NAT (only for IPv4)
 # (default is "yes")
 
diff --git a/files/olsrd.conf.default.lq-fisheye b/files/olsrd.conf.default.lq-fisheye
index 10a0dae..26c05d0 100644
--- a/files/olsrd.conf.default.lq-fisheye
+++ b/files/olsrd.conf.default.lq-fisheye
@@ -95,6 +95,22 @@
 
 # SmartGatewayEgressInterfaces ""
 
+# Determines the offset of the smart gateway egress interfaces mark that are
+# used in the policy routing rules in a multi-gateway setup. Only relevant
+# when a multi-gateway setup is used.
+# (default is 91)
+
+# SmartGatewayMarkOffsetEgress 91
+
+# Determines the offset of the smart gateway tunnel interfaces mark that are
+# used in the policy routing rules in a multi-gateway setup. Only relevant
+# when a multi-gateway setup is used.
+# The ranges [egress offset, egress offset + egress count] and
+# [tunnel offset, tunnel offset + use count] are not allowed to overlap.
+# (default is 101)
+
+# SmartGatewayMarkOffsetTunnels 101
+
 # Allows the selection of a smartgateway with NAT (only for IPv4)
 # (default is "yes")
 
diff --git a/lib/jsoninfo/src/olsrd_jsoninfo.c b/lib/jsoninfo/src/olsrd_jsoninfo.c
index 4636365..b5b9f4c 100644
--- a/lib/jsoninfo/src/olsrd_jsoninfo.c
+++ b/lib/jsoninfo/src/olsrd_jsoninfo.c
@@ -1002,6 +1002,8 @@ ipc_print_config(struct autobuf *abuf)
       abuf_json_string(abuf, "smartGatewayEgressInterfaces", egressbuf.buf);
       abuf_free(&egressbuf);
     }
+    abuf_json_int(abuf, "smartGatewayMarkOffsetEgress", olsr_cnf->smart_gw_mark_offset_egress);
+    abuf_json_int(abuf, "smartGatewayMarkOffsetTunnels", olsr_cnf->smart_gw_mark_offset_tunnels);
     abuf_json_boolean(abuf, "smartGatewayAllowNat", olsr_cnf->smart_gw_allow_nat);
     abuf_json_boolean(abuf, "smartGatewayUplinkNat", olsr_cnf->smart_gw_uplink_nat);
     abuf_json_int(abuf, "smartGatewayPeriod", olsr_cnf->smart_gw_period);
diff --git a/src/cfgparser/cfgfile_gen.c b/src/cfgparser/cfgfile_gen.c
index 6fb7761..88e8bce 100644
--- a/src/cfgparser/cfgfile_gen.c
+++ b/src/cfgparser/cfgfile_gen.c
@@ -465,6 +465,28 @@ void olsrd_write_cnf_autobuf(struct autobuf *out, struct olsrd_config *cnf) {
   }
   abuf_puts(out,
     "\n"
+    "# Determines the offset of the smart gateway egress interfaces mark that are\n"
+    "# used in the policy routing rules in a multi-gateway setup. Only relevant\n"
+    "# when a multi-gateway setup is used.\n"
+    "# (default is 91)\n"
+    "\n");
+  abuf_appendf(out, "%sSmartGatewayMarkOffsetEgress %u\n",
+      cnf->smart_gw_mark_offset_egress == DEF_GW_MARK_OFFSET_EGRESS ? "# " : "",
+      cnf->smart_gw_mark_offset_egress);
+  abuf_puts(out,
+    "\n"
+    "# Determines the offset of the smart gateway tunnel interfaces mark that are\n"
+    "# used in the policy routing rules in a multi-gateway setup. Only relevant\n"
+    "# when a multi-gateway setup is used.\n"
+    "# The ranges [egress offset, egress offset + egress count] and\n"
+    "# [tunnel offset, tunnel offset + use count] are not allowed to overlap.\n"
+    "# (default is 101)\n"
+    "\n");
+  abuf_appendf(out, "%sSmartGatewayMarkOffsetTunnels %u\n",
+      cnf->smart_gw_mark_offset_tunnels == DEF_GW_MARK_OFFSET_TUNNELS ? "# " : "",
+      cnf->smart_gw_mark_offset_tunnels);
+  abuf_puts(out,
+    "\n"
     "# Allows the selection of a smartgateway with NAT (only for IPv4)\n"
     "# (default is \"yes\")\n"
     "\n");
diff --git a/src/cfgparser/olsrd_conf.c b/src/cfgparser/olsrd_conf.c
index ebcef3d..8b2d3ec 100644
--- a/src/cfgparser/olsrd_conf.c
+++ b/src/cfgparser/olsrd_conf.c
@@ -588,6 +588,39 @@ olsrd_sanity_check_cnf(struct olsrd_config *cnf)
           cnf->smart_gw_egress_interfaces_count, MAX_SMARTGW_EGRESS_INTERFACE_COUNT_MAX);
       return -1;
     }
+
+    {
+      uint8_t egressLow = cnf->smart_gw_mark_offset_egress;
+      uint8_t egressHigh = egressLow + cnf->smart_gw_egress_interfaces_count - 1;
+      uint8_t tunnelsLow = cnf->smart_gw_mark_offset_tunnels;
+      uint8_t tunnelsHigh = tunnelsLow + cnf->smart_gw_use_count - 1;
+      bool overlap = false;
+
+      /* check that the egress interface marks range does not overflow */
+      if (egressLow > (UINT8_MAX - cnf->smart_gw_egress_interfaces_count)) {
+        fprintf(stderr, "Error, egress interface mark offset %u together with egress interface count %u overflows range [0, %u]\n",
+            egressLow, cnf->smart_gw_egress_interfaces_count, UINT8_MAX);
+        return -1;
+      }
+
+      /* check that the tunnel interface marks range does not overflow */
+      if (tunnelsLow > (UINT8_MAX - cnf->smart_gw_use_count)) {
+        fprintf(stderr, "Error, tunnel interface mark offset %u together with use count %u overflows range [0, %u]\n",
+            tunnelsLow, cnf->smart_gw_use_count, UINT8_MAX);
+        return -1;
+      }
+
+      /* check that the egress and tunnel marks ranges do not overlap */
+      overlap =            ((tunnelsLow <= egressLow)   && (egressLow   <= tunnelsHigh));
+      overlap = overlap || ((tunnelsLow <= egressHigh)  && (egressHigh  <= tunnelsHigh));
+      overlap = overlap || ((egressLow  <= tunnelsLow)  && (tunnelsLow  <= egressHigh));
+      overlap = overlap || ((egressLow  <= tunnelsHigh) && (tunnelsHigh <= egressHigh));
+      if (overlap) {
+        fprintf(stderr, "Error, egress interface mark range [%u, %u] overlaps with tunnel interface mark range [%u, %u]\n",
+            egressLow, egressHigh, tunnelsLow, tunnelsHigh);
+        return -1;
+      }
+    }
   }
 
   if (cnf->smart_gw_period < MIN_SMARTGW_PERIOD || cnf->smart_gw_period > MAX_SMARTGW_PERIOD) {
@@ -826,6 +859,8 @@ set_default_cnf(struct olsrd_config *cnf)
   cnf->smart_gw_use_count = DEF_GW_USE_COUNT;
   cnf->smart_gw_egress_interfaces = NULL;
   cnf->smart_gw_egress_interfaces_count = 0;
+  cnf->smart_gw_mark_offset_egress = DEF_GW_MARK_OFFSET_EGRESS;
+  cnf->smart_gw_mark_offset_tunnels = DEF_GW_MARK_OFFSET_TUNNELS;
   cnf->smart_gw_allow_nat = DEF_GW_ALLOW_NAT;
   cnf->smart_gw_period = DEF_GW_PERIOD;
   cnf->smart_gw_stablecount = DEF_GW_STABLE_COUNT;
@@ -966,6 +1001,10 @@ olsrd_print_cnf(struct olsrd_config *cnf)
   }
   printf("\n");
 
+  printf("SmGw. Mark Egress: %u\n", cnf->smart_gw_mark_offset_egress);
+
+  printf("SmGw. Mark Tunnel: %u\n", cnf->smart_gw_mark_offset_tunnels);
+
   printf("SmGw. Allow NAT  : %s\n", cnf->smart_gw_allow_nat ? "yes" : "no");
 
   printf("SmGw. period     : %d\n", cnf->smart_gw_period);
diff --git a/src/cfgparser/oparse.y b/src/cfgparser/oparse.y
index 4cb8e1d..c637dc7 100644
--- a/src/cfgparser/oparse.y
+++ b/src/cfgparser/oparse.y
@@ -218,6 +218,8 @@ static int add_ipv6_addr(YYSTYPE ipaddr_arg, YYSTYPE prefixlen_arg)
 %token TOK_SMART_GW
 %token TOK_SMART_GW_USE_COUNT
 %token TOK_SMART_GW_EGRESS_IFS
+%token TOK_SMART_GW_MARK_OFFSET_EGRESS
+%token TOK_SMART_GW_MARK_OFFSET_TUNNELS
 %token TOK_SMART_GW_ALLOW_NAT
 %token TOK_SMART_GW_PERIOD
 %token TOK_SMART_GW_STABLECOUNT
@@ -306,6 +308,8 @@ stmt:       idebug
           | suse_niit
           | bsmart_gw
           | ismart_gw_use_count
+          | ismart_gw_mark_offset_egress
+          | ismart_gw_mark_offset_tunnels
           | bsmart_gw_allow_nat
           | ismart_gw_period
           | asmart_gw_stablecount
@@ -1386,6 +1390,22 @@ sgw_egress_if: TOK_STRING
 }
 ;
 
+ismart_gw_mark_offset_egress: TOK_SMART_GW_MARK_OFFSET_EGRESS TOK_INTEGER
+{
+  PARSER_DEBUG_PRINTF("Smart gateway mark offset egress interfaces: %d\n", $2->integer);
+  olsr_cnf->smart_gw_mark_offset_egress = $2->integer;
+  free($2);
+}
+;
+
+ismart_gw_mark_offset_tunnels: TOK_SMART_GW_MARK_OFFSET_TUNNELS TOK_INTEGER
+{
+  PARSER_DEBUG_PRINTF("Smart gateway mark offset tunnel interfaces: %d\n", $2->integer);
+  olsr_cnf->smart_gw_mark_offset_tunnels = $2->integer;
+  free($2);
+}
+;
+
 bsmart_gw_allow_nat: TOK_SMART_GW_ALLOW_NAT TOK_BOOLEAN
 {
 	PARSER_DEBUG_PRINTF("Smart gateway allow client nat: %s\n", $2->boolean ? "yes" : "no");
diff --git a/src/cfgparser/oscan.lex b/src/cfgparser/oscan.lex
index c40fa3a..a86c161 100644
--- a/src/cfgparser/oscan.lex
+++ b/src/cfgparser/oscan.lex
@@ -476,6 +476,16 @@ IPV6ADDR {IPV6PAT1}|{IPV6PAT2}|{IPV6PAT3}|{IPV6PAT4}|{IPV6PAT5}|{IPV6PAT6}|{IPV6
     return TOK_SMART_GW_EGRESS_IFS;
 }
 
+"SmartGatewayMarkOffsetEgress" {
+    yylval = NULL;
+    return TOK_SMART_GW_MARK_OFFSET_EGRESS;
+}
+
+"SmartGatewayMarkOffsetTunnels" {
+    yylval = NULL;
+    return TOK_SMART_GW_MARK_OFFSET_TUNNELS;
+}
+
 "SmartGatewayAllowNAT" {
     yylval = NULL;
     return TOK_SMART_GW_ALLOW_NAT;
diff --git a/src/olsr_cfg.h b/src/olsr_cfg.h
index 3686497..e6f6a49 100644
--- a/src/olsr_cfg.h
+++ b/src/olsr_cfg.h
@@ -82,6 +82,8 @@
 #define DEF_USE_NIIT         true
 #define DEF_SMART_GW         false
 #define DEF_GW_USE_COUNT     1
+#define DEF_GW_MARK_OFFSET_EGRESS   91
+#define DEF_GW_MARK_OFFSET_TUNNELS 101
 #define DEF_GW_PERIOD        10*1000
 #define DEF_GW_STABLE_COUNT  6
 #define DEF_GW_ALLOW_NAT     true
@@ -291,6 +293,8 @@ struct olsrd_config {
   uint8_t smart_gw_use_count;
   struct sgw_egress_if * smart_gw_egress_interfaces;
   uint8_t smart_gw_egress_interfaces_count;
+  uint8_t smart_gw_mark_offset_egress;
+  uint8_t smart_gw_mark_offset_tunnels;
   uint32_t smart_gw_period;
   uint8_t smart_gw_stablecount;
   uint8_t smart_gw_thresh;
-- 
1.7.11.7





More information about the Olsr-dev mailing list