EthernetTap.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_ETHERNETTAP_HPP
  14. #define ZT_ETHERNETTAP_HPP
  15. #include "../node/Constants.hpp"
  16. #include "../node/InetAddress.hpp"
  17. #include "../node/MAC.hpp"
  18. #include "../node/MulticastGroup.hpp"
  19. #include <memory>
  20. #include <string>
  21. #include <vector>
  22. #define GETIFADDRS_CACHE_TIME 1000
  23. namespace ZeroTier {
  24. class EthernetTap {
  25. public:
  26. static std::shared_ptr<EthernetTap> newInstance(
  27. const char* tapDeviceType, // OS-specific, NULL for default
  28. unsigned int concurrency,
  29. bool pinning,
  30. const char* homePath,
  31. const MAC& mac,
  32. unsigned int mtu,
  33. unsigned int metric,
  34. uint64_t nwid,
  35. const char* friendlyName,
  36. void (*handler)(void*, void*, uint64_t, const MAC&, const MAC&, unsigned int, unsigned int, const void*, unsigned int),
  37. void* arg);
  38. EthernetTap();
  39. virtual ~EthernetTap();
  40. virtual void setEnabled(bool en) = 0;
  41. virtual bool enabled() const = 0;
  42. virtual bool addIp(const InetAddress& ip) = 0;
  43. virtual bool addIps(std::vector<InetAddress> ips); // uses addIp() unless overridden
  44. virtual bool removeIp(const InetAddress& ip) = 0;
  45. virtual std::vector<InetAddress> ips() const = 0;
  46. virtual void put(const MAC& from, const MAC& to, unsigned int etherType, const void* data, unsigned int len) = 0;
  47. virtual std::string deviceName() const = 0;
  48. virtual void setFriendlyName(const char* friendlyName) = 0;
  49. virtual std::string friendlyName() const;
  50. virtual void scanMulticastGroups(std::vector<MulticastGroup>& added, std::vector<MulticastGroup>& removed) = 0;
  51. virtual void setMtu(unsigned int mtu) = 0;
  52. virtual void setDns(const char* domain, const std::vector<InetAddress>& servers) = 0;
  53. };
  54. } // namespace ZeroTier
  55. #endif