defaultroute revision 50735
1#!/bin/sh - 2# 3# $FreeBSD: head/etc/rc.d/routing 50735 1999-09-01 08:57:01Z peter $ 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 [ "${ipxgateway_enable}" = "YES" ]; then 233 echo -n ' IPX gateway=YES' 234 sysctl -w net.ipx.ipx.ipxforwarding=1 >/dev/null 235 fi 236 237 if [ "${arpproxy_all}" = "YES" ]; then 238 echo -n ' ARP proxyall=YES' 239 sysctl -w net.link.ether.inet.proxyall=1 >/dev/null 240 fi 241 echo '.' 242 243 echo -n 'routing daemons:' 244 if [ "${router_enable}" = "YES" ]; then 245 echo -n " ${router}"; ${router} ${router_flags} 246 fi 247 248 if [ "${ipxrouted_enable}" = "YES" ]; then 249 echo -n ' IPXrouted' 250 IPXrouted ${ipxrouted_flags} > /dev/null 2>&1 251 fi 252 253 if [ "${mrouted_enable}" = "YES" ]; then 254 echo -n ' mrouted'; mrouted ${mrouted_flags} 255 fi 256 257 if [ "${rarpd_enable}" = "YES" ]; then 258 echo -n ' rarpd'; rarpd ${rarpd_flags} 259 fi 260 echo '.' 261 network_pass1_done=YES # Let future generations know we made it. 262} 263 264network_pass2() { 265 echo -n 'Doing additional network setup:' 266 if [ "${named_enable}" = "YES" ]; then 267 echo -n ' named'; ${named_program-"named"} ${named_flags} 268 fi 269 270 if [ "${ntpdate_enable}" = "YES" ]; then 271 echo -n ' ntpdate'; ${ntpdate_program} ${ntpdate_flags} >/dev/null 2>&1 272 fi 273 274 if [ "${xntpd_enable}" = "YES" ]; then 275 echo -n ' xntpd'; ${xntpd_program} ${xntpd_flags} 276 fi 277 278 if [ "${timed_enable}" = "YES" ]; then 279 echo -n ' timed'; timed ${timed_flags} 280 fi 281 282 if [ "${portmap_enable}" = "YES" ]; then 283 echo -n ' portmap'; ${portmap_program} ${portmap_flags} 284 fi 285 286 # Start ypserv if we're an NIS server. 287 # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server. 288 if [ "${nis_server_enable}" = "YES" ]; then 289 echo -n ' ypserv'; ypserv ${nis_server_flags} 290 291 if [ "${nis_ypxfrd_enable}" = "YES" ]; then 292 echo -n ' rpc.ypxfrd'; rpc.ypxfrd ${nis_ypxfrd_flags} 293 fi 294 295 if [ "${nis_yppasswdd_enable}" = "YES" ]; then 296 echo -n ' rpc.yppasswdd'; rpc.yppasswdd ${nis_yppasswdd_flags} 297 fi 298 fi 299 300 # Start ypbind if we're an NIS client 301 if [ "${nis_client_enable}" = "YES" ]; then 302 echo -n ' ypbind'; ypbind ${nis_client_flags} 303 if [ "${nis_ypset_enable}" = "YES" ]; then 304 echo -n ' ypset'; ypset ${nis_ypset_flags} 305 fi 306 fi 307 308 # Start keyserv if we are running Secure RPC 309 if [ "${keyserv_enable}" = "YES" ]; then 310 echo -n ' keyserv'; keyserv ${keyserv_flags} 311 fi 312 # Start ypupdated if we are running Secure RPC and we are NIS master 313 if [ "${rpc_ypupdated_enable}" = "YES" ]; then 314 echo -n ' rpc.ypupdated'; rpc.ypupdated 315 fi 316 317 # Start ATM daemons 318 if [ -n "${atm_pass2_done}" ]; then 319 atm_pass3 320 fi 321 322 echo '.' 323 network_pass2_done=YES 324} 325 326network_pass3() { 327 echo -n 'Starting final network daemons:' 328 329 if [ "${nfs_server_enable}" = "YES" -a -r /etc/exports ]; then 330 echo -n ' mountd' 331 if [ "${weak_mountd_authentication}" = "YES" ]; then 332 mountd_flags="-n" 333 fi 334 mountd ${mountd_flags} 335 if [ "${nfs_reserved_port_only}" = "YES" ]; then 336 echo -n ' NFS on reserved port only=YES' 337 sysctl -w vfs.nfs.nfs_privport=1 >/dev/null 338 fi 339 echo -n ' nfsd'; nfsd ${nfs_server_flags} 340 if [ "${rpc_lockd_enable}" = "YES" ]; then 341 echo -n ' rpc.lockd'; rpc.lockd 342 fi 343 if [ "${rpc_statd_enable}" = "YES" ]; then 344 echo -n ' rpc.statd'; rpc.statd 345 fi 346 fi 347 348 if [ "${nfs_client_enable}" = "YES" ]; then 349 echo -n ' nfsiod'; nfsiod ${nfs_client_flags} 350 if [ "${nfs_access_cache}" != "X" ]; then 351 echo -n " NFS access cache time=${nfs_access_cache}" 352 sysctl -w vfs.nfs.access_cache_timeout=${nfs_access_cache} \ 353 >/dev/null 354 fi 355 fi 356 357 if [ "${amd_enable}" = "YES" ]; then 358 echo -n ' amd' 359 if [ "${amd_map_program}" != "NO" ]; then 360 amd_flags="${amd_flags} `eval ${amd_map_program}`" 361 fi 362 if [ -n "${amd_flags}" ] 363 then 364 amd -p ${amd_flags} > /var/run/amd.pid 2> /dev/null 365 else 366 amd 2> /dev/null 367 fi 368 fi 369 370 if [ "${rwhod_enable}" = "YES" ]; then 371 echo -n ' rwhod'; rwhod ${rwhod_flags} 372 fi 373 374 # Kerberos runs ONLY on the Kerberos server machine 375 if [ "${kerberos_server_enable}" = "YES" ]; then 376 if [ "${kerberos_stash}" = "YES" ]; then 377 stash_flag=-n 378 else 379 stash_flag= 380 fi 381 echo -n ' kerberos'; \ 382 kerberos ${stash_flag} >> /var/log/kerberos.log & 383 if [ "${kadmind_server_enable}" = "YES" ]; then 384 echo -n ' kadmind'; \ 385 (sleep 20; kadmind ${stash_flag} >/dev/null 2>&1 &) & 386 fi 387 unset stash_flag 388 fi 389 390 echo '.' 391 network_pass3_done=YES 392} 393