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