When we are no longer the natgw master, dont put the natgw ip on loopback.
[sahlberg/ctdb.git] / config / events.d / 11.natgw
index 46de7fa617f07d651043eb3e89e55eae0b631581..1d5ba0f5570a804a7d5e782259cc002aec300667 100755 (executable)
@@ -8,13 +8,22 @@
 . $CTDB_BASE/functions
 loadconfig
 
-[ -z "$CTDB_NATGW_PUBLIC_IFACE" ] && exit 0
+[ -z "$CTDB_NATGW_NODES" ] && exit 0
+
+# Update capabilities to show whether we support teh NATGW capability or not
+if [ "$CTDB_NATGW_SLAVE_ONLY" = "yes" ] ; then
+       ctdb setnatgwstate off
+else
+       ctdb setnatgwstate on
+fi
 
 delete_all() {
        local _ip=`echo $CTDB_NATGW_PUBLIC_IP | cut -d '/' -f1`
        local _maskbits=`echo $CTDB_NATGW_PUBLIC_IP | cut -d '/' -f2`
 
-       delete_ip_from_iface $CTDB_NATGW_PUBLIC_IFACE $_ip $_maskbits
+       [ -z "$CTDB_NATGW_PUBLIC_IFACE" ] || {
+           delete_ip_from_iface $CTDB_NATGW_PUBLIC_IFACE $_ip $_maskbits 2>/dev/null
+       }
        delete_ip_from_iface lo $_ip 32
 
        ip route del 0.0.0.0/0 metric 10 >/dev/null 2>/dev/null
@@ -24,7 +33,7 @@ delete_all() {
        iptables -D POSTROUTING -t nat -s $CTDB_NATGW_PRIVATE_NETWORK -d ! $CTDB_NATGW_PRIVATE_NETWORK -j MASQUERADE >/dev/null 2>/dev/null
 
        # remove any iptables rule we may have on this address
-       iptables -D INPUT -p tcp --syn -d _ip/32 -j REJECT 2>/dev/null
+       iptables -D INPUT -p tcp --syn -d $_ip/32 -j REJECT 2>/dev/null
 }
 
 case "$1" in 
@@ -42,11 +51,9 @@ case "$1" in
        echo 3 > /proc/sys/net/ipv4/conf/all/arp_ignore
        # do not send out arp requests from loopback addresses
        echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
-       # update capabilities to show we are using natgw
-       ctdb setnatgwstate on
        ;;
 
-    recovered|updatenatgw)
+    recovered|updatenatgw|ipreallocated)
        MYPNN=`ctdb pnn | cut -d: -f2`
        NATGWMASTER=`ctdb natgwlist | head -1 | sed -e "s/ .*//"`
        NATGWIP=`ctdb natgwlist | head -1 | sed -e "s/^[^ ]* *//"`
@@ -59,7 +66,7 @@ case "$1" in
 
 
        if [ "$NATGWMASTER" = "-1" ]; then
-               echo "There is not NATGW master node"
+               echo "There is no NATGW master node"
                exit 1
        fi
 
@@ -84,8 +91,10 @@ case "$1" in
                # We do this so that the ip address will exist on a
                # non-loopback interface so that samba may send it along in the
                # KDC requests.
-               ip addr add $CTDB_NATGW_PUBLIC_IP_HOST dev lo scope host
                ip route add 0.0.0.0/0 via $NATGWIP metric 10
+               # Make sure winbindd does not stay bound to this address
+               # if we are no longer natgwmaster
+               smbcontrol winbindd ip-dropped $CTDB_NATGW_PUBLIC_IP >/dev/null 2>/dev/null
        fi
 
        # flush our route cache