1#!/bin/sh 2# 3# 4 5# PROVIDE: ip6addrctl 6# REQUIRE: FILESYSTEMS 7# BEFORE: netif 8# KEYWORD: nojailvnet 9 10. /etc/rc.subr 11. /etc/network.subr 12 13name="ip6addrctl" 14desc="configure address selection policy for IPv6 and IPv4" 15rcvar="ip6addrctl_enable" 16start_cmd="ip6addrctl_start" 17stop_cmd="ip6addrctl_stop" 18extra_commands="status prefer_ipv6 prefer_ipv4" 19status_cmd="ip6addrctl" 20prefer_ipv6_cmd="ip6addrctl_prefer_ipv6" 21prefer_ipv4_cmd="ip6addrctl_prefer_ipv4" 22config_file="/etc/ip6addrctl.conf" 23 24set_rcvar_obsolete ipv6_enable ipv6_activate_all_interfaces 25set_rcvar_obsolete ipv6_prefer ip6addrctl_policy 26 27IP6ADDRCTL_CMD="/usr/sbin/ip6addrctl" 28 29ip6addrctl_prefer_ipv6() 30{ 31 afexists inet6 || return 0 32 33 ${IP6ADDRCTL_CMD} flush >/dev/null 2>&1 34 cat <<EOT | ${IP6ADDRCTL_CMD} install /dev/stdin 35 ::1/128 50 0 36 ::/0 40 1 37 ::ffff:0:0/96 35 4 38 2002::/16 30 2 39 2001::/32 5 5 40 fc00::/7 3 13 41 ::/96 1 3 42 fec0::/10 1 11 43 3ffe::/16 1 12 44EOT 45} 46 47ip6addrctl_prefer_ipv4() 48{ 49 afexists inet6 || return 0 50 51 ${IP6ADDRCTL_CMD} flush >/dev/null 2>&1 52 cat <<EOT | ${IP6ADDRCTL_CMD} install /dev/stdin 53 ::1/128 50 0 54 ::/0 40 1 55 ::ffff:0:0/96 100 4 56 2002::/16 30 2 57 2001::/32 5 5 58 fc00::/7 3 13 59 ::/96 1 3 60 fec0::/10 1 11 61 3ffe::/16 1 12 62EOT 63} 64 65ip6addrctl_start() 66{ 67 afexists inet6 || return 0 68 69 # install the policy of the address selection algorithm. 70 case "${ip6addrctl_policy}" in 71 [Aa][Uu][Tt][Oo]) 72 if [ -r "${config_file}" -a -s "${config_file}" ]; then 73 ${IP6ADDRCTL_CMD} flush >/dev/null 2>&1 74 ${IP6ADDRCTL_CMD} install "${config_file}" 75 else 76 if checkyesno ipv6_activate_all_interfaces; then 77 ip6addrctl_prefer_ipv6 78 elif [ -n "$(list_vars ifconfig_\*_ipv6)" ]; then 79 ip6addrctl_prefer_ipv6 80 else 81 ip6addrctl_prefer_ipv4 82 fi 83 fi 84 ;; 85 ipv4_prefer) 86 ip6addrctl_prefer_ipv4 87 ;; 88 ipv6_prefer) 89 ip6addrctl_prefer_ipv6 90 ;; 91 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) 92 # Backward compatibility when ipv6_prefer=YES 93 ip6addrctl_prefer_ipv6 94 ;; 95 [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) 96 # Backward compatibility when ipv6_prefer=NO 97 ip6addrctl_prefer_ipv4 98 ;; 99 [Nn][Oo][Nn][Ee]) 100 ${IP6ADDRCTL_CMD} flush >/dev/null 2>&1 101 ;; 102 *) 103 warn "\$ip6addrctl_policy is invalid: ${ip6addrctl_policy}. " \ 104 " \"ipv4_prefer\" is used instead." 105 ip6addrctl_prefer_ipv4 106 ;; 107 esac 108 109 if checkyesno ip6addrctl_verbose; then 110 echo 'Address selection policy table for IPv4 and IPv6:' 111 ${IP6ADDRCTL_CMD} 112 fi 113} 114 115ip6addrctl_stop() 116{ 117 afexists inet6 || return 0 118 119 ip6addrctl flush >/dev/null 2>&1 120} 121 122load_rc_config $name 123run_rc_command "$1" 124