Filter.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef ZT_FILTER_HPP
  19. #define ZT_FILTER_HPP
  20. #include <stdint.h>
  21. #include <vector>
  22. #include "Constants.hpp"
  23. #include "../include/ZeroTierOne.h"
  24. #include "Address.hpp"
  25. #include "MAC.hpp"
  26. namespace ZeroTier {
  27. /**
  28. * A simple network packet filter with VL1, L2, and basic L3 rule support (and tags!)
  29. */
  30. class Filter
  31. {
  32. public:
  33. /**
  34. * Apply a list of rules to a packet
  35. *
  36. * This returns whether or not the packet should be accepted and may also
  37. * take other actions for e.g. the TEE and REDIRECT targets.
  38. *
  39. * @param nwid ZeroTier network ID
  40. * @param receiving True if on receiving side, false on sending side
  41. * @param ztSource Source ZeroTier address
  42. * @param ztDest Destination ZeroTier address
  43. * @param macSource Ethernet layer source address
  44. * @param macDest Ethernet layer destination address
  45. * @param frameData Ethernet frame data
  46. * @param frameLen Ethernet frame payload length
  47. * @param etherType 16-bit ethernet type ID
  48. * @param vlanId 16-bit VLAN ID
  49. * @param rules Pointer to array of rules
  50. * @param ruleCount Number of rules
  51. * @param tagKeys Tag keys for tags that may be relevant
  52. * @param tagValues Tag values for tags that may be relevant
  53. * @param tagCount Size of tagKeys[] and tagValues[]
  54. * @param sendCopyOfPacketTo Result parameter: if non-NULL send a copy of this packet to another node
  55. * @return True if packet should be accepted for send or receive
  56. */
  57. static bool run(
  58. const uint64_t nwid,
  59. const bool receiving,
  60. const Address &ztSource,
  61. const Address &ztDest,
  62. const MAC &macSource,
  63. const MAC &macDest,
  64. const uint8_t *frameData,
  65. const unsigned int frameLen,
  66. const unsigned int etherType,
  67. const unsigned int vlanId,
  68. const ZT_VirtualNetworkRule *rules,
  69. const unsigned int ruleCount,
  70. const uint32_t *tagKeys,
  71. const uint32_t *tagValues,
  72. const unsigned int tagCount,
  73. Address &sendCopyOfPacketTo);
  74. };
  75. } // namespace ZeroTier
  76. #endif