Commit e74e3d9a authored by Cédric BRINER's avatar Cédric BRINER Committed by Cédric BRINER
Browse files

function off to ipv6 static added

parent 9a39aa38
......@@ -4,6 +4,8 @@ export LC_ALL=C
if [[ -d /opt/sfw/bin ]]; then
export PATH="$PATH:/opt/sfw/bin"
fi
SVC_NAME="svc:/network/routing/ndp:default"
################################################################################
# C B R   LIB
_B="\e[34m"
......@@ -92,17 +94,15 @@ function get_os_release()
function restart_svc_ndp()
{
action=$1
svc_name="svc:/network/routing/ndp:default"
if svcs -H ${svc_name} &> /dev/null; then
if svcs -H ${SVC_NAME} &> /dev/null; then
if is_conf_younger_than_svc; then
pb "no need to restart the service as it is younger than the conf"
else
# TODO: do not restart ndp if file is older than ndp restart
status=$(svcs -H "${svc_name}" 2>/dev/null | awk '{print $1}' )
status=$(svcs -H "${SVC_NAME}" 2>/dev/null | awk '{print $1}' )
case ${status} in
#TODO: offline\*) to manage "(offline*)"
online)
svcadm restart ${svc_name}
svcadm restart ${SVC_NAME}
pb "service ndpd restarted"
;;
*)
......@@ -123,26 +123,8 @@ function restart_svc_ndp()
fi
}
function set_ndpd_no_all()
function enable_new_ndpd()
{
cat << eof > /tmp/ndpd.conf
ifdefault StatelessAddrConf false
ifdefault StatefulAddrConf false
ifdefault TmpAddrsEnabled false
eof
if [[ ! -e /etc/inet/ndpd.conf ]]; then
mv /tmp/ndpd.conf /etc/inet/ndpd.conf
pb "disabled conf for ndpd pushed"
else
if diff /tmp/ndpd.conf /etc/inet/ndpd.conf >& /dev/null; then
rm /tmp/ndpd.conf
pb "disabled conf for ndpd already in place"
else
mv /tmp/ndpd.conf /etc/inet/ndpd.conf
pb "disabled conf for ndpd pushed"
fi
fi
os_release=$(get_os_release)
case ${os_release} in
11.*)
......@@ -164,18 +146,195 @@ eof
;;
esac
}
function set_stateless_only()
{
cat << eof > /tmp/ndpd.conf
ifdefault StatelessAddrConf true
ifdefault StatefulAddrConf false
ifdefault TmpAddrsEnabled false
eof
if [[ ! -e /etc/inet/ndpd.conf ]]; then
mv /tmp/ndpd.conf /etc/inet/ndpd.conf
pb "stateless only conf for ndpd pushed"
else
if diff /tmp/ndpd.conf /etc/inet/ndpd.conf >& /dev/null; then
rm /tmp/ndpd.conf
pb "stateless only conf for ndpd already in place"
else
mv /tmp/ndpd.conf /etc/inet/ndpd.conf
pb "stateless only conf for ndpd pushed"
fi
fi
enable_new_ndpd
}
function set_ndpd_no_all()
{
cat << eof > /tmp/ndpd.conf
ifdefault StatelessAddrConf false
ifdefault StatefulAddrConf false
ifdefault TmpAddrsEnabled false
eof
if [[ ! -e /etc/inet/ndpd.conf ]]; then
mv /tmp/ndpd.conf /etc/inet/ndpd.conf
pb "disabled conf for ndpd pushed"
else
if diff /tmp/ndpd.conf /etc/inet/ndpd.conf >& /dev/null; then
rm /tmp/ndpd.conf
pb "disabled conf for ndpd already in place"
else
mv /tmp/ndpd.conf /etc/inet/ndpd.conf
pb "disabled conf for ndpd pushed"
fi
fi
enable_new_ndpd
}
function off_to_static()
{
# check that we are ipv6 off
echo ""
pb "--"
pb "Check that ipv6 is off"
cat << eof > /tmp/ndpd.conf
ifdefault StatelessAddrConf false
ifdefault StatefulAddrConf false
ifdefault TmpAddrsEnabled false
eof
if ! diff /tmp/ndpd.conf /etc/inet/ndpd.conf >& /dev/null; then
rm /tmp/ndpd.conf
pr "/etc/inet/ndpd.conf does not define a disabled ipv6."
pb "Exit !"
rm /tmp/ndpd.conf
exit 1
fi
if ! is_conf_younger_than_svc; then
pr "/etc/inet/ndpd.conf is younger than the service"
pr "We are unsure of the ndpd.conf in service"
pb "Exit !"
rm /tmp/ndpd.conf
exit 1
fi
pg "Ipv6 is off."
#
# enable temporarly the ipv6 stateless
echo ""
pb "--"
pb "Enable temporarly ipv6 stateless"
pb "--- start output of set_stateless_only ---"
set_stateless_only
pb "--- end output of set_stateless_only ---"
pb "find ipv6:"
ipadm | grep -w addrconf \
| grep v6 \
| grep -v " fe80:" \
| awk '{ print $5}' \
| cut -d "/" -f1 \
| sed "s|^| |"
#
# wait ipv6
echo ""
pb "--"
pb "wait for stateless"
for ipv6_prefix in 2001 fd69; do
pb " - wait for ${ipv6_prefix}: "
has_waited="false"
echo -n " "
while ! ipadm | grep -w "addrconf" | awk '{ print $5}' | grep -v "^fe80" | grep -q "^${ipv6_prefix}" ; do
sleep 0.1
echo -n "."
has_waited="true"
done
if [[ $has_waited = "true" ]]; then
echo ""
pg " ok"
else
pg "ok"
fi
done
#
# get the ip from the
echo ""
pb "--"
pb "find the ip provided by stateless"
pb " - are we 10 or 129 ip ?"
is_129_or_10=$(ipadm | grep -w static | grep v4 | grep -v lo | awk '{ print $5}' | cut -d "." -f1)
if [[ $is_129_or_10 = "10" ]]; then
pb " 10, then let's take a fd69 ipv6"
ipv6=$(ipadm | grep -w addrconf | grep v6 | grep -v " fe80:" | awk '{ print $5}' | grep "^fd69")
elif [[ $is_129_or_10 = "129" ]]; then
pb " 129, then let's take a 2001 ipv6"
ipv6=$(ipadm | grep -w addrconf | grep v6 | grep -v " fe80:" | awk '{ print $5}' | grep "^2001")
else
pr " neither 10 or 129 ips"
pb "Exit !"
exit 1
fi
pg " - ipv6 founded : ${ipv6}"
#
# disable-ndp
echo ""
pb "--"
pb "disable ndp for all"
pb "--- start output of set_ndpd_no_all ---"
set_ndpd_no_all
pb "--- end output of set_ndpd_no_all ---"
#
# wait remove ipv6 stateless
echo ""
pb "--"
pb "wait for stateless remove: "
for ipv6_prefix in 2001 fd69; do
pb " - wait for ${ipv6_prefix}: "
has_waited="false"
echo -n " "
while ipadm | grep -w "addrconf" | awk '{ print $5}' | grep -v "^fe80" | grep -q "^${ipv6_prefix}" ; do
sleep 0.1
echo -n "."
has_waited="true"
done
if [[ $has_waited = "true" ]]; then
echo ""
pg " ok"
else
pg "ok"
fi
done
#
# enable ipv6 static
pb "--"
pb "Enable ipv6 static with ipv6(${ipv6})"
if ! ipadm create-addr -T static -a local="${ipv6}" net0 >& /dev/null; then
pr "Unable to create a static address"
pb "Exit !"
exit 1
fi
pg " IPv6 ENABLED !"
ipadm | grep -w static | grep -v lo | grep net | grep v6 | awk '{ print $5}' | sed "s|^| |"
pb "--"
}
function usage()
{
pb "Usage: $0"
pb " disable-ndp: turn off stateless(ra), stateful(dhcp), tmpaddr (privacy)"
pb " enable-stateless-only: turn on stateless(ra). turn off stateful(dhcp) & tmpaddr (privacy)"
pb " off-to-ipv6-static: go from a disabled ipv6 to an activation of ipv6 static"
}
case $1 in
disable-ndp)
set_ndpd_no_all
;;
enable-stateless-only)
set_stateless_only
;;
off-to-ipv6-static)
off_to_static
;;
-h)
usage
exit 0
;;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment