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