tcg/tci: Split out tci_args_ri and tci_args_rI
[qemu/ar7.git] / net / filter-replay.c
blobeef8443059b5fe3523a02a4c3e6530f0654b6453
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 "qemu/error-report.h"
15 #include "qemu/iov.h"
16 #include "qemu/log.h"
17 #include "qemu/module.h"
18 #include "qemu/timer.h"
19 #include "qapi/visitor.h"
20 #include "net/filter.h"
21 #include "sysemu/replay.h"
22 #include "qom/object.h"
24 #define TYPE_FILTER_REPLAY "filter-replay"
26 OBJECT_DECLARE_SIMPLE_TYPE(NetFilterReplayState, FILTER_REPLAY)
28 struct NetFilterReplayState {
29 NetFilterState nfs;
30 ReplayNetState *rns;
33 static ssize_t filter_replay_receive_iov(NetFilterState *nf,
34 NetClientState *sndr,
35 unsigned flags,
36 const struct iovec *iov,
37 int iovcnt, NetPacketSent *sent_cb)
39 NetFilterReplayState *nfrs = FILTER_REPLAY(nf);
40 switch (replay_mode) {
41 case REPLAY_MODE_RECORD:
42 if (nf->netdev == sndr) {
43 replay_net_packet_event(nfrs->rns, flags, iov, iovcnt);
44 return iov_size(iov, iovcnt);
46 return 0;
47 case REPLAY_MODE_PLAY:
48 /* Drop all packets in replay mode.
49 Packets from the log will be injected by the replay module. */
50 return iov_size(iov, iovcnt);
51 default:
52 /* Pass all the packets. */
53 return 0;
57 static void filter_replay_instance_init(Object *obj)
59 NetFilterReplayState *nfrs = FILTER_REPLAY(obj);
60 nfrs->rns = replay_register_net(&nfrs->nfs);
63 static void filter_replay_instance_finalize(Object *obj)
65 NetFilterReplayState *nfrs = FILTER_REPLAY(obj);
66 replay_unregister_net(nfrs->rns);
69 static void filter_replay_class_init(ObjectClass *oc, void *data)
71 NetFilterClass *nfc = NETFILTER_CLASS(oc);
73 nfc->receive_iov = filter_replay_receive_iov;
76 static const TypeInfo filter_replay_info = {
77 .name = TYPE_FILTER_REPLAY,
78 .parent = TYPE_NETFILTER,
79 .class_init = filter_replay_class_init,
80 .instance_init = filter_replay_instance_init,
81 .instance_finalize = filter_replay_instance_finalize,
82 .instance_size = sizeof(NetFilterReplayState),
85 static void filter_replay_register_types(void)
87 type_register_static(&filter_replay_info);
90 type_init(filter_replay_register_types);