diff options
-rwxr-xr-x | configure | 4 | ||||
-rw-r--r-- | include/glib-compat.h | 6 | ||||
-rw-r--r-- | migration/colo.c | 12 | ||||
-rw-r--r-- | monitor.c | 5 | ||||
-rw-r--r-- | net/slirp.c | 32 | ||||
-rw-r--r-- | qga/commands-posix.c | 60 | ||||
-rw-r--r-- | qga/commands-win32.c | 105 | ||||
-rw-r--r-- | qga/commands.c | 49 | ||||
-rw-r--r-- | qga/main.c | 23 | ||||
-rw-r--r-- | qga/qapi-schema.json | 88 | ||||
-rw-r--r-- | qga/vss-win32.h | 1 | ||||
-rw-r--r-- | qga/vss-win32/install.cpp | 28 | ||||
-rw-r--r-- | qga/vss-win32/install.h | 20 | ||||
-rw-r--r-- | qga/vss-win32/provider.cpp | 1 | ||||
-rw-r--r-- | qga/vss-win32/requester.cpp | 2 | ||||
-rw-r--r-- | qga/vss-win32/vss-common.h | 11 | ||||
-rw-r--r-- | qga/vss-win32/vss-handles.h | 14 | ||||
-rw-r--r-- | slirp/ip_icmp.c | 5 | ||||
-rw-r--r-- | slirp/sbuf.h | 4 | ||||
-rw-r--r-- | slirp/slirp.c | 494 | ||||
-rw-r--r-- | slirp/socket.h | 24 | ||||
-rw-r--r-- | slirp/tcp_var.h | 6 | ||||
-rw-r--r-- | slirp/tftp.c | 2 |
23 files changed, 721 insertions, 275 deletions
@@ -743,7 +743,7 @@ if test "$mingw32" = "yes" ; then sysconfdir="\${prefix}" local_statedir= confsuffix="" - libs_qga="-lws2_32 -lwinmm -lpowrprof -liphlpapi -lnetapi32 $libs_qga" + libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -liphlpapi -lnetapi32 $libs_qga" fi werror="" @@ -1271,7 +1271,7 @@ for config in $mak_wilds; do done # Enumerate public trace backends for --help output -trace_backend_list=$(echo $(grep -le '^PUBLIC = True$' scripts/tracetool/backend/*.py | sed -e 's/^.*\/\(.*\)\.py$/\1/')) +trace_backend_list=$(echo $(grep -le '^PUBLIC = True$' "$source_path"/scripts/tracetool/backend/*.py | sed -e 's/^.*\/\(.*\)\.py$/\1/')) if test x"$show_help" = x"yes" ; then cat << EOF diff --git a/include/glib-compat.h b/include/glib-compat.h index 863c8cf..fcffcd3 100644 --- a/include/glib-compat.h +++ b/include/glib-compat.h @@ -217,6 +217,12 @@ static inline void g_hash_table_add(GHashTable *hash_table, gpointer key) { g_hash_table_replace(hash_table, key, key); } + +static inline gboolean g_hash_table_contains(GHashTable *hash_table, + gpointer key) +{ + return g_hash_table_lookup_extended(hash_table, key, NULL, NULL); +} #endif #ifndef g_assert_true diff --git a/migration/colo.c b/migration/colo.c index c19eb3f..963c802 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -153,6 +153,7 @@ void qmp_xen_set_replication(bool enable, bool primary, bool has_failover, bool failover, Error **errp) { +#ifdef CONFIG_REPLICATION ReplicationMode mode = primary ? REPLICATION_MODE_PRIMARY : REPLICATION_MODE_SECONDARY; @@ -171,10 +172,14 @@ void qmp_xen_set_replication(bool enable, bool primary, } replication_stop_all(failover, failover ? NULL : errp); } +#else + abort(); +#endif } ReplicationStatus *qmp_query_xen_replication_status(Error **errp) { +#ifdef CONFIG_REPLICATION Error *err = NULL; ReplicationStatus *s = g_new0(ReplicationStatus, 1); @@ -189,11 +194,18 @@ ReplicationStatus *qmp_query_xen_replication_status(Error **errp) error_free(err); return s; +#else + abort(); +#endif } void qmp_xen_colo_do_checkpoint(Error **errp) { +#ifdef CONFIG_REPLICATION replication_do_checkpoint_all(errp); +#else + abort(); +#endif } static void colo_send_message(QEMUFile *f, COLOMessage msg, @@ -974,6 +974,11 @@ static void qmp_unregister_commands_hack(void) #ifndef CONFIG_SPICE qmp_unregister_command(&qmp_commands, "query-spice"); #endif +#ifndef CONFIG_REPLICATION + qmp_unregister_command(&qmp_commands, "xen-set-replication"); + qmp_unregister_command(&qmp_commands, "query-xen-replication-status"); + qmp_unregister_command(&qmp_commands, "xen-colo-do-checkpoint"); +#endif #ifndef TARGET_I386 qmp_unregister_command(&qmp_commands, "rtc-reset-reinjection"); #endif diff --git a/net/slirp.c b/net/slirp.c index f97ec23..c705a60 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -80,7 +80,7 @@ typedef struct SlirpState { Slirp *slirp; Notifier exit_notifier; #ifndef _WIN32 - char smb_dir[128]; + gchar *smb_dir; #endif } SlirpState; @@ -487,7 +487,7 @@ static int slirp_hostfwd(SlirpState *s, const char *redir_str, goto fail_syntax; } host_port = strtol(buf, &end, 0); - if (*end != '\0' || host_port < 1 || host_port > 65535) { + if (*end != '\0' || host_port < 0 || host_port > 65535) { goto fail_syntax; } @@ -558,11 +558,10 @@ int net_slirp_redir(const char *redir_str) /* automatic user mode samba server configuration */ static void slirp_smb_cleanup(SlirpState *s) { - char cmd[128]; int ret; - if (s->smb_dir[0] != '\0') { - snprintf(cmd, sizeof(cmd), "rm -rf %s", s->smb_dir); + if (s->smb_dir) { + gchar *cmd = g_strdup_printf("rm -rf %s", s->smb_dir); ret = system(cmd); if (ret == -1 || !WIFEXITED(ret)) { error_report("'%s' failed.", cmd); @@ -570,15 +569,17 @@ static void slirp_smb_cleanup(SlirpState *s) error_report("'%s' failed. Error code: %d", cmd, WEXITSTATUS(ret)); } - s->smb_dir[0] = '\0'; + g_free(cmd); + g_free(s->smb_dir); + s->smb_dir = NULL; } } static int slirp_smb(SlirpState* s, const char *exported_dir, struct in_addr vserver_addr) { - char smb_conf[128]; - char smb_cmdline[128]; + char *smb_conf; + char *smb_cmdline; struct passwd *passwd; FILE *f; @@ -600,19 +601,19 @@ static int slirp_smb(SlirpState* s, const char *exported_dir, return -1; } - snprintf(s->smb_dir, sizeof(s->smb_dir), "/tmp/qemu-smb.XXXXXX"); - if (!mkdtemp(s->smb_dir)) { - error_report("could not create samba server dir '%s'", s->smb_dir); - s->smb_dir[0] = 0; + s->smb_dir = g_dir_make_tmp("qemu-smb.XXXXXX", NULL); + if (!s->smb_dir) { + error_report("could not create samba server dir"); return -1; } - snprintf(smb_conf, sizeof(smb_conf), "%s/%s", s->smb_dir, "smb.conf"); + smb_conf = g_strdup_printf("%s/%s", s->smb_dir, "smb.conf"); f = fopen(smb_conf, "w"); if (!f) { slirp_smb_cleanup(s); error_report("could not create samba server configuration file '%s'", smb_conf); + g_free(smb_conf); return -1; } fprintf(f, @@ -651,15 +652,18 @@ static int slirp_smb(SlirpState* s, const char *exported_dir, ); fclose(f); - snprintf(smb_cmdline, sizeof(smb_cmdline), "%s -l %s -s %s", + smb_cmdline = g_strdup_printf("%s -l %s -s %s", CONFIG_SMBD_COMMAND, s->smb_dir, smb_conf); + g_free(smb_conf); if (slirp_add_exec(s->slirp, 0, smb_cmdline, &vserver_addr, 139) < 0 || slirp_add_exec(s->slirp, 0, smb_cmdline, &vserver_addr, 445) < 0) { slirp_smb_cleanup(s); + g_free(smb_cmdline); error_report("conflicting/invalid smbserver address"); return -1; } + g_free(smb_cmdline); return 0; } diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 915df9e..ba06be4 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -15,6 +15,7 @@ #include <sys/ioctl.h> #include <sys/wait.h> #include <dirent.h> +#include <utmpx.h> #include "qga/guest-agent-core.h" #include "qga-qmp-commands.h" #include "qapi/qmp/qerror.h" @@ -2517,3 +2518,62 @@ void ga_command_state_init(GAState *s, GACommandState *cs) ga_command_state_add(cs, NULL, guest_fsfreeze_cleanup); #endif } + +#define QGA_MICRO_SECOND_TO_SECOND 1000000 + +static double ga_get_login_time(struct utmpx *user_info) +{ + double seconds = (double)user_info->ut_tv.tv_sec; + double useconds = (double)user_info->ut_tv.tv_usec; + useconds /= QGA_MICRO_SECOND_TO_SECOND; + return seconds + useconds; +} + +GuestUserList *qmp_guest_get_users(Error **err) +{ + GHashTable *cache = NULL; + GuestUserList *head = NULL, *cur_item = NULL; + struct utmpx *user_info = NULL; + gpointer value = NULL; + GuestUser *user = NULL; + GuestUserList *item = NULL; + double login_time = 0; + + cache = g_hash_table_new(g_str_hash, g_str_equal); + setutxent(); + + for (;;) { + user_info = getutxent(); + if (user_info == NULL) { + break; + } else if (user_info->ut_type != USER_PROCESS) { + continue; + } else if (g_hash_table_contains(cache, user_info->ut_user)) { + value = g_hash_table_lookup(cache, user_info->ut_user); + user = (GuestUser *)value; + login_time = ga_get_login_time(user_info); + /* We're ensuring the earliest login time to be sent */ + if (login_time < user->login_time) { + user->login_time = login_time; + } + continue; + } + + item = g_new0(GuestUserList, 1); + item->value = g_new0(GuestUser, 1); + item->value->user = g_strdup(user_info->ut_user); + item->value->login_time = ga_get_login_time(user_info); + + g_hash_table_insert(cache, item->value->user, item->value); + + if (!cur_item) { + head = cur_item = item; + } else { + cur_item->next = item; + cur_item = item; + } + } + endutxent(); + g_hash_table_destroy(cache); + return head; +} diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 04026ee..439d229 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -11,6 +11,9 @@ * See the COPYING file in the top-level directory. */ +#ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x0600 +#endif #include "qemu/osdep.h" #include <wtypes.h> #include <powrprof.h> @@ -25,6 +28,7 @@ #include <initguid.h> #endif #include <lm.h> +#include <wtsapi32.h> #include "qga/guest-agent-core.h" #include "qga/vss-win32.h" @@ -1344,7 +1348,7 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) vcpu = g_malloc0(sizeof *vcpu); vcpu->logical_id = current++; vcpu->online = true; - vcpu->has_can_offline = false; + vcpu->has_can_offline = true; entry = g_malloc0(sizeof *entry); entry->value = vcpu; @@ -1536,3 +1540,102 @@ void ga_command_state_init(GAState *s, GACommandState *cs) ga_command_state_add(cs, NULL, guest_fsfreeze_cleanup); } } + +/* MINGW is missing two fields: IncomingFrames & OutgoingFrames */ +typedef struct _GA_WTSINFOA { + WTS_CONNECTSTATE_CLASS State; + DWORD SessionId; + DWORD IncomingBytes; + DWORD OutgoingBytes; + DWORD IncomingFrames; + DWORD OutgoingFrames; + DWORD IncomingCompressedBytes; + DWORD OutgoingCompressedBy; + CHAR WinStationName[WINSTATIONNAME_LENGTH]; + CHAR Domain[DOMAIN_LENGTH]; + CHAR UserName[USERNAME_LENGTH + 1]; + LARGE_INTEGER ConnectTime; + LARGE_INTEGER DisconnectTime; + LARGE_INTEGER LastInputTime; + LARGE_INTEGER LogonTime; + LARGE_INTEGER CurrentTime; + +} GA_WTSINFOA; + +GuestUserList *qmp_guest_get_users(Error **err) +{ +#if (_WIN32_WINNT >= 0x0600) +#define QGA_NANOSECONDS 10000000 + + GHashTable *cache = NULL; + GuestUserList *head = NULL, *cur_item = NULL; + + DWORD buffer_size = 0, count = 0, i = 0; + GA_WTSINFOA *info = NULL; + WTS_SESSION_INFOA *entries = NULL; + GuestUserList *item = NULL; + GuestUser *user = NULL; + gpointer value = NULL; + INT64 login = 0; + double login_time = 0; + + cache = g_hash_table_new(g_str_hash, g_str_equal); + + if (WTSEnumerateSessionsA(NULL, 0, 1, &entries, &count)) { + for (i = 0; i < count; ++i) { + buffer_size = 0; + info = NULL; + if (WTSQuerySessionInformationA( + NULL, + entries[i].SessionId, + WTSSessionInfo, + (LPSTR *)&info, + &buffer_size + )) { + + if (strlen(info->UserName) == 0) { + WTSFreeMemory(info); + continue; + } + + login = info->LogonTime.QuadPart; + login -= W32_FT_OFFSET; + login_time = ((double)login) / QGA_NANOSECONDS; + + if (g_hash_table_contains(cache, info->UserName)) { + value = g_hash_table_lookup(cache, info->UserName); + user = (GuestUser *)value; + if (user->login_time > login_time) { + user->login_time = login_time; + } + } else { + item = g_new0(GuestUserList, 1); + item->value = g_new0(GuestUser, 1); + + item->value->user = g_strdup(info->UserName); + item->value->domain = g_strdup(info->Domain); + item->value->has_domain = true; + + item->value->login_time = login_time; + + g_hash_table_add(cache, item->value->user); + + if (!cur_item) { + head = cur_item = item; + } else { + cur_item->next = item; + cur_item = item; + } + } + } + WTSFreeMemory(info); + } + WTSFreeMemory(entries); + } + g_hash_table_destroy(cache); + return head; +#else + error_setg(err, QERR_UNSUPPORTED); + return NULL; +#endif +} diff --git a/qga/commands.c b/qga/commands.c index 4d92946..3333ed5 100644 --- a/qga/commands.c +++ b/qga/commands.c @@ -499,3 +499,52 @@ int ga_parse_whence(GuestFileWhence *whence, Error **errp) error_setg(errp, "invalid whence code %"PRId64, whence->u.value); return -1; } + +GuestHostName *qmp_guest_get_host_name(Error **err) +{ + GuestHostName *result = NULL; + gchar const *hostname = g_get_host_name(); + if (hostname != NULL) { + result = g_new0(GuestHostName, 1); + result->host_name = g_strdup(hostname); + } + return result; +} + +GuestTimezone *qmp_guest_get_timezone(Error **errp) +{ +#if GLIB_CHECK_VERSION(2, 28, 0) + GuestTimezone *info = NULL; + GTimeZone *tz = NULL; + gint64 now = 0; + gint32 intv = 0; + gchar const *name = NULL; + + info = g_new0(GuestTimezone, 1); + tz = g_time_zone_new_local(); + if (tz == NULL) { + error_setg(errp, QERR_QGA_COMMAND_FAILED, + "Couldn't retrieve local timezone"); + goto error; + } + + now = g_get_real_time() / G_USEC_PER_SEC; + intv = g_time_zone_find_interval(tz, G_TIME_TYPE_UNIVERSAL, now); + info->offset = g_time_zone_get_offset(tz, intv); + name = g_time_zone_get_abbreviation(tz, intv); + if (name != NULL) { + info->has_zone = true; + info->zone = g_strdup(name); + } + g_time_zone_unref(tz); + + return info; + +error: + g_free(info); + return NULL; +#else + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +#endif +} @@ -131,9 +131,32 @@ static void quit_handler(int sig) * unless all log/pid files are on unfreezable filesystems. there's * also a very likely chance killing the agent before unfreezing * the filesystems is a mistake (or will be viewed as one later). + * On Windows the freeze interval is limited to 10 seconds, so + * we should quit, but first we should wait for the timeout, thaw + * the filesystem and quit. */ if (ga_is_frozen(ga_state)) { +#ifdef _WIN32 + int i = 0; + Error *err = NULL; + HANDLE hEventTimeout; + + g_debug("Thawing filesystems before exiting"); + + hEventTimeout = OpenEvent(EVENT_ALL_ACCESS, FALSE, EVENT_NAME_TIMEOUT); + if (hEventTimeout) { + WaitForSingleObject(hEventTimeout, 0); + CloseHandle(hEventTimeout); + } + qga_vss_fsfreeze(&i, false, &err); + if (err) { + g_debug("Error unfreezing filesystems prior to exiting: %s", + error_get_pretty(err)); + error_free(err); + } +#else return; +#endif } g_debug("received signal num %d, quitting", sig); diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index a02dbf2..03743ab 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -426,7 +426,13 @@ ## # @guest-fsfreeze-freeze: # -# Sync and freeze all freezable, local guest filesystems +# Sync and freeze all freezable, local guest filesystems. If this +# command succeeded, you may call @guest-fsfreeze-thaw later to +# unfreeze. +# +# Note: On Windows, the command is implemented with the help of a +# Volume Shadow-copy Service DLL helper. The frozen state is limited +# for up to 10 seconds by VSS. # # Returns: Number of file systems currently frozen. On error, all filesystems # will be thawed. @@ -439,10 +445,12 @@ ## # @guest-fsfreeze-freeze-list: # -# Sync and freeze specified guest filesystems +# Sync and freeze specified guest filesystems. +# See also @guest-fsfreeze-freeze. # # @mountpoints: an array of mountpoints of filesystems to be frozen. # If omitted, every mounted filesystem is frozen. +# Invalid mount points are ignored. # # Returns: Number of file systems currently frozen. On error, all filesystems # will be thawed. @@ -1042,3 +1050,79 @@ 'data': { 'path': 'str', '*arg': ['str'], '*env': ['str'], '*input-data': 'str', '*capture-output': 'bool' }, 'returns': 'GuestExec' } + + +## +# @GuestHostName: +# @host-name: Fully qualified domain name of the guest OS +# +# Since: 2.10 +## +{ 'struct': 'GuestHostName', + 'data': { 'host-name': 'str' } } + +## +# @guest-get-host-name: +# +# Return a name for the machine. +# +# The returned name is not necessarily a fully-qualified domain name, or even +# present in DNS or some other name service at all. It need not even be unique +# on your local network or site, but usually it is. +# +# Returns: the host name of the machine on success +# +# Since: 2.10 +## +{ 'command': 'guest-get-host-name', + 'returns': 'GuestHostName' } + + +## +# @GuestUser: +# @user: Username +# @domain: Logon domain (windows only) +# @login-time: Time of login of this user on the computer. If multiple +# instances of the user are logged in, the earliest login time is +# reported. The value is in fractional seconds since epoch time. +# +# Since: 2.10 +## +{ 'struct': 'GuestUser', + 'data': { 'user': 'str', 'login-time': 'number', '*domain': 'str' } } + +## +# @guest-get-users: +# Retrieves a list of currently active users on the VM. +# +# Returns: A unique list of users. +# +# Since: 2.10 +## +{ 'command': 'guest-get-users', + 'returns': ['GuestUser'] } + +## +# @GuestTimezone: +# +# @zone: Timezone name. These values may differ depending on guest/OS and +# should only be used for informational purposes. +# @offset: Offset to UTC in seconds, negative numbers for time zones west of +# GMT, positive numbers for east +# +# Since: 2.10 +## +{ 'struct': 'GuestTimezone', + 'data': { '*zone': 'str', 'offset': 'int' } } + +## +# @guest-get-timezone: +# +# Retrieves the timezone information from the guest. +# +# Returns: A GuestTimezone dictionary. +# +# Since: 2.10 +## +{ 'command': 'guest-get-timezone', + 'returns': 'GuestTimezone' } diff --git a/qga/vss-win32.h b/qga/vss-win32.h index 51d303a..4f8e39a 100644 --- a/qga/vss-win32.h +++ b/qga/vss-win32.h @@ -13,6 +13,7 @@ #ifndef VSS_WIN32_H #define VSS_WIN32_H +#include "qga/vss-win32/vss-handles.h" bool vss_init(bool init_requester); void vss_deinit(bool deinit_requester); diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp index f4160a3..f41fcdf 100644 --- a/qga/vss-win32/install.cpp +++ b/qga/vss-win32/install.cpp @@ -14,7 +14,7 @@ #include "vss-common.h" #include <inc/win2003/vscoordint.h> -#include <comadmin.h> +#include "install.h" #include <wbemidl.h> #include <comdef.h> #include <comutil.h> @@ -276,7 +276,7 @@ STDAPI COMRegister(void) chk(pCatalog->CreateServiceForApplication( _bstr_t(QGA_PROVIDER_LNAME), _bstr_t(QGA_PROVIDER_LNAME), - _bstr_t(L"SERVICE_AUTO_START"), _bstr_t(L"SERVICE_ERROR_NORMAL"), + _bstr_t(L"SERVICE_DEMAND_START"), _bstr_t(L"SERVICE_ERROR_NORMAL"), _bstr_t(L""), _bstr_t(L".\\localsystem"), _bstr_t(L""), FALSE)); chk(pCatalog->InstallComponent(_bstr_t(QGA_PROVIDER_LNAME), _bstr_t(dllPath), _bstr_t(tlbPath), @@ -461,3 +461,27 @@ namespace _com_util return bstr; } } + +/* Stop QGA VSS provider service from COM+ Application Admin Catalog */ + +STDAPI StopService(void) +{ + HRESULT hr; + COMInitializer initializer; + COMPointer<IUnknown> pUnknown; + COMPointer<ICOMAdminCatalog2> pCatalog; + + int count = 0; + + chk(QGAProviderFind(QGAProviderCount, (void *)&count)); + if (count) { + chk(CoCreateInstance(CLSID_COMAdminCatalog, NULL, CLSCTX_INPROC_SERVER, + IID_IUnknown, (void **)pUnknown.replace())); + chk(pUnknown->QueryInterface(IID_ICOMAdminCatalog2, + (void **)pCatalog.replace())); + chk(pCatalog->ShutdownApplication(_bstr_t(QGA_PROVIDER_LNAME))); + } + +out: + return hr; +} diff --git a/qga/vss-win32/install.h b/qga/vss-win32/install.h new file mode 100644 index 0000000..35364af --- /dev/null +++ b/qga/vss-win32/install.h @@ -0,0 +1,20 @@ +/* + * QEMU Guest Agent VSS requester declarations + * + * Copyright Hitachi Data Systems Corp. 2013 + * + * Authors: + * Tomoki Sekiyama <tomoki.sekiyama@hds.com> + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef INSTALL_H +#define INSTALL_H + +#include <comadmin.h> + +STDAPI StopService(void); + +#endif diff --git a/qga/vss-win32/provider.cpp b/qga/vss-win32/provider.cpp index ef94669..72d8b0e 100644 --- a/qga/vss-win32/provider.cpp +++ b/qga/vss-win32/provider.cpp @@ -377,7 +377,6 @@ STDMETHODIMP CQGAVssProvider::CommitSnapshots(VSS_ID SnapshotSetId) if (WaitForSingleObject(hEventThaw, VSS_TIMEOUT_MSEC) != WAIT_OBJECT_0) { /* Send event to qemu-ga to notify the provider is timed out */ SetEvent(hEventTimeout); - hr = E_ABORT; } CloseHandle(hEventThaw); diff --git a/qga/vss-win32/requester.cpp b/qga/vss-win32/requester.cpp index 0cd2f0e..301762d 100644 --- a/qga/vss-win32/requester.cpp +++ b/qga/vss-win32/requester.cpp @@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "vss-common.h" #include "requester.h" +#include "install.h" #include <inc/win2003/vswriter.h> #include <inc/win2003/vsbackup.h> @@ -501,4 +502,5 @@ void requester_thaw(int *num_vols, ErrorSet *errset) requester_cleanup(); CoUninitialize(); + StopService(); } diff --git a/qga/vss-win32/vss-common.h b/qga/vss-win32/vss-common.h index c81a856..61c170b 100644 --- a/qga/vss-win32/vss-common.h +++ b/qga/vss-win32/vss-common.h @@ -51,21 +51,12 @@ * http://www.microsoft.com/en-us/download/details.aspx?id=23490 */ #include <inc/win2003/vss.h> +#include "vss-handles.h" /* Macros to convert char definitions to wchar */ #define _L(a) L##a #define L(a) _L(a) -/* Constants for QGA VSS Provider */ - -#define QGA_PROVIDER_NAME "QEMU Guest Agent VSS Provider" -#define QGA_PROVIDER_LNAME L(QGA_PROVIDER_NAME) -#define QGA_PROVIDER_VERSION L(QEMU_VERSION) - -#define EVENT_NAME_FROZEN "Global\\QGAVSSEvent-frozen" -#define EVENT_NAME_THAW "Global\\QGAVSSEvent-thaw" -#define EVENT_NAME_TIMEOUT "Global\\QGAVSSEvent-timeout" - const GUID g_gProviderId = { 0x3629d4ed, 0xee09, 0x4e0e, {0x9a, 0x5c, 0x6d, 0x8b, 0xa2, 0x87, 0x2a, 0xef} }; const GUID g_gProviderVersion = { 0x11ef8b15, 0xcac6, 0x40d6, diff --git a/qga/vss-win32/vss-handles.h b/qga/vss-win32/vss-handles.h new file mode 100644 index 0000000..ff399dd --- /dev/null +++ b/qga/vss-win32/vss-handles.h @@ -0,0 +1,14 @@ +#ifndef VSS_HANDLES +#define VSS_HANDLES + +/* Constants for QGA VSS Provider */ + +#define QGA_PROVIDER_NAME "QEMU Guest Agent VSS Provider" +#define QGA_PROVIDER_LNAME L(QGA_PROVIDER_NAME) +#define QGA_PROVIDER_VERSION L(QEMU_VERSION) + +#define EVENT_NAME_FROZEN "Global\\QGAVSSEvent-frozen" +#define EVENT_NAME_THAW "Global\\QGAVSSEvent-thaw" +#define EVENT_NAME_TIMEOUT "Global\\QGAVSSEvent-timeout" + +#endif diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c index 5ffc7a6..0b667a4 100644 --- a/slirp/ip_icmp.c +++ b/slirp/ip_icmp.c @@ -152,8 +152,9 @@ icmp_input(struct mbuf *m, int hlen) switch (icp->icmp_type) { case ICMP_ECHO: ip->ip_len += hlen; /* since ip_input subtracts this */ - if (ip->ip_dst.s_addr == slirp->vhost_addr.s_addr) { - icmp_reflect(m); + if (ip->ip_dst.s_addr == slirp->vhost_addr.s_addr || + ip->ip_dst.s_addr == slirp->vnameserver_addr.s_addr) { + icmp_reflect(m); } else if (slirp->restricted) { goto freeit; } else { diff --git a/slirp/sbuf.h b/slirp/sbuf.h index efcec39..a722ecb 100644 --- a/slirp/sbuf.h +++ b/slirp/sbuf.h @@ -12,8 +12,8 @@ #define sbspace(sb) ((sb)->sb_datalen - (sb)->sb_cc) struct sbuf { - u_int sb_cc; /* actual chars in buffer */ - u_int sb_datalen; /* Length of data */ + uint32_t sb_cc; /* actual chars in buffer */ + uint32_t sb_datalen; /* Length of data */ char *sb_wptr; /* write pointer. points to where the next * bytes should be written in the sbuf */ char *sb_rptr; /* read pointer. points to where the next diff --git a/slirp/slirp.c b/slirp/slirp.c index 9a50918..2f2ec2c 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -1133,259 +1133,317 @@ void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr, int guest_port, tcp_output(sototcpcb(so)); } -static void slirp_tcp_save(QEMUFile *f, struct tcpcb *tp) +static int slirp_tcp_post_load(void *opaque, int version) { - int i; - - qemu_put_sbe16(f, tp->t_state); - for (i = 0; i < TCPT_NTIMERS; i++) - qemu_put_sbe16(f, tp->t_timer[i]); - qemu_put_sbe16(f, tp->t_rxtshift); - qemu_put_sbe16(f, tp->t_rxtcur); - qemu_put_sbe16(f, tp->t_dupacks); - qemu_put_be16(f, tp->t_maxseg); - qemu_put_sbyte(f, tp->t_force); - qemu_put_be16(f, tp->t_flags); - qemu_put_be32(f, tp->snd_una); - qemu_put_be32(f, tp->snd_nxt); - qemu_put_be32(f, tp->snd_up); - qemu_put_be32(f, tp->snd_wl1); - qemu_put_be32(f, tp->snd_wl2); - qemu_put_be32(f, tp->iss); - qemu_put_be32(f, tp->snd_wnd); - qemu_put_be32(f, tp->rcv_wnd); - qemu_put_be32(f, tp->rcv_nxt); - qemu_put_be32(f, tp->rcv_up); - qemu_put_be32(f, tp->irs); - qemu_put_be32(f, tp->rcv_adv); - qemu_put_be32(f, tp->snd_max); - qemu_put_be32(f, tp->snd_cwnd); - qemu_put_be32(f, tp->snd_ssthresh); - qemu_put_sbe16(f, tp->t_idle); - qemu_put_sbe16(f, tp->t_rtt); - qemu_put_be32(f, tp->t_rtseq); - qemu_put_sbe16(f, tp->t_srtt); - qemu_put_sbe16(f, tp->t_rttvar); - qemu_put_be16(f, tp->t_rttmin); - qemu_put_be32(f, tp->max_sndwnd); - qemu_put_byte(f, tp->t_oobflags); - qemu_put_byte(f, tp->t_iobc); - qemu_put_sbe16(f, tp->t_softerror); - qemu_put_byte(f, tp->snd_scale); - qemu_put_byte(f, tp->rcv_scale); - qemu_put_byte(f, tp->request_r_scale); - qemu_put_byte(f, tp->requested_s_scale); - qemu_put_be32(f, tp->ts_recent); - qemu_put_be32(f, tp->ts_recent_age); - qemu_put_be32(f, tp->last_ack_sent); + tcp_template((struct tcpcb *)opaque); + + return 0; } -static void slirp_sbuf_save(QEMUFile *f, struct sbuf *sbuf) +static const VMStateDescription vmstate_slirp_tcp = { + .name = "slirp-tcp", + .version_id = 0, + .post_load = slirp_tcp_post_load, + .fields = (VMStateField[]) { + VMSTATE_INT16(t_state, struct tcpcb), + VMSTATE_INT16_ARRAY(t_timer, struct tcpcb, TCPT_NTIMERS), + VMSTATE_INT16(t_rxtshift, struct tcpcb), + VMSTATE_INT16(t_rxtcur, struct tcpcb), + VMSTATE_INT16(t_dupacks, struct tcpcb), + VMSTATE_UINT16(t_maxseg, struct tcpcb), + VMSTATE_UINT8(t_force, struct tcpcb), + VMSTATE_UINT16(t_flags, struct tcpcb), + VMSTATE_UINT32(snd_una, struct tcpcb), + VMSTATE_UINT32(snd_nxt, struct tcpcb), + VMSTATE_UINT32(snd_up, struct tcpcb), + VMSTATE_UINT32(snd_wl1, struct tcpcb), + VMSTATE_UINT32(snd_wl2, struct tcpcb), + VMSTATE_UINT32(iss, struct tcpcb), + VMSTATE_UINT32(snd_wnd, struct tcpcb), + VMSTATE_UINT32(rcv_wnd, struct tcpcb), + VMSTATE_UINT32(rcv_nxt, struct tcpcb), + VMSTATE_UINT32(rcv_up, struct tcpcb), + VMSTATE_UINT32(irs, struct tcpcb), + VMSTATE_UINT32(rcv_adv, struct tcpcb), + VMSTATE_UINT32(snd_max, struct tcpcb), + VMSTATE_UINT32(snd_cwnd, struct tcpcb), + VMSTATE_UINT32(snd_ssthresh, struct tcpcb), + VMSTATE_INT16(t_idle, struct tcpcb), + VMSTATE_INT16(t_rtt, struct tcpcb), + VMSTATE_UINT32(t_rtseq, struct tcpcb), + VMSTATE_INT16(t_srtt, struct tcpcb), + VMSTATE_INT16(t_rttvar, struct tcpcb), + VMSTATE_UINT16(t_rttmin, struct tcpcb), + VMSTATE_UINT32(max_sndwnd, struct tcpcb), + VMSTATE_UINT8(t_oobflags, struct tcpcb), + VMSTATE_UINT8(t_iobc, struct tcpcb), + VMSTATE_INT16(t_softerror, struct tcpcb), + VMSTATE_UINT8(snd_scale, struct tcpcb), + VMSTATE_UINT8(rcv_scale, struct tcpcb), + VMSTATE_UINT8(request_r_scale, struct tcpcb), + VMSTATE_UINT8(requested_s_scale, struct tcpcb), + VMSTATE_UINT32(ts_recent, struct tcpcb), + VMSTATE_UINT32(ts_recent_age, struct tcpcb), + VMSTATE_UINT32(last_ack_sent, struct tcpcb), + VMSTATE_END_OF_LIST() + } +}; + +/* The sbuf has a pair of pointers that are migrated as offsets; + * we calculate the offsets and restore the pointers using + * pre_save/post_load on a tmp structure. + */ +struct sbuf_tmp { + struct sbuf *parent; + uint32_t roff, woff; +}; + +static void sbuf_tmp_pre_save(void *opaque) { - uint32_t off; - - qemu_put_be32(f, sbuf->sb_cc); - qemu_put_be32(f, sbuf->sb_datalen); - off = (uint32_t)(sbuf->sb_wptr - sbuf->sb_data); - qemu_put_sbe32(f, off); - off = (uint32_t)(sbuf->sb_rptr - sbuf->sb_data); - qemu_put_sbe32(f, off); - qemu_put_buffer(f, (unsigned char*)sbuf->sb_data, sbuf->sb_datalen); + struct sbuf_tmp *tmp = opaque; + tmp->woff = tmp->parent->sb_wptr - tmp->parent->sb_data; + tmp->roff = tmp->parent->sb_rptr - tmp->parent->sb_data; } -static void slirp_socket_save(QEMUFile *f, struct socket *so) +static int sbuf_tmp_post_load(void *opaque, int version) { - qemu_put_be32(f, so->so_urgc); - qemu_put_be16(f, so->so_ffamily); - switch (so->so_ffamily) { - case AF_INET: - qemu_put_be32(f, so->so_faddr.s_addr); - qemu_put_be16(f, so->so_fport); - break; - default: - error_report("so_ffamily unknown, unable to save so_faddr and" - " so_fport"); + struct sbuf_tmp *tmp = opaque; + uint32_t requested_len = tmp->parent->sb_datalen; + + /* Allocate the buffer space used by the field after the tmp */ + sbreserve(tmp->parent, tmp->parent->sb_datalen); + + if (tmp->parent->sb_datalen != requested_len) { + return -ENOMEM; } - qemu_put_be16(f, so->so_lfamily); - switch (so->so_lfamily) { - case AF_INET: - qemu_put_be32(f, so->so_laddr.s_addr); - qemu_put_be16(f, so->so_lport); - break; - default: - error_report("so_ffamily unknown, unable to save so_laddr and" - " so_lport"); + if (tmp->woff >= requested_len || + tmp->roff >= requested_len) { + error_report("invalid sbuf offsets r/w=%u/%u len=%u", + tmp->roff, tmp->woff, requested_len); + return -EINVAL; } - qemu_put_byte(f, so->so_iptos); - qemu_put_byte(f, so->so_emu); - qemu_put_byte(f, so->so_type); - qemu_put_be32(f, so->so_state); - slirp_sbuf_save(f, &so->so_rcv); - slirp_sbuf_save(f, &so->so_snd); - slirp_tcp_save(f, so->so_tcpcb); -} -static void slirp_bootp_save(QEMUFile *f, Slirp *slirp) -{ - int i; + tmp->parent->sb_wptr = tmp->parent->sb_data + tmp->woff; + tmp->parent->sb_rptr = tmp->parent->sb_data + tmp->roff; - for (i = 0; i < NB_BOOTP_CLIENTS; i++) { - qemu_put_be16(f, slirp->bootp_clients[i].allocated); - qemu_put_buffer(f, slirp->bootp_clients[i].macaddr, 6); - } + return 0; } -static void slirp_state_save(QEMUFile *f, void *opaque) -{ - Slirp *slirp = opaque; - struct ex_list *ex_ptr; - - for (ex_ptr = slirp->exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) - if (ex_ptr->ex_pty == 3) { - struct socket *so; - so = slirp_find_ctl_socket(slirp, ex_ptr->ex_addr, - ntohs(ex_ptr->ex_fport)); - if (!so) - continue; - qemu_put_byte(f, 42); - slirp_socket_save(f, so); - } - qemu_put_byte(f, 0); +static const VMStateDescription vmstate_slirp_sbuf_tmp = { + .name = "slirp-sbuf-tmp", + .post_load = sbuf_tmp_post_load, + .pre_save = sbuf_tmp_pre_save, + .version_id = 0, + .fields = (VMStateField[]) { + VMSTATE_UINT32(woff, struct sbuf_tmp), + VMSTATE_UINT32(roff, struct sbuf_tmp), + VMSTATE_END_OF_LIST() + } +}; - qemu_put_be16(f, slirp->ip_id); +static const VMStateDescription vmstate_slirp_sbuf = { + .name = "slirp-sbuf", + .version_id = 0, + .fields = (VMStateField[]) { + VMSTATE_UINT32(sb_cc, struct sbuf), + VMSTATE_UINT32(sb_datalen, struct sbuf), + VMSTATE_WITH_TMP(struct sbuf, struct sbuf_tmp, vmstate_slirp_sbuf_tmp), + VMSTATE_VBUFFER_UINT32(sb_data, struct sbuf, 0, NULL, sb_datalen), + VMSTATE_END_OF_LIST() + } +}; - slirp_bootp_save(f, slirp); +static bool slirp_older_than_v4(void *opaque, int version_id) +{ + return version_id < 4; } -static void slirp_tcp_load(QEMUFile *f, struct tcpcb *tp) +static bool slirp_family_inet(void *opaque, int version_id) { - int i; - - tp->t_state = qemu_get_sbe16(f); - for (i = 0; i < TCPT_NTIMERS; i++) - tp->t_timer[i] = qemu_get_sbe16(f); - tp->t_rxtshift = qemu_get_sbe16(f); - tp->t_rxtcur = qemu_get_sbe16(f); - tp->t_dupacks = qemu_get_sbe16(f); - tp->t_maxseg = qemu_get_be16(f); - tp->t_force = qemu_get_sbyte(f); - tp->t_flags = qemu_get_be16(f); - tp->snd_una = qemu_get_be32(f); - tp->snd_nxt = qemu_get_be32(f); - tp->snd_up = qemu_get_be32(f); - tp->snd_wl1 = qemu_get_be32(f); - tp->snd_wl2 = qemu_get_be32(f); - tp->iss = qemu_get_be32(f); - tp->snd_wnd = qemu_get_be32(f); - tp->rcv_wnd = qemu_get_be32(f); - tp->rcv_nxt = qemu_get_be32(f); - tp->rcv_up = qemu_get_be32(f); - tp->irs = qemu_get_be32(f); - tp->rcv_adv = qemu_get_be32(f); - tp->snd_max = qemu_get_be32(f); - tp->snd_cwnd = qemu_get_be32(f); - tp->snd_ssthresh = qemu_get_be32(f); - tp->t_idle = qemu_get_sbe16(f); - tp->t_rtt = qemu_get_sbe16(f); - tp->t_rtseq = qemu_get_be32(f); - tp->t_srtt = qemu_get_sbe16(f); - tp->t_rttvar = qemu_get_sbe16(f); - tp->t_rttmin = qemu_get_be16(f); - tp->max_sndwnd = qemu_get_be32(f); - tp->t_oobflags = qemu_get_byte(f); - tp->t_iobc = qemu_get_byte(f); - tp->t_softerror = qemu_get_sbe16(f); - tp->snd_scale = qemu_get_byte(f); - tp->rcv_scale = qemu_get_byte(f); - tp->request_r_scale = qemu_get_byte(f); - tp->requested_s_scale = qemu_get_byte(f); - tp->ts_recent = qemu_get_be32(f); - tp->ts_recent_age = qemu_get_be32(f); - tp->last_ack_sent = qemu_get_be32(f); - tcp_template(tp); + union slirp_sockaddr *ssa = (union slirp_sockaddr *)opaque; + return ssa->ss.ss_family == AF_INET; } -static int slirp_sbuf_load(QEMUFile *f, struct sbuf *sbuf) +static int slirp_socket_pre_load(void *opaque) { - uint32_t off, sb_cc, sb_datalen; + struct socket *so = opaque; + if (tcp_attach(so) < 0) { + return -ENOMEM; + } + /* Older versions don't load these fields */ + so->so_ffamily = AF_INET; + so->so_lfamily = AF_INET; + return 0; +} - sb_cc = qemu_get_be32(f); - sb_datalen = qemu_get_be32(f); +#ifndef _WIN32 +#define VMSTATE_SIN4_ADDR(f, s, t) VMSTATE_UINT32_TEST(f, s, t) +#else +/* Win uses u_long rather than uint32_t - but it's still 32bits long */ +#define VMSTATE_SIN4_ADDR(f, s, t) VMSTATE_SINGLE_TEST(f, s, t, 0, \ + vmstate_info_uint32, u_long) +#endif - sbreserve(sbuf, sb_datalen); +/* The OS provided ss_family field isn't that portable; it's size + * and type varies (16/8 bit, signed, unsigned) + * and the values it contains aren't fully portable. + */ +typedef struct SS_FamilyTmpStruct { + union slirp_sockaddr *parent; + uint16_t portable_family; +} SS_FamilyTmpStruct; - if (sbuf->sb_datalen != sb_datalen) - return -ENOMEM; +#define SS_FAMILY_MIG_IPV4 2 /* Linux, BSD, Win... */ +#define SS_FAMILY_MIG_IPV6 10 /* Linux */ +#define SS_FAMILY_MIG_OTHER 0xffff - sbuf->sb_cc = sb_cc; +static void ss_family_pre_save(void *opaque) +{ + SS_FamilyTmpStruct *tss = opaque; - off = qemu_get_sbe32(f); - sbuf->sb_wptr = sbuf->sb_data + off; - off = qemu_get_sbe32(f); - sbuf->sb_rptr = sbuf->sb_data + off; - qemu_get_buffer(f, (unsigned char*)sbuf->sb_data, sbuf->sb_datalen); + tss->portable_family = SS_FAMILY_MIG_OTHER; - return 0; + if (tss->parent->ss.ss_family == AF_INET) { + tss->portable_family = SS_FAMILY_MIG_IPV4; + } else if (tss->parent->ss.ss_family == AF_INET6) { + tss->portable_family = SS_FAMILY_MIG_IPV6; + } } -static int slirp_socket_load(QEMUFile *f, struct socket *so, int version_id) +static int ss_family_post_load(void *opaque, int version_id) { - if (tcp_attach(so) < 0) - return -ENOMEM; + SS_FamilyTmpStruct *tss = opaque; - so->so_urgc = qemu_get_be32(f); - if (version_id <= 3) { - so->so_ffamily = AF_INET; - so->so_faddr.s_addr = qemu_get_be32(f); - so->so_laddr.s_addr = qemu_get_be32(f); - so->so_fport = qemu_get_be16(f); - so->so_lport = qemu_get_be16(f); - } else { - so->so_ffamily = qemu_get_be16(f); - switch (so->so_ffamily) { - case AF_INET: - so->so_faddr.s_addr = qemu_get_be32(f); - so->so_fport = qemu_get_be16(f); - break; - default: - error_report( - "so_ffamily unknown, unable to restore so_faddr and so_lport"); - } - so->so_lfamily = qemu_get_be16(f); - switch (so->so_lfamily) { - case AF_INET: - so->so_laddr.s_addr = qemu_get_be32(f); - so->so_lport = qemu_get_be16(f); - break; - default: - error_report( - "so_ffamily unknown, unable to restore so_laddr and so_lport"); - } + switch (tss->portable_family) { + case SS_FAMILY_MIG_IPV4: + tss->parent->ss.ss_family = AF_INET; + break; + case SS_FAMILY_MIG_IPV6: + case 23: /* compatibility: AF_INET6 from mingw */ + case 28: /* compatibility: AF_INET6 from FreeBSD sys/socket.h */ + tss->parent->ss.ss_family = AF_INET6; + break; + default: + error_report("invalid ss_family type %x", tss->portable_family); + return -EINVAL; } - so->so_iptos = qemu_get_byte(f); - so->so_emu = qemu_get_byte(f); - so->so_type = qemu_get_byte(f); - so->so_state = qemu_get_be32(f); - if (slirp_sbuf_load(f, &so->so_rcv) < 0) - return -ENOMEM; - if (slirp_sbuf_load(f, &so->so_snd) < 0) - return -ENOMEM; - slirp_tcp_load(f, so->so_tcpcb); return 0; } -static void slirp_bootp_load(QEMUFile *f, Slirp *slirp) -{ - int i; +static const VMStateDescription vmstate_slirp_ss_family = { + .name = "slirp-socket-addr/ss_family", + .pre_save = ss_family_pre_save, + .post_load = ss_family_post_load, + .fields = (VMStateField[]) { + VMSTATE_UINT16(portable_family, SS_FamilyTmpStruct), + VMSTATE_END_OF_LIST() + } +}; - for (i = 0; i < NB_BOOTP_CLIENTS; i++) { - slirp->bootp_clients[i].allocated = qemu_get_be16(f); - qemu_get_buffer(f, slirp->bootp_clients[i].macaddr, 6); +static const VMStateDescription vmstate_slirp_socket_addr = { + .name = "slirp-socket-addr", + .version_id = 4, + .fields = (VMStateField[]) { + VMSTATE_WITH_TMP(union slirp_sockaddr, SS_FamilyTmpStruct, + vmstate_slirp_ss_family), + VMSTATE_SIN4_ADDR(sin.sin_addr.s_addr, union slirp_sockaddr, + slirp_family_inet), + VMSTATE_UINT16_TEST(sin.sin_port, union slirp_sockaddr, + slirp_family_inet), + +#if 0 + /* Untested: Needs checking by someone with IPv6 test */ + VMSTATE_BUFFER_TEST(sin6.sin6_addr, union slirp_sockaddr, + slirp_family_inet6), + VMSTATE_UINT16_TEST(sin6.sin6_port, union slirp_sockaddr, + slirp_family_inet6), + VMSTATE_UINT32_TEST(sin6.sin6_flowinfo, union slirp_sockaddr, + slirp_family_inet6), + VMSTATE_UINT32_TEST(sin6.sin6_scope_id, union slirp_sockaddr, + slirp_family_inet6), +#endif + + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_slirp_socket = { + .name = "slirp-socket", + .version_id = 4, + .pre_load = slirp_socket_pre_load, + .fields = (VMStateField[]) { + VMSTATE_UINT32(so_urgc, struct socket), + /* Pre-v4 versions */ + VMSTATE_SIN4_ADDR(so_faddr.s_addr, struct socket, + slirp_older_than_v4), + VMSTATE_SIN4_ADDR(so_laddr.s_addr, struct socket, + slirp_older_than_v4), + VMSTATE_UINT16_TEST(so_fport, struct socket, slirp_older_than_v4), + VMSTATE_UINT16_TEST(so_lport, struct socket, slirp_older_than_v4), + /* v4 and newer */ + VMSTATE_STRUCT(fhost, struct socket, 4, vmstate_slirp_socket_addr, + union slirp_sockaddr), + VMSTATE_STRUCT(lhost, struct socket, 4, vmstate_slirp_socket_addr, + union slirp_sockaddr), + + VMSTATE_UINT8(so_iptos, struct socket), + VMSTATE_UINT8(so_emu, struct socket), + VMSTATE_UINT8(so_type, struct socket), + VMSTATE_INT32(so_state, struct socket), + VMSTATE_STRUCT(so_rcv, struct socket, 0, vmstate_slirp_sbuf, + struct sbuf), + VMSTATE_STRUCT(so_snd, struct socket, 0, vmstate_slirp_sbuf, + struct sbuf), + VMSTATE_STRUCT_POINTER(so_tcpcb, struct socket, vmstate_slirp_tcp, + struct tcpcb), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_slirp_bootp_client = { + .name = "slirp_bootpclient", + .fields = (VMStateField[]) { + VMSTATE_UINT16(allocated, BOOTPClient), + VMSTATE_BUFFER(macaddr, BOOTPClient), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_slirp = { + .name = "slirp", + .version_id = 4, + .fields = (VMStateField[]) { + VMSTATE_UINT16_V(ip_id, Slirp, 2), + VMSTATE_STRUCT_ARRAY(bootp_clients, Slirp, NB_BOOTP_CLIENTS, 3, + vmstate_slirp_bootp_client, BOOTPClient), + VMSTATE_END_OF_LIST() } +}; + +static void slirp_state_save(QEMUFile *f, void *opaque) +{ + Slirp *slirp = opaque; + struct ex_list *ex_ptr; + + for (ex_ptr = slirp->exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) + if (ex_ptr->ex_pty == 3) { + struct socket *so; + so = slirp_find_ctl_socket(slirp, ex_ptr->ex_addr, + ntohs(ex_ptr->ex_fport)); + if (!so) + continue; + + qemu_put_byte(f, 42); + vmstate_save_state(f, &vmstate_slirp_socket, so, NULL); + } + qemu_put_byte(f, 0); + + vmstate_save_state(f, &vmstate_slirp, slirp, NULL); } + static int slirp_state_load(QEMUFile *f, void *opaque, int version_id) { Slirp *slirp = opaque; @@ -1398,7 +1456,7 @@ static int slirp_state_load(QEMUFile *f, void *opaque, int version_id) if (!so) return -ENOMEM; - ret = slirp_socket_load(f, so, version_id); + ret = vmstate_load_state(f, &vmstate_slirp_socket, so, version_id); if (ret < 0) return ret; @@ -1420,13 +1478,5 @@ static int slirp_state_load(QEMUFile *f, void *opaque, int version_id) so->extra = (void *)ex_ptr->ex_exec; } - if (version_id >= 2) { - slirp->ip_id = qemu_get_be16(f); - } - - if (version_id >= 3) { - slirp_bootp_load(f, slirp); - } - - return 0; + return vmstate_load_state(f, &vmstate_slirp, slirp, version_id); } diff --git a/slirp/socket.h b/slirp/socket.h index 8feed2a..2f224bc 100644 --- a/slirp/socket.h +++ b/slirp/socket.h @@ -15,6 +15,12 @@ * Our socket structure */ +union slirp_sockaddr { + struct sockaddr_storage ss; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; +}; + struct socket { struct socket *so_next,*so_prev; /* For a linked list of sockets */ @@ -30,23 +36,15 @@ struct socket { * PING reply's */ struct tcpiphdr *so_ti; /* Pointer to the original ti within * so_mconn, for non-blocking connections */ - int so_urgc; - union { /* foreign host */ - struct sockaddr_storage ss; - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - } fhost; + uint32_t so_urgc; + union slirp_sockaddr fhost; /* Foreign host */ #define so_faddr fhost.sin.sin_addr #define so_fport fhost.sin.sin_port #define so_faddr6 fhost.sin6.sin6_addr #define so_fport6 fhost.sin6.sin6_port #define so_ffamily fhost.ss.ss_family - union { /* local host */ - struct sockaddr_storage ss; - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - } lhost; + union slirp_sockaddr lhost; /* Local host */ #define so_laddr lhost.sin.sin_addr #define so_lport lhost.sin.sin_port #define so_laddr6 lhost.sin6.sin6_addr @@ -56,8 +54,8 @@ struct socket { uint8_t so_iptos; /* Type of service */ uint8_t so_emu; /* Is the socket emulated? */ - u_char so_type; /* Type of socket, UDP or TCP */ - int so_state; /* internal state flags SS_*, below */ + uint8_t so_type; /* Type of socket, UDP or TCP */ + int32_t so_state; /* internal state flags SS_*, below */ struct tcpcb *so_tcpcb; /* pointer to TCP protocol control block */ u_int so_expire; /* When the socket will expire */ diff --git a/slirp/tcp_var.h b/slirp/tcp_var.h index 0f8f187..895ef6d 100644 --- a/slirp/tcp_var.h +++ b/slirp/tcp_var.h @@ -48,7 +48,7 @@ struct tcpcb { short t_rxtcur; /* current retransmit value */ short t_dupacks; /* consecutive dup acks recd */ u_short t_maxseg; /* maximum segment size */ - char t_force; /* 1 if forcing out a byte */ + uint8_t t_force; /* 1 if forcing out a byte */ u_short t_flags; #define TF_ACKNOW 0x0001 /* ack peer immediately */ #define TF_DELACK 0x0002 /* ack, but try to delay it */ @@ -109,8 +109,8 @@ struct tcpcb { uint32_t max_sndwnd; /* largest window peer has offered */ /* out-of-band data */ - char t_oobflags; /* have some */ - char t_iobc; /* input character */ + uint8_t t_oobflags; /* have some */ + uint8_t t_iobc; /* input character */ #define TCPOOB_HAVEDATA 0x01 #define TCPOOB_HADDATA 0x02 short t_softerror; /* possible error not yet reported */ diff --git a/slirp/tftp.c b/slirp/tftp.c index 50e7148..a9bc4bb 100644 --- a/slirp/tftp.c +++ b/slirp/tftp.c @@ -70,7 +70,7 @@ static int tftp_session_allocate(Slirp *slirp, struct sockaddr_storage *srcsas, found: memset(spt, 0, sizeof(*spt)); - spt->client_addr = *srcsas; + memcpy(&spt->client_addr, srcsas, sockaddr_size(srcsas)); spt->fd = -1; spt->block_size = 512; spt->client_port = tp->udp.uh_sport; |