[libvirt] network domain name patch

JJ Reynolds jjr at reynoldsus.net
Sat Sep 6 19:14:45 UTC 2008


Hi all,

This is a followup to the excellent patch which allows static IP address assignment.  The problem with that patch is that you can only set the host name and cannot set a FQDN because dnsmasq will, as a security measure, not allow it unless --domain is specified.

This patch adds support for adding <domain name="my.domain" /> to the network config file.  With that stanza, one can then use FQDNs on the static host assignments, and this should be the domain reported for any clients that request it.  If <domain name .. ./> is not specified in the config file, then there is no change in behaviour.

As a special case, you can also set the domain name to "#", whereupon dnsmasq interprets that to use the domain of the host OS.


Example default.xml:

<network>
  <name>default</name>
  <uuid>0098abb7-ff94-4df9-aa78-e4c3fe636a3d</uuid>
  <bridge name="virbr0" />
  <domain name="mynet.net" />
  <forward/>
  <ip address="192.168.122.1" netmask="255.255.255.0">
    <dhcp>
      <host name="vm1.mynet.net" mac="00:16:3e:24:a5:84" ip="192.168.122.101" />
      <host name='vm2.mynet.net' mac="00:16:3e:1f:9a:95" ip="192.168.122.102" />
      <range start="192.168.122.2" end="192.168.122.99" />
    </dhcp>
  </ip>
</network>



Here is the patch:

diff -r -U 3 libvirt-0.4.4/src/network_conf.c libvirt-0.4.4jjr/src/network_conf.c
--- libvirt-0.4.4/src/network_conf.c    2008-08-20 09:20:01.000000000 -0400
+++ libvirt-0.4.4jjr/src/network_conf.c 2008-09-06 14:03:56.000000000 -0400
@@ -326,6 +326,9 @@
         VIR_FREE(tmp);
     }

+    /* Parse network domain information */
+    def->domain = virXPathString(conn, "string(./domain[1]/@name)", ctxt);
+
     /* Parse bridge information */
     def->bridge = virXPathString(conn, "string(./bridge[1]/@name)", ctxt);
     tmp = virXPathString(conn, "string(./bridge[1]/@stp)", ctxt);
diff -r -U 3 libvirt-0.4.4/src/network_conf.h libvirt-0.4.4jjr/src/network_conf.h
--- libvirt-0.4.4/src/network_conf.h    2008-08-20 09:20:01.000000000 -0400
+++ libvirt-0.4.4jjr/src/network_conf.h 2008-09-06 14:03:56.000000000 -0400
@@ -57,6 +57,7 @@
     char *name;

     char *bridge;       /* Name of bridge device */
+    char *domain;
     unsigned long delay;   /* Bridge forward delay (ms) */
     int stp : 1; /* Spanning tree protocol */

diff -r -U 3 libvirt-0.4.4/src/qemu_driver.c libvirt-0.4.4jjr/src/qemu_driver.c
--- libvirt-0.4.4/src/qemu_driver.c     2008-08-29 03:20:02.000000000 -0400
+++ libvirt-0.4.4jjr/src/qemu_driver.c  2008-09-06 14:15:28.000000000 -0400
@@ -1105,6 +1105,7 @@
         1 + /* --keep-in-foreground */
         1 + /* --strict-order */
         1 + /* --bind-interfaces */
+        (network->def->domain?2:0) + /* --domain name */
         2 + /* --pid-file "" */
         2 + /* --conf-file "" */
         /*2 + *//* --interface virbr0 */
@@ -1136,6 +1137,11 @@
     APPEND_ARG(*argv, i++, "--strict-order");
     APPEND_ARG(*argv, i++, "--bind-interfaces");

+    if (network->def->domain) {
+       APPEND_ARG(*argv, i++, "--domain");
+       APPEND_ARG(*argv, i++, network->def->domain);
+    }
+
     APPEND_ARG(*argv, i++, "--pid-file");
     APPEND_ARG(*argv, i++, "");


Thanks!

-JJ Reynolds
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20080906/ef4bfb4b/attachment-0001.htm>


More information about the libvir-list mailing list