Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- :local rname "rt:main:out"
- :local rfname "rt:failover:out"
- :local lname "rt:main:lan"
- :local lfname "rt:failover:lan"
- :local mtname "rt:mt:out"
- :local uname "uplink_rt"
- :local createRoute do={
- :local count [/ip route print count-only where comment=$1]
- if ($count=0) do={
- # Creating main route
- /ip route add distance=$2 gateway=$3 comment=$1 routing-table=$4 check-gateway=$5
- }
- }
- :local updateRoute do={
- :local route [/ip route find where comment=$1]
- :if ([/ip route get $route gateway] != $2) do={
- /ip route set $route gateway=$2
- }
- }
- :if ($bound=1) do={
- :local rcount [/ip route print count-only where comment=$rname]
- # Main route
- :if ($rcount=0) do={
- $createRoute $rname 1 $"gateway-address" "rout_ISP1" "ping"
- } else={
- :if ($rcount>1) do={
- :error "Multiple main routes found"
- }
- $updateRoute $rname $"gateway-address"
- }
- # Fallback route
- :local rfcount [/ip route print count-only where comment=$rfname]
- :if ($rfcount=0) do={
- $createRoute $rfname 2 $"gateway-address" "rout_ISP2" "none"
- } else={
- :if ($rfcount > 1) do={
- :error "Multiple fallback routes found"
- }
- $updateRoute $rfname $"gateway-address"
- }
- # Main route for LAN
- :local lcount [/ip route print count-only where comment=$lname]
- :if ($lcount=0) do={
- $createRoute $lname 1 $"gateway-address" "lout_ISP1" "ping"
- } else={
- :if ($lcount > 1) do={
- :error "Multiple fallback routes found"
- }
- $updateRoute $lname $"gateway-address"
- }
- # Fallback route for LAN
- :local lfcount [/ip route print count-only where comment=$lfname]
- :if ($lfcount=0) do={
- $createRoute $lfname 2 $"gateway-address" "lout_ISP2" "none"
- } else={
- :if ($lfcount > 1) do={
- :error "Multiple fallback routes found"
- }
- $updateRoute $lfname $"gateway-address"
- }
- :local mtcount [/ip route print count-only where comment=$mtname]
- :if ($mtcount=0) do={
- $createRoute $mtname 2 $"gateway-address" "main" "none"
- } else={
- :if ($mtcount > 1) do={
- :error "Multiple fallback routes found"
- }
- $updateRoute $mtname $"gateway-address"
- }
- # Updating current IP just in case
- /ip firewall address-list remove [/ip firewall address-list find list=$lname]
- /ip firewall address-list add list=$uname address=$"lease-address"
- } else={
- /ip route remove [find comment=$rname]
- /ip route remove [find comment=$rfname]
- /ip route remove [find comment=$lname]
- /ip route remove [find comment=$lfname]
- /ip route remove [find comment=$mtname]
- }
- }
Add Comment
Please, Sign In to add comment