defaultroute revision 60628
1#!/bin/sh - 2# 3# $FreeBSD: head/etc/rc.d/routing 60628 2000-05-16 06:52:11Z dillon $ 4# From: @(#)netstart 5.9 (Berkeley) 3/30/91 5 6# Note that almost all of the user-configurable behavior is no longer in 7# this file, but rather in /etc/defaults/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 16 # Set the host name if it is not already set 17 # 18 if [ -z "`hostname -s`" ]; then 19 hostname ${hostname} 20 echo -n ' hostname' 21 fi 22 23 # Set the domainname if we're using NIS 24 # 25 case ${nisdomainname} in 26 [Nn][Oo] | '') 27 ;; 28 *) 29 domainname ${nisdomainname} 30 echo -n ' domain' 31 ;; 32 esac 33 34 echo '.' 35 36 # Initial ATM interface configuration 37 # 38 case ${atm_enable} in 39 [Yy][Ee][Ss]) 40 if [ -r /etc/rc.atm ]; then 41 . /etc/rc.atm 42 atm_pass1 43 fi 44 ;; 45 esac 46 47 # Special options for sppp(4) interfaces go here. These need 48 # to go _before_ the general ifconfig section, since in the case 49 # of hardwired (no link1 flag) but required authentication, you 50 # cannot pass auth parameters down to the already running interface. 51 # 52 for ifn in ${sppp_interfaces}; do 53 eval spppcontrol_args=\$spppconfig_${ifn} 54 if [ -n "${spppcontrol_args}" ]; then 55 # The auth secrets might contain spaces; in order 56 # to retain the quotation, we need to eval them 57 # here. 58 eval spppcontrol ${ifn} ${spppcontrol_args} 59 fi 60 done 61 62 # Set up all the network interfaces, calling startup scripts if needed 63 # 64 case ${network_interfaces} in 65 [Aa][Uu][Tt][Oo]) 66 network_interfaces="`ifconfig -l`" 67 ;; 68 esac 69 70 dhcp_interfaces="" 71 for ifn in ${network_interfaces}; do 72 if [ -r /etc/start_if.${ifn} ]; then 73 . /etc/start_if.${ifn} 74 eval showstat_$ifn=1 75 fi 76 77 # Do the primary ifconfig if specified 78 # 79 eval ifconfig_args=\$ifconfig_${ifn} 80 81 case ${ifconfig_args} in 82 '') 83 ;; 84 [Dd][Hh][Cc][Pp]) 85 # DHCP inits are done all in one go below 86 dhcp_interfaces="$dhcp_interfaces $ifn" 87 eval showstat_$ifn=1 88 ;; 89 *) 90 ifconfig ${ifn} ${ifconfig_args} 91 eval showstat_$ifn=1 92 ;; 93 esac 94 done 95 96 if [ ! -z "${dhcp_interfaces}" ]; then 97 ${dhcp_program:-/sbin/dhclient} ${dhcp_flags} ${dhcp_interfaces} 98 fi 99 100 for ifn in ${network_interfaces}; do 101 # Check to see if aliases need to be added 102 # 103 alias=0 104 while : ; do 105 eval ifconfig_args=\$ifconfig_${ifn}_alias${alias} 106 if [ -n "${ifconfig_args}" ]; then 107 ifconfig ${ifn} ${ifconfig_args} alias 108 eval showstat_$ifn=1 109 alias=`expr ${alias} + 1` 110 else 111 break; 112 fi 113 done 114 115 # Do ipx address if specified 116 # 117 eval ifconfig_args=\$ifconfig_${ifn}_ipx 118 if [ -n "${ifconfig_args}" ]; then 119 ifconfig ${ifn} ${ifconfig_args} 120 eval showstat_$ifn=1 121 fi 122 done 123 124 for ifn in ${network_interfaces}; do 125 eval showstat=\$showstat_${ifn} 126 if [ ! -z ${showstat} ]; then 127 ifconfig ${ifn} 128 fi 129 done 130 131 # ISDN subsystem startup 132 # 133 case ${isdn_enable} in 134 [Yy][Ee][Ss]) 135 if [ -r /etc/rc.isdn ]; then 136 . /etc/rc.isdn 137 fi 138 ;; 139 esac 140 141 # Warm up user ppp if required, must happen before natd. 142 # 143 case ${ppp_enable} in 144 [Yy][Ee][Ss]) 145 # Establish ppp mode. 146 # 147 if [ "${ppp_mode}" != "ddial" -a "${ppp_mode}" != "direct" \ 148 -a "${ppp_mode}" != "dedicated" \ 149 -a "${ppp_mode}" != "background" ]; then 150 ppp_mode="auto"; 151 fi 152 153 ppp_command="-${ppp_mode} "; 154 155 # Switch on alias mode? 156 # 157 case ${ppp_nat} in 158 [Yy][Ee][Ss]) 159 ppp_command="${ppp_command} -nat"; 160 ;; 161 esac 162 163 echo -n 'Starting ppp: '; ppp ${ppp_command} -quiet ${ppp_profile} 164 ;; 165 esac 166 167 # Initialize IP filtering using ipfw 168 # 169 echo '' 170 171 if /sbin/ipfw -q flush > /dev/null 2>&1; then 172 firewall_in_kernel=1 173 else 174 firewall_in_kernel=0 175 fi 176 177 case ${firewall_enable} in 178 [Yy][Ee][Ss]) 179 if [ "${firewall_in_kernel}" -eq 0 ] && kldload ipfw; then 180 firewall_in_kernel=1 181 echo "Kernel firewall module loaded." 182 elif [ "${firewall_in_kernel}" -eq 0 ]; then 183 echo "Warning: firewall kernel module failed to load." 184 fi 185 ;; 186 esac 187 188 # Load the filters if required 189 # 190 case ${firewall_in_kernel} in 191 1) 192 if [ -z "${firewall_script}" ]; then 193 firewall_script=/etc/rc.firewall 194 fi 195 196 case ${firewall_enable} in 197 [Yy][Ee][Ss]) 198 if [ -r "${firewall_script}" ]; then 199 . "${firewall_script}" 200 echo -n 'Firewall rules loaded, starting divert daemons:' 201 202 # Network Address Translation daemon 203 # 204 case ${natd_enable} in 205 [Yy][Ee][Ss]) 206 if [ -n "${natd_interface}" ]; then 207 if echo ${natd_interface} | \ 208 grep -q -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'; then 209 natd_ifarg="-a ${natd_interface}" 210 else 211 natd_ifarg="-n ${natd_interface}" 212 fi 213 214 echo -n ' natd'; ${natd_program:-/sbin/natd} ${natd_flags} ${natd_ifarg} 215 fi 216 ;; 217 esac 218 219 echo '.' 220 221 elif [ "`ipfw l 65535`" = "65535 deny ip from any to any" ]; then 222 echo -n "Warning: kernel has firewall functionality, " 223 echo "but firewall rules are not enabled." 224 echo " All ip services are disabled." 225 fi 226 227 case ${firewall_logging} in 228 [Yy][Ee][Ss] | '') 229 echo 'Firewall logging=YES' 230 sysctl -w net.inet.ip.fw.verbose=1 >/dev/null 231 ;; 232 *) 233 ;; 234 esac 235 236 ;; 237 esac 238 ;; 239 esac 240 241 # Additional ATM interface configuration 242 # 243 if [ -n "${atm_pass1_done}" ]; then 244 atm_pass2 245 fi 246 247 # Configure routing 248 # 249 case ${defaultrouter} in 250 [Nn][Oo] | '') 251 ;; 252 *) 253 static_routes="default ${static_routes}" 254 route_default="default ${defaultrouter}" 255 ;; 256 esac 257 258 # Set up any static routes. This should be done before router discovery. 259 # 260 if [ -n "${static_routes}" ]; then 261 for i in ${static_routes}; do 262 eval route_args=\$route_${i} 263 route add ${route_args} 264 done 265 fi 266 267 echo -n 'Additional routing options:' 268 case ${tcp_extensions} in 269 [Yy][Ee][Ss] | '') 270 ;; 271 *) 272 echo -n ' tcp extensions=NO' 273 sysctl -w net.inet.tcp.rfc1323=0 >/dev/null 274 ;; 275 esac 276 277 case ${icmp_bmcastecho} in 278 [Yy][Ee][Ss]) 279 echo -n ' broadcast ping responses=YES' 280 sysctl -w net.inet.icmp.bmcastecho=1 >/dev/null 281 ;; 282 esac 283 284 case ${icmp_drop_redirect} in 285 [Yy][Ee][Ss]) 286 echo -n ' ignore ICMP redirect=YES' 287 sysctl -w net.inet.icmp.drop_redirect=1 >/dev/null 288 ;; 289 esac 290 291 case ${icmp_log_redirect} in 292 [Yy][Ee][Ss]) 293 echo -n ' log ICMP redirect=YES' 294 sysctl -w net.inet.icmp.log_redirect=1 >/dev/null 295 ;; 296 esac 297 298 case ${gateway_enable} in 299 [Yy][Ee][Ss]) 300 echo -n ' IP gateway=YES' 301 sysctl -w net.inet.ip.forwarding=1 >/dev/null 302 ;; 303 esac 304 305 case ${forward_sourceroute} in 306 [Yy][Ee][Ss]) 307 echo -n ' do source routing=YES' 308 sysctl -w net.inet.ip.sourceroute=1 >/dev/null 309 ;; 310 esac 311 312 case ${accept_sourceroute} in 313 [Yy][Ee][Ss]) 314 echo -n ' accept source routing=YES' 315 sysctl -w net.inet.ip.accept_sourceroute=1 >/dev/null 316 ;; 317 esac 318 319 case ${tcp_keepalive} in 320 [Yy][Ee][Ss]) 321 echo -n ' TCP keepalive=YES' 322 sysctl -w net.inet.tcp.always_keepalive=1 >/dev/null 323 ;; 324 esac 325 326 case ${tcp_restrict_rst} in 327 [Yy][Ee][Ss]) 328 echo -n ' restrict TCP reset=YES' 329 sysctl -w net.inet.tcp.restrict_rst=1 >/dev/null 330 ;; 331 esac 332 333 case ${tcp_drop_synfin} in 334 [Yy][Ee][Ss]) 335 echo -n ' drop SYN+FIN packets=YES' 336 sysctl -w net.inet.tcp.drop_synfin=1 >/dev/null 337 ;; 338 esac 339 340 case ${ipxgateway_enable} in 341 [Yy][Ee][Ss]) 342 echo -n ' IPX gateway=YES' 343 sysctl -w net.ipx.ipx.ipxforwarding=1 >/dev/null 344 ;; 345 esac 346 347 case ${arpproxy_all} in 348 [Yy][Ee][Ss]) 349 echo -n ' ARP proxyall=YES' 350 sysctl -w net.link.ether.inet.proxyall=1 >/dev/null 351 ;; 352 esac 353 echo '.' 354 355 case ${ipsec_enable} in 356 [Yy][Ee][Ss]) 357 if [ -f ${ipsec_file} ]; then 358 echo ' ipsec: enabled' 359 setkey -f ${ipsec_file} 360 else 361 echo ' ipsec: file not found' 362 fi 363 ;; 364 esac 365 366 echo -n 'routing daemons:' 367 case ${router_enable} in 368 [Yy][Ee][Ss]) 369 echo -n " ${router}"; ${router} ${router_flags} 370 ;; 371 esac 372 373 case ${ipxrouted_enable} in 374 [Yy][Ee][Ss]) 375 echo -n ' IPXrouted' 376 IPXrouted ${ipxrouted_flags} > /dev/null 2>&1 377 ;; 378 esac 379 380 case ${mrouted_enable} in 381 [Yy][Ee][Ss]) 382 echo -n ' mrouted'; mrouted ${mrouted_flags} 383 ;; 384 esac 385 386 case ${rarpd_enable} in 387 [Yy][Ee][Ss]) 388 echo -n ' rarpd'; rarpd ${rarpd_flags} 389 ;; 390 esac 391 echo '.' 392 393 # Let future generations know we made it. 394 # 395 network_pass1_done=YES 396} 397 398network_pass2() { 399 echo -n 'Doing additional network setup:' 400 case ${named_enable} in 401 [Yy][Ee][Ss]) 402 echo -n ' named'; ${named_program:-named} ${named_flags} 403 ;; 404 esac 405 406 case ${ntpdate_enable} in 407 [Yy][Ee][Ss]) 408 echo -n ' ntpdate' 409 ${ntpdate_program:-ntpdate} ${ntpdate_flags} >/dev/null 2>&1 410 ;; 411 esac 412 413 case ${xntpd_enable} in 414 [Yy][Ee][Ss]) 415 echo -n ' ntpd'; ${xntpd_program:-ntpd} ${xntpd_flags} 416 ;; 417 esac 418 419 case ${timed_enable} in 420 [Yy][Ee][Ss]) 421 echo -n ' timed'; timed ${timed_flags} 422 ;; 423 esac 424 425 case ${portmap_enable} in 426 [Yy][Ee][Ss]) 427 echo -n ' portmap'; ${portmap_program:-/usr/sbin/portmap} ${portmap_flags} 428 ;; 429 esac 430 431 # Start ypserv if we're an NIS server. 432 # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server. 433 # 434 case ${nis_server_enable} in 435 [Yy][Ee][Ss]) 436 echo -n ' ypserv'; ypserv ${nis_server_flags} 437 438 case ${nis_ypxfrd_enable} in 439 [Yy][Ee][Ss]) 440 echo -n ' rpc.ypxfrd' 441 rpc.ypxfrd ${nis_ypxfrd_flags} 442 ;; 443 esac 444 445 case ${nis_yppasswdd_enable} in 446 [Yy][Ee][Ss]) 447 echo -n ' rpc.yppasswdd' 448 rpc.yppasswdd ${nis_yppasswdd_flags} 449 ;; 450 esac 451 ;; 452 esac 453 454 # Start ypbind if we're an NIS client 455 # 456 case ${nis_client_enable} in 457 [Yy][Ee][Ss]) 458 echo -n ' ypbind'; ypbind ${nis_client_flags} 459 case ${nis_ypset_enable} in 460 [Yy][Ee][Ss]) 461 echo -n ' ypset'; ypset ${nis_ypset_flags} 462 ;; 463 esac 464 ;; 465 esac 466 467 # Start keyserv if we are running Secure RPC 468 # 469 case ${keyserv_enable} in 470 [Yy][Ee][Ss]) 471 echo -n ' keyserv'; keyserv ${keyserv_flags} 472 ;; 473 esac 474 475 # Start ypupdated if we are running Secure RPC and we are NIS master 476 # 477 case ${rpc_ypupdated_enable} in 478 [Yy][Ee][Ss]) 479 echo -n ' rpc.ypupdated'; rpc.ypupdated 480 ;; 481 esac 482 483 # Start ATM daemons 484 if [ -n "${atm_pass2_done}" ]; then 485 atm_pass3 486 fi 487 488 echo '.' 489 network_pass2_done=YES 490} 491 492network_pass3() { 493 echo -n 'Starting final network daemons:' 494 495 case ${nfs_server_enable} in 496 [Yy][Ee][Ss]) 497 if [ -r /etc/exports ]; then 498 echo -n ' mountd' 499 500 case ${weak_mountd_authentication} in 501 [Yy][Ee][Ss]) 502 mountd_flags="-n" 503 ;; 504 esac 505 506 mountd ${mountd_flags} 507 508 case ${nfs_reserved_port_only} in 509 [Yy][Ee][Ss]) 510 echo -n ' NFS on reserved port only=YES' 511 sysctl -w vfs.nfs.nfs_privport=1 >/dev/null 512 ;; 513 esac 514 515 echo -n ' nfsd'; nfsd ${nfs_server_flags} 516 517 if [ -n "${nfs_bufpackets}" ]; then 518 sysctl -w vfs.nfs.bufpackets=${nfs_bufpackets} \ 519 > /dev/null 520 fi 521 522 case ${rpc_lockd_enable} in 523 [Yy][Ee][Ss]) 524 echo -n ' rpc.lockd'; rpc.lockd 525 ;; 526 esac 527 528 case ${rpc_statd_enable} in 529 [Yy][Ee][Ss]) 530 echo -n ' rpc.statd'; rpc.statd 531 ;; 532 esac 533 fi 534 ;; 535 *) 536 case ${single_mountd_enable} in 537 [Yy][Ee][Ss]) 538 if [ -r /etc/exports ]; then 539 echo -n ' mountd' 540 541 case ${weak_mountd_authentication} in 542 [Yy][Ee][Ss]) 543 mountd_flags="-n" 544 ;; 545 esac 546 547 mountd ${mountd_flags} 548 fi 549 ;; 550 esac 551 ;; 552 esac 553 554 case ${nfs_client_enable} in 555 [Yy][Ee][Ss]) 556 echo -n ' nfsiod'; nfsiod ${nfs_client_flags} 557 if [ -n "${nfs_access_cache}" ]; then 558 echo -n " NFS access cache time=${nfs_access_cache}" 559 sysctl -w vfs.nfs.access_cache_timeout=${nfs_access_cache} \ 560 >/dev/null 561 fi 562 ;; 563 esac 564 565 # If /var/db/mounttab exists, some nfs-server has not been 566 # sucessfully notified about a previous client shutdown. 567 # If there is no /var/db/mounttab, we do nothing. 568 if [ -f /var/db/mounttab ]; then 569 rpc.umntall -k 570 fi 571 572 case ${amd_enable} in 573 [Yy][Ee][Ss]) 574 echo -n ' amd' 575 case ${amd_map_program} in 576 [Nn][Oo] | '') 577 ;; 578 *) 579 amd_flags="${amd_flags} `eval ${amd_map_program}`" 580 ;; 581 esac 582 583 if [ -n "${amd_flags}" ]; then 584 amd -p ${amd_flags} > /var/run/amd.pid 2> /dev/null 585 else 586 amd 2> /dev/null 587 fi 588 ;; 589 esac 590 591 case ${rwhod_enable} in 592 [Yy][Ee][Ss]) 593 echo -n ' rwhod'; rwhod ${rwhod_flags} 594 ;; 595 esac 596 597 # Kerberos runs ONLY on the Kerberos server machine 598 case ${kerberos_server_enable} in 599 [Yy][Ee][Ss]) 600 case ${kerberos_stash} in 601 [Yy][Ee][Ss]) 602 stash_flag=-n 603 ;; 604 *) 605 stash_flag= 606 ;; 607 esac 608 609 echo -n ' kerberos' 610 kerberos ${stash_flag} >> /var/log/kerberos.log & 611 612 case ${kadmind_server_enable} in 613 [Yy][Ee][Ss]) 614 echo -n ' kadmind' 615 (sleep 20; kadmind ${stash_flag} >/dev/null 2>&1 &) & 616 ;; 617 esac 618 unset stash_flag 619 ;; 620 esac 621 622 case ${pppoed_enable} in 623 [Yy][Ee][Ss]) 624 if [ -n "${pppoed_provider}" ]; then 625 pppoed_flags="${pppoed_flags} -p ${pppoed_provider}" 626 fi 627 echo -n ' pppoed'; 628 /usr/libexec/pppoed ${pppoed_flags} ${pppoed_interface} 629 ;; 630 esac 631 632 case ${sshd_enable} in 633 [Yy][Ee][Ss]) 634 if [ ! -f /etc/ssh/ssh_host_key ]; then 635 echo ' creating ssh RSA host key'; 636 /usr/bin/ssh-keygen -N "" -f /etc/ssh/ssh_host_key 637 fi 638 if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then 639 echo ' creating ssh DSA host key'; 640 /usr/bin/ssh-keygen -d -N "" -f /etc/ssh/ssh_host_dsa_key 641 fi 642 ;; 643 esac 644 645 echo '.' 646 network_pass3_done=YES 647} 648 649network_pass4() { 650 echo -n 'Additional TCP options:' 651 case ${log_in_vain} in 652 [Nn][Oo] | '') 653 ;; 654 *) 655 echo -n ' log_in_vain=YES' 656 sysctl -w net.inet.tcp.log_in_vain=1 >/dev/null 657 sysctl -w net.inet.udp.log_in_vain=1 >/dev/null 658 ;; 659 esac 660 661 echo '.' 662 network_pass4_done=YES 663} 664