summaryrefslogtreecommitdiffstats
path: root/util/qemu-sockets.c
Commit message (Collapse)AuthorAgeFilesLines
* qemu-sockets: do not test path with access() before unlinkingPaolo Bonzini2015-11-061-2/+1
| | | | | | | | | | | | | | | Using access() is a time-of-check/time-of-use race condition. It is okay to use them to provide better error messages, but that is pretty much it. This is not one such case; on the other hand, access() *will* skip unlink() for a non-existent path, so ignore ENOENT return values from the unlink() system call. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* sockets: Convert to new qapi union layoutEric Blake2015-11-021-31/+31
| | | | | | | | | | | | | | | | | We have two issues with our qapi union layout: 1) Even though the QMP wire format spells the tag 'type', the C code spells it 'kind', requiring some hacks in the generator. 2) The C struct uses an anonymous union, which places all tag values in the same namespace as all non-variant members. This leads to spurious collisions if a tag value matches a non-variant member's name. Make the conversion to the new layout for socket-related code. Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1445898903-12082-17-git-send-email-eblake@redhat.com> [Commit message tweaked slightly] Signed-off-by: Markus Armbruster <armbru@redhat.com>
* sockets: allow port to be NULL when listening on IP addressDaniel P. Berrange2015-10-201-5/+13
| | | | | | | | | If the port in the SocketAddress struct is NULL, it can allow the kernel to automatically select a free port. This is useful in particular in unit tests to avoid a race trying to find a free port to run a test case on. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* sockets: move qapi_copy_SocketAddress into qemu-sockets.cDaniel P. Berrange2015-10-201-0/+30
| | | | | | | | | The qapi_copy_SocketAddress method is going to be useful in more places than just qemu-char.c, so move it into the qemu-sockets.c file to allow its reuse. Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* sockets: add helpers for creating SocketAddress from a socketDaniel P. Berrange2015-10-201-0/+110
| | | | | | | | Add two helper methods that, given a socket file descriptor, can return a populated SocketAddress struct containing either the local or remote address information. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* qemu-sockets: fix conversion of ipv4/ipv6 JSON to QemuOptsPaolo Bonzini2015-10-121-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: improve ai_flag hints for ipv6 hostsWolfgang Bumiller2015-06-231-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | *) Do not use AI_ADDRCONFIG on listening sockets, because this flag makes it impossible to explicitly listen on '127.0.0.1' if no global ipv4 address is configured additionally, making this a very uncomfortable option. *) Add AI_V4MAPPED hint for connecting sockets. If your system is globally only connected via ipv6 you often still want to be able to use '127.0.0.1' and 'localhost' (even if localhost doesn't also have an ipv6 entry). For example, PVE - unless explicitly asking for insecure mode - uses ipv4 loopback addresses with QEMU for live migrations tunneled over SSH. These fail to start because AI_ADDRCONFIG makes getaddrinfo refuse to work with '127.0.0.1'. As for the AI_V4MAPPED flag: glibc uses it by default, and providing non-0 flags removes it. I think it makes sense to use it. I also want to point out that glibc explicitly sidesteps POSIX standards when passing 0 as hints by then assuming both AI_V4MAPPED and AI_ADDRCONFIG (the latter being a rather weird choice IMO), while according to POSIX.1-2001 it should be assumed 0. (glibc considers its choice an improvement.) Since either AI_CANONNAME or AI_PASSIVE are passed in our cases, glibc's default flags in turn are disabled again unless explicitly added, which I do with this patch. Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* Change qemu_set_fd_handler2(..., NULL, ...) to qemu_set_fd_handlerFam Zheng2015-06-121-5/+3
| | | | | | | | | | | | | | | Done with following Coccinelle semantic patch, plus manual cosmetic changes in net/*.c. @@ expression E1, E2, E3, E4; @@ - qemu_set_fd_handler2(E1, NULL, E2, E3, E4); + qemu_set_fd_handler(E1, E2, E3, E4); Signed-off-by: Fam Zheng <famz@redhat.com> Message-id: 1433400324-7358-8-git-send-email-famz@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* util: socket: Add missing localaddr and localport option for DGRAM socketPeter Krempa2015-06-031-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The 'socket_optslist' structure does not contain the 'localaddr' and 'localport' options that are parsed in case you are creating a 'connect' type UDP character device. I've noticed it happening after commit f43e47dbf6de24db20ec9b588bb6cc762 made qemu abort() after seeing the invalid option. A minimal reproducer for the case is: $ qemu-system-x86_64 -chardev udp,id=charrng0,host=127.0.0.1,port=1234,localaddr=,localport=1234 qemu-system-x86_64: -chardev udp,id=charrng0,host=127.0.0.1,port=1234,localaddr=,localport=1234: Invalid parameter 'localaddr' Aborted (core dumped) Prior to the commit mentioned above the error would be printed but the value for localaddr and localport was simply ignored. I did not go through the code to find out when it was broken. Add the two fields so that the options can again be parsed correctly and qemu doesn't abort(). Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1220252 Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* qemu-sockets: Report explicit error if unlink failsCole Robinson2015-05-201-1/+6
| | | | | | | | | | | | | | | | | | | | | Consider this case: $ ls -ld ~/root-owned/ drwx--x--x. 2 root root 4096 Apr 29 12:55 /home/crobinso/root-owned/ $ ls -l ~/root-owned/foo.sock -rwxrwxrwx. 1 crobinso crobinso 0 Apr 29 12:55 /home/crobinso/root-owned/foo.sock $ qemu-system-x86_64 -vnc unix:~/root-owned/foo.sock qemu-system-x86_64: -vnc unix:/home/crobinso/root-owned/foo.sock: Failed to start VNC server: Failed to bind socket to /home/crobinso/root-owned/foo.sock: Address already in use ...which is techinically true, but the real error is that we failed to unlink. So report it. This may seem pathological but it's a real possibility via libvirt. Signed-off-by: Cole Robinson <crobinso@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
* qemu-sockets: Simplify setting numeric and boolean optionsMarkus Armbruster2015-02-261-9/+7
| | | | | | | | Don't convert numbers or bools to strings for use with qemu_opt_set(), simply use qemu_opt_set_number() or qemu_opt_set_bool() instead. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
* QemuOpts: Drop qemu_opt_set(), rename qemu_opt_set_err(), fix useMarkus Armbruster2015-02-261-16/+18
| | | | | | | | | | | | | | | | qemu_opt_set() is a wrapper around qemu_opt_set() that reports the error with qerror_report_err(). Most of its users assume the function can't fail. Make them use qemu_opt_set_err() with &error_abort, so that should the assumption ever break, it'll break noisily. Just two users remain, in util/qemu-config.c. Switch them to qemu_opt_set_err() as well, then rename qemu_opt_set_err() to qemu_opt_set(). Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
* QemuOpts: Convert qemu_opt_set_bool() to Error, fix its useMarkus Armbruster2015-02-261-2/+2
| | | | | | | | | | | | | | | | Return the Error object instead of reporting it with qerror_report_err(). Change callers that assume the function can't fail to pass &error_abort, so that should the assumption ever break, it'll break noisily. Turns out all callers outside its unit test assume that. We could drop the Error ** argument, but that would make the interface less regular, so don't. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
* qemu-sockets: Fix buffer overflow in inet_parse()Kevin Wolf2015-02-101-1/+1
| | | | | | | | | The size of the stack allocated host[] array didn't account for the terminating '\0' byte that sscanf() writes. Fix the array size. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* qemu-sockets: improve error reporting in unix_listen_optsPaolo Bonzini2015-02-101-6/+18
| | | | | | | | | Coverity complains about not checking the returned value of mkstemp. While at it, also improve error checking for snprintf, and refine error messages in general. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* qemu-sockets: Add error to non-blocking connect handlerCorey Minyard2014-10-091-5/+15
| | | | | | | | | An error value here would be quite handy and more consistent with the rest of the code. Signed-off-by: Corey Minyard <cminyard@mvista.com> [Make sure SO_ERROR value is passed to error_setg_errno. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-socket: Eliminate silly QERR_ macrosMarkus Armbruster2014-09-261-13/+13
| | | | | | | | | | | The QERR_ macros are leftovers from the days of "rich" error objects. They're used with error_set() and qerror_report(), and expand into the first *two* arguments. This trickiness has become pointless. Clean up. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* util/qemu-sockets.c: Support specifying IPv4 or IPv6 in socket_dgram()Peter Maydell2014-09-161-2/+1
| | | | | | | | | | | | | | | | | | Currently you can specify whether you want a UDP chardev backend to be IPv4 or IPv6 using the ipv4 or ipv6 options if you use the QemuOpts parsing code in inet_dgram_opts(). However the QMP struct parsing code in socket_dgram() doesn't provide this flexibility (which in turn prevents us from converting the UDP backend handling to the new style QAPI framework). Use the existing inet_addr_to_opts() function to convert the remote->inet address to option strings; this handles ipv4 and ipv6 flags as well as host and port. (It will also convert any 'to' specification, which is harmless as it is ignored in this context.) Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Message-id: 1409653457-27863-3-git-send-email-peter.maydell@linaro.org
* don't use 'Yoda conditions'Gonglei2014-08-151-1/+1
| | | | | | | | imitate nearby code about using '!value' or 'value == NULL' Signed-off-by: Gonglei <arei.gonglei@huawei.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* qapi event: convert SPICE eventsWenchao Xia2014-06-231-10/+0
| | | | | | | | | | | | | | | SPICE_INITIALIZED, SPICE_CONNECTED, SPICE_DISCONNECTED and SPICE_MIGRATE_COMPLETED are converted in one patch, since they use some common functions. inet_strfamily() is removed since no callers exist anymore. Note that there is no existing doc for SPICE_MIGRATE_COMPLETED in docs/qmp/qmp-events.txt before this patch. Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* qapi: adjust existing definesWenchao Xia2014-06-231-0/+10
| | | | | | | | | | | | | | | In order to let event defines use existing types later, instead of redefine new ones, some old type defines for spice and vnc are changed, and BlockErrorAction is moved from block.h to qapi schema. Note that BlockErrorAction is not merged with BlockdevOnError. At this point, VncInfo is not made a child of VncBasicInfo, because VncBasicInfo has mandatory fields where VncInfo makes them optional. Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* inet_listen_opts: add error checkingGerd Hoffmann2014-06-131-2/+13
| | | | | | | | | Don't use atoi() function which doesn't detect errors, switch to strtol and error out on failures. Also add a range check while being at it. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com>
* util/qemu-sockets.c: Avoid unused variable warningsPeter Maydell2014-06-101-2/+1
| | | | | | | | | | The 'on' variable is never used, and 'off' is only used if IPV6_V6ONLY is defined; delete 'on' and move 'off' to the point where it is used. This avoids warnings from clang 3.4. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* qemu-socket: Clean up inet_connect_opts()Markus Armbruster2014-05-211-12/+16
| | | | | | | | | | | | Separate the search for a working addrinfo from the code that does something with it. Makes for a clearer search loop. Use a local Error * to simplify resetting the error in the search loop. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
* qemu-option: Remove qemu_opts_create_nofailPeter Crosthwaite2014-01-061-9/+9
| | | | | | | | | | | | | This is a boiler-plate _nofail variant of qemu_opts_create. Remove and use error_abort in call sites. null/0 arguments needs to be added for the id and fail_if_exists fields in affected callsites due to argument inconsistency between the normal and no_fail variants. Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* util: call socket_set_fast_reuse instead of setting SO_REUSEADDRSebastian Ottlik2013-10-021-3/+3
| | | | | | | | | | SO_REUSEADDR should be avoided on Windows but is desired on other operating systems. So instead of setting it we call socket_set_fast_reuse that will result in the appropriate behaviour on all operating systems. Signed-off-by: Sebastian Ottlik <ottlik@fzi.de> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Stefan Weil <sw@weilnetz.de>
* qemu-socket: don't leak opts on errorGerd Hoffmann2013-06-281-1/+1
| | | | | | Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* qemu-socket: catch monitor_get_fd failuresGerd Hoffmann2013-06-281-1/+1
| | | | | | Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* qemu-socket: drop pointless allocationGerd Hoffmann2013-06-281-1/+0
| | | | | | Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* qemu-socket: zero-initialize SocketAddressGerd Hoffmann2013-06-281-2/+2
| | | | | | Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* qemu-socket: allow hostnames starting with a digitJán Tomko2013-06-181-9/+4
| | | | | | | | | | | According to RFC 1123 [1], hostnames can start with a digit too. [1] http://tools.ietf.org/html/rfc1123#page-13 Signed-off-by: Ján Tomko <jtomko@redhat.com> Cc: qemu-stable@nongnu.org [Use strspn, not strcspn. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* util: move socket_init() to osdep.cMarc-André Lureau2013-04-241-24/+0
| | | | | | | | vscclient needs to call socket_init() for portability. Moving to osdep.c since it has no internal dependency. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Alon Levy <alevy@redhat.com>
* qemu-socket: set passed fd non-blocking in socket_connect()Stefan Hajnoczi2013-04-021-0/+1
| | | | | | | | | | socket_connect() sets non-blocking on TCP or UNIX domain sockets if a callback function is passed. Do the same for file descriptor passing, otherwise we could unexpectedly be using a blocking file descriptor. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* oslib-posix: rename socket_set_nonblock() to qemu_set_nonblock()Stefan Hajnoczi2013-04-021-2/+2
| | | | | | | | | The fcntl(fd, F_SETFL, O_NONBLOCK) flag is not specific to sockets. Rename to qemu_set_nonblock() just like qemu_set_cloexec(). Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* Merge remote-tracking branch 'kwolf/for-anthony' into stagingAnthony Liguori2013-03-221-15/+15
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | # By Kevin Wolf (12) and Peter Lieven (2) # Via Kevin Wolf * kwolf/for-anthony: nbd: Check against invalid option combinations nbd: Use default port if only host is specified block: Allow omitting the file name when using driver-specific options block: Make find_image_format safe with NULL filename block: Rename variable to avoid shadowing block: Introduce .bdrv_parse_filename callback nbd: Accept -drive options for the network connection nbd: Remove unused functions nbd: Keep hostname and port separate qemu-socket: Make socket_optslist public block: Pass bdrv_file_open() options to block drivers block: Add options QDict to bdrv_file_open() prototypes block: complete all IOs before resizing a device Revert "block: complete all IOs before .bdrv_truncate"
| * nbd: Keep hostname and port separateKevin Wolf2013-03-221-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The NBD block supports an URL syntax, for which a URL parser returns separate hostname and port fields. It also supports the traditional qemu syntax encoded in a filename. Until now, after parsing the URL to get each piece of information, a new string is built to be fed to socket functions. Instead of building a string in the URL case that is immediately parsed again, parse the string in both cases and use the QemuOpts interface to qemu-sockets.c. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
| * qemu-socket: Make socket_optslist publicKevin Wolf2013-03-221-12/+12
| | | | | | | | | | | | | | Allow other users to create the QemuOpts needed for inet_connect_opts(). Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
* | MinGW: Replace setsockopt by qemu_setsocketoptStefan Weil2013-03-221-5/+5
|/ | | | | | | | | Instead of adding missing type casts which are needed by MinGW for the 4th argument, the patch uses qemu_setsockopt which was invented for this purpose. Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* chardev: add udp support to qapiGerd Hoffmann2013-03-131-0/+25
| | | | | | This patch adds 'udp' support to qapi. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
* char-socket: fix error reportingAnthony Liguori2013-03-081-0/+4
| | | | | | | | | | | | Right now the inet connect code tries all available addresses but until one doesn't fail. It passes local_err each time without clearing it from the previous failure. This can trigger an assert since the inet connect code tries to set an error on an object != NULL. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Amit Shah <amit.shah@redhat.com> Message-id: 16c806d60aa5e9660ed7751bb4e37dcd278f97f0.1362505276.git.amit.shah@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* error: Strip trailing '\n' from error string arguments (again)Markus Armbruster2013-02-111-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 6daf194d and be62a2eb got rid of a bunch, but they keep coming back. Tracked down with this Coccinelle semantic patch: @r@ expression err, eno, cls, fmt; position p; @@ ( error_report(fmt, ...)@p | error_set(err, cls, fmt, ...)@p | error_set_errno(err, eno, cls, fmt, ...)@p | error_setg(err, fmt, ...)@p | error_setg_errno(err, eno, fmt, ...)@p ) @script:python@ fmt << r.fmt; p << r.p; @@ if "\\n" in str(fmt): print "%s:%s:%s:%s" % (p[0].file, p[0].line, p[0].column, fmt) Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-id: 1360354939-10994-4-git-send-email-armbru@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* build: move libqemuutil.a components to util/Paolo Bonzini2013-01-121-0/+970
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
OpenPOWER on IntegriCloud