BSDEthernetTap.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_BSDETHERNETTAP_HPP
  14. #define ZT_BSDETHERNETTAP_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 BSDEthernetTap : public EthernetTap
  27. {
  28. public:
  29. BSDEthernetTap(
  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. virtual ~BSDEthernetTap();
  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. virtual void setMtu(unsigned int mtu);
  49. void threadMain()
  50. throw();
  51. private:
  52. void (*_handler)(void *,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