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"
17 #include "net/filter.h"
20 struct ReplayNetState
{
25 typedef struct 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);
39 rns
->id
= network_filters_count
++;
40 network_filters
= g_realloc(network_filters
,
42 * sizeof(*network_filters
));
43 network_filters
[network_filters_count
- 1] = nfs
;
47 void replay_unregister_net(ReplayNetState
*rns
)
49 network_filters
[rns
->id
] = NULL
;
53 void replay_net_packet_event(ReplayNetState
*rns
, unsigned flags
,
54 const struct iovec
*iov
, int iovcnt
)
56 NetEvent
*event
= g_new(NetEvent
, 1);
58 event
->data
= g_malloc(iov_size(iov
, iovcnt
));
59 event
->size
= iov_size(iov
, iovcnt
);
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
;
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
]);
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
);