Community discussions

MikroTik App
 
User avatar
paoloaga
Member Candidate
Member Candidate
Topic Author
Posts: 227
Joined: Tue Mar 08, 2011 2:52 am
Location: Lugano - Switzerland
Contact:

Fake IPv6 recursive nexthops

Mon Jul 29, 2019 1:47 pm

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"
 
User avatar
hknet
Member Candidate
Member Candidate
Posts: 126
Joined: Sun Jul 17, 2016 6:05 pm
Location: Vienna, Austria
Contact:

Re: Fake IPv6 recursive nexthops

Mon Jul 29, 2019 2:06 pm

+1
nice idea :)
 
mafiosa
Member Candidate
Member Candidate
Posts: 266
Joined: Fri Dec 09, 2016 8:10 pm
Location: Kolkata, India
Contact:

Re: Fake IPv6 recursive nexthops

Mon Jun 01, 2020 8:23 pm

Thanks +100
 
jkroon
Frequent Visitor
Frequent Visitor
Posts: 58
Joined: Thu Apr 03, 2008 2:18 am
Contact:

Re: Fake IPv6 recursive nexthops

Sat Aug 14, 2021 1:06 pm

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.

Who is online

Users browsing this forum: GoogleOther [Bot] and 25 guests