Best Route Table
Inspired by https://github.com/fivesheep/chnroutes.
This project aimed to generate the smallest route table, while preserves the minimalist requirements that IPs of specified countries or subnets will be routed to a specified gateway (default or VPN).
Generally speaking, the generated route table is at least 70% smaller than chnroutes's.
I started this project due to the huge route table generated by chnroutes doesn't fit into my router.
Which takes almost 4 minutes to load up, and it cannot be
put into OpenVPN's configuration file for my service
ping-reset 60 to the client, reseted
OpenVPN before route table being loaded up.
So I decided to minimize the route table.
How optimize it is?
For a example, a route table that route all IPs in China to default gateway, and US, GB, Japan, Hongkong and non-APNIC administered IPs to VPN gateway (based on 11/26/2012 data,) only need 1093 routing directives, while chnroutes needs 3563 routing directives.
Which is 70% smaller. And if route US address to VPN only, the route table has only 50 directives.
How it works
Unlike chnroutes, which will generate a route table that route all IPs of china to default gateway, while other IPs to VPN gateway. This project divides IPs in three groups. First group is guaranteed to be routed to default gateway, Second group is guaranteed to be routed to VPN gateway. And the last group will be dynamically assigned to one of the gateways, in a manner that will generate the smallest route table.
To achieve the goal, this project using dynamic programming algorithm to find out the most optimized route table.
We can prove that, the generated route table is the smallest one based on the given restrictions.
For further detail: http://ashi009.tumblr.com/post/36581070478/vpn
How to use
./generate.sh route_table > analysis_result
Which will output the routing directives (OpenVPN syntax) to
route_table and a summarized evaluation report to
The syntax for this script is:
./generate.sh output [options]
outputis the path of output route table.
optionswill be redirected to
Have some fun
node minifier.js [--local=specs] [--vpn=specs] [--onlyAPNIC=1]
--localis used to specify a list of country abbreviations and IP subnets to be routed to default gateway. Default to
--vpnis used to specify a list of country abbreviations and IP subnets to be routed to VPN gateway. Default to
--onlyAPNICis used ignore non-APNIC administered IPs. When not set, non-APNIC IPs will be routed by VPN gateway. Default not set.
specsis a list of country abbreviation names or IP subnet, seperated with comma(,). The abbreviation names can be found in
This script will output directives to
stdout, and statistic info to
stderr, so please redirect
stdout to a file. Recommend use
node minifier.js --local=CN --vpn=US,22.214.171.124/31 --onlyAPNIC=1
route 0.0.0.0 0.0.0.0 net_gateway route 126.96.36.199 255.255.0.0 vpn_gateway route 188.8.131.52 255.255.192.0 vpn_gateway route 184.108.40.206 255.254.0.0 vpn_gateway route 220.127.116.11 255.255.0.0 vpn_gateway route 18.104.22.168 255.224.0.0 vpn_gateway route 22.214.171.124 255.240.0.0 vpn_gateway route 126.96.36.199 255.255.224.0 vpn_gateway route 188.8.131.52 255.255.192.0 vpn_gateway route 184.108.40.206 255.255.224.0 vpn_gateway Total: 10 rules
Analysis a route table
node evaluator.js input [--verbose=1] [--default=default]
inputis the path to route table.
--verbosewhen set will output the route result for every block. Default not set.
--defaultis the default gateway for 0.0.0.0/0.
Note that, this script is not complete, as it only analysis the base IP of the block of each APNIC/nonAPNIC delegation. But some IPs in a block could be routed to other gateway than its base IP's (this only affects some nonAPNIC IP blocks, as it overlaps some APNIC IP blocks.)
Update IP delegation files
rm *.dat ./generate.sh