EthernetTap.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_ETHERNETTAP_HPP
  14. #define ZT_ETHERNETTAP_HPP
  15. #include "../core/Constants.hpp"
  16. #include "../core/MAC.hpp"
  17. #include "../core/InetAddress.hpp"
  18. #include "../core/MulticastGroup.hpp"
  19. #include <string>
  20. #include <memory>
  21. #include <vector>
  22. #include <mutex>
  23. #include <map>
  24. namespace ZeroTier {
  25. class EthernetTap
  26. {
  27. public:
  28. static std::shared_ptr<EthernetTap> newInstance(
  29. const char *tapDeviceType, // OS-specific, NULL for default
  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 std::string routingDeviceName() const;
  49. virtual void setFriendlyName(const char *friendlyName) = 0;
  50. virtual void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed) = 0;
  51. virtual void setMtu(unsigned int mtu) = 0;
  52. };
  53. } // namespace ZeroTier
  54. #endif