4
# Provides: nova-xcp-network
5
# Required-Start: $remote_fs $syslog
6
# Required-Stop: $remote_fs $syslog
7
# Default-Start: 2 3 4 5
9
# Short-Description: Apply initial OVS flows for Nova and network rules.
10
# Description: Apply initial OVS flows for Nova, and setup networking
11
# host rules for multi tenancy protections.
14
# Written by Thomas Goirand <zigo@debian.org> using
15
# plugins/xenserver/networking/etc/init.d/{openvswitch-nova,host-up}
18
# Licensed under the Apache License, Version 2.0 (the "License"); you may
19
# not use this file except in compliance with the License. You may obtain
20
# a copy of the License at
22
# http://www.apache.org/licenses/LICENSE-2.0
24
# Unless required by applicable law or agreed to in writing, software
25
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
26
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
27
# License for the specific language governing permissions and limitations
31
. /lib/lsb/init-functions
33
DESC="XCP openvswitch networking rules"
36
OVS_CONFIGURE_BASE_FLOWS=/usr/lib/xcp/plugins/ovs_configure_base_flows.py
37
IPTABLES=/sbin/iptables
38
EBTABLES=/sbin/ebtables
39
ARPTABLES=/sbin/arptables
41
# Quick check if everything is there...
42
if ! [ -x ${OVS_CONFIGURE_BASE_FLOWS} ] ; then
45
if ! [ -x ${IPTABLES} -a -x ${EBTABLES} -a -x ${ARPTABLES} ] ; then
48
if ! [ -x /usr/bin/ovs-ofctl -a -x /usr/bin/ovs-vsctl -a -x /sbin/ip ] ; then
52
# Load the VERBOSE setting and other rcS variables
53
[ -r /lib/init/vars.sh ] && . /lib/init/vars.sh
55
# Get $INTERFACES from /etc/default/openvswitch-nova,
56
# default to all what is available.
57
if [ -r /etc/default/openvswitch-nova ] ; then
58
. /etc/default/openvswitch-nova
60
if [ -z "${INTERFACES}" ] ; then
61
INTERFACES=$(cd /sys/class/net/; /bin/ls -d eth*)
64
# Get $NETWORK_MODE from /etc/xcp/network.conf,
65
# default to openvswitch
66
if [ -e /etc/xcp/network.conf ] ; then
67
NETWORK_MODE=`cat /etc/xcp/network.conf`
70
if [ -z "${NETWORK_MODE}" ] ; then
71
NETWORK_MODE=openvswitch
74
# Check validity of $NETWORK_MODE
75
case "${NETWORK_MODE}" in
82
echo "Open vSwitch disabled (/etc/xcp/network.conf is invalid)" >&2
87
run_ovs_conf_base_flows () {
89
my_all_interfaces=$(cd /sys/class/net/; /bin/ls -d eth*)
90
for i in ${INTERFACES} ; do
91
/usr/bin/python $OVS_CONFIGURE_BASE_FLOWS $my_action $i
95
# Functions to configure the firewall to work with openvswitch, XCP and nova
97
${IPTABLES} -P FORWARD DROP
98
for i in ${INTERFACES} ; do
99
${IPTABLES} -A FORWARD -m physdev --physdev-in ${i} -j ACCEPT
103
${EBTABLES} -P FORWARD DROP
104
for i in ${INTERFACES} ; do
105
${EBTABLES} -A FORWARD -o ${i} -j ACCEPT
109
${ARPTABLES} -P FORWARD DROP
110
for i in ${INTERFACES} ; do
111
${ARPTABLES} -A FORWARD --opcode Request --in-interface ${i} -j ACCEPT
112
${ARPTABLES} -A FORWARD --opcode Reply --in-interface ${i} -j ACCEPT
116
${IPTABLES} -P FORWARD ACCEPT
117
for i in ${INTERFACES} ; do
118
${IPTABLES} -D FORWARD -m physdev --physdev-in ${i} -j ACCEPT
122
${EBTABLES} -P FORWARD ACCEPT
123
for i in ${INTERFACES} ; do
124
${EBTABLES} -D FORWARD -o ${i} -j ACCEPT
128
${ARPTABLES} -P FORWARD ACCEPT
129
for i in ${INTERFACES} ; do
130
${ARPTABLES} -D FORWARD --opcode Request --in-interface ${i} -j ACCEPT
131
${ARPTABLES} -D FORWARD --opcode Reply --in-interface ${i} -j ACCEPT
137
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
141
run_ovs_conf_base_flows online
142
[ "$VERBOSE" != no ] && log_end_msg 0
145
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
146
run_ovs_conf_base_flows offline
150
[ "$VERBOSE" != no ] && log_end_msg 0
153
[ "$VERBOSE" != no ] && log_daemon_msg "Restarting $DESC" "$NAME"
154
run_ovs_conf_base_flows reset
155
[ "$VERBOSE" != no ] && log_end_msg 0
163
echo "Usage: $0 {start|stop|status|restart|reload|force-reload}" >&2