xref: /openbmc/qemu/include/net/filter.h (revision 7eceff5b)
1 /*
2  * Copyright (c) 2015 FUJITSU LIMITED
3  * Author: Yang Hongyang <yanghy@cn.fujitsu.com>
4  *
5  * This work is licensed under the terms of the GNU GPL, version 2 or
6  * later.  See the COPYING file in the top-level directory.
7  */
8 
9 #ifndef QEMU_NET_FILTER_H
10 #define QEMU_NET_FILTER_H
11 
12 #include "qapi/qapi-types-net.h"
13 #include "qom/object.h"
14 #include "qemu-common.h"
15 #include "net/queue.h"
16 
17 #define TYPE_NETFILTER "netfilter"
18 #define NETFILTER(obj) \
19     OBJECT_CHECK(NetFilterState, (obj), TYPE_NETFILTER)
20 #define NETFILTER_GET_CLASS(obj) \
21     OBJECT_GET_CLASS(NetFilterClass, (obj), TYPE_NETFILTER)
22 #define NETFILTER_CLASS(klass) \
23     OBJECT_CLASS_CHECK(NetFilterClass, (klass), TYPE_NETFILTER)
24 
25 typedef void (FilterSetup) (NetFilterState *nf, Error **errp);
26 typedef void (FilterCleanup) (NetFilterState *nf);
27 /*
28  * Return:
29  *   0: finished handling the packet, we should continue
30  *   size: filter stolen this packet, we stop pass this packet further
31  */
32 typedef ssize_t (FilterReceiveIOV)(NetFilterState *nc,
33                                    NetClientState *sender,
34                                    unsigned flags,
35                                    const struct iovec *iov,
36                                    int iovcnt,
37                                    NetPacketSent *sent_cb);
38 
39 typedef void (FilterStatusChanged) (NetFilterState *nf, Error **errp);
40 
41 typedef struct NetFilterClass {
42     ObjectClass parent_class;
43 
44     /* optional */
45     FilterSetup *setup;
46     FilterCleanup *cleanup;
47     FilterStatusChanged *status_changed;
48     /* mandatory */
49     FilterReceiveIOV *receive_iov;
50 } NetFilterClass;
51 
52 
53 struct NetFilterState {
54     /* private */
55     Object parent;
56 
57     /* protected */
58     char *netdev_id;
59     NetClientState *netdev;
60     NetFilterDirection direction;
61     bool on;
62     QTAILQ_ENTRY(NetFilterState) next;
63 };
64 
65 ssize_t qemu_netfilter_receive(NetFilterState *nf,
66                                NetFilterDirection direction,
67                                NetClientState *sender,
68                                unsigned flags,
69                                const struct iovec *iov,
70                                int iovcnt,
71                                NetPacketSent *sent_cb);
72 
73 /* pass the packet to the next filter */
74 ssize_t qemu_netfilter_pass_to_next(NetClientState *sender,
75                                     unsigned flags,
76                                     const struct iovec *iov,
77                                     int iovcnt,
78                                     void *opaque);
79 
80 #endif /* QEMU_NET_FILTER_H */
81