Setting tag sliver-openvswitch-2.2.90-1
[sliver-openvswitch.git] / debian / ifupdown.sh
1 #! /bin/sh
2
3 # Copyright (c) 2012, 2013 Nicira, Inc.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at:
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Have a look at /usr/share/doc/openvswitch-switch/README.Debian
18 # for more information about configuring the /etc/network/interfaces.
19
20 if [ -z "${IF_OVS_TYPE}" ]; then
21     exit 0
22 fi
23
24 ovs_vsctl() {
25     ovs-vsctl --timeout=5 "$@"
26 }
27
28 if (ovs_vsctl --version) > /dev/null 2>&1; then :; else
29     exit 0
30 fi
31
32 if [ "${MODE}" = "start" ]; then
33     eval OVS_EXTRA=\"${IF_OVS_EXTRA}\"
34
35     case "${IF_OVS_TYPE}" in
36         OVSBridge)
37                 ovs_vsctl -- --may-exist add-br "${IFACE}" ${IF_OVS_OPTIONS}\
38                          ${OVS_EXTRA+-- $OVS_EXTRA}
39
40                 if [ ! -z "${IF_OVS_PORTS}" ]; then
41                     ifup --allow="${IFACE}" ${IF_OVS_PORTS}
42                 fi
43                 ;;
44         OVSPort)
45                 ovs_vsctl -- --may-exist add-port "${IF_OVS_BRIDGE}"\
46                     "${IFACE}" ${IF_OVS_OPTIONS} \
47                     ${OVS_EXTRA+-- $OVS_EXTRA}
48
49                 ifconfig "${IFACE}" up
50                 ;;
51         OVSIntPort)
52                 ovs_vsctl -- --may-exist add-port "${IF_OVS_BRIDGE}"\
53                     "${IFACE}" ${IF_OVS_OPTIONS} -- set Interface "${IFACE}"\
54                     type=internal ${OVS_EXTRA+-- $OVS_EXTRA}
55
56                 ifconfig "${IFACE}" up
57                 ;;
58         OVSBond)
59                 ovs_vsctl -- --fake-iface add-bond "${IF_OVS_BRIDGE}"\
60                     "${IFACE}" ${IF_OVS_BONDS} ${IF_OVS_OPTIONS} \
61                     ${OVS_EXTRA+-- $OVS_EXTRA}
62
63                 ifconfig "${IFACE}" up
64                 for slave in ${IF_OVS_BONDS}
65                 do
66                     ifconfig "${slave}" up
67                 done
68                 ;;
69         OVSTunnel)
70                 ovs_vsctl -- --may-exist add-port "${IF_OVS_BRIDGE}"\
71                     "${IFACE}" ${IF_OVS_OPTIONS} -- set Interface "${IFACE}" \
72                     type=${IF_OVS_TUNNEL_TYPE} ${IF_OVS_TUNNEL_OPTIONS} \
73                     ${OVS_EXTRA+-- $OVS_EXTRA}
74                 ;;
75         *)
76                 exit 0
77                 ;;
78     esac
79 elif [ "${MODE}" = "stop" ]; then
80     case "${IF_OVS_TYPE}" in
81         OVSBridge)
82                 if [ ! -z "${IF_OVS_PORTS}" ]; then
83                     ifdown --allow="${IFACE}" ${IF_OVS_PORTS}
84                 fi
85
86                 ovs_vsctl -- --if-exists del-br "${IFACE}"
87                 ;;
88         OVSPort|OVSIntPort|OVSBond|OVSTunnel)
89                 ovs_vsctl -- --if-exists del-port "${IF_OVS_BRIDGE}" "${IFACE}"
90                 ;;
91         *)
92                 exit 0
93                 ;;
94     esac
95 fi
96
97 exit 0