xref: /titanic_52/usr/src/cmd/cmd-inet/usr.sbin/routeadm/svc-forwarding (revision 00d1d19828f3122eb24ae7a68175ba64744f8366)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26
27# This script is the shared method script for the ipv4-routing, ipv6-routing,
28# ipv4-forwarding and ipv6-forwarding services.
29
30. /lib/svc/share/smf_include.sh
31
32usage() {
33	echo "Usage: $0 { start | stop | refresh } { ipv4 | ipv6 }"
34}
35
36numv6ifs=`/usr/sbin/ifconfig -au6 | /usr/bin/grep -c inet6`
37
38method="$1"
39proto="$2"
40
41if [ -z "$proto" ]; then
42	usage
43	exit $SMF_ERROR_FATAL
44fi
45
46case "$1" in
47'start' | 'refresh' )
48	smf_configure_ip || exit $SMF_EXIT_OK
49	#
50	# Start ip forwarding.
51	#
52	if [ "$proto" = "ipv6" -a "$numv6ifs" = 0 ]; then
53		echo "Error: no IPv6 interface configured"
54		exit $SMF_EXIT_ERR_CONFIG
55	fi
56
57	/usr/sbin/ipadm set-prop -p forwarding=on $proto
58	[ "$proto" = "ipv6" ] && /usr/sbin/ipadm set-prop \
59				    -p ip6_send_redirects=1 ip
60        ;;
61'stop')
62	/usr/sbin/ipadm set-prop -p forwarding=off $proto
63	[ "$proto" = "ipv6" ] && /usr/sbin/ipadm set-prop \
64				    -p ip6_send_redirects=0 ip
65	;;
66*)
67	usage
68        exit $SMF_ERROR_FATAL
69        ;;
70esac
71
72exit "$SMF_EXIT_OK"
73