freebsd-src/etc/rc.d/ip6addrctl
Hiroki Sato 2e77c5abfb Fix several logic bugs in the previous IPv6 variable change and
re-add $ipv6_enable support for backward compatibility.  From
UPDATING:

 1. To use IPv6, simply define $ifconfig_IF_ipv6 like $ifconfig_IF
    for IPv4.  For aliases, $ifconfig_IF_aliasN should be used.
    Note that both variables need the "inet6" keyword at the head.

    Do not set $ipv6_network_interfaces manually if you do not
    understand what you are doing.  It is not needed in most cases.

    $ipv6_ifconfig_IF and $ipv6_ifconfig_IF_aliasN still work, but
    they are obsolete.

 2. $ipv6_enable is obsolete.  Use $ipv6_prefer and/or
    "inet6 accept_rtadv" keyword in ifconfig(8) instead.

    If you define $ipv6_enable=YES, it means $ipv6_prefer=YES and
    all configured interfaces have "inet6 accept_rtadv" in the
    $ifconfig_IF_ipv6.  These are for backward compatibility.

 3. A new variable $ipv6_prefer has been added.  If NO, IPv6
    functionality of interfaces with no corresponding
    $ifconfig_IF_ipv6 is disabled by using "inet6 ifdisabled" flag,
    and the default address selection policy of ip6addrctl(8)
    is the IPv4-preferred one (see rc.d/ip6addrctl for more details).
    Note that if you want to configure IPv6 functionality on the
    disabled interfaces after boot, first you need to clear the flag by
    using ifconfig(8) like:

         ifconfig em0 inet6 -ifdisabled

    If YES, the default address selection policy is set as
    IPv6-preferred.

    The default value of $ipv6_prefer is NO.

 4. If your system need to receive Router Advertisement messages,
    define "inet6 accept_rtadv" in $ifconfig_IF_ipv6.  The rc(8)
    scripts automatically invoke rtsol(8) when the interface becomes
    UP.  The Router Advertisement messages are used for SLAAC
    (State-Less Address AutoConfiguration).
2009-09-26 18:59:00 +00:00

76 lines
1.5 KiB
Bash
Executable file

#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: ip6addrctl
# REQUIRE: FILESYSTEMS
# BEFORE: netif
# KEYWORD: nojail
. /etc/rc.subr
name="ip6addrctl"
rcvar=`set_rcvar`
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"
set_rcvar_obsolete ipv6_enable ipv6_prefer
ip6addrctl_prefer_ipv6()
{
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()
{
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()
{
if ifconfig lo0 inet6 >/dev/null 2>&1; then
# We have IPv6 support in kernel.
# install the policy of the address selection algorithm.
if [ -f /etc/ip6addrctl.conf ]; then
ip6addrctl flush >/dev/null 2>&1
ip6addrctl install /etc/ip6addrctl.conf
checkyesno ip6addrctl_verbose && ip6addrctl
else
if checkyesno ipv6_prefer; then
ip6addrctl_prefer_ipv6
else
ip6addrctl_prefer_ipv4
fi
fi
fi
}
ip6addrctl_stop()
{
if ifconfig lo0 inet6 >/dev/null 2>&1; then
# We have IPv6 support in kernel.
ip6addrctl flush >/dev/null 2>&1
fi
}
load_rc_config $name
run_rc_command "$1"