blob: befceca0752f0640f166ce121a21f51d76371c60 (
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
#!/bin/sh
#
# Configure routing and miscellaneous network tunables
#
# $FreeBSD$
#
# PROVIDE: routing
# REQUIRE: faith netif ppp stf
# KEYWORD: nojail
. /etc/rc.subr
. /etc/network.subr
name="routing"
start_cmd="routing_start doall"
stop_cmd="routing_stop"
extra_commands="options static"
static_cmd="routing_start static"
options_cmd="routing_start options"
afcheck()
{
case $_af in
""|inet|inet6|ipx|atm)
;;
*)
err 1 "Unsupported address family: $_af."
;;
esac
}
routing_start()
{
local _cmd _af _a
_cmd=$1
_af=$2
afcheck
case $_af in
inet|inet6|ipx|atm)
setroutes $_cmd $_af
;;
"")
for _a in inet inet6 ipx atm; do
afexists $_a && setroutes $_cmd $_a
done
;;
esac
[ -n "${_ropts_initdone}" ] && echo '.'
}
routing_stop()
{
local _af _a
_af=$1
afcheck
case $_af in
inet|inet6|ipx|atm)
eval static_${_af} delete
eval routing_stop_${_af}
;;
"")
for _a in inet inet6 ipx atm; do
afexists $_a || continue
eval static_${_a} delete
eval routing_stop_${_a}
done
;;
esac
}
setroutes()
{
case $1 in
static)
static_$2 add
;;
options)
options_$2
;;
doall)
static_$2 add
options_$2
;;
esac
}
routing_stop_inet()
{
route -n flush -inet
}
routing_stop_inet6()
{
local i
route -n flush -inet6
for i in ${ipv6_network_interfaces}; do
ifconfig $i inet6 -defaultif
done
}
routing_stop_atm()
{
return 0
}
routing_stop_ipx()
{
return 0
}
static_inet()
{
local _action
_action=$1
case ${defaultrouter} in
[Nn][Oo] | '')
;;
*)
static_routes="default ${static_routes}"
route_default="default ${defaultrouter}"
;;
esac
if [ -n "${static_routes}" ]; then
for i in ${static_routes}; do
route_args=`get_if_var $i route_IF`
route ${_action} ${route_args}
done
fi
}
static_inet6()
{
local _action i
_action=$1
# disallow "internal" addresses to appear on the wire
route ${_action} -inet6 ::ffff:0.0.0.0 -prefixlen 96 ::1 -reject
route ${_action} -inet6 ::0.0.0.0 -prefixlen 96 ::1 -reject
case ${ipv6_defaultrouter} in
[Nn][Oo] | '')
;;
*)
ipv6_static_routes="default ${ipv6_static_routes}"
ipv6_route_default="default ${ipv6_defaultrouter}"
;;
esac
if [ -n "${ipv6_static_routes}" ]; then
for i in ${ipv6_static_routes}; do
ipv6_route_args=`get_if_var $i ipv6_route_IF`
route ${_action} -inet6 ${ipv6_route_args}
done
fi
# Fixup $ipv6_network_interfaces
case ${ipv6_network_interfaces} in
[Nn][Oo][Nn][Ee])
ipv6_network_interfaces=''
;;
esac
if checkyesno ipv6_gateway_enable; then
for i in ${ipv6_network_interfaces}; do
laddr=`network6_getladdr $i exclude_tentative`
case ${laddr} in
'')
;;
*)
ipv6_working_interfaces="$i \
${ipv6_working_interfaces}"
;;
esac
done
ipv6_network_interfaces=${ipv6_working_interfaces}
fi
# Install the "default interface" to kernel, which will be used
# as the default route when there's no router.
case "${ipv6_default_interface}" in
[Nn][Oo] | [Nn][Oo][Nn][Ee])
ipv6_default_interface=""
;;
[Aa][Uu][Tt][Oo] | "")
for i in ${ipv6_network_interfaces}; do
case $i in
lo0|faith[0-9]*)
continue
;;
esac
laddr=`network6_getladdr $i exclude_tentative`
case ${laddr} in
'')
;;
*)
ipv6_default_interface=$i
break
;;
esac
done
;;
esac
# Disallow unicast packets without outgoing scope identifiers,
# or route such packets to a "default" interface, if it is specified.
route ${_action} -inet6 fe80:: -prefixlen 10 ::1 -reject
case ${ipv6_default_interface} in
'')
route ${_action} -inet6 ff02:: -prefixlen 16 ::1 -reject
;;
*)
laddr=`network6_getladdr ${ipv6_default_interface}`
route ${_action} -inet6 ff02:: ${laddr} -prefixlen 16 -interface
# Disable installing the default interface with the
# case net.inet6.ip6.forwarding=0 and
# the interface with no ND6_IFF_ACCEPT_RTADV
# to avoid conflict between the default router list and
# the manual configured default route.
if ! checkyesno ipv6_gateway_enable; then
ifconfig ${ipv6_default_interface} nd6 | \
while read proto options
do
case "${proto}:${options}" in
nd6:*ACCEPT_RTADV*)
ifconfig ${ipv6_default_interface} inet6 defaultif
break
;;
esac
done
fi
;;
esac
}
static_atm()
{
local _action i route_args
_action=$1
if [ -n "${natm_static_routes}" ]; then
for i in ${natm_static_routes}; do
route_args=`get_if_var $i route_IF`
atmconfig natm ${_action} ${route_args}
done
fi
}
static_ipx()
{
}
_ropts_initdone=
ropts_init()
{
if [ -z "${_ropts_initdone}" ]; then
echo -n 'Additional routing options:'
_ropts_initdone=yes
fi
}
options_inet()
{
if checkyesno icmp_bmcastecho; then
ropts_init
echo -n ' broadcast ping responses=YES'
${SYSCTL_W} net.inet.icmp.bmcastecho=1 > /dev/null
else
${SYSCTL_W} net.inet.icmp.bmcastecho=0 > /dev/null
fi
if checkyesno icmp_drop_redirect; then
ropts_init
echo -n ' ignore ICMP redirect=YES'
${SYSCTL_W} net.inet.icmp.drop_redirect=1 > /dev/null
else
${SYSCTL_W} net.inet.icmp.drop_redirect=0 > /dev/null
fi
if checkyesno icmp_log_redirect; then
ropts_init
echo -n ' log ICMP redirect=YES'
${SYSCTL_W} net.inet.icmp.log_redirect=1 > /dev/null
else
${SYSCTL_W} net.inet.icmp.log_redirect=0 > /dev/null
fi
if checkyesno gateway_enable; then
ropts_init
echo -n ' IPv4 gateway=YES'
${SYSCTL_W} net.inet.ip.forwarding=1 > /dev/null
else
${SYSCTL_W} net.inet.ip.forwarding=0 > /dev/null
fi
if checkyesno forward_sourceroute; then
ropts_init
echo -n ' do source routing=YES'
${SYSCTL_W} net.inet.ip.sourceroute=1 > /dev/null
else
${SYSCTL_W} net.inet.ip.sourceroute=0 > /dev/null
fi
if checkyesno accept_sourceroute; then
ropts_init
echo -n ' accept source routing=YES'
${SYSCTL_W} net.inet.ip.accept_sourceroute=1 > /dev/null
else
${SYSCTL_W} net.inet.ip.accept_sourceroute=0 > /dev/null
fi
if checkyesno arpproxy_all; then
ropts_init
echo -n ' ARP proxyall=YES'
${SYSCTL_W} net.link.ether.inet.proxyall=1 > /dev/null
else
${SYSCTL_W} net.link.ether.inet.proxyall=0 > /dev/null
fi
}
options_inet6()
{
if checkyesno ipv6_gateway_enable; then
ropts_init
echo -n ' IPv6 gateway=YES'
${SYSCTL_W} net.inet6.ip6.forwarding=1 > /dev/null
else
${SYSCTL_W} net.inet6.ip6.forwarding=0 > /dev/null
fi
}
options_atm()
{
}
options_ipx()
{
if checkyesno ipxgateway_enable; then
ropts_init
echo -n ' IPX gateway=YES'
${SYSCTL_W} net.ipx.ipx.ipxforwarding=1 > /dev/null
else
${SYSCTL_W} net.ipx.ipx.ipxforwarding=0 > /dev/null
fi
}
load_rc_config $name
run_rc_command "$@"
|