Export smarter ip_range() with the /sbin/shorewall iprange command

git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@644 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb
This commit is contained in:
teastep
2003-07-06 13:24:23 +00:00
parent 130c8f95f9
commit 2ec4e96fbd
4 changed files with 76 additions and 16 deletions

View File

@ -270,11 +270,10 @@ encodeaddr() {
# 32-bit signed arithmetic, the range cannot span 128.0.0.0.
#
ip_range() {
local first
local last
local first last l x y z vlsm
case $1 in
*.*.*.*-*.*.*.*)
[0-9]*.*.*.*-*.*.*.*)
;;
*)
echo $1
@ -285,13 +284,27 @@ ip_range() {
first=`decodeaddr ${1%-*}`
last=`decodeaddr ${1#*-}`
if [ $first -gt $last -o $(($last - $first)) -gt 256 ]; then
if [ $first -gt $last ]; then
fatal_error "Invalid IP address range: $1"
fi
l=$(( $last + 1 ))
while [ $first -le $last ]; do
echo `encodeaddr $first`
first=$(($first + 1))
vlsm=
x=31
y=2
z=1
while [ $(( $first % $y )) -eq 0 -a $(( $first + $y )) -le $l ]; do
vlsm=$x
x=$(( $x - 1 ))
z=$y
y=$(( $y * 2 ))
done
[ -n "$vlsm" ] && echo `encodeaddr $first`/$vlsm || echo `encodeaddr $first`
first=$(($first + $z))
done
}