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"
18 #include "net/filter.h"
21 struct ReplayNetState
{
26 typedef struct 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);
40 rns
->id
= network_filters_count
++;
41 network_filters
= g_realloc(network_filters
,
43 * sizeof(*network_filters
));
44 network_filters
[network_filters_count
- 1] = nfs
;
48 void replay_unregister_net(ReplayNetState
*rns
)
50 network_filters
[rns
->id
] = NULL
;
54 void replay_net_packet_event(ReplayNetState
*rns
, unsigned flags
,
55 const struct iovec
*iov
, int iovcnt
)
57 NetEvent
*event
= g_new(NetEvent
, 1);
59 event
->data
= g_malloc(iov_size(iov
, iovcnt
));
60 event
->size
= iov_size(iov
, iovcnt
);
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
;
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
]);
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
);