]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - etc/rc.d/ip6addrctl
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / etc / rc.d / ip6addrctl
1 #!/bin/sh
2 #
3 # $FreeBSD$
4 #
5
6 # PROVIDE: ip6addrctl
7 # REQUIRE: FILESYSTEMS
8 # BEFORE: netif
9 # KEYWORD: nojail
10
11 . /etc/rc.subr
12 . /etc/network.subr
13
14 name="ip6addrctl"
15 rcvar="ip6addrctl_enable"
16 start_cmd="ip6addrctl_start"
17 stop_cmd="ip6addrctl_stop"
18 extra_commands="status prefer_ipv6 prefer_ipv4"
19 status_cmd="ip6addrctl"
20 prefer_ipv6_cmd="ip6addrctl_prefer_ipv6"
21 prefer_ipv4_cmd="ip6addrctl_prefer_ipv4"
22 config_file="/etc/ip6addrctl.conf"
23
24 set_rcvar_obsolete ipv6_enable ipv6_activate_all_interfaces
25 set_rcvar_obsolete ipv6_prefer ip6addrctl_policy
26
27 IP6ADDRCTL_CMD="/usr/sbin/ip6addrctl"
28
29 ip6addrctl_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
44 EOT
45 }
46
47 ip6addrctl_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
62 EOT
63 }
64
65 ip6addrctl_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
115 ip6addrctl_stop()
116 {
117         afexists inet6 || return 0
118
119         ip6addrctl flush >/dev/null 2>&1
120 }
121
122 load_rc_config $name
123 run_rc_command "$1"