#!/bin/sh # iproute2_ampr_munge v20070201 # # 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. WA7V's version of the shell script to process the # gateways (encap.txt) file for updating an iproute2-based Linux AMPRNet # gateway. # # Gateways "munge" script, *only* compatible with iproute2. # "ip" must be in your path, or the full path entered below. # Place YOUR gateway's IP in the MYGATE variable. # # 01 February, 2007, WA7V: # Edited commenting for public consumption. ;-) # 19 March, 2003, WA7V: # Cleaned up unneeded lines from ifconfig(8) and route(8), leaving only # ip(8) commands for inserting routes into the kernel routing table. # Added shell functions to take an "add" or "del" command-line argument, # and process the command while reusing as much code as possible. # Info on iproute2: http://linux-net.osdl.org/index.php/Iproute2 # # Significant portions and/or concepts were by: # Michael Taylor, VE3TIX # Ron Atkinson, N8FOW # Bdale Garbee, N3EUA # Usage: Gateway file on stdin, Linux iproute2 format file on stdout. # Requires "add" or "del" argument to create appropriate file. # eg. $0 add < encap.txt > ampr_add # $0 del < encap.txt > ampr_del MYGATE="11.22.33.44" VERSION="20070201" do_header() { echo "#" echo "# IP tunnel route table built by $LOGNAME on `date`" echo "# Using $0 v. $VERSION" echo "# Excluding [local] routes handled by $MYGATE from this file..." echo "#" echo "# Remote routes:" } do_footer() { echo "#" echo "# Default via mirrorshades.ucsd.edu:" echo "ip route $WHAT 44.0.0.0/8 via 128.54.16.18 dev tunl0 onlink" echo "#" echo "# " } add_routes() { fgrep encap | grep "^route" | grep -v " ${MYGATE}" | \ awk '{ split($3, s, "/") split(s[1], n,".") if (n[1] == "") n[1]="0" if (n[2] == "") n[2]="0" if (n[3] == "") n[3]="0" if (n[4] == "") n[4]="0" # if (s[2] == "32" || s[2] == "") printf "ip route add %s.%s.%s.%s via %s dev tunl0 onlink\n"\ ,n[1],n[2],n[3],n[4],$5 # else printf "ip route add %s.%s.%s.%s/%s via %s dev tunl0 onlink\n"\ ,n[1],n[2],n[3],n[4],s[2],$5 }' # } del_routes() { fgrep encap | grep "^route" | grep -v " ${MYGATE}" | \ awk '{ split($3, s, "/") split(s[1], n,".") if (n[1] == "") n[1]="0" if (n[2] == "") n[2]="0" if (n[3] == "") n[3]="0" if (n[4] == "") n[4]="0" # if (s[2] == "32" || s[2] == "") printf "ip route del %s.%s.%s.%s via %s dev tunl0 onlink\n"\ ,n[1],n[2],n[3],n[4],$5 # else printf "ip route del %s.%s.%s.%s/%s via %s dev tunl0 onlink\n"\ ,n[1],n[2],n[3],n[4],s[2],$5 }' # } # case "$1" in 'add') WHAT=add do_header add_routes do_footer ;; 'del') WHAT=del do_header del_routes do_footer ;; *) echo "Usage: $0 add|del < infile > outfile" echo "" echo "e.g. $0 add < encap.txt > ampr_add" echo " $0 del < encap.txt > ampr_del" echo "\"> outfile\" is optional. Default sends to stdout." echo "" exit 1 esac #