xref: /titanic_52/usr/src/cmd/cmd-inet/usr.sbin/routeadm/svc-forwarding (revision 946c3c722d7ae9fdb824ef1e5954d514773792f6)
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 2007 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26# ident	"%Z%%M%	%I%	%E% SMI"
27
28# This script is the shared method script for the ipv4-routing, ipv6-routing,
29# ipv4-forwarding and ipv6-forwarding services.
30
31. /lib/svc/share/smf_include.sh
32
33set_forwarding_flag() {
34	proto="$1"
35	value="$2"
36	ndd_flag="0"
37	if [ "$value" = "enabled" ]; then
38		ndd_flag="1"
39	fi
40	if [ "$proto" = "ipv4" ]; then
41		/usr/sbin/ndd -set /dev/ip ip_forwarding $ndd_flag
42	else
43		/usr/sbin/ndd -set /dev/ip ip6_forwarding $ndd_flag
44		/usr/sbin/ndd -set /dev/ip ip6_send_redirects $ndd_flag
45	fi
46}
47
48usage() {
49	echo "Usage: $0 { start | stop | refresh } { ipv4 | ipv6 }"
50}
51
52numv6ifs=`/usr/sbin/ifconfig -au6 | /usr/bin/grep -c inet6`
53
54method="$1"
55proto="$2"
56
57if [ -z "$proto" ]; then
58	usage
59	exit $SMF_ERROR_FATAL
60fi
61
62case "$1" in
63'start' | 'refresh' )
64	smf_configure_ip || exit $SMF_EXIT_OK
65	#
66	# Start ip forwarding.
67	#
68	if [ -z "$proto" ]; then
69		usage
70		exit $SMF_ERROR_FATAL
71	fi
72	if [ "$proto" = "ipv6" -a "$numv6ifs" = 0 ]; then
73		echo "Error: no IPv6 interface configured"
74		exit $SMF_EXIT_ERR_CONFIG
75	fi
76	set_forwarding_flag $proto enabled
77        ;;
78'stop')
79	set_forwarding_flag $proto disabled
80	;;
81*)
82	usage
83        exit $SMF_ERROR_FATAL
84        ;;
85esac
86
87exit "$SMF_EXIT_OK"
88