EthernetTap.hpp 1.9 KB

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