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 "qemu/queue.h" 14 #include "qom/object.h" 15 #include "net/queue.h" 16 17 #define TYPE_NETFILTER "netfilter" 18 typedef struct NetFilterClass NetFilterClass; 19 DECLARE_OBJ_CHECKERS(NetFilterState, NetFilterClass, 20 NETFILTER, TYPE_NETFILTER) 21 22 typedef void (FilterSetup) (NetFilterState *nf, Error **errp); 23 typedef void (FilterCleanup) (NetFilterState *nf); 24 /* 25 * Return: 26 * 0: finished handling the packet, we should continue 27 * size: filter stolen this packet, we stop pass this packet further 28 */ 29 typedef ssize_t (FilterReceiveIOV)(NetFilterState *nc, 30 NetClientState *sender, 31 unsigned flags, 32 const struct iovec *iov, 33 int iovcnt, 34 NetPacketSent *sent_cb); 35 36 typedef void (FilterStatusChanged) (NetFilterState *nf, Error **errp); 37 38 typedef void (FilterHandleEvent) (NetFilterState *nf, int event, Error **errp); 39 40 struct NetFilterClass { 41 ObjectClass parent_class; 42 43 /* optional */ 44 FilterSetup *setup; 45 FilterCleanup *cleanup; 46 FilterStatusChanged *status_changed; 47 FilterHandleEvent *handle_event; 48 /* mandatory */ 49 FilterReceiveIOV *receive_iov; 50 }; 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 char *position; 63 bool insert_before_flag; 64 QTAILQ_ENTRY(NetFilterState) next; 65 }; 66 67 ssize_t qemu_netfilter_receive(NetFilterState *nf, 68 NetFilterDirection direction, 69 NetClientState *sender, 70 unsigned flags, 71 const struct iovec *iov, 72 int iovcnt, 73 NetPacketSent *sent_cb); 74 75 /* pass the packet to the next filter */ 76 ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, 77 unsigned flags, 78 const struct iovec *iov, 79 int iovcnt, 80 void *opaque); 81 82 void colo_notify_filters_event(int event, Error **errp); 83 84 #endif /* QEMU_NET_FILTER_H */ 85