2014-04-07 21:47:39 +00:00
|
|
|
/*
|
2015-02-17 21:11:34 +00:00
|
|
|
* ZeroTier One - Network Virtualization Everywhere
|
|
|
|
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
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/>.
|
|
|
|
*
|
|
|
|
* --
|
|
|
|
*
|
|
|
|
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
|
|
|
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
*
|
|
|
|
* If you would like to embed ZeroTier into a commercial application or
|
|
|
|
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
|
|
|
* LLC. Start here: http://www.zerotier.com/
|
|
|
|
*/
|
|
|
|
|
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,
|
2015-04-15 00:57:51 +00:00
|
|
|
void (*handler)(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);
|
2014-04-07 21:47:39 +00:00
|
|
|
|
|
|
|
void threadMain()
|
|
|
|
throw();
|
|
|
|
|
|
|
|
private:
|
2015-04-15 00:57:51 +00:00
|
|
|
void (*_handler)(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
|