5088N/A#!/sbin/sh
5088N/A#
5088N/A#
5088N/A# CDDL HEADER START
5088N/A#
5088N/A# The contents of this file are subject to the terms of the
5088N/A# Common Development and Distribution License (the "License").
5088N/A# You may not use this file except in compliance with the License.
5088N/A#
5088N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5088N/A# or http://www.opensolaris.org/os/licensing.
5088N/A# See the License for the specific language governing permissions
5088N/A# and limitations under the License.
5088N/A#
5088N/A# When distributing Covered Code, include this CDDL HEADER in each
5088N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5088N/A# If applicable, add the following below this CDDL HEADER, with the
5088N/A# fields enclosed by brackets "[]" replaced with your own identifying
5088N/A# information: Portions Copyright [yyyy] [name of copyright owner]
5088N/A#
5088N/A# CDDL HEADER END
5088N/A#
5088N/A#
5088N/A
5088N/A#
5728N/A# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
5088N/A#
5088N/A
5088N/A. /lib/svc/share/smf_include.sh
5088N/A. /lib/svc/share/net_include.sh
5088N/A
5088N/Atypeset -r OVS_OVSDB_FMRI=svc:/application/openvswitch/ovsdb-server:default
5088N/Atypeset -r OVS_VSWITCHD_FMRI=svc:/application/openvswitch/vswitch-server:default
5088N/A
5088N/Atypeset -r OVS_USRLIB_DIR=/usr/lib/ovs
5088N/Atypeset -r OVS_VARLIB_DIR=/var/lib/ovs
5088N/Atypeset -r OVS_TMP_DIR=/var/run/ovs
5088N/Atypeset -r OVS_LOG_DIR=/var/log/ovs
5088N/A
5088N/Atypeset -r OVS_USER=_ovs
5088N/Atypeset -r OVS_GROUP=_ovs
5088N/A
5088N/Atypeset -r OVS_SBIN_DIR=/usr/sbin
5088N/Atypeset -r OVSDB_TOOL=${OVS_SBIN_DIR}/ovsdb-tool
5088N/Atypeset -r OVS_VSCTL=${OVS_SBIN_DIR}/ovs-vsctl
5088N/A
5088N/Atypeset -r OVS_VSWITCHD=ovs-vswitchd
5088N/Atypeset -r OVSDB_SERVER=ovsdb-server
5088N/Atypeset -r OVS_CLEAN=ovs-clean.py
5088N/Atypeset -r OVSDB_SERVER_PATH=${OVS_USRLIB_DIR}/${OVSDB_SERVER}
5088N/Atypeset -r OVS_VSWITCHD_PATH=${OVS_USRLIB_DIR}/${OVS_VSWITCHD}
5088N/Atypeset -r OVS_CLEAN_PATH=${OVS_USRLIB_DIR}/${OVS_CLEAN}
5088N/A
5088N/Atypeset -r OVSDB_REMOTE=${OVS_TMP_DIR}/db.sock
5088N/A
5088N/Atypeset -r PFEXEC=/usr/bin/pfexec
5088N/Atypeset -r MKDIR=/usr/bin/mkdir
5088N/Atypeset -r CHOWN=/usr/bin/chown
5088N/Atypeset -r PKILL=/usr/bin/pkill
5728N/Atypeset -r IPADM=/usr/sbin/ipadm
5088N/A
5088N/Aerrlog () {
5088N/A echo $1 >&2
5088N/A}
5088N/A
5088N/Acreate_ovs_tempdir() {
5088N/A if [[ ! -d ${OVS_TMP_DIR} ]]; then
5088N/A ${PFEXEC} ${MKDIR} -m 775 ${OVS_TMP_DIR} || exit $SMF_EXIT_ERR_CONFIG
5088N/A ${PFEXEC} ${CHOWN} ${OVS_USER}:${OVS_GROUP} ${OVS_TMP_DIR}
5088N/A fi
5088N/A}
5088N/A
5088N/Astart_ovsdb_server() {
5088N/A typeset -i OVSDB_INIT=0
5088N/A typeset -r OVSDB_DATABASE=${OVS_VARLIB_DIR}/etc/conf.db
5088N/A
5088N/A create_ovs_tempdir
5088N/A
5088N/A if [[ ! -f ${OVSDB_DATABASE} ]]; then
5088N/A typeset -r OVSDB_SCHEMA=${OVS_USRLIB_DIR}/share/vswitch.ovsschema
5088N/A
5088N/A echo "Creating ${OVSDB_DATABASE} from ${OVSDB_SCHEMA}"
5088N/A ${OVSDB_TOOL} create ${OVSDB_DATABASE} ${OVSDB_SCHEMA}
5088N/A if [ $? -ne 0 ]; then
5088N/A errlog "Error creating database, exiting"
5088N/A return 1
5088N/A fi
5088N/A OVSDB_INIT=1
5088N/A fi
5088N/A
5088N/A typeset -r OVSDB_LOGFILE=${OVS_LOG_DIR}/ovsdb-server.log
5088N/A typeset -r OVSDB_PIDFILE=${OVS_TMP_DIR}/ovsdb-server.pid
5088N/A
5088N/A ${OVSDB_SERVER_PATH} ${OVSDB_DATABASE} \
6016N/A -vconsole:emer -vsyslog:off -vfile:warn \
5088N/A --remote=punix:${OVSDB_REMOTE} \
5088N/A --remote=db:Open_vSwitch,Open_vSwitch,manager_options \
5088N/A --private-key=db:Open_vSwitch,SSL,private_key \
5088N/A --certificate=db:Open_vSwitch,SSL,certificate \
5088N/A --bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert \
5088N/A --no-chdir --log-file=${OVSDB_LOGFILE} \
5088N/A --pidfile=${OVSDB_PIDFILE} \
5088N/A --detach
5088N/A if [ $? -ne 0 ]; then
5088N/A errlog "${OVSDB_SERVER_PATH} failed with $?"
5088N/A exit $SMF_EXIT_ERR_FATAL
5088N/A fi
5088N/A
5088N/A if [ ${OVSDB_INIT} -ne 0 ]; then
5088N/A echo "Initializing OVSDB database"
5088N/A ${OVS_VSCTL} --no-wait init
5088N/A if [ $? -ne 0 ]; then
5088N/A errlog "${OVSDB_VSCTL} failed with $?"
5088N/A exit $SMF_EXIT_ERR_FATAL
5088N/A fi
5088N/A fi
5088N/A}
5088N/A
6734N/Aclean_vswitch() {
5088N/A typeset BRIDGENAME
5088N/A
6734N/A SVC_METHOD=$1
6734N/A
5088N/A ${OVS_VSCTL} list-br |
5088N/A while read BRIDGENAME; do
5728N/A ${PFEXEC} ${IPADM} disable-if -t ${BRIDGENAME} >/dev/null 2>&1
6734N/A ${OVS_CLEAN_PATH} delete-vnic ${BRIDGENAME} >/dev/null 2>&1
6734N/A if [[ $? -ne 0 && "$1" = 'stop' ]]; then
5088N/A errlog "Error $? removing ${BRIDGENAME} VNIC"
5088N/A fi
5088N/A done
5088N/A ${OVS_CLEAN_PATH} reset-ofports
6734N/A if [ $? -ne 0 ]; then
5088N/A errlog "Error $? resetting OF ports"
5088N/A fi
5088N/A
5088N/A ${OVS_CLEAN_PATH} remove-flows
5088N/A if [ $? -ne 0 ]; then
5088N/A errlog "Error $? removing OF flows"
5088N/A fi
5088N/A
5088N/A ${OVS_CLEAN_PATH} delete-etherstub ovs.etherstub0
5088N/A if [ $? -ne 0 ]; then
5088N/A errlog "Error $? deleting the OVS etherstub"
5088N/A fi
6734N/A}
5088N/A
6734N/Astop_vswitch_server() {
6734N/A typeset BRIDGENAME
6734N/A
6734N/A $PKILL -x -u ${OVS_USER} -z `smf_zonename` ${OVS_VSWITCHD}
6734N/A if [[ $? -ne 0 && $? -ne 1 ]]; then
6734N/A errlog "pkill of ${OVS_VSWITCHD} failed with $?"
6734N/A fi
6734N/A
6734N/A clean_vswitch stop
5088N/A}
5088N/A
5088N/Astart_vswitch_server() {
5088N/A typeset -r VSWITCHD_LOGFILE=${OVS_LOG_DIR}/ovs-vswitchd.log
5088N/A typeset -r VSWITCHD_PIDFILE=${OVS_TMP_DIR}/ovs-vswitchd.pid
5088N/A
5088N/A create_ovs_tempdir
5088N/A
6734N/A clean_vswitch start
6734N/A
6734N/A ${PFEXEC} ${OVS_VSWITCHD_PATH} unix:${OVSDB_REMOTE} \
6016N/A -vconsole:emer -vsyslog:off -vfile:warn --mlockall --no-chdir \
5088N/A --log-file=${VSWITCHD_LOGFILE} \
5088N/A --pidfile=${VSWITCHD_PIDFILE} \
5088N/A --detach
5088N/A if [ $? -ne 0 ]; then
5088N/A errlog "${OVS_VSWITCHD} failed with $?"
5088N/A exit $SMF_EXIT_ERR_FATAL
5088N/A fi
5728N/A
5728N/A
5728N/A ${OVS_VSCTL} list-br |
5728N/A while read BRIDGENAME; do
5728N/A ${PFEXEC} ${IPADM} enable-if -t ${BRIDGENAME} >/dev/null 2>&1
5728N/A done
5088N/A}
5088N/A
5088N/Acase "$1" in
5088N/A'start')
5088N/A case "$SMF_FMRI" in
5088N/A "${OVS_OVSDB_FMRI}")
5088N/A start_ovsdb_server
5088N/A ;;
5088N/A "${OVS_VSWITCHD_FMRI}")
5088N/A start_vswitch_server
5088N/A ;;
5088N/A *)
5088N/A echo "$SMF_FMRI does not support start method"
5088N/A exit $SMF_EXIT_ERR_FATAL
5088N/A ;;
5088N/A esac
5088N/A ;;
5088N/A'stop')
5088N/A case "$SMF_FMRI" in
5088N/A "${OVS_VSWITCHD_FMRI}")
5088N/A stop_vswitch_server
5088N/A ;;
5088N/A *)
5088N/A echo "$SMF_FMRI does not support stop method"
5088N/A exit $SMF_EXIT_ERR_FATAL
5088N/A ;;
5088N/A esac
5088N/A ;;
5088N/A*)
5088N/A echo "Service must be invoked from within SMF"
5088N/A exit $SMF_EXIT_ERR_FATAL
5088N/A ;;
5088N/Aesac
5088N/A
5088N/Aexit $SMF_EXIT_OK