Home | History | Annotate | Line # | Download | only in rc.d
ip6addrctl revision 1.2
      1 #!/bin/sh
      2 #
      3 # $FreeBSD: head/etc/rc.d/ip6addrctl 270836 2014-08-30 07:08:10Z hrs $
      4 #
      5 
      6 # PROVIDE: ip6addrctl
      7 # REQUIRE: root bootconf mountcritlocal tty
      8 
      9 . /etc/rc.subr
     10 
     11 name="ip6addrctl"
     12 rcvar="ip6addrctl"
     13 start_cmd="ip6addrctl_start"
     14 stop_cmd="ip6addrctl_stop"
     15 extra_commands="status prefer_ipv6 prefer_ipv4"
     16 status_cmd="ip6addrctl"
     17 prefer_ipv6_cmd="ip6addrctl_prefer_ipv6"
     18 prefer_ipv4_cmd="ip6addrctl_prefer_ipv4"
     19 config_file="/etc/ip6addrctl.conf"
     20 
     21 IP6ADDRCTL_CMD="/usr/sbin/ip6addrctl"
     22 
     23 ip6addrctl_prefer_ipv6()
     24 {
     25 	${IP6ADDRCTL_CMD} flush >/dev/null 2>&1
     26 	cat <<EOT | ${IP6ADDRCTL_CMD} install /dev/stdin
     27 	::1/128		 50	 0
     28 	::/0		 40	 1
     29 	::ffff:0:0/96	 35	 4
     30 	2002::/16	 30	 2
     31 	2001::/32	  5	 5
     32 	fc00::/7	  3	13
     33 	::/96		  1	 3
     34 	fec0::/10	  1	11
     35 	3ffe::/16	  1	12
     36 EOT
     37 }
     38 
     39 ip6addrctl_prefer_ipv4()
     40 {
     41 	${IP6ADDRCTL_CMD} flush >/dev/null 2>&1
     42 	cat <<EOT | ${IP6ADDRCTL_CMD} install /dev/stdin
     43 	::1/128		 50	 0
     44 	::/0		 40	 1
     45 	::ffff:0:0/96	100	 4
     46 	2002::/16	 30	 2
     47 	2001::/32	  5	 5
     48 	fc00::/7	  3	13
     49 	::/96		  1	 3
     50 	fec0::/10	  1	11
     51 	3ffe::/16	  1	12
     52 EOT
     53 }
     54 
     55 ip6addrctl_start()
     56 {
     57 	# install the policy of the address selection algorithm.
     58 	case "${ip6addrctl_policy}" in
     59 	[Aa][Uu][Tt][Oo])
     60 		if [ -r "${config_file}" -a -s "${config_file}" ]; then
     61 			${IP6ADDRCTL_CMD} flush >/dev/null 2>&1
     62 			${IP6ADDRCTL_CMD} install "${config_file}"
     63 		else
     64 			ip6addrctl_prefer_ipv6
     65 		fi
     66 	;;
     67 	ipv4_prefer)
     68 		ip6addrctl_prefer_ipv4
     69 	;;
     70 	ipv6_prefer)
     71 		ip6addrctl_prefer_ipv6
     72 	;;
     73 	*)
     74 		warn "\$ip6addrctl_policy is invalid: ${ip6addrctl_policy}. " \
     75 		    " \"ipv4_prefer\" is used instead."
     76 		ip6addrctl_prefer_ipv4
     77 	;;
     78 	esac
     79 
     80 	if checkyesno ip6addrctl_verbose; then
     81 		echo 'Address selection policy table for IPv4 and IPv6:'
     82 		${IP6ADDRCTL_CMD}
     83 	fi
     84 }
     85 
     86 ip6addrctl_stop()
     87 {
     88 	ip6addrctl flush >/dev/null 2>&1
     89 }
     90 
     91 load_rc_config $name
     92 run_rc_command "$1"
     93