net-routing-setup revision a192e900f6d2b0e1a822e3252c0dfd795ed49d76
0N/A#!/sbin/sh
2252N/A#
0N/A# CDDL HEADER START
0N/A#
0N/A# The contents of this file are subject to the terms of the
0N/A# Common Development and Distribution License (the "License").
0N/A# You may not use this file except in compliance with the License.
0N/A#
0N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0N/A# or http://www.opensolaris.org/os/licensing.
0N/A# See the License for the specific language governing permissions
0N/A# and limitations under the License.
0N/A#
0N/A# When distributing Covered Code, include this CDDL HEADER in each
0N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
0N/A# If applicable, add the following below this CDDL HEADER, with the
0N/A# fields enclosed by brackets "[]" replaced with your own identifying
0N/A# information: Portions Copyright [yyyy] [name of copyright owner]
1472N/A#
1472N/A# CDDL HEADER END
1472N/A#
0N/A#
0N/A# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
0N/A# Use is subject to license terms.
1879N/A#
1879N/A# ident "%Z%%M% %I% %E% SMI"
1879N/A
1879N/A# This script configures IP routing.
1879N/A
1879N/A. /lib/svc/share/smf_include.sh
1879N/A
0N/A#
0N/A# In a zone we need this service to be up, but all of the work
0N/A# it tries to do is irrelevant (and will actually lead to the service
0N/A# failing if we try to do it), so just bail out.
0N/A#
0N/Asmf_is_globalzone || exit $SMF_EXIT_OK
0N/A
0N/A#
0N/A# If routing.conf file is in place, and has not already been read in
0N/A# by previous invokation of routeadm, we run routeadm -u here to get
0N/A# and apply legacy configuration. We also run "routeadm -u" when
0N/A# a /var/svc/profile/upgrade file is found, as it may contain routeadm commands
0N/A# which need to be applied. It would be nice if we could do this in
0N/A# network/loopback, but since the SMF backend is read-only at that
0N/A# point in boot, we cannot.
0N/A#
0N/A
0N/Aupgrade_routing_conf=""
0N/Arouting_conf_read=`/usr/bin/svcprop -p routeadm/routing-conf-read $SMF_FMRI`
1703N/Aif [ -f /etc/inet/routing.conf -a "$routing_conf_read" = "false" ]; then
0N/A upgrade_routing_conf="true"
0N/Afi
0N/Aif [ "$upgrade_routing_conf" = "true" -o -f /var/svc/profile/upgrade ]; then
0N/A /sbin/routeadm -u
0N/Afi
0N/A
0N/A#
0N/A# Are we routing dynamically? routeadm(1M) reports this in the
0N/A# "current" values of ipv4/6-routing - if either are true, we are running
0N/A# routing daemons (or at least they are enabled to run).
0N/A#
0N/Adynamic_routing_test=`/sbin/routeadm -p | \
0N/Anawk '/^ipv[46]-routing [.]*/ { print $2 }' | /usr/bin/grep "current=enabled"`
0N/Aif [ -n "$dynamic_routing_test" ]; then
0N/A dynamic_routing="true"
0N/Afi
0N/A
0N/A/usr/sbin/ifconfig -a6u >/etc/svc/volatile/ifconfig.$$
0N/Anumv6ifs=`/usr/bin/grep -c inet6 /etc/svc/volatile/ifconfig.$$`
0N/Aif [ $numv6ifs -gt 1 ]; then
0N/A #
0N/A # Add a static route for multicast packets out of a link-local
0N/A # interface, although would like to specify multicast interface using
0N/A # an interface name!
0N/A #
0N/A set -- `/usr/bin/awk '
0N/A /inet6 fe80:/ {
0N/A print substr($2, 1, index($2, "/") - 1)
0N/A }' /etc/svc/volatile/ifconfig.$$`
0N/A
0N/A if [ -n "$1" ]; then
0N/A echo "Setting default IPv6 interface for multicast:" \
0N/A "add net ff00::/8: gateway $1"
0N/A /usr/sbin/route -n add -interface -inet6 "ff00::/8" "$1" \
0N/A >/dev/null
0N/A fi
0N/Afi
0N/A/usr/bin/rm -f /etc/svc/volatile/ifconfig.$$
0N/A
0N/A#
0N/A# Configure default IPv4 routers using the local "/etc/defaultrouter"
0N/A# configuration file. The file can contain the hostnames or IP
0N/A# addresses of one or more default routers. If hostnames are used,
1703N/A# each hostname must also be listed in the local "/etc/hosts" file
1703N/A# because NIS and NIS+ are not running at the time that this script is
0N/A# run. Each router name or address is listed on a single line by
2252N/A# itself in the file. Anything else on that line after the router's
2252N/A# name or address is ignored. Lines that begin with "#" are
2252N/A# considered comments and ignored.
2252N/A#
2252N/A# The default routes listed in the "/etc/defaultrouter" file will
2252N/A# replace those added by the kernel during diskless booting. An
2252N/A# empty "/etc/defaultrouter" file will cause the default route
2252N/A# added by the kernel to be deleted.
2252N/A#
2252N/A# Note that the default router file is ignored if we received routes
2252N/A# from a DHCP server. Our policy is to always trust DHCP over local
2252N/A# administration.
2252N/A#
2252N/Asmf_netstrategy
2252N/A
2252N/Aif [ "$_INIT_NET_STRATEGY" = "dhcp" ] && \
0N/A [ -n "`/sbin/dhcpinfo Router`" ]; then
0N/A defrouters=`/sbin/dhcpinfo Router`
2252N/Aelif [ -f /etc/defaultrouter ]; then
1703N/A defrouters=`/usr/bin/grep -v \^\# /etc/defaultrouter | \
0N/A /usr/bin/awk '{print $1}'`
0N/A if [ -n "$defrouters" ]; then
0N/A #
0N/A # We want the default router(s) listed in
0N/A # /etc/defaultrouter to replace the one added from the
0N/A # BOOTPARAMS WHOAMI response but we must avoid flushing
0N/A # the last route between the running system and its
0N/A # /usr file system.
0N/A #
0N/A
0N/A # First, remember the original route.
0N/A shift $#
0N/A set -- `/usr/bin/netstat -rn -f inet | \
0N/A /usr/bin/grep '^default'`
0N/A route_IP="$2"
0N/A
0N/A #
0N/A # Next, add those from /etc/defaultrouter. While doing
0N/A # this, if one of the routes we add is for the route
0N/A # previously added as a result of the BOOTPARAMS
0N/A # response, we will see a message of the form:
0N/A # "add net default: gateway a.b.c.d: entry exists"
0N/A #
0N/A do_delete=yes
0N/A for router in $defrouters; do
0N/A set -- `/usr/sbin/route -n add default \
0N/A -gateway $router`
0N/A [ $? -ne 0 -a "x$5" = "x$route_IP:" ] \
0N/A && do_delete=no
0N/A done
0N/A
0N/A #
0N/A # Finally, delete the original default route unless it
0N/A # was also listed in the defaultrouter file.
0N/A #
0N/A if [ -n "$route_IP" -a $do_delete = yes ]; then
0N/A /usr/sbin/route -n delete default \
0N/A -gateway $route_IP >/dev/null
0N/A fi
0N/A else
0N/A /usr/sbin/route -fn > /dev/null
0N/A fi
0N/Aelse
0N/A defrouters=
0N/Afi
0N/A
0N/A#
0N/A# Use routeadm(1M) to configure forwarding and launch routing daemons
0N/A# for IPv4 and IPv6 based on preset values. These settings only apply
0N/A# to the global zone. For IPv4 dynamic routing, the system will default
0N/A# to disabled if a default route was previously added via BOOTP, DHCP,
0N/A# or the /etc/defaultrouter file. routeadm also starts in.ndpd.
0N/A#
0N/Aif [ "$dynamic_routing" != "true" ] && [ -z "$defrouters" ]; then
0N/A #
0N/A # No default routes were setup by "route" command above.
0N/A # Check the kernel routing table for any other default
0N/A # routes.
0N/A #
0N/A /usr/bin/netstat -rn -f inet | \
0N/A /usr/bin/grep default >/dev/null 2>&1 && defrouters=yes
0N/Afi
1703N/A
0N/A#
0N/A# The routeadm/ipv4-routing-set property is true if the administrator
0N/A# has run "routeadm -e/-d ipv4-routing". If not, we revert to the
0N/A# appropriate defaults. We no longer run "routeadm -u" on every boot
0N/A# however, as persistent daemon state is now controlled by SMF.
0N/A#
1703N/Aipv4_routing_set=`/usr/bin/svcprop -p routeadm/ipv4-routing-set $SMF_FMRI`
0N/Aif [ -z "$defrouters" ]; then
0N/A #
0N/A # Set default value for ipv4-routing to enabled. If routeadm -e/-d
0N/A # has not yet been run by the administrator, we apply this default.
0N/A #
0N/A /usr/sbin/svccfg -s $SMF_FMRI \
1703N/A setprop routeadm/default-ipv4-routing = true
1703N/A if [ "$ipv4_routing_set" = "false" ]; then
1703N/A /sbin/routeadm -e ipv4-routing -u
0N/A fi
0N/Aelse
0N/A #
0N/A # Default router(s) have been found, so ipv4-routing default value
1703N/A # should be disabled. If routaedm -e/d has not yet been run by
0N/A # the administrator, we apply this default.
0N/A /usr/sbin/svccfg -s $SMF_FMRI \
0N/A setprop routeadm/default-ipv4-routing = false
0N/A if [ "$ipv4_routing_set" = "false" ]; then
1703N/A /sbin/routeadm -d ipv4-routing -u
1703N/A fi
1703N/Afi
1703N/A
1703N/A#
1703N/A# Set 6to4 Relay Router communication support policy and, if applicable,
1703N/A# the destination Relay Router IPv4 address. See /etc/default/inetinit for
1703N/A# setting and further info on ACCEPT6TO4RELAY and RELAY6TO4ADDR.
1703N/A# If ACCEPT6TO4RELAY=NO, the default value in the kernel will
1703N/A# be used.
0N/A#
0N/AACCEPT6TO4RELAY=`echo "$ACCEPT6TO4RELAY" | /usr/bin/tr '[A-Z]' '[a-z]'`
0N/Aif [ "$ACCEPT6TO4RELAY" = yes ]; then
0N/A if [ "$RELAY6TO4ADDR" ]; then
0N/A /usr/sbin/6to4relay -e -a $RELAY6TO4ADDR
0N/A else
0N/A /usr/sbin/6to4relay -e
0N/A fi
0N/Afi
0N/A
0N/A#
0N/A# Read /etc/inet/static_routes and add each route.
0N/A#
0N/Aif [ -f /etc/inet/static_routes ]; then
0N/A echo "Adding persistent routes:"
0N/A /usr/bin/egrep -v "^(#|$)" /etc/inet/static_routes | while read line; do
0N/A /usr/sbin/route add $line
0N/A done
0N/Afi
0N/A
1202N/A# Clear exit status.
1202N/Aexit $SMF_EXIT_OK
1202N/A