MacEthernetTap.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_OSXETHERNETTAP_HPP
  14. #define ZT_OSXETHERNETTAP_HPP
  15. #include "../node/Constants.hpp"
  16. #include "../node/InetAddress.hpp"
  17. #include "../node/MAC.hpp"
  18. #include "../node/MulticastGroup.hpp"
  19. #include "../node/Mutex.hpp"
  20. #include "EthernetTap.hpp"
  21. #include "Thread.hpp"
  22. #include <stdexcept>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string>
  26. #include <vector>
  27. namespace ZeroTier {
  28. class MacEthernetTap : public EthernetTap {
  29. public:
  30. MacEthernetTap(
  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 ~MacEthernetTap();
  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. Mutex _putLock;
  61. unsigned int _mtu;
  62. unsigned int _metric;
  63. unsigned int _devNo;
  64. int _shutdownSignalPipe[2];
  65. int _agentStdin, _agentStdout, _agentStderr, _agentStdin2, _agentStdout2, _agentStderr2;
  66. long _agentPid;
  67. volatile bool _enabled;
  68. mutable std::vector<InetAddress> _ifaddrs;
  69. mutable uint64_t _lastIfAddrsUpdate;
  70. };
  71. } // namespace ZeroTier
  72. #endif