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