ppc: xics: fix compilation with CentOS 6
[qemu/ar7.git] / net / filter-replay.c
blobcff65f86e5387fcd2cf2ada1153d7a964c348210
1 /*
2 * filter-replay.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 "clients.h"
14 #include "qapi/error.h"
15 #include "qemu-common.h"
16 #include "qemu/error-report.h"
17 #include "qemu/iov.h"
18 #include "qemu/log.h"
19 #include "qemu/timer.h"
20 #include "qapi/visitor.h"
21 #include "net/filter.h"
22 #include "sysemu/replay.h"
24 #define TYPE_FILTER_REPLAY "filter-replay"
26 #define FILTER_REPLAY(obj) \
27 OBJECT_CHECK(NetFilterReplayState, (obj), TYPE_FILTER_REPLAY)
29 struct NetFilterReplayState {
30 NetFilterState nfs;
31 ReplayNetState *rns;
33 typedef struct NetFilterReplayState NetFilterReplayState;
35 static ssize_t filter_replay_receive_iov(NetFilterState *nf,
36 NetClientState *sndr,
37 unsigned flags,
38 const struct iovec *iov,
39 int iovcnt, NetPacketSent *sent_cb)
41 NetFilterReplayState *nfrs = FILTER_REPLAY(nf);
42 switch (replay_mode) {
43 case REPLAY_MODE_RECORD:
44 if (nf->netdev == sndr) {
45 replay_net_packet_event(nfrs->rns, flags, iov, iovcnt);
46 return iov_size(iov, iovcnt);
48 return 0;
49 case REPLAY_MODE_PLAY:
50 /* Drop all packets in replay mode.
51 Packets from the log will be injected by the replay module. */
52 return iov_size(iov, iovcnt);
53 default:
54 /* Pass all the packets. */
55 return 0;
59 static void filter_replay_instance_init(Object *obj)
61 NetFilterReplayState *nfrs = FILTER_REPLAY(obj);
62 nfrs->rns = replay_register_net(&nfrs->nfs);
65 static void filter_replay_instance_finalize(Object *obj)
67 NetFilterReplayState *nfrs = FILTER_REPLAY(obj);
68 replay_unregister_net(nfrs->rns);
71 static void filter_replay_class_init(ObjectClass *oc, void *data)
73 NetFilterClass *nfc = NETFILTER_CLASS(oc);
75 nfc->receive_iov = filter_replay_receive_iov;
78 static const TypeInfo filter_replay_info = {
79 .name = TYPE_FILTER_REPLAY,
80 .parent = TYPE_NETFILTER,
81 .class_init = filter_replay_class_init,
82 .instance_init = filter_replay_instance_init,
83 .instance_finalize = filter_replay_instance_finalize,
84 .instance_size = sizeof(NetFilterReplayState),
87 static void filter_replay_register_types(void)
89 type_register_static(&filter_replay_info);
92 type_init(filter_replay_register_types);