2014-04-07 21:47:39 +00:00
|
|
|
/*
|
2019-08-23 16:23:39 +00:00
|
|
|
* Copyright (c)2019 ZeroTier, Inc.
|
2014-04-07 21:47:39 +00:00
|
|
|
*
|
2019-08-23 16:23:39 +00:00
|
|
|
* Use of this software is governed by the Business Source License included
|
|
|
|
* in the LICENSE.TXT file in the project's root directory.
|
2014-04-07 21:47:39 +00:00
|
|
|
*
|
2020-08-20 19:51:39 +00:00
|
|
|
* Change Date: 2025-01-01
|
2014-04-07 21:47:39 +00:00
|
|
|
*
|
2019-08-23 16:23:39 +00:00
|
|
|
* On the date above, in accordance with the Business Source License, use
|
|
|
|
* of this software will be governed by version 2.0 of the Apache License.
|
2014-04-07 21:47:39 +00:00
|
|
|
*/
|
2019-08-23 16:23:39 +00:00
|
|
|
/****/
|
2014-04-07 21:47:39 +00:00
|
|
|
|
2014-07-21 16:18:33 +00:00
|
|
|
#ifndef ZT_LINUXETHERNETTAP_HPP
|
|
|
|
#define ZT_LINUXETHERNETTAP_HPP
|
2014-04-07 21:47:39 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2015-04-20 22:12:31 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2014-04-07 21:47:39 +00:00
|
|
|
#include <stdexcept>
|
2019-08-07 23:14:12 +00:00
|
|
|
#include <atomic>
|
2020-11-17 02:40:25 +00:00
|
|
|
#include <array>
|
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
2015-04-20 22:12:31 +00:00
|
|
|
#include "../node/MulticastGroup.hpp"
|
2019-08-07 23:14:12 +00:00
|
|
|
#include "EthernetTap.hpp"
|
2014-04-07 21:47:39 +00:00
|
|
|
|
|
|
|
namespace ZeroTier {
|
|
|
|
|
2019-08-07 23:14:12 +00:00
|
|
|
class LinuxEthernetTap : public EthernetTap
|
2014-04-07 21:47:39 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-07-21 16:18:33 +00:00
|
|
|
LinuxEthernetTap(
|
2015-04-20 22:12:31 +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
|
|
|
|
2019-08-07 23:14:12 +00:00
|
|
|
virtual ~LinuxEthernetTap();
|
2014-04-07 21:47:39 +00:00
|
|
|
|
2019-08-07 23:14:12 +00:00
|
|
|
virtual void setEnabled(bool en);
|
|
|
|
virtual bool enabled() const;
|
|
|
|
virtual bool addIp(const InetAddress &ip);
|
2019-08-27 21:43:30 +00:00
|
|
|
virtual bool addIps(std::vector<InetAddress> ips);
|
2019-08-07 23:14:12 +00:00
|
|
|
virtual bool removeIp(const InetAddress &ip);
|
|
|
|
virtual std::vector<InetAddress> ips() const;
|
|
|
|
virtual void put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
|
|
|
virtual std::string deviceName() const;
|
|
|
|
virtual void setFriendlyName(const char *friendlyName);
|
|
|
|
virtual void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed);
|
|
|
|
virtual void setMtu(unsigned int mtu);
|
2020-08-12 16:14:10 +00:00
|
|
|
virtual void setDns(const char *domain, const std::vector<InetAddress> &servers) {}
|
2014-04-07 21:47:39 +00:00
|
|
|
|
|
|
|
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-20 22:12:31 +00:00
|
|
|
uint64_t _nwid;
|
2020-11-11 20:14:08 +00:00
|
|
|
MAC _mac;
|
2015-04-20 22:12:31 +00:00
|
|
|
std::string _homePath;
|
2014-04-07 21:47:39 +00:00
|
|
|
std::string _dev;
|
2015-04-20 22:12:31 +00:00
|
|
|
std::vector<MulticastGroup> _multicastGroups;
|
|
|
|
unsigned int _mtu;
|
2014-04-07 21:47:39 +00:00
|
|
|
int _fd;
|
2020-11-19 03:24:18 +00:00
|
|
|
int _shutdownSignalPipe[2];
|
2019-08-07 23:14:12 +00:00
|
|
|
std::atomic_bool _enabled;
|
2020-11-30 20:46:16 +00:00
|
|
|
std::atomic_bool _run;
|
2021-06-28 23:29:53 +00:00
|
|
|
std::thread _tapReaderThread;
|
2014-04-07 21:47:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ZeroTier
|
|
|
|
|
|
|
|
#endif
|