Does the libvirt has any capabilities to get the statistics of DHCP server ? How many packets received/sent ?
Is there a way to get those statistics if the APIs are not available ?

Thanks & Regards
Santhosh Kumar Gunturu


On Thu, Apr 30, 2020 at 1:45 PM Laine Stump <laine@redhat.com> wrote:
On 4/28/20 12:01 PM, Daniel P. Berrangé wrote:
> On Tue, Apr 28, 2020 at 08:51:45AM -0700, Santhosh Kumar Gunturu wrote:
>> Okay. Thanks.
>>
>> Do we have any facility APIs to set the DHCP Options via XML ?
>> Default gateway ?

libvirt has no supported method of specifying a default gateway other
than the IP of the bridge device on the virtualization host it self, and
DHCP clients on these networks will always end up getting their default
gateway set to the IP address of that bridge. Fortunately (for you :-)
that's not because libvirt is explicitly setting that address in the
dnsmasq config file, but just because that's what dnsmasq does when no
gateway address is specified in the config file.

You would set this in the dnsmasq.conf file with dhcp-option, e.g.:

   dhcp-option=option-router,192.168.122.5

and recent libvirt (5.6.0 and newer) allows adding arbitrary lines to
the dnsmasq.conf files it creates for its networks, using the
<dnsmasq:options> element in the network XML. For details on how to do
this, look at:

   https://libvirt.org/formatnetwork.html#elementsNamespaces



>> Dns-server ?

Not exact, but

<forwarder addr='8.8.8.8'/>

is *kind of* what you're looking for. It doesn't set the IP address sent
back in the dhcp reply, but sets up the dnsmasq instance listening for
the network to forward all requests on to 8.8.8.8 (you can also refine
this to forward the requests for only certain domains, by adding
"domain='example.com'" to the <forwarder> element).

(If you *really* need to have the guest send DNS requests directly to
the upstream DNS server rather than via dnsmasq, then you would need to
use <dnsmasq:options> to set something like
"dhcp-option=option-dns-server,8/8/8/8")

>> domain-name ?

domain can be set with "<domain name='example.com'/>".


>
> Everything is controlled through the XML document described here:
>
>     https://libvirt.org/formatnetwork.html
>
> We don't have separate APIs for each piece of info - just the one
> virNetworkDefineXML API that takes the XML document.
>
> Regards,
> Daniel
>