# # RIPv2 based AMPR Tunnel setup script for RouterOS # # by YO2LOJ, Marius # # RIP routes from AMPR GW go into an unused routing table # All dynamic tunnel names start with "ampr-" # Make sure you have no other IPIP tunnels using such names. # # Setup example: # # You need to set up a initial tunnel to amprgw # /interface ipip add !keepalive clamp-tcp-mss=yes local-address= \ # remote-address=169.228.66.251 name=ucsd-gw # # and add a local AMPR IP: # /ip address add address=/8 interface=ucsd-gw network=44.0.0.0 # # To be able to receive RIPv2 broadcasts into a specific table, first create a VRF: # /ip route vrf add interfaces=ucsd-gw routing-mark=44rip # # and activate passive RIP for that routing table: # /routing rip set garbage-timer=20m routing-table=44rip timeout-timer=10m update-timer=5m # /routing rip interface add authentication=simple authentication-key=ThePAssword \ # in-prefix-list=all interface=ucsd-gw out-prefix-list= none passive=yes receive=v2 # /routing rip network add network=44.0.0.0/8 # # ------------------------------------------------------------- # Setup parameters (change as needed) # ------------------------------------------------------------- # your gateway IP :local myip "89.122.215.236" ; # router local AMPR IP :local myampr "44.182.21.254" ; # routing distance for AMPR routes :local mydistance 50 ; # ------------------------------------------------------------- # # process tunnels from RIPv2 information # :foreach tunnel in=[/routing rip route find from=44.0.0.1] do={ :local subnet [/routing rip route get $tunnel dst-address] ; :local gw [/routing rip route get $tunnel gateway] ; :local ifname ("ampr-" . $gw) ; # only if it is not our gateway :if ($gw != $myip) do={ # create tunnel if it doesn't exist :if ([/interface ipip find name=$ifname] = "") do={ /interface ipip add !keepalive clamp-tcp-mss=yes local-address=$myip remote-address=$gw name=$ifname /ip neighbor discovery set $ifname discover=no } # change/add route :local amprupd false ; # we can have nore than one route :foreach myroute in=[/ip route find dst-address=$subnet !routing-mark] do={ :if ( $myroute != "") do={ # gateway is an array !!! Get the first string :local intf [:pick [/ip route get $myroute gateway] 0] ; # check if the interface starts with 'ampr-' :if ([:pick $intf 0 [:find $intf "-"]] = "ampr") do={ # update if needed :if ( $intf != $ifname) do={ /ip route remove $myroute /ip route add dst-address=$subnet gateway=$ifname distance=$mydistance pref-src=$myampr :set $amprupd true ; } else={ # route is up to date :set $amprupd true ; } } } } # if not updated previously add the route :if ($amprupd = false) do={ /ip route add dst-address=$subnet gateway=$ifname distance=$mydistance pref-src=$myampr } } } # check and remove obsolete routes :foreach myroute in=[/ip route find pref-src=$myampr] do={ :if ( $myroute != "") do={ # gateway is an array !!! Get the first string :local intf [:pick [/ip route get $myroute gateway] 0] ; # check if the interface starts with 'ampr-' :if ([:pick $intf 0 [:find $intf "-"]] = "ampr") do={ :local mysubnet ([/ip route get $myroute dst-address]) ; # check if the subnet is in RIP data, remove if not there :if ([/routing rip route find dst-address=$mysubnet] = "") do={ /ip route remove $myroute } } } } # check and remove obsolete interfaces :foreach mytunnel in=[/interface ipip find] do={ # check if the interface starts with 'ampr-' :local intf [/interface ipip get $mytunnel name] ; :if ([:pick $intf 0 [:find $intf "-"]] = "ampr") do={ # check if tunnel is used by any route :if ([/ip route find gateway=$intf] = "") do={ /interface ipip remove $mytunnel } } } #:log info "AMPR script done"