BSDEthernetTap.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef ZT_BSDETHERNETTAP_HPP
  19. #define ZT_BSDETHERNETTAP_HPP
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string>
  23. #include <vector>
  24. #include <stdexcept>
  25. #include "../node/Constants.hpp"
  26. #include "../node/MulticastGroup.hpp"
  27. #include "../node/MAC.hpp"
  28. #include "Thread.hpp"
  29. namespace ZeroTier {
  30. class BSDEthernetTap
  31. {
  32. public:
  33. BSDEthernetTap(
  34. const char *homePath,
  35. const MAC &mac,
  36. unsigned int mtu,
  37. unsigned int metric,
  38. uint64_t nwid,
  39. const char *friendlyName,
  40. void (*handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int),
  41. void *arg);
  42. ~BSDEthernetTap();
  43. void setEnabled(bool en);
  44. bool enabled() const;
  45. bool addIp(const InetAddress &ip);
  46. bool removeIp(const InetAddress &ip);
  47. std::vector<InetAddress> ips() const;
  48. void put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
  49. std::string deviceName() const;
  50. void setFriendlyName(const char *friendlyName);
  51. void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed);
  52. void threadMain()
  53. throw();
  54. private:
  55. void (*_handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int);
  56. void *_arg;
  57. uint64_t _nwid;
  58. Thread _thread;
  59. std::string _dev;
  60. std::vector<MulticastGroup> _multicastGroups;
  61. unsigned int _mtu;
  62. unsigned int _metric;
  63. int _fd;
  64. int _shutdownSignalPipe[2];
  65. volatile bool _enabled;
  66. };
  67. } // namespace ZeroTier
  68. #endif