tests: Add unit tests for the VM Generation ID feature
[qemu/ar7.git] / replay / replay-net.c
blob80b705415694f749de42c3b6333b1cd2a1d7e210
1 /*
2 * replay-net.c
4 * Copyright (c) 2010-2016 Institute for System Programming
5 * of the Russian Academy of Sciences.
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
12 #include "qemu/osdep.h"
13 #include "qemu/error-report.h"
14 #include "sysemu/replay.h"
15 #include "replay-internal.h"
16 #include "sysemu/sysemu.h"
17 #include "net/net.h"
18 #include "net/filter.h"
19 #include "qemu/iov.h"
21 struct ReplayNetState {
22 NetFilterState *nfs;
23 int id;
26 typedef struct NetEvent {
27 uint8_t id;
28 uint32_t flags;
29 uint8_t *data;
30 size_t size;
31 } NetEvent;
33 static NetFilterState **network_filters;
34 static int network_filters_count;
36 ReplayNetState *replay_register_net(NetFilterState *nfs)
38 ReplayNetState *rns = g_new0(ReplayNetState, 1);
39 rns->nfs = nfs;
40 rns->id = network_filters_count++;
41 network_filters = g_realloc(network_filters,
42 network_filters_count
43 * sizeof(*network_filters));
44 network_filters[network_filters_count - 1] = nfs;
45 return rns;
48 void replay_unregister_net(ReplayNetState *rns)
50 network_filters[rns->id] = NULL;
51 g_free(rns);
54 void replay_net_packet_event(ReplayNetState *rns, unsigned flags,
55 const struct iovec *iov, int iovcnt)
57 NetEvent *event = g_new(NetEvent, 1);
58 event->flags = flags;
59 event->data = g_malloc(iov_size(iov, iovcnt));
60 event->size = iov_size(iov, iovcnt);
61 event->id = rns->id;
62 iov_to_buf(iov, iovcnt, 0, event->data, event->size);
64 replay_add_event(REPLAY_ASYNC_EVENT_NET, event, NULL, 0);
67 void replay_event_net_run(void *opaque)
69 NetEvent *event = opaque;
70 struct iovec iov = {
71 .iov_base = (void *)event->data,
72 .iov_len = event->size
75 assert(event->id < network_filters_count);
77 qemu_netfilter_pass_to_next(network_filters[event->id]->netdev,
78 event->flags, &iov, 1, network_filters[event->id]);
80 g_free(event->data);
81 g_free(event);
84 void replay_event_net_save(void *opaque)
86 NetEvent *event = opaque;
88 replay_put_byte(event->id);
89 replay_put_dword(event->flags);
90 replay_put_array(event->data, event->size);
93 void *replay_event_net_load(void)
95 NetEvent *event = g_new(NetEvent, 1);
97 event->id = replay_get_byte();
98 event->flags = replay_get_dword();
99 replay_get_array_alloc(&event->data, &event->size);
101 return event;