Commit Graph

317 Commits

Author SHA1 Message Date
Frediano Ziglio
ba175f9be1 channel: add interface parameters to SpiceCoreInterfaceInternal
This patch and previous ones want to solve the problem of not having a
context in SpiceCoreInterface. SpiceCoreInterface defines a set of
callbacks to handle events in spice-server. These callbacks allow to
handle timers, watch for file descriptors and send channel events.
All these callbacks do not accept a context (usually in C passed as a
void* parameter) so it is hard for them to differentiate the interface
specified.
Unfortunately this structure is used even internally from different
contexts for instance every RedWorker thread has a different context. To
solve this issue some workarounds are used. Currently for timers a variable
depending on the current thread is used while for watches the opaque
parameter to pass to the event callback is used as it currently points just
to RedChannelClient structure.  This however imposes some implicit
maintainance problem in the future. What happens for instance if for some
reason a timer is registered during worker initialization, run in another
thread? What if we decide to register a file descriptor callback for
something not a RedChannelClient?  Could be that the program will run
without any issue till some bytes change and weird things could happen.

The implementation of this solution is done implementing an internal "core"
interface that has context specific and use it to differentiate the
context instead of relying on some other, hard to maintain, detail. Then an
adapter structure (name inpired to the adapter pattern) will provide the
internal core interface using the external, public, definition (in the
future this technique can be used to extend the external interface without
breaking the ABI).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-11 16:40:17 +00:00
Frediano Ziglio
9745ef5f9a channel: build adapter for public core interface
Add wrapper functions for SpiceCoreInterface in order to present
a SpiceCoreInterfaceInternal. These functions just expect
SpiceCoreInterfaceInternal API and forward request to
SpiceCoreInterface.
This allows to change ABI details of internal one.

See comments in "channel: add interface parameters to
SpiceCoreInterfaceInternal" patch.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-11 16:40:12 +00:00
Frediano Ziglio
adc0751950 channel: add a new internal SpiceCoreInterface
Define an internal structure that matches 100% the ABI of the public one.
The structure will be changed by following patches.
See comments in "channel: add interface parameters to
SpiceCoreInterfaceInternal" patch.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-11 16:29:53 +00:00
Frediano Ziglio
765b5209ef reds: do not use g_malloc0 in server code
The rest of code is using spice_malloc* functions, use them for
consistency.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-12-11 14:55:32 +00:00
Francois Gouget
f7613250c5 server: Add spice_get_monotonic_time_ms()
Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-12-11 12:43:26 +00:00
Frediano Ziglio
b12187b332 channel: rename red_channel_(client_)waits_* functions
Make clear that these funcion are just checking a condition.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-12-10 17:22:59 +00:00
Frediano Ziglio
febaed3529 server: misc header cleanups
Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-12-09 22:17:51 +00:00
Alon Levy
6e6126e024 server: multiple clients works ok if we limit the pipe to the slowest client
Signed-off-by: Alon Levy <alon@pobox.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Fabiano Fidêncio <fidencio@redhat.com>
2015-12-04 15:43:56 +00:00
Frediano Ziglio
525cd67be7 server: rename files
Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-12-03 23:54:32 +00:00
Marc-André Lureau
c5c176a5c7 server: remove OpenGL
This is really not supported, requires X11, so better to remove it for
now. Some day it might be revived, using DRM, ..

Note for later, this could be removed too (not used by client):
- spice-common/common/ogl_ctx

Acked-by: Fabiano Fidêncio <fidencio@redhat.com>
2015-11-21 13:50:46 +00:00
Pavel Grunt
57fe8ce268 reds: Do not abort due to wrong header
Just prevent the buggy client from connecting.

 #0  0x00007fffe83b2a98 in raise () at /lib64/libc.so.6
 #1  0x00007fffe83b469a in abort () at /lib64/libc.so.6
 #2  0x00007ffff7b1533d in spice_logv (log_domain=0x7ffff7b87226 "Spice", log_level=SPICE_LOG_LEVEL_ERROR, strloc=0x7ffff7b92aba "reds.c:1373", function=0x7ffff7b94f40 <__FUNCTION__.31775> "reds_send_link_ack", format=0x7ffff7b871fe "assertion `%s' failed", args=args@entry=0x7fffffffcb68) at log.c:109
 #3  0x00007ffff7b15468 in spice_log (log_domain=log_domain@entry=0x7ffff7b87226 "Spice", log_level=log_level@entry=SPICE_LOG_LEVEL_ERROR, strloc=strloc@entry=0x7ffff7b92aba "reds.c:1373", function=function@entry=0x7ffff7b94f40 <__FUNCTION__.31775> "reds_send_link_ack", format=format@entry=0x7ffff7b871fe "assertion `%s' failed") at log.c:123
 #4  0x00007ffff7aee335 in reds_handle_read_link_done (link=0x555556b27c70)
     at reds.c:1373
 #5  0x00007ffff7aee335 in reds_handle_read_link_done (opaque=0x555556b27c70)
     at reds.c:2139
 #6  0x000055555588acc6 in qemu_iohandler_poll ()
 #7  0x000055555588a8e1 in main_loop_wait ()
 #8  0x0000555555614064 in main ()

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1281442

Acked-by: Fabiano Fidêncio <fidencio@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-11-13 09:15:02 +00:00
Marc-André Lureau
f7b48981e3 worker: remove need for WorkerInitData
Move code around to declare and place it where it fits better.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-26 09:12:55 +00:00
snir sheriber
c749853d08 fix spelling mistakes in comments (reseting to resetting & dummym to dummy)
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-19 12:59:12 +01:00
Frediano Ziglio
9a62481b83 Avoid core calling spice_server_destroy
spice_server_destroy calls reds_exit which is called also at exit time
(is registered with atexit) so avoid to keep dangling pointers.
Currently this does not happen as spice_server_destroy is not called
by Qemu.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-08-26 15:42:59 +01:00
Jonathon Jongsma
3c39371b57 Fix typo in comments 2015-08-11 17:24:36 +02:00
Jonathon Jongsma
0eaf34c04b Cleanup: move static function declarations out of header
It doesn't make much sense to have static function declarations in a
header, even a private header. So move them down into the source file.
2015-08-11 17:24:36 +02:00
Christophe Fergeau
de66161c6e Adjust to new SpiceImageCompress name
This has been renamed to SpiceImageCompression in order to avoid clashes
with older spice-server in the SPICE_IMAGE_COMPRESS_ namespace. This
commit is a straight rename of SpiceImageCompress to
SpiceImageCompression and SPICE_IMAGE_COMPRESS_ to
SPICE_IMAGE_COMPRESSION_
2015-07-29 17:40:48 +02:00
Frediano Ziglio
40537f6a3e reds: Assure we don't have stale statistic files before trying to create a new one
If a previous Qemu executable is not able to delete the statistic file
on the next creation with same name (statitics file are based on pid
numbers so if pid get reused for another Qemu process you get the same
name) it fails as you can't open a file with 0444 permissions (these
are the permission used to create these files).
This patch assure there are no stale file trying to remove it before the
creation of the new one. As file is based on pid and name used for spice
you are not deleting another file.

Fixes: rhbz#1177326

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-07-20 11:19:28 +02:00
Francois Gouget
660bee0e93 server: spice_debug() messages don't need a trailing '\n'.
Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2015-07-20 11:15:55 +02:00
Javier Celaya
22c40b9d1f Use image compress constants from spice-protocol 2015-06-30 16:49:29 +02:00
Marc-André Lureau
55bc82f070 reds: increase listening socket backlog
With a TCP socket, the backlog doesn't seem to matter much,
perhaps because of latency or underlying protocol behaviour. However,
on UNIX socket, it is fairly easy to reach the backlog limit and the
client will get an EAGAIN error (but not ECONNREFUSED as stated in
listen(7)) that is not easy to deal with: attempting to reconnect in a
loop might busy-loop forever as there are no guarantee the server will
accept new connections, so it will be inherently racy.

Typically, Spice server can easily have up to 15 concurrent incoming
connections that are established during initialization of the session.
To improve the situation, raise the backlog limit to the default maximum
system value, which is 128 on Linux.
2015-06-17 15:58:56 +02:00
Cédric Bosdonnat
939e643c2a Add password length check
Don't allow setting a too long password.
2015-06-16 09:53:35 +02:00
Jonathon Jongsma
a94836a467 Remove duplicate streaming enumeration
There is already a enumeration in a public header that defines the
different streaming options, so there's no need to duplicate that
enumeration internally. Just use the public enum values.
2015-06-15 13:08:42 -05:00
Javier Celaya
7a081a7ced LZ4: warn if trying to set lz4 but not supported 2015-06-11 16:45:52 +02:00
Christophe Fergeau
14b7f5c8cf ppc: Fix endianness handling in initial SPICE connection
This commit fixes enough endianness issues that it's possible to
connect to a spice-server/qemu running on a big-endian box with a client
running on a little-endian machine.

I haven't tested more than getting to the bios/bootloader and typing a
bit on the keyboard as I did not manage to boot a distro afterwards :(

This is based on patches send by Erlon R. Cruz
<erlon.cruz@br.flextronics.com>
2015-04-10 20:16:54 +02:00
Marc-André Lureau
3c6b4e415f Remove spice-experimental
Remove unneded symbols that nobody should be using anyway.
ABI is modified with this patch, but the library version is not bumped.
2015-01-15 18:34:26 +01:00
Marc-André Lureau
72cc0cff71 Do not perform network tests on UNIX socket
By default, stream latency is 0 and bandwidth is infinite. On UNIX
socket do not perform unnecessary testing and keep those values.
2015-01-15 18:29:36 +01:00
Marc-André Lureau
5365caeaae reds: add Unix socket support
Learn to listen on a Unix address. In this case, the connection is plain
only (non-tls).
2015-01-15 18:29:36 +01:00
Marc-André Lureau
ea4e9f28bf Rename mm_timer/mm_time
As suggested by Christophe on the mailing list.
2014-11-27 14:32:37 +01:00
Marc-André Lureau
c541d7e29d Remove guest side video time-stamping
The multimedia time is defined by the server side monotonic time [1],
but the drawing time-stamp is done in guest side, so it requires
synchronization between host and guest. This is expensive, when no audio
is playing, there is a ~30x/sec wakeup to update the qxl device mmtime,
and it requires marking dirty the rom region.

Instead, the video timestamping can be done more efficiently on server
side, without visible drawbacks.

[1] a better timestamp could be the audio time, since audio players are
    usually sync with audio time)

Related to:
https://bugzilla.redhat.com/show_bug.cgi?id=912763
2014-11-27 14:27:41 +01:00
Christophe Fergeau
1ac4dfb317 Don't set SpiceLinkReply::pub_key if client advertises SASL cap
If the client advertises the SASL cap, it means it guarantees it will be
able to use SASL if the server supports, and that it does not need a valid
SpiceLinkReply::pub_key field when using SASL.

When the client cap is set, we thus don't need to create a RSA public key
if SASL is enabled server side.

The reason for needing client guarantees about not looking at the pub_key
field is that its presence and size is hardcoded in the protocol, but in
some hardened setups (using fips mode), generating a RSA 1024 bit key as
expected is forbidden and fails. With this new capability, the server
knows the client will be able to handle SASL if needed, and can skip
the generation of the key altogether. This means that on the setups
described above, SASL authentication has to be used.
2014-11-24 17:37:17 +01:00
Christophe Fergeau
24bebaa855 Introduce red_link_info_test_capability()
This just hides a bit of pointer arithmetic away from reds_send_link_ack.
This helper will be used in the next commits.
2014-11-24 17:37:17 +01:00
Uri Lublin
2d1c00a659 migration: Don't assert() if MIGRATE_DATA comes before attaching the agent
During seamless migration, after switching host, if a client was connected
during the migration, it will have data to send back to the new
qemu/spice-server instance. This is handled through MIGRATE_DATA messages.
SPICE char devices use such MIGRATE_DATA messages to restore their state.

However, the MIGRATE_DATA message can arrive any time after the new qemu
instance has started, this can happen before or after the SPICE char
devices have been created. In order to handle this, if the migrate data
arrives early, it's stored in reds->agent_state.mig_data, and
attach_to_red_agent() will restore the agent state as appropriate.

Unfortunately this does not work as expected, for main
channel (agent messages).
If attach_to_red_agent() is called before the MIGRATE_DATA
message reaches the server, all goes well,
but if MIGRATE_DATA reaches the server before
attach_to_red_agent() gets called, then some assert() gets
triggered in spice_char_device_state_restore():

((null):32507): Spice-ERROR **: char_device.c:937:spice_char_device_state_restore: assertion `dev->num_clients == 1 && dev->wait_for_migrate_data' failed
Thread 3 (Thread 0x7f406b543700 (LWP 32543)):
Thread 2 (Thread 0x7f40697ff700 (LWP 32586)):
Thread 1 (Thread 0x7f4079b45a40 (LWP 32507)):

When restoring state, a client must already be added to the
spice-char-device.
What happens is that a client is not being added to the char-device
when when MIGRATE_DATA arrives first, which leaves both
dev->num_clients and dev->wait_for_migrate_data value at 0.

This commit changes the logic in spice_server_char_device_add_interface(),
such that if there is migrate data pending in reds->agent_state.mig_data
but no client was added to the spice-char-device yet,
then first the client is added to the device by calling
spice_char_device_client_add(), and only then the state is restored.

=== How to Reproduce
To reproduce, add delays to the migration connection between
qmeu-kvm on the source host (SRC) and on the destination (DST).

Specifically I added a man in the middle DLY host between
migration ports from SRC to DST.

+-----+    +-----+     +-----+
| SRC |--> | DLY | --> | DST |
+-----+    +-----+     +-----+

DLY listens on port P1 (e.g. 4444) and DST listens on port
PINCOMING (e.g. 4444, from qemu-kvm '-incoming' command line option)

Precondition: make sure port P1 on DLY is accessible in iptables.
Option 1: use ssh tcp port forwarding
On DLY host run ssh:
  ssh DLY:P1:DST:PINCOMING DST
Then use the following migration command (on qemu-kvm monitor):
  client_migrate_info spice DST PSPICE
  migrate -d tcp:DLY:P1

Option 2: Use a simple proxy program that forwards
packets from SRC to DST while adding some delays.
The program runs on DLY, listens to port D1, upon
accept connects to DST:PINCOMING and forward all
packets from DLY:D1 to DST:PINCOMING.
Then use the same migrate command as in option 1:
  client_migrate_info spice DST PSPICE
  migrate -d tcp:DLY:P1

=== How to Reproduce Ends

This fixes https://bugzilla.redhat.com/show_bug.cgi?id=1035184

Based-on-a-patch-by: Christophe Fergeau <cfergeau@redhat.com>
2014-10-14 15:48:02 +03:00
Marc-André Lureau
5eb9967dbc clean-up: remove unused function 2014-09-08 14:49:29 +02:00
Marc-André Lureau
a434543eb1 reds: lookup corresponding channel id
In reds_send_link_ack(), lookup the channel with the same id as the link
message.

The bug was found during code review a while ago.

A reproducer bug was later reported:
https://bugzilla.redhat.com/show_bug.cgi?id=1058625
2014-09-08 14:48:08 +02:00
Christophe Fergeau
27f968afd2 Call correct SASL helper in reds_handle_auth_sasl_step
sasl_handle_auth_start() was called instead of reds_sasl_handle_auth_step()
2014-04-16 17:11:38 +02:00
Christophe Fergeau
17f89a348a Remove RedLinkInfo::async_read
9feed69 moved the async reader code to RedsStream so that it can be used
for the SASL authentication code. In particular, it introduced a
RedsStream::async_read member which is used by the SASL authentication code
for its async operations.

However, what was not done is to remove the now redundant
RedLinkInfo::async_read field. This causes failures when using SASL
authentication as the async read error callback is getting set
on the RedLinkInfo::async_read structure, but then the SASL code is trying
to use the RedeStream::async_read structure for its async IOs, which do not
have the needed error callback set.

This commit makes use of the newly introduced reds_stream_async_read()
helper in order to make use of RedsStream::async_read.
2014-04-16 17:11:38 +02:00
Christophe Fergeau
1148c97d4b Check RSA_generate_key_ex return value
This can fail in fips mode for example. If we ignore the failure, we'll get
a crash:

 #0  0x00007f38d63728a0 in BN_num_bits () from /lib64/libcrypto.so.10
 #1  0x00007f38d639661d in RSA_size () from /lib64/libcrypto.so.10
 #2  0x00007f38d7991762 in reds_handle_read_link_done () from /lib64/libspice-server.so.1
 #3  0x00007f38d7990c06 in spice_server_add_client () from /lib64/libspice-server.so.1
 #4  0x00007f38d7990c6a in reds_accept () from /lib64/libspice-server.so.1
 #5  0x00007f38dc0d2946 in qemu_iohandler_poll (pollfds=0x7f38dedce200, ret=755449965, ret@entry=1) at iohandler.c:143
 #6  0x00007f38dc0d6ea8 in main_loop_wait (nonblocking=<optimized out>) at main-loop.c:465
 #7  0x00007f38dbffd7c0 in main_loop () at vl.c:1988
 #8  main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at vl.c:4357

This commit will cause the client connection to fail but qemu won't
segfault.
2014-03-20 11:45:20 +01:00
Marc-André Lureau
25f6745202 Associate org.spice-space.webdav.0 port to webdav channel
For example, with qemu, a webdav channel can be created this way:

 -chardev spiceport,name=org.spice-space.webdav.0,...

And redirected to a virtio port:

 -device virtserialport,...,name=org.spice-space.webdav.0
2014-03-19 17:14:44 +01:00
Christophe Fergeau
660d63253d Fix test_capability() typo
It was spelt 'capabilty'
2014-03-13 17:13:38 +01:00
Christophe Fergeau
24e2e60a59 Fix typo in log message 2014-03-13 17:13:33 +01:00
Christophe Fergeau
28fa3b1b3f Introduce reds_stream_set_channel() 2014-01-20 12:15:42 +01:00
Christophe Fergeau
82511418a0 Introduce reds_stream_set_info_flag() 2014-01-20 12:15:42 +01:00
Christophe Fergeau
30fecf87f8 Introduce reds_stream_is_ssl() 2014-01-20 12:15:42 +01:00
Christophe Fergeau
7ff743c431 Move SASL authentication to reds_stream.h
SASL authentication mostly use members from RedsStream to do its work, so
it makes sense to have its code in reds_stream.c. This should allow to make
RedsStream::sasl private in the future.
2014-01-20 12:15:42 +01:00
Christophe Fergeau
9feed6940f Move async code to RedsStream
The AsyncRead structure in reds.h wraps an async read + callback to
be done on a stream. Moving it to reds_stream.h is needed in order
to move SASL authentication there.
2014-01-20 12:15:42 +01:00
Christophe Fergeau
cdaab7272c Move stream read/write callbacks to reds_stream.c
Now that stream creation and SSL enabling are done by helpers
in reds_stream.c, we can move the initialization of the vfunc
read/write pointers there too.
2014-01-20 12:15:41 +01:00
Christophe Fergeau
e0abf1adc2 Introduce reds_stream_new() helper
Initializing a new stream means initializing quite a few fields.
This commit factors this initialization in a dedicated reds_stream_new
helper. This also helps moving more code from reds.c to reds_stream.c
2014-01-20 12:15:41 +01:00
Christophe Fergeau
d533f72fe6 reds: Move SSL-related code to RedsStream
Code to initiate a SSL stream belongs there
2014-01-20 12:15:41 +01:00
Christophe Fergeau
e46743100f Move sync_write* to reds_stream.h
They are renamed to reds_stream_write*
2014-01-20 12:15:41 +01:00