Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / net / filter-replay.c
blob54690676ef0dd27abfca36230c1688400ce08cc9
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/module.h"
17 #include "qemu/timer.h"
18 #include "qapi/visitor.h"
19 #include "net/filter.h"
20 #include "sysemu/replay.h"
21 #include "qom/object.h"
23 #define TYPE_FILTER_REPLAY "filter-replay"
25 OBJECT_DECLARE_SIMPLE_TYPE(NetFilterReplayState, FILTER_REPLAY)
27 struct NetFilterReplayState {
28 NetFilterState nfs;
29 ReplayNetState *rns;
32 static ssize_t filter_replay_receive_iov(NetFilterState *nf,
33 NetClientState *sndr,
34 unsigned flags,
35 const struct iovec *iov,
36 int iovcnt, NetPacketSent *sent_cb)
38 NetFilterReplayState *nfrs = FILTER_REPLAY(nf);
39 switch (replay_mode) {
40 case REPLAY_MODE_RECORD:
41 if (nf->netdev == sndr) {
42 replay_net_packet_event(nfrs->rns, flags, iov, iovcnt);
43 return iov_size(iov, iovcnt);
45 return 0;
46 case REPLAY_MODE_PLAY:
47 /* Drop all packets in replay mode.
48 Packets from the log will be injected by the replay module. */
49 return iov_size(iov, iovcnt);
50 default:
51 /* Pass all the packets. */
52 return 0;
56 static void filter_replay_instance_init(Object *obj)
58 NetFilterReplayState *nfrs = FILTER_REPLAY(obj);
59 nfrs->rns = replay_register_net(&nfrs->nfs);
62 static void filter_replay_instance_finalize(Object *obj)
64 NetFilterReplayState *nfrs = FILTER_REPLAY(obj);
65 replay_unregister_net(nfrs->rns);
68 static void filter_replay_class_init(ObjectClass *oc, void *data)
70 NetFilterClass *nfc = NETFILTER_CLASS(oc);
72 nfc->receive_iov = filter_replay_receive_iov;
75 static const TypeInfo filter_replay_info = {
76 .name = TYPE_FILTER_REPLAY,
77 .parent = TYPE_NETFILTER,
78 .class_init = filter_replay_class_init,
79 .instance_init = filter_replay_instance_init,
80 .instance_finalize = filter_replay_instance_finalize,
81 .instance_size = sizeof(NetFilterReplayState),
84 static void filter_replay_register_types(void)
86 type_register_static(&filter_replay_info);
89 type_init(filter_replay_register_types);