learn: Fix bugs when learn actions use subfields wider than 64 bits.
[sliver-openvswitch.git] / xenserver / openvswitch-xen.spec.in
1 # Spec file for Open vSwitch.
2
3 # Copyright (C) 2009, 2010, 2011, 2012 Nicira Networks, Inc.
4 #
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.
9
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.
13 # for example:
14 #
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
21
22 %if %{?openvswitch_version:0}%{!?openvswitch_version:1}
23 %define openvswitch_version @VERSION@
24 %endif
25
26 %if %{?kernel_name:0}%{!?kernel_name:1}
27 %define kernel %(rpm -qa 'kernel*xen-devel' | head -1)
28 %define kernel_name %(rpm -q --queryformat "%%{Name}" %{kernel} | sed 's/-devel//' | sed 's/kernel-//')
29 %define kernel_version %(rpm -q --queryformat "%%{Version}-%%{Release}" %{kernel})
30 %define kernel_flavor xen
31 %endif
32
33 %define xen_version %{kernel_version}%{kernel_flavor}
34
35 # bump this when breaking compatibility with userspace
36 %define module_abi_version 0
37
38 # build-supplemental-pack.sh requires this naming for kernel module packages
39 %define module_package modules-%{kernel_flavor}-%{kernel_version}
40
41 Name: openvswitch
42 Summary: Open vSwitch daemon/database/utilities
43 Group: System Environment/Daemons
44 URL: http://www.openvswitch.org/
45 Vendor: Nicira Networks, Inc.
46 Version: %{openvswitch_version}
47
48 License: ASL 2.0
49 Release: 1
50 Source: openvswitch-%{openvswitch_version}.tar.gz
51 Buildroot: /tmp/openvswitch-xen-rpm
52 Requires: openvswitch_mod.ko.%{module_abi_version}
53
54 %description
55 Open vSwitch provides standard network bridging functions augmented with
56 support for the OpenFlow protocol for remote per-flow control of
57 traffic.
58
59 %package %{module_package}
60 Summary: Open vSwitch kernel module
61 Group: System Environment/Kernel
62 License: GPLv2
63 Provides: %{name}-modules-%{kernel_flavor} = %{kernel_version}, openvswitch_mod.ko.%{module_abi_version}
64 Requires: kernel-%{kernel_name} = %{kernel_version}
65
66 %description %{module_package}
67 Open vSwitch Linux kernel module compiled against kernel version
68 %{xen_version}.
69
70 %prep
71 %setup -q -n openvswitch-%{openvswitch_version}
72
73 %build
74 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=%{_localstatedir} --with-linux=/lib/modules/%{xen_version}/build --enable-ssl %{?build_number}
75 make %{_smp_mflags}
76
77 %install
78 rm -rf $RPM_BUILD_ROOT
79 make install DESTDIR=$RPM_BUILD_ROOT
80 install -d -m 755 $RPM_BUILD_ROOT/etc
81 install -d -m 755 $RPM_BUILD_ROOT/etc/init.d
82 install -m 755 xenserver/etc_init.d_openvswitch \
83          $RPM_BUILD_ROOT/etc/init.d/openvswitch
84 install -m 755 xenserver/etc_init.d_openvswitch-xapi-update \
85          $RPM_BUILD_ROOT/etc/init.d/openvswitch-xapi-update
86 install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
87 install -d -m 755 $RPM_BUILD_ROOT/etc/logrotate.d
88 install -m 755 xenserver/etc_logrotate.d_openvswitch \
89          $RPM_BUILD_ROOT/etc/logrotate.d/openvswitch
90 install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
91 install -m 755 xenserver/etc_profile.d_openvswitch.sh \
92          $RPM_BUILD_ROOT/etc/profile.d/openvswitch.sh
93 install -d -m 755 $RPM_BUILD_ROOT/etc/xapi.d/plugins
94 install -m 755 xenserver/etc_xapi.d_plugins_openvswitch-cfg-update \
95          $RPM_BUILD_ROOT/etc/xapi.d/plugins/openvswitch-cfg-update
96 install -d -m 755 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts
97 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
98              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/interface-reconfigure
99 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigure.py \
100              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigure.py
101 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureBridge.py \
102              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
103 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py \
104              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
105 install -m 755 xenserver/etc_xensource_scripts_vif \
106              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/vif
107 install -m 755 xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync \
108                $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-xapi-sync
109 install -m 755 xenserver/usr_share_openvswitch_scripts_sysconfig.template \
110          $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/sysconfig.template
111 install -d -m 755 $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base
112 install -m 644 \
113         xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
114                $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
115
116 install -d -m 755 $RPM_BUILD_ROOT/lib/modules/%{xen_version}/extra/openvswitch
117 find datapath/linux -name *.ko -exec install -m 755  \{\} $RPM_BUILD_ROOT/lib/modules/%{xen_version}/extra/openvswitch \;
118 install python/compat/uuid.py $RPM_BUILD_ROOT/usr/share/openvswitch/python
119 install python/compat/argparse.py $RPM_BUILD_ROOT/usr/share/openvswitch/python
120
121 install -d -m 755 $RPM_BUILD_ROOT/etc/xensource/bugtool
122 mv $RPM_BUILD_ROOT/usr/share/openvswitch/bugtool-plugins/* $RPM_BUILD_ROOT/etc/xensource/bugtool
123
124 # Get rid of stuff we don't want to make RPM happy.
125 rm \
126     $RPM_BUILD_ROOT/usr/bin/ovs-benchmark \
127     $RPM_BUILD_ROOT/usr/sbin/ovs-bugtool \
128     $RPM_BUILD_ROOT/usr/bin/ovs-controller \
129     $RPM_BUILD_ROOT/usr/bin/ovs-pki \
130     $RPM_BUILD_ROOT/usr/bin/ovs-test \
131     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-test.8 \
132     $RPM_BUILD_ROOT/usr/share/man/man1/ovs-benchmark.1 \
133     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-bugtool.8 \
134     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-controller.8 \
135     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-pki.8
136
137 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
138
139 %clean
140 rm -rf $RPM_BUILD_ROOT
141
142 %post
143 # A list of Citrix XenServer scripts that we might need to replace
144 # with our own versions.
145 scripts="
146     /etc/xensource/scripts/vif
147     /opt/xensource/libexec/InterfaceReconfigure.py
148     /opt/xensource/libexec/InterfaceReconfigureBridge.py
149     /opt/xensource/libexec/InterfaceReconfigureVswitch.py
150     /opt/xensource/libexec/interface-reconfigure"
151
152 # Calculate into $md5sums a comma-separated set of md5sums of the
153 # Citrix XenServer scripts that we might need to replace.  We might be
154 # upgrading an older version of the package that moved the files out
155 # of the way, so we need to look for the files in those out-of-the-way
156 # locations first.
157 md5sums=
158 for script in $scripts; do
159     b=$(basename "$script")
160     if test -e /usr/lib/openvswitch/xs-saved/"$b"; then
161         f=/usr/lib/openvswitch/xs-saved/"$b"
162     elif test -e /usr/lib/openvswitch/xs-original/"$b"; then
163         f=/usr/lib/openvswitch/xs-original/"$b"
164     elif test -e "$script" && test ! -h "$script"; then
165         f=$script
166     else
167         printf "\n$script: not found\n"
168         f=/dev/null
169     fi
170     md5sums="$md5sums,$(md5sum $f | awk '{print $1}')"
171 done
172 md5sums=${md5sums#,}
173
174 # Now check the md5sums against the known sets of md5sums:
175 #
176 #   - If they are known to be a version of XenServer scripts that we should
177 #     replace, we replace them (by putting $scripts into $replace_files).
178 #
179 #   - Otherwise, we guess that it's better not to replace them, because the
180 #     improvements that our versions of the scripts provide are minimal, so
181 #     it's better to avoid possibly breaking any changes made upstream by
182 #     Citrix.
183 case $md5sums in
184     cf09a68d9f8b434e79a4c83b01a3bb4b,395866df1b0b20c12c4dd2f7de0ecdb4,9d493545ae81463239d3162cbc798852,862d0939b441de9264a900628e950fe9,21f85db25599d7f026cd489385d58aa6)
185         keep_files=
186         replace_files=$scripts
187         printf "\nVerified host scripts from XenServer 6.0.0.\n"
188         ;;
189
190     c5f48246577a17cf1b971fb5ce4e920b,2e2c912f86f9c536c89adc34ff3c2b2b,28d3ff72d72bdec4f37d70699f5edb76,67e1d0af16fc1ddf10009c5c063ad2ba,f3feff30aa3b3f8b514664a96a8dc0ab)
191         keep_files=
192         replace_files=$scripts
193         printf "\nVerified host scripts from XenServer 5.6-SP2.\n"
194         ;;
195         
196     c5f48246577a17cf1b971fb5ce4e920b,2e2c912f86f9c536c89adc34ff3c2b2b,28d3ff72d72bdec4f37d70699f5edb76,67e1d0af16fc1ddf10009c5c063ad2ba,24bae6906d182ba47668174f8e480cc6)
197         keep_files=
198         replace_files=$scripts
199         printf "\nVerified host scripts from XenServer 5.6-FP1.\n"
200         ;;
201
202     *)
203         keep_files=$scripts
204         replace_files=
205         cat <<EOF
206
207 The host scripts on this machine are not those of any supported
208 version of XenServer.  On XenServer earlier than 5.6-FP1, your Open
209 vSwitch installation will not work.  On XenServer 5.6-FP1 or later,
210 Open vSwitch is not verified to work, which could lead to unexpected
211 behavior.
212
213 EOF
214         ;;
215 esac
216
217 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
218     cat >>/etc/sysctl.conf <<EOF
219 # This works around an issue in xhad, which binds to a particular
220 # Ethernet device, which in turn causes ICMP port unreachable messages
221 # if packets are received are on the wrong interface, which in turn
222 # can happen if we send out ARP replies on every interface (as Linux
223 # does by default) instead of just on the interface that has the IP
224 # address being ARPed for, which this sysctl setting in turn works
225 # around.
226 #
227 # Bug #1378.
228 net.ipv4.conf.all.arp_filter = 1
229 EOF
230 fi
231
232 if test ! -e /etc/openvswitch/conf.db; then
233     install -d -m 755 -o root -g root /etc/openvswitch
234
235     # Create ovs-vswitchd config database
236     ovsdb-tool -vANY:console:off create /etc/openvswitch/conf.db \
237             /usr/share/openvswitch/vswitch.ovsschema
238
239     # Create initial table in config database
240     ovsdb-tool -vANY:console:off transact /etc/openvswitch/conf.db \
241             '[{"op": "insert", "table": "Open_vSwitch", "row": {}}]' \
242             > /dev/null
243 fi
244
245 # Create default or update existing /etc/sysconfig/openvswitch.
246 SYSCONFIG=/etc/sysconfig/openvswitch
247 TEMPLATE=/usr/share/openvswitch/scripts/sysconfig.template
248 if [ ! -e $SYSCONFIG ]; then
249     cp $TEMPLATE $SYSCONFIG
250 else
251     for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
252     do
253         if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
254             echo >> $SYSCONFIG
255             sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
256         fi
257     done
258 fi
259
260 # Deliberately break %postun in broken OVS builds that revert original
261 # XenServer scripts during rpm -U by moving the directory where it thinks
262 # they are saved.
263 if [ -d /usr/lib/openvswitch/xs-original ]; then
264     mkdir -p /usr/lib/openvswitch/xs-saved
265     mv /usr/lib/openvswitch/xs-original/* /usr/lib/openvswitch/xs-saved/ &&
266         rmdir /usr/lib/openvswitch/xs-original
267 fi
268
269 # Replace XenServer files by our versions.
270 mkdir -p /usr/lib/openvswitch/xs-saved \
271     || printf "Could not create script backup directory.\n"
272 for f in $replace_files; do
273     s=$(basename "$f")
274     t=$(readlink "$f")
275     if [ -f "$f" ] && [ "$t" != "/usr/share/openvswitch/scripts/$s" ]; then
276         mv "$f" /usr/lib/openvswitch/xs-saved/ \
277             || printf "Could not save original XenServer $s script\n"
278         ln -s "/usr/share/openvswitch/scripts/$s" "$f" \
279             || printf "Could not link to Open vSwitch $s script\n"
280     fi
281 done
282
283 # Clean up dangling symlinks to removed OVS replacement scripts no longer
284 # provided by OVS. Any time a replacement script is removed from OVS,
285 # it should be added here to ensure correct reversion from old versions of
286 # OVS that don't clean up dangling symlinks during the uninstall phase.
287 for orig in /usr/sbin/brctl /usr/sbin/xen-bugtool $keep_files; do
288     saved=/usr/lib/openvswitch/xs-saved/$(basename "$orig")
289     [ -e "$saved" ] && mv -f "$saved" "$orig"
290 done
291
292 # Ensure all required services are set to run
293 for s in openvswitch openvswitch-xapi-update; do
294     if chkconfig --list $s >/dev/null 2>&1; then
295         chkconfig --del $s || printf "Could not remove $s init script."
296     fi
297     chkconfig --add $s || printf "Could not add $s init script."
298     chkconfig $s on || printf "Could not enable $s init script."
299 done
300
301 if [ "$1" = "1" ]; then    # $1 = 1 for install
302     # Configure system to use Open vSwitch
303     /opt/xensource/bin/xe-switch-network-backend vswitch
304 else    # $1 = 2 for upgrade
305
306     mode=$(cat /etc/xensource/network.conf)
307     if [ "$mode" != "vswitch" ] && [ "$mode" != "openvswitch" ]; then
308         printf "\nThe server is not configured to run Open vSwitch.  To run in\n"
309         printf "vswitch mode, you must run the following command:\n\n"
310         printf "\txe-switch-network-backend vswitch"
311     else
312         printf "\nTo use the new Open vSwitch install, you should reboot the\n"
313         printf "server now.  Failure to do so may result in incorrect operation."
314     fi
315
316     printf "\n\n"
317 fi
318
319 %posttrans %{module_package}
320 # Ensure that modprobe will find our modules.
321 #
322 # This has to be in %posttrans instead of %post because older versions
323 # installed modules into a different directory and "rpm -U" runs the
324 # new version's %post before removing the old version's files, so if
325 # we use %post then depmod may find the old versions that are about to
326 # be removed.
327 depmod %{xen_version}
328
329 %preun
330 if [ "$1" = "0" ]; then     # $1 = 0 for uninstall
331     # Configure system to use bridge
332     /opt/xensource/bin/xe-switch-network-backend bridge
333
334     # The "openvswitch" service should have been removed from
335     # "xe-switch-network-backend bridge".
336     for s in openvswitch openvswitch-xapi-update; do
337         if chkconfig --list $s >/dev/null 2>&1; then
338             chkconfig --del $s || printf "Could not remove $s init script."
339         fi
340     done
341 fi
342
343 %postun
344 # Restore original XenServer scripts if the OVS equivalent no longer exists.
345 # This works both in the upgrade and erase cases.
346 # This lists every file that every version of OVS has ever replaced. Never
347 # remove old files that OVS no longer replaces, or upgrades from old versions
348 # will fail to restore the XS originals, leaving the system in a broken state.
349 # Also be sure to add removed script paths to the %post scriptlet above to
350 # prevent the same problem when upgrading from old versions of OVS that lack
351 # this restore-on-upgrade logic.
352 for f in \
353     /etc/xensource/scripts/vif \
354     /usr/sbin/brctl \
355     /usr/sbin/xen-bugtool \
356     /opt/xensource/libexec/interface-reconfigure \
357     /opt/xensource/libexec/InterfaceReconfigure.py \
358     /opt/xensource/libexec/InterfaceReconfigureBridge.py \
359     /opt/xensource/libexec/InterfaceReconfigureVswitch.py
360 do
361     # Only revert dangling symlinks.
362     if [ -h "$f" ] && [ ! -e "$f" ]; then
363         s=$(basename "$f")
364         if [ ! -f "/usr/lib/openvswitch/xs-saved/$s" ]; then
365             printf "Original XenServer $s script not present in /usr/lib/openvswitch/xs-saved\n" >&2
366             printf "Could not restore original XenServer script.\n" >&2
367         else
368             (rm -f "$f" \
369                 && mv "/usr/lib/openvswitch/xs-saved/$s" "$f") \
370                 || printf "Could not restore original XenServer $s script.\n" >&2
371         fi
372     fi
373 done
374
375 if [ "$1" = "0" ]; then     # $1 = 0 for uninstall
376     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
377         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo
378
379     rm -f /usr/share/openvswitch/scripts/InterfaceReconfigure.pyc \
380         /usr/share/openvswitch/scripts/InterfaceReconfigure.pyo \
381         /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyc \
382         /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyo \
383         /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyc \
384         /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyo
385
386     # Remove all configuration files
387     rm -f /etc/openvswitch/conf.db
388     rm -f /etc/sysconfig/openvswitch
389     rm -f /etc/openvswitch/vswitchd.cacert
390
391     # Remove saved XenServer scripts directory, but only if it's empty
392     rmdir -p /usr/lib/openvswitch/xs-saved 2>/dev/null
393 fi
394
395 exit 0
396
397 %files
398 %defattr(-,root,root)
399 /etc/init.d/openvswitch
400 /etc/init.d/openvswitch-xapi-update
401 /etc/xapi.d/plugins/openvswitch-cfg-update
402 /etc/xensource/bugtool/*
403 /etc/logrotate.d/openvswitch
404 /etc/profile.d/openvswitch.sh
405 /usr/share/openvswitch/python/
406 /usr/share/openvswitch/scripts/ovs-xapi-sync
407 /usr/share/openvswitch/scripts/interface-reconfigure
408 /usr/share/openvswitch/scripts/InterfaceReconfigure.py
409 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
410 /usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
411 /usr/share/openvswitch/scripts/vif
412 /usr/share/openvswitch/scripts/sysconfig.template
413 /usr/share/openvswitch/scripts/ovs-bugtool-*
414 /usr/share/openvswitch/scripts/ovs-save
415 /usr/share/openvswitch/scripts/ovs-ctl
416 /usr/share/openvswitch/scripts/ovs-lib
417 /usr/share/openvswitch/vswitch.ovsschema
418 /usr/sbin/ovs-vlan-bug-workaround
419 /usr/sbin/ovs-vswitchd
420 /usr/sbin/ovsdb-server
421 /usr/bin/ovs-appctl
422 /usr/bin/ovs-dpctl
423 /usr/bin/ovs-ofctl
424 /usr/bin/ovs-parse-leaks
425 /usr/bin/ovs-pcap
426 /usr/bin/ovs-tcpundump
427 /usr/bin/ovs-vlan-test
428 /usr/bin/ovs-vsctl
429 /usr/bin/ovsdb-client
430 /usr/bin/ovsdb-tool
431 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
432 /usr/share/man/man1/ovsdb-client.1.gz
433 /usr/share/man/man1/ovsdb-server.1.gz
434 /usr/share/man/man1/ovsdb-tool.1.gz
435 /usr/share/man/man5/ovs-vswitchd.conf.db.5.gz
436 /usr/share/man/man8/ovs-appctl.8.gz
437 /usr/share/man/man8/ovs-ctl.8.gz
438 /usr/share/man/man8/ovs-dpctl.8.gz
439 /usr/share/man/man8/ovs-ofctl.8.gz
440 /usr/share/man/man8/ovs-parse-leaks.8.gz
441 /usr/share/man/man1/ovs-pcap.1.gz
442 /usr/share/man/man1/ovs-tcpundump.1.gz
443 /usr/share/man/man8/ovs-vlan-bug-workaround.8.gz
444 /usr/share/man/man8/ovs-vlan-test.8.gz
445 /usr/share/man/man8/ovs-vsctl.8.gz
446 /usr/share/man/man8/ovs-vswitchd.8.gz
447 /var/lib/openvswitch
448 %exclude /usr/lib/xsconsole/plugins-base/*.py[co]
449 %exclude /usr/sbin/ovs-brcompatd
450 %exclude /usr/share/man/man8/ovs-brcompatd.8.gz
451 %exclude /usr/share/openvswitch/scripts/*.py[co]
452 %exclude /usr/share/openvswitch/python/*.py[co]
453 %exclude /usr/share/openvswitch/python/ovs/*.py[co]
454 %exclude /usr/share/openvswitch/python/ovs/db/*.py[co]
455
456 %files %{module_package}
457 /lib/modules/%{xen_version}/extra/openvswitch/openvswitch_mod.ko
458 %exclude /lib/modules/%{xen_version}/extra/openvswitch/brcompat_mod.ko