2009-11-25 19:48:56 +01:00
|
|
|
/*
|
|
|
|
* QEMU System Emulator
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2008 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2016-01-29 18:50:00 +01:00
|
|
|
#include "qemu/osdep.h"
|
2009-11-25 19:48:56 +01:00
|
|
|
|
2012-10-24 08:43:34 +02:00
|
|
|
#include "net/net.h"
|
2012-09-17 18:43:51 +02:00
|
|
|
#include "clients.h"
|
2012-12-17 18:19:49 +01:00
|
|
|
#include "monitor/monitor.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2009-11-25 19:48:56 +01:00
|
|
|
#include "qemu-common.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/error-report.h"
|
|
|
|
#include "qemu/option.h"
|
|
|
|
#include "qemu/sockets.h"
|
|
|
|
#include "qemu/iov.h"
|
2013-08-21 17:02:47 +02:00
|
|
|
#include "qemu/main-loop.h"
|
2009-11-25 19:48:56 +01:00
|
|
|
|
|
|
|
typedef struct NetSocketState {
|
2012-07-24 17:35:13 +02:00
|
|
|
NetClientState nc;
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
int listen_fd;
|
2009-11-25 19:48:56 +01:00
|
|
|
int fd;
|
2016-05-13 09:35:19 +02:00
|
|
|
SocketReadState rs;
|
2012-08-20 11:14:35 +02:00
|
|
|
unsigned int send_index; /* number of bytes sent (only SOCK_STREAM) */
|
2009-11-25 19:48:56 +01:00
|
|
|
struct sockaddr_in dgram_dst; /* contains inet host and port destination iff connectionless (SOCK_DGRAM) */
|
2012-08-20 11:21:54 +02:00
|
|
|
IOHandler *send_fn; /* differs between SOCK_STREAM/SOCK_DGRAM */
|
|
|
|
bool read_poll; /* waiting to receive data? */
|
|
|
|
bool write_poll; /* waiting to transmit data? */
|
2009-11-25 19:48:56 +01:00
|
|
|
} NetSocketState;
|
|
|
|
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
static void net_socket_accept(void *opaque);
|
2012-08-20 11:21:54 +02:00
|
|
|
static void net_socket_writable(void *opaque);
|
|
|
|
|
|
|
|
static void net_socket_update_fd_handler(NetSocketState *s)
|
|
|
|
{
|
Change qemu_set_fd_handler2(..., NULL, ...) to qemu_set_fd_handler
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>
2015-06-04 08:45:18 +02:00
|
|
|
qemu_set_fd_handler(s->fd,
|
|
|
|
s->read_poll ? s->send_fn : NULL,
|
|
|
|
s->write_poll ? net_socket_writable : NULL,
|
|
|
|
s);
|
2012-08-20 11:21:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void net_socket_read_poll(NetSocketState *s, bool enable)
|
|
|
|
{
|
|
|
|
s->read_poll = enable;
|
|
|
|
net_socket_update_fd_handler(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void net_socket_write_poll(NetSocketState *s, bool enable)
|
|
|
|
{
|
|
|
|
s->write_poll = enable;
|
|
|
|
net_socket_update_fd_handler(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void net_socket_writable(void *opaque)
|
|
|
|
{
|
|
|
|
NetSocketState *s = opaque;
|
|
|
|
|
|
|
|
net_socket_write_poll(s, false);
|
|
|
|
|
|
|
|
qemu_flush_queued_packets(&s->nc);
|
|
|
|
}
|
2009-11-25 19:48:56 +01:00
|
|
|
|
2012-07-24 17:35:13 +02:00
|
|
|
static ssize_t net_socket_receive(NetClientState *nc, const uint8_t *buf, size_t size)
|
2009-11-25 19:48:56 +01:00
|
|
|
{
|
2009-11-25 19:49:08 +01:00
|
|
|
NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc);
|
2012-08-20 11:14:35 +02:00
|
|
|
uint32_t len = htonl(size);
|
|
|
|
struct iovec iov[] = {
|
|
|
|
{
|
|
|
|
.iov_base = &len,
|
|
|
|
.iov_len = sizeof(len),
|
|
|
|
}, {
|
|
|
|
.iov_base = (void *)buf,
|
|
|
|
.iov_len = size,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
size_t remaining;
|
|
|
|
ssize_t ret;
|
2009-11-25 19:48:56 +01:00
|
|
|
|
2012-08-20 11:14:35 +02:00
|
|
|
remaining = iov_size(iov, 2) - s->send_index;
|
|
|
|
ret = iov_send(s->fd, iov, 2, s->send_index, remaining);
|
|
|
|
|
|
|
|
if (ret == -1 && errno == EAGAIN) {
|
|
|
|
ret = 0; /* handled further down */
|
|
|
|
}
|
|
|
|
if (ret == -1) {
|
|
|
|
s->send_index = 0;
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
if (ret < (ssize_t)remaining) {
|
|
|
|
s->send_index += ret;
|
|
|
|
net_socket_write_poll(s, true);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
s->send_index = 0;
|
|
|
|
return size;
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
|
|
|
|
2012-07-24 17:35:13 +02:00
|
|
|
static ssize_t net_socket_receive_dgram(NetClientState *nc, const uint8_t *buf, size_t size)
|
2009-11-25 19:48:56 +01:00
|
|
|
{
|
2009-11-25 19:49:08 +01:00
|
|
|
NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc);
|
2012-08-20 11:28:53 +02:00
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
do {
|
net/socket: learn to talk with a unix dgram socket
-net socket has a fd argument, and may be passed pre-opened sockets.
TCP sockets use framing.
UDP sockets have datagram boundaries.
When given a unix dgram socket, it will be able to read from it, but
will attempt to send on the dgram_dst, which is unset. The other end
will not receive the data.
Let's teach -net socket to recognize a UNIX DGRAM socket, and use the
regular send() command (without dgram_dst).
This makes running slirp out-of-process possible that
way (python pseudo-code):
a, b = socket.socketpair(socket.AF_UNIX, socket.SOCK_DGRAM)
subprocess.Popen('qemu -net socket,fd=%d -net user' % a.fileno(), shell=True)
subprocess.Popen('qemu ... -net nic -net socket,fd=%d' % b.fileno(), shell=True)
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2019-03-11 18:25:05 +01:00
|
|
|
if (s->dgram_dst.sin_family != AF_UNIX) {
|
|
|
|
ret = qemu_sendto(s->fd, buf, size, 0,
|
|
|
|
(struct sockaddr *)&s->dgram_dst,
|
|
|
|
sizeof(s->dgram_dst));
|
|
|
|
} else {
|
|
|
|
ret = send(s->fd, buf, size, 0);
|
|
|
|
}
|
2012-08-20 11:28:53 +02:00
|
|
|
} while (ret == -1 && errno == EINTR);
|
|
|
|
|
|
|
|
if (ret == -1 && errno == EAGAIN) {
|
|
|
|
net_socket_write_poll(s, true);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ret;
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
|
|
|
|
2015-06-04 08:45:16 +02:00
|
|
|
static void net_socket_send_completed(NetClientState *nc, ssize_t len)
|
|
|
|
{
|
|
|
|
NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc);
|
|
|
|
|
|
|
|
if (!s->read_poll) {
|
|
|
|
net_socket_read_poll(s, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-13 09:35:19 +02:00
|
|
|
static void net_socket_rs_finalize(SocketReadState *rs)
|
|
|
|
{
|
|
|
|
NetSocketState *s = container_of(rs, NetSocketState, rs);
|
|
|
|
|
|
|
|
if (qemu_send_packet_async(&s->nc, rs->buf,
|
|
|
|
rs->packet_len,
|
|
|
|
net_socket_send_completed) == 0) {
|
|
|
|
net_socket_read_poll(s, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-25 19:48:56 +01:00
|
|
|
static void net_socket_send(void *opaque)
|
|
|
|
{
|
|
|
|
NetSocketState *s = opaque;
|
2016-03-07 21:36:03 +01:00
|
|
|
int size;
|
2016-05-13 09:35:19 +02:00
|
|
|
int ret;
|
2013-03-18 19:43:44 +01:00
|
|
|
uint8_t buf1[NET_BUFSIZE];
|
2009-11-25 19:48:56 +01:00
|
|
|
const uint8_t *buf;
|
|
|
|
|
2011-07-23 22:04:29 +02:00
|
|
|
size = qemu_recv(s->fd, buf1, sizeof(buf1), 0);
|
2009-11-25 19:48:56 +01:00
|
|
|
if (size < 0) {
|
2016-03-07 21:36:03 +01:00
|
|
|
if (errno != EWOULDBLOCK)
|
2009-11-25 19:48:56 +01:00
|
|
|
goto eoc;
|
|
|
|
} else if (size == 0) {
|
|
|
|
/* end of connection */
|
|
|
|
eoc:
|
2012-08-20 11:21:54 +02:00
|
|
|
net_socket_read_poll(s, false);
|
|
|
|
net_socket_write_poll(s, false);
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
if (s->listen_fd != -1) {
|
|
|
|
qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s);
|
|
|
|
}
|
2009-11-25 19:48:56 +01:00
|
|
|
closesocket(s->fd);
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
|
|
|
|
s->fd = -1;
|
2017-07-04 08:53:46 +02:00
|
|
|
net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
s->nc.link_down = true;
|
2021-04-02 05:03:33 +02:00
|
|
|
memset(s->nc.info_str, 0, sizeof(s->nc.info_str));
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
|
2009-11-25 19:48:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
buf = buf1;
|
|
|
|
|
2016-05-13 09:35:19 +02:00
|
|
|
ret = net_fill_rstate(&s->rs, buf, size);
|
|
|
|
|
|
|
|
if (ret == -1) {
|
|
|
|
goto eoc;
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void net_socket_send_dgram(void *opaque)
|
|
|
|
{
|
|
|
|
NetSocketState *s = opaque;
|
|
|
|
int size;
|
|
|
|
|
2016-05-13 09:35:19 +02:00
|
|
|
size = qemu_recv(s->fd, s->rs.buf, sizeof(s->rs.buf), 0);
|
2009-11-25 19:48:56 +01:00
|
|
|
if (size < 0)
|
|
|
|
return;
|
|
|
|
if (size == 0) {
|
|
|
|
/* end of connection */
|
2012-08-20 11:21:54 +02:00
|
|
|
net_socket_read_poll(s, false);
|
|
|
|
net_socket_write_poll(s, false);
|
2009-11-25 19:48:56 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-05-13 09:35:19 +02:00
|
|
|
if (qemu_send_packet_async(&s->nc, s->rs.buf, size,
|
2015-06-04 08:45:16 +02:00
|
|
|
net_socket_send_completed) == 0) {
|
|
|
|
net_socket_read_poll(s, false);
|
|
|
|
}
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
|
|
|
|
2017-09-04 16:35:38 +02:00
|
|
|
static int net_socket_mcast_create(struct sockaddr_in *mcastaddr,
|
|
|
|
struct in_addr *localaddr,
|
|
|
|
Error **errp)
|
2009-11-25 19:48:56 +01:00
|
|
|
{
|
|
|
|
struct ip_mreq imr;
|
|
|
|
int fd;
|
|
|
|
int val, ret;
|
Fix forcing multicast msgs to loopback on OpenBSD.
Fix forcing multicast msgs to loopback on OpenBSD.
e.g.
$ sudo qemu -m 128 -no-fd-bootchk \
-hda virtual.img -boot n -nographic \
-net nic,vlan=0,model=rtl8139,macaddr=52:54:00:12:34:03 \
-net user -tftp /usr/src/sys/arch/i386/compile/TEST -bootp pxeboot \
-net nic,vlan=1,model=rtl8139,macaddr=52:54:00:23:03:01 \
-net tap,vlan=1,script=no \
-net nic,vlan=3,model=rtl8139,macaddr=52:54:00:23:03:03 \
-net socket,vlan=3,mcast=230.0.0.1:10003
setsockopt(SOL_IP, IP_MULTICAST_LOOP): Invalid argument
qemu: -net socket,vlan=3,mcast=230.0.0.1:10003: Device 'socket' could not be initialized
Signed-off-by: Brad Smith <brad@comstyle.com>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2011-08-07 13:06:43 +02:00
|
|
|
#ifdef __OpenBSD__
|
|
|
|
unsigned char loop;
|
|
|
|
#else
|
|
|
|
int loop;
|
|
|
|
#endif
|
|
|
|
|
2009-11-25 19:48:56 +01:00
|
|
|
if (!IN_MULTICAST(ntohl(mcastaddr->sin_addr.s_addr))) {
|
2017-09-04 16:35:38 +02:00
|
|
|
error_setg(errp, "specified mcastaddr %s (0x%08x) "
|
|
|
|
"does not contain a multicast address",
|
|
|
|
inet_ntoa(mcastaddr->sin_addr),
|
|
|
|
(int)ntohl(mcastaddr->sin_addr.s_addr));
|
2011-12-07 16:01:48 +01:00
|
|
|
return -1;
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
2017-09-04 16:35:38 +02:00
|
|
|
|
2009-12-02 12:24:42 +01:00
|
|
|
fd = qemu_socket(PF_INET, SOCK_DGRAM, 0);
|
2009-11-25 19:48:56 +01:00
|
|
|
if (fd < 0) {
|
2017-09-04 16:35:38 +02:00
|
|
|
error_setg_errno(errp, errno, "can't create datagram socket");
|
2009-11-25 19:48:56 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-02 12:23:14 +02:00
|
|
|
/* Allow multiple sockets to bind the same multicast ip and port by setting
|
|
|
|
* SO_REUSEADDR. This is the only situation where SO_REUSEADDR should be set
|
|
|
|
* on windows. Use socket_set_fast_reuse otherwise as it sets SO_REUSEADDR
|
|
|
|
* only on posix systems.
|
|
|
|
*/
|
2009-11-25 19:48:56 +01:00
|
|
|
val = 1;
|
2013-03-08 19:58:32 +01:00
|
|
|
ret = qemu_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
|
2009-11-25 19:48:56 +01:00
|
|
|
if (ret < 0) {
|
2017-09-04 16:35:38 +02:00
|
|
|
error_setg_errno(errp, errno,
|
|
|
|
"can't set socket option SO_REUSEADDR");
|
2011-12-07 16:01:48 +01:00
|
|
|
goto fail;
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = bind(fd, (struct sockaddr *)mcastaddr, sizeof(*mcastaddr));
|
|
|
|
if (ret < 0) {
|
2017-09-04 16:35:38 +02:00
|
|
|
error_setg_errno(errp, errno, "can't bind ip=%s to socket",
|
|
|
|
inet_ntoa(mcastaddr->sin_addr));
|
2009-11-25 19:48:56 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add host to multicast group */
|
|
|
|
imr.imr_multiaddr = mcastaddr->sin_addr;
|
2010-12-01 20:16:47 +01:00
|
|
|
if (localaddr) {
|
|
|
|
imr.imr_interface = *localaddr;
|
|
|
|
} else {
|
|
|
|
imr.imr_interface.s_addr = htonl(INADDR_ANY);
|
|
|
|
}
|
2009-11-25 19:48:56 +01:00
|
|
|
|
2013-03-08 19:58:32 +01:00
|
|
|
ret = qemu_setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
|
|
|
&imr, sizeof(struct ip_mreq));
|
2009-11-25 19:48:56 +01:00
|
|
|
if (ret < 0) {
|
2017-09-04 16:35:38 +02:00
|
|
|
error_setg_errno(errp, errno,
|
|
|
|
"can't add socket to multicast group %s",
|
|
|
|
inet_ntoa(imr.imr_multiaddr));
|
2011-12-07 16:01:48 +01:00
|
|
|
goto fail;
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Force mcast msgs to loopback (eg. several QEMUs in same host */
|
Fix forcing multicast msgs to loopback on OpenBSD.
Fix forcing multicast msgs to loopback on OpenBSD.
e.g.
$ sudo qemu -m 128 -no-fd-bootchk \
-hda virtual.img -boot n -nographic \
-net nic,vlan=0,model=rtl8139,macaddr=52:54:00:12:34:03 \
-net user -tftp /usr/src/sys/arch/i386/compile/TEST -bootp pxeboot \
-net nic,vlan=1,model=rtl8139,macaddr=52:54:00:23:03:01 \
-net tap,vlan=1,script=no \
-net nic,vlan=3,model=rtl8139,macaddr=52:54:00:23:03:03 \
-net socket,vlan=3,mcast=230.0.0.1:10003
setsockopt(SOL_IP, IP_MULTICAST_LOOP): Invalid argument
qemu: -net socket,vlan=3,mcast=230.0.0.1:10003: Device 'socket' could not be initialized
Signed-off-by: Brad Smith <brad@comstyle.com>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2011-08-07 13:06:43 +02:00
|
|
|
loop = 1;
|
2013-03-08 19:58:32 +01:00
|
|
|
ret = qemu_setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP,
|
|
|
|
&loop, sizeof(loop));
|
2009-11-25 19:48:56 +01:00
|
|
|
if (ret < 0) {
|
2017-09-04 16:35:38 +02:00
|
|
|
error_setg_errno(errp, errno,
|
|
|
|
"can't force multicast message to loopback");
|
2011-12-07 16:01:48 +01:00
|
|
|
goto fail;
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
|
|
|
|
2010-12-01 20:16:47 +01:00
|
|
|
/* If a bind address is given, only send packets from that address */
|
|
|
|
if (localaddr != NULL) {
|
2013-03-08 19:58:32 +01:00
|
|
|
ret = qemu_setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF,
|
|
|
|
localaddr, sizeof(*localaddr));
|
2010-12-01 20:16:47 +01:00
|
|
|
if (ret < 0) {
|
2017-09-04 16:35:38 +02:00
|
|
|
error_setg_errno(errp, errno,
|
|
|
|
"can't set the default network send interface");
|
2010-12-01 20:16:47 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-27 10:10:43 +01:00
|
|
|
qemu_set_nonblock(fd);
|
2009-11-25 19:48:56 +01:00
|
|
|
return fd;
|
|
|
|
fail:
|
|
|
|
if (fd >= 0)
|
|
|
|
closesocket(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-07-24 17:35:13 +02:00
|
|
|
static void net_socket_cleanup(NetClientState *nc)
|
2009-11-25 19:48:56 +01:00
|
|
|
{
|
2009-11-25 19:49:08 +01:00
|
|
|
NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc);
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
if (s->fd != -1) {
|
2012-08-20 11:21:54 +02:00
|
|
|
net_socket_read_poll(s, false);
|
|
|
|
net_socket_write_poll(s, false);
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
close(s->fd);
|
|
|
|
s->fd = -1;
|
|
|
|
}
|
|
|
|
if (s->listen_fd != -1) {
|
|
|
|
qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL);
|
|
|
|
closesocket(s->listen_fd);
|
|
|
|
s->listen_fd = -1;
|
|
|
|
}
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
|
|
|
|
2009-11-25 19:49:08 +01:00
|
|
|
static NetClientInfo net_dgram_socket_info = {
|
qapi: Change Netdev into a flat union
This is a mostly-mechanical conversion that creates a new flat
union 'Netdev' QAPI type that covers all the branches of the
former 'NetClientOptions' simple union, where the branches are
now listed in a new 'NetClientDriver' enum rather than generated
from the simple union. The existence of a flat union has no
change to the command line syntax accepted for new code, and
will make it possible for a future patch to switch the QMP
command to parse a boxed union for no change to valid QMP; but
it does have some ripple effect on the C code when dealing with
the new types.
While making the conversion, note that the 'NetLegacy' type
remains unchanged: it applies only to legacy command line options,
and will not be ported to QMP, so it should remain a wrapper
around a simple union; to avoid confusion, the type named
'NetClientOptions' is now gone, and we introduce 'NetLegacyOptions'
in its place. Then, in the C code, we convert from NetLegacy to
Netdev as soon as possible, so that the bulk of the net stack
only has to deal with one QAPI type, not two. Note that since
the old legacy code always rejected 'hubport', we can just omit
that branch from the new 'NetLegacyOptions' simple union.
Based on an idea originally by Zoltán Kővágó <DirtY.iCE.hu@gmail.com>:
Message-Id: <01a527fbf1a5de880091f98cf011616a78adeeee.1441627176.git.DirtY.iCE.hu@gmail.com>
although the sed script in that patch no longer applies due to
other changes in the tree since then, and I also did some manual
cleanups (such as fixing whitespace to keep checkpatch happy).
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1468468228-27827-13-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Fixup from Eric squashed in]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-07-14 05:50:23 +02:00
|
|
|
.type = NET_CLIENT_DRIVER_SOCKET,
|
2009-11-25 19:49:08 +01:00
|
|
|
.size = sizeof(NetSocketState),
|
|
|
|
.receive = net_socket_receive_dgram,
|
|
|
|
.cleanup = net_socket_cleanup,
|
|
|
|
};
|
|
|
|
|
2012-07-24 17:35:13 +02:00
|
|
|
static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer,
|
2009-11-25 19:48:56 +01:00
|
|
|
const char *model,
|
|
|
|
const char *name,
|
2017-08-08 22:38:57 +02:00
|
|
|
int fd, int is_connected,
|
2017-09-04 16:35:38 +02:00
|
|
|
const char *mcast,
|
|
|
|
Error **errp)
|
2009-11-25 19:48:56 +01:00
|
|
|
{
|
|
|
|
struct sockaddr_in saddr;
|
|
|
|
int newfd;
|
2012-07-24 17:35:13 +02:00
|
|
|
NetClientState *nc;
|
2009-11-25 19:48:56 +01:00
|
|
|
NetSocketState *s;
|
net/socket: learn to talk with a unix dgram socket
-net socket has a fd argument, and may be passed pre-opened sockets.
TCP sockets use framing.
UDP sockets have datagram boundaries.
When given a unix dgram socket, it will be able to read from it, but
will attempt to send on the dgram_dst, which is unset. The other end
will not receive the data.
Let's teach -net socket to recognize a UNIX DGRAM socket, and use the
regular send() command (without dgram_dst).
This makes running slirp out-of-process possible that
way (python pseudo-code):
a, b = socket.socketpair(socket.AF_UNIX, socket.SOCK_DGRAM)
subprocess.Popen('qemu -net socket,fd=%d -net user' % a.fileno(), shell=True)
subprocess.Popen('qemu ... -net nic -net socket,fd=%d' % b.fileno(), shell=True)
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2019-03-11 18:25:05 +01:00
|
|
|
SocketAddress *sa;
|
|
|
|
SocketAddressType sa_type;
|
|
|
|
|
|
|
|
sa = socket_local_address(fd, errp);
|
|
|
|
if (!sa) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
sa_type = sa->type;
|
|
|
|
qapi_free_SocketAddress(sa);
|
2009-11-25 19:48:56 +01:00
|
|
|
|
|
|
|
/* fd passed: multicast: "learn" dgram_dst address from bound address and save it
|
|
|
|
* Because this may be "shared" socket from a "master" process, datagrams would be recv()
|
|
|
|
* by ONLY ONE process: we must "clone" this dgram socket --jjo
|
|
|
|
*/
|
|
|
|
|
2017-08-08 22:38:57 +02:00
|
|
|
if (is_connected && mcast != NULL) {
|
2017-09-04 16:35:39 +02:00
|
|
|
if (parse_host_port(&saddr, mcast, errp) < 0) {
|
2017-08-08 22:38:57 +02:00
|
|
|
goto err;
|
|
|
|
}
|
2011-12-07 16:01:48 +01:00
|
|
|
/* must be bound */
|
|
|
|
if (saddr.sin_addr.s_addr == 0) {
|
2017-09-04 16:35:38 +02:00
|
|
|
error_setg(errp, "can't setup multicast destination address");
|
2011-12-07 16:01:49 +01:00
|
|
|
goto err;
|
2011-12-07 16:01:48 +01:00
|
|
|
}
|
|
|
|
/* clone dgram socket */
|
2017-09-04 16:35:38 +02:00
|
|
|
newfd = net_socket_mcast_create(&saddr, NULL, errp);
|
2011-12-07 16:01:48 +01:00
|
|
|
if (newfd < 0) {
|
2011-12-07 16:01:49 +01:00
|
|
|
goto err;
|
2011-12-07 16:01:48 +01:00
|
|
|
}
|
|
|
|
/* clone newfd to fd, close newfd */
|
|
|
|
dup2(newfd, fd);
|
|
|
|
close(newfd);
|
|
|
|
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
|
|
|
|
2012-07-24 17:35:08 +02:00
|
|
|
nc = qemu_new_net_client(&net_dgram_socket_info, peer, model, name);
|
2009-11-25 19:49:08 +01:00
|
|
|
|
|
|
|
s = DO_UPCAST(NetSocketState, nc, nc);
|
|
|
|
|
2009-11-25 19:48:56 +01:00
|
|
|
s->fd = fd;
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
s->listen_fd = -1;
|
2012-08-20 11:21:54 +02:00
|
|
|
s->send_fn = net_socket_send_dgram;
|
2017-07-04 08:53:46 +02:00
|
|
|
net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
|
2012-08-20 11:21:54 +02:00
|
|
|
net_socket_read_poll(s, true);
|
2009-11-25 19:48:56 +01:00
|
|
|
|
|
|
|
/* mcast: save bound address as dst */
|
2017-11-06 15:05:46 +01:00
|
|
|
if (is_connected && mcast != NULL) {
|
2012-07-20 15:25:52 +02:00
|
|
|
s->dgram_dst = saddr;
|
2021-04-02 05:03:33 +02:00
|
|
|
snprintf(nc->info_str, sizeof(nc->info_str),
|
|
|
|
"socket: fd=%d (cloned mcast=%s:%d)",
|
|
|
|
fd, inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
|
2014-11-20 12:35:01 +01:00
|
|
|
} else {
|
net/socket: learn to talk with a unix dgram socket
-net socket has a fd argument, and may be passed pre-opened sockets.
TCP sockets use framing.
UDP sockets have datagram boundaries.
When given a unix dgram socket, it will be able to read from it, but
will attempt to send on the dgram_dst, which is unset. The other end
will not receive the data.
Let's teach -net socket to recognize a UNIX DGRAM socket, and use the
regular send() command (without dgram_dst).
This makes running slirp out-of-process possible that
way (python pseudo-code):
a, b = socket.socketpair(socket.AF_UNIX, socket.SOCK_DGRAM)
subprocess.Popen('qemu -net socket,fd=%d -net user' % a.fileno(), shell=True)
subprocess.Popen('qemu ... -net nic -net socket,fd=%d' % b.fileno(), shell=True)
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2019-03-11 18:25:05 +01:00
|
|
|
if (sa_type == SOCKET_ADDRESS_TYPE_UNIX) {
|
|
|
|
s->dgram_dst.sin_family = AF_UNIX;
|
|
|
|
}
|
2021-04-02 05:03:12 +02:00
|
|
|
|
2021-04-02 05:03:33 +02:00
|
|
|
snprintf(nc->info_str, sizeof(nc->info_str),
|
|
|
|
"socket: fd=%d %s", fd, SocketAddressType_str(sa_type));
|
2012-07-20 15:25:52 +02:00
|
|
|
}
|
2009-11-25 19:48:56 +01:00
|
|
|
|
|
|
|
return s;
|
2011-12-07 16:01:49 +01:00
|
|
|
|
|
|
|
err:
|
|
|
|
closesocket(fd);
|
|
|
|
return NULL;
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void net_socket_connect(void *opaque)
|
|
|
|
{
|
|
|
|
NetSocketState *s = opaque;
|
2012-08-20 11:21:54 +02:00
|
|
|
s->send_fn = net_socket_send;
|
|
|
|
net_socket_read_poll(s, true);
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
|
|
|
|
2009-11-25 19:49:08 +01:00
|
|
|
static NetClientInfo net_socket_info = {
|
qapi: Change Netdev into a flat union
This is a mostly-mechanical conversion that creates a new flat
union 'Netdev' QAPI type that covers all the branches of the
former 'NetClientOptions' simple union, where the branches are
now listed in a new 'NetClientDriver' enum rather than generated
from the simple union. The existence of a flat union has no
change to the command line syntax accepted for new code, and
will make it possible for a future patch to switch the QMP
command to parse a boxed union for no change to valid QMP; but
it does have some ripple effect on the C code when dealing with
the new types.
While making the conversion, note that the 'NetLegacy' type
remains unchanged: it applies only to legacy command line options,
and will not be ported to QMP, so it should remain a wrapper
around a simple union; to avoid confusion, the type named
'NetClientOptions' is now gone, and we introduce 'NetLegacyOptions'
in its place. Then, in the C code, we convert from NetLegacy to
Netdev as soon as possible, so that the bulk of the net stack
only has to deal with one QAPI type, not two. Note that since
the old legacy code always rejected 'hubport', we can just omit
that branch from the new 'NetLegacyOptions' simple union.
Based on an idea originally by Zoltán Kővágó <DirtY.iCE.hu@gmail.com>:
Message-Id: <01a527fbf1a5de880091f98cf011616a78adeeee.1441627176.git.DirtY.iCE.hu@gmail.com>
although the sed script in that patch no longer applies due to
other changes in the tree since then, and I also did some manual
cleanups (such as fixing whitespace to keep checkpatch happy).
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1468468228-27827-13-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Fixup from Eric squashed in]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-07-14 05:50:23 +02:00
|
|
|
.type = NET_CLIENT_DRIVER_SOCKET,
|
2009-11-25 19:49:08 +01:00
|
|
|
.size = sizeof(NetSocketState),
|
|
|
|
.receive = net_socket_receive,
|
|
|
|
.cleanup = net_socket_cleanup,
|
|
|
|
};
|
|
|
|
|
2012-07-24 17:35:13 +02:00
|
|
|
static NetSocketState *net_socket_fd_init_stream(NetClientState *peer,
|
2009-11-25 19:48:56 +01:00
|
|
|
const char *model,
|
|
|
|
const char *name,
|
|
|
|
int fd, int is_connected)
|
|
|
|
{
|
2012-07-24 17:35:13 +02:00
|
|
|
NetClientState *nc;
|
2009-11-25 19:48:56 +01:00
|
|
|
NetSocketState *s;
|
2009-11-25 19:49:08 +01:00
|
|
|
|
2012-07-24 17:35:08 +02:00
|
|
|
nc = qemu_new_net_client(&net_socket_info, peer, model, name);
|
2009-11-25 19:49:08 +01:00
|
|
|
|
2021-04-02 05:03:33 +02:00
|
|
|
snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d", fd);
|
2021-04-02 05:03:12 +02:00
|
|
|
|
2009-11-25 19:49:08 +01:00
|
|
|
s = DO_UPCAST(NetSocketState, nc, nc);
|
|
|
|
|
2009-11-25 19:48:56 +01:00
|
|
|
s->fd = fd;
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
s->listen_fd = -1;
|
2017-07-04 08:53:46 +02:00
|
|
|
net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
|
2009-11-25 19:49:08 +01:00
|
|
|
|
2013-02-27 15:05:47 +01:00
|
|
|
/* Disable Nagle algorithm on TCP sockets to reduce latency */
|
|
|
|
socket_set_nodelay(fd);
|
|
|
|
|
2009-11-25 19:48:56 +01:00
|
|
|
if (is_connected) {
|
|
|
|
net_socket_connect(s);
|
|
|
|
} else {
|
|
|
|
qemu_set_fd_handler(s->fd, NULL, net_socket_connect, s);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2012-07-24 17:35:13 +02:00
|
|
|
static NetSocketState *net_socket_fd_init(NetClientState *peer,
|
2009-11-25 19:48:56 +01:00
|
|
|
const char *model, const char *name,
|
2017-09-04 16:35:38 +02:00
|
|
|
int fd, int is_connected,
|
|
|
|
const char *mc, Error **errp)
|
2009-11-25 19:48:56 +01:00
|
|
|
{
|
|
|
|
int so_type = -1, optlen=sizeof(so_type);
|
|
|
|
|
|
|
|
if(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&so_type,
|
|
|
|
(socklen_t *)&optlen)< 0) {
|
2017-09-04 16:35:38 +02:00
|
|
|
error_setg(errp, "can't get socket option SO_TYPE");
|
2011-12-07 16:01:49 +01:00
|
|
|
closesocket(fd);
|
2011-12-07 16:01:48 +01:00
|
|
|
return NULL;
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
|
|
|
switch(so_type) {
|
|
|
|
case SOCK_DGRAM:
|
2017-09-04 16:35:38 +02:00
|
|
|
return net_socket_fd_init_dgram(peer, model, name, fd, is_connected,
|
|
|
|
mc, errp);
|
2009-11-25 19:48:56 +01:00
|
|
|
case SOCK_STREAM:
|
2012-07-24 17:35:05 +02:00
|
|
|
return net_socket_fd_init_stream(peer, model, name, fd, is_connected);
|
2009-11-25 19:48:56 +01:00
|
|
|
default:
|
2018-10-17 10:26:38 +02:00
|
|
|
error_setg(errp, "socket type=%d for fd=%d must be either"
|
|
|
|
" SOCK_DGRAM or SOCK_STREAM", so_type, fd);
|
2017-09-04 16:35:37 +02:00
|
|
|
closesocket(fd);
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void net_socket_accept(void *opaque)
|
|
|
|
{
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
NetSocketState *s = opaque;
|
2009-11-25 19:48:56 +01:00
|
|
|
struct sockaddr_in saddr;
|
|
|
|
socklen_t len;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
len = sizeof(saddr);
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
fd = qemu_accept(s->listen_fd, (struct sockaddr *)&saddr, &len);
|
2009-11-25 19:48:56 +01:00
|
|
|
if (fd < 0 && errno != EINTR) {
|
|
|
|
return;
|
|
|
|
} else if (fd >= 0) {
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL);
|
2009-11-25 19:48:56 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
|
|
|
|
s->fd = fd;
|
|
|
|
s->nc.link_down = false;
|
|
|
|
net_socket_connect(s);
|
2021-04-02 05:03:33 +02:00
|
|
|
snprintf(s->nc.info_str, sizeof(s->nc.info_str),
|
|
|
|
"socket: connection from %s:%d",
|
|
|
|
inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
|
|
|
|
2012-07-24 17:35:13 +02:00
|
|
|
static int net_socket_listen_init(NetClientState *peer,
|
2009-11-25 19:48:56 +01:00
|
|
|
const char *model,
|
|
|
|
const char *name,
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
const char *host_str,
|
|
|
|
Error **errp)
|
2009-11-25 19:48:56 +01:00
|
|
|
{
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
NetClientState *nc;
|
|
|
|
NetSocketState *s;
|
Revert "Change net/socket.c to use socket_*() functions" again
This reverts commit 883e4f7624e10b98d16d9adaffb8b1795664d899.
This code changed net/socket.c from using socket()+connect(),
to using socket_connect(). In theory this is great, but in
practice this has completely broken the ability to connect
the frontend and backend:
$ ./x86_64-softmmu/qemu-system-x86_64 \
-device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
-netdev socket,id=hn0,connect=localhost:1234
qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
The old code would call net_socket_fd_init() synchronously,
while letting the connect() complete in the backgorund. The
new code moved net_socket_fd_init() so that it is only called
after connect() completes in the background.
Thus at the time we initialize the NIC frontend, the backend
does not exist.
The socket_connect() conversion as done is a bad fit for the
current code, since it did not try to change the way it deals
with async connection completion. Rather than try to fix this,
just revert the socket_connect() conversion entirely.
The code is about to be converted to use QIOChannel which
will let the problem be solved in a cleaner manner. This
revert is more suitable for stable branches in the meantime.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-05-05 18:23:05 +02:00
|
|
|
struct sockaddr_in saddr;
|
|
|
|
int fd, ret;
|
2009-11-25 19:48:56 +01:00
|
|
|
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
if (parse_host_port(&saddr, host_str, errp) < 0) {
|
Revert "Change net/socket.c to use socket_*() functions" again
This reverts commit 883e4f7624e10b98d16d9adaffb8b1795664d899.
This code changed net/socket.c from using socket()+connect(),
to using socket_connect(). In theory this is great, but in
practice this has completely broken the ability to connect
the frontend and backend:
$ ./x86_64-softmmu/qemu-system-x86_64 \
-device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
-netdev socket,id=hn0,connect=localhost:1234
qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
The old code would call net_socket_fd_init() synchronously,
while letting the connect() complete in the backgorund. The
new code moved net_socket_fd_init() so that it is only called
after connect() completes in the background.
Thus at the time we initialize the NIC frontend, the backend
does not exist.
The socket_connect() conversion as done is a bad fit for the
current code, since it did not try to change the way it deals
with async connection completion. Rather than try to fix this,
just revert the socket_connect() conversion entirely.
The code is about to be converted to use QIOChannel which
will let the problem be solved in a cleaner manner. This
revert is more suitable for stable branches in the meantime.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-05-05 18:23:05 +02:00
|
|
|
return -1;
|
2017-09-04 16:35:39 +02:00
|
|
|
}
|
Revert "Change net/socket.c to use socket_*() functions" again
This reverts commit 883e4f7624e10b98d16d9adaffb8b1795664d899.
This code changed net/socket.c from using socket()+connect(),
to using socket_connect(). In theory this is great, but in
practice this has completely broken the ability to connect
the frontend and backend:
$ ./x86_64-softmmu/qemu-system-x86_64 \
-device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
-netdev socket,id=hn0,connect=localhost:1234
qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
The old code would call net_socket_fd_init() synchronously,
while letting the connect() complete in the backgorund. The
new code moved net_socket_fd_init() so that it is only called
after connect() completes in the background.
Thus at the time we initialize the NIC frontend, the backend
does not exist.
The socket_connect() conversion as done is a bad fit for the
current code, since it did not try to change the way it deals
with async connection completion. Rather than try to fix this,
just revert the socket_connect() conversion entirely.
The code is about to be converted to use QIOChannel which
will let the problem be solved in a cleaner manner. This
revert is more suitable for stable branches in the meantime.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-05-05 18:23:05 +02:00
|
|
|
|
|
|
|
fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
|
|
|
|
if (fd < 0) {
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
error_setg_errno(errp, errno, "can't create stream socket");
|
2009-11-25 19:48:56 +01:00
|
|
|
return -1;
|
|
|
|
}
|
Revert "Change net/socket.c to use socket_*() functions" again
This reverts commit 883e4f7624e10b98d16d9adaffb8b1795664d899.
This code changed net/socket.c from using socket()+connect(),
to using socket_connect(). In theory this is great, but in
practice this has completely broken the ability to connect
the frontend and backend:
$ ./x86_64-softmmu/qemu-system-x86_64 \
-device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
-netdev socket,id=hn0,connect=localhost:1234
qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
The old code would call net_socket_fd_init() synchronously,
while letting the connect() complete in the backgorund. The
new code moved net_socket_fd_init() so that it is only called
after connect() completes in the background.
Thus at the time we initialize the NIC frontend, the backend
does not exist.
The socket_connect() conversion as done is a bad fit for the
current code, since it did not try to change the way it deals
with async connection completion. Rather than try to fix this,
just revert the socket_connect() conversion entirely.
The code is about to be converted to use QIOChannel which
will let the problem be solved in a cleaner manner. This
revert is more suitable for stable branches in the meantime.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-05-05 18:23:05 +02:00
|
|
|
qemu_set_nonblock(fd);
|
|
|
|
|
|
|
|
socket_set_fast_reuse(fd);
|
2009-11-25 19:48:56 +01:00
|
|
|
|
Revert "Change net/socket.c to use socket_*() functions" again
This reverts commit 883e4f7624e10b98d16d9adaffb8b1795664d899.
This code changed net/socket.c from using socket()+connect(),
to using socket_connect(). In theory this is great, but in
practice this has completely broken the ability to connect
the frontend and backend:
$ ./x86_64-softmmu/qemu-system-x86_64 \
-device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
-netdev socket,id=hn0,connect=localhost:1234
qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
The old code would call net_socket_fd_init() synchronously,
while letting the connect() complete in the backgorund. The
new code moved net_socket_fd_init() so that it is only called
after connect() completes in the background.
Thus at the time we initialize the NIC frontend, the backend
does not exist.
The socket_connect() conversion as done is a bad fit for the
current code, since it did not try to change the way it deals
with async connection completion. Rather than try to fix this,
just revert the socket_connect() conversion entirely.
The code is about to be converted to use QIOChannel which
will let the problem be solved in a cleaner manner. This
revert is more suitable for stable branches in the meantime.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-05-05 18:23:05 +02:00
|
|
|
ret = bind(fd, (struct sockaddr *)&saddr, sizeof(saddr));
|
2016-08-30 14:04:12 +02:00
|
|
|
if (ret < 0) {
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
error_setg_errno(errp, errno, "can't bind ip=%s to socket",
|
|
|
|
inet_ntoa(saddr.sin_addr));
|
Revert "Change net/socket.c to use socket_*() functions" again
This reverts commit 883e4f7624e10b98d16d9adaffb8b1795664d899.
This code changed net/socket.c from using socket()+connect(),
to using socket_connect(). In theory this is great, but in
practice this has completely broken the ability to connect
the frontend and backend:
$ ./x86_64-softmmu/qemu-system-x86_64 \
-device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
-netdev socket,id=hn0,connect=localhost:1234
qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
The old code would call net_socket_fd_init() synchronously,
while letting the connect() complete in the backgorund. The
new code moved net_socket_fd_init() so that it is only called
after connect() completes in the background.
Thus at the time we initialize the NIC frontend, the backend
does not exist.
The socket_connect() conversion as done is a bad fit for the
current code, since it did not try to change the way it deals
with async connection completion. Rather than try to fix this,
just revert the socket_connect() conversion entirely.
The code is about to be converted to use QIOChannel which
will let the problem be solved in a cleaner manner. This
revert is more suitable for stable branches in the meantime.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-05-05 18:23:05 +02:00
|
|
|
closesocket(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ret = listen(fd, 0);
|
|
|
|
if (ret < 0) {
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
error_setg_errno(errp, errno, "can't listen on socket");
|
Revert "Change net/socket.c to use socket_*() functions" again
This reverts commit 883e4f7624e10b98d16d9adaffb8b1795664d899.
This code changed net/socket.c from using socket()+connect(),
to using socket_connect(). In theory this is great, but in
practice this has completely broken the ability to connect
the frontend and backend:
$ ./x86_64-softmmu/qemu-system-x86_64 \
-device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
-netdev socket,id=hn0,connect=localhost:1234
qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
The old code would call net_socket_fd_init() synchronously,
while letting the connect() complete in the backgorund. The
new code moved net_socket_fd_init() so that it is only called
after connect() completes in the background.
Thus at the time we initialize the NIC frontend, the backend
does not exist.
The socket_connect() conversion as done is a bad fit for the
current code, since it did not try to change the way it deals
with async connection completion. Rather than try to fix this,
just revert the socket_connect() conversion entirely.
The code is about to be converted to use QIOChannel which
will let the problem be solved in a cleaner manner. This
revert is more suitable for stable branches in the meantime.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-05-05 18:23:05 +02:00
|
|
|
closesocket(fd);
|
2009-11-25 19:48:56 +01:00
|
|
|
return -1;
|
|
|
|
}
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
|
|
|
|
nc = qemu_new_net_client(&net_socket_info, peer, model, name);
|
|
|
|
s = DO_UPCAST(NetSocketState, nc, nc);
|
|
|
|
s->fd = -1;
|
Revert "Change net/socket.c to use socket_*() functions" again
This reverts commit 883e4f7624e10b98d16d9adaffb8b1795664d899.
This code changed net/socket.c from using socket()+connect(),
to using socket_connect(). In theory this is great, but in
practice this has completely broken the ability to connect
the frontend and backend:
$ ./x86_64-softmmu/qemu-system-x86_64 \
-device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
-netdev socket,id=hn0,connect=localhost:1234
qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
The old code would call net_socket_fd_init() synchronously,
while letting the connect() complete in the backgorund. The
new code moved net_socket_fd_init() so that it is only called
after connect() completes in the background.
Thus at the time we initialize the NIC frontend, the backend
does not exist.
The socket_connect() conversion as done is a bad fit for the
current code, since it did not try to change the way it deals
with async connection completion. Rather than try to fix this,
just revert the socket_connect() conversion entirely.
The code is about to be converted to use QIOChannel which
will let the problem be solved in a cleaner manner. This
revert is more suitable for stable branches in the meantime.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-05-05 18:23:05 +02:00
|
|
|
s->listen_fd = fd;
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
s->nc.link_down = true;
|
2017-07-04 08:53:46 +02:00
|
|
|
net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
|
net: add the support for -netdev socket, listen
The -net socket,listen option does not work with the newer -netdev
syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets,
the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0
3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Drop the NetSocketListenState struct and add a listen_fd field
to NetSocketState. When a -netdev socket,listen= instance is created
there will be a NetSocketState with fd=-1 and a valid listen_fd. The
net_socket_accept() handler waits for listen_fd to become readable and
then accepts the connection. When this state transition happens, we no
longer monitor listen_fd for incoming connections...until the client
disconnects again.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-07-20 15:25:53 +02:00
|
|
|
|
|
|
|
qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s);
|
2009-11-25 19:48:56 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-24 17:35:13 +02:00
|
|
|
static int net_socket_connect_init(NetClientState *peer,
|
2009-11-25 19:48:56 +01:00
|
|
|
const char *model,
|
|
|
|
const char *name,
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
const char *host_str,
|
|
|
|
Error **errp)
|
2009-11-25 19:48:56 +01:00
|
|
|
{
|
Revert "Change net/socket.c to use socket_*() functions" again
This reverts commit 883e4f7624e10b98d16d9adaffb8b1795664d899.
This code changed net/socket.c from using socket()+connect(),
to using socket_connect(). In theory this is great, but in
practice this has completely broken the ability to connect
the frontend and backend:
$ ./x86_64-softmmu/qemu-system-x86_64 \
-device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
-netdev socket,id=hn0,connect=localhost:1234
qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
The old code would call net_socket_fd_init() synchronously,
while letting the connect() complete in the backgorund. The
new code moved net_socket_fd_init() so that it is only called
after connect() completes in the background.
Thus at the time we initialize the NIC frontend, the backend
does not exist.
The socket_connect() conversion as done is a bad fit for the
current code, since it did not try to change the way it deals
with async connection completion. Rather than try to fix this,
just revert the socket_connect() conversion entirely.
The code is about to be converted to use QIOChannel which
will let the problem be solved in a cleaner manner. This
revert is more suitable for stable branches in the meantime.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-05-05 18:23:05 +02:00
|
|
|
NetSocketState *s;
|
|
|
|
int fd, connected, ret;
|
|
|
|
struct sockaddr_in saddr;
|
|
|
|
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
if (parse_host_port(&saddr, host_str, errp) < 0) {
|
Revert "Change net/socket.c to use socket_*() functions" again
This reverts commit 883e4f7624e10b98d16d9adaffb8b1795664d899.
This code changed net/socket.c from using socket()+connect(),
to using socket_connect(). In theory this is great, but in
practice this has completely broken the ability to connect
the frontend and backend:
$ ./x86_64-softmmu/qemu-system-x86_64 \
-device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
-netdev socket,id=hn0,connect=localhost:1234
qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
The old code would call net_socket_fd_init() synchronously,
while letting the connect() complete in the backgorund. The
new code moved net_socket_fd_init() so that it is only called
after connect() completes in the background.
Thus at the time we initialize the NIC frontend, the backend
does not exist.
The socket_connect() conversion as done is a bad fit for the
current code, since it did not try to change the way it deals
with async connection completion. Rather than try to fix this,
just revert the socket_connect() conversion entirely.
The code is about to be converted to use QIOChannel which
will let the problem be solved in a cleaner manner. This
revert is more suitable for stable branches in the meantime.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-05-05 18:23:05 +02:00
|
|
|
return -1;
|
2017-09-04 16:35:39 +02:00
|
|
|
}
|
2009-11-25 19:48:56 +01:00
|
|
|
|
Revert "Change net/socket.c to use socket_*() functions" again
This reverts commit 883e4f7624e10b98d16d9adaffb8b1795664d899.
This code changed net/socket.c from using socket()+connect(),
to using socket_connect(). In theory this is great, but in
practice this has completely broken the ability to connect
the frontend and backend:
$ ./x86_64-softmmu/qemu-system-x86_64 \
-device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
-netdev socket,id=hn0,connect=localhost:1234
qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
The old code would call net_socket_fd_init() synchronously,
while letting the connect() complete in the backgorund. The
new code moved net_socket_fd_init() so that it is only called
after connect() completes in the background.
Thus at the time we initialize the NIC frontend, the backend
does not exist.
The socket_connect() conversion as done is a bad fit for the
current code, since it did not try to change the way it deals
with async connection completion. Rather than try to fix this,
just revert the socket_connect() conversion entirely.
The code is about to be converted to use QIOChannel which
will let the problem be solved in a cleaner manner. This
revert is more suitable for stable branches in the meantime.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-05-05 18:23:05 +02:00
|
|
|
fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
|
2009-11-25 19:48:56 +01:00
|
|
|
if (fd < 0) {
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
error_setg_errno(errp, errno, "can't create stream socket");
|
Revert "Change net/socket.c to use socket_*() functions" again
This reverts commit 883e4f7624e10b98d16d9adaffb8b1795664d899.
This code changed net/socket.c from using socket()+connect(),
to using socket_connect(). In theory this is great, but in
practice this has completely broken the ability to connect
the frontend and backend:
$ ./x86_64-softmmu/qemu-system-x86_64 \
-device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
-netdev socket,id=hn0,connect=localhost:1234
qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
The old code would call net_socket_fd_init() synchronously,
while letting the connect() complete in the backgorund. The
new code moved net_socket_fd_init() so that it is only called
after connect() completes in the background.
Thus at the time we initialize the NIC frontend, the backend
does not exist.
The socket_connect() conversion as done is a bad fit for the
current code, since it did not try to change the way it deals
with async connection completion. Rather than try to fix this,
just revert the socket_connect() conversion entirely.
The code is about to be converted to use QIOChannel which
will let the problem be solved in a cleaner manner. This
revert is more suitable for stable branches in the meantime.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-05-05 18:23:05 +02:00
|
|
|
return -1;
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
Revert "Change net/socket.c to use socket_*() functions" again
This reverts commit 883e4f7624e10b98d16d9adaffb8b1795664d899.
This code changed net/socket.c from using socket()+connect(),
to using socket_connect(). In theory this is great, but in
practice this has completely broken the ability to connect
the frontend and backend:
$ ./x86_64-softmmu/qemu-system-x86_64 \
-device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
-netdev socket,id=hn0,connect=localhost:1234
qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
The old code would call net_socket_fd_init() synchronously,
while letting the connect() complete in the backgorund. The
new code moved net_socket_fd_init() so that it is only called
after connect() completes in the background.
Thus at the time we initialize the NIC frontend, the backend
does not exist.
The socket_connect() conversion as done is a bad fit for the
current code, since it did not try to change the way it deals
with async connection completion. Rather than try to fix this,
just revert the socket_connect() conversion entirely.
The code is about to be converted to use QIOChannel which
will let the problem be solved in a cleaner manner. This
revert is more suitable for stable branches in the meantime.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-05-05 18:23:05 +02:00
|
|
|
qemu_set_nonblock(fd);
|
2016-08-30 14:04:12 +02:00
|
|
|
|
Revert "Change net/socket.c to use socket_*() functions" again
This reverts commit 883e4f7624e10b98d16d9adaffb8b1795664d899.
This code changed net/socket.c from using socket()+connect(),
to using socket_connect(). In theory this is great, but in
practice this has completely broken the ability to connect
the frontend and backend:
$ ./x86_64-softmmu/qemu-system-x86_64 \
-device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
-netdev socket,id=hn0,connect=localhost:1234
qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
The old code would call net_socket_fd_init() synchronously,
while letting the connect() complete in the backgorund. The
new code moved net_socket_fd_init() so that it is only called
after connect() completes in the background.
Thus at the time we initialize the NIC frontend, the backend
does not exist.
The socket_connect() conversion as done is a bad fit for the
current code, since it did not try to change the way it deals
with async connection completion. Rather than try to fix this,
just revert the socket_connect() conversion entirely.
The code is about to be converted to use QIOChannel which
will let the problem be solved in a cleaner manner. This
revert is more suitable for stable branches in the meantime.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-05-05 18:23:05 +02:00
|
|
|
connected = 0;
|
|
|
|
for(;;) {
|
|
|
|
ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr));
|
|
|
|
if (ret < 0) {
|
|
|
|
if (errno == EINTR || errno == EWOULDBLOCK) {
|
|
|
|
/* continue */
|
|
|
|
} else if (errno == EINPROGRESS ||
|
|
|
|
errno == EALREADY ||
|
|
|
|
errno == EINVAL) {
|
|
|
|
break;
|
|
|
|
} else {
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
error_setg_errno(errp, errno, "can't connect socket");
|
Revert "Change net/socket.c to use socket_*() functions" again
This reverts commit 883e4f7624e10b98d16d9adaffb8b1795664d899.
This code changed net/socket.c from using socket()+connect(),
to using socket_connect(). In theory this is great, but in
practice this has completely broken the ability to connect
the frontend and backend:
$ ./x86_64-softmmu/qemu-system-x86_64 \
-device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
-netdev socket,id=hn0,connect=localhost:1234
qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
The old code would call net_socket_fd_init() synchronously,
while letting the connect() complete in the backgorund. The
new code moved net_socket_fd_init() so that it is only called
after connect() completes in the background.
Thus at the time we initialize the NIC frontend, the backend
does not exist.
The socket_connect() conversion as done is a bad fit for the
current code, since it did not try to change the way it deals
with async connection completion. Rather than try to fix this,
just revert the socket_connect() conversion entirely.
The code is about to be converted to use QIOChannel which
will let the problem be solved in a cleaner manner. This
revert is more suitable for stable branches in the meantime.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-05-05 18:23:05 +02:00
|
|
|
closesocket(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
connected = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
s = net_socket_fd_init(peer, model, name, fd, connected, NULL, errp);
|
2017-09-04 16:35:38 +02:00
|
|
|
if (!s) {
|
Revert "Change net/socket.c to use socket_*() functions" again
This reverts commit 883e4f7624e10b98d16d9adaffb8b1795664d899.
This code changed net/socket.c from using socket()+connect(),
to using socket_connect(). In theory this is great, but in
practice this has completely broken the ability to connect
the frontend and backend:
$ ./x86_64-softmmu/qemu-system-x86_64 \
-device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
-netdev socket,id=hn0,connect=localhost:1234
qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
The old code would call net_socket_fd_init() synchronously,
while letting the connect() complete in the backgorund. The
new code moved net_socket_fd_init() so that it is only called
after connect() completes in the background.
Thus at the time we initialize the NIC frontend, the backend
does not exist.
The socket_connect() conversion as done is a bad fit for the
current code, since it did not try to change the way it deals
with async connection completion. Rather than try to fix this,
just revert the socket_connect() conversion entirely.
The code is about to be converted to use QIOChannel which
will let the problem be solved in a cleaner manner. This
revert is more suitable for stable branches in the meantime.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-05-05 18:23:05 +02:00
|
|
|
return -1;
|
2017-09-04 16:35:38 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 05:03:33 +02:00
|
|
|
snprintf(s->nc.info_str, sizeof(s->nc.info_str),
|
|
|
|
"socket: connect to %s:%d",
|
|
|
|
inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
|
2009-11-25 19:48:56 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-24 17:35:13 +02:00
|
|
|
static int net_socket_mcast_init(NetClientState *peer,
|
2009-11-25 19:48:56 +01:00
|
|
|
const char *model,
|
|
|
|
const char *name,
|
2010-12-01 20:16:47 +01:00
|
|
|
const char *host_str,
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
const char *localaddr_str,
|
|
|
|
Error **errp)
|
2009-11-25 19:48:56 +01:00
|
|
|
{
|
|
|
|
NetSocketState *s;
|
|
|
|
int fd;
|
|
|
|
struct sockaddr_in saddr;
|
2010-12-01 20:16:47 +01:00
|
|
|
struct in_addr localaddr, *param_localaddr;
|
2009-11-25 19:48:56 +01:00
|
|
|
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
if (parse_host_port(&saddr, host_str, errp) < 0) {
|
2009-11-25 19:48:56 +01:00
|
|
|
return -1;
|
2017-09-04 16:35:39 +02:00
|
|
|
}
|
2009-11-25 19:48:56 +01:00
|
|
|
|
2010-12-01 20:16:47 +01:00
|
|
|
if (localaddr_str != NULL) {
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
if (inet_aton(localaddr_str, &localaddr) == 0) {
|
|
|
|
error_setg(errp, "localaddr '%s' is not a valid IPv4 address",
|
|
|
|
localaddr_str);
|
2010-12-01 20:16:47 +01:00
|
|
|
return -1;
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
}
|
2010-12-01 20:16:47 +01:00
|
|
|
param_localaddr = &localaddr;
|
|
|
|
} else {
|
|
|
|
param_localaddr = NULL;
|
|
|
|
}
|
2009-11-25 19:48:56 +01:00
|
|
|
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
fd = net_socket_mcast_create(&saddr, param_localaddr, errp);
|
2017-09-04 16:35:38 +02:00
|
|
|
if (fd < 0) {
|
2011-12-07 16:01:48 +01:00
|
|
|
return -1;
|
2017-09-04 16:35:38 +02:00
|
|
|
}
|
2009-11-25 19:48:56 +01:00
|
|
|
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
s = net_socket_fd_init(peer, model, name, fd, 0, NULL, errp);
|
2017-09-04 16:35:38 +02:00
|
|
|
if (!s) {
|
2009-11-25 19:48:56 +01:00
|
|
|
return -1;
|
2017-09-04 16:35:38 +02:00
|
|
|
}
|
2009-11-25 19:48:56 +01:00
|
|
|
|
|
|
|
s->dgram_dst = saddr;
|
|
|
|
|
2021-04-02 05:03:33 +02:00
|
|
|
snprintf(s->nc.info_str, sizeof(s->nc.info_str),
|
|
|
|
"socket: mcast=%s:%d",
|
|
|
|
inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
|
2009-11-25 19:48:56 +01:00
|
|
|
return 0;
|
2021-04-02 05:03:12 +02:00
|
|
|
|
2009-11-25 19:48:56 +01:00
|
|
|
}
|
|
|
|
|
2012-07-24 17:35:13 +02:00
|
|
|
static int net_socket_udp_init(NetClientState *peer,
|
2012-01-11 01:20:54 +01:00
|
|
|
const char *model,
|
|
|
|
const char *name,
|
|
|
|
const char *rhost,
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
const char *lhost,
|
|
|
|
Error **errp)
|
2012-01-11 01:20:54 +01:00
|
|
|
{
|
|
|
|
NetSocketState *s;
|
2013-10-02 12:23:14 +02:00
|
|
|
int fd, ret;
|
2012-01-11 01:20:54 +01:00
|
|
|
struct sockaddr_in laddr, raddr;
|
|
|
|
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
if (parse_host_port(&laddr, lhost, errp) < 0) {
|
2012-01-11 01:20:54 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
if (parse_host_port(&raddr, rhost, errp) < 0) {
|
2012-01-11 01:20:54 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = qemu_socket(PF_INET, SOCK_DGRAM, 0);
|
|
|
|
if (fd < 0) {
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
error_setg_errno(errp, errno, "can't create datagram socket");
|
2012-01-11 01:20:54 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2013-10-02 12:23:14 +02:00
|
|
|
|
|
|
|
ret = socket_set_fast_reuse(fd);
|
2012-01-11 01:20:54 +01:00
|
|
|
if (ret < 0) {
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
error_setg_errno(errp, errno,
|
|
|
|
"can't set socket option SO_REUSEADDR");
|
2012-01-11 01:20:54 +01:00
|
|
|
closesocket(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ret = bind(fd, (struct sockaddr *)&laddr, sizeof(laddr));
|
|
|
|
if (ret < 0) {
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
error_setg_errno(errp, errno, "can't bind ip=%s to socket",
|
|
|
|
inet_ntoa(laddr.sin_addr));
|
2012-01-11 01:20:54 +01:00
|
|
|
closesocket(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-03-27 10:10:44 +01:00
|
|
|
qemu_set_nonblock(fd);
|
2012-01-11 01:20:54 +01:00
|
|
|
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
s = net_socket_fd_init(peer, model, name, fd, 0, NULL, errp);
|
2012-01-11 01:20:54 +01:00
|
|
|
if (!s) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->dgram_dst = raddr;
|
|
|
|
|
2021-04-02 05:03:33 +02:00
|
|
|
snprintf(s->nc.info_str, sizeof(s->nc.info_str),
|
|
|
|
"socket: udp=%s:%d",
|
|
|
|
inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port));
|
2012-01-11 01:20:54 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-14 05:50:12 +02:00
|
|
|
int net_init_socket(const Netdev *netdev, const char *name,
|
2015-05-15 13:58:50 +02:00
|
|
|
NetClientState *peer, Error **errp)
|
2009-11-25 19:48:56 +01:00
|
|
|
{
|
2012-07-17 16:17:17 +02:00
|
|
|
const NetdevSocketOptions *sock;
|
2009-11-25 19:48:56 +01:00
|
|
|
|
qapi: Change Netdev into a flat union
This is a mostly-mechanical conversion that creates a new flat
union 'Netdev' QAPI type that covers all the branches of the
former 'NetClientOptions' simple union, where the branches are
now listed in a new 'NetClientDriver' enum rather than generated
from the simple union. The existence of a flat union has no
change to the command line syntax accepted for new code, and
will make it possible for a future patch to switch the QMP
command to parse a boxed union for no change to valid QMP; but
it does have some ripple effect on the C code when dealing with
the new types.
While making the conversion, note that the 'NetLegacy' type
remains unchanged: it applies only to legacy command line options,
and will not be ported to QMP, so it should remain a wrapper
around a simple union; to avoid confusion, the type named
'NetClientOptions' is now gone, and we introduce 'NetLegacyOptions'
in its place. Then, in the C code, we convert from NetLegacy to
Netdev as soon as possible, so that the bulk of the net stack
only has to deal with one QAPI type, not two. Note that since
the old legacy code always rejected 'hubport', we can just omit
that branch from the new 'NetLegacyOptions' simple union.
Based on an idea originally by Zoltán Kővágó <DirtY.iCE.hu@gmail.com>:
Message-Id: <01a527fbf1a5de880091f98cf011616a78adeeee.1441627176.git.DirtY.iCE.hu@gmail.com>
although the sed script in that patch no longer applies due to
other changes in the tree since then, and I also did some manual
cleanups (such as fixing whitespace to keep checkpatch happy).
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1468468228-27827-13-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Fixup from Eric squashed in]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-07-14 05:50:23 +02:00
|
|
|
assert(netdev->type == NET_CLIENT_DRIVER_SOCKET);
|
|
|
|
sock = &netdev->u.socket;
|
2009-11-25 19:48:56 +01:00
|
|
|
|
2017-09-27 17:21:18 +02:00
|
|
|
if (sock->has_fd + sock->has_listen + sock->has_connect + sock->has_mcast +
|
|
|
|
sock->has_udp != 1) {
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
error_setg(errp, "exactly one of listen=, connect=, mcast= or udp="
|
|
|
|
" is required");
|
2012-07-17 16:17:17 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2009-11-25 19:48:56 +01:00
|
|
|
|
2012-07-17 16:17:17 +02:00
|
|
|
if (sock->has_localaddr && !sock->has_mcast && !sock->has_udp) {
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
error_setg(errp, "localaddr= is only valid with mcast= or udp=");
|
2012-07-17 16:17:17 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2009-11-25 19:48:56 +01:00
|
|
|
|
2012-07-17 16:17:17 +02:00
|
|
|
if (sock->has_fd) {
|
net: check if the file descriptor is valid before using it
qemu_set_nonblock() checks that the file descriptor can be used and, if
not, crashes QEMU. An assert() is used for that. The use of assert() is
used to detect programming error and the coredump will allow to debug
the problem.
But in the case of the tap device, this assert() can be triggered by
a misconfiguration by the user. At startup, it's not a real problem, but it
can also happen during the hot-plug of a new device, and here it's a
problem because we can crash a perfectly healthy system.
For instance:
# ip link add link virbr0 name macvtap0 type macvtap mode bridge
# ip link set macvtap0 up
# TAP=/dev/tap$(ip -o link show macvtap0 | cut -d: -f1)
# qemu-system-x86_64 -machine q35 -device pcie-root-port,id=pcie-root-port-0 -monitor stdio 9<> $TAP
(qemu) netdev_add type=tap,id=hostnet0,vhost=on,fd=9
(qemu) device_add driver=virtio-net-pci,netdev=hostnet0,id=net0,bus=pcie-root-port-0
(qemu) device_del net0
(qemu) netdev_del hostnet0
(qemu) netdev_add type=tap,id=hostnet1,vhost=on,fd=9
qemu-system-x86_64: .../util/oslib-posix.c:247: qemu_set_nonblock: Assertion `f != -1' failed.
Aborted (core dumped)
To avoid that, add a function, qemu_try_set_nonblock(), that allows to report the
problem without crashing.
In the same way, we also update the function for vhostfd in net_init_tap_one() and
for fd in net_init_socket() (both descriptors are provided by the user and can
be wrong).
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2020-07-07 20:45:14 +02:00
|
|
|
int fd, ret;
|
2009-11-25 19:48:56 +01:00
|
|
|
|
2020-10-05 17:58:44 +02:00
|
|
|
fd = monitor_fd_param(monitor_cur(), sock->fd, errp);
|
2013-03-27 10:10:44 +01:00
|
|
|
if (fd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
net: check if the file descriptor is valid before using it
qemu_set_nonblock() checks that the file descriptor can be used and, if
not, crashes QEMU. An assert() is used for that. The use of assert() is
used to detect programming error and the coredump will allow to debug
the problem.
But in the case of the tap device, this assert() can be triggered by
a misconfiguration by the user. At startup, it's not a real problem, but it
can also happen during the hot-plug of a new device, and here it's a
problem because we can crash a perfectly healthy system.
For instance:
# ip link add link virbr0 name macvtap0 type macvtap mode bridge
# ip link set macvtap0 up
# TAP=/dev/tap$(ip -o link show macvtap0 | cut -d: -f1)
# qemu-system-x86_64 -machine q35 -device pcie-root-port,id=pcie-root-port-0 -monitor stdio 9<> $TAP
(qemu) netdev_add type=tap,id=hostnet0,vhost=on,fd=9
(qemu) device_add driver=virtio-net-pci,netdev=hostnet0,id=net0,bus=pcie-root-port-0
(qemu) device_del net0
(qemu) netdev_del hostnet0
(qemu) netdev_add type=tap,id=hostnet1,vhost=on,fd=9
qemu-system-x86_64: .../util/oslib-posix.c:247: qemu_set_nonblock: Assertion `f != -1' failed.
Aborted (core dumped)
To avoid that, add a function, qemu_try_set_nonblock(), that allows to report the
problem without crashing.
In the same way, we also update the function for vhostfd in net_init_tap_one() and
for fd in net_init_socket() (both descriptors are provided by the user and can
be wrong).
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2020-07-07 20:45:14 +02:00
|
|
|
ret = qemu_try_set_nonblock(fd);
|
|
|
|
if (ret < 0) {
|
|
|
|
error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
|
|
|
|
name, fd);
|
|
|
|
return -1;
|
|
|
|
}
|
2017-09-04 16:35:38 +02:00
|
|
|
if (!net_socket_fd_init(peer, "socket", name, fd, 1, sock->mcast,
|
|
|
|
errp)) {
|
2009-11-25 19:48:56 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2012-07-17 16:17:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2009-11-25 19:48:56 +01:00
|
|
|
|
2012-07-17 16:17:17 +02:00
|
|
|
if (sock->has_listen) {
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
if (net_socket_listen_init(peer, "socket", name, sock->listen, errp)
|
|
|
|
< 0) {
|
2009-11-25 19:48:56 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2012-07-17 16:17:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2009-11-25 19:48:56 +01:00
|
|
|
|
2012-07-17 16:17:17 +02:00
|
|
|
if (sock->has_connect) {
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
if (net_socket_connect_init(peer, "socket", name, sock->connect, errp)
|
|
|
|
< 0) {
|
2009-11-25 19:48:56 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2012-07-17 16:17:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2009-11-25 19:48:56 +01:00
|
|
|
|
2012-07-17 16:17:17 +02:00
|
|
|
if (sock->has_mcast) {
|
|
|
|
/* if sock->localaddr is missing, it has been initialized to "all bits
|
|
|
|
* zero" */
|
2012-07-24 17:35:05 +02:00
|
|
|
if (net_socket_mcast_init(peer, "socket", name, sock->mcast,
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
sock->localaddr, errp) < 0) {
|
2012-01-11 01:20:54 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2012-07-17 16:17:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2012-01-11 01:20:54 +01:00
|
|
|
|
2012-07-17 16:17:17 +02:00
|
|
|
assert(sock->has_udp);
|
|
|
|
if (!sock->has_localaddr) {
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
error_setg(errp, "localaddr= is mandatory with udp=");
|
2012-07-17 16:17:17 +02:00
|
|
|
return -1;
|
|
|
|
}
|
net/socket: Improve -net socket error reporting
When -net socket fails, it first reports a specific error, then
a generic one, like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is required
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: Device 'socket' could not be initialized
Convert net_socket_*_init() to Error to get rid of the superfluous second
error message. After the patch, the effect like this:
$ ./x86_64-softmmu/qemu-system-x86_64 -net socket,mcast=230.0.0.1:1234,listen
qemu-system-x86_64: -net socket,mcast=230.0.0.1:1234,listen: exactly one of listen=, connect=, mcast= or udp= is requireda
This also fixes a few silent failures to report an error.
Cc: jasowang@redhat.com
Cc: armbru@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2017-09-04 16:35:40 +02:00
|
|
|
if (net_socket_udp_init(peer, "socket", name, sock->udp, sock->localaddr,
|
|
|
|
errp) < 0) {
|
2009-11-25 19:48:56 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|