<div dir="ltr"><br><br><br>On Tue, Aug 27, 2013 at 6:20 PM, Daniel P. Berrange <<a href="mailto:berrange@redhat.com">berrange@redhat.com</a>> wrote:<br>><br>> On Sun, Aug 25, 2013 at 04:45:44AM +0530, Nehal J Wani wrote:<br>
> > Use virDomainInterfacesAddresses in virsh<br>> ><br>> > tools/virsh-domain-monitor.c<br>> > * Introduce new command : domifaddr<br>> > virsh # domifaddr f18<br>> > Name MAC address IPv4 address IPv6 address<br>
> > -------------------------------------------------------------------------------<br>> > lo 00:00:00:00:00:00 <a href="http://127.0.0.1/8">127.0.0.1/8</a> ::1/128<br>> > eth0 52:54:00:89:4e:97 <a href="http://192.168.101.130/24">192.168.101.130/24</a> fe80::5054:ff:fe89:4e97/64<br>
> > eth0:1 52:54:00:89:4e:97 <a href="http://192.168.101.133/24">192.168.101.133/24</a><br>> > eth0:2 52:54:00:89:4e:97 <a href="http://192.168.101.132/24">192.168.101.132/24</a><br>> > eth1 52:54:00:89:ad:35 <a href="http://192.168.102.142/24">192.168.102.142/24</a> fe80::5054:ff:fe89:ad35/64<br>
> > eth1:1 52:54:00:89:ad:35 <a href="http://192.168.102.143/24">192.168.102.143/24</a><br>> > eth2 52:54:00:d3:39:ee <a href="http://192.168.103.183/24">192.168.103.183/24</a> fe80::5054:ff:fed3:39ee/64<br>
> > eth2:0 52:54:00:d3:39:ee <a href="http://192.168.103.184/24">192.168.103.184/24</a><br>> > eth2:1 52:54:00:d3:39:ee <a href="http://192.168.103.185/24">192.168.103.185/24</a><br>> > eth3 52:54:00:fe:4c:4f <a href="http://192.168.101.197/24">192.168.101.197/24</a> fe80::5054:ff:fefe:4c4f/64<br>
> > eth3:1 52:54:00:fe:4c:4f <a href="http://192.168.101.198/24">192.168.101.198/24</a><br>><br>> This formatting of IP addrs is broken.<br>><br>> We should not expose interface aliases 'eth0:1', 'eth0:2', etc. If QEMU agent<br>
> is returning such names, either we should fix the agent, or strip the ":1"<br>> suffixes in libvirt. The aliased names are an artifact of the legacy linux IP<br>> config tools. The new 'ip' command does not use these - it just shows 'eth0'<br>
> with multiple IPv4 and multiple IPv6 addresses, which is also how libvirt/netcf<br>> report physical device names & config.<br>><br>> Our display format must allow for NICs having arbitrarily many addresses<br>
> of either type, so displaying IPv4/IPv6 side by side will not work.<br>><br>> I think we need a display format like:<br>><br>> virsh domifaddr f18<br>> Name MAC address Protocol Address<br>
> -------------------------------------------------------------------------------<br>> lo 00:00:00:00:00:00 ipv4 <a href="http://127.0.0.1/8">127.0.0.1/8</a><br>> - - ipv6 ::1/128<br>
> eth0 52:54:00:89:4e:97 ipv4 <a href="http://192.168.101.130/24">192.168.101.130/24</a><br>> - - ipv4 <a href="http://192.168.101.133/24">192.168.101.133/24</a><br>
> - - ipv4 <a href="http://192.168.101.132/24">192.168.101.132/24</a><br>> - - ipv6 fe80::5054:ff:fe89:4e97/64<br>> eth1 52:54:00:89:ad:35 ipv4 <a href="http://192.168.102.142/24">192.168.102.142/24</a><br>
> - - ipv4 <a href="http://192.168.102.143/24">192.168.102.143/24</a><br>> - - ipv6 fe80::5054:ff:fe89:ad35/64<br>><br>><br>> With option to fully display all fields to make life easier for scripts:<br>
><br>> virsh domifaddr --full f18<br>> Name MAC address Protocol Address<br>> -------------------------------------------------------------------------------<br>> lo 00:00:00:00:00:00 ipv4 <a href="http://127.0.0.1/8">127.0.0.1/8</a><br>
> lo 00:00:00:00:00:00 ipv6 ::1/128<br>> eth0 52:54:00:89:4e:97 ipv4 <a href="http://192.168.101.130/24">192.168.101.130/24</a><br>> eth0 52:54:00:89:4e:97 ipv4 <a href="http://192.168.101.133/24">192.168.101.133/24</a><br>
> eth0 52:54:00:89:4e:97 ipv4 <a href="http://192.168.101.132/24">192.168.101.132/24</a><br>> eth0 52:54:00:89:4e:97 ipv6 fe80::5054:ff:fe89:4e97/64<br>> eth1 52:54:00:89:ad:35 ipv4 <a href="http://192.168.102.142/24">192.168.102.142/24</a><br>
> eth1 52:54:00:89:ad:35 ipv4 <a href="http://192.168.102.143/24">192.168.102.143/24</a><br>> eth1 52:54:00:89:ad:35 ipv6 fe80::5054:ff:fe89:ad35/64<br>><br>><br>> > +<br>
> > + for (i = 0; i < ifaces_count; i++) {<br>> > + virDomainInterfacePtr iface = ifaces[i];<br>> > + virBuffer buf = VIR_BUFFER_INITIALIZER;<br>> > + const char *hwaddr = "";<br>
> > + const char *ip_addr_str = NULL;<br>> > +<br>> > + if (interface && STRNEQ(interface, iface->name)) {<br>> > + virBufferFreeAndReset(&buf);<br>> > + continue;<br>
> > + }<br>> > +<br>> > + if (iface->hwaddr)<br>> > + hwaddr = iface->hwaddr;<br>> > +<br>> > + for (j = 0; j < iface->naddrs; j++) {<br>> > + if (j)<br>
> > + virBufferAsprintf(&buf, "%25s/%d",<br>> > + iface->addrs[j].addr,<br>> > + iface->addrs[j].prefix);<br>
> > + else<br>> > + virBufferAsprintf(&buf, "%s/%d",<br>> > + iface->addrs[j].addr,<br>> > + iface->addrs[j].prefix);<br>
><br>> This logic is very broken not allowing for multiple addrs per device<br>><br>> > + }<br>> > +<br>> > + if (virBufferError(&buf)) {<br>> > + virBufferFreeAndReset(&buf);<br>
> > + virReportOOMError();<br>> > + return ret;<br>> > + }<br>> > +<br>> > + ip_addr_str = virBufferContentAndReset(&buf);<br>> > +<br>> > + if (!ip_addr_str)<br>
> > + ip_addr_str = "";<br>> > +<br>> > + vshPrintExtra(ctl, " %-10s %-17s %s\n",<br>> > + iface->name, hwaddr, ip_addr_str);<br>> > +<br>
> > + virBufferFreeAndReset(&buf);<br>> > + }<br>> > +<br>> > + ret = true;<br>> > +<br>> > +cleanup:<br>> > + for (i = 0; i < ifaces_count; i++)<br>> > + virDomainInterfaceFree(ifaces[i]);<br>
> > + VIR_FREE(ifaces);<br>> > +<br>> > + virDomainFree(dom);<br>> > + return ret;<br>> > +}<br>> > +<br>> > const vshCmdDef domMonitoringCmds[] = {<br>> > {.name = "domblkerror",<br>
> > .handler = cmdDomBlkError,<br>> > @@ -1944,5 +2039,11 @@ const vshCmdDef domMonitoringCmds[] = {<br>> > .info = info_list,<br>> > .flags = 0<br>> > },<br>> > + {.name = "domifaddr",<br>
> > + .handler = cmdDomIfAddr,<br>> > + .opts = opts_domifaddr,<br>> > + .info = info_domifaddr,<br>> > + .flags = 0<br>> > + },<br>> > {.name = NULL}<br>> > };<br>
><br>><br>> Daniel<br>> --<br>> |: <a href="http://berrange.com">http://berrange.com</a> -o- <a href="http://www.flickr.com/photos/dberrange/">http://www.flickr.com/photos/dberrange/</a> :|<br>> |: <a href="http://libvirt.org">http://libvirt.org</a> -o- <a href="http://virt-manager.org">http://virt-manager.org</a> :|<br>
> |: <a href="http://autobuild.org">http://autobuild.org</a> -o- <a href="http://search.cpan.org/~danberr/">http://search.cpan.org/~danberr/</a> :|<br>> |: <a href="http://entangle-photo.org">http://entangle-photo.org</a> -o- <a href="http://live.gnome.org/gtk-vnc">http://live.gnome.org/gtk-vnc</a> :|<br>
><br>> --<br>> libvir-list mailing list<br>> <a href="mailto:libvir-list@redhat.com">libvir-list@redhat.com</a><br>> <a href="https://www.redhat.com/mailman/listinfo/libvir-list">https://www.redhat.com/mailman/listinfo/libvir-list</a><br>
<br>Suppose I have the following network configuration in my guest:<div><div>[root@localhost ~]# ifconfig </div><div>eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500</div><div> inet 192.168.154.8 netmask 255.255.0.0 broadcast 192.168.255.255</div>
<div> inet6 fe80::5054:ff:fefe:4c4f prefixlen 64 scopeid 0x20<link></div><div> inet6 2001:db8:0:f101::2 prefixlen 64 scopeid 0x0<global></div><div> inet6 2001:db8:0:f101::1 prefixlen 64 scopeid 0x0<global></div>
<div> ether 52:54:00:fe:4c:4f txqueuelen 1000 (Ethernet)</div><div> RX packets 1535 bytes 123240 (120.3 KiB)</div><div> RX errors 0 dropped 0 overruns 0 frame 0</div><div> TX packets 1133 bytes 160636 (156.8 KiB)</div>
<div> TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0</div><div><br></div><div>eth0:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500</div><div> inet 102.168.168.168 netmask 255.255.0.0 broadcast 192.168.255.255</div>
<div> ether 52:54:00:fe:4c:4f txqueuelen 1000 (Ethernet)</div><div><br></div><div>eth0:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500</div><div> inet 192.168.101.197 netmask 255.255.255.0 broadcast 192.168.101.255</div>
<div> ether 52:54:00:fe:4c:4f txqueuelen 1000 (Ethernet)</div><div><br></div><div>lo: flags=73<UP,LOOPBACK,RUNNING> mtu 16436</div><div> inet 127.0.0.1 netmask 255.0.0.0</div><div> inet6 ::1 prefixlen 128 scopeid 0x10<host></div>
<div> loop txqueuelen 0 (Local Loopback)</div><div> RX packets 8 bytes 616 (616.0 B)</div><div> RX errors 0 dropped 0 overruns 0 frame 0</div><div> TX packets 8 bytes 616 (616.0 B)</div>
<div> TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0</div><div><br></div><div>[root@localhost ~]# ip addr</div><div>1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN </div><div> link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00</div>
<div> inet <a href="http://127.0.0.1/8">127.0.0.1/8</a> scope host lo</div><div> inet6 ::1/128 scope host </div><div> valid_lft forever preferred_lft forever</div><div>2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000</div>
<div> link/ether 52:54:00:fe:4c:4f brd ff:ff:ff:ff:ff:ff</div><div> inet <a href="http://192.168.154.8/16">192.168.154.8/16</a> brd 192.168.255.255 scope global eth0</div><div> inet <a href="http://192.168.101.197/24">192.168.101.197/24</a> brd 192.168.101.255 scope global eth0:1</div>
<div> inet <a href="http://102.168.168.168/16">102.168.168.168/16</a> brd 192.168.255.255 scope global eth0:0</div><div> inet6 2001:db8:0:f101::2/64 scope global </div><div> valid_lft forever preferred_lft forever</div>
<div> inet6 2001:db8:0:f101::1/64 scope global </div><div> valid_lft forever preferred_lft forever</div><div> inet6 fe80::5054:ff:fefe:4c4f/64 scope link </div><div> valid_lft forever preferred_lft forever</div>
<div>[root@localhost ~]# </div><div><br></div><div>Now, qemu-guest-agent returns back (after making it pretty):</div><div><span style="color:rgb(0,0,0)">{</span><br></div><div><pre style="color:rgb(0,0,0)"> "return": [
{
"name": "lo",
"ip-addresses": [
{
"ip-address-type": "ipv4",
"ip-address": "127.0.0.1",
"prefix": 8
},
{
"ip-address-type": "ipv6",
"ip-address": "::1",
"prefix": 128
}
],
"hardware-address": "00:00:00:00:00:00"
},
{
"name": "eth0",
"ip-addresses": [
{
"ip-address-type": "ipv4",
"ip-address": "192.168.154.8",
"prefix": 16
},
{
"ip-address-type": "ipv6",
"ip-address": "2001:db8:0:f101::2",
"prefix": 64
},
{
"ip-address-type": "ipv6",
"ip-address": "2001:db8:0:f101::1",
"prefix": 64
},
{
"ip-address-type": "ipv6",
"ip-address": "fe80::5054:ff:fefe:4c4f",
"prefix": 64
}
],
"hardware-address": "52:54:00:fe:4c:4f"
},
{
"name": "eth0:1",
"ip-addresses": [
{
"ip-address-type": "ipv4",
"ip-address": "192.168.101.197",
"prefix": 24
}
],
"hardware-address": "52:54:00:fe:4c:4f"
},
{
"name": "eth0:0",
"ip-addresses": [
{
"ip-address-type": "ipv4",
"ip-address": "102.168.168.168",
"prefix": 16
}
],
"hardware-address": "52:54:00:fe:4c:4f"
}
]
}</pre></div>So, qemu-ga doesn't understand that there can't be more than one</div><div>device with same MAC addr. So, I think we are left with the following</div><div>options:</div><div>(i) Modify qemu-guest-agent to return addresses belonging to same<br>
</div><div>MAC address grouped under one interface only.</div><div>OR</div><div>(ii) Let the reply be as it is now. Strip the ":0", ":1" from the response</div><div>of guest agent (Is this really necessary?) . We'll have to parse the JSON</div>
<div>multiple times and fill the virDomainInterface structs by grouping them</div><div>according to the MAC addresses.</div><div><br>--<br>Nehal J Wani<br><br></div></div>