NetBSDEthernetTap.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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_NetBSDEthernetTap_HPP
  14. #define ZT_NetBSDEthernetTap_HPP
  15. #include "../node/Constants.hpp"
  16. #include "../node/MAC.hpp"
  17. #include "../node/MulticastGroup.hpp"
  18. #include "EthernetTap.hpp"
  19. #include "Thread.hpp"
  20. #include <stdexcept>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string>
  24. #include <vector>
  25. namespace ZeroTier {
  26. class NetBSDEthernetTap : public EthernetTap {
  27. public:
  28. NetBSDEthernetTap(
  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*, uint64_t, const MAC&, const MAC&, unsigned int, unsigned int, const void*, unsigned int),
  36. void* arg);
  37. virtual ~NetBSDEthernetTap();
  38. virtual void setEnabled(bool en);
  39. virtual bool enabled() const;
  40. virtual bool addIp(const InetAddress& ip);
  41. virtual bool removeIp(const InetAddress& ip);
  42. virtual std::vector<InetAddress> ips() const;
  43. virtual void put(const MAC& from, const MAC& to, unsigned int etherType, const void* data, unsigned int len);
  44. virtual std::string deviceName() const;
  45. virtual void setFriendlyName(const char* friendlyName);
  46. virtual void scanMulticastGroups(std::vector<MulticastGroup>& added, std::vector<MulticastGroup>& removed);
  47. virtual void setDns(const char* domain, const std::vector<InetAddress>& servers)
  48. {
  49. }
  50. void threadMain() throw();
  51. private:
  52. void (*_handler)(void*, uint64_t, const MAC&, const MAC&, unsigned int, unsigned int, const void*, unsigned int);
  53. void* _arg;
  54. uint64_t _nwid;
  55. Thread _thread;
  56. std::string _dev;
  57. std::vector<MulticastGroup> _multicastGroups;
  58. unsigned int _mtu;
  59. unsigned int _metric;
  60. int _fd;
  61. int _shutdownSignalPipe[2];
  62. volatile bool _enabled;
  63. };
  64. } // namespace ZeroTier
  65. #endif