PacketMultiplexer.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c)2013-2021 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2026-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. #ifndef ZT_PACKET_MULTIPLEXER_HPP
  14. #define ZT_PACKET_MULTIPLEXER_HPP
  15. #include "../osdep/BlockingQueue.hpp"
  16. #include "MAC.hpp"
  17. #include "Mutex.hpp"
  18. #include "RuntimeEnvironment.hpp"
  19. #include <thread>
  20. #include <vector>
  21. namespace ZeroTier {
  22. struct PacketRecord {
  23. void* tPtr;
  24. uint64_t nwid;
  25. void** nuptr;
  26. uint64_t source;
  27. uint64_t dest;
  28. unsigned int etherType;
  29. unsigned int vlanId;
  30. uint8_t data[ZT_MAX_MTU];
  31. unsigned int len;
  32. unsigned int flowId;
  33. };
  34. class PacketMultiplexer {
  35. public:
  36. const RuntimeEnvironment* RR;
  37. PacketMultiplexer(const RuntimeEnvironment* renv);
  38. void setUpPostDecodeReceiveThreads(unsigned int concurrency, bool cpuPinningEnabled);
  39. void putFrame(void* tPtr, uint64_t nwid, void** nuptr, const MAC& source, const MAC& dest, unsigned int etherType, unsigned int vlanId, const void* data, unsigned int len, unsigned int flowId);
  40. std::vector<BlockingQueue<PacketRecord*>*> _rxPacketQueues;
  41. unsigned int _concurrency;
  42. // pool
  43. std::vector<PacketRecord*> _rxPacketVector;
  44. std::vector<std::thread> _rxPacketThreads;
  45. Mutex _rxPacketVector_m, _rxPacketThreads_m;
  46. std::vector<std::thread> _rxThreads;
  47. unsigned int _rxThreadCount;
  48. bool _enabled;
  49. };
  50. } // namespace ZeroTier
  51. #endif // ZT_PACKET_MULTIPLEXER_HPP