/* SPDX-License-Identifier: MIT */
/*
 * libslirp
 *
 * Copyright (c) 2004-2008 Fabrice Bellard
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
#include "slirp.h"
#include "vmstate.h"
#include "stream.h"

static int slirp_tcp_post_load(void *opaque, int version)
{
    tcp_template((struct tcpcb *)opaque);

    return 0;
}

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 int sbuf_tmp_pre_save(void *opaque)
{
    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;

    return 0;
}

static int sbuf_tmp_post_load(void *opaque, int version)
{
    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->woff >= requested_len || tmp->roff >= requested_len) {
        g_critical("invalid sbuf offsets r/w=%u/%u len=%u", tmp->roff,
                   tmp->woff, requested_len);
        return -EINVAL;
    }

    tmp->parent->sb_wptr = tmp->parent->sb_data + tmp->woff;
    tmp->parent->sb_rptr = tmp->parent->sb_data + tmp->roff;

    return 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() }
};

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() }
};

static bool slirp_older_than_v4(void *opaque, int version_id)
{
    return version_id < 4;
}

static bool slirp_family_inet(void *opaque, int version_id)
{
    union slirp_sockaddr *ssa = (union slirp_sockaddr *)opaque;
    return ssa->ss.ss_family == AF_INET;
}

static int slirp_socket_pre_load(void *opaque)
{
    struct socket *so = opaque;

    tcp_attach(so);
    /* Older versions don't load these fields */
    so->so_ffamily = AF_INET;
    so->so_lfamily = AF_INET;
    return 0;
}

#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, slirp_vmstate_info_uint32, u_long)
#endif

/* 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;

#define SS_FAMILY_MIG_IPV4 2 /* Linux, BSD, Win... */
#define SS_FAMILY_MIG_IPV6 10 /* Linux */
#define SS_FAMILY_MIG_OTHER 0xffff

static int ss_family_pre_save(void *opaque)
{
    SS_FamilyTmpStruct *tss = opaque;

    tss->portable_family = SS_FAMILY_MIG_OTHER;

    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;
    }

    return 0;
}

static int ss_family_post_load(void *opaque, int version_id)
{
    SS_FamilyTmpStruct *tss = opaque;

    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:
        g_critical("invalid ss_family type %x", tss->portable_family);
        return -EINVAL;
    }

    return 0;
}

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() }
};

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() }
};

int slirp_state_save(Slirp *slirp, SlirpWriteCb write_cb, void *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) {
            struct socket *so;
            so = slirp_find_ctl_socket(slirp, ex_ptr->ex_addr,
                                       ntohs(ex_ptr->ex_fport));
            if (!so) {
                continue;
            }

            slirp_ostream_write_u8(&f, 42);
            slirp_vmstate_save_state(&f, &vmstate_slirp_socket, so);
        }
    slirp_ostream_write_u8(&f, 0);

    slirp_vmstate_save_state(&f, &vmstate_slirp, slirp);

    return 0;
}


int slirp_state_load(Slirp *slirp, int version_id, SlirpReadCb read_cb,
                     void *opaque)
{
    struct gfwd_list *ex_ptr;
    SlirpIStream f = {
        .read_cb = read_cb,
        .opaque = opaque,
    };

    while (slirp_istream_read_u8(&f)) {
        int ret;
        struct socket *so = socreate(slirp, -1);

        ret =
            slirp_vmstate_load_state(&f, &vmstate_slirp_socket, so, version_id);
        if (ret < 0) {
            return ret;
        }

        if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) !=
            slirp->vnetwork_addr.s_addr) {
            return -EINVAL;
        }
        for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) {
            if (ex_ptr->write_cb &&
                so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr &&
                so->so_fport == ex_ptr->ex_fport) {
                break;
            }
        }
        if (!ex_ptr) {
            return -EINVAL;
        }

        so->guestfwd = ex_ptr;
    }

    return slirp_vmstate_load_state(&f, &vmstate_slirp, slirp, version_id);
}

int slirp_state_version(void)
{
    return 4;
}
