2014-04-07 21:47:39 +00:00
|
|
|
/*
|
2015-02-17 21:11:34 +00:00
|
|
|
* ZeroTier One - Network Virtualization Everywhere
|
2017-04-28 03:47:25 +00:00
|
|
|
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
|
2014-04-07 21:47:39 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-04-28 03:47:25 +00:00
|
|
|
*
|
|
|
|
* --
|
|
|
|
*
|
|
|
|
* You can be released from the requirements of the license by purchasing
|
|
|
|
* a commercial license. Buying such a license is mandatory as soon as you
|
|
|
|
* develop commercial closed-source software that incorporates or links
|
|
|
|
* directly against ZeroTier software without disclosing the source code
|
|
|
|
* of your own application.
|
2014-04-07 21:47:39 +00:00
|
|
|
*/
|
|
|
|
|
2014-07-21 16:18:33 +00:00
|
|
|
#ifndef ZT_OSXETHERNETTAP_HPP
|
|
|
|
#define ZT_OSXETHERNETTAP_HPP
|
2014-04-07 21:47:39 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <stdexcept>
|
2015-04-15 00:57:51 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2014-04-07 21:47:39 +00:00
|
|
|
|
2015-04-10 18:40:45 +00:00
|
|
|
#include "../node/Constants.hpp"
|
|
|
|
#include "../node/MAC.hpp"
|
|
|
|
#include "../node/InetAddress.hpp"
|
|
|
|
#include "../node/MulticastGroup.hpp"
|
|
|
|
|
2015-04-09 02:03:30 +00:00
|
|
|
#include "Thread.hpp"
|
2014-04-07 21:47:39 +00:00
|
|
|
|
|
|
|
namespace ZeroTier {
|
|
|
|
|
|
|
|
/**
|
2014-07-21 16:18:33 +00:00
|
|
|
* OSX Ethernet tap using ZeroTier kernel extension zt# devices
|
2014-04-07 21:47:39 +00:00
|
|
|
*/
|
2015-04-10 17:19:45 +00:00
|
|
|
class OSXEthernetTap
|
2014-04-07 21:47:39 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-07-21 16:18:33 +00:00
|
|
|
OSXEthernetTap(
|
2015-04-15 00:57:51 +00:00
|
|
|
const char *homePath,
|
2014-04-07 21:47:39 +00:00
|
|
|
const MAC &mac,
|
|
|
|
unsigned int mtu,
|
2014-07-21 16:18:33 +00:00
|
|
|
unsigned int metric,
|
|
|
|
uint64_t nwid,
|
|
|
|
const char *friendlyName,
|
2017-03-28 00:03:17 +00:00
|
|
|
void (*handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int),
|
2014-07-21 16:18:33 +00:00
|
|
|
void *arg);
|
2014-04-07 21:47:39 +00:00
|
|
|
|
2015-04-10 17:19:45 +00:00
|
|
|
~OSXEthernetTap();
|
2014-04-07 21:47:39 +00:00
|
|
|
|
2015-04-10 17:19:45 +00:00
|
|
|
void setEnabled(bool en);
|
|
|
|
bool enabled() const;
|
2015-04-15 00:57:51 +00:00
|
|
|
bool addIp(const InetAddress &ip);
|
|
|
|
bool removeIp(const InetAddress &ip);
|
|
|
|
std::vector<InetAddress> ips() const;
|
2015-04-10 17:19:45 +00:00
|
|
|
void put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
|
|
|
std::string deviceName() const;
|
|
|
|
void setFriendlyName(const char *friendlyName);
|
2015-04-15 00:57:51 +00:00
|
|
|
void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed);
|
2017-05-05 02:31:50 +00:00
|
|
|
void setMtu(unsigned int mtu);
|
2014-04-07 21:47:39 +00:00
|
|
|
|
|
|
|
void threadMain()
|
|
|
|
throw();
|
|
|
|
|
|
|
|
private:
|
2017-03-28 00:03:17 +00:00
|
|
|
void (*_handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int);
|
2014-04-07 21:47:39 +00:00
|
|
|
void *_arg;
|
2015-04-15 00:57:51 +00:00
|
|
|
uint64_t _nwid;
|
2014-04-07 21:47:39 +00:00
|
|
|
Thread _thread;
|
2015-04-15 00:57:51 +00:00
|
|
|
std::string _homePath;
|
2014-04-07 21:47:39 +00:00
|
|
|
std::string _dev;
|
2015-04-15 00:57:51 +00:00
|
|
|
std::vector<MulticastGroup> _multicastGroups;
|
2014-07-31 22:13:48 +00:00
|
|
|
unsigned int _mtu;
|
|
|
|
unsigned int _metric;
|
2014-04-07 21:47:39 +00:00
|
|
|
int _fd;
|
|
|
|
int _shutdownSignalPipe[2];
|
|
|
|
volatile bool _enabled;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ZeroTier
|
|
|
|
|
|
|
|
#endif
|