Filter.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 "Constants.hpp"
  22. #include "../include/ZeroTierOne.h"
  23. #include "Address.hpp"
  24. #include "MAC.hpp"
  25. namespace ZeroTier {
  26. /**
  27. * A simple network packet filter with VL1, L2, and basic L3 rule support (and tags!)
  28. */
  29. class Filter
  30. {
  31. public:
  32. /**
  33. * Apply a list of rules to a packet
  34. *
  35. * This returns whether or not the packet should be accepted and may also
  36. * take other actions for e.g. the TEE and REDIRECT targets.
  37. *
  38. * @param nwid ZeroTier network ID
  39. * @param receiving True if on receiving side, false on sending side
  40. * @param ztSource Source ZeroTier address
  41. * @param ztDest Destination ZeroTier address
  42. * @param macSource Ethernet layer source address
  43. * @param macDest Ethernet layer destination address
  44. * @param frameData Ethernet frame data
  45. * @param frameLen Ethernet frame payload length
  46. * @param etherType 16-bit ethernet type ID
  47. * @param vlanId 16-bit VLAN ID
  48. * @param rules Pointer to array of rules
  49. * @param ruleCount Number of rules
  50. * @param tagKeys Tag keys for tags that may be relevant
  51. * @param tagValues Tag values for tags that may be relevant
  52. * @param tagCount Size of tagKeys[] and tagValues[]
  53. * @param sendCopyOfPacketTo Result parameter: if non-NULL send a copy of this packet to another node
  54. * @return True if packet should be accepted for send or receive
  55. */
  56. static bool run(
  57. const uint64_t nwid,
  58. const bool receiving,
  59. const Address &ztSource,
  60. const Address &ztDest,
  61. const MAC &macSource,
  62. const MAC &macDest,
  63. const uint8_t *frameData,
  64. const unsigned int frameLen,
  65. const unsigned int etherType,
  66. const unsigned int vlanId,
  67. const ZT_VirtualNetworkRule *rules,
  68. const unsigned int ruleCount,
  69. const uint32_t *tagKeys,
  70. const uint32_t *tagValues,
  71. const unsigned int tagCount,
  72. Address &sendCopyOfPacketTo);
  73. };
  74. } // namespace ZeroTier
  75. #endif