aboutsummaryrefslogtreecommitdiff
path: root/slirp/slirp.c
diff options
context:
space:
mode:
authorGuillaume Subiron <maethor@subiron.org>2015-12-19 22:24:58 +0100
committerJason Wang <jasowang@redhat.com>2016-02-04 13:22:06 +0800
commiteae303ff23f51259eddc8856c71453d887ffe51a (patch)
treee6ebb289e43d60bb5687264b5fc88dae2a595b03 /slirp/slirp.c
parent18137fba35980de428664fca3576b5d187e96fef (diff)
slirp: Make Socket structure IPv6 compatible
This patch replaces foreign and local address/port couples in Socket structure by 2 sockaddr_storage which can be casted in sockaddr_in. Direct access to address and port is still possible thanks to some \#define, so retrocompatibility of the existing code is assured. The ss_family field of sockaddr_storage is declared after each socket creation. The whole structure is also saved/restored when a Qemu session is saved/restored. This prepares for IPv6 support. Signed-off-by: Guillaume Subiron <maethor@subiron.org> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
Diffstat (limited to 'slirp/slirp.c')
-rw-r--r--slirp/slirp.c51
1 files changed, 42 insertions, 9 deletions
diff --git a/slirp/slirp.c b/slirp/slirp.c
index f8dc5059ee..b900775eff 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -23,6 +23,7 @@
*/
#include "qemu-common.h"
#include "qemu/timer.h"
+#include "qemu/error-report.h"
#include "sysemu/char.h"
#include "slirp.h"
#include "hw/hw.h"
@@ -234,7 +235,7 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
slirp->opaque = opaque;
- register_savevm(NULL, "slirp", 0, 3,
+ register_savevm(NULL, "slirp", 0, 4,
slirp_state_save, slirp_state_load, slirp);
QTAILQ_INSERT_TAIL(&slirp_instances, slirp, entry);
@@ -1046,10 +1047,26 @@ static void slirp_sbuf_save(QEMUFile *f, struct sbuf *sbuf)
static void slirp_socket_save(QEMUFile *f, struct socket *so)
{
qemu_put_be32(f, so->so_urgc);
- qemu_put_be32(f, so->so_faddr.s_addr);
- qemu_put_be32(f, so->so_laddr.s_addr);
- qemu_put_be16(f, so->so_fport);
- qemu_put_be16(f, so->so_lport);
+ 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\n");
+ }
+ 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\n");
+ }
qemu_put_byte(f, so->so_iptos);
qemu_put_byte(f, so->so_emu);
qemu_put_byte(f, so->so_type);
@@ -1169,10 +1186,26 @@ static int slirp_socket_load(QEMUFile *f, struct socket *so)
return -ENOMEM;
so->so_urgc = qemu_get_be32(f);
- 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);
+ 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\n");
+ }
+ 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\n");
+ }
so->so_iptos = qemu_get_byte(f);
so->so_emu = qemu_get_byte(f);
so->so_type = qemu_get_byte(f);