NetBSDEthernetTap.hpp 2.0 KB

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