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