mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-19 03:06:26 +00:00
Integrate arp into NetconEthernetTap.
This commit is contained in:
parent
c2226cf0df
commit
a8d7a31327
@ -67,6 +67,7 @@ NetconEthernetTap::NetconEthernetTap(
|
|||||||
_handler(handler),
|
_handler(handler),
|
||||||
_arg(arg),
|
_arg(arg),
|
||||||
_nwid(nwid),
|
_nwid(nwid),
|
||||||
|
_mac(mac),
|
||||||
_homePath(homePath),
|
_homePath(homePath),
|
||||||
_mtu(mtu),
|
_mtu(mtu),
|
||||||
_enabled(true),
|
_enabled(true),
|
||||||
@ -113,6 +114,11 @@ bool NetconEthernetTap::addIp(const InetAddress &ip)
|
|||||||
_ips.push_back(ip);
|
_ips.push_back(ip);
|
||||||
std::sort(_ips.begin(),_ips.end());
|
std::sort(_ips.begin(),_ips.end());
|
||||||
|
|
||||||
|
if (ip.isV4()) {
|
||||||
|
Mutex::Lock _l2(_arp_m);
|
||||||
|
_arp.setLocal((uint32_t)(reinterpret_cast<const struct sockaddr_in *>(ip)->sin_addr.s_addr),_mac);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: alloc IP in LWIP
|
// TODO: alloc IP in LWIP
|
||||||
//netif_set_addr(netif, ipaddr, netmask, gw);
|
//netif_set_addr(netif, ipaddr, netmask, gw);
|
||||||
}
|
}
|
||||||
@ -127,6 +133,12 @@ bool NetconEthernetTap::removeIp(const InetAddress &ip)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
_ips.erase(i);
|
_ips.erase(i);
|
||||||
|
|
||||||
|
if (ip.isV4()) {
|
||||||
|
Mutex::Lock _l2(_arp_m);
|
||||||
|
_arp.remove((uint32_t)(reinterpret_cast<const struct sockaddr_in *>(ip)->sin_addr.s_addr));
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: dealloc IP from LWIP
|
// TODO: dealloc IP from LWIP
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -142,6 +154,19 @@ void NetconEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType
|
|||||||
{
|
{
|
||||||
if (!_enabled)
|
if (!_enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (etherType == ZT_ETHERTYPE_ARP) {
|
||||||
|
char arpReplyBuf[ZT_ARP_BUF_LENGTH];
|
||||||
|
unsigned int arpReplyLen = 0;
|
||||||
|
MAC arpReplyDest;
|
||||||
|
|
||||||
|
Mutex::Lock _l2(_arp_m);
|
||||||
|
_arp.processIncomingArp(data,len,arpReplyBuf,arpReplyLen,arpReplyDest);
|
||||||
|
if (arpReplyLen > 0)
|
||||||
|
_handler(_arg,_nwid,_mac,from,ZT_ETHERTYPE_ARP,0,arpReplyBuf,arpReplyLen);
|
||||||
|
} else if (etherType == ZT_ETHERTYPE_IPV4) {
|
||||||
|
// TODO: pass IPv4 packets into LWIP
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string NetconEthernetTap::deviceName() const
|
std::string NetconEthernetTap::deviceName() const
|
||||||
@ -155,9 +180,29 @@ void NetconEthernetTap::setFriendlyName(const char *friendlyName)
|
|||||||
|
|
||||||
void NetconEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed)
|
void NetconEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed)
|
||||||
{
|
{
|
||||||
// TODO: get multicast subscriptions from LWIP
|
std::vector<MulticastGroup> newGroups;
|
||||||
}
|
Mutex::Lock _l(_multicastGroups_m);
|
||||||
|
|
||||||
|
// TODO: get multicast subscriptions from LWIP
|
||||||
|
|
||||||
|
std::vector<InetAddress> allIps(ips());
|
||||||
|
for(std::vector<InetAddress>::iterator ip(allIps.begin());ip!=allIps.end();++ip)
|
||||||
|
newGroups.push_back(MulticastGroup::deriveMulticastGroupForAddressResolution(*ip));
|
||||||
|
|
||||||
|
std::sort(newGroups.begin(),newGroups.end());
|
||||||
|
std::unique(newGroups.begin(),newGroups.end());
|
||||||
|
|
||||||
|
for(std::vector<MulticastGroup>::iterator m(newGroups.begin());m!=newGroups.end();++m) {
|
||||||
|
if (!std::binary_search(_multicastGroups.begin(),_multicastGroups.end(),*m))
|
||||||
|
added.push_back(*m);
|
||||||
|
}
|
||||||
|
for(std::vector<MulticastGroup>::iterator m(_multicastGroups.begin());m!=_multicastGroups.end();++m) {
|
||||||
|
if (!std::binary_search(newGroups.begin(),newGroups.end(),*m))
|
||||||
|
removed.push_back(*m);
|
||||||
|
}
|
||||||
|
|
||||||
|
_multicastGroups.swap(newGroups);
|
||||||
|
}
|
||||||
|
|
||||||
NetconConnection *NetconEthernetTap::getConnectionByPCB(struct tcp_pcb *pcb)
|
NetconConnection *NetconEthernetTap::getConnectionByPCB(struct tcp_pcb *pcb)
|
||||||
{
|
{
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#include "../node/InetAddress.hpp"
|
#include "../node/InetAddress.hpp"
|
||||||
#include "../osdep/Thread.hpp"
|
#include "../osdep/Thread.hpp"
|
||||||
#include "../osdep/Phy.hpp"
|
#include "../osdep/Phy.hpp"
|
||||||
|
#include "../osdep/Arp.hpp"
|
||||||
|
|
||||||
#include "NetconService.hpp"
|
#include "NetconService.hpp"
|
||||||
#include "NetconUtilities.hpp"
|
#include "NetconUtilities.hpp"
|
||||||
@ -151,12 +152,16 @@ private:
|
|||||||
std::vector<NetconClient*> clients;
|
std::vector<NetconClient*> clients;
|
||||||
|
|
||||||
uint64_t _nwid;
|
uint64_t _nwid;
|
||||||
|
MAC _mac;
|
||||||
Thread _thread;
|
Thread _thread;
|
||||||
std::string _homePath;
|
std::string _homePath;
|
||||||
std::string _dev; // path to Unix domain socket
|
std::string _dev; // path to Unix domain socket
|
||||||
|
|
||||||
std::vector<MulticastGroup> _lastMulticastGroupList;
|
Arp _arp;
|
||||||
Mutex _lastMulticastGroupList_m;
|
Mutex _arp_m;
|
||||||
|
|
||||||
|
std::vector<MulticastGroup> _multicastGroups;
|
||||||
|
Mutex _multicastGroups_m;
|
||||||
|
|
||||||
std::vector<InetAddress> _ips;
|
std::vector<InetAddress> _ips;
|
||||||
Mutex _ips_m;
|
Mutex _ips_m;
|
||||||
|
@ -353,4 +353,14 @@
|
|||||||
*/
|
*/
|
||||||
#define ZT_TEST_NETWORK_ID 0xffffffffffffffffULL
|
#define ZT_TEST_NETWORK_ID 0xffffffffffffffffULL
|
||||||
|
|
||||||
|
/* Ethernet frame types that might be relevant to us */
|
||||||
|
#define ZT_ETHERTYPE_IPV4 0x0800
|
||||||
|
#define ZT_ETHERTYPE_ARP 0x0806
|
||||||
|
#define ZT_ETHERTYPE_RARP 0x8035
|
||||||
|
#define ZT_ETHERTYPE_ATALK 0x809b
|
||||||
|
#define ZT_ETHERTYPE_AARP 0x80f3
|
||||||
|
#define ZT_ETHERTYPE_IPX_A 0x8137
|
||||||
|
#define ZT_ETHERTYPE_IPX_B 0x8138
|
||||||
|
#define ZT_ETHERTYPE_IPV6 0x86dd
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -47,16 +47,6 @@
|
|||||||
#include "IncomingPacket.hpp"
|
#include "IncomingPacket.hpp"
|
||||||
#include "Hashtable.hpp"
|
#include "Hashtable.hpp"
|
||||||
|
|
||||||
/* Ethernet frame types that might be relevant to us */
|
|
||||||
#define ZT_ETHERTYPE_IPV4 0x0800
|
|
||||||
#define ZT_ETHERTYPE_ARP 0x0806
|
|
||||||
#define ZT_ETHERTYPE_RARP 0x8035
|
|
||||||
#define ZT_ETHERTYPE_ATALK 0x809b
|
|
||||||
#define ZT_ETHERTYPE_AARP 0x80f3
|
|
||||||
#define ZT_ETHERTYPE_IPX_A 0x8137
|
|
||||||
#define ZT_ETHERTYPE_IPX_B 0x8138
|
|
||||||
#define ZT_ETHERTYPE_IPV6 0x86dd
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
class RuntimeEnvironment;
|
class RuntimeEnvironment;
|
||||||
|
Loading…
Reference in New Issue
Block a user