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