280N/A#!/sbin/sh
280N/A#
280N/A# CDDL HEADER START
280N/A#
280N/A# The contents of this file are subject to the terms of the
280N/A# Common Development and Distribution License (the "License").
280N/A# You may not use this file except in compliance with the License.
280N/A#
280N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
280N/A# or http://www.opensolaris.org/os/licensing.
280N/A# See the License for the specific language governing permissions
280N/A# and limitations under the License.
280N/A#
280N/A# When distributing Covered Code, include this CDDL HEADER in each
280N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
280N/A# If applicable, add the following below this CDDL HEADER, with the
280N/A# fields enclosed by brackets "[]" replaced with your own identifying
280N/A# information: Portions Copyright [yyyy] [name of copyright owner]
280N/A#
280N/A# CDDL HEADER END
280N/A#
280N/A
280N/A#
6166N/A# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
280N/A#
280N/A
280N/A. /lib/svc/share/smf_include.sh
280N/A. /lib/svc/share/net_include.sh
280N/A
280N/ASVCPROP=/usr/bin/svcprop
280N/ACHMOD=/usr/bin/chmod
6434N/ACHOWN=/usr/bin/chown
280N/ATOUCH=/usr/bin/touch
6434N/AID=/usr/bin/id
280N/A
280N/ADHCPD_IPV4="svc:/network/dhcp/server:ipv4"
280N/ADHCPD_IPV6="svc:/network/dhcp/server:ipv6"
280N/ADHCPRELAY_IPV4="svc:/network/dhcp/relay:ipv4"
747N/ADHCPRELAY_IPV6="svc:/network/dhcp/relay:ipv6"
280N/A
280N/ADHCPD_BIN="/usr/lib/inet/dhcpd"
280N/ADHCPRELAY_BIN="/usr/lib/inet/dhcrelay"
280N/A
280N/A#
280N/A# dhcpd/dhcprelay can run in a global or exclusive-stack zone only
280N/A#
280N/Asmf_configure_ip || exit $SMF_EXIT_OK
280N/A
280N/Aif [ -z $SMF_FMRI ]; then
280N/A echo "SMF framework variables are not initialized."
280N/A exit $SMF_EXIT_ERR
280N/Afi
280N/A
280N/A#
280N/A# get_prop fmri propname
280N/A#
280N/Aget_prop () {
747N/A VALUE="`$SVCPROP -cp config/$1 $SMF_FMRI 2>/dev/null`"
280N/A # Empty astring_list values show up as "" - do not return this.
280N/A if [ "$VALUE" != "\"\"" ]; then
280N/A echo $VALUE
280N/A fi
280N/A}
280N/A
280N/Aerrlog () {
280N/A echo $1 >&2
280N/A}
280N/A
280N/Aget_common_options() {
280N/A #
280N/A # get debug property value
280N/A #
280N/A if [ "`get_prop debug`" = "true" ]; then
280N/A DEBUG="-d"
280N/A else
280N/A DEBUG="-q"
280N/A fi
280N/A
280N/A export OPTIONS="$OPTIONS $DEBUG"
280N/A return 0
280N/A}
280N/A
964N/A#
964N/A# expand_prop "prop_name" "var_name" [ argflag ]
964N/A#
964N/A# prop_name FMRI property name
964N/A# var_name variable where result is stored; initialized
964N/A# to ""
964N/A# argflag The flag to be prepended to each property
964N/A# value; optional argument
964N/A#
964N/A# This function will retrieve the properties for "prop_name" via a call
964N/A# to get_prop(). It will split-up the property values; it assumes that
964N/A# the delimiter is whitespace. It will then prepend "argflag" to each
964N/A# property value. The results will be stored in "var_name" which is
964N/A# passed by reference.
964N/A#
964N/A# Return values:
964N/A#
964N/A# 0 Success
964N/A# 1 Failure
964N/A#
964N/Aexpand_prop() {
964N/A if [ $# -lt 2 ] || [ -z $2 ]; then
964N/A errlog "Internal error - expand_prop() has incorrect arguments"
964N/A return 1
964N/A fi
964N/A
964N/A prop_name=$1
964N/A typeset -n var_name=$2
964N/A argflag="$3"
964N/A
964N/A prop_values="`get_prop $prop_name`"
964N/A if [ -z "$prop_values" ]; then
964N/A errlog "The property, \"${prop_name}\", is empty"
964N/A return 1
964N/A fi
964N/A
964N/A var_name=""
964N/A for item in `IFS= ; set -- $prop_values; echo $@`; do
964N/A var_name="$var_name $argflag $item"
964N/A done
964N/A
964N/A return 0
964N/A}
964N/A
964N/A
280N/Aget_dhcpd_options() {
280N/A # get listen_ifname property value.
280N/A LISTENIFNAMES="`get_prop listen_ifnames`"
280N/A
280N/A #
280N/A # get common config file properties
280N/A #
280N/A CONFIGFILE=`get_prop config_file`
280N/A if [ -z "$CONFIGFILE" ]; then
280N/A errlog "No config_file specified, exiting"
280N/A return 1
280N/A fi
280N/A if [ ! -f "$CONFIGFILE" ]; then
280N/A errlog "Required config_file $CONFIGFILE not found, exiting"
280N/A return 1
280N/A fi
280N/A
280N/A #
280N/A # If a leasefile does not exist, create an empty file.
280N/A #
280N/A LEASEFILE=`get_prop lease_file`
280N/A if [ -z "$LEASEFILE" ]; then
280N/A errlog "No lease_file specified, exiting"
280N/A return 1
280N/A fi
6434N/A
6434N/A LEASEFILE_PERMS="u=rw,go=r"
280N/A if [ ! -f "$LEASEFILE" ]; then
280N/A $TOUCH $LEASEFILE
6434N/A $CHMOD $LEASEFILE_PERMS $LEASEFILE
6434N/A fi
6434N/A if [ ! -w "$LEASEFILE" ]; then
6434N/A errlog "Lease file '$LEASEFILE' is not writable. You should:"
6434N/A errlog "$CHOWN $($ID -u -n) '$LEASEFILE'"
6434N/A errlog "$CHMOD $LEASEFILE_PERMS '$LEASEFILE'"
6434N/A return 1
280N/A fi
280N/A
280N/A export OPTIONS="$OPTIONS -cf $CONFIGFILE -lf $LEASEFILE $LISTENIFNAMES"
280N/A return 0
280N/A}
280N/A
280N/Aget_dhcprelay_options_v4() {
280N/A #
280N/A # Get append_agent_option V4 property value
280N/A #
280N/A if [ "`get_prop append_agent_option`" = "true" ]; then
971N/A APPEND="-a -m append"
280N/A else
280N/A APPEND=""
280N/A fi
280N/A
280N/A #
280N/A # get listen_ifname property value and modify it.
280N/A # If listen_ifnames property value is "e1000g01 iprb0" then the
747N/A # command line option will look like "-i e1000g0 -i iprb0"
280N/A #
964N/A IIFLIST=
964N/A expand_prop listen_ifnames IIFLIST -i || return $?
280N/A
280N/A #
280N/A # Get servers V4 property value - command line option will look
964N/A # like "1.2.3.5" "4.5.6.7".
280N/A #
280N/A # NOTE: By default server property value is empty. User must
280N/A # first specify a server using svccfg/setprop command
280N/A # before enabling service.
280N/A #
280N/A DHCPSERVERS=`get_prop servers`
280N/A if [ -z "$DHCPSERVERS" ]; then
747N/A errlog 'Must specify at least one "servers" property value, exiting'
280N/A return 1
280N/A fi
280N/A
280N/A export OPTIONS="$OPTIONS -4 $APPEND $IIFLIST $DHCPSERVERS"
280N/A return 0
280N/A}
280N/A
280N/Aget_dhcprelay_options_v6() {
280N/A #
280N/A # Get receivelinks V6 property value and modify it:
280N/A # Given property values of "1.2.3.4%bge0#1 bge2,1.2.3.4%iprb",
280N/A # the command line option will look like "-l 1.2.3.4%bge0#1 -l
280N/A # bge2 -l 1.2.3.4%iprb".
280N/A #
280N/A # NOTE: By default receivelinks value is empty. User must
280N/A # first specify a server using svccfg/setprop command
280N/A # before enabling service.
280N/A #
964N/A IRECVLINKS=
964N/A expand_prop receive_query_links IRECVLINKS -l || return $?
280N/A #
280N/A # Get forwardlinks V6 property value and modify it:
747N/A # Given forward_query_links property value is "1.2.3.4%bge0 bge2,"
280N/A # then the command line option will look like "-u 1.2.3.4%bge0 -u
280N/A # bge2"
280N/A #
280N/A # NOTE: By default forwardlinks value is empty. User must
280N/A # first specify a server using svccfg/setprop command
280N/A # before enabling service.
280N/A #
964N/A IFWDLINKS=
964N/A expand_prop forward_query_links IFWDLINKS -u || return $?
280N/A
280N/A export OPTIONS="$OPTIONS -6 $IRECVLINKS $IFWDLINKS"
280N/A}
280N/A
280N/Aexport OPTIONS="--no-pid"
280N/A
280N/Acase "$SMF_FMRI" in
280N/A"$DHCPD_IPV4"|"$DHCPD_IPV6")
6166N/A # get omapi_conn_limit property value.
6166N/A export OMAPI_CONN_LIMIT=`get_prop omapi_conn_limit`
6166N/A
280N/A get_common_options
280N/A if [ "$?" != "0" ]; then
280N/A exit $SMF_EXIT_ERR_CONFIG
280N/A fi
280N/A get_dhcpd_options
280N/A if [ "$?" != "0" ]; then
280N/A exit $SMF_EXIT_ERR_CONFIG
280N/A fi
280N/A if [ "$SMF_FMRI" = "$DHCPD_IPV4" ]; then
280N/A OPTIONS="-4 $OPTIONS"
280N/A else
280N/A OPTIONS="-6 $OPTIONS"
280N/A fi
280N/A export EXECFILE=$DHCPD_BIN
280N/A ;;
280N/A
280N/A$DHCPRELAY_IPV4)
280N/A get_common_options
280N/A if [ $? != "0" ]; then
280N/A exit $SMF_EXIT_ERR_CONFIG
280N/A fi
280N/A get_dhcprelay_options_v4
280N/A if [ $? != "0" ]; then
280N/A exit $SMF_EXIT_ERR_CONFIG
280N/A fi
280N/A export EXECFILE=$DHCPRELAY_BIN
280N/A ;;
280N/A
280N/A$DHCPRELAY_IPV6)
280N/A get_common_options
280N/A if [ $? != "0" ]; then
280N/A exit $SMF_EXIT_ERR_CONFIG
280N/A fi
280N/A get_dhcprelay_options_v6
280N/A if [ $? != "0" ]; then
280N/A exit $SMF_EXIT_ERR_CONFIG
280N/A fi
280N/A export EXECFILE=$DHCPRELAY_BIN
280N/A ;;
280N/A
280N/A*)
280N/A echo "isc-dhcp must be invoked from within SMF"
280N/A exit $SMF_EXIT_ERR_FATAL
280N/A ;;
280N/A
280N/Aesac
280N/A
280N/A# Now start the daemon
280N/Aif [ "$DEBUG" = "-d" ]; then
280N/A $EXECFILE $OPTIONS &
280N/Aelse
280N/A $EXECFILE $OPTIONS
280N/Afi
280N/A
280N/Aif [ "$?" != "0" ]; then
280N/A exit $SMF_EXIT_ERR_FATAL
280N/Afi
280N/A
280N/Aexit $SMF_EXIT_OK