1 # Spec file for Open vSwitch.
3 # Copyright (C) 2009, 2010, 2011 Nicira Networks, Inc.
5 # Copying and distribution of this file, with or without modification,
6 # are permitted in any medium without royalty provided the copyright
7 # notice and this notice are preserved. This file is offered as-is,
8 # without warranty of any kind.
10 # When building, the rpmbuild command line should define
11 # openvswitch_version, kernel_name, kernel_version, kernel_flavor,
12 # and build_number using -D arguments.
15 # rpmbuild -D "openvswitch_version 1.1.0+build123"
16 # -D "kernel_name NAME-xen"
17 # -D "kernel_version 2.6.32.12-0.7.1.xs5.6.100.323.170596"
18 # -D "kernel_flavor xen"
19 # -D "build_number --with-build-number=123"
20 # -bb /usr/src/redhat/SPECS/openvswitch-xen.spec
22 %define xen_version %{kernel_version}%{kernel_flavor}
24 # bump this when breaking compatibility with userspace
25 %define module_abi_version 0
27 # extract kernel type (xen or kdump)
28 %define binsuffix -%(echo '%{xen_version}' | sed -r 's/^.*[0-9]+//')
29 # kernel version string w/o kernel type
30 %define kernel_version %(echo '%{xen_version}' | sed -r 's/[a-z]+$//')
31 # build-supplemental-pack.sh requires this naming for kernel module packages
32 %define module_package modules-%{kernel_flavor}-%{kernel_version}
35 Summary: Open vSwitch daemon/database/utilities
36 Group: System Environment/Daemons
37 URL: http://www.openvswitch.org/
38 Vendor: Nicira Networks, Inc.
39 Version: %{openvswitch_version}
43 Source: openvswitch-%{openvswitch_version}.tar.gz
44 Buildroot: /tmp/openvswitch-xen-rpm
45 Requires: openvswitch_mod.ko.%{module_abi_version}
48 Open vSwitch provides standard network bridging functions augmented with
49 support for the OpenFlow protocol for remote per-flow control of
52 %package %{module_package}
53 Summary: Open vSwitch kernel module
54 Group: System Environment/Kernel
56 Provides: %{name}-modules-%{kernel_flavor} = %{kernel_version}, openvswitch_mod.ko.%{module_abi_version}
57 Requires: kernel-%{kernel_name} = %{kernel_version}
59 %description %{module_package}
60 Open vSwitch Linux kernel module compiled against kernel version
64 %setup -q -n openvswitch-%{openvswitch_version}
67 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=%{_localstatedir} --with-l26=/lib/modules/%{xen_version}/build --enable-ssl %{build_number}
71 rm -rf $RPM_BUILD_ROOT
72 make install DESTDIR=$RPM_BUILD_ROOT
73 install -d -m 755 $RPM_BUILD_ROOT/etc
74 install -d -m 755 $RPM_BUILD_ROOT/etc/init.d
75 install -m 755 xenserver/etc_init.d_openvswitch \
76 $RPM_BUILD_ROOT/etc/init.d/openvswitch
77 install -m 755 xenserver/etc_init.d_openvswitch-xapi-update \
78 $RPM_BUILD_ROOT/etc/init.d/openvswitch-xapi-update
79 install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
80 install -d -m 755 $RPM_BUILD_ROOT/etc/logrotate.d
81 install -m 755 xenserver/etc_logrotate.d_openvswitch \
82 $RPM_BUILD_ROOT/etc/logrotate.d/openvswitch
83 install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
84 install -m 755 xenserver/etc_profile.d_openvswitch.sh \
85 $RPM_BUILD_ROOT/etc/profile.d/openvswitch.sh
86 install -d -m 755 $RPM_BUILD_ROOT/etc/xapi.d/plugins
87 install -m 755 xenserver/etc_xapi.d_plugins_openvswitch-cfg-update \
88 $RPM_BUILD_ROOT/etc/xapi.d/plugins/openvswitch-cfg-update
89 install -d -m 755 $RPM_BUILD_ROOT/etc/xensource/bugtool/network-status
90 install -m 644 xenserver/etc_xensource_bugtool_network-status_openvswitch.xml \
91 $RPM_BUILD_ROOT/etc/xensource/bugtool/network-status/openvswitch.xml
92 install -d -m 755 $RPM_BUILD_ROOT/etc/xensource/bugtool/kernel-info
93 install -m 644 xenserver/etc_xensource_bugtool_kernel-info_openvswitch.xml \
94 $RPM_BUILD_ROOT/etc/xensource/bugtool/kernel-info/openvswitch.xml
95 install -d -m 755 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts
96 install -m 644 vswitchd/vswitch.ovsschema \
97 $RPM_BUILD_ROOT/usr/share/openvswitch/vswitch.ovsschema
98 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
99 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/interface-reconfigure
100 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigure.py \
101 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigure.py
102 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureBridge.py \
103 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
104 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py \
105 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
106 install -m 755 xenserver/etc_xensource_scripts_vif \
107 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/vif
108 install -m 755 xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync \
109 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-xapi-sync
110 install -m 755 xenserver/usr_share_openvswitch_scripts_sysconfig.template \
111 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/sysconfig.template
112 install -m 755 xenserver/usr_share_openvswitch_scripts_xen-bugtool-tc-class-show \
113 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/xen-bugtool-tc-class-show
114 install -m 755 utilities/ovs-save \
115 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-save
116 install -d -m 755 $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base
118 xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
119 $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
121 install -d -m 755 $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/extra/openvswitch
122 find datapath/linux-2.6 -name *.ko -exec install -m 755 \{\} $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/extra/openvswitch \;
123 install xenserver/uuid.py $RPM_BUILD_ROOT/usr/share/openvswitch/python
125 # Get rid of stuff we don't want to make RPM happy.
127 $RPM_BUILD_ROOT/usr/bin/ovs-controller \
128 $RPM_BUILD_ROOT/usr/bin/ovs-openflowd \
129 $RPM_BUILD_ROOT/usr/bin/ovs-pki \
130 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-controller.8 \
131 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-openflowd.8 \
132 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-pki.8
134 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
137 rm -rf $RPM_BUILD_ROOT
140 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
141 cat >>/etc/sysctl.conf <<EOF
142 # This works around an issue in xhad, which binds to a particular
143 # Ethernet device, which in turn causes ICMP port unreachable messages
144 # if packets are received are on the wrong interface, which in turn
145 # can happen if we send out ARP replies on every interface (as Linux
146 # does by default) instead of just on the interface that has the IP
147 # address being ARPed for, which this sysctl setting in turn works
151 net.ipv4.conf.all.arp_filter = 1
155 if test ! -e /etc/openvswitch/conf.db; then
156 install -d -m 755 -o root -g root /etc/openvswitch
158 # Create ovs-vswitchd config database
159 ovsdb-tool -vANY:console:emer create /etc/openvswitch/conf.db \
160 /usr/share/openvswitch/vswitch.ovsschema
162 # Create initial table in config database
163 ovsdb-tool -vANY:console:emer transact /etc/openvswitch/conf.db \
164 '[{"op": "insert", "table": "Open_vSwitch", "row": {}}]' \
168 # Create default or update existing /etc/sysconfig/openvswitch.
169 SYSCONFIG=/etc/sysconfig/openvswitch
170 TEMPLATE=/usr/share/openvswitch/scripts/sysconfig.template
171 if [ ! -e $SYSCONFIG ]; then
172 cp $TEMPLATE $SYSCONFIG
174 for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
176 if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
178 sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
183 # Deliberately break %postun in broken OVS builds that revert original
184 # XenServer scripts during rpm -U by moving the directory where it thinks
186 if [ -d /usr/lib/openvswitch/xs-original ]; then
187 mkdir -p /usr/lib/openvswitch/xs-saved
188 mv /usr/lib/openvswitch/xs-original/* /usr/lib/openvswitch/xs-saved/ &&
189 rmdir /usr/lib/openvswitch/xs-original
192 # Replace XenServer files by our versions.
193 mkdir -p /usr/lib/openvswitch/xs-saved \
194 || printf "Could not create script backup directory.\n"
196 /opt/xensource/libexec/interface-reconfigure \
197 /opt/xensource/libexec/InterfaceReconfigure.py \
198 /opt/xensource/libexec/InterfaceReconfigureBridge.py \
199 /opt/xensource/libexec/InterfaceReconfigureVswitch.py \
200 /etc/xensource/scripts/vif
204 if [ -f "$f" ] && [ "$t" != "/usr/share/openvswitch/scripts/$s" ]; then
205 mv "$f" /usr/lib/openvswitch/xs-saved/ \
206 || printf "Could not save original XenServer $s script\n"
207 ln -s "/usr/share/openvswitch/scripts/$s" "$f" \
208 || printf "Could not link to Open vSwitch $s script\n"
212 # Clean up dangling symlinks to removed OVS replacement scripts no longer
213 # provided by OVS. Any time a replacement script is removed from OVS,
214 # it should be added here to ensure correct reversion from old versions of
215 # OVS that don't clean up dangling symlinks during the uninstall phase.
218 /usr/sbin/xen-bugtool
220 saved=/usr/lib/openvswitch/xs-saved/$(basename "$orig")
221 [ -e "$saved" ] && mv -f "$saved" "$orig"
224 # Ensure all required services are set to run
225 for s in openvswitch openvswitch-xapi-update; do
226 if chkconfig --list $s >/dev/null 2>&1; then
227 chkconfig --del $s || printf "Could not remove $s init script."
229 chkconfig --add $s || printf "Could not add $s init script."
230 chkconfig $s on || printf "Could not enable $s init script."
233 if [ "$1" = "1" ]; then # $1 = 2 for upgrade
234 # Configure system to use Open vSwitch
235 echo vswitch > /etc/xensource/network.conf
237 printf "\nYou MUST reboot the server NOW to complete the change to\n"
238 printf "Open vSwitch. Attempts to modify networking on the server\n"
239 printf "or any hosted VM will fail until after the reboot and could\n"
240 printf "leave the server in a state requiring manual recovery.\n\n"
243 mode=$(cat /etc/xensource/network.conf)
244 if [ "$mode" != "vswitch" ] && [ "$mode" != "openvswitch" ]; then
245 printf "\nThe server is not configured to run Open vSwitch. To run in\n"
246 printf "vswitch mode, you must run the following command:\n\n"
247 printf "\txe-switch-network-backend vswitch"
249 printf "\nTo use the new Open vSwitch install, you should reboot the\n"
250 printf "server now. Failure to do so may result in incorrect operation."
256 %post %{module_package}
257 # Ensure that modprobe will find our modules.
258 depmod %{xen_version}
261 if [ "$1" = "0" ]; then # $1 = 1 for upgrade
262 for s in openvswitch openvswitch-xapi-update; do
263 chkconfig --del $s || printf "Could not remove $s init script."
268 # Restore original XenServer scripts if the OVS equivalent no longer exists.
269 # This works both in the upgrade and erase cases.
270 # This lists every file that every version of OVS has ever replaced. Never
271 # remove old files that OVS no longer replaces, or upgrades from old versions
272 # will fail to restore the XS originals, leaving the system in a broken state.
273 # Also be sure to add removed script paths to the %post scriptlet above to
274 # prevent the same problem when upgrading from old versions of OVS that lack
275 # this restore-on-upgrade logic.
277 /etc/xensource/scripts/vif \
279 /usr/sbin/xen-bugtool \
280 /opt/xensource/libexec/interface-reconfigure \
281 /opt/xensource/libexec/InterfaceReconfigure.py \
282 /opt/xensource/libexec/InterfaceReconfigureBridge.py \
283 /opt/xensource/libexec/InterfaceReconfigureVswitch.py
285 # Only revert dangling symlinks.
286 if [ -h "$f" ] && [ ! -e "$f" ]; then
288 if [ ! -f "/usr/lib/openvswitch/xs-saved/$s" ]; then
289 printf "Original XenServer $s script not present in /usr/lib/openvswitch/xs-saved\n" >&2
290 printf "Could not restore original XenServer script.\n" >&2
293 && mv "/usr/lib/openvswitch/xs-saved/$s" "$f") \
294 || printf "Could not restore original XenServer $s script.\n" >&2
299 if [ "$1" = "0" ]; then # $1 = 1 for upgrade
300 rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
301 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo
303 rm -f /usr/share/openvswitch/scripts/InterfaceReconfigure.pyc \
304 /usr/share/openvswitch/scripts/InterfaceReconfigure.pyo \
305 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyc \
306 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyo \
307 /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyc \
308 /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyo
310 # Remove all configuration files
311 rm -f /etc/openvswitch/conf.db
312 rm -f /etc/sysconfig/openvswitch
313 rm -f /etc/openvswitch/vswitchd.cacert
314 rm -f /var/xapi/network.dbcache
316 # Remove saved XenServer scripts directory, but only if it's empty
317 rmdir -p /usr/lib/openvswitch/xs-saved 2>/dev/null
319 # Configure system to use bridge
320 echo bridge > /etc/xensource/network.conf
322 printf "\nYou MUST reboot the server now to complete the change to\n"
323 printf "standard Xen networking. Attempts to modify networking on the\n"
324 printf "server or any hosted VM will fail until after the reboot and\n"
325 printf "could leave the server in a state requiring manual recovery.\n\n"
329 %defattr(-,root,root)
330 /etc/init.d/openvswitch
331 /etc/init.d/openvswitch-xapi-update
332 /etc/xapi.d/plugins/openvswitch-cfg-update
333 /etc/xensource/bugtool/network-status/openvswitch.xml
334 /etc/xensource/bugtool/kernel-info/openvswitch.xml
335 /etc/logrotate.d/openvswitch
336 /etc/profile.d/openvswitch.sh
337 /usr/share/openvswitch/python/ovs/__init__.py
338 /usr/share/openvswitch/python/ovs/daemon.py
339 /usr/share/openvswitch/python/ovs/db/__init__.py
340 /usr/share/openvswitch/python/ovs/db/data.py
341 /usr/share/openvswitch/python/ovs/db/error.py
342 /usr/share/openvswitch/python/ovs/db/idl.py
343 /usr/share/openvswitch/python/ovs/db/parser.py
344 /usr/share/openvswitch/python/ovs/db/schema.py
345 /usr/share/openvswitch/python/ovs/db/types.py
346 /usr/share/openvswitch/python/ovs/dirs.py
347 /usr/share/openvswitch/python/ovs/fatal_signal.py
348 /usr/share/openvswitch/python/ovs/json.py
349 /usr/share/openvswitch/python/ovs/jsonrpc.py
350 /usr/share/openvswitch/python/ovs/ovsuuid.py
351 /usr/share/openvswitch/python/ovs/poller.py
352 /usr/share/openvswitch/python/ovs/process.py
353 /usr/share/openvswitch/python/ovs/reconnect.py
354 /usr/share/openvswitch/python/ovs/socket_util.py
355 /usr/share/openvswitch/python/ovs/stream.py
356 /usr/share/openvswitch/python/ovs/timeval.py
357 /usr/share/openvswitch/python/ovs/util.py
358 /usr/share/openvswitch/python/uuid.py
359 /usr/share/openvswitch/scripts/ovs-xapi-sync
360 /usr/share/openvswitch/scripts/interface-reconfigure
361 /usr/share/openvswitch/scripts/InterfaceReconfigure.py
362 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
363 /usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
364 /usr/share/openvswitch/scripts/vif
365 /usr/share/openvswitch/scripts/sysconfig.template
366 /usr/share/openvswitch/scripts/xen-bugtool-tc-class-show
367 /usr/share/openvswitch/scripts/ovs-save
368 /usr/share/openvswitch/vswitch.ovsschema
369 /usr/sbin/ovs-vlan-bug-workaround
370 /usr/sbin/ovs-vswitchd
371 /usr/sbin/ovsdb-server
376 /usr/bin/ovs-tcpundump
377 /usr/bin/ovs-vlan-test
379 /usr/bin/ovsdb-client
381 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
382 /usr/share/man/man1/ovsdb-client.1.gz
383 /usr/share/man/man1/ovsdb-server.1.gz
384 /usr/share/man/man1/ovsdb-tool.1.gz
385 /usr/share/man/man5/ovs-vswitchd.conf.db.5.gz
386 /usr/share/man/man8/ovs-appctl.8.gz
387 /usr/share/man/man8/ovs-dpctl.8.gz
388 /usr/share/man/man8/ovs-ofctl.8.gz
389 /usr/share/man/man8/ovs-parse-leaks.8.gz
390 /usr/share/man/man1/ovs-pcap.1.gz
391 /usr/share/man/man1/ovs-tcpundump.1.gz
392 /usr/share/man/man8/ovs-vlan-bug-workaround.8.gz
393 /usr/share/man/man8/ovs-vlan-test.8.gz
394 /usr/share/man/man8/ovs-vsctl.8.gz
395 /usr/share/man/man8/ovs-vswitchd.8.gz
397 %exclude /usr/lib/xsconsole/plugins-base/*.py[co]
398 %exclude /usr/sbin/ovs-brcompatd
399 %exclude /usr/share/man/man8/ovs-brcompatd.8.gz
400 %exclude /usr/share/openvswitch/scripts/*.py[co]
401 %exclude /usr/share/openvswitch/python/*.py[co]
402 %exclude /usr/share/openvswitch/python/ovs/*.py[co]
403 %exclude /usr/share/openvswitch/python/ovs/db/*.py[co]
405 %files %{module_package}
406 /lib/modules/%{xen_version}/kernel/extra/openvswitch/openvswitch_mod.ko
407 %exclude /lib/modules/%{xen_version}/kernel/extra/openvswitch/brcompat_mod.ko