filter.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #ifndef QEMU_NET_FILTER_H
  9. #define QEMU_NET_FILTER_H
  10. #include "qapi/qapi-types-common.h"
  11. #include "qemu/queue.h"
  12. #include "qom/object.h"
  13. #include "net/queue.h"
  14. #define TYPE_NETFILTER "netfilter"
  15. OBJECT_DECLARE_TYPE(NetFilterState, NetFilterClass, NETFILTER)
  16. typedef void (FilterSetup) (NetFilterState *nf, Error **errp);
  17. typedef void (FilterCleanup) (NetFilterState *nf);
  18. /*
  19. * Return:
  20. * 0: finished handling the packet, we should continue
  21. * size: filter stolen this packet, we stop pass this packet further
  22. */
  23. typedef ssize_t (FilterReceiveIOV)(NetFilterState *nc,
  24. NetClientState *sender,
  25. unsigned flags,
  26. const struct iovec *iov,
  27. int iovcnt,
  28. NetPacketSent *sent_cb);
  29. typedef void (FilterStatusChanged) (NetFilterState *nf, Error **errp);
  30. typedef void (FilterHandleEvent) (NetFilterState *nf, int event, Error **errp);
  31. struct NetFilterClass {
  32. ObjectClass parent_class;
  33. /* optional */
  34. FilterSetup *setup;
  35. FilterCleanup *cleanup;
  36. FilterStatusChanged *status_changed;
  37. FilterHandleEvent *handle_event;
  38. /* mandatory */
  39. FilterReceiveIOV *receive_iov;
  40. };
  41. struct NetFilterState {
  42. /* private */
  43. Object parent;
  44. /* protected */
  45. char *netdev_id;
  46. NetClientState *netdev;
  47. NetFilterDirection direction;
  48. bool on;
  49. char *position;
  50. bool insert_before_flag;
  51. QTAILQ_ENTRY(NetFilterState) next;
  52. };
  53. ssize_t qemu_netfilter_receive(NetFilterState *nf,
  54. NetFilterDirection direction,
  55. NetClientState *sender,
  56. unsigned flags,
  57. const struct iovec *iov,
  58. int iovcnt,
  59. NetPacketSent *sent_cb);
  60. /* pass the packet to the next filter */
  61. ssize_t qemu_netfilter_pass_to_next(NetClientState *sender,
  62. unsigned flags,
  63. const struct iovec *iov,
  64. int iovcnt,
  65. void *opaque);
  66. void colo_notify_filters_event(int event, Error **errp);
  67. #endif /* QEMU_NET_FILTER_H */