summaryrefslogtreecommitdiff
path: root/slirp
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2019-02-12 17:25:19 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2019-03-07 12:46:31 +0100
commitd890344166449c2c4cc039f19af61600920cd697 (patch)
tree39c0a5a5c95d4bc9bcc2005a7782762b006c649b /slirp
parentb92a1ff497dd2f84902b252ad3de22fcc33b60e3 (diff)
slirp: use libslirp migration code
slirp migration code uses QEMU vmstate so far, when building WITH_QEMU. Introduce slirp_state_{load,save,version}() functions to move the state saving handling to libslirp side. So far, the bitstream compatibility should remain equal with current QEMU, as this is effectively using the same code, with the same format etc. When libslirp is made standalone, we will need some mechanism to ensure bitstream compatibility regardless of the libslirp version installed. See the FIXME note in the code. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20190212162524.31504-3-marcandre.lureau@redhat.com> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Diffstat (limited to 'slirp')
-rw-r--r--slirp/libslirp.h8
-rw-r--r--slirp/slirp.c9
-rw-r--r--slirp/state.c52
-rw-r--r--slirp/state.h9
4 files changed, 31 insertions, 47 deletions
diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index 57bd6f597c..2d13950065 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -102,6 +102,14 @@ void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr,
int guest_port, const uint8_t *buf, int size);
size_t slirp_socket_can_recv(Slirp *slirp, struct in_addr guest_addr,
int guest_port);
+
+void slirp_state_save(Slirp *s, SlirpWriteCb write_cb, void *opaque);
+
+int slirp_state_load(Slirp *s, int version_id,
+ SlirpReadCb read_cb, void *opaque);
+
+int slirp_state_version(void);
+
#ifdef __cplusplus
} /* extern "C" */
#endif
diff --git a/slirp/slirp.c b/slirp/slirp.c
index cbdf9f778d..18af670a0a 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -23,9 +23,6 @@
*/
#include "slirp.h"
-#ifdef WITH_QEMU
-#include "state.h"
-#endif
#ifndef _WIN32
#include <net/if.h>
@@ -326,9 +323,6 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
translate_dnssearch(slirp, vdnssearch);
}
-#ifdef WITH_QEMU
- slirp_state_register(slirp);
-#endif
return slirp;
}
@@ -342,9 +336,6 @@ void slirp_cleanup(Slirp *slirp)
g_free(e);
}
-#ifdef WITH_QEMU
- slirp_state_unregister(slirp);
-#endif
ip_cleanup(slirp);
ip6_cleanup(slirp);
m_cleanup(slirp);
diff --git a/slirp/state.c b/slirp/state.c
index 0e5a706e87..f5dd80cdc8 100644
--- a/slirp/state.c
+++ b/slirp/state.c
@@ -21,13 +21,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#include "qemu/osdep.h"
-
#include "slirp.h"
+#include "vmstate.h"
#include "state.h"
-#include "migration/vmstate.h"
-#include "migration/qemu-file-types.h"
-#include "migration/register.h"
+#include "stream.h"
static int slirp_tcp_post_load(void *opaque, int version)
{
@@ -180,7 +177,7 @@ static int slirp_socket_pre_load(void *opaque)
#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)
+ slirp_vmstate_info_uint32, u_long)
#endif
/* The OS provided ss_family field isn't that portable; it's size
@@ -322,10 +319,13 @@ static const VMStateDescription vmstate_slirp = {
}
};
-static void slirp_state_save(QEMUFile *f, void *opaque)
+void slirp_state_save(Slirp *slirp, SlirpWriteCb write_cb, void *opaque)
{
- Slirp *slirp = opaque;
struct gfwd_list *ex_ptr;
+ SlirpOStream f = {
+ .write_cb = write_cb,
+ .opaque = opaque,
+ };
for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next)
if (ex_ptr->write_cb) {
@@ -336,25 +336,29 @@ static void slirp_state_save(QEMUFile *f, void *opaque)
continue;
}
- qemu_put_byte(f, 42);
- vmstate_save_state(f, &vmstate_slirp_socket, so, NULL);
+ slirp_ostream_write_u8(&f, 42);
+ slirp_vmstate_save_state(&f, &vmstate_slirp_socket, so);
}
- qemu_put_byte(f, 0);
+ slirp_ostream_write_u8(&f, 0);
- vmstate_save_state(f, &vmstate_slirp, slirp, NULL);
+ slirp_vmstate_save_state(&f, &vmstate_slirp, slirp);
}
-static int slirp_state_load(QEMUFile *f, void *opaque, int version_id)
+int slirp_state_load(Slirp *slirp, int version_id,
+ SlirpReadCb read_cb, void *opaque)
{
- Slirp *slirp = opaque;
struct gfwd_list *ex_ptr;
+ SlirpIStream f = {
+ .read_cb = read_cb,
+ .opaque = opaque,
+ };
- while (qemu_get_byte(f)) {
+ while (slirp_istream_read_u8(&f)) {
int ret;
struct socket *so = socreate(slirp);
- ret = vmstate_load_state(f, &vmstate_slirp_socket, so, version_id);
+ ret = slirp_vmstate_load_state(&f, &vmstate_slirp_socket, so, version_id);
if (ret < 0) {
return ret;
}
@@ -375,20 +379,10 @@ static int slirp_state_load(QEMUFile *f, void *opaque, int version_id)
}
}
- return vmstate_load_state(f, &vmstate_slirp, slirp, version_id);
-}
-
-void slirp_state_register(Slirp *slirp)
-{
- static SaveVMHandlers savevm_slirp_state = {
- .save_state = slirp_state_save,
- .load_state = slirp_state_load,
- };
-
- register_savevm_live(NULL, "slirp", 0, 4, &savevm_slirp_state, slirp);
+ return slirp_vmstate_load_state(&f, &vmstate_slirp, slirp, version_id);
}
-void slirp_state_unregister(Slirp *slirp)
+int slirp_state_version(void)
{
- unregister_savevm(NULL, "slirp", slirp);
+ return 4;
}
diff --git a/slirp/state.h b/slirp/state.h
index 154866898f..e69de29bb2 100644
--- a/slirp/state.h
+++ b/slirp/state.h
@@ -1,9 +0,0 @@
-#ifndef SLIRP_STATE_H_
-#define SLIRP_STATE_H_
-
-#include "libslirp.h"
-
-void slirp_state_register(Slirp *slirp);
-void slirp_state_unregister(Slirp *slirp);
-
-#endif /* SLIRP_STATE_H_ */