#!/usr/bin/perl # # Original shell script to convert a KA9Q NOS format gateways route file # (usually called 'encap.txt') into a Linux routing table format for the # IP tunnel driver. Enhanced Perl version by OH7LZB # # From: Ron Atkinson # # This script is basically the 'munge' script written by Bdale N3EUA # for the IPIP daemon and is modified by Ron Atkinson N8FOW. It's # purpose is to convert a KA9Q NOS format gateways route file # (usually called 'encap.txt') into a Linux routing table format # for the IP tunnel driver. # # Enhanced Perl version by Heikki Hannikainen # # Version history: # # 2.1 hessu Thu Jul 8 19:41:18 EEST 1999 # - Modified for /sbin/ip # # Usage: # eg. munge encap.txt rc.tun-routes # # NOTE: Before you use this script be sure to check or change the # following items: # # 1) Change the @my_addresses list to include your gateways # ip address(es) (and others which you have hand-made # static routes for). REMOVE MINE !! # # Tunnel device used $tunnel_device = "tunl0"; # Local gateway addresses (whose routes are skipped) @my_addresses = ("193.167.178.112", "193.166.55.160", "195.148.207.30"); # route binary $routebin = "/sbin/ip"; # tcp window to set $window = 840; if ($#ARGV != 1) { print "Usage: $0 encap.txt rc.tun-routes\n"; exit 1; } open(inf, @ARGV[0]) || die "Cannot open @ARGV[0]: $!"; open(upf, ">@ARGV[1]") or die "Cannot open @ARGV[1]: $!";; $hdr = "#\n# IP tunnel route table\n#\n#\n"; print upf $hdr; LOOP: while ($line = ) { @fields = (); @abytes = (); $bits = ""; @fields = split(' ', $line); if (@fields[0] ne "route") { next LOOP; } $gw = @fields[4]; $net = @fields[2]; ($addr, $bits) = split('/', $net); if (!$bits) { $bits = 32; } @abytes = split('\.', $addr); for ($i = 0; $i < 4; $i++) { if (@abytes[$i] eq "") { @abytes[$i] = "0"; } } $addr = join('.', @abytes); foreach $my (@my_addresses) { if ($gw eq $my) { print "$addr/$bits > $gw blocked, local gw\n"; next LOOP; } } if ($addr !~ /^44\./) { print "$addr/$bits > $gw blocked, non-amprnet address!\n"; next LOOP; } if ($gw =~ /^44\./) { print "$addr/$bits > $gw blocked, inside amprnet!\n"; next LOOP; } if ($bits < 16) { print "$addr/$bits > $gw blocked, mask smaller than 16 bits!\n"; next LOOP; } print upf "$routebin route add $addr/$bits via $gw dev $tunnel_device onlink 2>/dev/null\n"; } print upf "#\n# the end\n#\n"; close(inf); close(upf);