MacKextEthernetTap.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c)2019 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_MacKextEthernetTap_HPP
  14. #define ZT_MacKextEthernetTap_HPP
  15. #include "../node/Constants.hpp"
  16. #include "../node/InetAddress.hpp"
  17. #include "../node/MAC.hpp"
  18. #include "../node/MulticastGroup.hpp"
  19. #include "EthernetTap.hpp"
  20. #include "Thread.hpp"
  21. #include <stdexcept>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string>
  25. #include <thread>
  26. #include <vector>
  27. namespace ZeroTier {
  28. class MacKextEthernetTap : public EthernetTap {
  29. public:
  30. MacKextEthernetTap(
  31. const char* homePath,
  32. const MAC& mac,
  33. unsigned int mtu,
  34. unsigned int metric,
  35. uint64_t nwid,
  36. const char* friendlyName,
  37. void (*handler)(void*, void*, uint64_t, const MAC&, const MAC&, unsigned int, unsigned int, const void*, unsigned int),
  38. void* arg);
  39. virtual ~MacKextEthernetTap();
  40. virtual void setEnabled(bool en);
  41. virtual bool enabled() const;
  42. virtual bool addIp(const InetAddress& ip);
  43. virtual bool removeIp(const InetAddress& ip);
  44. virtual std::vector<InetAddress> ips() const;
  45. virtual void put(const MAC& from, const MAC& to, unsigned int etherType, const void* data, unsigned int len);
  46. virtual std::string deviceName() const;
  47. virtual void setFriendlyName(const char* friendlyName);
  48. virtual void scanMulticastGroups(std::vector<MulticastGroup>& added, std::vector<MulticastGroup>& removed);
  49. virtual void setMtu(unsigned int mtu);
  50. virtual void setDns(const char* domain, const std::vector<InetAddress>& servers);
  51. void threadMain() throw();
  52. private:
  53. void (*_handler)(void*, void*, uint64_t, const MAC&, const MAC&, unsigned int, unsigned int, const void*, unsigned int);
  54. void* _arg;
  55. uint64_t _nwid;
  56. Thread _thread;
  57. std::string _homePath;
  58. std::string _dev;
  59. std::vector<MulticastGroup> _multicastGroups;
  60. unsigned int _mtu;
  61. unsigned int _metric;
  62. int _fd;
  63. int _shutdownSignalPipe[2];
  64. volatile bool _enabled;
  65. std::vector<std::thread> _rxThreads;
  66. };
  67. } // namespace ZeroTier
  68. #endif