qemu-sockets: fix conversion of ipv4/ipv6 JSON to QemuOpts
commitb77e7c8e99f9ac726c4eaa2fc3461fd886017dc0
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 12 Oct 2015 13:35:16 +0000 (12 15:35 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 12 Oct 2015 16:29:26 +0000 (12 18:29 +0200)
treeed4975227ff5a2fe955ea81f36caf6469bbff8e6
parent5ea530491fe9ac56f75bc1833cc3fd7722b24efd
qemu-sockets: fix conversion of ipv4/ipv6 JSON to QemuOpts

The QemuOpts-based code treats "option not set" and "option set
to false" the same way for the ipv4 and ipv6 options, because it
is meant to handle only the ",ipv4" and ",ipv6" substrings in
hand-crafted option parsers.

When converting InetSocketAddress to QemuOpts, however, it is
necessary to handle all three cases (not set, set to true, set
to false).  Currently we are not handling all cases correctly.
The rules are:

* if none or both options are absent, leave things as is

* if the single present option is Y, the other should be N.
This can be implemented by leaving things as is, or by setting
the other option to N as done in this patch.

* if the single present option is N, the other should be Y.
This is handled by the "else if" branch of this patch.

This ensures that the ipv4 option has an effect on Windows,
where creating the socket with PF_UNSPEC makes an ipv6
socket.  With this patch, ",ipv4" will result in a PF_INET
socket instead.

Reported-by: Sair, Umair <Umair_Sair@mentor.com>
Tested-by: Sair, Umair <Umair_Sair@mentor.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
util/qemu-sockets.c