Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts: fix potential overflow when cnovert ip to value #464

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ function help() {
echo " [-nc|--noConfirm] if specified, deploy no need to confirm"
}

function ip_value() {
echo $1 | awk -F '[:/.]' '{
mask = (2 ^ 8)
printf ("%.0f", (($1 * mask + $2) * mask + $3) * mask + $4)
}'
}

# 从subnet获取ip
function get_ip_from_subnet() {
subnet=$1
prefix=`echo $subnet|awk -F/ '{print $1}'|awk -F. '{printf "%d", ($1*(2^24))+($2*(2^16))+($3*(2^8))+$4}'`
prefix=$(ip_value $subnet)
mod=`echo $subnet|awk -F/ '{print $2}'`
mask=$((2**32-2**(32-$mod)))
# 对prefix再取一次模,为了支持10.182.26.50/22这种格式
Expand All @@ -55,7 +62,7 @@ function get_ip_from_subnet() {
for i in `/sbin/ifconfig -a|grep inet|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
do
# 把ip转换成整数
ip_int=`echo $i|awk -F. '{printf "%d\n", ($1*(2^24))+($2*(2^16))+($3*(2^8))+$4}'`
ip_int=$(ip_value $i)
if [ $(($ip_int&$mask)) -eq $prefix ]
then
ip=$i
Expand Down
11 changes: 9 additions & 2 deletions curve-ansible/roles/install_package/templates/mds-daemon.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ daemonLog=${logPath}/curve-mds-daemon.log
# console output
consoleLog=${logPath}/curve-mds-console.log

function ip_value() {
echo $1 | awk -F '[:/.]' '{
mask = (2 ^ 8)
printf ("%.0f", (($1 * mask + $2) * mask + $3) * mask + $4)
}'
}

# 启动mds
function start_mds() {
# 检查daemon
Expand Down Expand Up @@ -88,7 +95,7 @@ function start_mds() {
then
subnet=`cat $confPath|grep global.subnet|awk -F"=" '{print $2}'`
port=`cat $confPath|grep global.port|awk -F"=" '{print $2}'`
prefix=`echo $subnet|awk -F/ '{print $1}'|awk -F. '{printf "%d", ($1*(2^24))+($2*(2^16))+($3*(2^8))+$4}'`
prefix=$(ip_value $subnet)
mod=`echo $subnet|awk -F/ '{print $2}'`
mask=$((2**32-2**(32-$mod)))
ip=
Expand All @@ -99,7 +106,7 @@ function start_mds() {
for i in `/sbin/ifconfig -a|grep inet|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
do
# 把ip转换成整数
ip_int=`echo $i|awk -F. '{printf "%d\n", ($1*(2^24))+($2*(2^16))+($3*(2^8))+$4}'`
ip_int=$(ip_value $i)
if [ $(($ip_int&$mask)) -eq $prefix ]
then
ip=$i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ daemonLog=${logPath}/curve-snapshot-daemon.log
# console output
consoleLog=${logPath}/curve-snapshot-console.log

function ip_value() {
echo $1 | awk -F '[:/.]' '{
mask = (2 ^ 8)
printf ("%.0f", (($1 * mask + $2) * mask + $3) * mask + $4)
}'
}

# 启动snapshotcloneserver
function start_server() {
# 检查daemon
Expand Down Expand Up @@ -88,7 +95,7 @@ function start_server() {
then
subnet=`cat $confPath|grep server.subnet|awk -F"=" '{print $2}'`
port=`cat $confPath|grep server.port|awk -F"=" '{print $2}'`
prefix=`echo $subnet|awk -F/ '{print $1}'|awk -F. '{printf "%d", ($1*(2^24))+($2*(2^16))+($3*(2^8))+$4}'`
prefix=$(ip_value $subnet)
mod=`echo $subnet|awk -F/ '{print $2}'`
mask=$((2**32-2**(32-$mod)))
ip=
Expand All @@ -99,7 +106,7 @@ function start_server() {
for i in `/sbin/ifconfig -a|grep inet|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
do
# 把ip转换成整数
ip_int=`echo $i|awk -F. '{printf "%d\n", ($1*(2^24))+($2*(2^16))+($3*(2^8))+$4}'`
ip_int=$(ip_value $i)
if [ $(($ip_int&$mask)) -eq $prefix ]
then
ip=$i
Expand Down