EthernetTap.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  4. *
  5. * (c) ZeroTier, Inc.
  6. * https://www.zerotier.com/
  7. */
  8. #ifndef ZT_ETHERNETTAP_HPP
  9. #define ZT_ETHERNETTAP_HPP
  10. #include "../node/Constants.hpp"
  11. #include "../node/InetAddress.hpp"
  12. #include "../node/MAC.hpp"
  13. #include "../node/MulticastGroup.hpp"
  14. #include <memory>
  15. #include <string>
  16. #include <vector>
  17. #define GETIFADDRS_CACHE_TIME 1000
  18. namespace ZeroTier {
  19. class EthernetTap {
  20. public:
  21. static std::shared_ptr<EthernetTap> newInstance(
  22. const char* tapDeviceType, // OS-specific, NULL for default
  23. unsigned int concurrency,
  24. bool pinning,
  25. const char* homePath,
  26. const MAC& mac,
  27. unsigned int mtu,
  28. unsigned int metric,
  29. uint64_t nwid,
  30. const char* friendlyName,
  31. void (*handler)(void*, void*, uint64_t, const MAC&, const MAC&, unsigned int, unsigned int, const void*, unsigned int),
  32. void* arg);
  33. EthernetTap();
  34. virtual ~EthernetTap();
  35. virtual void setEnabled(bool en) = 0;
  36. virtual bool enabled() const = 0;
  37. virtual bool addIp(const InetAddress& ip) = 0;
  38. virtual bool addIps(std::vector<InetAddress> ips); // uses addIp() unless overridden
  39. virtual bool removeIp(const InetAddress& ip) = 0;
  40. virtual std::vector<InetAddress> ips() const = 0;
  41. virtual void put(const MAC& from, const MAC& to, unsigned int etherType, const void* data, unsigned int len) = 0;
  42. virtual std::string deviceName() const = 0;
  43. virtual void setFriendlyName(const char* friendlyName) = 0;
  44. virtual std::string friendlyName() const;
  45. virtual void scanMulticastGroups(std::vector<MulticastGroup>& added, std::vector<MulticastGroup>& removed) = 0;
  46. virtual void setMtu(unsigned int mtu) = 0;
  47. virtual void setDns(const char* domain, const std::vector<InetAddress>& servers) = 0;
  48. };
  49. } // namespace ZeroTier
  50. #endif