MacKextEthernetTap.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c)2013-2020 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: 2025-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 "../core/Constants.hpp"
  21. #include "../core/MAC.hpp"
  22. #include "../core/InetAddress.hpp"
  23. #include "../core/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. void threadMain()
  51. 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. };
  66. } // namespace ZeroTier
  67. #endif