Wednesday 15 August 2012

SPLAT/GAIA Static-Route migration scripts

Hi Everyone,

So I recently came across a situation where I needed to accomplish two things quite quickly:
1) Remove all active interfaces from a device and reconfigure them into load-sharing LACP bonds
2) Restore the previous routing configuration to the device post-interface removal.

Since #2 involved redoing over 1000 static routes, I of course didn't want to do this manually :)

I've created two sets of scripts; One for backing up the current configuration, and one for restoring the configuration post config-change.

(I'd suggest using wget to pull the raw files, however you can copy however you'd like):


Backups:
GAIA:
route_backup_gaia.sh
SPLAT:
route_backup_splat.sh

Restoring:
GAIA
route_rebuild_gaia.sh
SPLAT
route_rebuild_splat.sh


As for how to use them, I'll give you a basic scenario. Currently most routes for my test box are via eth2, however I want to move this link into a bond for better throughput and availability.


GAIA1# clish -c "show route"
Codes: C - Connected, S - Static, R - RIP, B - BGP,
       O - OSPF IntraArea (IA - InterArea, E - External, N - NSSA)
       A - Aggregate, K - Kernel Remnant, H - Hidden, P - Suppressed

S     0.0.0.0/0           via 192.168.0.1, eth0, cost 0, age 4 
C     10.100.100.0/24     is directly connected, eth2 
S     10.100.101.0/24     via 10.100.100.2, eth2, cost 0, age 5993 
S     10.100.102.0/24     via 10.100.100.2, eth2, cost 0, age 1090 
S     10.100.103.0/24     via 10.100.100.2, eth2, cost 0, age 1087 
S     10.100.104.0/24     via 10.100.100.2, eth2, cost 0, age 1084 
C     127.0.0.0/8         is directly connected, lo 
C     192.168.0.0/24      is directly connected, eth0 


Prior to making our changes, I run the backup script like so:
[Expert@GAIA1]# ./route_backup_gaia.sh
Backing up routes now...

DONE

You can find your routes in /home/admin/150812_195030_GAIA1_routes.txt


Looking through the route file you can see that it's parsed it into a useful format:
[Expert@GAIA1]# cat 150812_195030_GAIA1_routes.txt
0.0.0.0/0 192.168.0.1
10.100.101.0/24 10.100.100.2
10.100.102.0/24 10.100.100.2
10.100.103.0/24 10.100.100.2
10.100.104.0/24 10.100.100.2


We'll make our interface changes now (remove eth2 - migrate to bond0)

Post change we can see that we now have bond0 on 10.100.100/24, however all of our routes are now gone:

GAIA1> show route
Codes: C - Connected, S - Static, R - RIP, B - BGP,
       O - OSPF IntraArea (IA - InterArea, E - External, N - NSSA)
       A - Aggregate, K - Kernel Remnant, H - Hidden, P - Suppressed

S     0.0.0.0/0           via 192.168.0.1, eth0, cost 0, age 5490 
C     10.100.100.0/24     is directly connected, bond0 
C     127.0.0.0/8         is directly connected, lo 
C     192.168.0.0/24      is directly connected, eth0 
 

Now we want to restore our previous routes:
[Expert@GAIA1]# ./route_rebuild_gaia.sh
Hello, please enter the correct log file to analyze
150812_195030_GAIA1_routes.txt
150812_195030_GAIA1_routes.txt
Thank you - Rebuilding the routing table now
Finished rebuilding the routing table...

Please remember to verify if the routes were rebuilt correctly!!
Goodbye
[Expert@GAIA1]# clish -c "show route"
Codes: C - Connected, S - Static, R - RIP, B - BGP,
       O - OSPF IntraArea (IA - InterArea, E - External, N - NSSA)
       A - Aggregate, K - Kernel Remnant, H - Hidden, P - Suppressed

S     0.0.0.0/0           via 192.168.0.1, eth0, cost 0, age 5669 
C     10.100.100.0/24     is directly connected, bond0 
S     10.100.101.0/24     via 10.100.100.2, bond0, cost 0, age 12 
S     10.100.102.0/24     via 10.100.100.2, bond0, cost 0, age 12 
S     10.100.103.0/24     via 10.100.100.2, bond0, cost 0, age 12 
S     10.100.104.0/24     via 10.100.100.2, bond0, cost 0, age 12 
C     127.0.0.0/8         is directly connected, lo 
C     192.168.0.0/24      is directly connected, eth0


And there you have it - nice and simple :)

SPLAT works the same way, however the scripts themselves are different of course since we need to use CLISH now.

If you want to get this to work on IPSO, the GAIA script would only need very minor modifications to how it deals with write-locks. If you need some help, let me know :)





8 comments:

  1. Hi Craig,

    I thought that the static routes where the exit intf is not yet configured are just 'inactive', or i am wrong?
    I will have to add to my FW's new network intf [1Gb] to replace existing 100mb intf. Based on your post, the static routes already added will be deleted or is to early in the morning for me :) ?

    ReplyDelete
  2. Thanks for the scripts!

    During testing of scripts, it seems that backup script records also OSPF routes and have to be tuned a little to ignore these routes.

    ReplyDelete
  3. @Dilianch, yeah, the SPLAT one does unfortunately (it was an afterthought really). I'll update that in a bit. As for GAIA, it will *only* grab static routes:
    | grep "S " |

    @JustRelaxx,
    It is "supposed" to be that way, but it seems gated/routed are somewhat inconsistent with their behaviour. Occassionally I've been able to just 'service network restart' and have the routes come back, however more often than not they are completely gone if the interface is removed...

    This is obviously also useful in rebuilding backup members with the master's routes etc if your backups fail ;)

    Thanks for the comments!

    ReplyDelete
  4. Hi Craig,

    Thank for the reply. To be safe [instead of sorry] i am backing up the routes :).

    Looking forward for new posts :)

    Mihai

    ReplyDelete
  5. Haha, no problem. Thanks for reading :)

    ReplyDelete
  6. Hi,

    Thanks for this job!
    I have a problem with backup route on IPSO and restore them on GAIA.

    The backup gaia script work welle on IPSO but the clish show route command on IPSO give the answer:
    0.0.0.0/0 10.1.205.20
    10.1.1/24 192.168.9.7
    10.1.7/24 192.168.9.7
    10.1.101/24 10.1.207.1

    The .0 is missing on all routes /24 or /16 /8...
    Because of that the import script is not importing all these routes.

    Do you have an idea?

    ReplyDelete
  7. I will recommend you to copy your output to notepad:
    10.1.1/24 192.168.9.7
    10.1.7/24 192.168.9.7
    10.1.101/24 10.1.207.1
    x.x/16 y.y.y.y
    Z/8 y.y.y.y

    Then use find and replace to correct it:
    Find: /24 Replaceto: .0/24
    Find: /16 Replaceto: .0.0/16
    Find: /8 Replaceto: .0.0.0/8

    Then in Gaia, via web > static routes: you can import multiple routes, you just have to paste this corrected notepad and there you go.
    NOTE: dont put here the 0.0.0.0/0.. create the default manually.

    ReplyDelete
  8. Many thanks !! saved my huge times !! :)

    ReplyDelete