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 14 #ifndef ZT_MacKextEthernetTap_HPP 15 #define ZT_MacKextEthernetTap_HPP 16 17 #include <stdio.h> 18 #include <stdlib.h> 19 20 #include <stdexcept> 21 #include <string> 22 #include <vector> 23 24 #include "../node/Constants.hpp" 25 #include "../node/MAC.hpp" 26 #include "../node/InetAddress.hpp" 27 #include "../node/MulticastGroup.hpp" 28 29 #include "Thread.hpp" 30 #include "EthernetTap.hpp" 31 32 namespace ZeroTier { 33 34 class MacKextEthernetTap : public EthernetTap 35 { 36 public: 37 MacKextEthernetTap( 38 const char *homePath, 39 const MAC &mac, 40 unsigned int mtu, 41 unsigned int metric, 42 uint64_t nwid, 43 const char *friendlyName, 44 void (*handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int), 45 void *arg); 46 47 virtual ~MacKextEthernetTap(); 48 49 virtual void setEnabled(bool en); 50 virtual bool enabled() const; 51 virtual bool addIp(const InetAddress &ip); 52 virtual bool removeIp(const InetAddress &ip); 53 virtual std::vector<InetAddress> ips() const; 54 virtual void put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len); 55 virtual std::string deviceName() const; 56 virtual void setFriendlyName(const char *friendlyName); 57 virtual void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed); 58 virtual void setMtu(unsigned int mtu); 59 virtual void setDns(const char *domain, const std::vector<InetAddress> &servers); 60 61 62 void threadMain() 63 throw(); 64 65 private: 66 void (*_handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int); 67 void *_arg; 68 uint64_t _nwid; 69 Thread _thread; 70 std::string _homePath; 71 std::string _dev; 72 std::vector<MulticastGroup> _multicastGroups; 73 unsigned int _mtu; 74 unsigned int _metric; 75 int _fd; 76 int _shutdownSignalPipe[2]; 77 volatile bool _enabled; 78 }; 79 80 } // namespace ZeroTier 81 82 #endif 83