#!/bin/sh
#
# 	Copyright (c) 2005-2008 Peter V. Saveliev
#
# 	This file is part of rt-network utilities package.
#
# 	rt-network 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.
#
# 	rt-network 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 rt-network; if not, write to the Free Software
# 	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


if [ -z "$1" ]; then {
	INTERFACES=`/sbin/ip link show | gawk '/^[0-9]/ {print gensub(/:$/,"","",$2)}'`
} else {
	/sbin/ip link show dev $1 >/dev/null 2>&1 && INTERFACES=$1
} fi

p1=/usr/local/share/rt-network
p2=/usr/share/rt-network
p3=.

lib=""
[ -d $p1 ] && lib=$p1
[ -d $p2 -a -z "$lib" ] && lib=$p2
[ -d $p3 -a -z "$lib" ] && lib=$p3

for i in $INTERFACES; do {

        echo -e "\n* interface $i:\n|"

	gawk -v _iface=$i           \
		-W re-interval      \
		-f $lib/syntax.awk  \
		-f $lib/egress.awk
} done
