xref: /illumos-gate/usr/src/cmd/cmd-inet/usr.sbin/in.routed/svc-route (revision 4eaa471005973e11a6110b69fe990530b3b95a38)
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 2009 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26
27. /lib/svc/share/smf_include.sh
28. /lib/svc/share/routing_include.sh
29. /lib/svc/share/ipf_include.sh
30
31smf_configure_ip || exit $SMF_EXIT_OK
32
33create_ipf_rules()
34{
35	FMRI=$1
36	file=`fmri_to_file ${FMRI} $IPF_SUFFIX`
37
38	#
39	# route:default is enabled iff route discovery is required. Allow
40	# incoming icmp from routers for successful discovery.
41	echo "# $FMRI" >$file
42	gen_IRDP_rules $file
43
44	#
45	# A potential router so apply policy to RIP, 520 udp
46	#
47	policy=`get_policy $FMRI`
48	iana_name=`svcprop -p $FW_CONTEXT_PG/name ${FMRI} 2>/dev/null`
49
50	tport=`$SERVINFO -p -t -s $iana_name 2>/dev/null`
51	uport=`$SERVINFO -p -u -s $iana_name 2>/dev/null`
52
53	if [ -n "$tport" ]; then
54		generate_rules $FMRI $policy "tcp" "any" $tport $file
55	fi
56
57	if [ -n "$uport" ]; then
58		generate_rules $FMRI $policy "udp" "any" $uport $file
59	fi
60}
61
62if [ -n "$1" -a "$1" = "ipfilter" ]; then
63	create_ipf_rules $2
64	exit "$SMF_EXIT_OK"
65fi
66
67daemon_args=`get_daemon_args $SMF_FMRI`
68options="AdghmnqsStvVzT:F:P:"
69
70#
71# Handle upgrade - routing/daemon-args property must be mapped to properties
72# in routeadm property group.  Note that the SMF-incompatible -t option is not
73# supported, since it requires that in.routed run in the foreground.
74#
75if [ -n "$daemon_args" ]; then
76	set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
77	    "$options" "A" ignore_auth false true
78	set_daemon_ordered_multivalue_property "$SMF_FMRI" "$daemon_args" \
79	    "$options" "F" minimize_routes
80	set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
81	    "$options" "g" offer_default_route true false
82	set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
83	    "$options" "h" advertise_host_routes false true
84	set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
85	    "$options" "m" advertise_host_routes_primary true false
86	set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
87	    "$options" "n" install_routes false true
88	set_daemon_ordered_multivalue_property "$SMF_FMRI" "$daemon_args" \
89	    "$options" "P" parameters
90	set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
91	    "$options" "q" quiet_mode true false
92	set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
93	    "$options" "s" supply_routes true false
94	set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
95	    "$options" "S" default_routes_only true false
96	set_daemon_value_property "$SMF_FMRI" "$daemon_args" \
97	    "$options" "T" log_file
98	set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
99	    "$options" "v" debug true false
100	set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
101	    "$options" "z" debug true
102	clear_daemon_args $SMF_FMRI
103fi
104
105#
106# Assemble arguments to daemon from properties
107#
108args="`get_daemon_option_from_boolean_property $SMF_FMRI ignore_auth \
109	A false`"
110args="$args`get_daemon_option_from_boolean_property $SMF_FMRI \
111	offer_default_route g true`"
112args="$args`get_daemon_option_from_boolean_property $SMF_FMRI \
113	advertise_host_routes h false`"
114args="$args`get_daemon_option_from_boolean_property $SMF_FMRI \
115	advertise_host_routes_primary m true`"
116args="$args`get_daemon_option_from_boolean_property $SMF_FMRI \
117	install_routes n false`"
118args="$args`get_daemon_option_from_boolean_property $SMF_FMRI \
119	quiet_mode q true`"
120args="$args`get_daemon_option_from_boolean_property $SMF_FMRI \
121		supply_routes s true`"
122args="$args`get_daemon_option_from_boolean_property $SMF_FMRI \
123	default_routes_only S true`"
124args="$args`get_daemon_option_from_boolean_property $SMF_FMRI \
125	debug z true`"
126if [ -n "$args" ]; then
127	args="-${args}"
128fi
129args="$args `get_daemon_ordered_multivalue_option_from_property $SMF_FMRI \
130	minimize_routes F`"
131args="$args `get_daemon_ordered_multivalue_option_from_property \
132	$SMF_FMRI parameters P`"
133args="$args `get_daemon_option_from_property $SMF_FMRI \
134	log_file T`"
135
136/usr/sbin/in.routed $args
137
138[ "$?" = 0 ] || exit $SMF_EXIT_ERR_FATAL
139
140exit "$SMF_EXIT_OK"
141