#! /usr/bin/awk -f # KARTELL -- tells kernel iface/routing table in zebra.conf format # Copyright (C) 2007 Matous Jan Fialka # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU general Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU general Public License for # more details. # # You should have received a copy of the GNU general Public License along with # this program. If not, see . # Usage: ip route list | kartell.awk /^default/ { ++l default[$5] = $5 " " $3 next } /^[0-9]+\./ { ++l p = $1 q = "" if(! gsub(/^.*\//, "", p)) q = p = "/32" if($2 == "via") { route[$3] = route[$3] " " $1 q } else if($2 == "dev" && $8 == "") { route[$3] = route[$3] " " $1 q } else if($2 == "dev" && $8 == "src") { iface[$3] = iface[$3] " " $9 "/" p } next } { suspicious[++l] = $0 next } END { for(d in default) { split(default[d], m) uplink[m[1]] = m[1] } for(i in iface) { split(iface[i], a) if(i in default) printf "! " print "interface " i for(x in a) { ++c if(i in default) printf "! " print " ip address " a[x] } print "!" } for(r in route) { split(route[r], t) for(x in t) { ++c print "ip route " t[x] " " r } print "!" } for(d in default) { ++c split(default[d], m) print "! ip route 0.0.0.0/0 " m[2] } if(c != l) { for(s in suspicious) { gsub(/^[ \t]*/, "", suspicious[s]) gsub(/[ \t]*$/, "", suspicious[s]) print "SUSPICIOUS " suspicious[s] >> "/dev/stderr" } exit 1 } exit 0 }