network: fix endless loop when starting network with multiple IPs and no dhcp
network: fix endless loop when starting network with multiple IPs and no dhcp

commit 9065cfaa added the ability to disable DNS services for a
libvirt virtual network. If neither DNS nor DHCP is needed for a
network, then we don't need to start dnsmasq, so code was added to
check for this.

Unfortunately, it was written with a great lack of attention to detail
(I can say that, because I was the author), and the loop that checked
if DHCP is needed for the network would never end if the network had
multiple IP addresses and the first <ip> had no <dhcp> subelement
(which would have contained a <range> or <host> subelement, thus
requiring DHCP services).

This patch rewrites the check to be more compact and (more
importantly) finite.

This bug was present in release 2.2.0 and 2.3.0, so will need to be
backported to any relevant maintainence branches.

Reported here:
  https://www.redhat.com/archives/libvirt-users/2016-October/msg00032.html
  https://www.redhat.com/archives/libvirt-users/2016-October/msg00045.html

eskultety/libvirt,jfehlig/libvirt,jfehlig/libvirt,zippy2/libvirt,VenkatDatta/libvirt,eskultety/libvirt,fabianfreyer/libvirt,taget/libvirt,andreabolognani/libvirt,jardasgit/libvirt,andreabolognani/libvirt,zippy2/libvirt,fabianfreyer/libvirt,andreabolognani/libvirt,libvirt/libvirt,datto/libvirt,jfehlig/libvirt,fabianfreyer/libvirt,datto/libvirt,nertpinx/libvirt,andreabolognani/libvirt,nertpinx/libvirt,jardasgit/libvirt,zippy2/libvirt,eskultety/libvirt,libvirt/libvirt,VenkatDatta/libvirt,jardasgit/libvirt,libvirt/libvirt,taget/libvirt,eskultety/libvirt,datto/libvirt,VenkatDatta/libvirt,olafhering/libvirt,datto/libvirt,taget/libvirt,olafhering/libvirt,datto/libvirt,olafhering/libvirt,crobinso/libvirt,VenkatDatta/libvirt,VenkatDatta/libvirt,libvirt/libvirt,andreabolognani/libvirt,jardasgit/libvirt,zippy2/libvirt,crobinso/libvirt,eskultety/libvirt,crobinso/libvirt,nertpinx/libvirt,olafhering/libvirt,nertpinx/libvirt,jfehlig/libvirt,taget/libvirt,fabianfreyer/libvirt,nertpinx/libvirt,crobinso/libvirt,taget/libvirt,fabianfreyer/libvirt,jardasgit/libvirt