Community discussions

 
User avatar
paoloaga
Member Candidate
Member Candidate
Topic Author
Posts: 222
Joined: Tue Mar 08, 2011 2:52 am
Location: Vaprio d'Agogna (NO) - Italy
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
Frequent Visitor
Frequent Visitor
Posts: 88
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 :)

Who is online

Users browsing this forum: No registered users and 4 guests