xref: /onnv-gate/usr/src/cmd/cmd-inet/usr.sbin/routeadm/svc-forwarding (revision 3448:aaf16568054b)
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*3448Sdh155122# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
243048Samaguire# Use is subject to license terms.
253048Samaguire#
263048Samaguire# ident	"%Z%%M%	%I%	%E% SMI"
273048Samaguire
283048Samaguire# This script is the shared method script for the ipv4-routing, ipv6-routing,
293048Samaguire# ipv4-forwarding and ipv6-forwarding services.
303048Samaguire
313048Samaguire. /lib/svc/share/smf_include.sh
323048Samaguire
333048Samaguireset_forwarding_flag() {
343048Samaguire	proto="$1"
353048Samaguire	value="$2"
363048Samaguire	ndd_flag="0"
373048Samaguire	if [ "$value" = "enabled" ]; then
383048Samaguire		ndd_flag="1"
393048Samaguire	fi
403048Samaguire	if [ "$proto" = "ipv4" ]; then
413048Samaguire		/usr/sbin/ndd -set /dev/ip ip_forwarding $ndd_flag
423048Samaguire	else
433048Samaguire		/usr/sbin/ndd -set /dev/ip ip6_forwarding $ndd_flag
443048Samaguire		/usr/sbin/ndd -set /dev/ip ip6_send_redirects $ndd_flag
453048Samaguire	fi
463048Samaguire}
473048Samaguire
483048Samaguireusage() {
493048Samaguire	echo "Usage: $0 { start | stop | refresh } { ipv4 | ipv6 }"
503048Samaguire}
513048Samaguire
523048Samaguirenumv6ifs=`/usr/sbin/ifconfig -au6 | /usr/bin/grep -c inet6`
533048Samaguire
543048Samaguiremethod="$1"
553048Samaguireproto="$2"
563048Samaguire
573048Samaguireif [ -z "$proto" ]; then
583048Samaguire	usage
593048Samaguire	exit $SMF_ERROR_FATAL
603048Samaguirefi
613048Samaguire
623048Samaguirecase "$1" in
633048Samaguire'start' | 'refresh' )
64*3448Sdh155122	smf_configure_ip || exit $SMF_EXIT_OK
653048Samaguire	#
663048Samaguire	# Start ip forwarding.
673048Samaguire	#
683048Samaguire	if [ -z "$proto" ]; then
693048Samaguire		usage
703048Samaguire		exit $SMF_ERROR_FATAL
713048Samaguire	fi
723048Samaguire	if [ "$proto" = "ipv6" -a "$numv6ifs" = 0 ]; then
733048Samaguire		echo "Error: no IPv6 interface configured"
743048Samaguire		exit $SMF_EXIT_ERR_CONFIG
753048Samaguire	fi
763048Samaguire	set_forwarding_flag $proto enabled
773048Samaguire        ;;
783048Samaguire'stop')
793048Samaguire	set_forwarding_flag $proto disabled
803048Samaguire	;;
813048Samaguire*)
823048Samaguire	usage
833048Samaguire        exit $SMF_ERROR_FATAL
843048Samaguire        ;;
853048Samaguireesac
863048Samaguire
873048Samaguireexit "$SMF_EXIT_OK"
88