]> git.proxmox.com Git - ovs.git/blame - debian/ifupdown.sh
initial import
[ovs.git] / debian / ifupdown.sh
CommitLineData
9a25910a
TL
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
20if [ -z "${IF_OVS_TYPE}" ]; then
21 exit 0
22fi
23
24ovs_vsctl() {
25 ovs-vsctl --timeout=5 "$@"
26}
27
28if_up() {
29 if [ -x /bin/ip ] ; then
30 /bin/ip link set up dev "$1"
31 else
32 ifconfig "${1}" up
33 fi
34}
35
36if (ovs_vsctl --version) > /dev/null 2>&1; then :; else
37 exit 0
38fi
39
40SERVICE_UNIT=/usr/lib/systemd/system/openvswitch-nonetwork.service
41if [ -f $SERVICE_UNIT ] && [ -x /usr/bin/systemctl ]; then
42 if ! systemctl --quiet is-active openvswitch-nonetwork.service; then
43 systemctl start openvswitch-nonetwork.service
44 fi
45else
46 if service openvswitch-switch status > /dev/null 2>&1; then
47 service openvswitch-switch start
48 fi
49fi
50
51if [ "${MODE}" = "start" ]; then
52 eval OVS_EXTRA=\"${IF_OVS_EXTRA}\"
53
54 case "${IF_OVS_TYPE}" in
55 OVSBridge)
56 ovs_vsctl -- --may-exist add-br "${IFACE}" ${IF_OVS_OPTIONS}\
57 ${OVS_EXTRA+-- $OVS_EXTRA}
58
59 if [ ! -z "${IF_OVS_PORTS}" ]; then
60 ifup --allow="${IFACE}" ${IF_OVS_PORTS}
61 fi
62 ;;
63 OVSPort)
64 ovs_vsctl -- --may-exist add-port "${IF_OVS_BRIDGE}"\
65 "${IFACE}" ${IF_OVS_OPTIONS} \
66 ${OVS_EXTRA+-- $OVS_EXTRA}
67
68 if_up "${IFACE}"
69 ;;
70 OVSIntPort)
71 ovs_vsctl -- --may-exist add-port "${IF_OVS_BRIDGE}"\
72 "${IFACE}" ${IF_OVS_OPTIONS} -- set Interface "${IFACE}"\
73 type=internal ${OVS_EXTRA+-- $OVS_EXTRA}
74
75 if_up "${IFACE}"
76 ;;
77 OVSBond)
78 ovs_vsctl -- --may-exist --fake-iface add-bond "${IF_OVS_BRIDGE}"\
79 "${IFACE}" ${IF_OVS_BONDS} ${IF_OVS_OPTIONS} \
80 ${OVS_EXTRA+-- $OVS_EXTRA}
81
82 if_up "${IFACE}"
83 for slave in ${IF_OVS_BONDS}
84 do
85 if_up "${slave}"
86 if [ -n "${IF_OVS_MTU}" ] ; then
87 ovs-vsctl set Interface "${slave}" mtu_request=${IF_OVS_MTU}
88 fi
89 done
90 ;;
91 OVSPatchPort)
92 ovs_vsctl -- --may-exist add-port "${IF_OVS_BRIDGE}"\
93 "${IFACE}" ${IF_OVS_OPTIONS} -- set Interface "${IFACE}" \
94 type=patch options:peer="${IF_OVS_PATCH_PEER}" \
95 ${OVS_EXTRA+-- $OVS_EXTRA}
96 ;;
97 OVSTunnel)
98 ovs_vsctl -- --may-exist add-port "${IF_OVS_BRIDGE}"\
99 "${IFACE}" ${IF_OVS_OPTIONS} -- set Interface "${IFACE}" \
100 type=${IF_OVS_TUNNEL_TYPE} ${IF_OVS_TUNNEL_OPTIONS} \
101 ${OVS_EXTRA+-- $OVS_EXTRA}
102 ;;
103 *)
104 exit 0
105 ;;
106 esac
107 if [ -n "${IF_OVS_MTU}" ] ; then
108 ovs-vsctl set Interface ${IFACE} mtu_request=${IF_OVS_MTU}
109 fi
110elif [ "${MODE}" = "stop" ]; then
111 case "${IF_OVS_TYPE}" in
112 OVSBridge)
113 if [ ! -z "${IF_OVS_PORTS}" ]; then
114 ifdown --allow="${IFACE}" ${IF_OVS_PORTS}
115 fi
116
117 ovs-vsctl -- --if-exists del-br "${IFACE}"
118 ;;
119 OVSPort|OVSIntPort|OVSBond|OVSPatchPort|OVSTunnel)
120 ovs-vsctl -- --if-exists del-port "${IF_OVS_BRIDGE}" "${IFACE}"
121 ;;
122 *)
123 exit 0
124 ;;
125 esac
126fi
127
128exit 0