render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
a54075
From 935cd0c56643d28a5c60ff6658b16bd4c2fd920c Mon Sep 17 00:00:00 2001
a54075
From: Laine Stump <laine@laine.org>
a54075
Date: Wed, 10 Sep 2014 13:10:45 -0400
a54075
Subject: [PATCH] network: try to eliminate default network conflict during
a54075
 package install
a54075
a54075
Sometimes libvirt is installed on a host that is already using the
a54075
network 192.168.122.0/24. If the libvirt-daemon-config-network package
a54075
is installed, this creates a conflict, since that package has been
a54075
hard-coded to create a virtual network that also uses
a54075
192.168.122.0/24. In the past libvirt has attempted to warn of /
a54075
remediate this situation by checking for conflicting routes when the
a54075
network is started, but it turns out that isn't always useful (for
a54075
example in the case that the *other* interface/network creating the
a54075
conflict hasn't yet been started at the time libvirtd start its own
a54075
networks).
a54075
a54075
This patch attempts to catch the problem earlier - at install
a54075
time. During the %post install script for
a54075
libvirt-daemon-config-network, we use a case statement to look through
a54075
the output of "ip route show" for a route that exactly matches
a54075
192.168.122.0/24, and if found we search for a similar route that
a54075
*doesn't* match (e.g. 192.168.124.0/24) (note that the search starts
a54075
with "124" instead of 123 because of reports of people already
a54075
modifying their L1 host's network to 192.168.123.0/24 in an attempt to
a54075
solve exactly the problem we are also trying to solve).  When we find
a54075
an available route, we just replace all occurrences of "122" in the
a54075
default.xml that is being created with the newly found 192.168
a54075
subnet. This could obviously be made more complicated - examine the
a54075
template defaul.xml to automatically determine the existing network
a54075
address and mask rather than hard coding it in the specfile, etc, but
a54075
this scripting is simpler and gets the job done as long as we continue
a54075
to use 192.168.122.0/24 in the template. (If anyone with mad bash
a54075
skillz wants to suggest something to do that, by all means please do).
a54075
a54075
This is intended to at least "further reduce" occurrence of the
a54075
problems detailed in:
a54075
a54075
  https://bugzilla.redhat.com/show_bug.cgi?id=811967
a54075
a54075
(cherry picked from commit 5f71959667e4902d738a849e7c9391e794fccf22)
a54075
---
a54075
 libvirt.spec.in | 31 ++++++++++++++++++++++++++++++-
a54075
 1 file changed, 30 insertions(+), 1 deletion(-)
a54075
a54075
diff --git a/libvirt.spec.in b/libvirt.spec.in
a54075
index 4dc801b..75a91f5 100644
a54075
--- a/libvirt.spec.in
a54075
+++ b/libvirt.spec.in
a54075
@@ -1732,8 +1732,37 @@ fi
a54075
     %if %{with_network}
a54075
 %post daemon-config-network
a54075
 if test $1 -eq 1 && test ! -f %{_sysconfdir}/libvirt/qemu/networks/default.xml ; then
a54075
+    # see if the network used by default network creates a conflict,
a54075
+    # and try to resolve it
a54075
+    # NB: 192.168.122.0/24 is used in the default.xml template file;
a54075
+    # do not modify any of those values here without also modifying
a54075
+    # them in the template.
a54075
+    orig_sub=122
a54075
+    sub=${orig_sub}
a54075
+    nl='
a54075
+'
a54075
+    routes="${nl}$(ip route show | cut -d' ' -f1)"
a54075
+    case ${routes} in
a54075
+      *"${nl}192.168.${orig_sub}.0/24${nl}"*)
a54075
+        # there was a match, so we need to look for an unused subnet
a54075
+        for new_sub in $(seq 124 254); do
a54075
+          case ${routes} in
a54075
+          *"${nl}192.168.${new_sub}.0/24${nl}"*)
a54075
+            ;;
a54075
+          *)
a54075
+            sub=$new_sub
a54075
+            break;
a54075
+            ;;
a54075
+          esac
a54075
+        done
a54075
+        ;;
a54075
+      *)
a54075
+        ;;
a54075
+    esac
a54075
+
a54075
     UUID=`/usr/bin/uuidgen`
a54075
-    sed -e "s,</name>,</name>\n  <uuid>$UUID</uuid>," \
a54075
+    sed -e "s/${orig_sub}/${sub}/g" \
a54075
+        -e "s,</name>,</name>\n  <uuid>$UUID</uuid>," \
a54075
          < %{_datadir}/libvirt/networks/default.xml \
a54075
          > %{_sysconfdir}/libvirt/qemu/networks/default.xml
a54075
     ln -s ../default.xml %{_sysconfdir}/libvirt/qemu/networks/autostart/default.xml