]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - etc/rc.d/routing
MFC r231852,232127:
[FreeBSD/stable/8.git] / etc / rc.d / routing
1 #!/bin/sh
2 #
3 # Configure routing and miscellaneous network tunables
4 #
5 # $FreeBSD$
6 #
7
8 # PROVIDE: routing
9 # REQUIRE: netif ppp
10 # KEYWORD: nojail
11
12 . /etc/rc.subr
13 . /etc/network.subr
14
15 name="routing"
16 start_cmd="routing_start"
17 stop_cmd="routing_stop"
18 extra_commands="options static"
19 static_cmd="static_start"
20 options_cmd="options_start"
21
22 routing_start()
23 {
24         static_start
25         options_start
26 }
27
28 routing_stop()
29 {
30         route -n flush
31 }
32
33 static_start()
34 {
35         case ${defaultrouter} in
36         [Nn][Oo] | '')
37                 ;;
38         *)
39                 static_routes="default ${static_routes}"
40                 route_default="default ${defaultrouter}"
41                 ;;
42         esac
43
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
48                         eval route_args=\$route_${i}
49                         route add ${route_args}
50                 done
51         fi
52         # Now ATM static routes
53         #
54         if [ -n "${natm_static_routes}" ]; then
55                 for i in ${natm_static_routes}; do
56                         eval route_args=\$route_${i}
57                         atmconfig natm add ${route_args}
58                 done
59         fi
60
61         # Disallow "internal" addresses to appear on the wire if inet6
62         # is enabled.
63         if afexists inet6; then
64                 local fibs i
65
66                 # Get the number of FIBs supported.
67                 fibs=`sysctl -n net.fibs`
68                 : ${fibs:=1}
69
70                 # disallow "internal" addresses to appear on the wire
71                 i=0
72                 while test ${i} -lt ${fibs}; do
73                         setfib -F ${i} route add -inet6 \
74                             ::ffff:0.0.0.0 -prefixlen 96 ::1 -reject
75                         setfib -F ${i} route add -inet6 \
76                             ::0.0.0.0 -prefixlen 96 ::1 -reject
77                         i=$((i + 1))
78                 done
79         fi
80 }
81
82 _ropts_initdone=
83 ropts_init()
84 {
85         if [ -z "${_ropts_initdone}" ]; then
86                 echo -n 'Additional routing options:'
87                 _ropts_initdone=yes
88         fi
89 }
90
91 options_start()
92 {
93         case ${icmp_bmcastecho} in
94         [Yy][Ee][Ss])
95                 ropts_init
96                 echo -n ' broadcast ping responses=YES'
97                 sysctl net.inet.icmp.bmcastecho=1 >/dev/null
98                 ;;
99         esac
100
101         case ${icmp_drop_redirect} in
102         [Yy][Ee][Ss])
103                 ropts_init
104                 echo -n ' ignore ICMP redirect=YES'
105                 sysctl net.inet.icmp.drop_redirect=1 >/dev/null
106                 ;;
107         esac
108
109         case ${icmp_log_redirect} in
110         [Yy][Ee][Ss])
111                 ropts_init
112                 echo -n ' log ICMP redirect=YES'
113                 sysctl net.inet.icmp.log_redirect=1 >/dev/null
114                 ;;
115         esac
116
117         case ${gateway_enable} in
118         [Yy][Ee][Ss])
119                 ropts_init
120                 echo -n ' IP gateway=YES'
121                 sysctl net.inet.ip.forwarding=1 >/dev/null
122                 ;;
123         esac
124
125         case ${forward_sourceroute} in
126         [Yy][Ee][Ss])
127                 ropts_init
128                 echo -n ' do source routing=YES'
129                 sysctl net.inet.ip.sourceroute=1 >/dev/null
130                 ;;
131         esac
132
133         case ${accept_sourceroute} in
134         [Yy][Ee][Ss])
135                 ropts_init
136                 echo -n ' accept source routing=YES'
137                 sysctl net.inet.ip.accept_sourceroute=1 >/dev/null
138                 ;;
139         esac
140
141         case ${ipxgateway_enable} in
142         [Yy][Ee][Ss])
143                 ropts_init
144                 echo -n ' IPX gateway=YES'
145                 sysctl net.ipx.ipx.ipxforwarding=1 >/dev/null
146                 ;;
147         esac
148
149         case ${arpproxy_all} in
150         [Yy][Ee][Ss])
151                 ropts_init
152                 echo -n ' ARP proxyall=YES'
153                 sysctl net.link.ether.inet.proxyall=1 >/dev/null
154                 ;;
155         esac
156
157          [ -n "${_ropts_initdone}" ] && echo '.'
158 }
159
160 load_rc_config $name
161 run_rc_command "$1"