bug 3768,3769,3770
This commit is contained in:
parent
53209a79d1
commit
115aef46f3
@ -15,7 +15,7 @@ function v4mask2prefix(){
|
||||
case $num_dec in
|
||||
255) let num_bits+=8;;
|
||||
254) let num_bits+=7;;
|
||||
253) let num_bits+=6;;
|
||||
252) let num_bits+=6;;
|
||||
248) let num_bits+=5;;
|
||||
240) let num_bits+=4;;
|
||||
224) let num_bits+=3;;
|
||||
@ -28,6 +28,72 @@ function v4mask2prefix(){
|
||||
echo "$num_bits"
|
||||
}
|
||||
|
||||
function v4prefix2mask(){
|
||||
local a=$1
|
||||
local b=0
|
||||
local num_index=1
|
||||
local str_temp=''
|
||||
local str_mask=''
|
||||
|
||||
while [[ $num_index -le 4 ]]
|
||||
do
|
||||
if [ $a -ge 8 ];then
|
||||
b=8
|
||||
a=$((a-8))
|
||||
else
|
||||
b=$a
|
||||
a=0
|
||||
fi
|
||||
case $b in
|
||||
0) str_temp="0";;
|
||||
1) str_temp="128";;
|
||||
2) str_temp="192";;
|
||||
3) str_temp="224";;
|
||||
4) str_temp="240";;
|
||||
5) str_temp="248";;
|
||||
6) str_temp="252";;
|
||||
7) str_temp="254";;
|
||||
8) str_temp="255";;
|
||||
esac
|
||||
|
||||
str_mask=$str_mask$str_temp"."
|
||||
|
||||
num_index=$((num_index+1))
|
||||
done
|
||||
|
||||
str_mask=`echo $str_mask | sed 's/.$//'`
|
||||
echo "$str_mask"
|
||||
}
|
||||
|
||||
function v4calcbcase(){
|
||||
local str_mask=$2
|
||||
echo $str_mask | grep '\.'
|
||||
if [ $? -ne 0 ];then
|
||||
str_mask=$(v4prefix2mask $str_mask)
|
||||
fi
|
||||
local str_bcast=''
|
||||
local str_temp=''
|
||||
local str_ifs=$IFS
|
||||
IFS=$'.'
|
||||
local array_ip=($1)
|
||||
local array_mask=($str_mask)
|
||||
IFS=$str_ifs
|
||||
|
||||
if [ ${#array_ip[*]} -ne 4 -o ${#array_mask[*]} -ne 4 ];then
|
||||
echo "255.255.255.255"
|
||||
return
|
||||
fi
|
||||
|
||||
for index in {0..3}
|
||||
do
|
||||
str_temp=`echo $[ ${array_ip[$index]}|(${array_mask[$index]} ^ 255) ]`
|
||||
str_bcast=$str_bcast$str_temp"."
|
||||
done
|
||||
|
||||
str_bcast=`echo $str_bcast | sed 's/.$//'`
|
||||
echo "$str_bcast"
|
||||
}
|
||||
|
||||
function configipv4(){
|
||||
str_if_name=$1
|
||||
str_v4ip=$2
|
||||
@ -230,8 +296,9 @@ function add_ip_temporary(){
|
||||
str_label=$str_nic_name
|
||||
fi
|
||||
|
||||
str_bcase=$(calcbcase $str_ip $str_mask)
|
||||
#the label is ready, add the ip address directly
|
||||
ip addr add $str_ip/${str_mask} dev $str_nic_name scope global label $str_label
|
||||
ip addr add $str_ip/${str_mask} broadcast $str_bcase dev $str_nic_name scope global label $str_label
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@ -392,7 +459,7 @@ while [ $num_index -lt ${#array_nic_ips[*]} ];do
|
||||
|
||||
#fetch the subnet and netmask in networks definition
|
||||
str_subnet=`echo $str_line | awk -F'net=' '{print $2}' | awk -F'|' '{print $1}'`
|
||||
str_netmask=`echo $str_line | awk -F'mask=' '{print $2}' | awk -F'|' '{print $1}'`
|
||||
str_netmask=`echo $str_line | awk -F'mask=' '{print $2}' | awk -F'|' '{print $1}' | sed 's:^/::'`
|
||||
str_gateway=`echo $str_line | awk -F'gateway=' '{print $2}' | awk -F'|' '{print $1}'`
|
||||
|
||||
if [ ! $str_subnet -o ! $str_netmask ];then
|
||||
@ -405,7 +472,8 @@ while [ $num_index -lt ${#array_nic_ips[*]} ];do
|
||||
array_nic_subnet[$num_index]=$str_subnet
|
||||
array_nic_netmask[$num_index]=$str_netmask
|
||||
array_nic_gateway[$num_index]=$str_gateway
|
||||
if [ -n "$str_gateway" ];then
|
||||
echo "$str_gateway" | grep ':'
|
||||
if [ $? -eq 0 ];then
|
||||
str_ipv6_gateway=$str_gateway
|
||||
fi
|
||||
logger -t xcat -p local4.err "configeth: $str_ip, $str_subnet, $str_netmask, $str_gateway"
|
||||
|
Loading…
Reference in New Issue
Block a user