Deleted Added
full compact
routing (180563) routing (197139)
1#!/bin/sh
2#
3# Configure routing and miscellaneous network tunables
4#
1#!/bin/sh
2#
3# Configure routing and miscellaneous network tunables
4#
5# $FreeBSD: head/etc/rc.d/routing 180563 2008-07-16 19:22:48Z dougb $
5# $FreeBSD: head/etc/rc.d/routing 197139 2009-09-12 22:13:41Z hrs $
6#
7
8# PROVIDE: routing
9# REQUIRE: netif ppp
10# KEYWORD: nojail
11
12. /etc/rc.subr
13. /etc/network.subr
14
15name="routing"
16start_cmd="routing_start"
17stop_cmd="routing_stop"
18extra_commands="options static"
19static_cmd="static_start"
20options_cmd="options_start"
21
22routing_start()
23{
6#
7
8# PROVIDE: routing
9# REQUIRE: netif ppp
10# KEYWORD: nojail
11
12. /etc/rc.subr
13. /etc/network.subr
14
15name="routing"
16start_cmd="routing_start"
17stop_cmd="routing_stop"
18extra_commands="options static"
19static_cmd="static_start"
20options_cmd="options_start"
21
22routing_start()
23{
24 static_start
25 options_start
24 static_start "$@"
25 options_start "$@"
26}
27
28routing_stop()
29{
26}
27
28routing_stop()
29{
30 static_stop "$@"
30 route -n flush
31 route -n flush
32 for i in ${ipv6_network_interfaces}; do
33 ifconfig $i inet6 -defaultif
34 done
31}
32
33static_start()
34{
35}
36
37static_start()
38{
39 local _af
40 _af=$1
41
42 case ${_af} in
43 inet)
44 do_static inet add
45 ;;
46 inet6)
47 do_static inet6 add
48 ;;
49 atm)
50 do_static atm add
51 ;;
52 *)
53 do_static inet add
54 do_static inet6 add
55 do_static atm add
56 ;;
57 esac
58}
59
60static_stop()
61{
62 local _af
63 _af=$1
64
65 case ${_af} in
66 inet)
67 do_static inet delete
68 ;;
69 inet6)
70 do_static inet6 delete
71 ;;
72 atm)
73 do_static atm delete
74 ;;
75 *)
76 do_static inet delete
77 do_static inet6 delete
78 do_static atm delete
79 ;;
80 esac
81}
82
83do_static()
84{
85 local _af _action
86 _af=$1
87 _action=$2
88
89 eval $1_static $2
90}
91
92inet_static()
93{
94 local _action
95 _action=$1
96
35 case ${defaultrouter} in
36 [Nn][Oo] | '')
37 ;;
38 *)
39 static_routes="default ${static_routes}"
40 route_default="default ${defaultrouter}"
41 ;;
42 esac
43
97 case ${defaultrouter} in
98 [Nn][Oo] | '')
99 ;;
100 *)
101 static_routes="default ${static_routes}"
102 route_default="default ${defaultrouter}"
103 ;;
104 esac
105
44 # Setup static routes. This should be done before router discovery.
45 #
46 if [ -n "${static_routes}" ]; then
47 for i in ${static_routes}; do
106 if [ -n "${static_routes}" ]; then
107 for i in ${static_routes}; do
48 eval route_args=\$route_${i}
49 route add ${route_args}
108 route_args=`get_if_var $i route_IF`
109 route ${_action} ${route_args}
50 done
51 fi
110 done
111 fi
52 # Now ATM static routes
53 #
112}
113
114inet6_static()
115{
116 local _action i
117 _action=$1
118
119 # disallow "internal" addresses to appear on the wire
120 route ${_action} -inet6 ::ffff:0.0.0.0 -prefixlen 96 ::1 -reject
121 route ${_action} -inet6 ::0.0.0.0 -prefixlen 96 ::1 -reject
122
123 case ${ipv6_defaultrouter} in
124 [Nn][Oo] | '')
125 ;;
126 *)
127 ipv6_static_routes="default ${ipv6_static_routes}"
128 ipv6_route_default="default ${ipv6_defaultrouter}"
129 ;;
130 esac
131
132 if [ -n "${ipv6_static_routes}" ]; then
133 for i in ${ipv6_static_routes}; do
134 ipv6_route_args=`get_if_var $i ipv6_route_IF`
135 route ${_action} -inet6 ${route_args}
136 done
137 fi
138
139 # Fixup $ipv6_network_interfaces
140 case ${ipv6_network_interfaces} in
141 [Nn][Oo][Nn][Ee])
142 ipv6_network_interfaces=''
143 ;;
144 esac
145
146 if checkyesno ipv6_gateway_enable; then
147 for i in ${ipv6_network_interfaces}; do
148
149 laddr=`network6_getladdr $i exclude_tentative`
150 case ${laddr} in
151 '')
152 ;;
153 *)
154 ipv6_working_interfaces="$i \
155 ${ipv6_working_interfaces}"
156 ;;
157 esac
158 done
159 ipv6_network_interfaces=${ipv6_working_interfaces}
160 fi
161
162 # Install the "default interface" to kernel, which will be used
163 # as the default route when there's no router.
164 case "${ipv6_default_interface}" in
165 [Nn][Oo] | [Nn][Oo][Nn][Ee])
166 ipv6_default_interface=""
167 ;;
168 [Aa][Uu][Tt][Oo] | "")
169 for i in ${ipv6_network_interfaces}; do
170 case $i in
171 lo0|faith[0-9]*)
172 continue
173 ;;
174 esac
175 laddr=`network6_getladdr $i exclude_tentative`
176 case ${laddr} in
177 '')
178 ;;
179 *)
180 ipv6_default_interface=$i
181 break
182 ;;
183 esac
184 done
185 ;;
186 esac
187
188 # Disallow unicast packets without outgoing scope identifiers,
189 # or route such packets to a "default" interface, if it is specified.
190 route ${_action} -inet6 fe80:: -prefixlen 10 ::1 -reject
191
192 case ${ipv6_default_interface} in
193 '')
194 route ${_action} -inet6 ff02:: -prefixlen 16 ::1 -reject
195 ;;
196 *)
197 laddr=`network6_getladdr ${ipv6_default_interface}`
198 route ${_action} -inet6 ff02:: ${laddr} -prefixlen 16 -interface
199
200 # Disable installing the default interface with the
201 # case net.inet6.ip6.forwarding=0 and
202 # the interface with no ND6_IFF_ACCEPT_RTADV
203 # to avoid conflict between the default router list and
204 # the manual configured default route.
205 if ! checkyesno ipv6_gateway_enable; then
206 ifconfig ${ipv6_default_interface} nd6 | \
207 while read proto options
208 do
209 case "${proto}:${options}" in
210 nd6:*ACCEPT_RTADV*)
211 ifconfig ${ipv6_default_interface} inet6 defaultif
212 break
213 ;;
214 esac
215 done
216 fi
217 ;;
218 esac
219}
220
221atm_static()
222{
223 local _action i
224 _action=$1
225
54 if [ -n "${natm_static_routes}" ]; then
55 for i in ${natm_static_routes}; do
226 if [ -n "${natm_static_routes}" ]; then
227 for i in ${natm_static_routes}; do
56 eval route_args=\$route_${i}
57 atmconfig natm add ${route_args}
228 route_args=`get_if_var $i route_IF`
229 atmconfig natm ${_action} ${route_args}
58 done
59 fi
60}
61
62_ropts_initdone=
63ropts_init()
64{
65 if [ -z "${_ropts_initdone}" ]; then
66 echo -n 'Additional routing options:'
67 _ropts_initdone=yes
68 fi
69}
70
71options_start()
72{
230 done
231 fi
232}
233
234_ropts_initdone=
235ropts_init()
236{
237 if [ -z "${_ropts_initdone}" ]; then
238 echo -n 'Additional routing options:'
239 _ropts_initdone=yes
240 fi
241}
242
243options_start()
244{
73 case ${icmp_bmcastecho} in
74 [Yy][Ee][Ss])
245 if checkyesno icmp_bmcastecho; then
75 ropts_init
76 echo -n ' broadcast ping responses=YES'
77 sysctl net.inet.icmp.bmcastecho=1 >/dev/null
246 ropts_init
247 echo -n ' broadcast ping responses=YES'
248 sysctl net.inet.icmp.bmcastecho=1 >/dev/null
78 ;;
79 esac
249 fi
80
250
81 case ${icmp_drop_redirect} in
82 [Yy][Ee][Ss])
251 if checkyesno icmp_drop_redirect; then
83 ropts_init
84 echo -n ' ignore ICMP redirect=YES'
85 sysctl net.inet.icmp.drop_redirect=1 >/dev/null
252 ropts_init
253 echo -n ' ignore ICMP redirect=YES'
254 sysctl net.inet.icmp.drop_redirect=1 >/dev/null
86 ;;
87 esac
255 fi
88
256
89 case ${icmp_log_redirect} in
90 [Yy][Ee][Ss])
257 if checkyesno icmp_log_redirect; then
91 ropts_init
92 echo -n ' log ICMP redirect=YES'
93 sysctl net.inet.icmp.log_redirect=1 >/dev/null
258 ropts_init
259 echo -n ' log ICMP redirect=YES'
260 sysctl net.inet.icmp.log_redirect=1 >/dev/null
94 ;;
95 esac
261 fi
96
262
97 case ${gateway_enable} in
98 [Yy][Ee][Ss])
263 if checkyesno gateway_enable; then
99 ropts_init
264 ropts_init
100 echo -n ' IP gateway=YES'
265 echo -n ' IPv4 gateway=YES'
101 sysctl net.inet.ip.forwarding=1 >/dev/null
266 sysctl net.inet.ip.forwarding=1 >/dev/null
102 ;;
103 esac
267 fi
104
268
105 case ${forward_sourceroute} in
106 [Yy][Ee][Ss])
269 if checkyesno ipv6_gateway_enable; then
107 ropts_init
270 ropts_init
271 echo -n ' IPv6 gateway=YES'
272 sysctl net.inet6.ip6.forwarding=1 >/dev/null
273 fi
274
275 if checkyesno forward_sourceroute; then
276 ropts_init
108 echo -n ' do source routing=YES'
109 sysctl net.inet.ip.sourceroute=1 >/dev/null
277 echo -n ' do source routing=YES'
278 sysctl net.inet.ip.sourceroute=1 >/dev/null
110 ;;
111 esac
279 fi
112
280
113 case ${accept_sourceroute} in
114 [Yy][Ee][Ss])
281 if checkyesno accept_sourceroute; then
115 ropts_init
116 echo -n ' accept source routing=YES'
117 sysctl net.inet.ip.accept_sourceroute=1 >/dev/null
282 ropts_init
283 echo -n ' accept source routing=YES'
284 sysctl net.inet.ip.accept_sourceroute=1 >/dev/null
118 ;;
119 esac
285 fi
120
286
121 case ${ipxgateway_enable} in
122 [Yy][Ee][Ss])
287 if checkyesno ipxgateway_enable; then
123 ropts_init
124 echo -n ' IPX gateway=YES'
125 sysctl net.ipx.ipx.ipxforwarding=1 >/dev/null
288 ropts_init
289 echo -n ' IPX gateway=YES'
290 sysctl net.ipx.ipx.ipxforwarding=1 >/dev/null
126 ;;
127 esac
291 fi
128
292
129 case ${arpproxy_all} in
130 [Yy][Ee][Ss])
293 if checkyesno arpproxy_all; then
131 ropts_init
132 echo -n ' ARP proxyall=YES'
133 sysctl net.link.ether.inet.proxyall=1 >/dev/null
294 ropts_init
295 echo -n ' ARP proxyall=YES'
296 sysctl net.link.ether.inet.proxyall=1 >/dev/null
134 ;;
135 esac
297 fi
136
137 [ -n "${_ropts_initdone}" ] && echo '.'
138}
139
140load_rc_config $name
298
299 [ -n "${_ropts_initdone}" ] && echo '.'
300}
301
302load_rc_config $name
141run_rc_command "$1"
303run_rc_command "$@"