network.subr revision 49122
1#!/bin/sh - 2# 3# $Id: rc.network,v 1.51 1999/07/26 10:49:31 brian Exp $ 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 "x$nisdomainname" != "xNO" ] ; then 23 domainname $nisdomainname 24 echo -n ' domain' 25 fi 26 echo '.' 27 28 # Initial ATM interface configuration 29 if [ "X${atm_enable}" = X"YES" -a -f /etc/rc.atm ]; then 30 . /etc/rc.atm 31 atm_pass1 32 fi 33 34 # ISDN subsystem startup 35 if [ "X${isdn_enable}" = X"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 [ "x${network_interfaces}" = "xauto" ]; 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 [ X"${ifconfig_args}" = X"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 [ "X$ppp_enable" = X"YES" ]; then 101 # Establish ppp mode. 102 if [ "X$ppp_mode" != X"ddial" -a "X$ppp_mode" != X"direct" \ 103 -a "X$ppp_mode" != X"dedicated" ]; then \ 104 ppp_mode="auto"; 105 fi 106 ppp_command="-${ppp_mode} "; 107 108 # Switch on alias mode? 109 if [ "X$ppp_alias" = X"YES" ]; then 110 ppp_command="${ppp_command} -alias"; 111 fi 112 113 echo -n 'Starting ppp: '; ppp ${ppp_command} ${ppp_profile} 114 fi 115 116 # Initialize IP filtering using ipfw 117 echo "" 118 /sbin/ipfw -q flush > /dev/null 2>&1 119 if [ $? = 0 ] ; then 120 firewall_in_kernel=1 121 else 122 firewall_in_kernel=0 123 fi 124 125 if [ $firewall_in_kernel = 0 -a "x$firewall_enable" = "xYES" ] ; then 126 if kldload ipfw; then 127 firewall_in_kernel=1 # module loaded successfully 128 echo "Kernel firewall module loaded." 129 else 130 echo "Warning: firewall kernel module failed to load." 131 fi 132 fi 133 134 # Load the filters if required 135 if [ $firewall_in_kernel = 1 ]; then 136 if [ -z "${firewall_script}" ] ; then 137 firewall_script="/etc/rc.firewall" 138 fi 139 if [ -f ${firewall_script} -a X"$firewall_enable" = X"YES" ]; then 140 . ${firewall_script} 141 echo -n 'Firewall rules loaded, starting divert daemons:' 142 143 # Network Address Translation daemon 144 if [ X"${natd_enable}" = X"YES" -a -n "${natd_interface}" ]; then 145 if echo ${natd_interface} | \ 146 grep -q -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'; then 147 natd_ifarg="-a ${natd_interface}" 148 else 149 natd_ifarg="-n ${natd_interface}" 150 fi 151 echo -n ' natd'; ${natd_program} ${natd_flags} ${natd_ifarg} 152 fi 153 echo '.' 154 else 155 IPFW_DEFAULT=`ipfw l 65535` 156 if [ "$IPFW_DEFAULT" = "65535 deny ip from any to any" ]; then 157 echo -n "Warning: kernel has firewall functionality, " 158 echo "but firewall rules are not enabled." 159 echo " All ip services are disabled." 160 fi 161 fi 162 fi 163 164 # Additional ATM interface configuration 165 if [ -n "${atm_pass1_done}" ]; then 166 atm_pass2 167 fi 168 169 # Configure routing 170 171 if [ "x$defaultrouter" != "xNO" ] ; then 172 static_routes="default ${static_routes}" 173 route_default="default ${defaultrouter}" 174 fi 175 176 # Set up any static routes. This should be done before router discovery. 177 if [ "x${static_routes}" != "x" ]; then 178 for i in ${static_routes}; do 179 eval route_args=\$route_${i} 180 route add ${route_args} 181 done 182 fi 183 184 echo -n 'Additional routing options:' 185 if [ -n "$tcp_extensions" -a "x$tcp_extensions" != "xYES" ] ; then 186 echo -n ' tcp extensions=NO' 187 sysctl -w net.inet.tcp.rfc1323=0 >/dev/null 188 fi 189 190 if [ -n "$log_in_vain" -a "x$log_in_vain" != "xNO" ] ; then 191 echo -n ' log_in_vain=YES' 192 sysctl -w net.inet.tcp.log_in_vain=1 >/dev/null 193 sysctl -w net.inet.udp.log_in_vain=1 >/dev/null 194 fi 195 196 if [ X"$icmp_bmcastecho" = X"YES" ]; then 197 echo -n ' broadcast ping responses=YES' 198 sysctl -w net.inet.icmp.bmcastecho=1 >/dev/null 199 fi 200 201 if [ "X$gateway_enable" = X"YES" ]; then 202 echo -n ' IP gateway=YES' 203 sysctl -w net.inet.ip.forwarding=1 >/dev/null 204 fi 205 206 if [ "X$forward_sourceroute" = X"YES" ]; then 207 echo -n ' do source routing=YES' 208 sysctl -w net.inet.ip.sourceroute=1 >/dev/null 209 fi 210 211 if [ "X$accept_sourceroute" = X"YES" ]; then 212 echo -n ' accept source routing=YES' 213 sysctl -w net.inet.ip.accept_sourceroute=1 >/dev/null 214 fi 215 216 if [ "X$tcp_keepalive" = X"YES" ]; then 217 echo -n ' TCP keepalive=YES' 218 sysctl -w net.inet.tcp.always_keepalive=1 >/dev/null 219 fi 220 221 if [ "X$ipxgateway_enable" = X"YES" ]; then 222 echo -n ' IPX gateway=YES' 223 sysctl -w net.ipx.ipx.ipxforwarding=1 >/dev/null 224 fi 225 226 if [ "X$arpproxy_all" = X"YES" ]; then 227 echo -n ' ARP proxyall=YES' 228 sysctl -w net.link.ether.inet.proxyall=1 >/dev/null 229 fi 230 echo '.' 231 232 echo -n 'routing daemons:' 233 if [ "X$router_enable" = X"YES" ]; then 234 echo -n " ${router}"; ${router} ${router_flags} 235 fi 236 237 if [ "X$ipxrouted_enable" = X"YES" ]; then 238 echo -n ' IPXrouted' 239 IPXrouted ${ipxrouted_flags} > /dev/null 2>&1 240 fi 241 242 if [ "X${mrouted_enable}" = X"YES" ]; then 243 echo -n ' mrouted'; mrouted ${mrouted_flags} 244 fi 245 246 if [ "X$rarpd_enable" = X"YES" ]; then 247 echo -n ' rarpd'; rarpd ${rarpd_flags} 248 fi 249 echo '.' 250 network_pass1_done=YES # Let future generations know we made it. 251} 252 253network_pass2() { 254 echo -n 'Doing additional network setup:' 255 if [ "X${named_enable}" = X"YES" ]; then 256 echo -n ' named'; ${named_program-"named"} ${named_flags} 257 fi 258 259 if [ "X${ntpdate_enable}" = X"YES" ]; then 260 echo -n ' ntpdate'; ${ntpdate_program} ${ntpdate_flags} >/dev/null 2>&1 261 fi 262 263 if [ "X${xntpd_enable}" = X"YES" ]; then 264 echo -n ' xntpd'; ${xntpd_program} ${xntpd_flags} 265 fi 266 267 if [ "X${timed_enable}" = X"YES" ]; then 268 echo -n ' timed'; timed ${timed_flags} 269 fi 270 271 if [ "X${portmap_enable}" = X"YES" ]; then 272 echo -n ' portmap'; ${portmap_program} ${portmap_flags} 273 fi 274 275 # Start ypserv if we're an NIS server. 276 # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server. 277 if [ "X${nis_server_enable}" = X"YES" ]; then 278 echo -n ' ypserv'; ypserv ${nis_server_flags} 279 280 if [ "X${nis_ypxfrd_enable}" = X"YES" ]; then 281 echo -n ' rpc.ypxfrd'; rpc.ypxfrd ${nis_ypxfrd_flags} 282 fi 283 284 if [ "X${nis_yppasswdd_enable}" = X"YES" ]; then 285 echo -n ' rpc.yppasswdd'; rpc.yppasswdd ${nis_yppasswdd_flags} 286 fi 287 fi 288 289 # Start ypbind if we're an NIS client 290 if [ "X${nis_client_enable}" = X"YES" ]; then 291 echo -n ' ypbind'; ypbind ${nis_client_flags} 292 if [ "X${nis_ypset_enable}" = X"YES" ]; then 293 echo -n ' ypset'; ypset ${nis_ypset_flags} 294 fi 295 fi 296 297 # Start keyserv if we are running Secure RPC 298 if [ "X${keyserv_enable}" = X"YES" ]; then 299 echo -n ' keyserv'; keyserv ${keyserv_flags} 300 fi 301 # Start ypupdated if we are running Secure RPC and we are NIS master 302 if [ "X$rpc_ypupdated_enable" = X"YES" ]; then 303 echo -n ' rpc.ypupdated'; rpc.ypupdated 304 fi 305 306 # Start ATM daemons 307 if [ -n "${atm_pass2_done}" ]; then 308 atm_pass3 309 fi 310 311 echo '.' 312 network_pass2_done=YES 313} 314 315network_pass3() { 316 echo -n 'Starting final network daemons:' 317 318 if [ "X${nfs_server_enable}" = X"YES" -a -r /etc/exports ]; then 319 echo -n ' mountd' 320 if [ "X${weak_mountd_authentication}" = X"YES" ]; then 321 mountd_flags="-n" 322 fi 323 mountd ${mountd_flags} 324 if [ "X${nfs_reserved_port_only}" = X"YES" ]; then 325 echo -n ' NFS on reserved port only=YES' 326 sysctl -w vfs.nfs.nfs_privport=1 >/dev/null 327 fi 328 echo -n ' nfsd'; nfsd ${nfs_server_flags} 329 if [ "X$rpc_lockd_enable" = X"YES" ]; then 330 echo -n ' rpc.lockd'; rpc.lockd 331 fi 332 if [ "X$rpc_statd_enable" = X"YES" ]; then 333 echo -n ' rpc.statd'; rpc.statd 334 fi 335 fi 336 337 if [ "X${nfs_client_enable}" = X"YES" ]; then 338 echo -n ' nfsiod'; nfsiod ${nfs_client_flags} 339 if [ "X${nfs_access_cache}" != X ]; then 340 echo -n " NFS access cache time=${nfs_access_cache}" 341 sysctl -w vfs.nfs.access_cache_timeout=${nfs_access_cache} \ 342 >/dev/null 343 fi 344 fi 345 346 if [ "X${amd_enable}" = X"YES" ]; then 347 echo -n ' amd' 348 if [ "X${amd_map_program}" != X"NO" ]; then 349 amd_flags="${amd_flags} `eval ${amd_map_program}`" 350 fi 351 if [ -n "$amd_flags" ] 352 then 353 amd -p ${amd_flags} > /var/run/amd.pid 2> /dev/null 354 else 355 amd 2> /dev/null 356 fi 357 fi 358 359 if [ "X${rwhod_enable}" = X"YES" ]; then 360 echo -n ' rwhod'; rwhod ${rwhod_flags} 361 fi 362 363 # Kerberos runs ONLY on the Kerberos server machine 364 if [ "X${kerberos_server_enable}" = X"YES" ]; then 365 if [ "X${kerberos_stash}" = "XYES" ]; then 366 stash_flag=-n 367 else 368 stash_flag= 369 fi 370 echo -n ' kerberos'; \ 371 kerberos ${stash_flag} >> /var/log/kerberos.log & 372 if [ "X${kadmind_server_enable}" = "XYES" ]; then 373 echo -n ' kadmind'; \ 374 (sleep 20; kadmind ${stash_flag} >/dev/null 2>&1 &) & 375 fi 376 unset stash_flag 377 fi 378 379 echo '.' 380 network_pass3_done=YES 381} 382