bridge: Eject NORMAL flows without a learning entry from datapath.
[sliver-openvswitch.git] / xenserver / vswitch-xen.spec
1 # Spec file for vswitch and related programs.
2
3 # Copyright (C) 2009 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 # vswitch_version, xen_version, and build_number using -D arguments.
12 # for example:
13 #
14 #    rpmbuild -D "vswitch_version 0.8.9~1+build123" -D "xen_version 2.6.18-128.1.1.el5.xs5.1.0.483.1000xen" -D "build_number --with-build-number=123" -bb /usr/src/redhat/SPECS/vswitch-xen.spec
15 #
16 %define version %{vswitch_version}-%{xen_version}
17 %define _prefix /root/vswitch
18
19 Name: vswitch
20 Summary: Virtual switch
21 Group: System Environment/Daemons
22 URL: http://www.openvswitch.org/
23 Version: %{vswitch_version}
24
25 # The entire source code is ASL 2.0 except datapath/ which is GPLv2
26 License: ASL 2.0 and GPLv2
27 Release: 1
28 Source: openvswitch-%{vswitch_version}.tar.gz
29 Buildroot: /tmp/vswitch-xen-rpm
30 Requires: kernel-xen = %(echo '%{xen_version}' | sed 's/xen$//')
31
32 %description
33 The vswitch provides standard network bridging functions augmented with
34 support for the OpenFlow protocol for remote per-flow control of
35 traffic.
36
37 %prep
38 %setup -q -n openvswitch-%{vswitch_version}
39
40 %build
41 ./configure --prefix=%{_prefix} --localstatedir=%{_localstatedir} --with-l26=/lib/modules/%{xen_version}/build --enable-ssl %{build_number}
42 make %{_smp_mflags}
43
44 %install
45 rm -rf $RPM_BUILD_ROOT
46 make install DESTDIR=$RPM_BUILD_ROOT prefix=%{_prefix}
47 install -d -m 755 $RPM_BUILD_ROOT/etc
48 install -d -m 755 $RPM_BUILD_ROOT/etc/init.d
49 install -m 755 xenserver/etc_init.d_vswitch \
50          $RPM_BUILD_ROOT/etc/init.d/vswitch
51 install -m 755 xenserver/etc_init.d_vswitch-xapi-update \
52          $RPM_BUILD_ROOT/etc/init.d/vswitch-xapi-update
53 install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
54 install -d -m 755 $RPM_BUILD_ROOT/etc/logrotate.d
55 install -m 755 xenserver/etc_logrotate.d_vswitch \
56          $RPM_BUILD_ROOT/etc/logrotate.d/vswitch
57 install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
58 install -m 755 xenserver/etc_profile.d_vswitch.sh \
59          $RPM_BUILD_ROOT/etc/profile.d/vswitch.sh
60 install -d -m 755 $RPM_BUILD_ROOT/etc/xapi.d/plugins
61 install -m 755 xenserver/etc_xapi.d_plugins_vswitch-cfg-update \
62          $RPM_BUILD_ROOT/etc/xapi.d/plugins/vswitch-cfg-update
63 install -d -m 755 $RPM_BUILD_ROOT%{_prefix}/scripts
64 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
65              $RPM_BUILD_ROOT%{_prefix}/scripts/interface-reconfigure
66 install -m 755 xenserver/etc_xensource_scripts_vif \
67              $RPM_BUILD_ROOT%{_prefix}/scripts/vif
68 install -m 755 xenserver/root_vswitch_scripts_dump-vif-details \
69                $RPM_BUILD_ROOT%{_prefix}/scripts/dump-vif-details
70 install -m 755 xenserver/root_vswitch_scripts_refresh-xs-network-uuids \
71                $RPM_BUILD_ROOT%{_prefix}/scripts/refresh-xs-network-uuids
72 install -m 755 xenserver/usr_sbin_xen-bugtool \
73              $RPM_BUILD_ROOT%{_prefix}/scripts/xen-bugtool
74 install -m 755 xenserver/usr_sbin_brctl \
75              $RPM_BUILD_ROOT%{_prefix}/scripts/brctl
76 install -m 755 xenserver/root_vswitch_scripts_sysconfig.template \
77          $RPM_BUILD_ROOT/root/vswitch/scripts/sysconfig.template
78 install -m 644 \
79         xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
80                $RPM_BUILD_ROOT%{_prefix}/scripts/XSFeatureVSwitch.py
81
82 install -d -m 755 $RPM_BUILD_ROOT%{_prefix}/kernel_modules
83 find datapath/linux-2.6 -name *.ko -exec install -m 755  \{\} $RPM_BUILD_ROOT%{_prefix}/kernel_modules/ \;
84
85 # Get rid of stuff we don't want to make RPM happy.
86 rm -rf \
87     $RPM_BUILD_ROOT/root/vswitch/bin/ezio-term \
88     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-controller \
89     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-discover \
90     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-kill \
91     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-pki \
92     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-switchui \
93     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-wdt \
94     $RPM_BUILD_ROOT/root/vswitch/bin/secchan \
95     $RPM_BUILD_ROOT/root/vswitch/sbin/ovs-monitor \
96     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-controller.8 \
97     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-discover.8 \
98     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-kill.8 \
99     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-pki.8 \
100     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/secchan.8 \
101     $RPM_BUILD_ROOT/root/vswitch/share/openvswitch
102
103 %clean
104 rm -rf $RPM_BUILD_ROOT
105
106 %post
107 if [ ! -f /etc/xensource-inventory ]; then
108     printf "XenSource inventory not present in /etc/xensource-inventory"
109     exit 1
110 fi
111
112 if [ "$1" = "1" ]; then
113     if ! md5sum -c --status <<EOF
114 b8e9835862ef1a9cec2a3f477d26c989  /etc/xensource/scripts/vif
115 51970ad613a3996d5997e18e44db47da  /opt/xensource/libexec/interface-reconfigure
116 5654c8c36699fcc8744ca9cd5b855414  /usr/sbin/xen-bugtool
117 EOF
118     then
119         printf "\nThe original XenServer scripts replaced by this package\n"
120         printf "are different than expected.  This could lead to unexpected\n"
121         printf "behavior of your server.  Unless you are sure you know what\n"
122         printf "you are doing, it is highly recommended that you remove this\n"
123         printf "package immediately after the install completes, which\n"
124         printf "will restore the XenServer scripts that you were previously\n"
125         printf "using.\n\n"
126     fi
127     if test "`/usr/sbin/brctl --version`" != "bridge-utils, 1.1"; then
128 cat <<EOF
129
130 /usr/sbin/brctl replaced by this package reports the following version:
131
132 `/usr/sbin/brctl --version`
133
134 The expected version was:
135
136 bridge-utils, 1.1
137
138 Unless you are sure you know what you are doing, it is highly recommended that
139 you remove this package immediately after the install completes, which will
140 restore the original /usr/sbin/brctl.
141
142 EOF
143     fi
144 fi
145
146 if test ! -e /var/lib/openvswitch/dbcache; then
147     if test "$1" = 1; then
148         printf "Creating xapi database cache...  "
149     else
150         printf "warning: Open vSwitch is being re-installed or upgraded,\n"
151         printf "         but the xapi database cache is missing.\n"
152         printf "Re-creating xapi database cache...  "
153     fi
154
155     mkdir -p /var/lib/openvswitch
156     if /root/vswitch/scripts/interface-reconfigure rewrite; then
157         printf "done.\n"
158     else
159         printf "FAILED\n"
160         printf "Open vSwitch can only be installed on a XenServer that\n"
161         printf "has connectivity to xapi on the pool master.  Please\n"
162         printf "fix connectivity to the pool master, then try again.\n"
163         exit 1
164     fi
165 fi
166
167 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
168     cat >>/etc/sysctl.conf <<EOF
169 # This works around an issue in xhad, which binds to a particular
170 # Ethernet device, which in turn causes ICMP port unreachable messages
171 # if packets are received are on the wrong interface, which in turn
172 # can happen if we send out ARP replies on every interface (as Linux
173 # does by default) instead of just on the interface that has the IP
174 # address being ARPed for, which this sysctl setting in turn works
175 # around.
176 #
177 # Bug #1378.
178 net.ipv4.conf.all.arp_filter = 1
179 EOF
180 fi
181
182 # Ensure ovs-vswitchd.conf exists
183 touch /etc/ovs-vswitchd.conf
184
185 # Create default or update existing /etc/sysconfig/vswitch.
186 SYSCONFIG=/etc/sysconfig/vswitch
187 TEMPLATE=/root/vswitch/scripts/sysconfig.template
188 if [ ! -e $SYSCONFIG ]; then
189     cp $TEMPLATE $SYSCONFIG
190 else
191     for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
192     do
193         if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
194             echo >> $SYSCONFIG
195             sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
196         fi
197     done
198 fi
199
200 # Replace XenServer files by our versions.
201 mkdir -p %{_prefix}/xs-original \
202     || printf "Could not create script backup directory.\n"
203 for f in \
204     /opt/xensource/libexec/interface-reconfigure \
205     /etc/xensource/scripts/vif \
206     /usr/sbin/xen-bugtool \
207     /usr/sbin/brctl
208 do
209     s=$(basename "$f")
210     t=$(readlink "$f")
211     if [ "$t" != "%{_prefix}/scripts/$s" ]; then
212         mv "$f" %{_prefix}/xs-original/ \
213             || printf "Could not save original XenServer $s script\n"
214         ln -s "%{_prefix}/scripts/$s" "$f" \
215             || printf "Could not link to vSwitch $s script\n"
216     fi
217 done
218
219 # Install xsconsole plugin
220 plugin=$(readlink /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py)
221 if [ "$plugin" != "/root/vswitch/scripts/XSFeatureVSwitch.py" ]; then
222     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
223     ln -s /root/vswitch/scripts/XSFeatureVSwitch.py /usr/lib/xsconsole/plugins-base/ || printf "Could not link to vSswitch xsconsole plugin.\n"
224 fi
225
226 # Ensure all required services are set to run
227 for s in vswitch vswitch-xapi-update; do
228     if chkconfig --list $s >/dev/null 2>&1; then
229         chkconfig --del $s || printf "Could not remove $s init script."
230     fi
231     chkconfig --add $s || printf "Could not add $s init script."
232     chkconfig $s on || printf "Could not enable $s init script."
233 done
234
235 if [ "$1" = "1" ]; then    # $1 = 2 for upgrade
236     printf "\nYou MUST reboot the server NOW to complete the change to the\n"
237     printf "the vSwitch.  Attempts to modify networking on the server\n"
238     printf "or any hosted VM will fail until after the reboot and could\n"
239     printf "leave the server in an state requiring manual recovery.\n\n"
240 else
241     printf "\nTo use the new vSwitch, you should reboot the server\n"
242     printf "now.  Failure to do so may result in incorrect operation.\n\n"
243 fi
244
245 %preun
246 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
247     for s in vswitch vswitch-xapi-update; do
248         chkconfig --del $s || printf "Could not remove $s init script."
249     done
250 fi
251
252
253 %postun
254 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
255
256     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py \
257         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
258         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo \
259         || printf "Could not remove vSwitch xsconsole plugin.\n"
260
261     # Restore original XenServer scripts
262     for f in \
263         /opt/xensource/libexec/interface-reconfigure \
264         /etc/xensource/scripts/vif \
265         /usr/sbin/xen-bugtool \
266         /usr/sbin/brctl
267     do
268         s=$(basename "$f")
269         if [ ! -f "%{_prefix}/xs-original/$s" ]; then
270             printf "Original XenServer $s script not present in %{_prefix}/xs-original\n"
271             printf "Could not restore original XenServer script.\n"
272         else
273             (rm -f "$f" \
274                 && mv "%{_prefix}/xs-original/$s" "$f") \
275                 || printf "Could not restore original XenServer $s script.\n"
276         fi
277     done
278
279     find  %{_prefix} -type d -depth -exec rmdir \{\} \; \
280         || printf "Could not remove vSwitch install directory.\n"
281
282     # Remove all configuration and log files
283     rm -f /etc/ovs-vswitchd.conf
284     rm -f /etc/sysconfig/vswitch
285     rm -f /var/log/vswitch*
286     rm -f /etc/ovs-vswitchd.cacert
287     rm -f /var/lib/openvswitch/dbcache
288
289     printf "\nYou MUST reboot the server now to complete the change to\n"
290     printf "standard Xen networking.  Attempts to modify networking on the\n"
291     printf "server or any hosted VM will fail until after the reboot and\n"
292     printf "could leave the server in a state requiring manual recovery.\n\n"
293 fi
294
295
296 %files
297 %defattr(-,root,root)
298 /etc/init.d/vswitch
299 /etc/init.d/vswitch-xapi-update
300 /etc/xapi.d/plugins/vswitch-cfg-update
301 /etc/logrotate.d/vswitch
302 /etc/profile.d/vswitch.sh
303 /root/vswitch/kernel_modules/brcompat_mod.ko
304 /root/vswitch/kernel_modules/openvswitch_mod.ko
305 /root/vswitch/kernel_modules/veth_mod.ko
306 /root/vswitch/scripts/dump-vif-details
307 /root/vswitch/scripts/refresh-xs-network-uuids
308 /root/vswitch/scripts/interface-reconfigure
309 /root/vswitch/scripts/vif
310 /root/vswitch/scripts/xen-bugtool
311 /root/vswitch/scripts/XSFeatureVSwitch.py
312 /root/vswitch/scripts/brctl
313 /root/vswitch/scripts/sysconfig.template
314 # Following two files are generated automatically by rpm.  We don't
315 # really need them and they won't be used on the XenServer, but there
316 # isn't an obvious place to get rid of them since they are generated
317 # after the install script runs.  Since they are small, we just
318 # include them.
319 /root/vswitch/scripts/XSFeatureVSwitch.pyc
320 /root/vswitch/scripts/XSFeatureVSwitch.pyo
321 /root/vswitch/sbin/ovs-brcompatd
322 /root/vswitch/sbin/ovs-vswitchd
323 /root/vswitch/bin/ovs-appctl
324 /root/vswitch/bin/ovs-cfg-mod
325 /root/vswitch/bin/ovs-dpctl
326 /root/vswitch/bin/ovs-ofctl
327 /root/vswitch/share/man/man5/ovs-vswitchd.conf.5
328 /root/vswitch/share/man/man8/ovs-appctl.8
329 /root/vswitch/share/man/man8/ovs-brcompatd.8
330 /root/vswitch/share/man/man8/ovs-cfg-mod.8
331 /root/vswitch/share/man/man8/ovs-dpctl.8
332 /root/vswitch/share/man/man8/ovs-ofctl.8
333 /root/vswitch/share/man/man8/ovs-vswitchd.8