eventscripts: 13.per_ip_routing should remove bogus routes on ipreallocated
authorMartin Schwenke <martin@meltin.net>
Fri, 15 Jun 2012 07:22:02 +0000 (17:22 +1000)
committerMartin Schwenke <martin@meltin.net>
Tue, 11 Sep 2012 02:52:22 +0000 (12:52 +1000)
Signed-off-by: Martin Schwenke <martin@meltin.net>
config/events.d/13.per_ip_routing

index ea3cffea80eba1f5409c76a9d992e6ddb7fa8be9..9f71669e5150c0092c4dc95207fff7bf58a5c5e8 100755 (executable)
@@ -293,6 +293,31 @@ add_missing_routes ()
     } || exit $?
 }
 
+# Remove rules/routes for addresses that we're not hosting.  If a
+# releaseip event failed in an earlier script then we might not have
+# had a chance to remove the corresponding rules/routes.
+remove_bogus_routes ()
+{
+    # Get a IPs current hosted by this node, each anchored with '@'.
+    _ips=$(ctdb ip -v -Y | awk -F: 'NR > 1 && $4 != "" {printf "@%s@\n", $2}')
+
+    ip rule show |
+    while read _p _x _i _x _t ; do
+       # Remove trailing colon after priority/preference.
+       _p="${_p%:}"
+       # Only remove rules that match our priority/preference.
+       [ "$CTDB_PER_IP_ROUTING_RULE_PREF" = "$_p" ] || continue
+       # Only remove rules for which we don't have an IP.  This could
+       # be done with grep, but let's do it with shell prefix removal
+       # to avoid unnecessary processes.  This falls through if
+       # "@${_i}@" isn't present in $_ips.
+       [ "$_ips" = "${_ips#*@${_i}@}" ] || continue
+
+       echo "Removing ip rule/routes for unhosted public address $_i"
+       del_routing_for_ip "$_i"
+    done
+}
+
 ######################################################################
 
 ctdb_check_args "$@"
@@ -354,6 +379,7 @@ case "$1" in
 
     ipreallocated)
        add_missing_routes
+       remove_bogus_routes
        ;;
 
     *)