vnc: add support for multiple vnc displays
cover vnc: add support for multiple vnc displays
Hi,
Next (and hopefully final) round of the multiple vnc display patch series. Renamed the monitor command from query-vnc2 to query-vnc-servers as suggested by Markus.
please review,
Gerd
Gerd Hoffmann (10):
vnc: remove vnc_display global
vnc: remove unused DisplayState parameter, add id instead.
vnc: add display id to acl names
vnc: switch to QemuOpts, allow multiple servers
vnc: allow binding servers to qemu consoles
vnc: update docs/multiseat.txt
vnc: track & limit connections
vnc: factor out qmp_query_client_list
monitor: add query-vnc-servers command
monitor: add vnc websockets
docs/multiseat.txt | 18 +- include/ui/console.h | 18 +- qapi-schema.json | 73 +++++- qmp-commands.hx | 5 + qmp.c | 15 +- ui/vnc.c | 634 ++++++++++++++++++++++++++++++++++++++------------- ui/vnc.h | 5 + vl.c | 41 ++-- 8 files changed, 611 insertions(+), 198 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 10/10 monitor: add vnc websockets
Add websockets bool to VncBasicInfo, report websocket server sockets, flag websocket client connections.
--- qapi-schema.json | 5 ++++- ui/vnc.c | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-)
qapi-schema.json +4 -1
@@ -672,12 +672,15 @@ # # @family: address family # +# @websocket: true in case the socket is a websocket (since 2.3). +# # Since: 2.1 ## { 'type': 'VncBasicInfo', 'data': { 'host': 'str', 'service': 'str', - 'family': 'NetworkAddressFamily' } } + 'family': 'NetworkAddressFamily', + 'websocket': 'bool' } } ## # @VncServerInfo
ui/vnc.c +12 -3
@@ -353,6 +353,9 @@ static VncClientInfo *qmp_query_vnc_client(const VncState *client) info->base->host =g_strdup (host); info->base->service =g_strdup (serv); info->base->family =inet_netfamily (sa.ss_family); +#ifdef CONFIG_VNC_WS + info->base->websocket = client->websocket; +#endif #ifdef CONFIG_VNC_TLS if (client->tls.session && client->tls.dname) {
@@ -457,6 +460,7 @@ out_error: }static VncBasicInfoList *qmp_query_server_entry (int socket, +bool websocket,VncBasicInfoList *prev) {VncBasicInfoList *list;
@@ -477,6 +481,7 @@ static VncBasicInfoList *qmp_query_server_entry(int socket, info->host =g_strdup (host); info->service =g_strdup (serv); info->family =inet_netfamily (sa.ss_family); + info->websocket = websocket; list =g_new0 (VncBasicInfoList,1 ); list->value = info;
@@ -572,12 +577,13 @@ VncInfo2List *qmp_query_vnc_servers(Error **errp) info->display =g_strdup (dev->id); }if (vd->lsock !=-1 ) { - info->server =qmp_query_server_entry (vd->lsock, + info->server =qmp_query_server_entry (vd->lsock, false, info->server); }#ifdef CONFIG_VNC_WS if (vd->lwebsock !=-1 ) { -/* TODO */ + info->server =qmp_query_server_entry (vd->lwebsock, true, + info->server); }#endif
@@ -3304,10 +3310,13 @@ void vnc_display_open(const char *id, Error **errp) {VncDisplay *vs =vnc_display_find (id);QemuOpts *opts =qemu_opts_find (&qemu_vnc_opts, id); -const char *display, *websocket, *share, *device_id; +const char *display, *share, *device_id;QemuConsole *con;int password =0 ;int reverse =0 ; +#ifdef CONFIG_VNC_WS +const char *websocket; +#endif #ifdef CONFIG_VNC_TLS int tls =0 , x509 =0 ;const char *path;
Signature · 1 line
1.8.3.1
PATCH 2/10 vnc: remove unused DisplayState parameter, add id instead.
In reply to Gerd HoffmannDisplayState isn't used anywhere, drop it. Add the vnc server ID as parameter instead, so it is possible to specify the server instance.
--- include/ui/console.h | 16 ++++++++-------- ui/vnc.c | 29 ++++++++++++++--------------- vl.c | 7 ++++--- 3 files changed, 26 insertions(+), 26 deletions(-)
include/ui/console.h +8 -8
@@ -327,19 +327,19 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);void cocoa_display_init (DisplayState *ds,int full_screen);/* vnc.c */ -void vnc_display_init (DisplayState *ds); -void vnc_display_open (DisplayState *ds,const char *display,Error **errp); -void vnc_display_add_client (DisplayState *ds,int csock,bool skipauth); -char *vnc_display_local_addr (DisplayState *ds); +void vnc_display_init (const char *id); +void vnc_display_open (const char *id,const char *display,Error **errp); +void vnc_display_add_client (const char *id,int csock,bool skipauth); +char *vnc_display_local_addr (const char *id);#ifdef CONFIG_VNC -int vnc_display_password (DisplayState *ds,const char *password); -int vnc_display_pw_expire (DisplayState *ds,time_t expires); +int vnc_display_password (const char *id,const char *password); +int vnc_display_pw_expire (const char *id,time_t expires);#else -static inline int vnc_display_password (DisplayState *ds,const char *password) +static inline int vnc_display_password (const char *id,const char *password) {return -ENODEV ; } -static inline int vnc_display_pw_expire (DisplayState *ds,time_t expires) +static inline int vnc_display_pw_expire (const char *id,time_t expires) {return -ENODEV ; };
ui/vnc.c +14 -15
@@ -2967,10 +2967,11 @@ static const DisplayChangeListenerOps dcl_ops = { .dpy_cursor_define = vnc_dpy_cursor_define, }; -void vnc_display_init (DisplayState *ds) +void vnc_display_init (const char *id) {VncDisplay *vs =g_malloc0 (sizeof (*vs)); + vs->id =strdup (id);QTAILQ_INSERT_TAIL (&vnc_displays, vs, next); vs->lsock =-1 ;
@@ -2999,10 +3000,8 @@ void vnc_display_init(DisplayState *ds) } -static void vnc_display_close (DisplayState *ds) +static void vnc_display_close (VncDisplay *vs) { -VncDisplay *vs =vnc_display_find (NULL ); -if (!vs)return ;g_free (vs->display);
@@ -3028,9 +3027,9 @@ static void vnc_display_close(DisplayState *ds)#endif } -int vnc_display_password (DisplayState *ds,const char *password) +int vnc_display_password (const char *id,const char *password) { -VncDisplay *vs =vnc_display_find (NULL ); +VncDisplay *vs =vnc_display_find (id);if (!vs) {return -EINVAL ;
@@ -3047,9 +3046,9 @@ int vnc_display_password(DisplayState *ds, const char *password)return 0 ; } -int vnc_display_pw_expire (DisplayState *ds,time_t expires) +int vnc_display_pw_expire (const char *id,time_t expires) { -VncDisplay *vs =vnc_display_find (NULL ); +VncDisplay *vs =vnc_display_find (id);if (!vs) {return -EINVAL ;
@@ -3059,16 +3058,16 @@ int vnc_display_pw_expire(DisplayState *ds, time_t expires)return 0 ; } -char *vnc_display_local_addr (DisplayState *ds) +char *vnc_display_local_addr (const char *id) { -VncDisplay *vs =vnc_display_find (NULL ); +VncDisplay *vs =vnc_display_find (id);return vnc_socket_local_addr ("%s:%s" , vs->lsock); } -void vnc_display_open (DisplayState *ds,const char *display,Error **errp) +void vnc_display_open (const char *id,const char *display,Error **errp) { -VncDisplay *vs =vnc_display_find (NULL ); +VncDisplay *vs =vnc_display_find (id);const char *options;int password =0 ;int reverse =0 ;
@@ -3088,7 +3087,7 @@ void vnc_display_open(DisplayState *ds, const char *display, Error **errp)error_setg (errp,"VNC display not active" );return ; } -vnc_display_close (ds); +vnc_display_close (vs);if (strcmp (display,"none" ) ==0 )return ;
@@ -3381,9 +3380,9 @@ fail:#endif /* CONFIG_VNC_WS */ } -void vnc_display_add_client (DisplayState *ds,int csock,bool skipauth) +void vnc_display_add_client (const char *id,int csock,bool skipauth) { -VncDisplay *vs =vnc_display_find (NULL ); +VncDisplay *vs =vnc_display_find (id);if (!vs) {return ;
vl.c +4 -3
@@ -4276,8 +4276,9 @@ int main(int argc, char **argv, char **envp)/* init remote displays */ if (vnc_display) {Error *local_err =NULL ; -vnc_display_init (ds); -vnc_display_open (ds, vnc_display, &local_err); +const char *id ="default" ; +vnc_display_init (id); +vnc_display_open (id, vnc_display, &local_err);if (local_err !=NULL ) {error_report ("Failed to start VNC server on `%s': %s" , vnc_display,error_get_pretty (local_err));
@@ -4286,7 +4287,7 @@ int main(int argc, char **argv, char **envp) }if (show_vnc_port) { -printf ("VNC server running on `%s'\n" ,vnc_display_local_addr (ds)); +printf ("VNC server running on `%s'\n" ,vnc_display_local_addr (id)); } }#endif
Signature · 1 line
1.8.3.1
PATCH 3/10 vnc: add display id to acl names
In reply to Gerd HoffmannIn case the display id is "default" (which is the one you get if you don't explicitly assign one) we keep the old name scheme, without display, for backward compatibility reasons.
--- ui/vnc.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
ui/vnc.c +20 -2
@@ -3206,18 +3206,36 @@ void vnc_display_open(const char *id, const char *display, Error **errp)#ifdef CONFIG_VNC_TLS if (acl && x509 && vs->tls.x509verify) { -if (!(vs->tls.acl =qemu_acl_init ("vnc.x509dname" ))) { +char *aclname; + +if (strcmp (vs->id,"default" ) ==0 ) { + aclname =g_strdup ("vnc.x509dname" ); + }else { + aclname =g_strdup_printf ("vnc.%s.x509dname" , vs->id); + } + vs->tls.acl =qemu_acl_init (aclname); +if (!vs->tls.acl) {fprintf (stderr,"Failed to create x509 dname ACL\n" );exit (1 ); } +g_free (aclname); }#endif #ifdef CONFIG_VNC_SASL if (acl && sasl) { -if (!(vs->sasl.acl =qemu_acl_init ("vnc.username" ))) { +char *aclname; + +if (strcmp (vs->id,"default" ) ==0 ) { + aclname =g_strdup ("vnc.username" ); + }else { + aclname =g_strdup_printf ("vnc.%s.username" , vs->id); + } + vs->sasl.acl =qemu_acl_init (aclname); +if (!vs->sasl.acl) {fprintf (stderr,"Failed to create username ACL\n" );exit (1 ); } +g_free (aclname); }#endif
Signature · 1 line
1.8.3.1
PATCH 1/10 vnc: remove vnc_display global
In reply to Gerd HoffmannReplace with a vnc_displays list, so we can have multiple vnc server instances. Add vnc_server_find function to lookup a display by id. With no id supplied return the first vnc server, for backward compatibility reasons.
It is not possible (yet) to actually create multiple vnc server instances.
--- ui/vnc.c | 63 +++++++++++++++++++++++++++++++++++++++++---------------------- ui/vnc.h | 2 ++ 2 files changed, 43 insertions(+), 22 deletions(-)
ui/vnc.c +41 -22
@@ -46,7 +46,8 @@ static const struct timeval VNC_REFRESH_LOSSY = { 2, 0 };#include "vnc_keysym.h" #include "d3des.h" -static VncDisplay *vnc_display;/* needed for info vnc */ +static QTAILQ_HEAD(, VncDisplay) vnc_displays = +QTAILQ_HEAD_INITIALIZER (vnc_displays);static int vnc_cursor_define (VncState *vs);static void vnc_release_modifiers (VncState *vs);
@@ -226,10 +227,10 @@ static const char *vnc_auth_name(VncDisplay *vd) {return "unknown" ; } -static VncServerInfo *vnc_server_info_get (void ) +static VncServerInfo *vnc_server_info_get (VncDisplay *vd) {VncServerInfo *info; -VncBasicInfo *bi =vnc_basic_info_get_from_server_addr (vnc_display->lsock); +VncBasicInfo *bi =vnc_basic_info_get_from_server_addr (vd->lsock);if (!bi) {return NULL ; }
@@ -237,7 +238,7 @@ static VncServerInfo *vnc_server_info_get(void) info =g_malloc (sizeof (*info)); info->base = bi; info->has_auth = true; - info->auth =g_strdup (vnc_auth_name (vnc_display)); + info->auth =g_strdup (vnc_auth_name (vd));return info; }
@@ -282,7 +283,7 @@ static void vnc_qmp_event(VncState *vs, QAPIEvent event) }g_assert (vs->info->base); - si =vnc_server_info_get (); + si =vnc_server_info_get (vs->vd);if (!si) {return ; }
@@ -345,11 +346,27 @@ static VncClientInfo *qmp_query_vnc_client(const VncState *client)return info; } +static VncDisplay *vnc_display_find (const char *id) +{ +VncDisplay *vd; + +if (id ==NULL ) { +return QTAILQ_FIRST (&vnc_displays); + } + QTAILQ_FOREACH(vd, &vnc_displays, next) { +if (strcmp (id, vd->id) ==0 ) { +return vd; + } + } +return NULL ; +} +VncInfo *qmp_query_vnc (Error **errp) {VncInfo *info =g_malloc0 (sizeof (*info)); +VncDisplay *vd =vnc_display_find (NULL ); -if (vnc_display ==NULL || vnc_display->display ==NULL ) { +if (vd ==NULL || vd->display ==NULL ) { info->enabled = false; }else {VncClientInfoList *cur_item =NULL ;
@@ -364,7 +381,7 @@ VncInfo *qmp_query_vnc(Error **errp)/* for compatibility with the original command */ info->has_clients = true; - QTAILQ_FOREACH(client, &vnc_display->clients, next) { + QTAILQ_FOREACH(client, &vd->clients, next) {VncClientInfoList *cinfo =g_malloc0 (sizeof (*info)); cinfo->value =qmp_query_vnc_client (client);
@@ -377,11 +394,11 @@ VncInfo *qmp_query_vnc(Error **errp) } } -if (vnc_display->lsock ==-1 ) { +if (vd->lsock ==-1 ) {return info; } -if (getsockname (vnc_display->lsock, (struct sockaddr *)&sa, +if (getsockname (vd->lsock, (struct sockaddr *)&sa, &salen) ==-1 ) {error_set (errp,QERR_UNDEFINED_ERROR ); goto out_error;
@@ -405,7 +422,7 @@ VncInfo *qmp_query_vnc(Error **errp) info->family =inet_netfamily (sa.ss_family); info->has_auth = true; - info->auth =g_strdup (vnc_auth_name (vnc_display)); + info->auth =g_strdup (vnc_auth_name (vd)); }return info;
@@ -853,7 +870,7 @@ static int vnc_cursor_define(VncState *vs)static void vnc_dpy_cursor_define (DisplayChangeListener *dcl,QEMUCursor *c) { -VncDisplay *vd = vnc_display; +VncDisplay *vd =container_of (dcl, VncDisplay, dcl);VncState *vs;cursor_put (vd->cursor);
@@ -2818,6 +2835,7 @@ static void vnc_connect(VncDisplay *vd, int csock,int i; vs->csock = csock; + vs->vd = vd;if (skipauth) { vs->auth =VNC_AUTH_NONE ;
@@ -2862,8 +2880,6 @@ static void vnc_connect(VncDisplay *vd, int csock,vnc_qmp_event (vs,QAPI_EVENT_VNC_CONNECTED );vnc_set_share_mode (vs,VNC_SHARE_MODE_CONNECTING ); - vs->vd = vd; -#ifdef CONFIG_VNC_WS if (!vs->websocket)#endif
@@ -2955,7 +2971,7 @@ void vnc_display_init(DisplayState *ds) {VncDisplay *vs =g_malloc0 (sizeof (*vs)); - vnc_display = vs; +QTAILQ_INSERT_TAIL (&vnc_displays, vs, next); vs->lsock =-1 ;#ifdef CONFIG_VNC_WS
@@ -2985,7 +3001,7 @@ void vnc_display_init(DisplayState *ds)static void vnc_display_close (DisplayState *ds) { -VncDisplay *vs = vnc_display; +VncDisplay *vs =vnc_display_find (NULL );if (!vs)return ;
@@ -3014,7 +3030,7 @@ static void vnc_display_close(DisplayState *ds)int vnc_display_password (DisplayState *ds,const char *password) { -VncDisplay *vs = vnc_display; +VncDisplay *vs =vnc_display_find (NULL );if (!vs) {return -EINVAL ;
@@ -3033,7 +3049,7 @@ int vnc_display_password(DisplayState *ds, const char *password)int vnc_display_pw_expire (DisplayState *ds,time_t expires) { -VncDisplay *vs = vnc_display; +VncDisplay *vs =vnc_display_find (NULL );if (!vs) {return -EINVAL ;
@@ -3045,14 +3061,14 @@ int vnc_display_pw_expire(DisplayState *ds, time_t expires)char *vnc_display_local_addr (DisplayState *ds) { -VncDisplay *vs = vnc_display; - +VncDisplay *vs =vnc_display_find (NULL ); +return vnc_socket_local_addr ("%s:%s" , vs->lsock); }void vnc_display_open (DisplayState *ds,const char *display,Error **errp) { -VncDisplay *vs = vnc_display; +VncDisplay *vs =vnc_display_find (NULL );const char *options;int password =0 ;int reverse =0 ;
@@ -3068,7 +3084,7 @@ void vnc_display_open(DisplayState *ds, const char *display, Error **errp)#endif int lock_key_sync =1 ; -if (!vnc_display) { +if (!vs) {error_setg (errp,"VNC display not active" );return ; }
@@ -3367,7 +3383,10 @@ fail:void vnc_display_add_client (DisplayState *ds,int csock,bool skipauth) { -VncDisplay *vs = vnc_display; +VncDisplay *vs =vnc_display_find (NULL ); +if (!vs) { +return ; + }vnc_connect (vs, csock, skipauth, false); }
ui/vnc.h +2 -0
@@ -171,6 +171,8 @@ struct VncDisplaystruct VncSurface guest;/* guest visible surface (aka ds->surface) */ pixman_image_t *server;/* vnc server surface */ +const char *id; +QTAILQ_ENTRY (VncDisplay) next;char *display;char *password;time_t expires;
Signature · 1 line
1.8.3.1
PATCH 9/10 monitor: add query-vnc-servers command
In reply to Gerd HoffmannAdd new query vnc qmp command, for the lack of better ideas just name it "query-vnc-servers". Changes over query-vnc:
* It returns a list of vnc servers, so multiple vnc server instances are covered.
* Each vnc server returns a list of server sockets. Followup patch will use that to also report websockets. In case we add support for multiple server sockets server sockets (to better support ipv4+ipv6 dualstack) we can add them to the list too.
--- qapi-schema.json | 68 ++++++++++++++++++++++++++++ qmp-commands.hx | 5 +++ ui/vnc.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+)
qapi-schema.json +68 -0
@@ -751,6 +751,63 @@ '*service': 'str', '*auth': 'str', '*clients': ['VncClientInfo']} } ## +# @VncPriAuth: +# +# vnc primary authentication method. +# +# Since: 2.3 +## +{ 'enum': 'VncPrimaryAuth', + 'data': [ 'none', 'vnc', 'ra2', 'ra2ne', 'tight', 'ultra', + 'tls', 'vencrypt', 'sasl' ] } + +## +# @VncVencryptSubAuth: +# +# vnc sub authentication method with vencrypt. +# +# Since: 2.3 +## +{ 'enum': 'VncVencryptSubAuth', + 'data': [ 'plain', + 'tls-none', 'x509-none', + 'tls-vnc', 'x509-vnc', + 'tls-plain', 'x509-plain', + 'tls-sasl', 'x509-sasl' ] } + +## +# @VncInfo2: +# +# Information about a vnc server +# +# @id: vnc server name. +# +# @server: A list of @VncBasincInfo describing all listening sockets. +# The list can be empty (in case the vnc server is disabled). +# It also may have multiple entries: normal + websocket, +# possibly also ipv4 + ipv6 in the future. +# +# @clients: A list of @VncClientInfo of all currently connected clients. +# The list can be empty, for obvious reasons. +# +# @auth: The current authentication type used by the server +# +# @vencrypt: #optional The vencrypt sub authentication type used by the server, +# only specified in case auth == vencrypt. +# +# @display: #optional The display device the vnc server is linked to. +# +# Since: 2.3 +## +{ 'type': 'VncInfo2', + 'data': { 'id' : 'str', + 'server' : ['VncBasicInfo'], + 'clients' : ['VncClientInfo'], + 'auth' : 'VncPrimaryAuth', + '*vencrypt' : 'VncVencryptSubAuth', + '*display' : 'str' } } + +## # @query-vnc: # # Returns information about the current VNC server
@@ -762,6 +819,17 @@ { 'command': 'query-vnc', 'returns': 'VncInfo' } ## +# @query-vnc-servers: +# +# Returns a list of vnc servers. The list can be empty. +# +# Returns: a list of @VncInfo2 +# +# Since: 2.3 +## +{ 'command': 'query-vnc-servers', 'returns': ['VncInfo2'] } + +## # @SpiceBasicInfo # # The basic information for SPICE network connection
qmp-commands.hx +5 -0
@@ -2825,6 +2825,11 @@ EQMP .args_type = "", .mhandler.cmd_new = qmp_marshal_input_query_vnc, }, + { + .name = "query-vnc-servers", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_vnc_servers, + }, SQMP query-spice
ui/vnc.c +133 -0
139 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 6/10 vnc: update docs/multiseat.txt
In reply to Gerd Hoffmannvnc joins the party ;)
Also some s/head/seat/ to clarify.
--- docs/multiseat.txt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
docs/multiseat.txt +14 -4
@@ -7,7 +7,7 @@ host side First you must compile qemu with a user interface supporting multihead/multiseat and input event routing. Right now this -list includes sdl2 and gtk (both 2+3): +list includes sdl2, gtk (both 2+3) and vnc: ./configure --enable-sdl --with-sdlabi=2.0
@@ -16,16 +16,16 @@ or ./configure --enable-gtk -Next put together the qemu command line: +Next put together the qemu command line (sdk/gtk): qemu -enable-kvm -usb $memory $disk $whatever \ -display [ sdl | gtk ] \ -vga std \ -device usb-tablet -That is it for the first head, which will use the standard vga, the +That is it for the first seat, which will use the standard vga, the standard ps/2 keyboard (implicitly there) and the usb-tablet. Now the -additional switches for the second head: +additional switches for the second seat: -device pci-bridge,addr=12.0,chassis_nr=2,id=head.2 \ -device secondary-vga,bus=head.2,addr=02.0,id=video.2 \
@@ -47,6 +47,16 @@ in a separate tab. You can either simply switch tabs to switch heads, or use the "View / Detach tab" menu item to move one of the displays to its own window so you can see both display devices side-by-side. +For vnc some additional configuration on the command line is needed. +We'll create two vnc server instances, and bind the second one to the +second seat, simliar to input devices: + + -display vnc=:1,id=primary \ + -display vnc=:2,id=secondary,display=video.2 + +Connecting to vnc display :1 gives you access to the first seat, and +likewise connecting to vnc display :2 shows the second seat. + Note on spice: Spice handles multihead just fine. But it can't do multiseat. For tablet events the event source is sent to the spice agent. But qemu can't figure it, so it can't do input routing.
Signature · 1 line
1.8.3.1
PATCH 4/10 vnc: switch to QemuOpts, allow multiple servers
In reply to Gerd HoffmannThis patch switches vnc over to QemuOpts, and it (more or less as side effect) allows multiple vnc server instances.
--- include/ui/console.h | 4 +- qmp.c | 15 ++- ui/vnc.c | 270 ++++++++++++++++++++++++++++++++------------------- vl.c | 42 +++----- 4 files changed, 199 insertions(+), 132 deletions(-)
include/ui/console.h +3 -1
@@ -328,12 +328,14 @@ void cocoa_display_init(DisplayState *ds, int full_screen);/* vnc.c */ void vnc_display_init (const char *id); -void vnc_display_open (const char *id,const char *display,Error **errp); +void vnc_display_open (const char *id,Error **errp);void vnc_display_add_client (const char *id,int csock,bool skipauth);char *vnc_display_local_addr (const char *id);#ifdef CONFIG_VNC int vnc_display_password (const char *id,const char *password);int vnc_display_pw_expire (const char *id,time_t expires); +QemuOpts *vnc_parse_func (const char *str); +int vnc_init_func (QemuOpts *opts,void *opaque);#else static inline int vnc_display_password (const char *id,const char *password) {
qmp.c +14 -1
@@ -368,7 +368,20 @@ void qmp_change_vnc_password(const char *password, Error **errp)static void qmp_change_vnc_listen (const char *target,Error **errp) { -vnc_display_open (NULL , target, errp); +QemuOptsList *olist =qemu_find_opts ("vnc" ); +QemuOpts *opts; + +if (strstr (target,"id=" )) { +error_setg (errp,"id not supported" ); +return ; + } + + opts =qemu_opts_find (olist,"default" ); +if (opts) { +qemu_opts_del (opts); + } + opts =vnc_parse_func (target); +vnc_display_open ("default" , errp); } static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
ui/vnc.c +169 -101
314 lines not on this page · raw message
vl.c +13 -29
73 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 5/10 vnc: allow binding servers to qemu consoles
In reply to Gerd HoffmannThis patch adds a display= parameter to the vnc options. This allows to bind a vnc server instance to a specific display, allowing to create a multiseat setup with a vnc server for each seat.
--- ui/vnc.c | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-)
ui/vnc.c +43 -7
@@ -27,6 +27,7 @@#include "vnc.h" #include "vnc-jobs.h" #include "trace.h" +#include "hw/qdev.h" #include "sysemu/sysemu.h" #include "qemu/sockets.h" #include "qemu/timer.h"
@@ -1665,7 +1666,8 @@ static void do_key_event(VncState *vs, int down, int keycode, int sym) vs->modifiers_state[keycode] =0 ;break ; case 0x02 ... 0x0a: /* '1' to '9' keys */ -if (down && vs->modifiers_state[0x1d ] && vs->modifiers_state[0x38 ]) { +if (vs->vd->dcl.con ==NULL && + down && vs->modifiers_state[0x1d ] && vs->modifiers_state[0x38 ]) {/* Reset the modifiers sent to the current console */ reset_keys (vs);console_select (keycode -0x02 );
@@ -2073,8 +2075,8 @@ static void set_pixel_format(VncState *vs,set_pixel_conversion (vs); -graphic_hw_invalidate (NULL ); -graphic_hw_update (NULL ); +graphic_hw_invalidate (vs->vd->dcl.con); +graphic_hw_update (vs->vd->dcl.con); }static void pixel_format_message (VncState *vs) {
@@ -2801,7 +2803,7 @@ static void vnc_refresh(DisplayChangeListener *dcl)return ; } -graphic_hw_update (NULL ); +graphic_hw_update (vd->dcl.con);if (vnc_trylock_display (vd)) {update_displaychangelistener (&vd->dcl,VNC_REFRESH_INTERVAL_BASE );
@@ -2907,7 +2909,7 @@ void vnc_init_state(VncState *vs)QTAILQ_INSERT_HEAD (&vd->clients, vs, next); -graphic_hw_update (NULL ); +graphic_hw_update (vd->dcl.con);vnc_write (vs,"RFB 003.008\n" ,12 );vnc_flush (vs);
@@ -2930,7 +2932,7 @@ static void vnc_listen_read(void *opaque, bool websocket)int csock;/* Catch-up */ -graphic_hw_update (NULL ); +graphic_hw_update (vs->dcl.con);#ifdef CONFIG_VNC_WS if (websocket) { csock =qemu_accept (vs->lwebsock, (struct sockaddr *)&addr, &addrlen);
@@ -3089,6 +3091,12 @@ static QemuOptsList qemu_vnc_opts = { .name = "share", .type = QEMU_OPT_STRING, },{ + .name = "display", + .type = QEMU_OPT_STRING, + },{ + .name = "head", + .type = QEMU_OPT_NUMBER, + },{ .name = "password", .type = QEMU_OPT_BOOL, },{
@@ -3124,7 +3132,8 @@ void vnc_display_open(const char *id, Error **errp) {VncDisplay *vs =vnc_display_find (id);QemuOpts *opts =qemu_opts_find (&qemu_vnc_opts, id); -const char *display, *websocket, *share; +const char *display, *websocket, *share, *device_id; +QemuConsole *con;int password =0 ;int reverse =0 ;#ifdef CONFIG_VNC_TLS
@@ -3353,6 +3362,33 @@ void vnc_display_open(const char *id, Error **errp)#endif vs->lock_key_sync = lock_key_sync; + device_id =qemu_opt_get (opts,"display" ); +if (device_id) { +DeviceState *dev; +int head =qemu_opt_get_number (opts,"head" ,0 ); + + dev =qdev_find_recursive (sysbus_get_default (), device_id); +if (dev ==NULL ) { +error_set (errp,QERR_DEVICE_NOT_FOUND , device_id); + goto fail; + } + + con =qemu_console_lookup_by_device (dev, head); +if (con ==NULL ) { +error_setg (errp,"Device %s is not bound to a QemuConsole" , + device_id); + goto fail; + } + }else { + con =NULL ; + } + +if (con != vs->dcl.con) { +unregister_displaychangelistener (&vs->dcl); + vs->dcl.con = con; +register_displaychangelistener (&vs->dcl); + } +if (reverse) {/* connect to viewer */ int csock;
Signature · 1 line
1.8.3.1
PATCH 7/10 vnc: track & limit connections
In reply to Gerd HoffmannAlso track the number of connections in "connecting" and "shared" state (in addition to the "exclusive" state). Apply a configurable limit to these connections.
The logic to apply the limit to connections in "shared" state is pretty
simple: When the limit is reached no new connections are allowed.
The logic to apply the limit to connections in "connecting" state (this is the state you are in *before* successful authentication) is slightly different: A new connect kicks out the oldest client which is still in "connecting" state. This avoids a easy DoS by unauthenticated users by simply opening connections until the limit is reached.
--- ui/vnc.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- ui/vnc.h | 3 +++ 2 files changed, 46 insertions(+), 3 deletions(-)
ui/vnc.c +43 -3
@@ -68,12 +68,34 @@ static void vnc_set_share_mode(VncState *vs, VncShareMode mode) vs->csock, mn[vs->share_mode], mn[mode]);#endif -if (vs->share_mode ==VNC_SHARE_MODE_EXCLUSIVE ) { +switch (vs->share_mode) { +case VNC_SHARE_MODE_CONNECTING : + vs->vd->num_connecting--; +break ; +case VNC_SHARE_MODE_SHARED : + vs->vd->num_shared--; +break ; +case VNC_SHARE_MODE_EXCLUSIVE : vs->vd->num_exclusive--; +break ; +default : +break ; } + vs->share_mode = mode; -if (vs->share_mode ==VNC_SHARE_MODE_EXCLUSIVE ) { + +switch (vs->share_mode) { +case VNC_SHARE_MODE_CONNECTING : + vs->vd->num_connecting++; +break ; +case VNC_SHARE_MODE_SHARED : + vs->vd->num_shared++; +break ; +case VNC_SHARE_MODE_EXCLUSIVE : vs->vd->num_exclusive++; +break ; +default : +break ; } }
@@ -2337,6 +2359,11 @@ static int protocol_client_init(VncState *vs, uint8_t *data, size_t len) }vnc_set_share_mode (vs, mode); +if (vs->vd->num_shared > vs->vd->connections_limit) { +vnc_disconnect_start (vs); +return 0 ; + } + vs->client_width =pixman_image_get_width (vs->vd->server); vs->client_height =pixman_image_get_height (vs->vd->server);vnc_write_u16 (vs, vs->client_width);
@@ -2889,6 +2916,15 @@ static void vnc_connect(VncDisplay *vd, int csock, {vnc_init_state (vs); } + +if (vd->num_connecting > vd->connections_limit) { + QTAILQ_FOREACH(vs, &vd->clients, next) { +if (vs->share_mode ==VNC_SHARE_MODE_CONNECTING ) { +vnc_disconnect_start (vs); +return ; + } + } + } }void vnc_init_state (VncState *vs)
@@ -2907,7 +2943,7 @@ void vnc_init_state(VncState *vs)qemu_mutex_init (&vs->output_mutex); vs->bh =qemu_bh_new (vnc_jobs_bh, vs); -QTAILQ_INSERT_HEAD (&vd->clients, vs, next); +QTAILQ_INSERT_TAIL (&vd->clients, vs, next);graphic_hw_update (vd->dcl.con);
@@ -3097,6 +3133,9 @@ static QemuOptsList qemu_vnc_opts = { .name = "head", .type = QEMU_OPT_NUMBER, },{ + .name = "connections", + .type = QEMU_OPT_NUMBER, + },{ .name = "password", .type = QEMU_OPT_BOOL, },{
@@ -3210,6 +3249,7 @@ void vnc_display_open(const char *id, Error **errp) }else { vs->share_policy =VNC_SHARE_POLICY_ALLOW_EXCLUSIVE ; } + vs->connections_limit =qemu_opt_get_number (opts,"connections" ,32 );#ifdef CONFIG_VNC_WS websocket =qemu_opt_get (opts,"websocket" );
ui/vnc.h +3 -0
@@ -150,7 +150,10 @@ typedef enum VncSharePolicy {struct VncDisplay { QTAILQ_HEAD(, VncState) clients; +int num_connecting; +int num_shared;int num_exclusive; +int connections_limit;VncSharePolicy share_policy;int lsock;#ifdef CONFIG_VNC_WS
Signature · 1 line
1.8.3.1
PATCH 8/10 vnc: factor out qmp_query_client_list
In reply to Gerd Hoffmannso we can reuse it for the new vnc query command.
--- ui/vnc.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
ui/vnc.c +15 -15
@@ -385,6 +385,20 @@ static VncDisplay *vnc_display_find(const char *id)return NULL ; } +static VncClientInfoList *qmp_query_client_list (VncDisplay *vd) +{ +VncClientInfoList *cinfo, *prev =NULL ; +VncState *client; + + QTAILQ_FOREACH(client, &vd->clients, next) { + cinfo =g_new0 (VncClientInfoList,1 ); + cinfo->value =qmp_query_vnc_client (client); + cinfo->next = prev; + prev = cinfo; + } +return prev; +} +VncInfo *qmp_query_vnc (Error **errp) {VncInfo *info =g_malloc0 (sizeof (*info));
@@ -393,30 +407,16 @@ VncInfo *qmp_query_vnc(Error **errp)if (vd ==NULL || vd->display ==NULL ) { info->enabled = false; }else { -VncClientInfoList *cur_item =NULL ;struct sockaddr_storage sa;socklen_t salen =sizeof (sa);char host[NI_MAXHOST ];char serv[NI_MAXSERV ]; -VncState *client; info->enabled = true;/* for compatibility with the original command */ info->has_clients = true; - - QTAILQ_FOREACH(client, &vd->clients, next) { -VncClientInfoList *cinfo =g_malloc0 (sizeof (*info)); - cinfo->value =qmp_query_vnc_client (client); - -/* XXX: waiting for the qapi to support GSList */ -if (!cur_item) { - info->clients = cur_item = cinfo; - }else { - cur_item->next = cinfo; - cur_item = cinfo; - } - } + info->clients =qmp_query_client_list (vd);if (vd->lsock ==-1 ) {return info;
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 04/10] vnc: switch to QemuOpts, allow multiple servers
In reply to Gerd HoffmannQuoted 4 lines · Gerd Hoffmann
This patch switches vnc over to QemuOpts, and it (more or less as side effect) allows multiple vnc server instances.
Signed-off-by Gerd Hoffmann <[email protected]>
I'm afraid this broke monitor command change vnc.
Reproducer
Terminal 1:
$ qemu -nodefaults -S -display vnc=:0 -monitor stdio QEMU 2.2.50 monitor - type 'help' for more information
Terminal 2:
$ vncviewer :0
Terminal 1:
(qemu) change vnc :1
Terminal 3:
$ vncviewer :1
Before this patch, vncviewer works both times. The second one kills the first one.
After this patch, the first one still works, but the second one fails. netstat shows nobody's listening on the port.
Speculation on possible cause inline.
Furthermore, the conversion to QemuOpts makes VNC visible in -writeconfig, but if you -readconfig it back, it doesn't quite work.
With -display vnc=:0, -writeconfig produces
[vnc]
vnc = ":0"If I append that to the config file I -readconfig, I a working VNC display on :0 (good), but I also get an SDL display (not good).
Quoted 33 lines
--- include/ui/console.h | 4 +- qmp.c | 15 ++- ui/vnc.c | 270 ++++++++++++++++++++++++++++++++------------------- vl.c | 42 +++----- 4 files changed, 199 insertions(+), 132 deletions(-)include/ui/console.h +3
-1@@ -328,12 +328,14 @@ void cocoa_display_init(DisplayState *ds, int full_screen);/* vnc.c */ void vnc_display_init (const char *id); -void vnc_display_open (const char *id,const char *display,Error **errp); +void vnc_display_open (const char *id,Error **errp);void vnc_display_add_client (const char *id,int csock,bool skipauth);char *vnc_display_local_addr (const char *id);#ifdef CONFIG_VNC int vnc_display_password (const char *id,const char *password);int vnc_display_pw_expire (const char *id,time_t expires); +QemuOpts *vnc_parse_func (const char *str); +int vnc_init_func (QemuOpts *opts,void *opaque);#else static inline int vnc_display_password (const char *id,const char *password) {qmp.c +0
-0@@ -368,7 +368,20 @@ void qmp_change_vnc_password(const char *password, Error **errp)
qmp.c void qmp_change_vnc_password(const char *password, Error **errp) · line 377
Quoted 10 lines
qmp.c +7
-1static void qmp_change_vnc_listen (const char *target,Error **errp) { -vnc_display_open (NULL , target, errp); +QemuOptsList *olist =qemu_find_opts ("vnc" ); +QemuOpts *opts; + +if (strstr (target,"id=" )) { +error_setg (errp,"id not supported" ); +return ; + }
Aside: this is unclean. Could we somehow test qemu_opts_id() instead?
qmp.c void qmp_change_vnc_password(const char *password, Error **errp) · line 378
Quoted 1 line
qmp.c +1
-0+
This deletes the QemuOpts with id=default:
qmp.c void qmp_change_vnc_password(const char *password, Error **errp) · line 382
Quoted 4 lines
qmp.c +4
-0+ opts =qemu_opts_find (olist,"default" ); +if (opts) { +qemu_opts_del (opts); + }
But this creates one without id:
qmp.c void qmp_change_vnc_password(const char *password, Error **errp) · line 383
Quoted 1 line
qmp.c +1
-0+ opts =vnc_parse_func (target);
The first argument orders vnc_display_open() to look for QemuOpts with id=default, which doesn't exist anymore:
Quoted 5 lines
qmp.c +1
-0+vnc_display_open ("default" , errp); }static void qmp_change_vnc(const char *target, bool
has_arg, const char *arg,
[...]
Re: [Qemu-devel] [PATCH 04/10] vnc: switch to QemuOpts, allow multiple servers
In reply to Gerd HoffmannOne more question...
Quoted 44 lines · Gerd Hoffmann
This patch switches vnc over to QemuOpts, and it (more or less as side effect) allows multiple vnc server instances.
Signed-off-by Gerd Hoffmann <[email protected]>--- include/ui/console.h | 4 +- qmp.c | 15 ++- ui/vnc.c | 270 ++++++++++++++++++++++++++++++++------------------- vl.c | 42 +++----- 4 files changed, 199 insertions(+), 132 deletions(-)include/ui/console.h +3
-1@@ -328,12 +328,14 @@ void cocoa_display_init(DisplayState *ds, int full_screen);/* vnc.c */ void vnc_display_init (const char *id); -void vnc_display_open (const char *id,const char *display,Error **errp); +void vnc_display_open (const char *id,Error **errp);void vnc_display_add_client (const char *id,int csock,bool skipauth);char *vnc_display_local_addr (const char *id);#ifdef CONFIG_VNC int vnc_display_password (const char *id,const char *password);int vnc_display_pw_expire (const char *id,time_t expires); +QemuOpts *vnc_parse_func (const char *str); +int vnc_init_func (QemuOpts *opts,void *opaque);#else static inline int vnc_display_password (const char *id,const char *password) {qmp.c +4
-1@@ -368,7 +368,20 @@ void qmp_change_vnc_password(const char *password, Error **errp)static void qmp_change_vnc_listen (const char *target,Error **errp) { -vnc_display_open (NULL , target, errp); +QemuOptsList *olist =qemu_find_opts ("vnc" ); +QemuOpts *opts; + +if (strstr (target,"id=" )) {
qmp.c void qmp_change_vnc_password(const char *password, Error **errp) · line 384
Quoted 10 lines
qmp.c +10
-0+error_setg (errp,"id not supported" ); +return ; + } + + opts =qemu_opts_find (olist,"default" ); +if (opts) { +qemu_opts_del (opts); + } + opts =vnc_parse_func (target); +vnc_display_open ("default" , errp);
vnc_parse_func() can fail. Shouldn't we keep the old display configuration then?
Quoted 2 lines
qmp.c +0
-0}
[...]
Re: [Qemu-devel] [PATCH 09/10] monitor: add query-vnc-servers command
In reply to Gerd HoffmannQuoted 8 lines · Gerd Hoffmann
Add new query vnc qmp command, for the lack of better ideas just name it "query-vnc-servers". Changes over query-vnc:
* It returns a list of vnc servers, so multiple vnc server instances are covered.
* Each vnc server returns a list of server sockets. Followup patch will use that to also report websockets. In case we add support for multiple server sockets server sockets (to better support ipv4+ipv6
s/( server sockets){2}/\1/
Quoted 9 lines
dualstack) we can add them to the list too.
Signed-off-by Gerd Hoffmann <[email protected]>--- qapi-schema.json | 68 ++++++++++++++++++++++++++++ qmp-commands.hx | 5 +++ ui/vnc.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 10/10] monitor: add vnc websockets
In reply to Gerd HoffmannQuoted 9 lines · Gerd Hoffmann
Add websockets bool to VncBasicInfo, report websocket server sockets, flag websocket client connections.
Signed-off-by Gerd Hoffmann <[email protected]>--- qapi-schema.json | 5 ++++- ui/vnc.c | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 04/10] vnc: switch to QemuOpts, allow multiple servers
In reply to Markus ArmbrusterQuoted 26 lines · Markus Armbruster
Quoted 4 lines · Gerd Hoffmann
This patch switches vnc over to QemuOpts, and it (more or less as side effect) allows multiple vnc server instances.
Signed-off-by Gerd Hoffmann <[email protected]>I'm afraid this broke monitor command change vnc.
Reproducer
Terminal 1:
$ qemu -nodefaults -S -display vnc=:0 -monitor stdio QEMU 2.2.50 monitor - type 'help' for more information
Terminal 2:
$ vncviewer :0
Terminal 1:
(qemu) change vnc :1
Terminal 3:
Quoted 7 lines
$ vncviewer :1
Before this patch, vncviewer works both times. The second one kills the first one.
After this patch, the first one still works, but the second one fails. netstat shows nobody's listening on the port.
Fix for this is on the list already (Gonglei) and included in the pending vnc pull request.
Quoted 10 lines
Furthermore, the conversion to QemuOpts makes VNC visible in -writeconfig, but if you -readconfig it back, it doesn't quite work.
With -display vnc=:0, -writeconfig produces
[vnc] vnc = ":0"If I append that to the config file I -readconfig, I a working VNC display on :0 (good), but I also get an SDL display (not good).
Will send a fix to the list in a moment.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 04/10] vnc: switch to QemuOpts, allow multiple servers
In reply to Markus ArmbrusterHi,
Quoted 11 lines
qmp.c void qmp_change_vnc_password(const char *password, Error **errp) · line 377
Quoted 10 lines
static void
qmp_change_vnc_listen(const char *target, Error **errp){qmp.c +7
-1-vnc_display_open (NULL , target, errp); +QemuOptsList *olist =qemu_find_opts ("vnc" ); +QemuOpts *opts; + +if (strstr (target,"id=" )) { +error_setg (errp,"id not supported" ); +return ; + }
Quoted 1 line
Aside: this is unclean. Could we somehow test
qemu_opts_id()instead?
For that we would have to parse it first, which has some ugly corner cases on id clashes ...
All I wanna do here is keep it alive for the existing use cases, without support for multiple displays, with minimum effort.
Should we need support for vnc config change in a multiple vnc server setup a new qmp monitor command should be designed for that.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 04/10] vnc: switch to QemuOpts, allow multiple servers
Quoted 15 lines · Gerd Hoffmann
Hi,
Quoted 11 lines
qmp.c void qmp_change_vnc_password(const char *password, Error **errp) · line 377
Quoted 10 lines
static void
qmp_change_vnc_listen(const char *target, Error **errp){qmp.c +7
-1-vnc_display_open (NULL , target, errp); +QemuOptsList *olist =qemu_find_opts ("vnc" ); +QemuOpts *opts; + +if (strstr (target,"id=" )) { +error_setg (errp,"id not supported" ); +return ; + }Quoted 1 line
Aside: this is unclean. Could we somehow test
qemu_opts_id()instead?
Quoted 8 lines
For that we would have to parse it first, which has some ugly corner cases on id clashes ...
All I wanna do here is keep it alive for the existing use cases, without support for multiple displays, with minimum effort.
Should we need support for vnc config change in a multiple vnc server setup a new qmp monitor command should be designed for that.
Fair enough. Suggests that the QemuOpts API is lacking, though.