MacKextEthernetTap.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 <stdio.h>
  16. #include <stdlib.h>
  17. #include <stdexcept>
  18. #include <string>
  19. #include <vector>
  20. #include "../node/Constants.hpp"
  21. #include "../node/MAC.hpp"
  22. #include "../node/InetAddress.hpp"
  23. #include "../node/MulticastGroup.hpp"
  24. #include "Thread.hpp"
  25. #include "EthernetTap.hpp"
  26. namespace ZeroTier {
  27. class MacKextEthernetTap : public EthernetTap
  28. {
  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()
  52. throw();
  53. private:
  54. void (*_handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int);
  55. void *_arg;
  56. uint64_t _nwid;
  57. Thread _thread;
  58. std::string _homePath;
  59. std::string _dev;
  60. std::vector<MulticastGroup> _multicastGroups;
  61. unsigned int _mtu;
  62. unsigned int _metric;
  63. int _fd;
  64. int _shutdownSignalPipe[2];
  65. volatile bool _enabled;
  66. };
  67. } // namespace ZeroTier
  68. #endif