block: use BdrvRequestFlags type for supported flag fields
[qemu/ar7.git] / replay / replay-net.c
blob3b70f71cf12eb1a87ae39115730353e5961f9909
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 "net/net.h"
17 #include "net/filter.h"
18 #include "qemu/iov.h"
20 struct ReplayNetState {
21 NetFilterState *nfs;
22 int id;
25 typedef struct NetEvent {
26 uint8_t id;
27 uint32_t flags;
28 uint8_t *data;
29 size_t size;
30 } NetEvent;
32 static NetFilterState **network_filters;
33 static int network_filters_count;
35 ReplayNetState *replay_register_net(NetFilterState *nfs)
37 ReplayNetState *rns = g_new0(ReplayNetState, 1);
38 rns->nfs = nfs;
39 rns->id = network_filters_count++;
40 network_filters = g_realloc(network_filters,
41 network_filters_count
42 * sizeof(*network_filters));
43 network_filters[network_filters_count - 1] = nfs;
44 return rns;
47 void replay_unregister_net(ReplayNetState *rns)
49 network_filters[rns->id] = NULL;
50 g_free(rns);
53 void replay_net_packet_event(ReplayNetState *rns, unsigned flags,
54 const struct iovec *iov, int iovcnt)
56 NetEvent *event = g_new(NetEvent, 1);
57 event->flags = flags;
58 event->data = g_malloc(iov_size(iov, iovcnt));
59 event->size = iov_size(iov, iovcnt);
60 event->id = rns->id;
61 iov_to_buf(iov, iovcnt, 0, event->data, event->size);
63 replay_add_event(REPLAY_ASYNC_EVENT_NET, event, NULL, 0);
66 void replay_event_net_run(void *opaque)
68 NetEvent *event = opaque;
69 struct iovec iov = {
70 .iov_base = (void *)event->data,
71 .iov_len = event->size
74 assert(event->id < network_filters_count);
76 qemu_netfilter_pass_to_next(network_filters[event->id]->netdev,
77 event->flags, &iov, 1, network_filters[event->id]);
79 g_free(event->data);
80 g_free(event);
83 void replay_event_net_save(void *opaque)
85 NetEvent *event = opaque;
87 replay_put_byte(event->id);
88 replay_put_dword(event->flags);
89 replay_put_array(event->data, event->size);
92 void *replay_event_net_load(void)
94 NetEvent *event = g_new(NetEvent, 1);
96 event->id = replay_get_byte();
97 event->flags = replay_get_dword();
98 replay_get_array_alloc(&event->data, &event->size);
100 return event;