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"
14 #include "qemu-common.h"
15 #include "qemu/error-report.h"
18 #include "qemu/timer.h"
19 #include "qapi/visitor.h"
20 #include "net/filter.h"
21 #include "sysemu/replay.h"
23 #define TYPE_FILTER_REPLAY "filter-replay"
25 #define FILTER_REPLAY(obj) \
26 OBJECT_CHECK(NetFilterReplayState, (obj), TYPE_FILTER_REPLAY)
28 struct NetFilterReplayState
{
32 typedef struct NetFilterReplayState NetFilterReplayState
;
34 static ssize_t
filter_replay_receive_iov(NetFilterState
*nf
,
37 const struct iovec
*iov
,
38 int iovcnt
, NetPacketSent
*sent_cb
)
40 NetFilterReplayState
*nfrs
= FILTER_REPLAY(nf
);
41 switch (replay_mode
) {
42 case REPLAY_MODE_RECORD
:
43 if (nf
->netdev
== sndr
) {
44 replay_net_packet_event(nfrs
->rns
, flags
, iov
, iovcnt
);
45 return iov_size(iov
, iovcnt
);
48 case REPLAY_MODE_PLAY
:
49 /* Drop all packets in replay mode.
50 Packets from the log will be injected by the replay module. */
51 return iov_size(iov
, iovcnt
);
53 /* Pass all the packets. */
58 static void filter_replay_instance_init(Object
*obj
)
60 NetFilterReplayState
*nfrs
= FILTER_REPLAY(obj
);
61 nfrs
->rns
= replay_register_net(&nfrs
->nfs
);
64 static void filter_replay_instance_finalize(Object
*obj
)
66 NetFilterReplayState
*nfrs
= FILTER_REPLAY(obj
);
67 replay_unregister_net(nfrs
->rns
);
70 static void filter_replay_class_init(ObjectClass
*oc
, void *data
)
72 NetFilterClass
*nfc
= NETFILTER_CLASS(oc
);
74 nfc
->receive_iov
= filter_replay_receive_iov
;
77 static const TypeInfo filter_replay_info
= {
78 .name
= TYPE_FILTER_REPLAY
,
79 .parent
= TYPE_NETFILTER
,
80 .class_init
= filter_replay_class_init
,
81 .instance_init
= filter_replay_instance_init
,
82 .instance_finalize
= filter_replay_instance_finalize
,
83 .instance_size
= sizeof(NetFilterReplayState
),
86 static void filter_replay_register_types(void)
88 type_register_static(&filter_replay_info
);
91 type_init(filter_replay_register_types
);