stat(1): Fix -Wundef.
[dragonfly.git] / etc / rc.d / ip6addrctl
blob7531a688e3e28fbe2591a410941bad20701d5e02
1 #!/bin/sh
3 # $FreeBSD: head/libexec/rc/rc.d/ip6addrctl 320802 2017-07-08 09:28:31Z kp $
6 # PROVIDE: ip6addrctl
7 # REQUIRE: root mountcritlocal
8 # BEFORE: netif
9 # KEYWORD: nojailvnet
11 . /etc/rc.subr
12 . /etc/network.subr
14 name="ip6addrctl"
15 desc="configure address selection policy for IPv6 and IPv4"
16 rcvar="ip6addrctl_enable"
17 start_cmd="ip6addrctl_start"
18 stop_cmd="ip6addrctl_stop"
19 extra_commands="status prefer_ipv6 prefer_ipv4"
20 status_cmd="ip6addrctl"
21 prefer_ipv6_cmd="ip6addrctl_prefer_ipv6"
22 prefer_ipv4_cmd="ip6addrctl_prefer_ipv4"
23 config_file="/etc/ip6addrctl.conf"
25 IP6ADDRCTL_CMD="/usr/sbin/ip6addrctl"
27 has_inet6() {
28 ${SYSCTL} -q net.inet6 >/dev/null || {
29 warn "kernel does not support INET6"
30 false
34 ip6addrctl_prefer_ipv6()
36 has_inet6 || return 0
38 ${IP6ADDRCTL_CMD} flush >/dev/null 2>&1
39 cat <<EOT | ${IP6ADDRCTL_CMD} install /dev/stdin
40 ::1/128 50 0
41 ::/0 40 1
42 ::ffff:0:0/96 35 4
43 2002::/16 30 2
44 2001::/32 5 5
45 fc00::/7 3 13
46 ::/96 1 3
47 fec0::/10 1 11
48 3ffe::/16 1 12
49 EOT
52 ip6addrctl_prefer_ipv4()
54 has_inet6 || return 0
56 ${IP6ADDRCTL_CMD} flush >/dev/null 2>&1
57 cat <<EOT | ${IP6ADDRCTL_CMD} install /dev/stdin
58 ::1/128 50 0
59 ::/0 40 1
60 ::ffff:0:0/96 100 4
61 2002::/16 30 2
62 2001::/32 5 5
63 fc00::/7 3 13
64 ::/96 1 3
65 fec0::/10 1 11
66 3ffe::/16 1 12
67 EOT
70 ip6addrctl_start()
72 has_inet6 || return 0
74 # Install the policy of the address selection algorithm.
75 case "${ip6addrctl_policy}" in
76 [Aa][Uu][Tt][Oo])
77 if [ -r "${config_file}" -a -s "${config_file}" ]; then
78 ${IP6ADDRCTL_CMD} flush >/dev/null 2>&1
79 ${IP6ADDRCTL_CMD} install "${config_file}"
80 else
81 if checkyesno ipv6_enable; then
82 ip6addrctl_prefer_ipv6
83 else
84 ip6addrctl_prefer_ipv4
88 ipv4_prefer)
89 ip6addrctl_prefer_ipv4
91 ipv6_prefer)
92 ip6addrctl_prefer_ipv6
94 [Nn][Oo][Nn][Ee])
95 ${IP6ADDRCTL_CMD} flush >/dev/null 2>&1
98 warn "\$ip6addrctl_policy is invalid: ${ip6addrctl_policy}. " \
99 " \"ipv4_prefer\" is used instead."
100 ip6addrctl_prefer_ipv4
102 esac
104 if checkyesno ip6addrctl_verbose; then
105 echo 'Address selection policy table for IPv4 and IPv6:'
106 ${IP6ADDRCTL_CMD}
110 ip6addrctl_stop()
112 has_inet6 || return 0
114 ip6addrctl flush >/dev/null 2>&1
117 load_rc_config $name
118 run_rc_command "$1"