ctdb-eventscripts: CTDB_NATGW_STATIC_ROUTES can specify gateways
authorMartin Schwenke <martin@meltin.net>
Fri, 7 Mar 2014 04:33:17 +0000 (15:33 +1100)
committerAmitay Isaacs <amitay@samba.org>
Wed, 26 Mar 2014 03:21:42 +0000 (04:21 +0100)
Extend CTDB_NATGW_STATIC_ROUTES so that each network can have an
optional gateway that overrides CTDB_NATGW_DEFAULT_GATEWAY.

Signed-off-by: Martin Schwenke <martin@meltin.net>
ctdb/config/events.d/11.natgw
ctdb/doc/ctdbd.conf.5.xml

index 45b4d212ae409103bd262eb91eca14a699d3d811..b2a219cdebc132ec08d00fb515120b9fc7b11926 100755 (executable)
@@ -46,7 +46,8 @@ natgw_clear ()
 
     delete_ip_from_iface \
        $CTDB_NATGW_PUBLIC_IFACE $_ip $_maskbits >/dev/null 2>&1
-    for _net in $CTDB_NATGW_STATIC_ROUTES ; do
+    for _net_gw in $CTDB_NATGW_STATIC_ROUTES ; do
+       _net="${_net_gw%@*}"
        ip route del "$_net" metric 10 >/dev/null 2>/dev/null
     done
 
@@ -74,18 +75,25 @@ natgw_set_master ()
        -d $ctdb_natgw_public_ip_host -j REJECT 2>/dev/null
 
     ip addr add $CTDB_NATGW_PUBLIC_IP dev $CTDB_NATGW_PUBLIC_IFACE
-    if [ -n "$CTDB_NATGW_DEFAULT_GATEWAY" ] ; then
-       for _net in $CTDB_NATGW_STATIC_ROUTES ; do
-           ip route add "$_net" metric 10 via $CTDB_NATGW_DEFAULT_GATEWAY
-       done
-    fi
+    for _net_gw in $CTDB_NATGW_STATIC_ROUTES ; do
+       _net="${_net_gw%@*}"
+       if [ "$_net" != "$_net_gw" ] ; then
+           _gw="${_net_gw#*@}"
+       else
+           _gw="$CTDB_NATGW_DEFAULT_GATEWAY"
+       fi
+
+       [ -n "$_gw" ] || continue
+       ip route add "$_net" metric 10 via "$_gw"
+    done
 }
 
 natgw_set_slave ()
 {
     _natgwip="$1"
 
-    for _net in $CTDB_NATGW_STATIC_ROUTES ; do
+    for _net_gw in $CTDB_NATGW_STATIC_ROUTES ; do
+       _net="${_net_gw%@*}"
        ip route add "$_net" via "$_natgwip" metric 10
     done
 
index ff064cfffd12c912cd8f5eee4433e2e64bccfc44..188a4df093f8c1866cd754585214d238e03af4f0 100644 (file)
        </varlistentry>
 
        <varlistentry>
-         <term>CTDB_NATGW_STATIC_ROUTES=<parameter>IPADDR/MASK</parameter> ...</term>
+         <term>CTDB_NATGW_STATIC_ROUTES=<parameter>IPADDR/MASK[@GATEWAY]</parameter> ...</term>
          <listitem>
            <para>
              Each IPADDR/MASK identifies a network or host to which
              can not reach required infrastructure, that overrides
              the NAT gateway default route.
            </para>
+           <para>
+             If GATEWAY is specified then the corresponding route on
+             the NATGW master node will be via GATEWAY.  Such routes
+             are created even if
+             <varname>CTDB_NATGW_DEFAULT_GATEWAY</varname> is not
+             specified.  If GATEWAY is not specified for some
+             networks then routes are only created on the NATGW
+             master node for those networks if
+             <varname>CTDB_NATGW_DEFAULT_GATEWAY</varname> is
+             specified.
+           </para>
            <para>
              This should be used with care to avoid causing traffic
              to unnecessarily double-hop through the NAT gateway