- copy mask2pfxlen from /etc/sysconfig/network/scripts/functions

to hv_set_ifconfig (bnc#879256)

OBS-URL: https://build.opensuse.org/package/show/Virtualization/hyper-v?expand=0&rev=94
This commit is contained in:
Olaf Hering 2014-05-26 13:51:55 +00:00 committed by Git OBS Bridge
parent a50ee553aa
commit 419a3fa06f
2 changed files with 37 additions and 8 deletions

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Mon May 26 15:50:21 CEST 2014 - ohering@suse.de
- copy mask2pfxlen from /etc/sysconfig/network/scripts/functions
to hv_set_ifconfig (bnc#879256)
-------------------------------------------------------------------
Wed May 21 12:05:31 CEST 2014 - ohering@suse.de

View File

@ -44,14 +44,37 @@ then
fi
# send subshell output to syslog
(
f=/etc/sysconfig/network/scripts/functions
if test -f ${f}
then
. ${f}
else
echo "MISSING ${f}"
exit 1
fi
# copied from /etc/sysconfig/network/scripts/functions
mask2pfxlen() {
local i octet width=0 mask=(${1//./ })
test ${#mask[@]} -eq 4 || return 1
for octet in 0 1 2 3
do
test "${mask[octet]}" -ge 0 -a "${mask[octet]}" -le 255 || return 1
for i in 128 192 224 240 248 252 254 255
do
test ${mask[octet]} -ge $i && ((width++))
done
done
echo $width
return 0
}
pfxlen2mask() {
test -n "$1" || return 1
local o i n=0 adr=() len=$(($1))
for o in 0 1 2 3
do
adr[$o]=0
for i in 128 64 32 16 8 4 2 1
do
((n++ < len)) && ((adr[$o] = ${adr[$o]} + $i))
done
done
echo ${adr[0]}.${adr[1]}.${adr[2]}.${adr[3]}
return 0
}
# remove known config variables from environment
unset HWADDR
unset BOOTPROTO