Fake IPv6 recursive nexthops

I created this script as a really ugly patch that allows my customers to announce their ipv6 routes via BGP and let it work until the real IPv6 nexthops will be correctly resolved.
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.

/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"

+1
nice idea :slight_smile:

Thanks +100

Unfortunately this doesn’t scale:

[admin@xxxx] > /ipv6 route print count-only 
153622

Just to give an idea of how badly this performs (Yes MT, we really want you to fix the underlying issue, and this is a major issue now):

jkroon@plastiekpoot ~ $ time ssh --internal admin@core-a /ipv6 route find where bgp=yes
Trying MT hostname detection mechanism
SSH destination host: core-a (172.31.255.1)
CHECK:  Server is in CRM.

real	9m25.035s <----
user	0m0.084s
sys	0m0.001s

The route count is likely going to double if not triple in the next few days.