Diff for scripts/shell/firewall/firewall.d/subnets/simplify-subnets.sh between version 1.5 and 1.6
| version 1.5, 2018/05/08 00:20:40 |
version 1.6, 2018/05/08 00:51:39 |
|
|
| # |
# |
| # Changelog: |
# Changelog: |
| # 2018-05-07 - created |
# 2018-05-07 - created |
| |
# 2018-05-08 - merging multiple C-class into one B-class |
| |
# based on C-class subnets counting |
| # |
# |
| |
|
| # $Platon: scripts/shell/firewall/firewall.d/subnets/simplify-subnets.sh,v 1.4 2018/05/08 00:00:30 nepto Exp $ |
# $Platon: scripts/shell/firewall/firewall.d/subnets/simplify-subnets.sh,v 1.5 2018/05/08 00:20:40 nepto Exp $ |
| |
|
| # Minimum amount of C-classes to be merged into one B-class |
# Minimum amount of C-classes to be merged into one B-class |
| MIN_C_CLASS_MERGE=120; |
MIN_C_CLASS_MERGE=120; |
| Line 23 if [ -z "$SUBNET_FILE" ]; then |
|
| Line 25 if [ -z "$SUBNET_FILE" ]; then |
|
| exit 1; |
exit 1; |
| fi |
fi |
| |
|
| |
# Simple subnet implementation of pow() |
| |
# It returns 1 for /24, 2 for /23, 4 for /22, and so on |
| |
c_class_subnets_count () # {{{ |
| |
{ |
| |
local pow ret i |
| |
pow=$(( 24 - $1 )) |
| |
ret=1 |
| |
i=1 |
| |
while [ $i -le $pow ]; do |
| |
ret=$(( ret * 2 )) |
| |
i=$(( i + 1 )) |
| |
done |
| |
echo $ret; |
| |
} # }}} |
| |
|
| prev_C=''; |
prev_C=''; |
| prev_B=''; |
prev_B=''; |
| cnt_CinB=1; |
cnt_CinB=1; |
| Line 55 while IFS='' read -r line; do |
|
| Line 72 while IFS='' read -r line; do |
|
| to_write="$to_write"$'\n'; |
to_write="$to_write"$'\n'; |
| to_write="$to_write$subnet_C/$mask"; |
to_write="$to_write$subnet_C/$mask"; |
| prev_C="$subnet_C"; |
prev_C="$subnet_C"; |
| cnt_CinB=$(( cnt_CinB + 1 )); |
# /24=1, /23=2, /22=4, /21=8, ... |
| |
subnet_count="`c_class_subnets_count $mask`"; |
| |
cnt_CinB=$(( cnt_CinB + subnet_count )); |
| continue; |
continue; |
| fi |
fi |
| |
|
Platon Group <platon@platon.org> http://platon.org/
|
|