blob: 750e7662c33a8bc21a241bf705a7fa5c0852384c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#!/bin/sh
# PROVIDE: u6rd
# REQUIRE: SERVERS
# BEFORE: DAEMON
# KEYWORD: shutdown
u6rd_enable=${u6rd_enable:-"NO"}
u6rd_prefix=${u6rd_prefix:-""} # 6rd prefix from your ISP (prefix/len)
u6rd_relay_v4_addr=${u6rd_relay_v4_addr:-""} # 6rd relay router of your ISP
u6rd_my_v4_addr=${u6rd_my_v4_addr:-""} # Your global IPv4 address
u6rd_my_v6_addr=${u6rd_my_v6_addr:-""} # Your global IPv6 address (addr/len)
u6rd_defaultrouter=${u6rd_defaultrouter:-""}
u6rd_interface=${u6rd_interface:-"tun0"}
u6rd_interface_flags=${u6rd_interface_flags:-"inet6 -nud"}
u6rd_username=${u6rd_username:-"nobody"}
. /etc/rc.subr
name="u6rd"
rcvar=u6rd_enable
command="%%PREFIX%%/sbin/${name}"
pidfile="/var/run/${name}.pid"
start_precmd=start_precmd
stop_postcmd=stop_postcmd
get_plen()
{
local prefix plen
prefix="$1"
plen=$(expr "${prefix}" : '.*/\([0-9]*\)')
if [ -z "${plen}" ]; then
plen=64
fi
echo ${plen}
}
plen_equal()
{
if [ -z "$1" -o -z "$2" ]; then
return 1
fi
if [ $(get_plen "$1") -ne $(get_plen "$2") ]; then
return 1
fi
return 0
}
start_precmd()
{
ifconfig ${u6rd_interface} create
ifconfig ${u6rd_interface} inet6 -ifdisabled >/dev/null 2>&1
if [ -n "${u6rd_interface_flags}" ]; then
ifconfig ${u6rd_interface} ${u6rd_interface_flags}
fi
if [ -n "${u6rd_my_v6_addr}" ]; then
ifconfig ${u6rd_interface} inet6 ${u6rd_my_v6_addr}
fi
if [ -n "${u6rd_fib}" ]; then
ifconfig ${u6rd_interface} fib ${u6rd_fib}
fi
ifconfig ${u6rd_interface} up
if ! plen_equal ${u6rd_prefix} ${u6rd_my_v6_addr}; then
route delete -inet6 ${u6rd_prefix} ${route_fib} >/dev/null 2>&1
route add -inet6 ${u6rd_prefix} ::1 -ifp ${u6rd_interface} ${route_fib}
fi
if [ -n "${u6rd_defaultrouter}" ]; then
route delete -inet6 default ${route_fib} >/dev/null 2>&1
route add -inet6 default ${u6rd_defaultrouter} ${route_fib}
fi
}
stop_postcmd()
{
if [ -n "${u6rd_defaultrouter}" ]; then
route delete -inet6 default ${route_fib}
fi
if ! plen_equal ${u6rd_prefix} ${u6rd_my_v6_addr}; then
route delete -inet6 ${u6rd_prefix} ${route_fib}
fi
ifconfig ${u6rd_interface} destroy
}
load_rc_config ${name}
command_args="-u ${u6rd_username} ${u6rd_interface} ${u6rd_prefix} ${u6rd_relay_v4_addr} ${u6rd_my_v4_addr}"
if [ -n "${u6rd_fib}" ]; then
route_fib="-fib ${u6rd_fib}"
fi
run_rc_command "$1"
|