parse IP address for bridge interfaces

This commit is contained in:
John Levon 2009-01-23 01:48:47 +00:00
parent c4985e9419
commit e80f10064e
11 changed files with 106 additions and 6 deletions

View File

@ -1,3 +1,14 @@
Thu Jan 22 17:42:37 PST 2009 John Levon <john.levon@sun.com>
* src/domain_conf.c, src/domain_conf.h, src/xend_internal.c,
src/xm_internal.c: parse IP address for bridge interfaces
* tests/sexpr2xmltest.c, tests/xml2sexprtest.c,
tests/sexpr2xmldata/sexpr2xml-bridge-ipaddr.sexpr,
tests/sexpr2xmldata/sexpr2xml-bridge-ipaddr.xml,
tests/xml2sexprdata/xml2sexpr-bridge-ipaddr.sexpr,
tests/xml2sexprdata/xml2sexpr-bridge-ipaddr.xml: add tests
Thu Jan 21 19:44:12 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
Use the GNULIB random_r function

View File

@ -289,6 +289,7 @@ void virDomainNetDefFree(virDomainNetDefPtr def)
case VIR_DOMAIN_NET_TYPE_BRIDGE:
VIR_FREE(def->data.bridge.brname);
VIR_FREE(def->data.bridge.script);
VIR_FREE(def->data.bridge.ipaddr);
break;
}
@ -887,7 +888,8 @@ virDomainNetDefParseXML(virConnectPtr conn,
address = virXMLPropString(cur, "address");
port = virXMLPropString(cur, "port");
} else if ((address == NULL) &&
(def->type == VIR_DOMAIN_NET_TYPE_ETHERNET) &&
(def->type == VIR_DOMAIN_NET_TYPE_ETHERNET ||
def->type == VIR_DOMAIN_NET_TYPE_BRIDGE) &&
(xmlStrEqual(cur->name, BAD_CAST "ip"))) {
address = virXMLPropString(cur, "address");
} else if ((ifname == NULL) &&
@ -954,6 +956,10 @@ virDomainNetDefParseXML(virConnectPtr conn,
def->data.bridge.script = script;
script = NULL;
}
if (address != NULL) {
def->data.bridge.ipaddr = address;
address = NULL;
}
break;
case VIR_DOMAIN_NET_TYPE_CLIENT:
@ -2889,6 +2895,9 @@ virDomainNetDefFormat(virConnectPtr conn,
case VIR_DOMAIN_NET_TYPE_BRIDGE:
virBufferEscapeString(buf, " <source bridge='%s'/>\n",
def->data.bridge.brname);
if (def->data.bridge.ipaddr)
virBufferVSprintf(buf, " <ip address='%s'/>\n",
def->data.bridge.ipaddr);
if (def->data.bridge.script)
virBufferEscapeString(buf, " <script path='%s'/>\n",
def->data.bridge.script);

View File

@ -155,6 +155,7 @@ struct _virDomainNetDef {
struct {
char *brname;
char *script;
char *ipaddr;
} bridge;
} data;
char *ifname;

View File

@ -1763,11 +1763,19 @@ xenDaemonParseSxprNets(virConnectPtr conn,
net->type == VIR_DOMAIN_NET_TYPE_BRIDGE &&
!(net->data.bridge.script = strdup(tmp2)))
goto no_memory;
tmp = sexpr_node(node, "device/vif/ip");
if (tmp &&
!(net->data.bridge.ipaddr = strdup(tmp)))
goto no_memory;
} else {
net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
if (tmp2 &&
!(net->data.ethernet.script = strdup(tmp2)))
goto no_memory;
tmp = sexpr_node(node, "device/vif/ip");
if (tmp &&
!(net->data.ethernet.ipaddr = strdup(tmp)))
goto no_memory;
}
tmp = sexpr_node(node, "device/vif/vifname");
@ -1801,11 +1809,6 @@ xenDaemonParseSxprNets(virConnectPtr conn,
net->mac[5] = mac[5];
}
tmp = sexpr_node(node, "device/vif/ip");
if (tmp &&
!(net->data.ethernet.ipaddr = strdup(tmp)))
goto no_memory;
if (model &&
!(net->model = strdup(model)))
goto no_memory;
@ -5135,6 +5138,8 @@ xenDaemonFormatSxprNet(virConnectPtr conn,
script = def->data.bridge.script;
virBufferVSprintf(buf, "(script '%s')", script);
if (def->data.bridge.ipaddr != NULL)
virBufferVSprintf(buf, "(ip '%s')", def->data.bridge.ipaddr);
break;
case VIR_DOMAIN_NET_TYPE_NETWORK:

View File

@ -1089,6 +1089,9 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) {
if (script[0] &&
!(net->data.bridge.script = strdup(script)))
goto no_memory;
if (ip[0] &&
!(net->data.bridge.ipaddr = strdup(ip)))
goto no_memory;
} else {
if (script[0] &&
!(net->data.ethernet.script = strdup(script)))
@ -1883,6 +1886,8 @@ static int xenXMDomainConfigFormatNet(virConnectPtr conn,
switch (net->type) {
case VIR_DOMAIN_NET_TYPE_BRIDGE:
virBufferVSprintf(&buf, ",bridge=%s", net->data.bridge.brname);
if (net->data.bridge.ipaddr)
virBufferVSprintf(&buf, ",ip=%s", net->data.bridge.ipaddr);
break;
case VIR_DOMAIN_NET_TYPE_ETHERNET:

View File

@ -0,0 +1,2 @@
(domain (domid 6)(name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w')))(device (vif (mac '00:11:22:33:44:55')(bridge 'xenbr2')(script 'vif-bridge')(ip '192.0.2.1')))

View File

@ -0,0 +1,34 @@
<domain type='xen' id='6'>
<name>pvtest</name>
<uuid>596a5d21-71f4-8fb2-e068-e2386a5c413e</uuid>
<memory>430080</memory>
<currentMemory>430080</currentMemory>
<vcpu>2</vcpu>
<os>
<type>linux</type>
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
<initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
<cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os </cmdline>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>destroy</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/some.img'/>
<target dev='xvda' bus='xen'/>
</disk>
<interface type='bridge'>
<mac address='00:11:22:33:44:55'/>
<source bridge='xenbr2'/>
<ip address='192.0.2.1'/>
<script path='vif-bridge'/>
<target dev='vif6.0'/>
</interface>
<console type='pty'>
<target port='0'/>
</console>
</devices>
</domain>

View File

@ -139,6 +139,7 @@ mymain(int argc, char **argv)
DO_TEST("net-routed", "net-routed", 2);
DO_TEST("net-bridged", "net-bridged", 2);
DO_TEST("net-e1000", "net-e1000", 2);
DO_TEST("bridge-ipaddr", "bridge-ipaddr", 3);
DO_TEST("no-source-cdrom", "no-source-cdrom", 2);
DO_TEST("fv-utc", "fv-utc", 1);

View File

@ -0,0 +1 @@
(vm (name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d21-71f4-8fb2-e068-e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w')))(device (vif (mac '00:11:22:33:44:55')(bridge 'xenbr2')(script 'vif-bridge')(ip '192.0.2.1'))))

View File

@ -0,0 +1,30 @@
<domain type='xen' id='15'>
<name>pvtest</name>
<uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
<os>
<type>linux</type>
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
<initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
<cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os </cmdline>
</os>
<memory>430080</memory>
<vcpu>2</vcpu>
<on_poweroff>destroy</on_poweroff>
<on_reboot>destroy</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<disk type='file' device='disk'>
<source file='/root/some.img'/>
<target dev='xvda'/>
</disk>
<interface type="bridge">
<mac address="00:11:22:33:44:55"/>
<source bridge="xenbr2"/>
<ip address="192.0.2.1"/>
<script path="vif-bridge"/>
<target dev="vif4.0"/>
</interface>
<console tty='/dev/pts/4'/>
</devices>
</domain>

View File

@ -126,6 +126,7 @@ mymain(int argc, char **argv)
DO_TEST("net-routed", "net-routed", "pvtest", 2);
DO_TEST("net-bridged", "net-bridged", "pvtest", 2);
DO_TEST("net-e1000", "net-e1000", "pvtest", 2);
DO_TEST("bridge-ipaddr", "bridge-ipaddr", "pvtest", 2);
DO_TEST("no-source-cdrom", "no-source-cdrom", "test", 2);
DO_TEST("fv-utc", "fv-utc", "fvtest", 1);