defaultroute revision 51209
1#!/bin/sh - 2# 3# $FreeBSD: head/etc/rc.d/routing 51209 1999-09-12 17:22:08Z des $ 4# From: @(#)netstart 5.9 (Berkeley) 3/30/91 5 6# Note that almost all the user-configurable behavior is no longer in 7# this file, but rather in /etc/rc.conf. Please check that file 8# first before contemplating any changes here. If you do need to change 9# this file for some reason, we would like to know about it. 10 11# First pass startup stuff. 12 13network_pass1() { 14 echo -n 'Doing initial network setup:' 15 # Set the host name if it is not already set 16 if [ -z "`hostname -s`" ] ; then 17 hostname ${hostname} 18 echo -n ' hostname' 19 fi 20 21 # Set the domainname if we're using NIS 22 if [ -n "${nisdomainname}" -a "${nisdomainname}" != "NO" ] ; then 23 domainname ${nisdomainname} 24 echo -n ' domain' 25 fi 26 echo '.' 27 28 # Initial ATM interface configuration 29 if [ "${atm_enable}" = "YES" -a -f /etc/rc.atm ]; then 30 . /etc/rc.atm 31 atm_pass1 32 fi 33 34 # ISDN subsystem startup 35 if [ "${isdn_enable}" = "YES" -a -f /etc/rc.isdn ]; then 36 . /etc/rc.isdn 37 fi 38 39 # Special options for sppp(4) interfaces go here. These need 40 # to go _before_ the general ifconfig section, since in the case 41 # of hardwired (no link1 flag) but required authentication, you 42 # cannot pass auth parameters down to the already running interface. 43 for ifn in ${sppp_interfaces}; do 44 eval spppcontrol_args=\$spppconfig_${ifn} 45 if [ -n "${spppcontrol_args}" ] ; then 46 # The auth secrets might contain spaces; in order 47 # to retain the quotation, we need to eval them 48 # here. 49 eval spppcontrol ${ifn} ${spppcontrol_args} 50 fi 51 done 52 53 # Set up all the network interfaces, calling startup scripts if needed 54 if [ "${network_interfaces}" = "auto" ]; then 55 network_interfaces="`ifconfig -l`" 56 fi 57 for ifn in ${network_interfaces}; do 58 showstat=false 59 if [ -e /etc/start_if.${ifn} ]; then 60 . /etc/start_if.${ifn} 61 showstat=true 62 fi 63 # Do the primary ifconfig if specified 64 eval ifconfig_args=\$ifconfig_${ifn} 65 if [ -n "${ifconfig_args}" ] ; then 66 # See if we are using DHCP 67 if [ "${ifconfig_args}" = "DHCP" ]; then 68 ${dhcp_program} ${dhcp_flags} ${ifn} 69 else 70 ifconfig ${ifn} ${ifconfig_args} 71 fi 72 showstat=true 73 fi 74 # Check to see if aliases need to be added 75 alias=0 76 while : 77 do 78 eval ifconfig_args=\$ifconfig_${ifn}_alias${alias} 79 if [ -n "${ifconfig_args}" ]; then 80 ifconfig ${ifn} ${ifconfig_args} alias 81 showstat=true 82 alias=`expr ${alias} + 1` 83 else 84 break; 85 fi 86 done 87 # Do ipx address if specified 88 eval ifconfig_args=\$ifconfig_${ifn}_ipx 89 if [ -n "${ifconfig_args}" ]; then 90 ifconfig ${ifn} ${ifconfig_args} 91 showstat=true 92 fi 93 if [ "${showstat}" = "true" ] 94 then 95 ifconfig ${ifn} 96 fi 97 done 98 99 # Warm up user ppp if required, must happen before natd. 100 if [ "${ppp_enable}" = "YES" ]; then 101 # Establish ppp mode. 102 if [ "${ppp_mode}" != "ddial" -a "${ppp_mode}" != "direct" \ 103 -a "${ppp_mode}" != "dedicated" \ 104 -a "${ppp_mode}" != "background" ]; then 105 ppp_mode="auto"; 106 fi 107 ppp_command="-${ppp_mode} "; 108 109 # Switch on alias mode? 110 if [ "${ppp_nat}" = "YES" ]; then 111 ppp_command="${ppp_command} -nat"; 112 fi 113 114 echo -n 'Starting ppp: '; ppp ${ppp_command} -quiet ${ppp_profile} 115 fi 116 117 # Initialize IP filtering using ipfw 118 echo "" 119 /sbin/ipfw -q flush > /dev/null 2>&1 120 if [ $? = 0 ] ; then 121 firewall_in_kernel=1 122 else 123 firewall_in_kernel=0 124 fi 125 126 if [ ${firewall_in_kernel} = 0 -a "${firewall_enable}" = "YES" ] ; then 127 if kldload ipfw; then 128 firewall_in_kernel=1 # module loaded successfully 129 echo "Kernel firewall module loaded." 130 else 131 echo "Warning: firewall kernel module failed to load." 132 fi 133 fi 134 135 # Load the filters if required 136 if [ ${firewall_in_kernel} = 1 ]; then 137 if [ -z "${firewall_script}" ] ; then 138 firewall_script="/etc/rc.firewall" 139 fi 140 if [ -f ${firewall_script} -a "${firewall_enable}" = "YES" ]; then 141 . ${firewall_script} 142 echo -n 'Firewall rules loaded, starting divert daemons:' 143 144 # Network Address Translation daemon 145 if [ "${natd_enable}" = "YES" -a -n "${natd_interface}" ]; then 146 if echo ${natd_interface} | \ 147 grep -q -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'; then 148 natd_ifarg="-a ${natd_interface}" 149 else 150 natd_ifarg="-n ${natd_interface}" 151 fi 152 echo -n ' natd'; ${natd_program} ${natd_flags} ${natd_ifarg} 153 fi 154 echo '.' 155 else 156 IPFW_DEFAULT=`ipfw l 65535` 157 if [ "${IPFW_DEFAULT}" = "65535 deny ip from any to any" ]; then 158 echo -n "Warning: kernel has firewall functionality, " 159 echo "but firewall rules are not enabled." 160 echo " All ip services are disabled." 161 fi 162 fi 163 fi 164 165 # Additional ATM interface configuration 166 if [ -n "${atm_pass1_done}" ]; then 167 atm_pass2 168 fi 169 170 # Configure routing 171 172 if [ "${defaultrouter}" != "NO" ] ; then 173 static_routes="default ${static_routes}" 174 route_default="default ${defaultrouter}" 175 fi 176 177 # Set up any static routes. This should be done before router discovery. 178 if [ -n "${static_routes}" ]; then 179 for i in ${static_routes}; do 180 eval route_args=\$route_${i} 181 route add ${route_args} 182 done 183 fi 184 185 echo -n 'Additional routing options:' 186 if [ -n "${tcp_extensions}" -a "${tcp_extensions}" != "YES" ] ; then 187 echo -n ' tcp extensions=NO' 188 sysctl -w net.inet.tcp.rfc1323=0 >/dev/null 189 fi 190 191 if [ -n "${log_in_vain}" -a "${log_in_vain}" != "NO" ] ; then 192 echo -n ' log_in_vain=YES' 193 sysctl -w net.inet.tcp.log_in_vain=1 >/dev/null 194 sysctl -w net.inet.udp.log_in_vain=1 >/dev/null 195 fi 196 197 if [ "${icmp_bmcastecho}" = "YES" ]; then 198 echo -n ' broadcast ping responses=YES' 199 sysctl -w net.inet.icmp.bmcastecho=1 >/dev/null 200 fi 201 202 if [ "${icmp_drop_redirect}" = "YES" ]; then 203 echo -n ' ignore ICMP redirect=YES' 204 sysctl -w net.inet.icmp.drop_redirect=1 >/dev/null 205 fi 206 207 if [ "${icmp_log_redirect}" = "YES" ]; then 208 echo -n ' log ICMP redirect=YES' 209 sysctl -w net.inet.icmp.log_redirect=1 >/dev/null 210 fi 211 212 if [ "${gateway_enable}" = "YES" ]; then 213 echo -n ' IP gateway=YES' 214 sysctl -w net.inet.ip.forwarding=1 >/dev/null 215 fi 216 217 if [ "${forward_sourceroute}" = "YES" ]; then 218 echo -n ' do source routing=YES' 219 sysctl -w net.inet.ip.sourceroute=1 >/dev/null 220 fi 221 222 if [ "${accept_sourceroute}" = "YES" ]; then 223 echo -n ' accept source routing=YES' 224 sysctl -w net.inet.ip.accept_sourceroute=1 >/dev/null 225 fi 226 227 if [ "${tcp_keepalive}" = "YES" ]; then 228 echo -n ' TCP keepalive=YES' 229 sysctl -w net.inet.tcp.always_keepalive=1 >/dev/null 230 fi 231 232 if [ "X$tcp_restrict_rst" = X"YES" ]; then 233 echo -n ' restrict TCP reset=YES' 234 sysctl -w net.inet.tcp.restrict_rst=1 >/dev/null 235 fi 236 237 if [ "X$tcp_drop_synfin" = X"YES" ]; then 238 echo -n ' drop SYN+FIN packets=YES' 239 sysctl -w net.inet.tcp.drop_synfin=1 >/dev/null 240 fi 241 242 if [ "${ipxgateway_enable}" = "YES" ]; then 243 echo -n ' IPX gateway=YES' 244 sysctl -w net.ipx.ipx.ipxforwarding=1 >/dev/null 245 fi 246 247 if [ "${arpproxy_all}" = "YES" ]; then 248 echo -n ' ARP proxyall=YES' 249 sysctl -w net.link.ether.inet.proxyall=1 >/dev/null 250 fi 251 echo '.' 252 253 echo -n 'routing daemons:' 254 if [ "${router_enable}" = "YES" ]; then 255 echo -n " ${router}"; ${router} ${router_flags} 256 fi 257 258 if [ "${ipxrouted_enable}" = "YES" ]; then 259 echo -n ' IPXrouted' 260 IPXrouted ${ipxrouted_flags} > /dev/null 2>&1 261 fi 262 263 if [ "${mrouted_enable}" = "YES" ]; then 264 echo -n ' mrouted'; mrouted ${mrouted_flags} 265 fi 266 267 if [ "${rarpd_enable}" = "YES" ]; then 268 echo -n ' rarpd'; rarpd ${rarpd_flags} 269 fi 270 echo '.' 271 network_pass1_done=YES # Let future generations know we made it. 272} 273 274network_pass2() { 275 echo -n 'Doing additional network setup:' 276 if [ "${named_enable}" = "YES" ]; then 277 echo -n ' named'; ${named_program-"named"} ${named_flags} 278 fi 279 280 if [ "${ntpdate_enable}" = "YES" ]; then 281 echo -n ' ntpdate'; ${ntpdate_program} ${ntpdate_flags} >/dev/null 2>&1 282 fi 283 284 if [ "${xntpd_enable}" = "YES" ]; then 285 echo -n ' xntpd'; ${xntpd_program} ${xntpd_flags} 286 fi 287 288 if [ "${timed_enable}" = "YES" ]; then 289 echo -n ' timed'; timed ${timed_flags} 290 fi 291 292 if [ "${portmap_enable}" = "YES" ]; then 293 echo -n ' portmap'; ${portmap_program} ${portmap_flags} 294 fi 295 296 # Start ypserv if we're an NIS server. 297 # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server. 298 if [ "${nis_server_enable}" = "YES" ]; then 299 echo -n ' ypserv'; ypserv ${nis_server_flags} 300 301 if [ "${nis_ypxfrd_enable}" = "YES" ]; then 302 echo -n ' rpc.ypxfrd'; rpc.ypxfrd ${nis_ypxfrd_flags} 303 fi 304 305 if [ "${nis_yppasswdd_enable}" = "YES" ]; then 306 echo -n ' rpc.yppasswdd'; rpc.yppasswdd ${nis_yppasswdd_flags} 307 fi 308 fi 309 310 # Start ypbind if we're an NIS client 311 if [ "${nis_client_enable}" = "YES" ]; then 312 echo -n ' ypbind'; ypbind ${nis_client_flags} 313 if [ "${nis_ypset_enable}" = "YES" ]; then 314 echo -n ' ypset'; ypset ${nis_ypset_flags} 315 fi 316 fi 317 318 # Start keyserv if we are running Secure RPC 319 if [ "${keyserv_enable}" = "YES" ]; then 320 echo -n ' keyserv'; keyserv ${keyserv_flags} 321 fi 322 # Start ypupdated if we are running Secure RPC and we are NIS master 323 if [ "${rpc_ypupdated_enable}" = "YES" ]; then 324 echo -n ' rpc.ypupdated'; rpc.ypupdated 325 fi 326 327 # Start ATM daemons 328 if [ -n "${atm_pass2_done}" ]; then 329 atm_pass3 330 fi 331 332 echo '.' 333 network_pass2_done=YES 334} 335 336network_pass3() { 337 echo -n 'Starting final network daemons:' 338 339 if [ "${nfs_server_enable}" = "YES" -a -r /etc/exports ]; then 340 echo -n ' mountd' 341 if [ "${weak_mountd_authentication}" = "YES" ]; then 342 mountd_flags="-n" 343 fi 344 mountd ${mountd_flags} 345 if [ "${nfs_reserved_port_only}" = "YES" ]; then 346 echo -n ' NFS on reserved port only=YES' 347 sysctl -w vfs.nfs.nfs_privport=1 >/dev/null 348 fi 349 echo -n ' nfsd'; nfsd ${nfs_server_flags} 350 if [ "${rpc_lockd_enable}" = "YES" ]; then 351 echo -n ' rpc.lockd'; rpc.lockd 352 fi 353 if [ "${rpc_statd_enable}" = "YES" ]; then 354 echo -n ' rpc.statd'; rpc.statd 355 fi 356 fi 357 358 if [ "${nfs_client_enable}" = "YES" ]; then 359 echo -n ' nfsiod'; nfsiod ${nfs_client_flags} 360 if [ "${nfs_access_cache}" != "X" ]; then 361 echo -n " NFS access cache time=${nfs_access_cache}" 362 sysctl -w vfs.nfs.access_cache_timeout=${nfs_access_cache} \ 363 >/dev/null 364 fi 365 fi 366 367 if [ "${amd_enable}" = "YES" ]; then 368 echo -n ' amd' 369 if [ "${amd_map_program}" != "NO" ]; then 370 amd_flags="${amd_flags} `eval ${amd_map_program}`" 371 fi 372 if [ -n "${amd_flags}" ] 373 then 374 amd -p ${amd_flags} > /var/run/amd.pid 2> /dev/null 375 else 376 amd 2> /dev/null 377 fi 378 fi 379 380 if [ "${rwhod_enable}" = "YES" ]; then 381 echo -n ' rwhod'; rwhod ${rwhod_flags} 382 fi 383 384 # Kerberos runs ONLY on the Kerberos server machine 385 if [ "${kerberos_server_enable}" = "YES" ]; then 386 if [ "${kerberos_stash}" = "YES" ]; then 387 stash_flag=-n 388 else 389 stash_flag= 390 fi 391 echo -n ' kerberos'; \ 392 kerberos ${stash_flag} >> /var/log/kerberos.log & 393 if [ "${kadmind_server_enable}" = "YES" ]; then 394 echo -n ' kadmind'; \ 395 (sleep 20; kadmind ${stash_flag} >/dev/null 2>&1 &) & 396 fi 397 unset stash_flag 398 fi 399 400 echo '.' 401 network_pass3_done=YES 402} 403