From ef3e319c64600a921c9d6b33391f026644ec2492 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 9 Jul 2013 14:06:55 -0400 Subject: Several things: (1) Probable fix for issue #7 and major cleanup of EthernetTap code with consolidation for all unix-like systems and specialization for different flavors only when needed. (2) Refactor of Buffer<> to make its members private, and Packet to use Buffer's methods exclusively to access them. This improves clarity and means we're no longer lying about Buffer's role in the code's security posture. (3) Add -fstack-protect to Makefile to bounds check stack variables. --- node/Network.cpp | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) (limited to 'node/Network.cpp') diff --git a/node/Network.cpp b/node/Network.cpp index 41f04e9f..f34e07e0 100644 --- a/node/Network.cpp +++ b/node/Network.cpp @@ -32,49 +32,29 @@ namespace ZeroTier { Network::Network(const RuntimeEnvironment *renv,uint64_t id) throw(std::runtime_error) : - Thread(), _r(renv), _id(id), - _tap(renv,renv->identity.address().toMAC(),ZT_IF_MTU), + _tap(renv,renv->identity.address().toMAC(),ZT_IF_MTU,&_CBhandleTapData,this), _members(), _open(false), _lock() { - TRACE("new network %llu created, TAP device: %s",id,_tap.deviceName().c_str()); - start(); } Network::~Network() { - _tap.close(); - join(); - TRACE("network %llu (%s) closed",_id,_tap.deviceName().c_str()); } -void Network::main() - throw() +void Network::_CBhandleTapData(void *arg,const MAC &from,const MAC &to,unsigned int etherType,const Buffer<4096> &data) { - Buffer<4096> buf; - MAC from,to; - unsigned int etherType = 0; - - while (_tap.open()) { - unsigned int len = _tap.get(from,to,etherType,buf.data()); - if (len) { - buf.setSize(len); - try { - if (!*__refCount) - break; // sanity check - _r->sw->onLocalEthernet(SharedPtr(this),from,to,etherType,buf); - } catch (std::exception &exc) { - TRACE("unexpected exception handling local packet: %s",exc.what()); - } catch ( ... ) { - TRACE("unexpected exception handling local packet"); - } - } else break; + const RuntimeEnvironment *_r = ((Network *)arg)->_r; + try { + _r->sw->onLocalEthernet(SharedPtr((Network *)arg),from,to,etherType,data); + } catch (std::exception &exc) { + TRACE("unexpected exception handling local packet: %s",exc.what()); + } catch ( ... ) { + TRACE("unexpected exception handling local packet"); } - - TRACE("network %llu thread terminating",_id); } } // namespace ZeroTier -- cgit v1.2.3