1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-16 10:20:30 +00:00
freebsd/etc/rc.d/ip6addrctl
Doug Barton 801c438304 Prepare for the removal of set_rcvar() by changing the rcvar=
assignments to the literal values it would have returned.

The concept of set_rcvar() was nice in theory, but the forks
it creates are a drag on the startup process, which is especially
noticeable on slower systems, such as embedded ones.

During the discussion on freebsd-rc@ a preference was expressed for
using ${name}_enable instead of the literal values. However the
code portability concept doesn't really apply since there are so
many other places where the literal name has to be searched for
and replaced. Also, using the literal value is also a tiny bit
faster than dereferencing the variables, and every little bit helps.
2012-01-14 02:18:41 +00:00

103 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: ip6addrctl
# REQUIRE: FILESYSTEMS
# BEFORE: netif
# KEYWORD: nojail
. /etc/rc.subr
. /etc/network.subr
name="ip6addrctl"
rcvar="ip6addrctl_enable"
start_cmd="ip6addrctl_start"
stop_cmd="ip6addrctl_stop"
extra_commands="status prefer_ipv6 prefer_ipv4"
status_cmd="ip6addrctl"
prefer_ipv6_cmd="ip6addrctl_prefer_ipv6"
prefer_ipv4_cmd="ip6addrctl_prefer_ipv4"
config_file="/etc/ip6addrctl.conf"
set_rcvar_obsolete ipv6_enable ipv6_activate_all_interfaces
set_rcvar_obsolete ipv6_prefer ip6addrctl_policy
ip6addrctl_prefer_ipv6()
{
afexists inet6 || return 0
ip6addrctl flush >/dev/null 2>&1
ip6addrctl add ::1/128 50 0
ip6addrctl add ::/0 40 1
ip6addrctl add 2002::/16 30 2
ip6addrctl add ::/96 20 3
ip6addrctl add ::ffff:0:0/96 10 4
checkyesno ip6addrctl_verbose && ip6addrctl
}
ip6addrctl_prefer_ipv4()
{
afexists inet6 || return 0
ip6addrctl flush >/dev/null 2>&1
ip6addrctl add ::ffff:0:0/96 50 0
ip6addrctl add ::1/128 40 1
ip6addrctl add ::/0 30 2
ip6addrctl add 2002::/16 20 3
ip6addrctl add ::/96 10 4
checkyesno ip6addrctl_verbose && ip6addrctl
}
ip6addrctl_start()
{
afexists inet6 || return 0
# install the policy of the address selection algorithm.
case "${ip6addrctl_policy}" in
[Aa][Uu][Tt][Oo])
if [ -r "${config_file}" -a -s "${config_file}" ]; then
ip6addrctl flush >/dev/null 2>&1
ip6addrctl install "${config_file}"
checkyesno ip6addrctl_verbose && ip6addrctl
else
if checkyesno ipv6_activate_all_interfaces; then
ip6addrctl_prefer_ipv6
else
ip6addrctl_prefer_ipv4
fi
fi
;;
ipv4_prefer)
ip6addrctl_prefer_ipv4
;;
ipv6_prefer)
ip6addrctl_prefer_ipv6
;;
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
# Backward compatibility when ipv6_prefer=YES
ip6addrctl_prefer_ipv6
;;
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
# Backward compatibility when ipv6_prefer=NO
ip6addrctl_prefer_ipv4
;;
*)
warn "\$ip6addrctl_policy is invalid: ${ip6addrctl_policy}. " \
" \"ipv4_prefer\" is used instead."
ip6addrctl_prefer_ipv4
;;
esac
}
ip6addrctl_stop()
{
afexists inet6 || return 0
ip6addrctl flush >/dev/null 2>&1
}
load_rc_config $name
run_rc_command "$1"