net-routing-setup revision f4b3ec61df05330d25f55a36b975b4d7519fdeb1
6d1a8b922859f63b629351cba4793043627d7c8fvboxsync# CDDL HEADER START
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# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync# See the License for the specific language governing permissions
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync# and limitations under the License.
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# CDDL HEADER END
27537ffef7291d0bb3a24e459a6b94c65586defevboxsync# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
7a39033381dbde37dc7b59b2440d643b1cbac21dvboxsync# Use is subject to license terms.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync# ident "%Z%%M% %I% %E% SMI"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync# This script configures IP routing.
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.
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# 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).
9e201d78ac6efdd08550263f2e146cdb76e9d49bvboxsyncnawk '/^ipv[46]-routing [.]*/ { print $2 }' | /usr/bin/grep "current=enabled"`
9e201d78ac6efdd08550263f2e146cdb76e9d49bvboxsyncif [ -n "$dynamic_routing_test" ]; then
8887849668e69def9136d8d8a31766069a60d7f5vboxsync/usr/sbin/ifconfig -a6u >/etc/svc/volatile/ifconfig.$$
9e201d78ac6efdd08550263f2e146cdb76e9d49bvboxsyncnumv6ifs=`/usr/bin/grep -c inet6 /etc/svc/volatile/ifconfig.$$`
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!
4e46eee5a96078ebec6cb36939b794a391f1ade0vboxsync /inet6 fe80:/ {
4e46eee5a96078ebec6cb36939b794a391f1ade0vboxsync print substr($2, 1, index($2, "/") - 1)
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" \
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.
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.
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.
48eca14ff165b52c459d7c3090f1f5dba0d1fedbvboxsync defrouters=`/usr/bin/grep -v \^\# /etc/defaultrouter | \
9e201d78ac6efdd08550263f2e146cdb76e9d49bvboxsync if [ -n "$defrouters" ]; then
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 # First, remember the original route.
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"
9e201d78ac6efdd08550263f2e146cdb76e9d49bvboxsync # Finally, delete the original default route unless it
9e201d78ac6efdd08550263f2e146cdb76e9d49bvboxsync # was also listed in the defaultrouter file.
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.
10f224d85cd1135f0ca4ee1c1c1a7e15988bed58vboxsyncif [ "$dynamic_routing" != "true" ] && [ -z "$defrouters" ]; then
9e201d78ac6efdd08550263f2e146cdb76e9d49bvboxsync # No default routes were setup by "route" command above.
9e201d78ac6efdd08550263f2e146cdb76e9d49bvboxsync # Check the kernel routing table for any other default
9e201d78ac6efdd08550263f2e146cdb76e9d49bvboxsync /usr/bin/grep default >/dev/null 2>&1 && defrouters=yes
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.
if [ -z "$defrouters" ]; then
if [ "$RELAY6TO4ADDR" ]; then
# Read /etc/inet/static_routes and add each route.
exit $SMF_EXIT_OK