It uses BGP MED (1 to 254) to choose the preferred path in case of multiple links/routes.
I know it's extremely ugly, but it just works.
Code: Select all
/system script remove [find name=ipv6bgpfix]
/system script add name=ipv6bgpfix source={
:local comment "mikroshit bgp patch"
:local commentlen [:len $comment]
:local bgproutes [/ipv6 route find where bgp=yes]
:local allstaticroutes [/ipv6 route find where static]
:local staticbgproutes
:foreach S in=$allstaticroutes do={
:if ([:pick [/ipv6 route get $S comment] 0 $commentlen] = "$comment") do={
:set staticbgproutes ($staticbgproutes, $S)
}
}
:foreach R in=$bgproutes do={
:local bgpmed [:tonum [/ipv6 route get $R bgp-med]]
:local dstaddr [/ipv6 route get $R dst-address]
:local localgw [/ipv6 route get $R gateway]
:local localpref [/ipv6 route get $R bgp-local-pref]
:local gateway [/routing bgp peer get [/ipv6 route get $R received-from] remote-address]
:local staticcomment "$comment $dstaddr $localgw $localpref $bgpmed"
:local staticroute [/ipv6 route find where static=yes and comment="$staticcomment"]
:if ($bgpmed < 1) do={
:set bgpmed 200
}
:if ($bgpmed > 254) do={
:set bgpmed 254
}
:if ([:len $staticroute] > 0) do={
/ipv6 route set $staticroute check-gateway=ping distance=$bgpmed gateway="$gateway"
:local oldstaticroutes $staticbgproutes
:set staticbgproutes
:foreach S in=$staticbgproutes do={
:if ($S != $staticroute) do={
:set staticbgproutes ($staticbgproutes, $S)
}
}
} else={
/ipv6 route add check-gateway=ping comment="$staticcomment" distance=$bgpmed dst-address="$dstaddr" gateway="$gateway"
}
}
:foreach R in=$staticbgproutes do={
/ipv6 route remove $R
}
}
/system scheduler remove [find name=ipv6bgpfix]
/system scheduler add interval=2m name=ipv6bgpfix on-event="/system script run ipv6bgpfix"