|
rdobuilder |
b024ac |
#!/bin/bash
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
# Copyright (c) 2011 Alexey I. Froloff.
|
|
rdobuilder |
b024ac |
#
|
|
rdobuilder |
b024ac |
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
rdobuilder |
b024ac |
# you may not use this file except in compliance with the License.
|
|
rdobuilder |
b024ac |
# You may obtain a copy of the License at:
|
|
rdobuilder |
b024ac |
#
|
|
rdobuilder |
b024ac |
# http://www.apache.org/licenses/LICENSE-2.0
|
|
rdobuilder |
b024ac |
#
|
|
rdobuilder |
b024ac |
# Unless required by applicable law or agreed to in writing, software
|
|
rdobuilder |
b024ac |
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
rdobuilder |
b024ac |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
rdobuilder |
b024ac |
# See the License for the specific language governing permissions and
|
|
rdobuilder |
b024ac |
# limitations under the License.
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
. /etc/init.d/functions
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
cd /etc/sysconfig/network-scripts
|
|
rdobuilder |
b024ac |
. ./network-functions
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
[ -f ../network ] && . ../network
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
CONFIG=${1}
|
|
rdobuilder |
b024ac |
TIMEOUT=10
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
need_config ${CONFIG}
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
source_config
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-${REAL_DEVICETYPE}"
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
if [ ! -x ${OTHERSCRIPT} ]; then
|
|
rdobuilder |
b024ac |
OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-eth"
|
|
rdobuilder |
b024ac |
fi
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
check_recursion ()
|
|
rdobuilder |
b024ac |
{
|
|
rdobuilder |
b024ac |
[ -n "${UPPEDSTACK}" ] && for _r in ${UPPEDSTACK}; do
|
|
rdobuilder |
b024ac |
[ "$_r" = "$1" ] && return 1
|
|
rdobuilder |
b024ac |
done
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
return 0
|
|
rdobuilder |
b024ac |
}
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
ifup_ovs_bridge ()
|
|
rdobuilder |
b024ac |
{
|
|
rdobuilder |
b024ac |
if ovs-vsctl br-exists "${OVS_BRIDGE}"; then :; else
|
|
rdobuilder |
b024ac |
/sbin/ifup "${OVS_BRIDGE}"
|
|
rdobuilder |
b024ac |
fi
|
|
rdobuilder |
b024ac |
}
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
if [ -z "${UPPEDSTACK}" ]; then
|
|
rdobuilder |
b024ac |
UPPEDSTACK="${DEVICE}"
|
|
rdobuilder |
b024ac |
fi
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
[ -n "${OVSREQUIRES}" ] && for _i in ${OVSREQUIRES}; do
|
|
rdobuilder |
b024ac |
if ( check_recursion "$_i" ); then
|
|
rdobuilder |
b024ac |
UPPEDSTACK="${UPPEDSTACK} $_i" /sbin/ifup "$_i"
|
|
rdobuilder |
b024ac |
fi
|
|
rdobuilder |
b024ac |
done
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
SERVICE_UNIT=/usr/lib/systemd/system/openvswitch.service
|
|
rdobuilder |
b024ac |
if [ -f $SERVICE_UNIT ] && [ -x /usr/bin/systemctl ]; then
|
|
rdobuilder |
b024ac |
if ! systemctl --quiet is-active openvswitch.service; then
|
|
rdobuilder |
b024ac |
systemctl start openvswitch.service
|
|
rdobuilder |
b024ac |
fi
|
|
rdobuilder |
b024ac |
else
|
|
rdobuilder |
b024ac |
if [ ! -f /var/lock/subsys/openvswitch ]; then
|
|
rdobuilder |
b024ac |
/sbin/service openvswitch start
|
|
rdobuilder |
b024ac |
fi
|
|
rdobuilder |
b024ac |
fi
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
case "$TYPE" in
|
|
rdobuilder |
b024ac |
OVSBridge|OVSUserBridge)
|
|
rdobuilder |
b024ac |
# If bridge already exists and is up, it has been configured through
|
|
rdobuilder |
b024ac |
# other cases like OVSPort, OVSIntPort and OVSBond. If it is down or
|
|
rdobuilder |
b024ac |
# it does not exist, create it. It is possible for a bridge to exist
|
|
rdobuilder |
b024ac |
# because it remained in the OVSDB for some reason, but it won't be up.
|
|
rdobuilder |
b024ac |
if [ "${TYPE}" = "OVSUserBridge" ]; then
|
|
rdobuilder |
b024ac |
DATAPATH="netdev"
|
|
rdobuilder |
b024ac |
fi
|
|
rdobuilder |
b024ac |
if check_device_down "${DEVICE}"; then
|
|
rdobuilder |
b024ac |
ovs-vsctl -t ${TIMEOUT} -- --may-exist add-br "$DEVICE" $OVS_OPTIONS \
|
|
rdobuilder |
b024ac |
${OVS_EXTRA+-- $OVS_EXTRA} \
|
|
rdobuilder |
b024ac |
${STP+-- set bridge "$DEVICE" stp_enable="${STP}"} \
|
|
rdobuilder |
b024ac |
${DATAPATH+-- set bridge "$DEVICE" datapath_type="$DATAPATH"}
|
|
rdobuilder |
b024ac |
else
|
|
rdobuilder |
b024ac |
OVSBRIDGECONFIGURED="yes"
|
|
rdobuilder |
b024ac |
fi
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
# If MACADDR is provided in the interface configuration file,
|
|
rdobuilder |
b024ac |
# we need to set it using ovs-vsctl; setting it with the "ip"
|
|
rdobuilder |
b024ac |
# command in ifup-eth does not make the change persistent.
|
|
rdobuilder |
b024ac |
if [ -n "$MACADDR" ]; then
|
|
rdobuilder |
b024ac |
ovs-vsctl -t ${TIMEOUT} -- set bridge "$DEVICE" \
|
|
rdobuilder |
b024ac |
other-config:hwaddr="$MACADDR"
|
|
rdobuilder |
b024ac |
fi
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
# When dhcp is enabled, the assumption is that there will be a port to
|
|
rdobuilder |
b024ac |
# attach (otherwise, we can't reach out for dhcp). So, we do not
|
|
rdobuilder |
b024ac |
# configure the bridge through rhel's ifup infrastructure unless
|
|
rdobuilder |
b024ac |
# it is being configured after the port has been configured.
|
|
rdobuilder |
b024ac |
# The "OVSINTF" is set only after the port is configured.
|
|
rdobuilder |
b024ac |
if [ "${OVSBOOTPROTO}" = "dhcp" ] && [ -n "${OVSINTF}" ]; then
|
|
rdobuilder |
b024ac |
case " ${OVSDHCPINTERFACES} " in
|
|
rdobuilder |
b024ac |
*" ${OVSINTF} "*)
|
|
rdobuilder |
b024ac |
BOOTPROTO=dhcp ${OTHERSCRIPT} ${CONFIG}
|
|
rdobuilder |
b024ac |
;;
|
|
rdobuilder |
b024ac |
esac
|
|
rdobuilder |
b024ac |
fi
|
|
rdobuilder |
b024ac |
|
|
rdobuilder |
b024ac |
# When dhcp is not enabled, it is possible that someone may want
|
|
rdobuilder |
b024ac |
# a standalone bridge (i.e it may not have any ports). Configure it.
|
|
rdobuilder |
b024ac |
if [ "${OVSBOOTPROTO}" != "dhcp" ] && [ -z "${OVSINTF}" ] && \
|
|
rdobuilder |
b024ac |
[ "${OVSBRIDGECONFIGURED}" != "yes" ]; then
|
|
rdobuilder |
b024ac |
${OTHERSCRIPT} ${CONFIG}
|
|
rdobuilder |
b024ac |
fi
|
|
rdobuilder |
b024ac |
exit 0
|
|
rdobuilder |
b024ac |
;;
|
|
rdobuilder |
b024ac |
OVSPort)
|
|
rdobuilder |
b024ac |
ifup_ovs_bridge
|
|
rdobuilder |
b024ac |
${OTHERSCRIPT} ${CONFIG} ${2}
|
|
rdobuilder |
b024ac |
# The port might be already in the database but not yet
|
|
rdobuilder |
b024ac |
# in the datapath. So, remove the stale interface first.
|
|
rdobuilder |
b024ac |
ovs-vsctl -t ${TIMEOUT} \
|
|
rdobuilder |
b024ac |
-- --if-exists del-port "$OVS_BRIDGE" "$DEVICE" \
|
|
rdobuilder |
b024ac |
-- add-port "$OVS_BRIDGE" "$DEVICE" $OVS_OPTIONS ${OVS_EXTRA+-- $OVS_EXTRA}
|
|
rdobuilder |
b024ac |
OVSINTF=${DEVICE} /sbin/ifup "$OVS_BRIDGE"
|
|
rdobuilder |
b024ac |
;;
|
|
rdobuilder |
b024ac |
OVSIntPort)
|
|
rdobuilder |
b024ac |
ifup_ovs_bridge
|
|
rdobuilder |
b024ac |
ovs-vsctl -t ${TIMEOUT} \
|
|
rdobuilder |
b024ac |
-- --if-exists del-port "$OVS_BRIDGE" "$DEVICE" \
|
|
rdobuilder |
b024ac |
-- add-port "$OVS_BRIDGE" "$DEVICE" $OVS_OPTIONS \
|
|
rdobuilder |
b024ac |
-- set Interface "$DEVICE" type=internal ${OVS_EXTRA+-- $OVS_EXTRA}
|
|
rdobuilder |
b024ac |
if [ -n "${OVSDHCPINTERFACES}" ]; then
|
|
rdobuilder |
b024ac |
for _iface in ${OVSDHCPINTERFACES}; do
|
|
rdobuilder |
b024ac |
/sbin/ifup ${_iface}
|
|
rdobuilder |
b024ac |
done
|
|
rdobuilder |
b024ac |
fi
|
|
rdobuilder |
b024ac |
BOOTPROTO="${OVSBOOTPROTO}" ${OTHERSCRIPT} ${CONFIG} ${2}
|
|
rdobuilder |
b024ac |
;;
|
|
rdobuilder |
b024ac |
OVSBond)
|
|
rdobuilder |
b024ac |
ifup_ovs_bridge
|
|
rdobuilder |
b024ac |
for _iface in $BOND_IFACES; do
|
|
rdobuilder |
b024ac |
/sbin/ifup ${_iface}
|
|
rdobuilder |
b024ac |
done
|
|
rdobuilder |
b024ac |
ovs-vsctl -t ${TIMEOUT} \
|
|
rdobuilder |
b024ac |
-- --if-exists del-port "$OVS_BRIDGE" "$DEVICE" \
|
|
rdobuilder |
b024ac |
-- add-bond "$OVS_BRIDGE" "$DEVICE" ${BOND_IFACES} $OVS_OPTIONS ${OVS_EXTRA+-- $OVS_EXTRA}
|
|
rdobuilder |
b024ac |
OVSINTF=${DEVICE} /sbin/ifup "$OVS_BRIDGE"
|
|
rdobuilder |
b024ac |
;;
|
|
rdobuilder |
b024ac |
OVSTunnel)
|
|
rdobuilder |
b024ac |
ifup_ovs_bridge
|
|
rdobuilder |
b024ac |
ovs-vsctl -t ${TIMEOUT} \
|
|
rdobuilder |
b024ac |
-- --if-exists del-port "$OVS_BRIDGE" "$DEVICE" \
|
|
rdobuilder |
b024ac |
-- add-port "$OVS_BRIDGE" "$DEVICE" $OVS_OPTIONS \
|
|
rdobuilder |
b024ac |
-- set Interface "$DEVICE" type=$OVS_TUNNEL_TYPE $OVS_TUNNEL_OPTIONS ${OVS_EXTRA+-- $OVS_EXTRA}
|
|
rdobuilder |
b024ac |
;;
|
|
rdobuilder |
b024ac |
OVSPatchPort)
|
|
rdobuilder |
b024ac |
ifup_ovs_bridge
|
|
rdobuilder |
b024ac |
ovs-vsctl -t ${TIMEOUT} \
|
|
rdobuilder |
b024ac |
-- --if-exists del-port "$OVS_BRIDGE" "$DEVICE" \
|
|
rdobuilder |
b024ac |
-- add-port "$OVS_BRIDGE" "$DEVICE" $OVS_OPTIONS \
|
|
rdobuilder |
b024ac |
-- set Interface "$DEVICE" type=patch options:peer="${OVS_PATCH_PEER}" ${OVS_EXTRA+-- $OVS_EXTRA}
|
|
rdobuilder |
b024ac |
;;
|
|
rdobuilder |
b024ac |
OVSDPDKPort)
|
|
rdobuilder |
b024ac |
ifup_ovs_bridge
|
|
rdobuilder |
b024ac |
BRIDGE_MAC_ORIG=$(get_hwaddr $OVS_BRIDGE)
|
|
rdobuilder |
b024ac |
ovs-vsctl -t ${TIMEOUT} \
|
|
rdobuilder |
b024ac |
-- --if-exists del-port "$OVS_BRIDGE" "$DEVICE" \
|
|
rdobuilder |
b024ac |
-- add-port "$OVS_BRIDGE" "$DEVICE" $OVS_OPTIONS \
|
|
rdobuilder |
b024ac |
-- set Interface "$DEVICE" type=dpdk ${OVS_EXTRA+-- $OVS_EXTRA}
|
|
rdobuilder |
b024ac |
BRIDGE_MAC=$(get_hwaddr $OVS_BRIDGE)
|
|
rdobuilder |
b024ac |
# The bridge may change its MAC to be the lower one among all its
|
|
rdobuilder |
b024ac |
# ports. If that happens, bridge configuration (e.g. routes) will
|
|
rdobuilder |
b024ac |
# be lost. Restore the post-up bridge configuration again.
|
|
rdobuilder |
b024ac |
if [ "$BRIDGE_MAC_ORIG" != "$BRIDGE_MAC" ]; then
|
|
rdobuilder |
b024ac |
${OTHERSCRIPT} "$OVS_BRIDGE"
|
|
rdobuilder |
b024ac |
fi
|
|
rdobuilder |
b024ac |
;;
|
|
rdobuilder |
b024ac |
OVSDPDKVhostUserPort)
|
|
rdobuilder |
b024ac |
ifup_ovs_bridge
|
|
rdobuilder |
b024ac |
PORT_TYPE="dpdkvhostuser"
|
|
rdobuilder |
b024ac |
PORT_PATH=""
|
|
rdobuilder |
b024ac |
if [ "$OVS_PORT_MODE" == "client" ]; then
|
|
rdobuilder |
b024ac |
PORT_TYPE="dpdkvhostuserclient"
|
|
rdobuilder |
b024ac |
PORT_PATH="options:vhost-server-path=${OVS_PORT_PATH}"
|
|
rdobuilder |
b024ac |
fi
|
|
rdobuilder |
b024ac |
ovs-vsctl -t ${TIMEOUT} \
|
|
rdobuilder |
b024ac |
-- --if-exists del-port "$OVS_BRIDGE" "$DEVICE" \
|
|
rdobuilder |
b024ac |
-- add-port "$OVS_BRIDGE" "$DEVICE" $OVS_OPTIONS \
|
|
rdobuilder |
b024ac |
-- set Interface "$DEVICE" type=$PORT_TYPE \
|
|
rdobuilder |
b024ac |
$PORT_PATH \
|
|
rdobuilder |
b024ac |
${OVS_EXTRA+-- $OVS_EXTRA}
|
|
rdobuilder |
b024ac |
;;
|
|
rdobuilder |
b024ac |
OVSDPDKBond)
|
|
rdobuilder |
b024ac |
ifup_ovs_bridge
|
|
rdobuilder |
b024ac |
BRIDGE_MAC_ORIG=$(get_hwaddr $OVS_BRIDGE)
|
|
rdobuilder |
b024ac |
for _iface in $BOND_IFACES; do
|
|
rdobuilder |
b024ac |
IFACE_TYPES="${IFACE_TYPES} -- set interface ${_iface} type=dpdk"
|
|
rdobuilder |
b024ac |
done
|
|
rdobuilder |
b024ac |
ovs-vsctl -t ${TIMEOUT} \
|
|
rdobuilder |
b024ac |
-- --if-exists del-port "$OVS_BRIDGE" "$DEVICE" \
|
|
rdobuilder |
b024ac |
-- add-bond "$OVS_BRIDGE" "$DEVICE" ${BOND_IFACES} $OVS_OPTIONS ${IFACE_TYPES} ${OVS_EXTRA+-- $OVS_EXTRA}
|
|
rdobuilder |
b024ac |
BRIDGE_MAC=$(get_hwaddr $OVS_BRIDGE)
|
|
rdobuilder |
b024ac |
# The bridge may change its MAC to be the lower one among all its
|
|
rdobuilder |
b024ac |
# ports. If that happens, bridge configuration (e.g. routes) will
|
|
rdobuilder |
b024ac |
# be lost. Restore the post-up bridge configuration again.
|
|
rdobuilder |
b024ac |
if [ "$BRIDGE_MAC_ORIG" != "$BRIDGE_MAC" ]; then
|
|
rdobuilder |
b024ac |
${OTHERSCRIPT} "$OVS_BRIDGE"
|
|
rdobuilder |
b024ac |
fi
|
|
rdobuilder |
b024ac |
;;
|
|
rdobuilder |
b024ac |
*)
|
|
rdobuilder |
b024ac |
echo $"Invalid OVS interface type $TYPE"
|
|
rdobuilder |
b024ac |
exit 1
|
|
rdobuilder |
b024ac |
;;
|
|
rdobuilder |
b024ac |
esac
|