Deleted Added
full compact
stf (197139) stf (197697)
1#!/bin/sh
1#!/bin/sh
2# $FreeBSD: head/etc/rc.d/stf 197139 2009-09-12 22:13:41Z hrs $
2# $FreeBSD: head/etc/rc.d/stf 197697 2009-10-02 02:24:25Z hrs $
3#
4
5# PROVIDE: stf
6# REQUIRE: netif routing
7# KEYWORD: nojail
8
9. /etc/rc.subr
10. /etc/network.subr
11
12name="stf"
13start_cmd="stf_up"
14stop_cmd="stf_down"
15
16stf_up()
17{
3#
4
5# PROVIDE: stf
6# REQUIRE: netif routing
7# KEYWORD: nojail
8
9. /etc/rc.subr
10. /etc/network.subr
11
12name="stf"
13start_cmd="stf_up"
14stop_cmd="stf_down"
15
16stf_up()
17{
18 afexists inet6 || return 0
19
18 case ${stf_interface_ipv4addr} in
19 [Nn][Oo] | '')
20 ;;
21 *)
22 # assign IPv6 addr and interface route for 6to4 interface
23 stf_prefixlen=$((16+${stf_interface_ipv4plen:-0}))
24 OIFS="$IFS"
25 IFS=".$IFS"
26 set ${stf_interface_ipv4addr}
27 IFS="$OIFS"
28 hexfrag1=`hexprint $(($1*256 + $2))`
29 hexfrag2=`hexprint $(($3*256 + $4))`
30 ipv4_in_hexformat="${hexfrag1}:${hexfrag2}"
31 case ${stf_interface_ipv6_ifid} in
32 [Aa][Uu][Tt][Oo] | '')
33 for i in ${ipv6_network_interfaces}; do
34 laddr=`network6_getladdr ${i}`
35 case ${laddr} in
36 '')
37 ;;
38 *)
39 break
40 ;;
41 esac
42 done
43 stf_interface_ipv6_ifid=`expr "${laddr}" : \
44 'fe80::\(.*\)%\(.*\)'`
45 case ${stf_interface_ipv6_ifid} in
46 '')
47 stf_interface_ipv6_ifid=0:0:0:1
48 ;;
49 esac
50 ;;
51 esac
52 echo "Configuring 6to4 tunnel interface: stf0."
53 ifconfig stf0 create >/dev/null 2>&1
54 ifconfig stf0 inet6 2002:${ipv4_in_hexformat}:${stf_interface_ipv6_slaid:-0}:${stf_interface_ipv6_ifid} \
55 prefixlen ${stf_prefixlen}
56 if [ -z "${rc_quiet}" ]; then
57 /sbin/ifconfig stf0
58 fi
59 # disallow packets to malicious 6to4 prefix
60 route add -inet6 2002:e000:: -prefixlen 20 ::1 -reject
61 route add -inet6 2002:7f00:: -prefixlen 24 ::1 -reject
62 route add -inet6 2002:0000:: -prefixlen 24 ::1 -reject
63 route add -inet6 2002:ff00:: -prefixlen 24 ::1 -reject
64 ;;
65 esac
66}
67
68stf_down()
69{
20 case ${stf_interface_ipv4addr} in
21 [Nn][Oo] | '')
22 ;;
23 *)
24 # assign IPv6 addr and interface route for 6to4 interface
25 stf_prefixlen=$((16+${stf_interface_ipv4plen:-0}))
26 OIFS="$IFS"
27 IFS=".$IFS"
28 set ${stf_interface_ipv4addr}
29 IFS="$OIFS"
30 hexfrag1=`hexprint $(($1*256 + $2))`
31 hexfrag2=`hexprint $(($3*256 + $4))`
32 ipv4_in_hexformat="${hexfrag1}:${hexfrag2}"
33 case ${stf_interface_ipv6_ifid} in
34 [Aa][Uu][Tt][Oo] | '')
35 for i in ${ipv6_network_interfaces}; do
36 laddr=`network6_getladdr ${i}`
37 case ${laddr} in
38 '')
39 ;;
40 *)
41 break
42 ;;
43 esac
44 done
45 stf_interface_ipv6_ifid=`expr "${laddr}" : \
46 'fe80::\(.*\)%\(.*\)'`
47 case ${stf_interface_ipv6_ifid} in
48 '')
49 stf_interface_ipv6_ifid=0:0:0:1
50 ;;
51 esac
52 ;;
53 esac
54 echo "Configuring 6to4 tunnel interface: stf0."
55 ifconfig stf0 create >/dev/null 2>&1
56 ifconfig stf0 inet6 2002:${ipv4_in_hexformat}:${stf_interface_ipv6_slaid:-0}:${stf_interface_ipv6_ifid} \
57 prefixlen ${stf_prefixlen}
58 if [ -z "${rc_quiet}" ]; then
59 /sbin/ifconfig stf0
60 fi
61 # disallow packets to malicious 6to4 prefix
62 route add -inet6 2002:e000:: -prefixlen 20 ::1 -reject
63 route add -inet6 2002:7f00:: -prefixlen 24 ::1 -reject
64 route add -inet6 2002:0000:: -prefixlen 24 ::1 -reject
65 route add -inet6 2002:ff00:: -prefixlen 24 ::1 -reject
66 ;;
67 esac
68}
69
70stf_down()
71{
72 afexists inet6 || return 0
73
70 echo "Removing 6to4 tunnel interface: stf0."
71 ifconfig stf0 destroy
72 route delete -inet6 2002:e000:: -prefixlen 20 ::1
73 route delete -inet6 2002:7f00:: -prefixlen 24 ::1
74 route delete -inet6 2002:0000:: -prefixlen 24 ::1
75 route delete -inet6 2002:ff00:: -prefixlen 24 ::1
76}
77
78load_rc_config $name
79run_rc_command "$1"
74 echo "Removing 6to4 tunnel interface: stf0."
75 ifconfig stf0 destroy
76 route delete -inet6 2002:e000:: -prefixlen 20 ::1
77 route delete -inet6 2002:7f00:: -prefixlen 24 ::1
78 route delete -inet6 2002:0000:: -prefixlen 24 ::1
79 route delete -inet6 2002:ff00:: -prefixlen 24 ::1
80}
81
82load_rc_config $name
83run_rc_command "$1"