summaryrefslogtreecommitdiffstats
path: root/include/net/filter.h
blob: e8fb6259db0f7a5e17893aeb1d243e984ad472bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Copyright (c) 2015 FUJITSU LIMITED
 * Author: Yang Hongyang <yanghy@cn.fujitsu.com>
 *
 * This work is licensed under the terms of the GNU GPL, version 2 or
 * later.  See the COPYING file in the top-level directory.
 */

#ifndef QEMU_NET_FILTER_H
#define QEMU_NET_FILTER_H

#include "qapi/qapi-types-net.h"
#include "qemu/queue.h"
#include "qom/object.h"
#include "net/queue.h"

#define TYPE_NETFILTER "netfilter"
#define NETFILTER(obj) \
    OBJECT_CHECK(NetFilterState, (obj), TYPE_NETFILTER)
#define NETFILTER_GET_CLASS(obj) \
    OBJECT_GET_CLASS(NetFilterClass, (obj), TYPE_NETFILTER)
#define NETFILTER_CLASS(klass) \
    OBJECT_CLASS_CHECK(NetFilterClass, (klass), TYPE_NETFILTER)

typedef void (FilterSetup) (NetFilterState *nf, Error **errp);
typedef void (FilterCleanup) (NetFilterState *nf);
/*
 * Return:
 *   0: finished handling the packet, we should continue
 *   size: filter stolen this packet, we stop pass this packet further
 */
typedef ssize_t (FilterReceiveIOV)(NetFilterState *nc,
                                   NetClientState *sender,
                                   unsigned flags,
                                   const struct iovec *iov,
                                   int iovcnt,
                                   NetPacketSent *sent_cb);

typedef void (FilterStatusChanged) (NetFilterState *nf, Error **errp);

typedef void (FilterHandleEvent) (NetFilterState *nf, int event, Error **errp);

typedef struct NetFilterClass {
    ObjectClass parent_class;

    /* optional */
    FilterSetup *setup;
    FilterCleanup *cleanup;
    FilterStatusChanged *status_changed;
    FilterHandleEvent *handle_event;
    /* mandatory */
    FilterReceiveIOV *receive_iov;
} NetFilterClass;


struct NetFilterState {
    /* private */
    Object parent;

    /* protected */
    char *netdev_id;
    NetClientState *netdev;
    NetFilterDirection direction;
    bool on;
    QTAILQ_ENTRY(NetFilterState) next;
};

ssize_t qemu_netfilter_receive(NetFilterState *nf,
                               NetFilterDirection direction,
                               NetClientState *sender,
                               unsigned flags,
                               const struct iovec *iov,
                               int iovcnt,
                               NetPacketSent *sent_cb);

/* pass the packet to the next filter */
ssize_t qemu_netfilter_pass_to_next(NetClientState *sender,
                                    unsigned flags,
                                    const struct iovec *iov,
                                    int iovcnt,
                                    void *opaque);

void colo_notify_filters_event(int event, Error **errp);

#endif /* QEMU_NET_FILTER_H */