]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - etc/rc.d/ip6addrctl
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.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                         else
79                                 ip6addrctl_prefer_ipv4
80                         fi
81                 fi
82         ;;
83         ipv4_prefer)
84                 ip6addrctl_prefer_ipv4
85         ;;
86         ipv6_prefer)
87                 ip6addrctl_prefer_ipv6
88         ;;
89         [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
90                 # Backward compatibility when ipv6_prefer=YES
91                 ip6addrctl_prefer_ipv6
92         ;;
93         [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
94                 # Backward compatibility when ipv6_prefer=NO
95                 ip6addrctl_prefer_ipv4
96         ;;
97         [Nn][Oo][Nn][Ee])
98                 ${IP6ADDRCTL_CMD} flush >/dev/null 2>&1
99         ;;
100         *)
101                 warn "\$ip6addrctl_policy is invalid: ${ip6addrctl_policy}. " \
102                     " \"ipv4_prefer\" is used instead."
103                 ip6addrctl_prefer_ipv4
104         ;;
105         esac
106
107         if checkyesno ip6addrctl_verbose; then
108                 echo 'Address selection policy table for IPv4 and IPv6:'
109                 ${IP6ADDRCTL_CMD}
110         fi
111 }
112
113 ip6addrctl_stop()
114 {
115         afexists inet6 || return 0
116
117         ip6addrctl flush >/dev/null 2>&1
118 }
119
120 load_rc_config $name
121 run_rc_command "$1"