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_ETHERNETTAP_HPP
15 #define ZT_ETHERNETTAP_HPP
16 
17 #include "../node/Constants.hpp"
18 #include "../node/MAC.hpp"
19 #include "../node/InetAddress.hpp"
20 #include "../node/MulticastGroup.hpp"
21 
22 #include <string>
23 #include <memory>
24 #include <vector>
25 
26 namespace ZeroTier {
27 
28 class EthernetTap
29 {
30 public:
31 	static std::shared_ptr<EthernetTap> newInstance(
32 		const char *tapDeviceType, // OS-specific, NULL for default
33 		const char *homePath,
34 		const MAC &mac,
35 		unsigned int mtu,
36 		unsigned int metric,
37 		uint64_t nwid,
38 		const char *friendlyName,
39 		void (*handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int),
40 		void *arg);
41 
42 	EthernetTap();
43 	virtual ~EthernetTap();
44 
45 	virtual void setEnabled(bool en) = 0;
46 	virtual bool enabled() const = 0;
47 	virtual bool addIp(const InetAddress &ip) = 0;
48 	virtual bool addIps(std::vector<InetAddress> ips); // uses addIp() unless overridden
49 	virtual bool removeIp(const InetAddress &ip) = 0;
50 	virtual std::vector<InetAddress> ips() const = 0;
51 	virtual void put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len) = 0;
52 	virtual std::string deviceName() const = 0;
53 	virtual void setFriendlyName(const char *friendlyName) = 0;
54 	virtual std::string friendlyName() const;
55 	virtual void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed) = 0;
56 	virtual void setMtu(unsigned int mtu) = 0;
57 	virtual void setDns(const char *domain, const std::vector<InetAddress> &servers) = 0;
58 };
59 
60 } // namespace ZeroTier
61 
62 #endif
63