EthernetTap.hpp 1.9 KB

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