13048Samaguire#!/sbin/sh 23048Samaguire# 33048Samaguire# CDDL HEADER START 43048Samaguire# 53048Samaguire# The contents of this file are subject to the terms of the 63048Samaguire# Common Development and Distribution License (the "License"). 73048Samaguire# You may not use this file except in compliance with the License. 83048Samaguire# 93048Samaguire# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 103048Samaguire# or http://www.opensolaris.org/os/licensing. 113048Samaguire# See the License for the specific language governing permissions 123048Samaguire# and limitations under the License. 133048Samaguire# 143048Samaguire# When distributing Covered Code, include this CDDL HEADER in each 153048Samaguire# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 163048Samaguire# If applicable, add the following below this CDDL HEADER, with the 173048Samaguire# fields enclosed by brackets "[]" replaced with your own identifying 183048Samaguire# information: Portions Copyright [yyyy] [name of copyright owner] 193048Samaguire# 203048Samaguire# CDDL HEADER END 213048Samaguire# 223048Samaguire# 23*12926SMark.Haywood@Oracle.COM# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 243048Samaguire 253048Samaguire# This script configures IP routing. 263048Samaguire 273048Samaguire. /lib/svc/share/smf_include.sh 283048Samaguire 293048Samaguire# 303448Sdh155122# In a shared-IP zone we need this service to be up, but all of the work 313048Samaguire# it tries to do is irrelevant (and will actually lead to the service 323048Samaguire# failing if we try to do it), so just bail out. 333448Sdh155122# In the global zone and exclusive-IP zones we proceed. 343048Samaguire# 353448Sdh155122smf_configure_ip || exit $SMF_EXIT_OK 363048Samaguire 373048Samaguire# 383048Samaguire# If routing.conf file is in place, and has not already been read in 393094Samaguire# by previous invokation of routeadm, legacy configuration is upgraded 403094Samaguire# by this call to "routeadm -u". This call is also needed when 413048Samaguire# a /var/svc/profile/upgrade file is found, as it may contain routeadm commands 423094Samaguire# which need to be applied. Finally, routeadm starts in.ndpd by 433094Samaguire# enabling the ndp service (in.ndpd), which is required for IPv6 address 443094Samaguire# autoconfiguration. It would be nice if we could do this in 453048Samaguire# network/loopback, but since the SMF backend is read-only at that 463048Samaguire# point in boot, we cannot. 473048Samaguire# 483094Samaguire/sbin/routeadm -u 493048Samaguire 503048Samaguire# 513048Samaguire# Are we routing dynamically? routeadm(1M) reports this in the 523048Samaguire# "current" values of ipv4/6-routing - if either are true, we are running 533048Samaguire# routing daemons (or at least they are enabled to run). 543048Samaguire# 553048Samaguiredynamic_routing_test=`/sbin/routeadm -p | \ 563048Samaguirenawk '/^ipv[46]-routing [.]*/ { print $2 }' | /usr/bin/grep "current=enabled"` 573048Samaguireif [ -n "$dynamic_routing_test" ]; then 583048Samaguire dynamic_routing="true" 593048Samaguirefi 603048Samaguire 614121Samaguire# 623048Samaguire# Configure default IPv4 routers using the local "/etc/defaultrouter" 633048Samaguire# configuration file. The file can contain the hostnames or IP 643048Samaguire# addresses of one or more default routers. If hostnames are used, 653048Samaguire# each hostname must also be listed in the local "/etc/hosts" file 6611262SRajagopal.Andra@Sun.COM# because NIS is not running at the time that this script is 673048Samaguire# run. Each router name or address is listed on a single line by 683048Samaguire# itself in the file. Anything else on that line after the router's 693048Samaguire# name or address is ignored. Lines that begin with "#" are 703048Samaguire# considered comments and ignored. 713048Samaguire# 723048Samaguire# The default routes listed in the "/etc/defaultrouter" file will 733048Samaguire# replace those added by the kernel during diskless booting. An 743048Samaguire# empty "/etc/defaultrouter" file will cause the default route 753048Samaguire# added by the kernel to be deleted. 763048Samaguire# 773048Samaguire# Note that the default router file is ignored if we received routes 783048Samaguire# from a DHCP server. Our policy is to always trust DHCP over local 793048Samaguire# administration. 803048Samaguire# 813048Samaguiresmf_netstrategy 823048Samaguire 833048Samaguireif [ "$_INIT_NET_STRATEGY" = "dhcp" ] && \ 843048Samaguire [ -n "`/sbin/dhcpinfo Router`" ]; then 853048Samaguire defrouters=`/sbin/dhcpinfo Router` 863048Samaguireelif [ -f /etc/defaultrouter ]; then 873048Samaguire defrouters=`/usr/bin/grep -v \^\# /etc/defaultrouter | \ 883048Samaguire /usr/bin/awk '{print $1}'` 893048Samaguire if [ -n "$defrouters" ]; then 903048Samaguire # 913048Samaguire # We want the default router(s) listed in 923048Samaguire # /etc/defaultrouter to replace the one added from the 933048Samaguire # BOOTPARAMS WHOAMI response but we must avoid flushing 943048Samaguire # the last route between the running system and its 953048Samaguire # /usr file system. 963048Samaguire # 973048Samaguire 983048Samaguire # First, remember the original route. 993048Samaguire shift $# 1003048Samaguire set -- `/usr/bin/netstat -rn -f inet | \ 1013048Samaguire /usr/bin/grep '^default'` 1023048Samaguire route_IP="$2" 1033048Samaguire 1043048Samaguire # 1053048Samaguire # Next, add those from /etc/defaultrouter. While doing 1063048Samaguire # this, if one of the routes we add is for the route 1073048Samaguire # previously added as a result of the BOOTPARAMS 1083048Samaguire # response, we will see a message of the form: 1093048Samaguire # "add net default: gateway a.b.c.d: entry exists" 1103048Samaguire # 1113048Samaguire do_delete=yes 1123048Samaguire for router in $defrouters; do 1134216Samaguire route_added=`/usr/sbin/route -n add default \ 1143048Samaguire -gateway $router` 1154216Samaguire res=$? 1164216Samaguire set -- $route_added 1174216Samaguire [ $res -ne 0 -a "$5" = "$route_IP:" ] && do_delete=no 1183048Samaguire done 1193048Samaguire 1203048Samaguire # 1213048Samaguire # Finally, delete the original default route unless it 1223048Samaguire # was also listed in the defaultrouter file. 1233048Samaguire # 1243048Samaguire if [ -n "$route_IP" -a $do_delete = yes ]; then 1253048Samaguire /usr/sbin/route -n delete default \ 1263048Samaguire -gateway $route_IP >/dev/null 1273048Samaguire fi 1283048Samaguire else 1293048Samaguire /usr/sbin/route -fn > /dev/null 1303048Samaguire fi 1313048Samaguireelse 1323048Samaguire defrouters= 1333048Samaguirefi 1343048Samaguire 1353048Samaguire# 1363048Samaguire# Use routeadm(1M) to configure forwarding and launch routing daemons 1373048Samaguire# for IPv4 and IPv6 based on preset values. These settings only apply 1383048Samaguire# to the global zone. For IPv4 dynamic routing, the system will default 1393048Samaguire# to disabled if a default route was previously added via BOOTP, DHCP, 1403048Samaguire# or the /etc/defaultrouter file. routeadm also starts in.ndpd. 1413048Samaguire# 1423048Samaguireif [ "$dynamic_routing" != "true" ] && [ -z "$defrouters" ]; then 1433048Samaguire # 1443048Samaguire # No default routes were setup by "route" command above. 1453048Samaguire # Check the kernel routing table for any other default 1463048Samaguire # routes. 1473048Samaguire # 1483048Samaguire /usr/bin/netstat -rn -f inet | \ 1493048Samaguire /usr/bin/grep default >/dev/null 2>&1 && defrouters=yes 1503048Samaguirefi 1513048Samaguire 1523048Samaguire# 1533048Samaguire# The routeadm/ipv4-routing-set property is true if the administrator 1543048Samaguire# has run "routeadm -e/-d ipv4-routing". If not, we revert to the 1553048Samaguire# appropriate defaults. We no longer run "routeadm -u" on every boot 1563048Samaguire# however, as persistent daemon state is now controlled by SMF. 1573048Samaguire# 1583048Samaguireipv4_routing_set=`/usr/bin/svcprop -p routeadm/ipv4-routing-set $SMF_FMRI` 1593048Samaguireif [ -z "$defrouters" ]; then 1603048Samaguire # 1613048Samaguire # Set default value for ipv4-routing to enabled. If routeadm -e/-d 1623048Samaguire # has not yet been run by the administrator, we apply this default. 1633294Samaguire # The -b option is project-private and informs routeadm not 1643294Samaguire # to treat the enable as administrator-driven. 1653048Samaguire # 1663048Samaguire /usr/sbin/svccfg -s $SMF_FMRI \ 1673048Samaguire setprop routeadm/default-ipv4-routing = true 1683048Samaguire if [ "$ipv4_routing_set" = "false" ]; then 1693294Samaguire /sbin/routeadm -b -e ipv4-routing -u 1703048Samaguire fi 1713048Samaguireelse 1723048Samaguire # 1733048Samaguire # Default router(s) have been found, so ipv4-routing default value 1743048Samaguire # should be disabled. If routaedm -e/d has not yet been run by 1753294Samaguire # the administrator, we apply this default. The -b option is 1763294Samaguire # project-private and informs routeadm not to treat the disable as 1773294Samaguire # administrator-driven. 1783294Samaguire # 1793048Samaguire /usr/sbin/svccfg -s $SMF_FMRI \ 1803048Samaguire setprop routeadm/default-ipv4-routing = false 1813048Samaguire if [ "$ipv4_routing_set" = "false" ]; then 1823294Samaguire /sbin/routeadm -b -d ipv4-routing -u 1833048Samaguire fi 1843048Samaguirefi 1853048Samaguire 1863048Samaguire# 187*12926SMark.Haywood@Oracle.COM# See if static routes were created by install. If so, they were created 188*12926SMark.Haywood@Oracle.COM# under /etc/svc/volatile. Copy them into their proper place. 189*12926SMark.Haywood@Oracle.COM# 190*12926SMark.Haywood@Oracle.COMif [ -f /etc/svc/volatile/etc/inet/static_routes ]; then 191*12926SMark.Haywood@Oracle.COM echo "Installing persistent routes" 192*12926SMark.Haywood@Oracle.COM if [ -f /etc/inet/static_routes ]; then 193*12926SMark.Haywood@Oracle.COM cat /etc/svc/volatile/etc/inet/static_routes | grep -v '^#' \ 194*12926SMark.Haywood@Oracle.COM >> /etc/inet/static_routes 195*12926SMark.Haywood@Oracle.COM else 196*12926SMark.Haywood@Oracle.COM cp /etc/svc/volatile/etc/inet/static_routes \ 197*12926SMark.Haywood@Oracle.COM /etc/inet/static_routes 198*12926SMark.Haywood@Oracle.COM fi 199*12926SMark.Haywood@Oracle.COM /usr/bin/rm /etc/svc/volatile/etc/inet/static_routes 200*12926SMark.Haywood@Oracle.COM 201*12926SMark.Haywood@Oracle.COMfi 202*12926SMark.Haywood@Oracle.COM 203*12926SMark.Haywood@Oracle.COM# 2043048Samaguire# Read /etc/inet/static_routes and add each route. 2053048Samaguire# 2063048Samaguireif [ -f /etc/inet/static_routes ]; then 2073048Samaguire echo "Adding persistent routes:" 2083048Samaguire /usr/bin/egrep -v "^(#|$)" /etc/inet/static_routes | while read line; do 2093048Samaguire /usr/sbin/route add $line 2103048Samaguire done 2113048Samaguirefi 2123048Samaguire 2133048Samaguire# Clear exit status. 2143048Samaguireexit $SMF_EXIT_OK 215