Merge branch 'adamierymenko-dev' into android-jni

This commit is contained in:
Grant Limberg 2015-04-25 18:59:52 -07:00
commit ec45aeb42a
52 changed files with 11356 additions and 2340 deletions

View File

@ -1,949 +0,0 @@
/*
* ZeroTier One - Network Virtualization Everywhere
* Copyright (C) 2011-2015 ZeroTier, Inc.
*
* 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/
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <list>
#include <vector>
#include <string>
#include "Constants.hpp"
#ifdef __WINDOWS__
#include <WinSock2.h>
#include <Windows.h>
#include <ShlObj.h>
#else
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <sys/file.h>
#endif
#include "../version.h"
#include "Node.hpp"
#include "RuntimeEnvironment.hpp"
#include "Logger.hpp"
#include "Utils.hpp"
#include "Defaults.hpp"
#include "Identity.hpp"
#include "Topology.hpp"
#include "SocketManager.hpp"
#include "Packet.hpp"
#include "Switch.hpp"
#include "EthernetTap.hpp"
#include "CMWC4096.hpp"
#include "NodeConfig.hpp"
#include "Network.hpp"
#include "MulticastGroup.hpp"
#include "Multicaster.hpp"
#include "Mutex.hpp"
#include "SoftwareUpdater.hpp"
#include "Buffer.hpp"
#include "AntiRecursion.hpp"
#include "HttpClient.hpp"
#include "NetworkConfigMaster.hpp"
namespace ZeroTier {
struct _NodeImpl
{
RuntimeEnvironment renv;
std::string reasonForTerminationStr;
volatile Node::ReasonForTermination reasonForTermination;
volatile bool started;
volatile bool running;
volatile bool resynchronize;
volatile bool disableRootTopologyUpdates;
std::string overrideRootTopology;
// This function performs final node tear-down
inline Node::ReasonForTermination terminate()
{
RuntimeEnvironment *RR = &renv;
LOG("terminating: %s",reasonForTerminationStr.c_str());
running = false;
delete renv.updater; renv.updater = (SoftwareUpdater *)0;
delete renv.nc; renv.nc = (NodeConfig *)0; // shut down all networks, close taps, etc.
delete renv.topology; renv.topology = (Topology *)0; // now we no longer need routing info
delete renv.mc; renv.mc = (Multicaster *)0;
delete renv.antiRec; renv.antiRec = (AntiRecursion *)0;
delete renv.sw; renv.sw = (Switch *)0; // order matters less from here down
delete renv.http; renv.http = (HttpClient *)0;
delete renv.prng; renv.prng = (CMWC4096 *)0;
delete renv.log; renv.log = (Logger *)0; // but stop logging last of all
return reasonForTermination;
}
inline Node::ReasonForTermination terminateBecause(Node::ReasonForTermination r,const char *rstr)
{
reasonForTerminationStr = rstr;
reasonForTermination = r;
return terminate();
}
};
Node::Node(
const char *hp,
EthernetTapFactory *tf,
SocketManager *sm,
NetworkConfigMaster *nm,
bool resetIdentity,
const char *overrideRootTopology) throw() :
_impl(new _NodeImpl)
{
_NodeImpl *impl = (_NodeImpl *)_impl;
if ((hp)&&(hp[0]))
impl->renv.homePath = hp;
else impl->renv.homePath = ZT_DEFAULTS.defaultHomePath;
impl->renv.tapFactory = tf;
impl->renv.sm = sm;
impl->renv.netconfMaster = nm;
if (resetIdentity) {
// Forget identity and peer database, peer keys, etc.
Utils::rm((impl->renv.homePath + ZT_PATH_SEPARATOR_S + "identity.public").c_str());
Utils::rm((impl->renv.homePath + ZT_PATH_SEPARATOR_S + "identity.secret").c_str());
Utils::rm((impl->renv.homePath + ZT_PATH_SEPARATOR_S + "peers.persist").c_str());
// Truncate network config information in networks.d but leave the files since we
// still want to remember any networks we have joined. This will force those networks
// to be reconfigured with our newly regenerated identity after startup.
std::string networksDotD(impl->renv.homePath + ZT_PATH_SEPARATOR_S + "networks.d");
std::map< std::string,bool > nwfiles(Utils::listDirectory(networksDotD.c_str()));
for(std::map<std::string,bool>::iterator nwf(nwfiles.begin());nwf!=nwfiles.end();++nwf) {
FILE *trun = fopen((networksDotD + ZT_PATH_SEPARATOR_S + nwf->first).c_str(),"w");
if (trun)
fclose(trun);
}
}
impl->reasonForTermination = Node::NODE_RUNNING;
impl->started = false;
impl->running = false;
impl->resynchronize = false;
if (overrideRootTopology) {
impl->disableRootTopologyUpdates = true;
impl->overrideRootTopology = overrideRootTopology;
} else {
impl->disableRootTopologyUpdates = false;
}
}
Node::~Node()
{
delete (_NodeImpl *)_impl;
}
static void _CBztTraffic(const SharedPtr<Socket> &fromSock,void *arg,const InetAddress &from,Buffer<ZT_SOCKET_MAX_MESSAGE_LEN> &data)
{
((const RuntimeEnvironment *)arg)->sw->onRemotePacket(fromSock,from,data);
}
static void _cbHandleGetRootTopology(void *arg,int code,const std::string &url,const std::string &body)
{
RuntimeEnvironment *RR = (RuntimeEnvironment *)arg;
if ((code != 200)||(body.length() == 0)) {
TRACE("failed to retrieve %s",url.c_str());
return;
}
try {
Dictionary rt(body);
if (!Topology::authenticateRootTopology(rt)) {
LOG("discarded invalid root topology update from %s (signature check failed)",url.c_str());
return;
}
{
std::string rootTopologyPath(RR->homePath + ZT_PATH_SEPARATOR_S + "root-topology");
std::string rootTopology;
if (Utils::readFile(rootTopologyPath.c_str(),rootTopology)) {
Dictionary alreadyHave(rootTopology);
if (alreadyHave == rt) {
TRACE("retrieved root topology from %s but no change (same as on disk)",url.c_str());
return;
} else if (alreadyHave.signatureTimestamp() > rt.signatureTimestamp()) {
TRACE("retrieved root topology from %s but no change (ours is newer)",url.c_str());
return;
}
}
Utils::writeFile(rootTopologyPath.c_str(),body);
}
RR->topology->setSupernodes(Dictionary(rt.get("supernodes")));
} catch ( ... ) {
LOG("discarded invalid root topology update from %s (format invalid)",url.c_str());
return;
}
}
Node::ReasonForTermination Node::run()
throw()
{
_NodeImpl *impl = (_NodeImpl *)_impl;
RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
impl->started = true;
impl->running = true;
try {
#ifdef ZT_LOG_STDOUT
RR->log = new Logger((const char *)0,(const char *)0,0);
#else
RR->log = new Logger((RR->homePath + ZT_PATH_SEPARATOR_S + "node.log").c_str(),(const char *)0,131072);
#endif
LOG("starting version %s",versionString());
// Create non-crypto PRNG right away in case other code in init wants to use it
RR->prng = new CMWC4096();
// Read identity public and secret, generating if not present
{
bool gotId = false;
std::string identitySecretPath(RR->homePath + ZT_PATH_SEPARATOR_S + "identity.secret");
std::string identityPublicPath(RR->homePath + ZT_PATH_SEPARATOR_S + "identity.public");
std::string idser;
if (Utils::readFile(identitySecretPath.c_str(),idser))
gotId = RR->identity.fromString(idser);
if ((gotId)&&(!RR->identity.locallyValidate()))
gotId = false;
if (gotId) {
// Make sure identity.public matches identity.secret
idser = std::string();
Utils::readFile(identityPublicPath.c_str(),idser);
std::string pubid(RR->identity.toString(false));
if (idser != pubid) {
if (!Utils::writeFile(identityPublicPath.c_str(),pubid))
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"could not write identity.public (home path not writable?)");
}
} else {
LOG("no identity found or identity invalid, generating one... this might take a few seconds...");
RR->identity.generate();
LOG("generated new identity: %s",RR->identity.address().toString().c_str());
idser = RR->identity.toString(true);
if (!Utils::writeFile(identitySecretPath.c_str(),idser))
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"could not write identity.secret (home path not writable?)");
idser = RR->identity.toString(false);
if (!Utils::writeFile(identityPublicPath.c_str(),idser))
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"could not write identity.public (home path not writable?)");
}
Utils::lockDownFile(identitySecretPath.c_str(),false);
}
// Make sure networks.d exists (used by NodeConfig to remember networks)
{
std::string networksDotD(RR->homePath + ZT_PATH_SEPARATOR_S + "networks.d");
#ifdef __WINDOWS__
CreateDirectoryA(networksDotD.c_str(),NULL);
#else
mkdir(networksDotD.c_str(),0700);
#endif
}
// Make sure iddb.d exists (used by Topology to remember identities)
{
std::string iddbDotD(RR->homePath + ZT_PATH_SEPARATOR_S + "iddb.d");
#ifdef __WINDOWS__
CreateDirectoryA(iddbDotD.c_str(),NULL);
#else
mkdir(iddbDotD.c_str(),0700);
#endif
}
RR->http = new HttpClient();
RR->sw = new Switch(RR);
RR->mc = new Multicaster(RR);
RR->antiRec = new AntiRecursion();
RR->topology = new Topology(RR);
try {
RR->nc = new NodeConfig(RR);
} catch (std::exception &exc) {
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"unable to initialize IPC socket: is ZeroTier One already running?");
}
RR->node = this;
#ifdef ZT_AUTO_UPDATE
if (ZT_DEFAULTS.updateLatestNfoURL.length()) {
RR->updater = new SoftwareUpdater(RR);
RR->updater->cleanOldUpdates(); // clean out updates.d on startup
} else {
LOG("WARNING: unable to enable software updates: latest .nfo URL from ZT_DEFAULTS is empty (does this platform actually support software updates?)");
}
#endif
// Initialize root topology from defaults or root-toplogy file in home path on disk
if (impl->overrideRootTopology.length() == 0) {
std::string rootTopologyPath(RR->homePath + ZT_PATH_SEPARATOR_S + "root-topology");
std::string rootTopology;
if (!Utils::readFile(rootTopologyPath.c_str(),rootTopology))
rootTopology = ZT_DEFAULTS.defaultRootTopology;
try {
Dictionary rt(rootTopology);
if (Topology::authenticateRootTopology(rt)) {
// Set supernodes if root topology signature is valid
RR->topology->setSupernodes(Dictionary(rt.get("supernodes",""))); // set supernodes from root-topology
// If root-topology contains noupdate=1, disable further updates and only use what was on disk
impl->disableRootTopologyUpdates = (Utils::strToInt(rt.get("noupdate","0").c_str()) > 0);
} else {
// Revert to built-in defaults if root topology fails signature check
LOG("%s failed signature check, using built-in defaults instead",rootTopologyPath.c_str());
Utils::rm(rootTopologyPath.c_str());
RR->topology->setSupernodes(Dictionary(Dictionary(ZT_DEFAULTS.defaultRootTopology).get("supernodes","")));
impl->disableRootTopologyUpdates = false;
}
} catch ( ... ) {
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"invalid root-topology format");
}
} else {
try {
Dictionary rt(impl->overrideRootTopology);
RR->topology->setSupernodes(Dictionary(rt.get("supernodes","")));
impl->disableRootTopologyUpdates = true;
} catch ( ... ) {
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"invalid root-topology format");
}
}
// Delete peers.persist if it exists -- legacy file, just takes up space
Utils::rm(std::string(RR->homePath + ZT_PATH_SEPARATOR_S + "peers.persist").c_str());
} catch (std::bad_alloc &exc) {
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"memory allocation failure");
} catch (std::runtime_error &exc) {
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,exc.what());
} catch ( ... ) {
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"unknown exception during initialization");
}
// Core I/O loop
try {
/* Shut down if this file exists but fails to open. This is used on Mac to
* shut down automatically on .app deletion by symlinking this to the
* Info.plist file inside the ZeroTier One application. This causes the
* service to die when the user throws away the app, allowing uninstallation
* in the natural Mac way. */
std::string shutdownIfUnreadablePath(RR->homePath + ZT_PATH_SEPARATOR_S + "shutdownIfUnreadable");
uint64_t lastNetworkAutoconfCheck = Utils::now() - 5000ULL; // check autoconf again after 5s for startup
uint64_t lastPingCheck = 0;
uint64_t lastClean = Utils::now(); // don't need to do this immediately
uint64_t lastMulticastCheck = 0;
uint64_t lastSupernodePingCheck = 0;
uint64_t lastBeacon = 0;
uint64_t lastRootTopologyFetch = 0;
uint64_t lastShutdownIfUnreadableCheck = 0;
long lastDelayDelta = 0;
RR->timeOfLastResynchronize = Utils::now();
// We are up and running
RR->initialized = true;
while (impl->reasonForTermination == NODE_RUNNING) {
uint64_t now = Utils::now();
bool resynchronize = false;
/* This is how the service automatically shuts down when the OSX .app is
* thrown in the trash. It's not used on any other platform for now but
* could do similar things. It's disabled on Windows since it doesn't really
* work there. */
#ifdef __UNIX_LIKE__
if ((now - lastShutdownIfUnreadableCheck) > 10000) {
lastShutdownIfUnreadableCheck = now;
if (Utils::fileExists(shutdownIfUnreadablePath.c_str(),false)) {
int tmpfd = ::open(shutdownIfUnreadablePath.c_str(),O_RDONLY,0);
if (tmpfd < 0) {
return impl->terminateBecause(Node::NODE_NORMAL_TERMINATION,"shutdownIfUnreadable exists but is not readable");
} else ::close(tmpfd);
}
}
#endif
// If it looks like the computer slept and woke, resynchronize.
if (lastDelayDelta >= ZT_SLEEP_WAKE_DETECTION_THRESHOLD) {
resynchronize = true;
LOG("probable suspend/resume detected, pausing a moment for things to settle...");
Thread::sleep(ZT_SLEEP_WAKE_SETTLE_TIME);
}
// Supernodes do not resynchronize unless explicitly ordered via SIGHUP.
if ((resynchronize)&&(RR->topology->amSupernode()))
resynchronize = false;
// Check for SIGHUP / force resync.
if (impl->resynchronize) {
impl->resynchronize = false;
resynchronize = true;
LOG("resynchronize forced by user, syncing with network");
}
if (resynchronize) {
RR->tcpTunnelingEnabled = false; // turn off TCP tunneling master switch at first, will be reenabled on persistent UDP failure
RR->timeOfLastResynchronize = now;
}
/* Supernodes are pinged separately and more aggressively. The
* ZT_STARTUP_AGGRO parameter sets a limit on how rapidly they are
* tried, while PingSupernodesThatNeedPing contains the logic for
* determining if they need PING. */
if ((now - lastSupernodePingCheck) >= ZT_STARTUP_AGGRO) {
lastSupernodePingCheck = now;
uint64_t lastReceiveFromAnySupernode = 0; // function object result paramter
RR->topology->eachSupernodePeer(Topology::FindMostRecentDirectReceiveTimestamp(lastReceiveFromAnySupernode));
// Turn on TCP tunneling master switch if we haven't heard anything since before
// the last resynchronize and we've been trying long enough.
uint64_t tlr = RR->timeOfLastResynchronize;
if ((lastReceiveFromAnySupernode < tlr)&&((now - tlr) >= ZT_TCP_TUNNEL_FAILOVER_TIMEOUT)) {
TRACE("network still unreachable after %u ms, TCP TUNNELING ENABLED",(unsigned int)ZT_TCP_TUNNEL_FAILOVER_TIMEOUT);
RR->tcpTunnelingEnabled = true;
}
RR->topology->eachSupernodePeer(Topology::PingSupernodesThatNeedPing(RR,now));
}
if (resynchronize) {
RR->sm->closeTcpSockets();
} else {
/* Periodically check for changes in our local multicast subscriptions
* and broadcast those changes to directly connected peers. */
if ((now - lastMulticastCheck) >= ZT_MULTICAST_LOCAL_POLL_PERIOD) {
lastMulticastCheck = now;
try {
std::vector< SharedPtr<Network> > networks(RR->nc->networks());
for(std::vector< SharedPtr<Network> >::const_iterator nw(networks.begin());nw!=networks.end();++nw)
(*nw)->rescanMulticastGroups();
} catch (std::exception &exc) {
LOG("unexpected exception announcing multicast groups: %s",exc.what());
} catch ( ... ) {
LOG("unexpected exception announcing multicast groups: (unknown)");
}
}
/* Periodically ping all our non-stale direct peers unless we're a supernode.
* Supernodes only ping each other (which is done above). */
if ((!RR->topology->amSupernode())&&((now - lastPingCheck) >= ZT_PING_CHECK_DELAY)) {
lastPingCheck = now;
try {
RR->topology->eachPeer(Topology::PingPeersThatNeedPing(RR,now));
} catch (std::exception &exc) {
LOG("unexpected exception running ping check cycle: %s",exc.what());
} catch ( ... ) {
LOG("unexpected exception running ping check cycle: (unkonwn)");
}
}
}
// Update network configurations when needed.
try {
if ((resynchronize)||((now - lastNetworkAutoconfCheck) >= ZT_NETWORK_AUTOCONF_CHECK_DELAY)) {
lastNetworkAutoconfCheck = now;
std::vector< SharedPtr<Network> > nets(RR->nc->networks());
for(std::vector< SharedPtr<Network> >::iterator n(nets.begin());n!=nets.end();++n) {
if ((now - (*n)->lastConfigUpdate()) >= ZT_NETWORK_AUTOCONF_DELAY)
(*n)->requestConfiguration();
}
}
} catch ( ... ) {
LOG("unexpected exception updating network configurations (non-fatal, will retry)");
}
// Do periodic tasks in submodules.
if ((now - lastClean) >= ZT_DB_CLEAN_PERIOD) {
lastClean = now;
try {
RR->topology->clean(now);
} catch ( ... ) {
LOG("unexpected exception in Topology::clean() (non-fatal)");
}
try {
RR->mc->clean(now);
} catch ( ... ) {
LOG("unexpected exception in Multicaster::clean() (non-fatal)");
}
try {
RR->nc->clean();
} catch ( ... ) {
LOG("unexpected exception in NodeConfig::clean() (non-fatal)");
}
try {
if (RR->updater)
RR->updater->checkIfMaxIntervalExceeded(now);
} catch ( ... ) {
LOG("unexpected exception in SoftwareUpdater::checkIfMaxIntervalExceeded() (non-fatal)");
}
}
// Send beacons to physical local LANs
try {
if ((resynchronize)||((now - lastBeacon) >= ZT_BEACON_INTERVAL)) {
lastBeacon = now;
char bcn[ZT_PROTO_BEACON_LENGTH];
void *bcnptr = bcn;
*((uint32_t *)(bcnptr)) = RR->prng->next32();
bcnptr = bcn + 4;
*((uint32_t *)(bcnptr)) = RR->prng->next32();
RR->identity.address().copyTo(bcn + ZT_PROTO_BEACON_IDX_ADDRESS,ZT_ADDRESS_LENGTH);
TRACE("sending LAN beacon to %s",ZT_DEFAULTS.v4Broadcast.toString().c_str());
RR->antiRec->logOutgoingZT(bcn,ZT_PROTO_BEACON_LENGTH);
RR->sm->send(ZT_DEFAULTS.v4Broadcast,false,false,bcn,ZT_PROTO_BEACON_LENGTH);
}
} catch ( ... ) {
LOG("unexpected exception sending LAN beacon (non-fatal)");
}
// Check for updates to root topology (supernodes) periodically
try {
if ((now - lastRootTopologyFetch) >= ZT_UPDATE_ROOT_TOPOLOGY_CHECK_INTERVAL) {
lastRootTopologyFetch = now;
if (!impl->disableRootTopologyUpdates) {
TRACE("fetching root topology from %s",ZT_DEFAULTS.rootTopologyUpdateURL.c_str());
RR->http->GET(ZT_DEFAULTS.rootTopologyUpdateURL,HttpClient::NO_HEADERS,60,&_cbHandleGetRootTopology,RR);
}
}
} catch ( ... ) {
LOG("unexpected exception attempting to check for root topology updates (non-fatal)");
}
// Sleep for loop interval or until something interesting happens.
try {
unsigned long delay = std::min((unsigned long)ZT_MAX_SERVICE_LOOP_INTERVAL,RR->sw->doTimerTasks());
uint64_t start = Utils::now();
RR->sm->poll(delay,&_CBztTraffic,RR);
lastDelayDelta = (long)(Utils::now() - start) - (long)delay; // used to detect sleep/wake
} catch (std::exception &exc) {
LOG("unexpected exception running Switch doTimerTasks: %s",exc.what());
} catch ( ... ) {
LOG("unexpected exception running Switch doTimerTasks: (unknown)");
}
}
} catch ( ... ) {
LOG("FATAL: unexpected exception in core loop: unknown exception");
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"unexpected exception during outer main I/O loop");
}
return impl->terminate();
}
const char *Node::terminationMessage() const
throw()
{
if ((!((_NodeImpl *)_impl)->started)||(((_NodeImpl *)_impl)->running))
return (const char *)0;
return ((_NodeImpl *)_impl)->reasonForTerminationStr.c_str();
}
void Node::terminate(ReasonForTermination reason,const char *reasonText)
throw()
{
((_NodeImpl *)_impl)->reasonForTermination = reason;
((_NodeImpl *)_impl)->reasonForTerminationStr = ((reasonText) ? reasonText : "");
((_NodeImpl *)_impl)->renv.sm->whack();
}
void Node::resync()
throw()
{
((_NodeImpl *)_impl)->resynchronize = true;
((_NodeImpl *)_impl)->renv.sm->whack();
}
bool Node::online()
throw()
{
_NodeImpl *impl = (_NodeImpl *)_impl;
RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
if ((!RR)||(!RR->initialized))
return false;
uint64_t now = Utils::now();
uint64_t since = RR->timeOfLastResynchronize;
std::vector< SharedPtr<Peer> > snp(RR->topology->supernodePeers());
for(std::vector< SharedPtr<Peer> >::const_iterator sn(snp.begin());sn!=snp.end();++sn) {
uint64_t lastRec = (*sn)->lastDirectReceive();
if ((lastRec)&&(lastRec > since)&&((now - lastRec) < ZT_PEER_PATH_ACTIVITY_TIMEOUT))
return true;
}
return false;
}
bool Node::started()
throw()
{
_NodeImpl *impl = (_NodeImpl *)_impl;
return impl->started;
}
bool Node::running()
throw()
{
_NodeImpl *impl = (_NodeImpl *)_impl;
return impl->running;
}
bool Node::initialized()
throw()
{
_NodeImpl *impl = (_NodeImpl *)_impl;
RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
return ((RR)&&(RR->initialized));
}
uint64_t Node::address()
throw()
{
_NodeImpl *impl = (_NodeImpl *)_impl;
RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
if ((!RR)||(!RR->initialized))
return 0;
return RR->identity.address().toInt();
}
void Node::join(uint64_t nwid)
throw()
{
_NodeImpl *impl = (_NodeImpl *)_impl;
RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
if ((RR)&&(RR->initialized))
RR->nc->join(nwid);
}
void Node::leave(uint64_t nwid)
throw()
{
_NodeImpl *impl = (_NodeImpl *)_impl;
RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
if ((RR)&&(RR->initialized))
RR->nc->leave(nwid);
}
struct GatherPeerStatistics
{
uint64_t now;
ZT1_Node_Status *status;
inline void operator()(Topology &t,const SharedPtr<Peer> &p)
{
++status->knownPeers;
if (p->hasActiveDirectPath(now))
++status->directlyConnectedPeers;
if (p->alive(now))
++status->alivePeers;
}
};
void Node::status(ZT1_Node_Status *status)
throw()
{
_NodeImpl *impl = (_NodeImpl *)_impl;
RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
memset(status,0,sizeof(ZT1_Node_Status));
if ((!RR)||(!RR->initialized))
return;
Utils::scopy(status->publicIdentity,sizeof(status->publicIdentity),RR->identity.toString(false).c_str());
RR->identity.address().toString(status->address,sizeof(status->address));
status->rawAddress = RR->identity.address().toInt();
status->knownPeers = 0;
status->supernodes = RR->topology->numSupernodes();
status->directlyConnectedPeers = 0;
status->alivePeers = 0;
GatherPeerStatistics gps;
gps.now = Utils::now();
gps.status = status;
RR->topology->eachPeer<GatherPeerStatistics &>(gps);
if (status->alivePeers > 0) {
double dlsr = (double)status->directlyConnectedPeers / (double)status->alivePeers;
if (dlsr > 1.0) dlsr = 1.0;
if (dlsr < 0.0) dlsr = 0.0;
status->directLinkSuccessRate = (float)dlsr;
} else status->directLinkSuccessRate = 1.0f; // no connections to no active peers == 100% success at nothing
status->online = online();
status->running = impl->running;
status->initialized = true;
}
struct CollectPeersAndPaths
{
std::vector< std::pair< SharedPtr<Peer>,std::vector<Path> > > data;
inline void operator()(Topology &t,const SharedPtr<Peer> &p) { this->data.push_back(std::pair< SharedPtr<Peer>,std::vector<Path> >(p,p->paths())); }
};
struct SortPeersAndPathsInAscendingAddressOrder
{
inline bool operator()(const std::pair< SharedPtr<Peer>,std::vector<Path> > &a,const std::pair< SharedPtr<Peer>,std::vector<Path> > &b) const { return (a.first->address() < b.first->address()); }
};
ZT1_Node_PeerList *Node::listPeers()
throw()
{
_NodeImpl *impl = (_NodeImpl *)_impl;
RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
if ((!RR)||(!RR->initialized))
return (ZT1_Node_PeerList *)0;
CollectPeersAndPaths pp;
RR->topology->eachPeer<CollectPeersAndPaths &>(pp);
std::sort(pp.data.begin(),pp.data.end(),SortPeersAndPathsInAscendingAddressOrder());
unsigned int returnBufSize = sizeof(ZT1_Node_PeerList);
for(std::vector< std::pair< SharedPtr<Peer>,std::vector<Path> > >::iterator p(pp.data.begin());p!=pp.data.end();++p)
returnBufSize += sizeof(ZT1_Node_Peer) + (sizeof(ZT1_Node_PhysicalPath) * (unsigned int)p->second.size());
char *buf = (char *)::malloc(returnBufSize);
if (!buf)
return (ZT1_Node_PeerList *)0;
memset(buf,0,returnBufSize);
ZT1_Node_PeerList *pl = (ZT1_Node_PeerList *)buf;
buf += sizeof(ZT1_Node_PeerList);
pl->peers = (ZT1_Node_Peer *)buf;
buf += (sizeof(ZT1_Node_Peer) * pp.data.size());
pl->numPeers = 0;
uint64_t now = Utils::now();
for(std::vector< std::pair< SharedPtr<Peer>,std::vector<Path> > >::iterator p(pp.data.begin());p!=pp.data.end();++p) {
ZT1_Node_Peer *prec = &(pl->peers[pl->numPeers++]);
if (p->first->remoteVersionKnown())
Utils::snprintf(prec->remoteVersion,sizeof(prec->remoteVersion),"%u.%u.%u",p->first->remoteVersionMajor(),p->first->remoteVersionMinor(),p->first->remoteVersionRevision());
p->first->address().toString(prec->address,sizeof(prec->address));
prec->rawAddress = p->first->address().toInt();
prec->latency = p->first->latency();
prec->role = RR->topology->isSupernode(p->first->address()) ? ZT1_Node_Peer_SUPERNODE : ZT1_Node_Peer_NODE;
prec->paths = (ZT1_Node_PhysicalPath *)buf;
buf += sizeof(ZT1_Node_PhysicalPath) * p->second.size();
prec->numPaths = 0;
for(std::vector<Path>::iterator pi(p->second.begin());pi!=p->second.end();++pi) {
ZT1_Node_PhysicalPath *path = &(prec->paths[prec->numPaths++]);
path->type = (ZT1_Node_PhysicalPathType)pi->type();
if (pi->address().isV6()) {
path->address.type = ZT1_Node_PhysicalAddress_TYPE_IPV6;
memcpy(path->address.bits,pi->address().rawIpData(),16);
// TODO: zoneIndex not supported yet, but should be once echo-location works w/V6
} else {
path->address.type = ZT1_Node_PhysicalAddress_TYPE_IPV4;
memcpy(path->address.bits,pi->address().rawIpData(),4);
}
path->address.port = pi->address().port();
Utils::scopy(path->address.ascii,sizeof(path->address.ascii),pi->address().toIpString().c_str());
path->lastSend = (pi->lastSend() > 0) ? ((long)(now - pi->lastSend())) : (long)-1;
path->lastReceive = (pi->lastReceived() > 0) ? ((long)(now - pi->lastReceived())) : (long)-1;
path->lastPing = (pi->lastPing() > 0) ? ((long)(now - pi->lastPing())) : (long)-1;
path->active = pi->active(now);
path->fixed = pi->fixed();
}
}
return pl;
}
// Fills out everything but ips[] and numIps, which must be done more manually
static void _fillNetworkQueryResultBuffer(const SharedPtr<Network> &network,const SharedPtr<NetworkConfig> &nconf,ZT1_Node_Network *nbuf)
{
nbuf->nwid = network->id();
Utils::snprintf(nbuf->nwidHex,sizeof(nbuf->nwidHex),"%.16llx",(unsigned long long)network->id());
if (nconf) {
Utils::scopy(nbuf->name,sizeof(nbuf->name),nconf->name().c_str());
Utils::scopy(nbuf->description,sizeof(nbuf->description),nconf->description().c_str());
}
Utils::scopy(nbuf->device,sizeof(nbuf->device),network->tapDeviceName().c_str());
Utils::scopy(nbuf->statusStr,sizeof(nbuf->statusStr),Network::statusString(network->status()));
network->mac().toString(nbuf->macStr,sizeof(nbuf->macStr));
network->mac().copyTo(nbuf->mac,sizeof(nbuf->mac));
uint64_t lcu = network->lastConfigUpdate();
if (lcu > 0)
nbuf->configAge = (long)(Utils::now() - lcu);
else nbuf->configAge = -1;
nbuf->status = (ZT1_Node_NetworkStatus)network->status();
nbuf->enabled = network->enabled();
nbuf->isPrivate = (nconf) ? nconf->isPrivate() : true;
}
ZT1_Node_Network *Node::getNetworkStatus(uint64_t nwid)
throw()
{
_NodeImpl *impl = (_NodeImpl *)_impl;
RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
if ((!RR)||(!RR->initialized))
return (ZT1_Node_Network *)0;
SharedPtr<Network> network(RR->nc->network(nwid));
if (!network)
return (ZT1_Node_Network *)0;
SharedPtr<NetworkConfig> nconf(network->config2());
std::set<InetAddress> ips(network->ips());
char *buf = (char *)::malloc(sizeof(ZT1_Node_Network) + (sizeof(ZT1_Node_PhysicalAddress) * ips.size()));
if (!buf)
return (ZT1_Node_Network *)0;
memset(buf,0,sizeof(ZT1_Node_Network) + (sizeof(ZT1_Node_PhysicalAddress) * ips.size()));
ZT1_Node_Network *nbuf = (ZT1_Node_Network *)buf;
buf += sizeof(ZT1_Node_Network);
_fillNetworkQueryResultBuffer(network,nconf,nbuf);
nbuf->ips = (ZT1_Node_PhysicalAddress *)buf;
nbuf->numIps = 0;
for(std::set<InetAddress>::iterator ip(ips.begin());ip!=ips.end();++ip) {
ZT1_Node_PhysicalAddress *ipb = &(nbuf->ips[nbuf->numIps++]);
if (ip->isV6()) {
ipb->type = ZT1_Node_PhysicalAddress_TYPE_IPV6;
memcpy(ipb->bits,ip->rawIpData(),16);
} else {
ipb->type = ZT1_Node_PhysicalAddress_TYPE_IPV4;
memcpy(ipb->bits,ip->rawIpData(),4);
}
ipb->port = ip->port();
Utils::scopy(ipb->ascii,sizeof(ipb->ascii),ip->toIpString().c_str());
}
return nbuf;
}
ZT1_Node_NetworkList *Node::listNetworks()
throw()
{
_NodeImpl *impl = (_NodeImpl *)_impl;
RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
if ((!RR)||(!RR->initialized))
return (ZT1_Node_NetworkList *)0;
std::vector< SharedPtr<Network> > networks(RR->nc->networks());
std::vector< SharedPtr<NetworkConfig> > nconfs(networks.size());
std::vector< std::set<InetAddress> > ipsv(networks.size());
unsigned long returnBufSize = sizeof(ZT1_Node_NetworkList);
for(unsigned long i=0;i<networks.size();++i) {
nconfs[i] = networks[i]->config2(); // note: can return NULL
ipsv[i] = networks[i]->ips();
returnBufSize += sizeof(ZT1_Node_Network) + (sizeof(ZT1_Node_PhysicalAddress) * (unsigned int)ipsv[i].size());
}
char *buf = (char *)::malloc(returnBufSize);
if (!buf)
return (ZT1_Node_NetworkList *)0;
memset(buf,0,returnBufSize);
ZT1_Node_NetworkList *nl = (ZT1_Node_NetworkList *)buf;
buf += sizeof(ZT1_Node_NetworkList);
nl->networks = (ZT1_Node_Network *)buf;
buf += sizeof(ZT1_Node_Network) * networks.size();
for(unsigned long i=0;i<networks.size();++i) {
ZT1_Node_Network *nbuf = &(nl->networks[nl->numNetworks++]);
_fillNetworkQueryResultBuffer(networks[i],nconfs[i],nbuf);
nbuf->ips = (ZT1_Node_PhysicalAddress *)buf;
buf += sizeof(ZT1_Node_PhysicalAddress) * ipsv[i].size();
nbuf->numIps = 0;
for(std::set<InetAddress>::iterator ip(ipsv[i].begin());ip!=ipsv[i].end();++ip) {
ZT1_Node_PhysicalAddress *ipb = &(nbuf->ips[nbuf->numIps++]);
if (ip->isV6()) {
ipb->type = ZT1_Node_PhysicalAddress_TYPE_IPV6;
memcpy(ipb->bits,ip->rawIpData(),16);
} else {
ipb->type = ZT1_Node_PhysicalAddress_TYPE_IPV4;
memcpy(ipb->bits,ip->rawIpData(),4);
}
ipb->port = ip->port();
Utils::scopy(ipb->ascii,sizeof(ipb->ascii),ip->toIpString().c_str());
}
}
return nl;
}
void Node::freeQueryResult(void *qr)
throw()
{
if (qr)
::free(qr);
}
bool Node::updateCheck()
throw()
{
_NodeImpl *impl = (_NodeImpl *)_impl;
RuntimeEnvironment *RR = (RuntimeEnvironment *)&(impl->renv);
if (RR->updater) {
RR->updater->checkNow();
return true;
}
return false;
}
class _VersionStringMaker
{
public:
char vs[32];
_VersionStringMaker()
{
Utils::snprintf(vs,sizeof(vs),"%d.%d.%d",(int)ZEROTIER_ONE_VERSION_MAJOR,(int)ZEROTIER_ONE_VERSION_MINOR,(int)ZEROTIER_ONE_VERSION_REVISION);
}
~_VersionStringMaker() {}
};
static const _VersionStringMaker __versionString;
const char *Node::versionString() throw() { return __versionString.vs; }
unsigned int Node::versionMajor() throw() { return ZEROTIER_ONE_VERSION_MAJOR; }
unsigned int Node::versionMinor() throw() { return ZEROTIER_ONE_VERSION_MINOR; }
unsigned int Node::versionRevision() throw() { return ZEROTIER_ONE_VERSION_REVISION; }
} // namespace ZeroTier

View File

@ -1,245 +0,0 @@
/*
* ZeroTier One - Network Virtualization Everywhere
* Copyright (C) 2011-2015 ZeroTier, Inc.
*
* 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/
*/
#ifndef ZT_NODE_HPP
#define ZT_NODE_HPP
#include <stdint.h>
#include "../include/ZeroTierOne.h"
namespace ZeroTier {
class EthernetTapFactory;
class RoutingTable;
class SocketManager;
class NetworkConfigMaster;
/**
* A ZeroTier One node
*/
class Node
{
public:
/**
* Returned by node main if/when it terminates
*/
enum ReasonForTermination
{
/**
* Node is currently in run()
*/
NODE_RUNNING = 0,
/**
* Node is shutting down for normal reasons, including a signal
*/
NODE_NORMAL_TERMINATION = 1,
/**
* An upgrade is available. Its path is in reasonForTermination().
*/
NODE_RESTART_FOR_UPGRADE = 2,
/**
* A serious unrecoverable error has occurred.
*/
NODE_UNRECOVERABLE_ERROR = 3,
/**
* An address collision occurred (typically this should cause re-invocation with resetIdentity set to true)
*/
NODE_ADDRESS_COLLISION = 4
};
/**
* Create a new node
*
* The node is not executed until run() is called. The supplied tap factory
* and routing table must not be freed until the node is no longer
* executing. Node does not delete these objects; the caller still owns
* them.
*
* @param hp Home directory path or NULL for system-wide default for this platform
* @param tf Ethernet tap factory for platform network stack
* @param sm Socket manager for physical network I/O
* @param nm Network configuration master or NULL for none
* @param resetIdentity If true, delete identity before starting and regenerate
* @param overrideRootTopology Override root topology with this dictionary (in string serialized format) and do not update (default: NULL for none)
*/
Node(
const char *hp,
EthernetTapFactory *tf,
SocketManager *sm,
NetworkConfigMaster *nm,
bool resetIdentity,
const char *overrideRootTopology = (const char *)0) throw();
~Node();
/**
* Execute node in current thread, return on shutdown
*
* @return Reason for termination
*/
ReasonForTermination run()
throw();
/**
* Obtain a human-readable reason for node termination
*
* @return Reason for node termination or NULL if run() has not returned
*/
const char *terminationMessage() const
throw();
/**
* Terminate this node, causing run() to return
*
* @param reason Reason for termination
* @param reasonText Text to be returned by terminationMessage()
*/
void terminate(ReasonForTermination reason,const char *reasonText)
throw();
/**
* Forget p2p links now and resynchronize with peers
*
* This can be used if the containing application knows its network environment has
* changed. ZeroTier itself tries to detect such changes, but is not always successful.
*/
void resync()
throw();
/**
* @return True if we appear to be online in some viable capacity
*/
bool online()
throw();
/**
* @return True if run() has been called
*/
bool started()
throw();
/**
* @return True if run() has not yet returned
*/
bool running()
throw();
/**
* @return True if initialization phase of startup is complete
*/
bool initialized()
throw();
/**
* @return This node's address (in least significant 40 bits of 64-bit int) or 0 if not yet initialized
*/
uint64_t address()
throw();
/**
* Join a network
*
* Use getNetworkStatus() to check the network's status after joining. If you
* are already a member of the network, this does nothing.
*
* @param nwid 64-bit network ID
*/
void join(uint64_t nwid)
throw();
/**
* Leave a network (if a member)
*
* @param nwid 64-bit network ID
*/
void leave(uint64_t nwid)
throw();
/**
* Get the status of this node
*
* @param status Buffer to fill with status information
*/
void status(ZT1_Node_Status *status)
throw();
/**
* @return List of known peers or NULL on failure
*/
ZT1_Node_PeerList *listPeers()
throw();
/**
* @param nwid 64-bit network ID
* @return Network status or NULL if we are not a member of this network
*/
ZT1_Node_Network *getNetworkStatus(uint64_t nwid)
throw();
/**
* @return List of networks we've joined or NULL on failure
*/
ZT1_Node_NetworkList *listNetworks()
throw();
/**
* Free a query result buffer
*
* Use this to free the return values of listNetworks(), listPeers(), etc.
*
* @param qr Query result buffer
*/
void freeQueryResult(void *qr)
throw();
/**
* Check for software updates (if enabled) (updates will eventually get factored out of node/)
*/
bool updateCheck()
throw();
static const char *versionString() throw();
static unsigned int versionMajor() throw();
static unsigned int versionMinor() throw();
static unsigned int versionRevision() throw();
private:
// Nodes are not copyable
Node(const Node&);
const Node& operator=(const Node&);
void *const _impl; // private implementation
};
} // namespace ZeroTier
#endif

View File

@ -1,162 +0,0 @@
/*
* ZeroTier One - Network Virtualization Everywhere
* Copyright (C) 2011-2015 ZeroTier, Inc.
*
* 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/
*/
#include "WindowsEthernetTapFactory.hpp"
#include "WindowsEthernetTap.hpp"
namespace ZeroTier {
WindowsEthernetTapFactory::Env::Env()
{
#ifdef _WIN64
is64Bit = TRUE;
devcon = "\\devcon_x64.exe";
tapDriver = "\\tap-windows\\x64\\zttap200.inf";
#else
is64Bit = FALSE;
IsWow64Process(GetCurrentProcess(),&is64Bit);
devcon = ((is64Bit == TRUE) ? "\\devcon_x64.exe" : "\\devcon_x86.exe");
tapDriver = ((is64Bit == TRUE) ? "\\tap-windows\\x64\\zttap200.inf" : "\\tap-windows\\x86\\zttap200.inf");
#endif
}
const WindowsEthernetTapFactory::Env WindowsEthernetTapFactory::WINENV;
WindowsEthernetTapFactory::WindowsEthernetTapFactory(const char *pathToHelpers) :
_pathToHelpers(pathToHelpers)
{
}
WindowsEthernetTapFactory::~WindowsEthernetTapFactory()
{
Mutex::Lock _l(_devices_m);
for(std::vector<EthernetTap *>::iterator d(_devices.begin());d!=_devices.end();++d)
delete *d;
}
EthernetTap *WindowsEthernetTapFactory::open(
const MAC &mac,
unsigned int mtu,
unsigned int metric,
uint64_t nwid,
const char *desiredDevice,
const char *friendlyName,
void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &),
void *arg)
{
Mutex::Lock _l(_devices_m);
EthernetTap *t = new WindowsEthernetTap(_pathToHelpers.c_str(),mac,mtu,metric,nwid,desiredDevice,friendlyName,handler,arg);
_devices.push_back(t);
return t;
}
void WindowsEthernetTapFactory::close(EthernetTap *tap,bool destroyPersistentDevices)
{
if (!tap)
return;
std::string instanceId(((WindowsEthernetTap *)tap)->instanceId());
Mutex::Lock _l(_devices_m);
for(std::vector<EthernetTap *>::iterator d(_devices.begin());d!=_devices.end();++d) {
if (*d == tap) {
_devices.erase(d);
break;
}
}
delete tap;
if (destroyPersistentDevices)
_deletePersistentTapDevice(_pathToHelpers.c_str(),instanceId.c_str());
}
void WindowsEthernetTapFactory::destroyAllPersistentTapDevices(const char *pathToHelpers)
{
char subkeyName[4096];
char subkeyClass[4096];
char data[4096];
std::set<std::string> instanceIdPathsToRemove;
{
HKEY nwAdapters;
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}",0,KEY_READ|KEY_WRITE,&nwAdapters) != ERROR_SUCCESS)
return;
for(DWORD subkeyIndex=0;;++subkeyIndex) {
DWORD type;
DWORD dataLen;
DWORD subkeyNameLen = sizeof(subkeyName);
DWORD subkeyClassLen = sizeof(subkeyClass);
FILETIME lastWriteTime;
if (RegEnumKeyExA(nwAdapters,subkeyIndex,subkeyName,&subkeyNameLen,(DWORD *)0,subkeyClass,&subkeyClassLen,&lastWriteTime) == ERROR_SUCCESS) {
type = 0;
dataLen = sizeof(data);
if (RegGetValueA(nwAdapters,subkeyName,"ComponentId",RRF_RT_ANY,&type,(PVOID)data,&dataLen) == ERROR_SUCCESS) {
data[dataLen] = '\0';
if (!strnicmp(data,"zttap",5)) {
std::string instanceIdPath;
type = 0;
dataLen = sizeof(data);
if (RegGetValueA(nwAdapters,subkeyName,"DeviceInstanceID",RRF_RT_ANY,&type,(PVOID)data,&dataLen) == ERROR_SUCCESS)
instanceIdPath.assign(data,dataLen);
if (instanceIdPath.length() != 0)
instanceIdPathsToRemove.insert(instanceIdPath);
}
}
} else break; // end of list or failure
}
RegCloseKey(nwAdapters);
}
for(std::set<std::string>::iterator iidp(instanceIdPathsToRemove.begin());iidp!=instanceIdPathsToRemove.end();++iidp)
_deletePersistentTapDevice(pathToHelpers,iidp->c_str());
}
void WindowsEthernetTapFactory::_deletePersistentTapDevice(const char *pathToHelpers,const char *instanceId)
{
HANDLE devconLog = CreateFileA((std::string(pathToHelpers) + "\\devcon.log").c_str(),GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
STARTUPINFOA startupInfo;
startupInfo.cb = sizeof(startupInfo);
if (devconLog != INVALID_HANDLE_VALUE) {
SetFilePointer(devconLog,0,0,FILE_END);
startupInfo.hStdOutput = devconLog;
startupInfo.hStdError = devconLog;
}
PROCESS_INFORMATION processInfo;
memset(&startupInfo,0,sizeof(STARTUPINFOA));
memset(&processInfo,0,sizeof(PROCESS_INFORMATION));
if (CreateProcessA(NULL,(LPSTR)(std::string("\"") + pathToHelpers + WINENV.devcon + "\" remove @" + instanceId).c_str(),NULL,NULL,FALSE,0,NULL,NULL,&startupInfo,&processInfo)) {
WaitForSingleObject(processInfo.hProcess,INFINITE);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
}
if (devconLog != INVALID_HANDLE_VALUE)
CloseHandle(devconLog);
}
} // namespace ZeroTier

View File

@ -1,90 +0,0 @@
/*
* ZeroTier One - Network Virtualization Everywhere
* Copyright (C) 2011-2015 ZeroTier, Inc.
*
* 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/
*/
#ifndef ZT_WINDOWSETHERNETTAPFACTORY_HPP
#define ZT_WINDOWSETHERNETTAPFACTORY_HPP
#include <vector>
#include <string>
#include "../node/EthernetTapFactory.hpp"
#include "../node/Mutex.hpp"
namespace ZeroTier {
class WindowsEthernetTapFactory : public EthernetTapFactory
{
public:
class Env
{
public:
Env();
BOOL is64Bit; // true if WIN64 or WoW64 (32-bit binary on 64-bit architecture)
const char *devcon; // name of devcon binary in pathToHelpers to use
const char *tapDriver; // relative path to driver under pathToHelpers to use
};
/**
* Constants related to Windows environment, computed on program start
*/
static const Env WINENV;
/**
* @param pathToHelpers Path to devcon32.exe, devcon64.exe, and other required helper binaries (ZeroTier running directory)
*/
WindowsEthernetTapFactory(const char *pathToHelpers);
virtual ~WindowsEthernetTapFactory();
virtual EthernetTap *open(
const MAC &mac,
unsigned int mtu,
unsigned int metric,
uint64_t nwid,
const char *desiredDevice,
const char *friendlyName,
void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &),
void *arg);
virtual void close(EthernetTap *tap,bool destroyPersistentDevices);
/**
* Uninstalls all persistent tap devices in the system belonging to ZeroTier
*
* This is for uninstallation. Do not call this while tap devices are active.
*/
static void destroyAllPersistentTapDevices(const char *pathToHelpers);
private:
static void _deletePersistentTapDevice(const char *pathToHelpers,const char *instanceId);
std::string _pathToHelpers;
std::vector<EthernetTap *> _devices;
Mutex _devices_m;
};
} // namespace ZeroTier
#endif

View File

@ -1,887 +0,0 @@
/*
* ZeroTier One - Network Virtualization Everywhere
* Copyright (C) 2011-2015 ZeroTier, Inc.
*
* 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/
*/
// Uncomment on Windows to assume -C and run in console instead of service
// Useful for Visual Studio debugging (launch VS as Administrator to run)
//#define ZT_WIN_RUN_IN_CONSOLE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <string>
#include <stdexcept>
#include "node/Constants.hpp"
#ifdef __WINDOWS__
#include <WinSock2.h>
#include <Windows.h>
#include <tchar.h>
#include <wchar.h>
#include <lmcons.h>
#include <newdev.h>
#include <atlbase.h>
#include "windows/ZeroTierOne/ServiceInstaller.h"
#include "windows/ZeroTierOne/ServiceBase.h"
#include "windows/ZeroTierOne/ZeroTierOneService.h"
#else
#include <unistd.h>
#include <pwd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#endif
#include "node/Constants.hpp"
#include "node/Defaults.hpp"
#include "node/Utils.hpp"
#include "node/Node.hpp"
#include "node/C25519.hpp"
#include "node/Identity.hpp"
#include "node/Thread.hpp"
#include "node/CertificateOfMembership.hpp"
#include "node/EthernetTapFactory.hpp"
#include "node/SocketManager.hpp"
#include "control/NodeControlClient.hpp"
#include "control/NodeControlService.hpp"
#include "osdep/NativeSocketManager.hpp"
#ifdef ZT_ENABLE_NETCONF_MASTER
#include "netconf/SqliteNetworkConfigMaster.hpp"
#endif // ZT_ENABLE_NETCONF_MASTER
#ifdef __WINDOWS__
#include "osdep/WindowsEthernetTapFactory.hpp"
#define ZTCreatePlatformEthernetTapFactory (new WindowsEthernetTapFactory(homeDir))
#endif // __WINDOWS__
#ifdef __LINUX__
#include "osdep/LinuxEthernetTapFactory.hpp"
#define ZTCreatePlatformEthernetTapFactory (new LinuxEthernetTapFactory())
#endif // __LINUX__
#ifdef __APPLE__
#include "osdep/OSXEthernetTapFactory.hpp"
#define ZTCreatePlatformEthernetTapFactory (new OSXEthernetTapFactory(homeDir,"tap.kext"))
#endif // __APPLE__
#ifndef ZTCreatePlatformEthernetTapFactory
#ifdef __BSD__
#include "osdep/BSDEthernetTapFactory.hpp"
#define ZTCreatePlatformEthernetTapFactory (new BSDEthernetTapFactory())
#else
#error Sorry, this platform has no osdep/ implementation yet. Fork me on GitHub and add one?
#endif // __BSD__
#endif // ZTCreatePlatformEthernetTapFactory
using namespace ZeroTier;
static Node *node = (Node *)0;
namespace ZeroTierCLI { // ---------------------------------------------------
static void printHelp(FILE *out,const char *cn)
{
fprintf(out,"Usage: %s <command> (use 'help' for help)"ZT_EOL_S,cn);
}
static void _CBresultHandler(void *arg,const char *line)
{
if (line) {
if ((line[0] == '.')&&(line[1] == (char)0)) {
fflush(stdout);
::exit(0); // terminate CLI on end of message
} else {
fprintf(stdout,"%s"ZT_EOL_S,line);
}
}
}
#ifdef __WINDOWS__
static int main(const char *homeDir,int argc,_TCHAR* argv[])
#else
static int main(const char *homeDir,int argc,char **argv)
#endif
{
if (argc < 2) {
printHelp(stdout,argv[0]);
return 1;
}
std::string query;
for(int i=1;i<argc;++i) {
if (argv[i][0] == '-') {
switch(argv[i][1]) {
case 'q': // ignore -q since it's used to invoke this
break;
case 'h':
default:
printHelp(stdout,argv[0]);
return 1;
}
} else if ((!homeDir)||(strcmp(homeDir,argv[i]))) {
if (query.length())
query.push_back(' ');
query.append(argv[i]);
}
}
if (!query.length()) {
printHelp(stdout,argv[0]);
return 1;
}
if (!homeDir)
homeDir = ZT_DEFAULTS.defaultHomePath.c_str();
try {
std::string buf;
if (!Utils::readFile((std::string(homeDir) + ZT_PATH_SEPARATOR_S + "identity.public").c_str(),buf)) {
fprintf(stderr,"%s: fatal error: unable to read node address from identity.public in home path"ZT_EOL_S,argv[0]);
return 1;
}
Identity id;
if (!id.fromString(buf)) {
fprintf(stderr,"%s: fatal error: unable to read node address from identity.public in home path"ZT_EOL_S,argv[0]);
return 1;
}
std::string authToken(NodeControlClient::getAuthToken((std::string(homeDir) + ZT_PATH_SEPARATOR_S + "authtoken.secret").c_str(),false));
if (!authToken.length())
authToken = NodeControlClient::getAuthToken(NodeControlClient::authTokenDefaultUserPath(),false);
if (!authToken.length()) {
fprintf(stderr,"%s: fatal error: unable to read authentication token from home path or user home"ZT_EOL_S,argv[0]);
return 1;
}
NodeControlClient client((std::string(ZT_IPC_ENDPOINT_BASE) + id.address().toString()).c_str(),authToken.c_str(),&_CBresultHandler,(void *)0);
const char *err = client.error();
if (err) {
fprintf(stderr,"%s: fatal error: unable to connect (is ZeroTier One running?) (%s)"ZT_EOL_S,argv[0],err);
return 1;
}
client.send(query.c_str());
for(;;) { Thread::sleep(60000); } // exit() is called at end of message from handler
} catch (std::exception &exc) {
fprintf(stderr,"%s: fatal error: unable to connect (is ZeroTier One running?) (%s)"ZT_EOL_S,argv[0],exc.what());
return 1;
} catch ( ... ) {
fprintf(stderr,"%s: fatal error: unable to connect (is ZeroTier One running?) (unknown exception)"ZT_EOL_S,argv[0]);
return 1;
}
return 0;
}
} // namespace ZeroTierCLI ---------------------------------------------------
namespace ZeroTierIdTool { // ------------------------------------------------
static void printHelp(FILE *out,const char *pn)
{
fprintf(out,"Usage: %s <command> [<args>]"ZT_EOL_S""ZT_EOL_S"Commands:"ZT_EOL_S,pn);
fprintf(out," generate [<identity.secret>] [<identity.public>]"ZT_EOL_S);
fprintf(out," validate <identity.secret/public>"ZT_EOL_S);
fprintf(out," getpublic <identity.secret>"ZT_EOL_S);
fprintf(out," sign <identity.secret> <file>"ZT_EOL_S);
fprintf(out," verify <identity.secret/public> <file> <signature>"ZT_EOL_S);
fprintf(out," mkcom <identity.secret> [<id,value,maxDelta> ...] (hexadecimal integers)"ZT_EOL_S);
}
static Identity getIdFromArg(char *arg)
{
Identity id;
if ((strlen(arg) > 32)&&(arg[10] == ':')) { // identity is a literal on the command line
if (id.fromString(arg))
return id;
} else { // identity is to be read from a file
std::string idser;
if (Utils::readFile(arg,idser)) {
if (id.fromString(idser))
return id;
}
}
return Identity();
}
#ifdef __WINDOWS__
static int main(int argc,_TCHAR* argv[])
#else
static int main(int argc,char **argv)
#endif
{
if (argc < 2) {
printHelp(stdout,argv[0]);
return 1;
}
if (!strcmp(argv[1],"generate")) {
Identity id;
id.generate();
std::string idser = id.toString(true);
if (argc >= 3) {
if (!Utils::writeFile(argv[2],idser)) {
fprintf(stderr,"Error writing to %s"ZT_EOL_S,argv[2]);
return 1;
} else printf("%s written"ZT_EOL_S,argv[2]);
if (argc >= 4) {
idser = id.toString(false);
if (!Utils::writeFile(argv[3],idser)) {
fprintf(stderr,"Error writing to %s"ZT_EOL_S,argv[3]);
return 1;
} else printf("%s written"ZT_EOL_S,argv[3]);
}
} else printf("%s",idser.c_str());
} else if (!strcmp(argv[1],"validate")) {
if (argc < 3) {
printHelp(stdout,argv[0]);
return 1;
}
Identity id = getIdFromArg(argv[2]);
if (!id) {
fprintf(stderr,"Identity argument invalid or file unreadable: %s"ZT_EOL_S,argv[2]);
return 1;
}
if (!id.locallyValidate()) {
fprintf(stderr,"%s FAILED validation."ZT_EOL_S,argv[2]);
return 1;
} else printf("%s is a valid identity"ZT_EOL_S,argv[2]);
} else if (!strcmp(argv[1],"getpublic")) {
if (argc < 3) {
printHelp(stdout,argv[0]);
return 1;
}
Identity id = getIdFromArg(argv[2]);
if (!id) {
fprintf(stderr,"Identity argument invalid or file unreadable: %s"ZT_EOL_S,argv[2]);
return 1;
}
printf("%s",id.toString(false).c_str());
} else if (!strcmp(argv[1],"sign")) {
if (argc < 4) {
printHelp(stdout,argv[0]);
return 1;
}
Identity id = getIdFromArg(argv[2]);
if (!id) {
fprintf(stderr,"Identity argument invalid or file unreadable: %s"ZT_EOL_S,argv[2]);
return 1;
}
if (!id.hasPrivate()) {
fprintf(stderr,"%s does not contain a private key (must use private to sign)"ZT_EOL_S,argv[2]);
return 1;
}
std::string inf;
if (!Utils::readFile(argv[3],inf)) {
fprintf(stderr,"%s is not readable"ZT_EOL_S,argv[3]);
return 1;
}
C25519::Signature signature = id.sign(inf.data(),(unsigned int)inf.length());
printf("%s",Utils::hex(signature.data,(unsigned int)signature.size()).c_str());
} else if (!strcmp(argv[1],"verify")) {
if (argc < 4) {
printHelp(stdout,argv[0]);
return 1;
}
Identity id = getIdFromArg(argv[2]);
if (!id) {
fprintf(stderr,"Identity argument invalid or file unreadable: %s"ZT_EOL_S,argv[2]);
return 1;
}
std::string inf;
if (!Utils::readFile(argv[3],inf)) {
fprintf(stderr,"%s is not readable"ZT_EOL_S,argv[3]);
return 1;
}
std::string signature(Utils::unhex(argv[4]));
if ((signature.length() > ZT_ADDRESS_LENGTH)&&(id.verify(inf.data(),(unsigned int)inf.length(),signature.data(),(unsigned int)signature.length()))) {
printf("%s signature valid"ZT_EOL_S,argv[3]);
} else {
fprintf(stderr,"%s signature check FAILED"ZT_EOL_S,argv[3]);
return 1;
}
} else if (!strcmp(argv[1],"mkcom")) {
if (argc < 3) {
printHelp(stdout,argv[0]);
return 1;
}
Identity id = getIdFromArg(argv[2]);
if ((!id)||(!id.hasPrivate())) {
fprintf(stderr,"Identity argument invalid, does not include private key, or file unreadable: %s"ZT_EOL_S,argv[2]);
return 1;
}
CertificateOfMembership com;
for(int a=3;a<argc;++a) {
std::vector<std::string> params(Utils::split(argv[a],",","",""));
if (params.size() == 3) {
uint64_t qId = Utils::hexStrToU64(params[0].c_str());
uint64_t qValue = Utils::hexStrToU64(params[1].c_str());
uint64_t qMaxDelta = Utils::hexStrToU64(params[2].c_str());
com.setQualifier(qId,qValue,qMaxDelta);
}
}
if (!com.sign(id)) {
fprintf(stderr,"Signature of certificate of membership failed."ZT_EOL_S);
return 1;
}
printf("%s",com.toString().c_str());
} else {
printHelp(stdout,argv[0]);
return 1;
}
return 0;
}
} // namespace ZeroTierIdTool ------------------------------------------------
#ifdef __UNIX_LIKE__
static void sighandlerHup(int sig)
{
Node *n = node;
if (n)
n->resync();
}
static void sighandlerQuit(int sig)
{
Node *n = node;
if (n)
n->terminate(Node::NODE_NORMAL_TERMINATION,"terminated by signal");
else exit(0);
}
#endif
#ifdef __WINDOWS__
// Console signal handler routine to allow CTRL+C to work, mostly for testing
static BOOL WINAPI _winConsoleCtrlHandler(DWORD dwCtrlType)
{
switch(dwCtrlType) {
case CTRL_C_EVENT:
case CTRL_BREAK_EVENT:
case CTRL_CLOSE_EVENT:
case CTRL_SHUTDOWN_EVENT:
Node *n = node;
if (n)
n->terminate(Node::NODE_NORMAL_TERMINATION,"terminated by signal");
return TRUE;
}
return FALSE;
}
// Pokes a hole in the Windows firewall (advfirewall) for the running program
static void _winPokeAHole()
{
char myPath[MAX_PATH];
DWORD ps = GetModuleFileNameA(NULL,myPath,sizeof(myPath));
if ((ps > 0)&&(ps < (DWORD)sizeof(myPath))) {
STARTUPINFOA startupInfo;
PROCESS_INFORMATION processInfo;
startupInfo.cb = sizeof(startupInfo);
memset(&startupInfo,0,sizeof(STARTUPINFOA));
memset(&processInfo,0,sizeof(PROCESS_INFORMATION));
if (CreateProcessA(NULL,(LPSTR)(std::string("C:\\Windows\\System32\\netsh.exe advfirewall firewall delete rule name=\"ZeroTier One\" program=\"") + myPath + "\"").c_str(),NULL,NULL,FALSE,0,NULL,NULL,&startupInfo,&processInfo)) {
WaitForSingleObject(processInfo.hProcess,INFINITE);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
}
startupInfo.cb = sizeof(startupInfo);
memset(&startupInfo,0,sizeof(STARTUPINFOA));
memset(&processInfo,0,sizeof(PROCESS_INFORMATION));
if (CreateProcessA(NULL,(LPSTR)(std::string("C:\\Windows\\System32\\netsh.exe advfirewall firewall add rule name=\"ZeroTier One\" dir=in action=allow program=\"") + myPath + "\" enable=yes").c_str(),NULL,NULL,FALSE,0,NULL,NULL,&startupInfo,&processInfo)) {
WaitForSingleObject(processInfo.hProcess,INFINITE);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
}
startupInfo.cb = sizeof(startupInfo);
memset(&startupInfo,0,sizeof(STARTUPINFOA));
memset(&processInfo,0,sizeof(PROCESS_INFORMATION));
if (CreateProcessA(NULL,(LPSTR)(std::string("C:\\Windows\\System32\\netsh.exe advfirewall firewall add rule name=\"ZeroTier One\" dir=out action=allow program=\"") + myPath + "\" enable=yes").c_str(),NULL,NULL,FALSE,0,NULL,NULL,&startupInfo,&processInfo)) {
WaitForSingleObject(processInfo.hProcess,INFINITE);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
}
}
}
// Returns true if this is running as the local administrator
static BOOL IsCurrentUserLocalAdministrator(void)
{
BOOL fReturn = FALSE;
DWORD dwStatus;
DWORD dwAccessMask;
DWORD dwAccessDesired;
DWORD dwACLSize;
DWORD dwStructureSize = sizeof(PRIVILEGE_SET);
PACL pACL = NULL;
PSID psidAdmin = NULL;
HANDLE hToken = NULL;
HANDLE hImpersonationToken = NULL;
PRIVILEGE_SET ps;
GENERIC_MAPPING GenericMapping;
PSECURITY_DESCRIPTOR psdAdmin = NULL;
SID_IDENTIFIER_AUTHORITY SystemSidAuthority = SECURITY_NT_AUTHORITY;
const DWORD ACCESS_READ = 1;
const DWORD ACCESS_WRITE = 2;
__try
{
if (!OpenThreadToken(GetCurrentThread(), TOKEN_DUPLICATE|TOKEN_QUERY,TRUE,&hToken))
{
if (GetLastError() != ERROR_NO_TOKEN)
__leave;
if (!OpenProcessToken(GetCurrentProcess(),TOKEN_DUPLICATE|TOKEN_QUERY, &hToken))
__leave;
}
if (!DuplicateToken (hToken, SecurityImpersonation,&hImpersonationToken))
__leave;
if (!AllocateAndInitializeSid(&SystemSidAuthority, 2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0, &psidAdmin))
__leave;
psdAdmin = LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
if (psdAdmin == NULL)
__leave;
if (!InitializeSecurityDescriptor(psdAdmin,SECURITY_DESCRIPTOR_REVISION))
__leave;
dwACLSize = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(psidAdmin) - sizeof(DWORD);
pACL = (PACL)LocalAlloc(LPTR, dwACLSize);
if (pACL == NULL)
__leave;
if (!InitializeAcl(pACL, dwACLSize, ACL_REVISION2))
__leave;
dwAccessMask= ACCESS_READ | ACCESS_WRITE;
if (!AddAccessAllowedAce(pACL, ACL_REVISION2, dwAccessMask, psidAdmin))
__leave;
if (!SetSecurityDescriptorDacl(psdAdmin, TRUE, pACL, FALSE))
__leave;
SetSecurityDescriptorGroup(psdAdmin, psidAdmin, FALSE);
SetSecurityDescriptorOwner(psdAdmin, psidAdmin, FALSE);
if (!IsValidSecurityDescriptor(psdAdmin))
__leave;
dwAccessDesired = ACCESS_READ;
GenericMapping.GenericRead = ACCESS_READ;
GenericMapping.GenericWrite = ACCESS_WRITE;
GenericMapping.GenericExecute = 0;
GenericMapping.GenericAll = ACCESS_READ | ACCESS_WRITE;
if (!AccessCheck(psdAdmin, hImpersonationToken, dwAccessDesired,
&GenericMapping, &ps, &dwStructureSize, &dwStatus,
&fReturn))
{
fReturn = FALSE;
__leave;
}
}
__finally
{
// Clean up.
if (pACL) LocalFree(pACL);
if (psdAdmin) LocalFree(psdAdmin);
if (psidAdmin) FreeSid(psidAdmin);
if (hImpersonationToken) CloseHandle (hImpersonationToken);
if (hToken) CloseHandle (hToken);
}
return fReturn;
}
#endif // __WINDOWS__
// ---------------------------------------------------------------------------
static void printHelp(const char *cn,FILE *out)
{
fprintf(out,"ZeroTier One version %d.%d.%d"ZT_EOL_S"(c)2011-2014 ZeroTier Networks LLC"ZT_EOL_S,Node::versionMajor(),Node::versionMinor(),Node::versionRevision());
fprintf(out,"Licensed under the GNU General Public License v3"ZT_EOL_S""ZT_EOL_S);
#ifdef ZT_AUTO_UPDATE
fprintf(out,"Auto-update enabled build, will update from URL:"ZT_EOL_S);
fprintf(out," %s"ZT_EOL_S,ZT_DEFAULTS.updateLatestNfoURL.c_str());
fprintf(out,"Update authentication signing authorities: "ZT_EOL_S);
int no = 0;
for(std::map< Address,Identity >::const_iterator sa(ZT_DEFAULTS.updateAuthorities.begin());sa!=ZT_DEFAULTS.updateAuthorities.end();++sa) {
if (no == 0)
fprintf(out," %s",sa->first.toString().c_str());
else fprintf(out,", %s",sa->first.toString().c_str());
if (++no == 6) {
fprintf(out,ZT_EOL_S);
no = 0;
}
}
fprintf(out,ZT_EOL_S""ZT_EOL_S);
#else
fprintf(out,"Auto-updates not enabled on this build. You must update manually."ZT_EOL_S""ZT_EOL_S);
#endif
fprintf(out,"Usage: %s [-switches] [home directory] [-q <query>]"ZT_EOL_S""ZT_EOL_S,cn);
fprintf(out,"Available switches:"ZT_EOL_S);
fprintf(out," -h - Display this help"ZT_EOL_S);
fprintf(out," -v - Show version"ZT_EOL_S);
fprintf(out," -p<port> - Port for UDP (default: 9993)"ZT_EOL_S);
fprintf(out," -t<port> - Port for TCP (default: disabled)"ZT_EOL_S);
//fprintf(out," -T<path> - Override root topology, do not authenticate or update"ZT_EOL_S);
#ifdef __UNIX_LIKE__
fprintf(out," -d - Fork and run as daemon (Unix-ish OSes)"ZT_EOL_S);
#endif
fprintf(out," -q - Send a query to a running service (zerotier-cli)"ZT_EOL_S);
fprintf(out," -i - Generate and manage identities (zerotier-idtool)"ZT_EOL_S);
#ifdef __WINDOWS__
fprintf(out," -C - Run from command line instead of as service (Windows)"ZT_EOL_S);
fprintf(out," -I - Install Windows service (Windows)"ZT_EOL_S);
fprintf(out," -R - Uninstall Windows service (Windows)"ZT_EOL_S);
fprintf(out," -D - Load tap driver into system driver store (Windows)"ZT_EOL_S);
#endif
}
#ifdef __WINDOWS__
int _tmain(int argc, _TCHAR* argv[])
#else
int main(int argc,char **argv)
#endif
{
#ifdef __UNIX_LIKE__
signal(SIGHUP,&sighandlerHup);
signal(SIGPIPE,SIG_IGN);
signal(SIGUSR1,SIG_IGN);
signal(SIGUSR2,SIG_IGN);
signal(SIGALRM,SIG_IGN);
signal(SIGINT,&sighandlerQuit);
signal(SIGTERM,&sighandlerQuit);
signal(SIGQUIT,&sighandlerQuit);
/* Ensure that there are no inherited file descriptors open from a previous
* incarnation. This is a hack to ensure that GitHub issue #61 or variants
* of it do not return, and should not do anything otherwise bad. */
{
int mfd = STDIN_FILENO;
if (STDOUT_FILENO > mfd) mfd = STDOUT_FILENO;
if (STDERR_FILENO > mfd) mfd = STDERR_FILENO;
for(int f=mfd+1;f<1024;++f)
::close(f);
}
#endif
#ifdef __WINDOWS__
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2),&wsaData);
#endif
if ((strstr(argv[0],"zerotier-cli"))||(strstr(argv[0],"ZEROTIER-CLI")))
return ZeroTierCLI::main((const char *)0,argc,argv);
if ((strstr(argv[0],"zerotier-idtool"))||(strstr(argv[0],"ZEROTIER-IDTOOL")))
return ZeroTierIdTool::main(argc,argv);
const char *homeDir = (const char *)0;
unsigned int udpPort = ZT_DEFAULT_UDP_PORT;
unsigned int tcpPort = 0;
std::string overrideRootTopology;
#ifdef __UNIX_LIKE__
bool runAsDaemon = false;
#endif
#ifdef __WINDOWS__
#ifdef ZT_WIN_RUN_IN_CONSOLE
bool winRunFromCommandLine = true;
#else
bool winRunFromCommandLine = false;
#endif
#endif // __WINDOWS__
for(int i=1;i<argc;++i) {
if (argv[i][0] == '-') {
switch(argv[i][1]) {
case 'p':
udpPort = Utils::strToUInt(argv[i] + 2);
if (udpPort > 65535) {
printHelp(argv[0],stdout);
return 1;
}
break;
case 't':
tcpPort = Utils::strToUInt(argv[i] + 2);
if (tcpPort > 65535) {
printHelp(argv[0],stdout);
return 1;
}
break;
#ifdef __UNIX_LIKE__
case 'd':
runAsDaemon = true;
break;
#endif
case 'T':
if (argv[i][2]) {
if (!Utils::readFile(argv[i] + 2,overrideRootTopology)) {
fprintf(stderr,"%s: cannot read root topology from %s"ZT_EOL_S,argv[0],argv[i] + 2);
return 1;
}
} else {
printHelp(argv[0],stdout);
return 1;
}
break;
case 'v':
printf("%s"ZT_EOL_S,Node::versionString());
return 0;
case 'q':
if (argv[i][2]) {
printHelp(argv[0],stdout);
return 0;
} else return ZeroTierCLI::main(homeDir,argc,argv);
case 'i':
if (argv[i][2]) {
printHelp(argv[0],stdout);
return 0;
} else return ZeroTierIdTool::main(argc,argv);
#ifdef __WINDOWS__
case 'C':
winRunFromCommandLine = true;
break;
case 'I': { // install self as service
if (IsCurrentUserLocalAdministrator() != TRUE) {
fprintf(stderr,"%s: must be run as a local administrator."ZT_EOL_S,argv[0]);
return 1;
}
std::string ret(InstallService(ZT_SERVICE_NAME,ZT_SERVICE_DISPLAY_NAME,ZT_SERVICE_START_TYPE,ZT_SERVICE_DEPENDENCIES,ZT_SERVICE_ACCOUNT,ZT_SERVICE_PASSWORD));
if (ret.length()) {
fprintf(stderr,"%s: unable to install service: %s"ZT_EOL_S,argv[0],ret.c_str());
return 3;
}
return 0;
} break;
case 'R': { // uninstall self as service
if (IsCurrentUserLocalAdministrator() != TRUE) {
fprintf(stderr,"%s: must be run as a local administrator."ZT_EOL_S,argv[0]);
return 1;
}
std::string ret(UninstallService(ZT_SERVICE_NAME));
if (ret.length()) {
fprintf(stderr,"%s: unable to uninstall service: %s"ZT_EOL_S,argv[0],ret.c_str());
return 3;
}
return 0;
} break;
case 'D': { // install Windows driver (since PNPUTIL.EXE seems to be weirdly unreliable)
std::string pathToInf;
#ifdef _WIN64
pathToInf = ZT_DEFAULTS.defaultHomePath + "\\tap-windows\\x64\\zttap200.inf";
#else
pathToInf = ZT_DEFAULTS.defaultHomePath + "\\tap-windows\\x86\\zttap200.inf";
#endif
printf("Installing ZeroTier One virtual Ethernet port driver."ZT_EOL_S""ZT_EOL_S"NOTE: If you don't see a confirmation window to allow driver installation,"ZT_EOL_S"check to make sure it didn't appear under the installer."ZT_EOL_S);
BOOL needReboot = FALSE;
if (DiInstallDriverA(NULL,pathToInf.c_str(),DIIRFLAG_FORCE_INF,&needReboot)) {
printf("%s: driver successfully installed from %s"ZT_EOL_S,argv[0],pathToInf.c_str());
return 0;
} else {
printf("%s: failed installing %s: %d"ZT_EOL_S,argv[0],pathToInf.c_str(),(int)GetLastError());
return 3;
}
} break;
#endif // __WINDOWS__
case 'h':
case '?':
default:
printHelp(argv[0],stdout);
return 0;
}
} else {
if (homeDir) {
printHelp(argv[0],stdout);
return 0;
} else homeDir = argv[i];
}
}
if ((!homeDir)||(strlen(homeDir) == 0))
homeDir = ZT_DEFAULTS.defaultHomePath.c_str();
#ifdef __UNIX_LIKE__
if (getuid() != 0) {
fprintf(stderr,"%s: must be run as root (uid 0)\n",argv[0]);
return 1;
}
if (runAsDaemon) {
long p = (long)fork();
if (p < 0) {
fprintf(stderr,"%s: could not fork"ZT_EOL_S,argv[0]);
return 1;
} else if (p > 0)
return 0; // forked
// else p == 0, so we are daemonized
}
mkdir(homeDir,0755); // will fail if it already exists, but that's fine
{
// Write .pid file to home folder
char pidpath[4096];
Utils::snprintf(pidpath,sizeof(pidpath),"%s/zerotier-one.pid",homeDir);
FILE *pf = fopen(pidpath,"w");
if (pf) {
fprintf(pf,"%ld",(long)getpid());
fclose(pf);
}
}
#endif // __UNIX_LIKE__
#ifdef __WINDOWS__
if (winRunFromCommandLine) {
// Running in "interactive" mode (mostly for debugging)
if (IsCurrentUserLocalAdministrator() != TRUE) {
fprintf(stderr,"%s: must be run as a local administrator."ZT_EOL_S,argv[0]);
return 1;
}
_winPokeAHole();
SetConsoleCtrlHandler(&_winConsoleCtrlHandler,TRUE);
// continues on to ordinary command line execution code below...
} else {
// Running from service manager
_winPokeAHole();
ZeroTierOneService zt1Service;
if (CServiceBase::Run(zt1Service) == TRUE) {
return 0;
} else {
fprintf(stderr,"%s: unable to start service (try -h for help)"ZT_EOL_S,argv[0]);
return 1;
}
}
#endif // __WINDOWS__
int exitCode = 0;
bool needsReset = false;
EthernetTapFactory *tapFactory = (EthernetTapFactory *)0;
SocketManager *socketManager = (SocketManager *)0;
NodeControlService *controlService = (NodeControlService *)0;
NetworkConfigMaster *netconfMaster = (NetworkConfigMaster *)0;
try {
// Get or create authtoken.secret -- note that if this fails, authentication
// will always fail since an empty auth token won't work. This should always
// succeed unless something is wrong with the filesystem.
std::string authToken(NodeControlClient::getAuthToken((std::string(homeDir) + ZT_PATH_SEPARATOR_S + "authtoken.secret").c_str(),true));
tapFactory = ZTCreatePlatformEthernetTapFactory;
try {
socketManager = new NativeSocketManager(udpPort,tcpPort);
} catch ( ... ) {
fprintf(stderr,"%s: unable to bind to port: %u/UDP, %u/TCP (0 == disabled)"ZT_EOL_S,argv[0],udpPort,tcpPort);
throw;
}
node = new Node(homeDir,tapFactory,socketManager,netconfMaster,needsReset,(overrideRootTopology.length() > 0) ? overrideRootTopology.c_str() : (const char *)0);
controlService = new NodeControlService(node,authToken.c_str());
switch(node->run()) {
#ifdef __WINDOWS__
case Node::NODE_RESTART_FOR_UPGRADE: {
const char *upgPath = node->terminationMessage();
if (upgPath) {
if (!ZeroTierOneService::doStartUpgrade(std::string(upgPath))) {
exitCode = 3;
fprintf(stderr,"%s: abnormal termination: unable to execute update at %s (doStartUpgrade failed)"ZT_EOL_S,argv[0],(upgPath) ? upgPath : "(unknown path)");
}
} else {
exitCode = 3;
fprintf(stderr,"%s: abnormal termination: unable to execute update at %s (no upgrade path provided)"ZT_EOL_S,argv[0],(upgPath) ? upgPath : "(unknown path)");
}
} break;
#else // __UNIX_LIKE__
case Node::NODE_RESTART_FOR_UPGRADE: {
const char *upgPath = node->terminationMessage();
// On Unix-type OSes we exec() right into the upgrade. This in turn will
// end with us being re-launched either via the upgrade itself or something
// like OSX's launchd.
if (upgPath) {
Utils::rm((std::string(homeDir)+"/zerotier-one.pid").c_str());
std::string updateLogPath(homeDir);
updateLogPath.append("/autoupdate.log");
Utils::rm(updateLogPath.c_str());
Utils::redirectUnixOutputs(updateLogPath.c_str(),(const char *)0);
::execl(upgPath,upgPath,(char *)0);
}
exitCode = 3;
fprintf(stderr,"%s: abnormal termination: unable to execute update at %s"ZT_EOL_S,argv[0],(upgPath) ? upgPath : "(unknown path)");
} break;
#endif // __WINDOWS__ / __UNIX_LIKE__
case Node::NODE_UNRECOVERABLE_ERROR: {
exitCode = 3;
const char *termReason = node->terminationMessage();
fprintf(stderr,"%s: abnormal termination: %s"ZT_EOL_S,argv[0],(termReason) ? termReason : "(unknown reason)");
} break;
default:
break;
}
} catch ( std::exception &exc ) {
fprintf(stderr,"%s: unexpected exception: %s"ZT_EOL_S,argv[0],exc.what());
exitCode = 3;
} catch ( ... ) {
fprintf(stderr,"%s: unexpected exception: unknown exception"ZT_EOL_S,argv[0]);
exitCode = 3;
}
delete controlService;
delete node; node = (Node *)0;
delete socketManager;
delete tapFactory;
#ifdef __UNIX_LIKE__
Utils::rm((std::string(homeDir)+"/zerotier-one.pid").c_str());
#endif
return exitCode;
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,143 @@
;
; ZeroTier One Virtual Network Port NDIS6 Driver
;
; Based on the OpenVPN tap-windows6 driver version 9.21.1 git
; commit 48f027cfca52b16b5fd23d82e6016ed8a91fc4d3.
; See: https://github.com/OpenVPN/tap-windows6
;
; Modified by ZeroTier, Inc. - https://www.zerotier.com/
;
; (1) Comment out 'tun' functionality and related features such as DHCP
; emulation, since we don't use any of that. Just want straight 'tap'.
; (2) Added custom IOCTL to enumerate L2 multicast memberships.
; (3) Increase maximum number of multicast memberships to 128.
; (4) Set default and max device MTU to 2800.
; (5) Rename/rebrand driver as ZeroTier network port driver.
;
; Original copyright below. Modifications released under GPLv2 as well.
;
; ****************************************************************************
; * Copyright (C) 2002-2014 OpenVPN Technologies, Inc. *
; * This program is free software; you can redistribute it and/or modify *
; * it under the terms of the GNU General Public License version 2 *
; * as published by the Free Software Foundation. *
; ****************************************************************************
;
[Version]
Signature = "$Windows NT$"
CatalogFile = zttap300.cat
ClassGUID = {4d36e972-e325-11ce-bfc1-08002be10318}
Provider = %Provider%
Class = Net
DriverVer=04/25/2015,6.2.9200.20557
[Strings]
DeviceDescription = "ZeroTier One Virtual Port"
Provider = "ZeroTier Networks LLC" ; We're ZeroTier, Inc. now but kernel mode certs are $300+ so fuqdat.
; To build for x86, take NTamd64 off this and off the named section manually, build, then put it back!
[Manufacturer]
%Provider%=zttap300,NTamd64
[zttap300]
%DeviceDescription% = zttap300.ndi, root\zttap300 ; Root enumerated
%DeviceDescription% = zttap300.ndi, zttap300 ; Legacy
[zttap300.NTamd64]
%DeviceDescription% = zttap300.ndi, root\zttap300 ; Root enumerated
%DeviceDescription% = zttap300.ndi, zttap300 ; Legacy
;----------------- Characteristics ------------
; NCF_PHYSICAL = 0x04
; NCF_VIRTUAL = 0x01
; NCF_SOFTWARE_ENUMERATED = 0x02
; NCF_HIDDEN = 0x08
; NCF_NO_SERVICE = 0x10
; NCF_HAS_UI = 0x80
;----------------- Characteristics ------------
[zttap300.ndi]
CopyFiles = zttap300.driver, zttap300.files
AddReg = zttap300.reg
AddReg = zttap300.params.reg
Characteristics = 0x81
*IfType = 0x6 ; IF_TYPE_ETHERNET_CSMACD
*MediaType = 0x0 ; NdisMedium802_3
*PhysicalMediaType = 14 ; NdisPhysicalMedium802_3
[zttap300.ndi.Services]
AddService = zttap300, 2, zttap300.service
[zttap300.reg]
HKR, Ndi, Service, 0, "zttap300"
HKR, Ndi\Interfaces, UpperRange, 0, "ndis5" ; yes, 'ndis5' is correct... yup, Windows.
HKR, Ndi\Interfaces, LowerRange, 0, "ethernet"
HKR, , Manufacturer, 0, "%Provider%"
HKR, , ProductName, 0, "%DeviceDescription%"
[zttap300.params.reg]
HKR, Ndi\params\MTU, ParamDesc, 0, "MTU"
HKR, Ndi\params\MTU, Type, 0, "int"
HKR, Ndi\params\MTU, Default, 0, "2800"
HKR, Ndi\params\MTU, Optional, 0, "0"
HKR, Ndi\params\MTU, Min, 0, "100"
HKR, Ndi\params\MTU, Max, 0, "2800"
HKR, Ndi\params\MTU, Step, 0, "1"
HKR, Ndi\params\MediaStatus, ParamDesc, 0, "Media Status"
HKR, Ndi\params\MediaStatus, Type, 0, "enum"
HKR, Ndi\params\MediaStatus, Default, 0, "0"
HKR, Ndi\params\MediaStatus, Optional, 0, "0"
HKR, Ndi\params\MediaStatus\enum, "0", 0, "Application Controlled"
HKR, Ndi\params\MediaStatus\enum, "1", 0, "Always Connected"
HKR, Ndi\params\MAC, ParamDesc, 0, "MAC Address"
HKR, Ndi\params\MAC, Type, 0, "edit"
HKR, Ndi\params\MAC, Optional, 0, "1"
HKR, Ndi\params\AllowNonAdmin, ParamDesc, 0, "Non-Admin Access"
HKR, Ndi\params\AllowNonAdmin, Type, 0, "enum"
HKR, Ndi\params\AllowNonAdmin, Default, 0, "0"
HKR, Ndi\params\AllowNonAdmin, Optional, 0, "0"
HKR, Ndi\params\AllowNonAdmin\enum, "0", 0, "Not Allowed"
HKR, Ndi\params\AllowNonAdmin\enum, "1", 0, "Allowed"
;---------- Service Type -------------
; SERVICE_KERNEL_DRIVER = 0x01
; SERVICE_WIN32_OWN_PROCESS = 0x10
;---------- Service Type -------------
;---------- Start Mode ---------------
; SERVICE_BOOT_START = 0x0
; SERVICE_SYSTEM_START = 0x1
; SERVICE_AUTO_START = 0x2
; SERVICE_DEMAND_START = 0x3
; SERVICE_DISABLED = 0x4
;---------- Start Mode ---------------
[zttap300.service]
DisplayName = %DeviceDescription%
ServiceType = 1
StartType = 3
ErrorControl = 1
LoadOrderGroup = NDIS
ServiceBinary = %12%\zttap300.sys
;----------------- Copy Flags ------------
; COPYFLG_NOSKIP = 0x02
; COPYFLG_NOVERSIONCHECK = 0x04
;----------------- Copy Flags ------------
[SourceDisksNames]
1 = %DeviceDescription%, zttap300.sys
[SourceDisksFiles]
zttap300.sys = 1
[DestinationDirs]
zttap300.files = 11
zttap300.driver = 12
[zttap300.files]
;
[zttap300.driver]
zttap300.sys,,,6 ; COPYFLG_NOSKIP | COPYFLG_NOVERSIONCHECK

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,139 @@
;
; ZeroTier One Virtual Network Port NDIS6 Driver
;
; Based on the OpenVPN tap-windows6 driver version 9.21.1 git
; commit 48f027cfca52b16b5fd23d82e6016ed8a91fc4d3.
; See: https://github.com/OpenVPN/tap-windows6
;
; Modified by ZeroTier, Inc. - https://www.zerotier.com/
;
; (1) Comment out 'tun' functionality and related features such as DHCP
; emulation, since we don't use any of that. Just want straight 'tap'.
; (2) Added custom IOCTL to enumerate L2 multicast memberships.
; (3) Increase maximum number of multicast memberships to 128.
; (4) Set default and max device MTU to 2800.
; (5) Rename/rebrand driver as ZeroTier network port driver.
;
; Original copyright below. Modifications released under GPLv2 as well.
;
; ****************************************************************************
; * Copyright (C) 2002-2014 OpenVPN Technologies, Inc. *
; * This program is free software; you can redistribute it and/or modify *
; * it under the terms of the GNU General Public License version 2 *
; * as published by the Free Software Foundation. *
; ****************************************************************************
;
[Version]
Signature = "$Windows NT$"
CatalogFile = zttap300.cat
ClassGUID = {4d36e972-e325-11ce-bfc1-08002be10318}
Provider = %Provider%
Class = Net
DriverVer=04/25/2015,6.2.9200.20557
[Strings]
DeviceDescription = "ZeroTier One Virtual Port"
Provider = "ZeroTier Networks LLC" ; We're ZeroTier, Inc. now but kernel mode certs are $300+ so fuqdat.
; To build for x86, take NTamd64 off this and off the named section manually, build, then put it back!
[Manufacturer]
%Provider%=zttap300
[zttap300]
%DeviceDescription% = zttap300.ndi, root\zttap300 ; Root enumerated
%DeviceDescription% = zttap300.ndi, zttap300 ; Legacy
;----------------- Characteristics ------------
; NCF_PHYSICAL = 0x04
; NCF_VIRTUAL = 0x01
; NCF_SOFTWARE_ENUMERATED = 0x02
; NCF_HIDDEN = 0x08
; NCF_NO_SERVICE = 0x10
; NCF_HAS_UI = 0x80
;----------------- Characteristics ------------
[zttap300.ndi]
CopyFiles = zttap300.driver, zttap300.files
AddReg = zttap300.reg
AddReg = zttap300.params.reg
Characteristics = 0x81
*IfType = 0x6 ; IF_TYPE_ETHERNET_CSMACD
*MediaType = 0x0 ; NdisMedium802_3
*PhysicalMediaType = 14 ; NdisPhysicalMedium802_3
[zttap300.ndi.Services]
AddService = zttap300, 2, zttap300.service
[zttap300.reg]
HKR, Ndi, Service, 0, "zttap300"
HKR, Ndi\Interfaces, UpperRange, 0, "ndis5" ; yes, 'ndis5' is correct... yup, Windows.
HKR, Ndi\Interfaces, LowerRange, 0, "ethernet"
HKR, , Manufacturer, 0, "%Provider%"
HKR, , ProductName, 0, "%DeviceDescription%"
[zttap300.params.reg]
HKR, Ndi\params\MTU, ParamDesc, 0, "MTU"
HKR, Ndi\params\MTU, Type, 0, "int"
HKR, Ndi\params\MTU, Default, 0, "2800"
HKR, Ndi\params\MTU, Optional, 0, "0"
HKR, Ndi\params\MTU, Min, 0, "100"
HKR, Ndi\params\MTU, Max, 0, "2800"
HKR, Ndi\params\MTU, Step, 0, "1"
HKR, Ndi\params\MediaStatus, ParamDesc, 0, "Media Status"
HKR, Ndi\params\MediaStatus, Type, 0, "enum"
HKR, Ndi\params\MediaStatus, Default, 0, "0"
HKR, Ndi\params\MediaStatus, Optional, 0, "0"
HKR, Ndi\params\MediaStatus\enum, "0", 0, "Application Controlled"
HKR, Ndi\params\MediaStatus\enum, "1", 0, "Always Connected"
HKR, Ndi\params\MAC, ParamDesc, 0, "MAC Address"
HKR, Ndi\params\MAC, Type, 0, "edit"
HKR, Ndi\params\MAC, Optional, 0, "1"
HKR, Ndi\params\AllowNonAdmin, ParamDesc, 0, "Non-Admin Access"
HKR, Ndi\params\AllowNonAdmin, Type, 0, "enum"
HKR, Ndi\params\AllowNonAdmin, Default, 0, "0"
HKR, Ndi\params\AllowNonAdmin, Optional, 0, "0"
HKR, Ndi\params\AllowNonAdmin\enum, "0", 0, "Not Allowed"
HKR, Ndi\params\AllowNonAdmin\enum, "1", 0, "Allowed"
;---------- Service Type -------------
; SERVICE_KERNEL_DRIVER = 0x01
; SERVICE_WIN32_OWN_PROCESS = 0x10
;---------- Service Type -------------
;---------- Start Mode ---------------
; SERVICE_BOOT_START = 0x0
; SERVICE_SYSTEM_START = 0x1
; SERVICE_AUTO_START = 0x2
; SERVICE_DEMAND_START = 0x3
; SERVICE_DISABLED = 0x4
;---------- Start Mode ---------------
[zttap300.service]
DisplayName = %DeviceDescription%
ServiceType = 1
StartType = 3
ErrorControl = 1
LoadOrderGroup = NDIS
ServiceBinary = %12%\zttap300.sys
;----------------- Copy Flags ------------
; COPYFLG_NOSKIP = 0x02
; COPYFLG_NOVERSIONCHECK = 0x04
;----------------- Copy Flags ------------
[SourceDisksNames]
1 = %DeviceDescription%, zttap300.sys
[SourceDisksFiles]
zttap300.sys = 1
[DestinationDirs]
zttap300.files = 11
zttap300.driver = 12
[zttap300.files]
;
[zttap300.driver]
zttap300.sys,,,6 ; COPYFLG_NOSKIP | COPYFLG_NOVERSIONCHECK

Binary file not shown.

View File

@ -72,20 +72,21 @@ public:
#ifdef _WIN64
is64Bit = TRUE;
devcon = "\\devcon_x64.exe";
tapDriver = "\\tap-windows\\x64\\zttap200.inf";
tapDriverNdis5 = "\\tap-windows\\x64\\zttap200.inf";
tapDriverNdis6 = "\\tap-windows\\x64\\zttap300.inf";
#else
is64Bit = FALSE;
IsWow64Process(GetCurrentProcess(),&is64Bit);
devcon = ((is64Bit == TRUE) ? "\\devcon_x64.exe" : "\\devcon_x86.exe");
tapDriver = ((is64Bit == TRUE) ? "\\tap-windows\\x64\\zttap200.inf" : "\\tap-windows\\x86\\zttap200.inf");
tapDriverNdis5 = ((is64Bit == TRUE) ? "\\tap-windows\\x64\\zttap200.inf" : "\\tap-windows\\x86\\zttap200.inf");
tapDriverNdis6 = ((is64Bit == TRUE) ? "\\tap-windows\\x64\\zttap300.inf" : "\\tap-windows\\x86\\zttap300.inf");
#endif
}
BOOL is64Bit;
std::string devcon;
std::string tapDriver;
const char *devcon;
const char *tapDriverNdis5;
const char *tapDriverNdis6;
};
static const WindowsEthernetTapEnv WINENV;
} // anonymous namespace
@ -123,6 +124,16 @@ WindowsEthernetTap::WindowsEthernetTap(
Mutex::Lock _l(_systemTapInitLock);
std::string tapDriverPath(_pathToHelpers + WINENV.tapDriverNdis6);
const char *tapDriverName = "zttap300";
if (::PathFileExistsA(tapDriverPath.c_str()) == FALSE) {
tapDriverPath = _pathToHelpers + WINENV.tapDriverNdis5;
tapDriverName = "zttap200";
if (::PathFileExistsA(tapDriverPath.c_str()) == FALSE) {
throw std::runtime_error("no tap driver available: cannot find zttap300.inf (NDIS6) or zttap200.inf (NDIS5) under home path");
}
}
HKEY nwAdapters;
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}",0,KEY_READ|KEY_WRITE,&nwAdapters) != ERROR_SUCCESS)
throw std::runtime_error("unable to open registry key for network adapter enumeration");
@ -198,7 +209,7 @@ WindowsEthernetTap::WindowsEthernetTap(
PROCESS_INFORMATION processInfo;
memset(&startupInfo,0,sizeof(STARTUPINFOA));
memset(&processInfo,0,sizeof(PROCESS_INFORMATION));
if (!CreateProcessA(NULL,(LPSTR)(std::string("\"") + _pathToHelpers + WINENV.devcon + "\" install \"" + _pathToHelpers + WINENV.tapDriver + "\" zttap200").c_str(),NULL,NULL,FALSE,0,NULL,NULL,&startupInfo,&processInfo)) {
if (!CreateProcessA(NULL,(LPSTR)(std::string("\"") + _pathToHelpers + WINENV.devcon + "\" install \"" + tapDriverPath + "\" " + tapDriverName).c_str(),NULL,NULL,FALSE,0,NULL,NULL,&startupInfo,&processInfo)) {
RegCloseKey(nwAdapters);
if (devconLog != INVALID_HANDLE_VALUE)
CloseHandle(devconLog);

View File

@ -0,0 +1,371 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Win8 Debug|Win32">
<Configuration>Win8 Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Win8 Release|Win32">
<Configuration>Win8 Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Win7 Debug|Win32">
<Configuration>Win7 Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Win7 Release|Win32">
<Configuration>Win7 Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Vista Debug|Win32">
<Configuration>Vista Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Vista Release|Win32">
<Configuration>Vista Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Win8 Debug|x64">
<Configuration>Win8 Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Win8 Release|x64">
<Configuration>Win8 Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Win7 Debug|x64">
<Configuration>Win7 Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Win7 Release|x64">
<Configuration>Win7 Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Vista Debug|x64">
<Configuration>Vista Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Vista Release|x64">
<Configuration>Vista Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}</ProjectGuid>
<TemplateGuid>{1bc93793-694f-48fe-9372-81e2b05556fd}</TemplateGuid>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
<Configuration>Win8 Debug</Configuration>
<Platform Condition="'$(Platform)' == ''">Win32</Platform>
</PropertyGroup>
<PropertyGroup Label="Globals">
<RootNamespace>TapDriver6</RootNamespace>
<VCTargetsPath Condition="'$(VCTargetsPath11)' != '' and '$(VisualStudioVersion)' == '11.0'">$(VCTargetsPath11)</VCTargetsPath>
</PropertyGroup>
<PropertyGroup Label="PropertySheets">
<PlatformToolset>WindowsKernelModeDriver8.0</PlatformToolset>
<ConfigurationType>Driver</ConfigurationType>
<DriverType>KMDF</DriverType>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'" Label="Configuration">
<TargetVersion>Windows8</TargetVersion>
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'" Label="Configuration">
<TargetVersion>Windows8</TargetVersion>
<UseDebugLibraries>false</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|Win32'" Label="Configuration">
<TargetVersion>Windows7</TargetVersion>
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win7 Release|Win32'" Label="Configuration">
<TargetVersion>Windows7</TargetVersion>
<UseDebugLibraries>false</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Vista Debug|Win32'" Label="Configuration">
<TargetVersion>Vista</TargetVersion>
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Vista Release|Win32'" Label="Configuration">
<TargetVersion>Vista</TargetVersion>
<UseDebugLibraries>false</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'" Label="Configuration">
<TargetVersion>Windows8</TargetVersion>
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'" Label="Configuration">
<TargetVersion>Windows8</TargetVersion>
<UseDebugLibraries>false</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|x64'" Label="Configuration">
<TargetVersion>Windows7</TargetVersion>
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win7 Release|x64'" Label="Configuration">
<TargetVersion>Windows7</TargetVersion>
<UseDebugLibraries>false</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Vista Debug|x64'" Label="Configuration">
<TargetVersion>Vista</TargetVersion>
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Vista Release|x64'" Label="Configuration">
<TargetVersion>Vista</TargetVersion>
<UseDebugLibraries>false</UseDebugLibraries>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Vista Debug|Win32'">
<TargetName>zttap300</TargetName>
</PropertyGroup>
<PropertyGroup>
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'">
<TargetName>zttap300</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Vista Release|Win32'">
<TargetName>zttap300</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|Win32'">
<TargetName>zttap300</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win7 Release|Win32'">
<TargetName>zttap300</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">
<TargetName>zttap300</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Vista Debug|x64'">
<TargetName>zttap300</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">
<TargetName>zttap300</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Vista Release|x64'">
<TargetName>zttap300</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|x64'">
<TargetName>zttap300</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win7 Release|x64'">
<TargetName>zttap300</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">
<TargetName>zttap300</TargetName>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<WppEnabled>false</WppEnabled>
<WppScanConfigurationData Condition="'%(ClCompile. ScanConfigurationData)' == ''">trace.h</WppScanConfigurationData>
<WppKernelMode>false</WppKernelMode>
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Vista Debug|Win32'">false</WppMinimalRebuildFromTracking>
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'">false</WppMinimalRebuildFromTracking>
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Vista Release|Win32'">false</WppMinimalRebuildFromTracking>
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|Win32'">false</WppMinimalRebuildFromTracking>
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Win7 Release|Win32'">false</WppMinimalRebuildFromTracking>
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">false</WppMinimalRebuildFromTracking>
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Vista Debug|x64'">false</WppMinimalRebuildFromTracking>
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">false</WppMinimalRebuildFromTracking>
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Vista Release|x64'">false</WppMinimalRebuildFromTracking>
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|x64'">false</WppMinimalRebuildFromTracking>
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Win7 Release|x64'">false</WppMinimalRebuildFromTracking>
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">false</WppMinimalRebuildFromTracking>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Vista Debug|Win32'">Level1</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'">Level1</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Vista Release|Win32'">Level1</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|Win32'">Level1</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Win7 Release|Win32'">Level1</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">Level1</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Vista Debug|x64'">Level1</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">Level1</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Vista Release|x64'">Level1</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|x64'">Level1</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Win7 Release|x64'">Level1</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">Level1</WarningLevel>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Vista Debug|Win32'">Default</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'">Default</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Vista Release|Win32'">Default</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|Win32'">Default</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Win7 Release|Win32'">Default</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">Default</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Vista Debug|x64'">Default</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">Default</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Vista Release|x64'">Default</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|x64'">Default</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Win7 Release|x64'">Default</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">Default</CompileAs>
</ClCompile>
<Link>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Vista Debug|x64'">C:\WinDDK\7600.16385.1\lib\win7\amd64\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">C:\WinDDK\7600.16385.1\lib\win7\amd64\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Vista Release|x64'">C:\WinDDK\7600.16385.1\lib\win7\amd64\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|x64'">C:\WinDDK\7600.16385.1\lib\win7\amd64\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Win7 Release|x64'">C:\WinDDK\7600.16385.1\lib\win7\amd64\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">C:\WinDDK\7600.16385.1\lib\win7\amd64\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Vista Debug|Win32'">C:\WinDDK\7600.16385.1\lib\win7\i386\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'">C:\WinDDK\7600.16385.1\lib\win7\i386\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Vista Release|Win32'">C:\WinDDK\7600.16385.1\lib\win7\i386\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|Win32'">C:\WinDDK\7600.16385.1\lib\win7\i386\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Win7 Release|Win32'">C:\WinDDK\7600.16385.1\lib\win7\i386\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">C:\WinDDK\7600.16385.1\lib\win7\i386\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Inf>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Vista Debug|Win32'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Vista Debug|Win32'">false</SpecifyDriverVerDirectiveVersion>
<SpecifyDriverVerDirectiveDate Condition="'$(Configuration)|$(Platform)'=='Vista Debug|Win32'">false</SpecifyDriverVerDirectiveDate>
</Inf>
<Inf>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'">false</SpecifyDriverVerDirectiveVersion>
<SpecifyDriverVerDirectiveDate Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'">false</SpecifyDriverVerDirectiveDate>
</Inf>
<Inf>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Vista Release|Win32'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Vista Release|Win32'">false</SpecifyDriverVerDirectiveVersion>
<SpecifyDriverVerDirectiveDate Condition="'$(Configuration)|$(Platform)'=='Vista Release|Win32'">false</SpecifyDriverVerDirectiveDate>
</Inf>
<Inf>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|Win32'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|Win32'">false</SpecifyDriverVerDirectiveVersion>
<SpecifyDriverVerDirectiveDate Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|Win32'">false</SpecifyDriverVerDirectiveDate>
</Inf>
<Inf>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win7 Release|Win32'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win7 Release|Win32'">false</SpecifyDriverVerDirectiveVersion>
<SpecifyDriverVerDirectiveDate Condition="'$(Configuration)|$(Platform)'=='Win7 Release|Win32'">false</SpecifyDriverVerDirectiveDate>
</Inf>
<Inf>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">false</SpecifyDriverVerDirectiveVersion>
<SpecifyDriverVerDirectiveDate Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">false</SpecifyDriverVerDirectiveDate>
</Inf>
<Inf>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Vista Debug|x64'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Vista Debug|x64'">false</SpecifyDriverVerDirectiveVersion>
<SpecifyDriverVerDirectiveDate Condition="'$(Configuration)|$(Platform)'=='Vista Debug|x64'">false</SpecifyDriverVerDirectiveDate>
</Inf>
<Inf>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">false</SpecifyDriverVerDirectiveVersion>
<SpecifyDriverVerDirectiveDate Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">false</SpecifyDriverVerDirectiveDate>
</Inf>
<Inf>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Vista Release|x64'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Vista Release|x64'">false</SpecifyDriverVerDirectiveVersion>
<SpecifyDriverVerDirectiveDate Condition="'$(Configuration)|$(Platform)'=='Vista Release|x64'">false</SpecifyDriverVerDirectiveDate>
</Inf>
<Inf>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|x64'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|x64'">false</SpecifyDriverVerDirectiveVersion>
<SpecifyDriverVerDirectiveDate Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|x64'">false</SpecifyDriverVerDirectiveDate>
</Inf>
<Inf>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win7 Release|x64'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win7 Release|x64'">false</SpecifyDriverVerDirectiveVersion>
<SpecifyDriverVerDirectiveDate Condition="'$(Configuration)|$(Platform)'=='Win7 Release|x64'">false</SpecifyDriverVerDirectiveDate>
</Inf>
<Inf>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">false</SpecifyDriverVerDirectiveVersion>
<SpecifyDriverVerDirectiveDate Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">false</SpecifyDriverVerDirectiveDate>
</Inf>
</ItemDefinitionGroup>
<ItemGroup>
<FilesToPackage Include="$(TargetPath)" />
<FilesToPackage Include="@(Inf->'%(CopyOutput)')" Condition="'@(Inf)'!=''" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="adapter.c" />
<ClCompile Include="device.c" />
<ClCompile Include="error.c" />
<ClCompile Include="macinfo.c" />
<ClCompile Include="mem.c" />
<ClCompile Include="oidrequest.c" />
<ClCompile Include="rxpath.c" />
<ClCompile Include="tapdrvr.c" />
<ClCompile Include="txpath.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="adapter.h" />
<ClInclude Include="config.h" />
<ClInclude Include="constants.h" />
<ClInclude Include="device.h" />
<ClInclude Include="endian.h" />
<ClInclude Include="error.h" />
<ClInclude Include="hexdump.h" />
<ClInclude Include="lock.h" />
<ClInclude Include="macinfo.h" />
<ClInclude Include="mem.h" />
<ClInclude Include="proto.h" />
<ClInclude Include="prototypes.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="tap-windows.h" />
<ClInclude Include="tap.h" />
<ClInclude Include="types.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc" />
</ItemGroup>
<ItemGroup>
<Inf Include="zttap300.inf">
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win7 Release|x64'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Vista Debug|Win32'">false</SpecifyDriverVerDirectiveVersion>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Vista Debug|Win32'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'">false</SpecifyDriverVerDirectiveVersion>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Vista Release|Win32'">false</SpecifyDriverVerDirectiveVersion>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Vista Release|Win32'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|Win32'">false</SpecifyDriverVerDirectiveVersion>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|Win32'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win7 Release|Win32'">false</SpecifyDriverVerDirectiveVersion>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win7 Release|Win32'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">false</SpecifyDriverVerDirectiveVersion>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Vista Debug|x64'">false</SpecifyDriverVerDirectiveVersion>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Vista Debug|x64'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">false</SpecifyDriverVerDirectiveVersion>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Vista Release|x64'">false</SpecifyDriverVerDirectiveVersion>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Vista Release|x64'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|x64'">false</SpecifyDriverVerDirectiveVersion>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win7 Debug|x64'">3.00.00.0</TimeStamp>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win7 Release|x64'">false</SpecifyDriverVerDirectiveVersion>
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">false</SpecifyDriverVerDirectiveVersion>
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">3.00.00.0</TimeStamp>
</Inf>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Driver Files">
<UniqueIdentifier>{8E41214B-6785-4CFE-B992-037D68949A14}</UniqueIdentifier>
<Extensions>inf;inv;inx;mof;mc;</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="adapter.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="device.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="error.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="macinfo.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="mem.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="oidrequest.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="rxpath.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="tapdrvr.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="txpath.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="adapter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="constants.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="device.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="endian.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="error.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="hexdump.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="lock.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="macinfo.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="mem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="proto.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="prototypes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="tap.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="tap-windows.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="types.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Inf Include="zttap300.inf">
<Filter>Driver Files</Filter>
</Inf>
</ItemGroup>
</Project>

1716
windows/TapDriver6/adapter.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,352 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __TAP_ADAPTER_CONTEXT_H_
#define __TAP_ADAPTER_CONTEXT_H_
#include "tap.h"
// Memory allocation tags.
#define TAP_ADAPTER_TAG ((ULONG)'ApaT') // "TapA
#define TAP_RX_NBL_TAG ((ULONG)'RpaT') // "TapR
#define TAP_RX_INJECT_BUFFER_TAG ((ULONG)'IpaT') // "TapI
#define TAP_MAX_NDIS_NAME_LENGTH 64 // 38 character GUID string plus extra..
// TAP receive indication NBL flag definitions.
#define TAP_RX_NBL_FLAGS NBL_FLAGS_MINIPORT_RESERVED
#define TAP_RX_NBL_FLAGS_CLEAR_ALL(_NBL) ((_NBL)->Flags &= ~TAP_RX_NBL_FLAGS)
#define TAP_RX_NBL_FLAG_SET(_NBL, _F) ((_NBL)->Flags |= ((_F) & TAP_RX_NBL_FLAGS))
#define TAP_RX_NBL_FLAG_CLEAR(_NBL, _F) ((_NBL)->Flags &= ~((_F) & TAP_RX_NBL_FLAGS))
#define TAP_RX_NBL_FLAG_TEST(_NBL, _F) (((_NBL)->Flags & ((_F) & TAP_RX_NBL_FLAGS)) != 0)
#define TAP_RX_NBL_FLAGS_IS_P2P 0x00001000
#define TAP_RX_NBL_FLAGS_IS_INJECTED 0x00002000
// MSDN Ref: http://msdn.microsoft.com/en-us/library/windows/hardware/ff560490(v=vs.85).aspx
typedef
enum _TAP_MINIPORT_ADAPTER_STATE
{
// The Halted state is the initial state of all adapters. When an
// adapter is in the Halted state, NDIS can call the driver's
// MiniportInitializeEx function to initialize the adapter.
MiniportHaltedState,
// In the Shutdown state, a system shutdown and restart must occur
// before the system can use the adapter again.
MiniportShutdownState,
// In the Initializing state, a miniport driver completes any
//operations that are required to initialize an adapter.
MiniportInitializingState,
// Entering the Paused state...
MiniportPausingState,
// In the Paused state, the adapter does not indicate received
// network data or accept send requests.
MiniportPausedState,
// In the Running state, a miniport driver performs send and
// receive processing for an adapter.
MiniportRunning,
// In the Restarting state, a miniport driver completes any
// operations that are required to restart send and receive
// operations for an adapter.
MiniportRestartingState
} TAP_MINIPORT_ADAPTER_STATE, *PTAP_MINIPORT_ADAPTER_STATE;
//
// Each adapter managed by this driver has a TapAdapter struct.
// ------------------------------------------------------------
// Since there is a one-to-one relationship between adapter instances
// and device instances this structure is the device extension as well.
//
typedef struct _TAP_ADAPTER_CONTEXT
{
LIST_ENTRY AdapterListLink;
volatile LONG RefCount;
NDIS_HANDLE MiniportAdapterHandle;
NDIS_SPIN_LOCK AdapterLock; // Lock for protection of state and outstanding sends and recvs
//
// All fields that are protected by the AdapterLock are included
// in the Locked structure to remind us to take the Lock
// before accessing them :)
//
struct
{
TAP_MINIPORT_ADAPTER_STATE AdapterState;
} Locked;
BOOLEAN ResetInProgress;
//
// NetCfgInstanceId as UNICODE_STRING
// ----------------------------------
// This a GUID string provided by NDIS that identifies the adapter instance.
// An example is:
//
// NetCfgInstanceId={410EB49D-2381-4FE7-9B36-498E22619DF0}
//
// Other names are derived from NetCfgInstanceId. For example, MiniportName:
//
// MiniportName=\DEVICE\{410EB49D-2381-4FE7-9B36-498E22619DF0}
//
NDIS_STRING NetCfgInstanceId;
WCHAR NetCfgInstanceIdBuffer[TAP_MAX_NDIS_NAME_LENGTH];
# define MINIPORT_INSTANCE_ID(a) ((a)->NetCfgInstanceIdAnsi.Buffer)
ANSI_STRING NetCfgInstanceIdAnsi; // Used occasionally
ULONG MtuSize; // 1500 byte (typical)
// TRUE if adapter should always be "connected" even when device node
// is not open by a userspace process.
//
// FALSE if connection state is application controlled.
BOOLEAN MediaStateAlwaysConnected;
// TRUE if device is "connected".
BOOLEAN LogicalMediaState;
NDIS_DEVICE_POWER_STATE CurrentPowerState;
BOOLEAN AllowNonAdmin;
MACADDR PermanentAddress; // From registry, if available
MACADDR CurrentAddress;
// Device registration parameters from NdisRegisterDeviceEx.
NDIS_STRING DeviceName;
WCHAR DeviceNameBuffer[TAP_MAX_NDIS_NAME_LENGTH];
NDIS_STRING LinkName;
WCHAR LinkNameBuffer[TAP_MAX_NDIS_NAME_LENGTH];
NDIS_HANDLE DeviceHandle;
PDEVICE_OBJECT DeviceObject;
BOOLEAN TapDeviceCreated; // WAS: m_TapIsRunning
PFILE_OBJECT TapFileObject; // Exclusive access
BOOLEAN TapFileIsOpen; // WAS: m_TapOpens
LONG TapFileOpenCount; // WAS: m_NumTapOpens
// Cancel-Safe read IRP queue.
TAP_IRP_CSQ PendingReadIrpQueue;
// Queue containing TAP packets representing host send NBs. These are
// waiting to be read by user-mode application.
TAP_PACKET_QUEUE SendPacketQueue;
// NBL pool for making TAP receive indications.
NDIS_HANDLE ReceiveNblPool;
volatile LONG ReceiveNblInFlightCount;
#define TAP_WAIT_POLL_LOOP_TIMEOUT 3000 // 3 seconds
NDIS_EVENT ReceiveNblInFlightCountZeroEvent;
/*
// Info for point-to-point mode
BOOLEAN m_tun;
IPADDR m_localIP;
IPADDR m_remoteNetwork;
IPADDR m_remoteNetmask;
ETH_HEADER m_TapToUser;
ETH_HEADER m_UserToTap;
ETH_HEADER m_UserToTap_IPv6; // same as UserToTap but proto=ipv6
*/
// Info for DHCP server masquerade
/*
BOOLEAN m_dhcp_enabled;
IPADDR m_dhcp_addr;
ULONG m_dhcp_netmask;
IPADDR m_dhcp_server_ip;
BOOLEAN m_dhcp_server_arp;
MACADDR m_dhcp_server_mac;
ULONG m_dhcp_lease_time;
UCHAR m_dhcp_user_supplied_options_buffer[DHCP_USER_SUPPLIED_OPTIONS_BUFFER_SIZE];
ULONG m_dhcp_user_supplied_options_buffer_len;
BOOLEAN m_dhcp_received_discover;
ULONG m_dhcp_bad_requests;
*/
// Multicast list. Fixed size.
ULONG ulMCListSize;
UCHAR MCList[TAP_MAX_MCAST_LIST][MACADDR_SIZE];
ULONG PacketFilter;
ULONG ulLookahead;
//
// Statistics
// -------------------------------------------------------------------------
//
// Packet counts
ULONG64 FramesRxDirected;
ULONG64 FramesRxMulticast;
ULONG64 FramesRxBroadcast;
ULONG64 FramesTxDirected;
ULONG64 FramesTxMulticast;
ULONG64 FramesTxBroadcast;
// Byte counts
ULONG64 BytesRxDirected;
ULONG64 BytesRxMulticast;
ULONG64 BytesRxBroadcast;
ULONG64 BytesTxDirected;
ULONG64 BytesTxMulticast;
ULONG64 BytesTxBroadcast;
// Count of transmit errors
ULONG TxAbortExcessCollisions;
ULONG TxLateCollisions;
ULONG TxDmaUnderrun;
ULONG TxLostCRS;
ULONG TxOKButDeferred;
ULONG OneRetry;
ULONG MoreThanOneRetry;
ULONG TotalRetries;
ULONG TransmitFailuresOther;
// Count of receive errors
ULONG RxCrcErrors;
ULONG RxAlignmentErrors;
ULONG RxResourceErrors;
ULONG RxDmaOverrunErrors;
ULONG RxCdtFrames;
ULONG RxRuntErrors;
#if PACKET_TRUNCATION_CHECK
LONG m_RxTrunc, m_TxTrunc;
#endif
BOOLEAN m_InterfaceIsRunning;
LONG m_Rx, m_RxErr;
NDIS_MEDIUM m_Medium;
// Help to tear down the adapter by keeping
// some state information on allocated
// resources.
BOOLEAN m_CalledAdapterFreeResources;
BOOLEAN m_RegisteredAdapterShutdownHandler;
} TAP_ADAPTER_CONTEXT, *PTAP_ADAPTER_CONTEXT;
FORCEINLINE
LONG
tapAdapterContextReference(
__in PTAP_ADAPTER_CONTEXT Adapter
)
{
LONG refCount = NdisInterlockedIncrement(&Adapter->RefCount);
ASSERT(refCount>1); // Cannot dereference a zombie.
return refCount;
}
VOID
tapAdapterContextFree(
__in PTAP_ADAPTER_CONTEXT Adapter
);
FORCEINLINE
LONG
tapAdapterContextDereference(
IN PTAP_ADAPTER_CONTEXT Adapter
)
{
LONG refCount = NdisInterlockedDecrement(&Adapter->RefCount);
ASSERT(refCount >= 0);
if (!refCount)
{
tapAdapterContextFree(Adapter);
}
return refCount;
}
VOID
tapAdapterAcquireLock(
__in PTAP_ADAPTER_CONTEXT Adapter,
__in BOOLEAN DispatchLevel
);
VOID
tapAdapterReleaseLock(
__in PTAP_ADAPTER_CONTEXT Adapter,
__in BOOLEAN DispatchLevel
);
// Returns with added reference on adapter context.
PTAP_ADAPTER_CONTEXT
tapAdapterContextFromDeviceObject(
__in PDEVICE_OBJECT DeviceObject
);
BOOLEAN
tapAdapterReadAndWriteReady(
__in PTAP_ADAPTER_CONTEXT Adapter
);
NDIS_STATUS
tapAdapterSendAndReceiveReady(
__in PTAP_ADAPTER_CONTEXT Adapter
);
ULONG
tapGetNetBufferFrameType(
__in PNET_BUFFER NetBuffer
);
ULONG
tapGetNetBufferCountsFromNetBufferList(
__in PNET_BUFFER_LIST NetBufferList,
__inout_opt PULONG TotalByteCount // Of all linked NBs
);
// Prototypes for standard NDIS miniport entry points
MINIPORT_SET_OPTIONS AdapterSetOptions;
MINIPORT_INITIALIZE AdapterCreate;
MINIPORT_HALT AdapterHalt;
MINIPORT_UNLOAD TapDriverUnload;
MINIPORT_PAUSE AdapterPause;
MINIPORT_RESTART AdapterRestart;
MINIPORT_OID_REQUEST AdapterOidRequest;
MINIPORT_SEND_NET_BUFFER_LISTS AdapterSendNetBufferLists;
MINIPORT_RETURN_NET_BUFFER_LISTS AdapterReturnNetBufferLists;
MINIPORT_CANCEL_SEND AdapterCancelSend;
MINIPORT_CHECK_FOR_HANG AdapterCheckForHangEx;
MINIPORT_RESET AdapterReset;
MINIPORT_DEVICE_PNP_EVENT_NOTIFY AdapterDevicePnpEventNotify;
MINIPORT_SHUTDOWN AdapterShutdownEx;
MINIPORT_CANCEL_OID_REQUEST AdapterCancelOidRequest;
#endif // __TAP_ADAPTER_CONTEXT_H_

View File

@ -0,0 +1,9 @@
#define PRODUCT_NAME "ZeroTier One Virtual Port"
#define PRODUCT_VERSION "3.0.0"
#define PRODUCT_VERSION_RESOURCE 3,0,0,1
#define PRODUCT_TAP_WIN_COMPONENT_ID "zttap300"
#define PRODUCT_TAP_WIN_MAJOR 3
#define PRODUCT_TAP_WIN_MINOR 0
#define PRODUCT_TAP_WIN_PROVIDER "ZeroTier Networks"
#define PRODUCT_TAP_WIN_DEVICE_DESCRIPTION PRODUCT_NAME
#define PRODUCT_TAP_WIN_RELDATE "04/25/2015"

View File

@ -0,0 +1,196 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//====================================================================
// Product and Version public settings
//====================================================================
#define PRODUCT_STRING PRODUCT_TAP_DEVICE_DESCRIPTION
//
// Update the driver version number every time you release a new driver
// The high word is the major version. The low word is the minor version.
// Also make sure that VER_FILEVERSION specified in the .RC file also
// matches with the driver version because NDISTESTER checks for that.
//
#ifndef TAP_DRIVER_MAJOR_VERSION
#define TAP_DRIVER_MAJOR_VERSION 0x04
#define TAP_DRIVER_MINOR_VERSION 0x02
#endif
#define TAP_DRIVER_VENDOR_VERSION ((TAP_DRIVER_MAJOR_VERSION << 16) | TAP_DRIVER_MINOR_VERSION)
//
// Define the NDIS miniport interface version that this driver targets.
//
#if defined(NDIS60_MINIPORT)
# define TAP_NDIS_MAJOR_VERSION 6
# define TAP_NDIS_MINOR_VERSION 0
#elif defined(NDIS61_MINIPORT)
# define TAP_NDIS_MAJOR_VERSION 6
# define TAP_NDIS_MINOR_VERSION 1
#elif defined(NDIS620_MINIPORT)
# define TAP_NDIS_MAJOR_VERSION 6
# define TAP_NDIS_MINOR_VERSION 20
#elif defined(NDIS630_MINIPORT)
# define TAP_NDIS_MAJOR_VERSION 6
# define TAP_NDIS_MINOR_VERSION 30
#else
#define TAP_NDIS_MAJOR_VERSION 5
#define TAP_NDIS_MINOR_VERSION 0
#endif
//===========================================================
// Driver constants
//===========================================================
#define ETHERNET_HEADER_SIZE (sizeof (ETH_HEADER))
//#define ETHERNET_MTU 1500
#define ETHERNET_MTU 2800
#define ETHERNET_PACKET_SIZE (ETHERNET_MTU + ETHERNET_HEADER_SIZE)
#define DEFAULT_PACKET_LOOKAHEAD (ETHERNET_PACKET_SIZE)
#define VLAN_TAG_SIZE 4
//===========================================================
// Medium properties
//===========================================================
#define TAP_FRAME_HEADER_SIZE ETHERNET_HEADER_SIZE
#define TAP_FRAME_MAX_DATA_SIZE ETHERNET_MTU
#define TAP_MAX_FRAME_SIZE (TAP_FRAME_HEADER_SIZE + TAP_FRAME_MAX_DATA_SIZE)
#define TAP_MIN_FRAME_SIZE 60
#define TAP_MEDIUM_TYPE NdisMedium802_3
//===========================================================
// Physical adapter properties
//===========================================================
// The bus that connects the adapter to the PC.
// (Example: PCI adapters should use NdisInterfacePci).
#define TAP_INTERFACE_TYPE NdisInterfaceInternal
#define TAP_VENDOR_DESC PRODUCT_TAP_WIN_DEVICE_DESCRIPTION
// Highest byte is the NIC byte plus three vendor bytes. This is normally
// obtained from the NIC.
#define TAP_VENDOR_ID 0x00FFFFFF
// If you have physical hardware on 802.3, use NdisPhysicalMedium802_3.
#define TAP_PHYSICAL_MEDIUM NdisPhysicalMediumUnspecified
// Claim to be 100mbps duplex
#define MEGABITS_PER_SECOND 1000000ULL
#define TAP_XMIT_SPEED (100ULL*MEGABITS_PER_SECOND)
#define TAP_RECV_SPEED (100ULL*MEGABITS_PER_SECOND)
// Max number of multicast addresses supported in hardware
#define TAP_MAX_MCAST_LIST 128
#define TAP_MAX_LOOKAHEAD TAP_FRAME_MAX_DATA_SIZE
#define TAP_BUFFER_SIZE TAP_MAX_FRAME_SIZE
// Set this value to TRUE if there is a physical adapter.
#define TAP_HAS_PHYSICAL_CONNECTOR FALSE
#define TAP_ACCESS_TYPE NET_IF_ACCESS_BROADCAST
#define TAP_DIRECTION_TYPE NET_IF_DIRECTION_SENDRECEIVE
#define TAP_CONNECTION_TYPE NET_IF_CONNECTION_DEDICATED
// This value must match the *IfType in the driver .inf file
#define TAP_IFTYPE IF_TYPE_ETHERNET_CSMACD
//
// This is a virtual device, so it can tolerate surprise removal and
// suspend. Ensure the correct flags are set for your hardware.
//
#define TAP_ADAPTER_ATTRIBUTES_FLAGS (\
NDIS_MINIPORT_ATTRIBUTES_SURPRISE_REMOVE_OK | NDIS_MINIPORT_ATTRIBUTES_NDIS_WDM)
#define TAP_SUPPORTED_FILTERS ( \
NDIS_PACKET_TYPE_DIRECTED | \
NDIS_PACKET_TYPE_MULTICAST | \
NDIS_PACKET_TYPE_BROADCAST | \
NDIS_PACKET_TYPE_ALL_LOCAL | \
NDIS_PACKET_TYPE_PROMISCUOUS | \
NDIS_PACKET_TYPE_ALL_MULTICAST)
//#define TAP_MAX_MCAST_LIST 128 // Max length of multicast address list
//
// Specify a bitmask that defines optional properties of the NIC.
// This miniport indicates receive with NdisMIndicateReceiveNetBufferLists
// function. Such a driver should set this NDIS_MAC_OPTION_TRANSFERS_NOT_PEND
// flag.
//
// NDIS_MAC_OPTION_NO_LOOPBACK tells NDIS that NIC has no internal
// loopback support so NDIS will manage loopbacks on behalf of
// this driver.
//
// NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA tells the protocol that
// our receive buffer is not on a device-specific card. If
// NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA is not set, multi-buffer
// indications are copied to a single flat buffer.
//
#define TAP_MAC_OPTIONS (\
NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA | \
NDIS_MAC_OPTION_TRANSFERS_NOT_PEND | \
NDIS_MAC_OPTION_NO_LOOPBACK)
#define TAP_ADAPTER_CHECK_FOR_HANG_TIME_IN_SECONDS 4
// NDIS 6.x miniports must support all counters in OID_GEN_STATISTICS.
#define TAP_SUPPORTED_STATISTICS (\
NDIS_STATISTICS_FLAGS_VALID_DIRECTED_FRAMES_RCV | \
NDIS_STATISTICS_FLAGS_VALID_MULTICAST_FRAMES_RCV | \
NDIS_STATISTICS_FLAGS_VALID_BROADCAST_FRAMES_RCV | \
NDIS_STATISTICS_FLAGS_VALID_BYTES_RCV | \
NDIS_STATISTICS_FLAGS_VALID_RCV_DISCARDS | \
NDIS_STATISTICS_FLAGS_VALID_RCV_ERROR | \
NDIS_STATISTICS_FLAGS_VALID_DIRECTED_FRAMES_XMIT | \
NDIS_STATISTICS_FLAGS_VALID_MULTICAST_FRAMES_XMIT | \
NDIS_STATISTICS_FLAGS_VALID_BROADCAST_FRAMES_XMIT | \
NDIS_STATISTICS_FLAGS_VALID_BYTES_XMIT | \
NDIS_STATISTICS_FLAGS_VALID_XMIT_ERROR | \
NDIS_STATISTICS_FLAGS_VALID_XMIT_DISCARDS | \
NDIS_STATISTICS_FLAGS_VALID_DIRECTED_BYTES_RCV | \
NDIS_STATISTICS_FLAGS_VALID_MULTICAST_BYTES_RCV | \
NDIS_STATISTICS_FLAGS_VALID_BROADCAST_BYTES_RCV | \
NDIS_STATISTICS_FLAGS_VALID_DIRECTED_BYTES_XMIT | \
NDIS_STATISTICS_FLAGS_VALID_MULTICAST_BYTES_XMIT | \
NDIS_STATISTICS_FLAGS_VALID_BROADCAST_BYTES_XMIT)
#define MINIMUM_MTU 576 // USE TCP Minimum MTU
#define MAXIMUM_MTU 65536 // IP maximum MTU
#define PACKET_QUEUE_SIZE 64 // tap -> userspace queue size
#define IRP_QUEUE_SIZE 16 // max number of simultaneous i/o operations from userspace
#define INJECT_QUEUE_SIZE 16 // DHCP/ARP -> tap injection queue
#define TAP_LITTLE_ENDIAN // affects ntohs, htonl, etc. functions

1209
windows/TapDriver6/device.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,50 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __TAP_DEVICE_H_
#define __TAP_DEVICE_H_
//======================================================================
// TAP Prototypes for standard Win32 device I/O entry points
//======================================================================
__drv_dispatchType(IRP_MJ_CREATE)
DRIVER_DISPATCH TapDeviceCreate;
__drv_dispatchType(IRP_MJ_READ)
DRIVER_DISPATCH TapDeviceRead;
__drv_dispatchType(IRP_MJ_WRITE)
DRIVER_DISPATCH TapDeviceWrite;
__drv_dispatchType(IRP_MJ_DEVICE_CONTROL)
DRIVER_DISPATCH TapDeviceControl;
__drv_dispatchType(IRP_MJ_CLEANUP)
DRIVER_DISPATCH TapDeviceCleanup;
__drv_dispatchType(IRP_MJ_CLOSE)
DRIVER_DISPATCH TapDeviceClose;
#endif // __TAP_DEVICE_H_

View File

@ -0,0 +1,35 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef TAP_LITTLE_ENDIAN
#define ntohs(x) RtlUshortByteSwap(x)
#define htons(x) RtlUshortByteSwap(x)
#define ntohl(x) RtlUlongByteSwap(x)
#define htonl(x) RtlUlongByteSwap(x)
#else
#define ntohs(x) ((USHORT)(x))
#define htons(x) ((USHORT)(x))
#define ntohl(x) ((ULONG)(x))
#define htonl(x) ((ULONG)(x))
#endif

398
windows/TapDriver6/error.c Normal file
View File

@ -0,0 +1,398 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "tap.h"
//-----------------
// DEBUGGING OUTPUT
//-----------------
const char *g_LastErrorFilename;
int g_LastErrorLineNumber;
#if DBG
DebugOutput g_Debug;
BOOLEAN
NewlineExists (const char *str, int len)
{
while (len-- > 0)
{
const char c = *str++;
if (c == '\n')
return TRUE;
else if (c == '\0')
break;
}
return FALSE;
}
VOID
MyDebugInit (unsigned int bufsiz)
{
NdisZeroMemory (&g_Debug, sizeof (g_Debug));
g_Debug.text = (char *) MemAlloc (bufsiz, FALSE);
if (g_Debug.text)
{
g_Debug.capacity = bufsiz;
}
}
VOID
MyDebugFree ()
{
if (g_Debug.text)
{
MemFree (g_Debug.text, g_Debug.capacity);
}
NdisZeroMemory (&g_Debug, sizeof (g_Debug));
}
VOID
MyDebugPrint (const unsigned char* format, ...)
{
if (g_Debug.text && g_Debug.capacity > 0 && CAN_WE_PRINT)
{
BOOLEAN owned;
ACQUIRE_MUTEX_ADAPTIVE (&g_Debug.lock, owned);
if (owned)
{
const int remaining = (int)g_Debug.capacity - (int)g_Debug.out;
if (remaining > 0)
{
va_list args;
NTSTATUS status;
char *end;
#ifdef DBG_PRINT
va_start (args, format);
vDbgPrintEx (DPFLTR_IHVNETWORK_ID, DPFLTR_INFO_LEVEL, format, args);
va_end (args);
#endif
va_start (args, format);
status = RtlStringCchVPrintfExA (g_Debug.text + g_Debug.out,
remaining,
&end,
NULL,
STRSAFE_NO_TRUNCATION | STRSAFE_IGNORE_NULLS,
format,
args);
va_end (args);
va_start (args, format);
vDbgPrintEx(DPFLTR_IHVDRIVER_ID , 1, format, args);
va_end (args);
if (status == STATUS_SUCCESS)
g_Debug.out = (unsigned int) (end - g_Debug.text);
else
g_Debug.error = TRUE;
}
else
g_Debug.error = TRUE;
RELEASE_MUTEX (&g_Debug.lock);
}
else
g_Debug.error = TRUE;
}
}
BOOLEAN
GetDebugLine (
__in char *buf,
__in const int len
)
{
static const char *truncated = "[OUTPUT TRUNCATED]\n";
BOOLEAN ret = FALSE;
NdisZeroMemory (buf, len);
if (g_Debug.text && g_Debug.capacity > 0)
{
BOOLEAN owned;
ACQUIRE_MUTEX_ADAPTIVE (&g_Debug.lock, owned);
if (owned)
{
int i = 0;
if (g_Debug.error || NewlineExists (g_Debug.text + g_Debug.in, (int)g_Debug.out - (int)g_Debug.in))
{
while (i < (len - 1) && g_Debug.in < g_Debug.out)
{
const char c = g_Debug.text[g_Debug.in++];
if (c == '\n')
break;
buf[i++] = c;
}
if (i < len)
buf[i] = '\0';
}
if (!i)
{
if (g_Debug.in == g_Debug.out)
{
g_Debug.in = g_Debug.out = 0;
if (g_Debug.error)
{
const unsigned int tlen = strlen (truncated);
if (tlen < g_Debug.capacity)
{
NdisMoveMemory (g_Debug.text, truncated, tlen+1);
g_Debug.out = tlen;
}
g_Debug.error = FALSE;
}
}
}
else
ret = TRUE;
RELEASE_MUTEX (&g_Debug.lock);
}
}
return ret;
}
VOID
PrMac (const MACADDR mac)
{
DEBUGP (("%x:%x:%x:%x:%x:%x",
mac[0], mac[1], mac[2],
mac[3], mac[4], mac[5]));
}
VOID
PrIP (IPADDR ip_addr)
{
const unsigned char *ip = (const unsigned char *) &ip_addr;
DEBUGP (("%d.%d.%d.%d",
ip[0], ip[1], ip[2], ip[3]));
}
const char *
PrIPProto (int proto)
{
switch (proto)
{
case IPPROTO_UDP:
return "UDP";
case IPPROTO_TCP:
return "TCP";
case IPPROTO_ICMP:
return "ICMP";
case IPPROTO_IGMP:
return "IGMP";
default:
return "???";
}
}
VOID
DumpARP (const char *prefix, const ARP_PACKET *arp)
{
DEBUGP (("%s ARP src=", prefix));
PrMac (arp->m_MAC_Source);
DEBUGP ((" dest="));
PrMac (arp->m_MAC_Destination);
DEBUGP ((" OP=0x%04x",
(int)ntohs(arp->m_ARP_Operation)));
DEBUGP ((" M=0x%04x(%d)",
(int)ntohs(arp->m_MAC_AddressType),
(int)arp->m_MAC_AddressSize));
DEBUGP ((" P=0x%04x(%d)",
(int)ntohs(arp->m_PROTO_AddressType),
(int)arp->m_PROTO_AddressSize));
DEBUGP ((" MacSrc="));
PrMac (arp->m_ARP_MAC_Source);
DEBUGP ((" MacDest="));
PrMac (arp->m_ARP_MAC_Destination);
DEBUGP ((" IPSrc="));
PrIP (arp->m_ARP_IP_Source);
DEBUGP ((" IPDest="));
PrIP (arp->m_ARP_IP_Destination);
DEBUGP (("\n"));
}
struct ethpayload
{
ETH_HEADER eth;
UCHAR payload[DEFAULT_PACKET_LOOKAHEAD];
};
#ifdef ALLOW_PACKET_DUMP
VOID
DumpPacket2(
__in const char *prefix,
__in const ETH_HEADER *eth,
__in const unsigned char *data,
__in unsigned int len
)
{
struct ethpayload *ep = (struct ethpayload *) MemAlloc (sizeof (struct ethpayload), TRUE);
if (ep)
{
if (len > DEFAULT_PACKET_LOOKAHEAD)
len = DEFAULT_PACKET_LOOKAHEAD;
ep->eth = *eth;
NdisMoveMemory (ep->payload, data, len);
DumpPacket (prefix, (unsigned char *) ep, sizeof (ETH_HEADER) + len);
MemFree (ep, sizeof (struct ethpayload));
}
}
VOID
DumpPacket(
__in const char *prefix,
__in const unsigned char *data,
__in unsigned int len
)
{
const ETH_HEADER *eth = (const ETH_HEADER *) data;
const IPHDR *ip = (const IPHDR *) (data + sizeof (ETH_HEADER));
if (len < sizeof (ETH_HEADER))
{
DEBUGP (("%s TRUNCATED PACKET LEN=%d\n", prefix, len));
return;
}
// ARP Packet?
if (len >= sizeof (ARP_PACKET) && eth->proto == htons (ETH_P_ARP))
{
DumpARP (prefix, (const ARP_PACKET *) data);
return;
}
// IPv4 packet?
if (len >= (sizeof (IPHDR) + sizeof (ETH_HEADER))
&& eth->proto == htons (ETH_P_IP)
&& IPH_GET_VER (ip->version_len) == 4)
{
const int hlen = IPH_GET_LEN (ip->version_len);
const int blen = len - sizeof (ETH_HEADER);
BOOLEAN did = FALSE;
DEBUGP (("%s IPv4 %s[%d]", prefix, PrIPProto (ip->protocol), len));
if (!(ntohs (ip->tot_len) == blen && hlen <= blen))
{
DEBUGP ((" XXX"));
return;
}
// TCP packet?
if (ip->protocol == IPPROTO_TCP
&& blen - hlen >= (sizeof (TCPHDR)))
{
const TCPHDR *tcp = (TCPHDR *) (data + sizeof (ETH_HEADER) + hlen);
DEBUGP ((" "));
PrIP (ip->saddr);
DEBUGP ((":%d", ntohs (tcp->source)));
DEBUGP ((" -> "));
PrIP (ip->daddr);
DEBUGP ((":%d", ntohs (tcp->dest)));
did = TRUE;
}
// UDP packet?
else if ((ntohs (ip->frag_off) & IP_OFFMASK) == 0
&& ip->protocol == IPPROTO_UDP
&& blen - hlen >= (sizeof (UDPHDR)))
{
const UDPHDR *udp = (UDPHDR *) (data + sizeof (ETH_HEADER) + hlen);
// DHCP packet?
if ((udp->dest == htons (BOOTPC_PORT) || udp->dest == htons (BOOTPS_PORT))
&& blen - hlen >= (sizeof (UDPHDR) + sizeof (DHCP)))
{
const DHCP *dhcp = (DHCP *) (data
+ hlen
+ sizeof (ETH_HEADER)
+ sizeof (UDPHDR));
int optlen = len
- sizeof (ETH_HEADER)
- hlen
- sizeof (UDPHDR)
- sizeof (DHCP);
if (optlen < 0)
optlen = 0;
DumpDHCP (eth, ip, udp, dhcp, optlen);
did = TRUE;
}
if (!did)
{
DEBUGP ((" "));
PrIP (ip->saddr);
DEBUGP ((":%d", ntohs (udp->source)));
DEBUGP ((" -> "));
PrIP (ip->daddr);
DEBUGP ((":%d", ntohs (udp->dest)));
did = TRUE;
}
}
if (!did)
{
DEBUGP ((" ipproto=%d ", ip->protocol));
PrIP (ip->saddr);
DEBUGP ((" -> "));
PrIP (ip->daddr);
}
DEBUGP (("\n"));
return;
}
{
DEBUGP (("%s ??? src=", prefix));
PrMac (eth->src);
DEBUGP ((" dest="));
PrMac (eth->dest);
DEBUGP ((" proto=0x%04x len=%d\n",
(int) ntohs(eth->proto),
len));
}
}
#endif // ALLOW_PACKET_DUMP
#endif

114
windows/TapDriver6/error.h Normal file
View File

@ -0,0 +1,114 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//-----------------
// DEBUGGING OUTPUT
//-----------------
extern const char *g_LastErrorFilename;
extern int g_LastErrorLineNumber;
// Debug info output
#define ALSO_DBGPRINT 1
#define DEBUGP_AT_DISPATCH 1
// Uncomment line below to allow packet dumps
//#define ALLOW_PACKET_DUMP 1
#define NOTE_ERROR() \
{ \
g_LastErrorFilename = __FILE__; \
g_LastErrorLineNumber = __LINE__; \
}
#if DBG
typedef struct
{
unsigned int in;
unsigned int out;
unsigned int capacity;
char *text;
BOOLEAN error;
MUTEX lock;
} DebugOutput;
VOID MyDebugPrint (const unsigned char* format, ...);
VOID PrMac (const MACADDR mac);
VOID PrIP (IPADDR ip_addr);
#ifdef ALLOW_PACKET_DUMP
VOID
DumpPacket(
__in const char *prefix,
__in const unsigned char *data,
__in unsigned int len
);
DumpPacket2(
__in const char *prefix,
__in const ETH_HEADER *eth,
__in const unsigned char *data,
__in unsigned int len
);
#else
#define DUMP_PACKET(prefix, data, len)
#define DUMP_PACKET2(prefix, eth, data, len)
#endif
#define CAN_WE_PRINT (DEBUGP_AT_DISPATCH || KeGetCurrentIrql () < DISPATCH_LEVEL)
#if ALSO_DBGPRINT
#define DEBUGP(fmt) { MyDebugPrint fmt; if (CAN_WE_PRINT) DbgPrint fmt; }
#else
#define DEBUGP(fmt) { MyDebugPrint fmt; }
#endif
#ifdef ALLOW_PACKET_DUMP
#define DUMP_PACKET(prefix, data, len) \
DumpPacket (prefix, data, len)
#define DUMP_PACKET2(prefix, eth, data, len) \
DumpPacket2 (prefix, eth, data, len)
#endif
BOOLEAN
GetDebugLine (
__in char *buf,
__in const int len
);
#else
#define DEBUGP(fmt)
#define DUMP_PACKET(prefix, data, len)
#define DUMP_PACKET2(prefix, eth, data, len)
#endif

View File

@ -0,0 +1,63 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef HEXDUMP_DEFINED
#define HEXDUMP_DEFINED
#ifdef __cplusplus
extern "C" {
#endif
//=====================================================================================
// Debug Routines
//=====================================================================================
#ifndef NDIS_MINIPORT_DRIVER
# include <stdio.h>
# include <ctype.h>
# include <windows.h>
# include <winnt.h>
# include <memory.h>
# ifndef DEBUGP
# define DEBUGP(fmt) { DbgMessage fmt; }
# endif
extern VOID (*DbgMessage)(char *p_Format, ...);
VOID DisplayDebugString (char *p_Format, ...);
#endif
//===================================================================================
// Reporting / Debugging
//===================================================================================
#define IfPrint(c) (c >= 32 && c < 127 ? c : '.')
VOID HexDump (unsigned char *p_Buffer, unsigned long p_Size);
#ifdef __cplusplus
}
#endif
#endif

75
windows/TapDriver6/lock.h Normal file
View File

@ -0,0 +1,75 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
typedef struct
{
volatile long count;
} MUTEX;
#define MUTEX_SLEEP_TIME 10000 // microseconds
#define INIT_MUTEX(m) { (m)->count = 0; }
#define ACQUIRE_MUTEX_BLOCKING(m) \
{ \
while (NdisInterlockedIncrement (&((m)->count)) != 1) \
{ \
NdisInterlockedDecrement(&((m)->count)); \
NdisMSleep(MUTEX_SLEEP_TIME); \
} \
}
#define RELEASE_MUTEX(m) \
{ \
NdisInterlockedDecrement(&((m)->count)); \
}
#define ACQUIRE_MUTEX_NONBLOCKING(m, result) \
{ \
if (NdisInterlockedIncrement (&((m)->count)) != 1) \
{ \
NdisInterlockedDecrement(&((m)->count)); \
result = FALSE; \
} \
else \
{ \
result = TRUE; \
} \
}
#define ACQUIRE_MUTEX_ADAPTIVE(m, result) \
{ \
result = TRUE; \
while (NdisInterlockedIncrement (&((m)->count)) != 1) \
{ \
NdisInterlockedDecrement(&((m)->count)); \
if (KeGetCurrentIrql () < DISPATCH_LEVEL) \
NdisMSleep(MUTEX_SLEEP_TIME); \
else \
{ \
result = FALSE; \
break; \
} \
} \
}

View File

@ -0,0 +1,164 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "tap.h"
int
HexStringToDecimalInt (const int p_Character)
{
int l_Value = 0;
if (p_Character >= 'A' && p_Character <= 'F')
l_Value = (p_Character - 'A') + 10;
else if (p_Character >= 'a' && p_Character <= 'f')
l_Value = (p_Character - 'a') + 10;
else if (p_Character >= '0' && p_Character <= '9')
l_Value = p_Character - '0';
return l_Value;
}
BOOLEAN
ParseMAC (MACADDR dest, const char *src)
{
int c;
int mac_index = 0;
BOOLEAN high_digit = FALSE;
int delim_action = 1;
ASSERT (src);
ASSERT (dest);
CLEAR_MAC (dest);
while (c = *src++)
{
if (IsMacDelimiter (c))
{
mac_index += delim_action;
high_digit = FALSE;
delim_action = 1;
}
else if (IsHexDigit (c))
{
const int digit = HexStringToDecimalInt (c);
if (mac_index < sizeof (MACADDR))
{
if (!high_digit)
{
dest[mac_index] = (char)(digit);
high_digit = TRUE;
delim_action = 1;
}
else
{
dest[mac_index] = (char)(dest[mac_index] * 16 + digit);
++mac_index;
high_digit = FALSE;
delim_action = 0;
}
}
else
return FALSE;
}
else
return FALSE;
}
return (mac_index + delim_action) >= sizeof (MACADDR);
}
/*
* Generate a MAC using the GUID in the adapter name.
*
* The mac is constructed as 00:FF:xx:xx:xx:xx where
* the Xs are taken from the first 32 bits of the GUID in the
* adapter name. This is similar to the Linux 2.4 tap MAC
* generator, except linux uses 32 random bits for the Xs.
*
* In general, this solution is reasonable for most
* applications except for very large bridged TAP networks,
* where the probability of address collisions becomes more
* than infintesimal.
*
* Using the well-known "birthday paradox", on a 1000 node
* network the probability of collision would be
* 0.000116292153. On a 10,000 node network, the probability
* of collision would be 0.01157288998621678766.
*/
VOID
GenerateRandomMac(
__in MACADDR mac,
__in const unsigned char *adapter_name
)
{
unsigned const char *cp = adapter_name;
unsigned char c;
unsigned int i = 2;
unsigned int byte = 0;
int brace = 0;
int state = 0;
CLEAR_MAC (mac);
mac[0] = 0x00;
mac[1] = 0xFF;
while (c = *cp++)
{
if (i >= sizeof (MACADDR))
break;
if (c == '{')
brace = 1;
if (IsHexDigit (c) && brace)
{
const unsigned int digit = HexStringToDecimalInt (c);
if (state)
{
byte <<= 4;
byte |= digit;
mac[i++] = (unsigned char) byte;
state = 0;
}
else
{
byte = digit;
state = 1;
}
}
}
}
VOID
GenerateRelatedMAC(
__in MACADDR dest,
__in const MACADDR src,
__in const int delta
)
{
ETH_COPY_NETWORK_ADDRESS (dest, src);
dest[2] += (UCHAR) delta;
}

View File

@ -0,0 +1,53 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef MacInfoDefined
#define MacInfoDefined
//===================================================================================
// Macros
//===================================================================================
#define IsMacDelimiter(a) (a == ':' || a == '-' || a == '.')
#define IsHexDigit(c) ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))
#define CLEAR_MAC(dest) NdisZeroMemory ((dest), sizeof (MACADDR))
#define MAC_EQUAL(a,b) (memcmp ((a), (b), sizeof (MACADDR)) == 0)
BOOLEAN
ParseMAC (MACADDR dest, const char *src);
VOID
GenerateRandomMac(
__in MACADDR mac,
__in const unsigned char *adapter_name
);
VOID
GenerateRelatedMAC(
__in MACADDR dest,
__in const MACADDR src,
__in const int delta
);
#endif

401
windows/TapDriver6/mem.c Normal file
View File

@ -0,0 +1,401 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//------------------
// Memory Management
//------------------
#include "tap.h"
PVOID
MemAlloc(
__in ULONG p_Size,
__in BOOLEAN zero
)
{
PVOID l_Return = NULL;
if (p_Size)
{
__try
{
if (NdisAllocateMemoryWithTag (&l_Return, p_Size, 'APAT')
== NDIS_STATUS_SUCCESS)
{
if (zero)
{
NdisZeroMemory (l_Return, p_Size);
}
}
else
{
l_Return = NULL;
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
l_Return = NULL;
}
}
return l_Return;
}
VOID
MemFree(
__in PVOID p_Addr,
__in ULONG p_Size
)
{
if (p_Addr && p_Size)
{
__try
{
#if DBG
NdisZeroMemory (p_Addr, p_Size);
#endif
NdisFreeMemory (p_Addr, p_Size, 0);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
}
}
}
//======================================================================
// TAP Packet Queue Support
//======================================================================
VOID
tapPacketQueueInsertTail(
__in PTAP_PACKET_QUEUE TapPacketQueue,
__in PTAP_PACKET TapPacket
)
{
KIRQL irql;
KeAcquireSpinLock(&TapPacketQueue->QueueLock,&irql);
InsertTailList(&TapPacketQueue->Queue,&TapPacket->QueueLink);
// BUGBUG!!! Enforce PACKET_QUEUE_SIZE queue count limit???
// For NDIS 6 there is no per-packet status, so this will need to
// be handled on per-NBL basis in AdapterSendNetBufferLists...
// Update counts
++TapPacketQueue->Count;
if(TapPacketQueue->Count > TapPacketQueue->MaxCount)
{
TapPacketQueue->MaxCount = TapPacketQueue->Count;
DEBUGP (("[TAP] tapPacketQueueInsertTail: New MAX queued packet count = %d\n",
TapPacketQueue->MaxCount));
}
KeReleaseSpinLock(&TapPacketQueue->QueueLock,irql);
}
// Call with QueueLock held
PTAP_PACKET
tapPacketRemoveHeadLocked(
__in PTAP_PACKET_QUEUE TapPacketQueue
)
{
PTAP_PACKET tapPacket = NULL;
PLIST_ENTRY listEntry;
listEntry = RemoveHeadList(&TapPacketQueue->Queue);
if(listEntry != &TapPacketQueue->Queue)
{
tapPacket = CONTAINING_RECORD(listEntry, TAP_PACKET, QueueLink);
// Update counts
--TapPacketQueue->Count;
}
return tapPacket;
}
PTAP_PACKET
tapPacketRemoveHead(
__in PTAP_PACKET_QUEUE TapPacketQueue
)
{
PTAP_PACKET tapPacket = NULL;
KIRQL irql;
KeAcquireSpinLock(&TapPacketQueue->QueueLock,&irql);
tapPacket = tapPacketRemoveHeadLocked(TapPacketQueue);
KeReleaseSpinLock(&TapPacketQueue->QueueLock,irql);
return tapPacket;
}
VOID
tapPacketQueueInitialize(
__in PTAP_PACKET_QUEUE TapPacketQueue
)
{
KeInitializeSpinLock(&TapPacketQueue->QueueLock);
NdisInitializeListHead(&TapPacketQueue->Queue);
}
//======================================================================
// TAP Cancel-Safe Queue Support
//======================================================================
VOID
tapIrpCsqInsert (
__in struct _IO_CSQ *Csq,
__in PIRP Irp
)
{
PTAP_IRP_CSQ tapIrpCsq;
tapIrpCsq = (PTAP_IRP_CSQ )Csq;
InsertTailList(
&tapIrpCsq->Queue,
&Irp->Tail.Overlay.ListEntry
);
// Update counts
++tapIrpCsq->Count;
if(tapIrpCsq->Count > tapIrpCsq->MaxCount)
{
tapIrpCsq->MaxCount = tapIrpCsq->Count;
DEBUGP (("[TAP] tapIrpCsqInsert: New MAX queued IRP count = %d\n",
tapIrpCsq->MaxCount));
}
}
VOID
tapIrpCsqRemoveIrp(
__in PIO_CSQ Csq,
__in PIRP Irp
)
{
PTAP_IRP_CSQ tapIrpCsq;
tapIrpCsq = (PTAP_IRP_CSQ )Csq;
// Update counts
--tapIrpCsq->Count;
RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
}
PIRP
tapIrpCsqPeekNextIrp(
__in PIO_CSQ Csq,
__in PIRP Irp,
__in PVOID PeekContext
)
{
PTAP_IRP_CSQ tapIrpCsq;
PIRP nextIrp = NULL;
PLIST_ENTRY nextEntry;
PLIST_ENTRY listHead;
PIO_STACK_LOCATION irpStack;
tapIrpCsq = (PTAP_IRP_CSQ )Csq;
listHead = &tapIrpCsq->Queue;
//
// If the IRP is NULL, we will start peeking from the listhead, else
// we will start from that IRP onwards. This is done under the
// assumption that new IRPs are always inserted at the tail.
//
if (Irp == NULL)
{
nextEntry = listHead->Flink;
}
else
{
nextEntry = Irp->Tail.Overlay.ListEntry.Flink;
}
while(nextEntry != listHead)
{
nextIrp = CONTAINING_RECORD(nextEntry, IRP, Tail.Overlay.ListEntry);
irpStack = IoGetCurrentIrpStackLocation(nextIrp);
//
// If context is present, continue until you find a matching one.
// Else you break out as you got next one.
//
if (PeekContext)
{
if (irpStack->FileObject == (PFILE_OBJECT) PeekContext)
{
break;
}
}
else
{
break;
}
nextIrp = NULL;
nextEntry = nextEntry->Flink;
}
return nextIrp;
}
//
// tapIrpCsqAcquireQueueLock modifies the execution level of the current processor.
//
// KeAcquireSpinLock raises the execution level to Dispatch Level and stores
// the current execution level in the Irql parameter to be restored at a later
// time. KeAcqurieSpinLock also requires us to be running at no higher than
// Dispatch level when it is called.
//
// The annotations reflect these changes and requirments.
//
__drv_raisesIRQL(DISPATCH_LEVEL)
__drv_maxIRQL(DISPATCH_LEVEL)
VOID
tapIrpCsqAcquireQueueLock(
__in PIO_CSQ Csq,
__out PKIRQL Irql
)
{
PTAP_IRP_CSQ tapIrpCsq;
tapIrpCsq = (PTAP_IRP_CSQ )Csq;
//
// Suppressing because the address below csq is valid since it's
// part of TAP_ADAPTER_CONTEXT structure.
//
#pragma prefast(suppress: __WARNING_BUFFER_UNDERFLOW, "Underflow using expression 'adapter->PendingReadCsqQueueLock'")
KeAcquireSpinLock(&tapIrpCsq->QueueLock, Irql);
}
//
// tapIrpCsqReleaseQueueLock modifies the execution level of the current processor.
//
// KeReleaseSpinLock assumes we already hold the spin lock and are therefore
// running at Dispatch level. It will use the Irql parameter saved in a
// previous call to KeAcquireSpinLock to return the thread back to it's original
// execution level.
//
// The annotations reflect these changes and requirments.
//
__drv_requiresIRQL(DISPATCH_LEVEL)
VOID
tapIrpCsqReleaseQueueLock(
__in PIO_CSQ Csq,
__in KIRQL Irql
)
{
PTAP_IRP_CSQ tapIrpCsq;
tapIrpCsq = (PTAP_IRP_CSQ )Csq;
//
// Suppressing because the address below csq is valid since it's
// part of TAP_ADAPTER_CONTEXT structure.
//
#pragma prefast(suppress: __WARNING_BUFFER_UNDERFLOW, "Underflow using expression 'adapter->PendingReadCsqQueueLock'")
KeReleaseSpinLock(&tapIrpCsq->QueueLock, Irql);
}
VOID
tapIrpCsqCompleteCanceledIrp(
__in PIO_CSQ pCsq,
__in PIRP Irp
)
{
UNREFERENCED_PARAMETER(pCsq);
Irp->IoStatus.Status = STATUS_CANCELLED;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
}
VOID
tapIrpCsqInitialize(
__in PTAP_IRP_CSQ TapIrpCsq
)
{
KeInitializeSpinLock(&TapIrpCsq->QueueLock);
NdisInitializeListHead(&TapIrpCsq->Queue);
IoCsqInitialize(
&TapIrpCsq->CsqQueue,
tapIrpCsqInsert,
tapIrpCsqRemoveIrp,
tapIrpCsqPeekNextIrp,
tapIrpCsqAcquireQueueLock,
tapIrpCsqReleaseQueueLock,
tapIrpCsqCompleteCanceledIrp
);
}
VOID
tapIrpCsqFlush(
__in PTAP_IRP_CSQ TapIrpCsq
)
{
PIRP pendingIrp;
//
// Flush the pending read IRP queue.
//
pendingIrp = IoCsqRemoveNextIrp(
&TapIrpCsq->CsqQueue,
NULL
);
while(pendingIrp)
{
// Cancel the IRP
pendingIrp->IoStatus.Information = 0;
pendingIrp->IoStatus.Status = STATUS_CANCELLED;
IoCompleteRequest(pendingIrp, IO_NO_INCREMENT);
pendingIrp = IoCsqRemoveNextIrp(
&TapIrpCsq->CsqQueue,
NULL
);
}
ASSERT(IsListEmpty(&TapIrpCsq->Queue));
}

113
windows/TapDriver6/mem.h Normal file
View File

@ -0,0 +1,113 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//------------------
// Memory Management
//------------------
PVOID
MemAlloc(
__in ULONG p_Size,
__in BOOLEAN zero
);
VOID
MemFree(
__in PVOID p_Addr,
__in ULONG p_Size
);
//======================================================================
// TAP Packet Queue
//======================================================================
typedef
struct _TAP_PACKET
{
LIST_ENTRY QueueLink;
# define TAP_PACKET_SIZE(data_size) (sizeof (TAP_PACKET) + (data_size))
# define TP_TUN 0x80000000
# define TP_SIZE_MASK (~TP_TUN)
ULONG m_SizeFlags;
// m_Data must be the last struct member
UCHAR m_Data [];
} TAP_PACKET, *PTAP_PACKET;
#define TAP_PACKET_TAG '6PAT' // "TAP6"
typedef struct _TAP_PACKET_QUEUE
{
KSPIN_LOCK QueueLock;
LIST_ENTRY Queue;
ULONG Count; // Count of currently queued items
ULONG MaxCount;
} TAP_PACKET_QUEUE, *PTAP_PACKET_QUEUE;
VOID
tapPacketQueueInsertTail(
__in PTAP_PACKET_QUEUE TapPacketQueue,
__in PTAP_PACKET TapPacket
);
// Call with QueueLock held
PTAP_PACKET
tapPacketRemoveHeadLocked(
__in PTAP_PACKET_QUEUE TapPacketQueue
);
PTAP_PACKET
tapPacketRemoveHead(
__in PTAP_PACKET_QUEUE TapPacketQueue
);
VOID
tapPacketQueueInitialize(
__in PTAP_PACKET_QUEUE TapPacketQueue
);
//----------------------
// Cancel-Safe IRP Queue
//----------------------
typedef struct _TAP_IRP_CSQ
{
IO_CSQ CsqQueue;
KSPIN_LOCK QueueLock;
LIST_ENTRY Queue;
ULONG Count; // Count of currently queued items
ULONG MaxCount;
} TAP_IRP_CSQ, *PTAP_IRP_CSQ;
VOID
tapIrpCsqInitialize(
__in PTAP_IRP_CSQ TapIrpCsq
);
VOID
tapIrpCsqFlush(
__in PTAP_IRP_CSQ TapIrpCsq
);

File diff suppressed because it is too large Load Diff

224
windows/TapDriver6/proto.h Normal file
View File

@ -0,0 +1,224 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//============================================================
// MAC address, Ethernet header, and ARP
//============================================================
#pragma pack(1)
#define IP_HEADER_SIZE 20
#define IPV6_HEADER_SIZE 40
#define MACADDR_SIZE 6
typedef unsigned char MACADDR[MACADDR_SIZE];
typedef unsigned long IPADDR;
typedef unsigned char IPV6ADDR[16];
//-----------------
// Ethernet address
//-----------------
typedef struct {
MACADDR addr;
} ETH_ADDR;
typedef struct {
ETH_ADDR list[TAP_MAX_MCAST_LIST];
} MC_LIST;
// BUGBUG!!! Consider using ststem defines in netiodef.h!!!
//----------------
// Ethernet header
//----------------
typedef struct
{
MACADDR dest; /* destination eth addr */
MACADDR src; /* source ether addr */
USHORT proto; /* packet type ID field */
} ETH_HEADER, *PETH_HEADER;
//----------------
// ARP packet
//----------------
typedef struct
{
MACADDR m_MAC_Destination; // Reverse these two
MACADDR m_MAC_Source; // to answer ARP requests
USHORT m_Proto; // 0x0806
# define MAC_ADDR_TYPE 0x0001
USHORT m_MAC_AddressType; // 0x0001
USHORT m_PROTO_AddressType; // 0x0800
UCHAR m_MAC_AddressSize; // 0x06
UCHAR m_PROTO_AddressSize; // 0x04
# define ARP_REQUEST 0x0001
# define ARP_REPLY 0x0002
USHORT m_ARP_Operation; // 0x0001 for ARP request, 0x0002 for ARP reply
MACADDR m_ARP_MAC_Source;
IPADDR m_ARP_IP_Source;
MACADDR m_ARP_MAC_Destination;
IPADDR m_ARP_IP_Destination;
}
ARP_PACKET, *PARP_PACKET;
//----------
// IP Header
//----------
typedef struct {
# define IPH_GET_VER(v) (((v) >> 4) & 0x0F)
# define IPH_GET_LEN(v) (((v) & 0x0F) << 2)
UCHAR version_len;
UCHAR tos;
USHORT tot_len;
USHORT id;
# define IP_OFFMASK 0x1fff
USHORT frag_off;
UCHAR ttl;
# define IPPROTO_UDP 17 /* UDP protocol */
# define IPPROTO_TCP 6 /* TCP protocol */
# define IPPROTO_ICMP 1 /* ICMP protocol */
# define IPPROTO_IGMP 2 /* IGMP protocol */
UCHAR protocol;
USHORT check;
ULONG saddr;
ULONG daddr;
/* The options start here. */
} IPHDR;
//-----------
// UDP header
//-----------
typedef struct {
USHORT source;
USHORT dest;
USHORT len;
USHORT check;
} UDPHDR;
//--------------------------
// TCP header, per RFC 793.
//--------------------------
typedef struct {
USHORT source; /* source port */
USHORT dest; /* destination port */
ULONG seq; /* sequence number */
ULONG ack_seq; /* acknowledgement number */
# define TCPH_GET_DOFF(d) (((d) & 0xF0) >> 2)
UCHAR doff_res;
# define TCPH_FIN_MASK (1<<0)
# define TCPH_SYN_MASK (1<<1)
# define TCPH_RST_MASK (1<<2)
# define TCPH_PSH_MASK (1<<3)
# define TCPH_ACK_MASK (1<<4)
# define TCPH_URG_MASK (1<<5)
# define TCPH_ECE_MASK (1<<6)
# define TCPH_CWR_MASK (1<<7)
UCHAR flags;
USHORT window;
USHORT check;
USHORT urg_ptr;
} TCPHDR;
#define TCPOPT_EOL 0
#define TCPOPT_NOP 1
#define TCPOPT_MAXSEG 2
#define TCPOLEN_MAXSEG 4
//------------
// IPv6 Header
//------------
typedef struct {
UCHAR version_prio;
UCHAR flow_lbl[3];
USHORT payload_len;
# define IPPROTO_ICMPV6 0x3a /* ICMP protocol v6 */
UCHAR nexthdr;
UCHAR hop_limit;
IPV6ADDR saddr;
IPV6ADDR daddr;
} IPV6HDR;
//--------------------------------------------
// IPCMPv6 NS/NA Packets (RFC4443 and RFC4861)
//--------------------------------------------
// Neighbor Solictiation - RFC 4861, 4.3
// (this is just the ICMPv6 part of the packet)
typedef struct {
UCHAR type;
# define ICMPV6_TYPE_NS 135 // neighbour solicitation
UCHAR code;
# define ICMPV6_CODE_0 0 // no specific sub-code for NS/NA
USHORT checksum;
ULONG reserved;
IPV6ADDR target_addr;
} ICMPV6_NS;
// Neighbor Advertisement - RFC 4861, 4.4 + 4.6/4.6.1
// (this is just the ICMPv6 payload)
typedef struct {
UCHAR type;
# define ICMPV6_TYPE_NA 136 // neighbour advertisement
UCHAR code;
# define ICMPV6_CODE_0 0 // no specific sub-code for NS/NA
USHORT checksum;
UCHAR rso_bits; // Router(0), Solicited(2), Ovrrd(4)
UCHAR reserved[3];
IPV6ADDR target_addr;
// always include "Target Link-layer Address" option (RFC 4861 4.6.1)
UCHAR opt_type;
#define ICMPV6_OPTION_TLLA 2
UCHAR opt_length;
#define ICMPV6_LENGTH_TLLA 1 // multiplied by 8 -> 1 = 8 bytes
MACADDR target_macaddr;
} ICMPV6_NA;
// this is the complete packet with Ethernet and IPv6 headers
typedef struct {
ETH_HEADER eth;
IPV6HDR ipv6;
ICMPV6_NA icmpv6;
} ICMPV6_NA_PKT;
#pragma pack()

View File

@ -0,0 +1,91 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef TAP_PROTOTYPES_DEFINED
#define TAP_PROTOTYPES_DEFINED
DRIVER_INITIALIZE DriverEntry;
//VOID AdapterFreeResources
// (
// TapAdapterPointer p_Adapter
// );
//
//
//NTSTATUS TapDeviceHook
// (
// IN PDEVICE_OBJECT p_DeviceObject,
// IN PIRP p_IRP
// );
//
NDIS_STATUS
CreateTapDevice(
__in PTAP_ADAPTER_CONTEXT Adapter
);
VOID
DestroyTapDevice(
__in PTAP_ADAPTER_CONTEXT Adapter
);
// Flush the pending send TAP packet queue.
VOID
tapFlushSendPacketQueue(
__in PTAP_ADAPTER_CONTEXT Adapter
);
VOID
IndicateReceivePacket(
__in PTAP_ADAPTER_CONTEXT Adapter,
__in PUCHAR packetData,
__in const unsigned int packetLength
);
/*
BOOLEAN
ProcessDHCP(
__in PTAP_ADAPTER_CONTEXT Adapter,
__in const ETH_HEADER *eth,
__in const IPHDR *ip,
__in const UDPHDR *udp,
__in const DHCP *dhcp,
__in int optlen
);
*/
/*
BOOLEAN
ProcessARP(
__in PTAP_ADAPTER_CONTEXT Adapter,
__in const PARP_PACKET src,
__in const IPADDR adapter_ip,
__in const IPADDR ip_network,
__in const IPADDR ip_netmask,
__in const MACADDR mac
);
*/
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,88 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,0,0,0
PRODUCTVERSION 3,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x9L
#else
FILEFLAGS 0x8L
#endif
FILEOS 0x40004L
FILETYPE 0x3L
FILESUBTYPE 0x6L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "ZeroTier Networks LLC"
VALUE "FileDescription", "ZeroTier One Virtual Network Port"
VALUE "FileVersion", "3.0.0 3/0"
VALUE "InternalName", "zttap300.sys"
VALUE "LegalCopyright", "ZeroTier, Inc., OpenVPN Technologies, Inc."
VALUE "OriginalFilename", "zttap300.sys"
VALUE "ProductName", "ZeroTier One Virtual Network Port"
VALUE "ProductVersion", "3.0.0 3/0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

669
windows/TapDriver6/rxpath.c Normal file
View File

@ -0,0 +1,669 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//
// Include files.
//
#include "tap.h"
//======================================================================
// TAP Receive Path Support
//======================================================================
#ifdef ALLOC_PRAGMA
#pragma alloc_text( PAGE, TapDeviceWrite)
#endif // ALLOC_PRAGMA
//===============================================================
// Used in cases where internally generated packets such as
// ARP or DHCP replies must be returned to the kernel, to be
// seen as an incoming packet "arriving" on the interface.
//===============================================================
VOID
IndicateReceivePacket(
__in PTAP_ADAPTER_CONTEXT Adapter,
__in PUCHAR packetData,
__in const unsigned int packetLength
)
{
PUCHAR injectBuffer;
//
// Handle miniport Pause
// ---------------------
// NDIS 6 miniports implement a temporary "Pause" state normally followed
// by the Restart. While in the Pause state it is forbidden for the miniport
// to indicate receive NBLs.
//
// That is: The device interface may be "up", but the NDIS miniport send/receive
// interface may be temporarily "down".
//
// BUGBUG!!! In the initial implementation of the NDIS 6 TapOas inject path
// the code below will simply ignore inject packets passed to the driver while
// the miniport is in the Paused state.
//
// The correct implementation is to go ahead and build the NBLs corresponding
// to the inject packet - but queue them. When Restart is entered the
// queued NBLs would be dequeued and indicated to the host.
//
if(tapAdapterSendAndReceiveReady(Adapter) != NDIS_STATUS_SUCCESS)
{
DEBUGP (("[%s] Lying send in IndicateReceivePacket while adapter paused\n",
MINIPORT_INSTANCE_ID (Adapter)));
return;
}
// Allocate flat buffer for packet data.
injectBuffer = (PUCHAR )NdisAllocateMemoryWithTagPriority(
Adapter->MiniportAdapterHandle,
packetLength,
TAP_RX_INJECT_BUFFER_TAG,
NormalPoolPriority
);
if( injectBuffer)
{
PMDL mdl;
// Copy packet data to flat buffer.
NdisMoveMemory (injectBuffer, packetData, packetLength);
// Allocate MDL for flat buffer.
mdl = NdisAllocateMdl(
Adapter->MiniportAdapterHandle,
injectBuffer,
packetLength
);
if( mdl )
{
PNET_BUFFER_LIST netBufferList;
mdl->Next = NULL; // No next MDL
// Allocate the NBL and NB. Link MDL chain to NB.
netBufferList = NdisAllocateNetBufferAndNetBufferList(
Adapter->ReceiveNblPool,
0, // ContextSize
0, // ContextBackFill
mdl, // MDL chain
0,
packetLength
);
if(netBufferList != NULL)
{
ULONG receiveFlags = 0;
LONG nblCount;
NET_BUFFER_LIST_NEXT_NBL(netBufferList) = NULL; // Only one NBL
if(KeGetCurrentIrql() == DISPATCH_LEVEL)
{
receiveFlags |= NDIS_RECEIVE_FLAGS_DISPATCH_LEVEL;
}
// Set flag indicating that this is an injected packet
TAP_RX_NBL_FLAGS_CLEAR_ALL(netBufferList);
TAP_RX_NBL_FLAG_SET(netBufferList,TAP_RX_NBL_FLAGS_IS_INJECTED);
netBufferList->MiniportReserved[0] = NULL;
netBufferList->MiniportReserved[1] = NULL;
// Increment in-flight receive NBL count.
nblCount = NdisInterlockedIncrement(&Adapter->ReceiveNblInFlightCount);
ASSERT(nblCount > 0 );
netBufferList->SourceHandle = Adapter->MiniportAdapterHandle;
//
// Indicate the packet
// -------------------
// Irp->AssociatedIrp.SystemBuffer with length irpSp->Parameters.Write.Length
// contains the complete packet including Ethernet header and payload.
//
NdisMIndicateReceiveNetBufferLists(
Adapter->MiniportAdapterHandle,
netBufferList,
NDIS_DEFAULT_PORT_NUMBER,
1, // NumberOfNetBufferLists
receiveFlags
);
return;
}
else
{
DEBUGP (("[%s] NdisAllocateNetBufferAndNetBufferList failed in IndicateReceivePacket\n",
MINIPORT_INSTANCE_ID (Adapter)));
NOTE_ERROR ();
NdisFreeMdl(mdl);
NdisFreeMemory(injectBuffer,0,0);
}
}
else
{
DEBUGP (("[%s] NdisAllocateMdl failed in IndicateReceivePacket\n",
MINIPORT_INSTANCE_ID (Adapter)));
NOTE_ERROR ();
NdisFreeMemory(injectBuffer,0,0);
}
}
else
{
DEBUGP (("[%s] NdisAllocateMemoryWithTagPriority failed in IndicateReceivePacket\n",
MINIPORT_INSTANCE_ID (Adapter)));
NOTE_ERROR ();
}
}
VOID
tapCompleteIrpAndFreeReceiveNetBufferList(
__in PTAP_ADAPTER_CONTEXT Adapter,
__in PNET_BUFFER_LIST NetBufferList, // Only one NB here...
__in NTSTATUS IoCompletionStatus
)
{
PIRP irp;
ULONG frameType, netBufferCount, byteCount;
LONG nblCount;
// Fetch NB frame type.
frameType = tapGetNetBufferFrameType(NET_BUFFER_LIST_FIRST_NB(NetBufferList));
// Fetch statistics for all NBs linked to the NB.
netBufferCount = tapGetNetBufferCountsFromNetBufferList(
NetBufferList,
&byteCount
);
// Update statistics by frame type
if(IoCompletionStatus == STATUS_SUCCESS)
{
switch(frameType)
{
case NDIS_PACKET_TYPE_DIRECTED:
Adapter->FramesRxDirected += netBufferCount;
Adapter->BytesRxDirected += byteCount;
break;
case NDIS_PACKET_TYPE_BROADCAST:
Adapter->FramesRxBroadcast += netBufferCount;
Adapter->BytesRxBroadcast += byteCount;
break;
case NDIS_PACKET_TYPE_MULTICAST:
Adapter->FramesRxMulticast += netBufferCount;
Adapter->BytesRxMulticast += byteCount;
break;
default:
ASSERT(FALSE);
break;
}
}
//
// Handle P2P Packet
// -----------------
// Free MDL allocated for P2P Ethernet header.
//
if(TAP_RX_NBL_FLAG_TEST(NetBufferList,TAP_RX_NBL_FLAGS_IS_P2P))
{
PNET_BUFFER netBuffer;
PMDL mdl;
netBuffer = NET_BUFFER_LIST_FIRST_NB(NetBufferList);
mdl = NET_BUFFER_FIRST_MDL(netBuffer);
mdl->Next = NULL;
NdisFreeMdl(mdl);
}
//
// Handle Injected Packet
// -----------------------
// Free MDL and data buffer allocated for injected packet.
//
if(TAP_RX_NBL_FLAG_TEST(NetBufferList,TAP_RX_NBL_FLAGS_IS_INJECTED))
{
PNET_BUFFER netBuffer;
PMDL mdl;
PUCHAR injectBuffer;
netBuffer = NET_BUFFER_LIST_FIRST_NB(NetBufferList);
mdl = NET_BUFFER_FIRST_MDL(netBuffer);
injectBuffer = (PUCHAR )MmGetSystemAddressForMdlSafe(mdl,NormalPagePriority);
if(injectBuffer)
{
NdisFreeMemory(injectBuffer,0,0);
}
NdisFreeMdl(mdl);
}
//
// Complete the IRP
//
irp = (PIRP )NetBufferList->MiniportReserved[0];
if(irp)
{
irp->IoStatus.Status = IoCompletionStatus;
IoCompleteRequest(irp, IO_NO_INCREMENT);
}
// Decrement in-flight receive NBL count.
nblCount = NdisInterlockedDecrement(&Adapter->ReceiveNblInFlightCount);
ASSERT(nblCount >= 0 );
if (0 == nblCount)
{
NdisSetEvent(&Adapter->ReceiveNblInFlightCountZeroEvent);
}
// Free the NBL
NdisFreeNetBufferList(NetBufferList);
}
VOID
AdapterReturnNetBufferLists(
__in NDIS_HANDLE MiniportAdapterContext,
__in PNET_BUFFER_LIST NetBufferLists,
__in ULONG ReturnFlags
)
{
PTAP_ADAPTER_CONTEXT adapter = (PTAP_ADAPTER_CONTEXT )MiniportAdapterContext;
PNET_BUFFER_LIST currentNbl, nextNbl;
UNREFERENCED_PARAMETER(ReturnFlags);
//
// Process each NBL individually
//
currentNbl = NetBufferLists;
while (currentNbl)
{
PNET_BUFFER_LIST nextNbl;
nextNbl = NET_BUFFER_LIST_NEXT_NBL(currentNbl);
NET_BUFFER_LIST_NEXT_NBL(currentNbl) = NULL;
// Complete write IRP and free NBL and associated resources.
tapCompleteIrpAndFreeReceiveNetBufferList(
adapter,
currentNbl,
STATUS_SUCCESS
);
// Move to next NBL
currentNbl = nextNbl;
}
}
// IRP_MJ_WRITE callback.
NTSTATUS
TapDeviceWrite(
PDEVICE_OBJECT DeviceObject,
PIRP Irp
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;// Assume success
PIO_STACK_LOCATION irpSp;// Pointer to current stack location
PTAP_ADAPTER_CONTEXT adapter = NULL;
ULONG dataLength;
PAGED_CODE();
irpSp = IoGetCurrentIrpStackLocation( Irp );
//
// Fetch adapter context for this device.
// --------------------------------------
// Adapter pointer was stashed in FsContext when handle was opened.
//
adapter = (PTAP_ADAPTER_CONTEXT )(irpSp->FileObject)->FsContext;
ASSERT(adapter);
//
// Sanity checks on state variables
//
if (!tapAdapterReadAndWriteReady(adapter))
{
//DEBUGP (("[%s] Interface is down in IRP_MJ_WRITE\n",
// MINIPORT_INSTANCE_ID (adapter)));
//NOTE_ERROR();
Irp->IoStatus.Status = ntStatus = STATUS_CANCELLED;
Irp->IoStatus.Information = 0;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return ntStatus;
}
// Save IRP-accessible copy of buffer length
Irp->IoStatus.Information = irpSp->Parameters.Write.Length;
if (Irp->MdlAddress == NULL)
{
DEBUGP (("[%s] MdlAddress is NULL for IRP_MJ_WRITE\n",
MINIPORT_INSTANCE_ID (adapter)));
NOTE_ERROR();
Irp->IoStatus.Status = ntStatus = STATUS_INVALID_PARAMETER;
Irp->IoStatus.Information = 0;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return ntStatus;
}
//
// Try to get a virtual address for the MDL.
//
NdisQueryMdl(
Irp->MdlAddress,
&Irp->AssociatedIrp.SystemBuffer,
&dataLength,
NormalPagePriority
);
if (Irp->AssociatedIrp.SystemBuffer == NULL)
{
DEBUGP (("[%s] Could not map address in IRP_MJ_WRITE\n",
MINIPORT_INSTANCE_ID (adapter)));
NOTE_ERROR();
Irp->IoStatus.Status = ntStatus = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Information = 0;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return ntStatus;
}
ASSERT(dataLength == irpSp->Parameters.Write.Length);
Irp->IoStatus.Information = irpSp->Parameters.Write.Length;
//
// Handle miniport Pause
// ---------------------
// NDIS 6 miniports implement a temporary "Pause" state normally followed
// by the Restart. While in the Pause state it is forbidden for the miniport
// to indicate receive NBLs.
//
// That is: The device interface may be "up", but the NDIS miniport send/receive
// interface may be temporarily "down".
//
// BUGBUG!!! In the initial implementation of the NDIS 6 TapOas receive path
// the code below will perform a "lying send" for write IRPs passed to the
// driver while the miniport is in the Paused state.
//
// The correct implementation is to go ahead and build the NBLs corresponding
// to the user-mode write - but queue them. When Restart is entered the
// queued NBLs would be dequeued and indicated to the host.
//
if(tapAdapterSendAndReceiveReady(adapter) == NDIS_STATUS_SUCCESS)
{
if (/*!adapter->m_tun &&*/ ((irpSp->Parameters.Write.Length) >= ETHERNET_HEADER_SIZE))
{
PNET_BUFFER_LIST netBufferList;
DUMP_PACKET ("IRP_MJ_WRITE ETH",
(unsigned char *) Irp->AssociatedIrp.SystemBuffer,
irpSp->Parameters.Write.Length);
//=====================================================
// If IPv4 packet, check whether or not packet
// was truncated.
//=====================================================
#if PACKET_TRUNCATION_CHECK
IPv4PacketSizeVerify (
(unsigned char *) Irp->AssociatedIrp.SystemBuffer,
irpSp->Parameters.Write.Length,
FALSE,
"RX",
&adapter->m_RxTrunc
);
#endif
(Irp->MdlAddress)->Next = NULL; // No next MDL
// Allocate the NBL and NB. Link MDL chain to NB.
netBufferList = NdisAllocateNetBufferAndNetBufferList(
adapter->ReceiveNblPool,
0, // ContextSize
0, // ContextBackFill
Irp->MdlAddress, // MDL chain
0,
dataLength
);
if(netBufferList != NULL)
{
LONG nblCount;
NET_BUFFER_LIST_NEXT_NBL(netBufferList) = NULL; // Only one NBL
// Stash IRP pointer in NBL MiniportReserved[0] field.
netBufferList->MiniportReserved[0] = Irp;
netBufferList->MiniportReserved[1] = NULL;
// This IRP is pended.
IoMarkIrpPending(Irp);
// This IRP cannot be cancelled while in-flight.
IoSetCancelRoutine(Irp,NULL);
TAP_RX_NBL_FLAGS_CLEAR_ALL(netBufferList);
// Increment in-flight receive NBL count.
nblCount = NdisInterlockedIncrement(&adapter->ReceiveNblInFlightCount);
ASSERT(nblCount > 0 );
//
// Indicate the packet
// -------------------
// Irp->AssociatedIrp.SystemBuffer with length irpSp->Parameters.Write.Length
// contains the complete packet including Ethernet header and payload.
//
NdisMIndicateReceiveNetBufferLists(
adapter->MiniportAdapterHandle,
netBufferList,
NDIS_DEFAULT_PORT_NUMBER,
1, // NumberOfNetBufferLists
0 // ReceiveFlags
);
ntStatus = STATUS_PENDING;
}
else
{
DEBUGP (("[%s] NdisMIndicateReceiveNetBufferLists failed in IRP_MJ_WRITE\n",
MINIPORT_INSTANCE_ID (adapter)));
NOTE_ERROR ();
// Fail the IRP
Irp->IoStatus.Information = 0;
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}
}
/*
else if (adapter->m_tun && ((irpSp->Parameters.Write.Length) >= IP_HEADER_SIZE))
{
PETH_HEADER p_UserToTap = &adapter->m_UserToTap;
PMDL mdl; // Head of MDL chain.
// For IPv6, need to use Ethernet header with IPv6 proto
if ( IPH_GET_VER( ((IPHDR*) Irp->AssociatedIrp.SystemBuffer)->version_len) == 6 )
{
p_UserToTap = &adapter->m_UserToTap_IPv6;
}
DUMP_PACKET2 ("IRP_MJ_WRITE P2P",
p_UserToTap,
(unsigned char *) Irp->AssociatedIrp.SystemBuffer,
irpSp->Parameters.Write.Length);
//=====================================================
// If IPv4 packet, check whether or not packet
// was truncated.
//=====================================================
#if PACKET_TRUNCATION_CHECK
IPv4PacketSizeVerify (
(unsigned char *) Irp->AssociatedIrp.SystemBuffer,
irpSp->Parameters.Write.Length,
TRUE,
"RX",
&adapter->m_RxTrunc
);
#endif
//
// Allocate MDL for Ethernet header
// --------------------------------
// Irp->AssociatedIrp.SystemBuffer with length irpSp->Parameters.Write.Length
// contains the only the Ethernet payload. Prepend the user-mode provided
// payload with the Ethernet header pointed to by p_UserToTap.
//
mdl = NdisAllocateMdl(
adapter->MiniportAdapterHandle,
p_UserToTap,
sizeof(ETH_HEADER)
);
if(mdl != NULL)
{
PNET_BUFFER_LIST netBufferList;
// Chain user's Ethernet payload behind Ethernet header.
mdl->Next = Irp->MdlAddress;
(Irp->MdlAddress)->Next = NULL; // No next MDL
// Allocate the NBL and NB. Link MDL chain to NB.
netBufferList = NdisAllocateNetBufferAndNetBufferList(
adapter->ReceiveNblPool,
0, // ContextSize
0, // ContextBackFill
mdl, // MDL chain
0,
sizeof(ETH_HEADER) + dataLength
);
if(netBufferList != NULL)
{
LONG nblCount;
NET_BUFFER_LIST_NEXT_NBL(netBufferList) = NULL; // Only one NBL
// This IRP is pended.
IoMarkIrpPending(Irp);
// This IRP cannot be cancelled while in-flight.
IoSetCancelRoutine(Irp,NULL);
// Stash IRP pointer in NBL MiniportReserved[0] field.
netBufferList->MiniportReserved[0] = Irp;
netBufferList->MiniportReserved[1] = NULL;
// Set flag indicating that this is P2P packet
TAP_RX_NBL_FLAGS_CLEAR_ALL(netBufferList);
TAP_RX_NBL_FLAG_SET(netBufferList,TAP_RX_NBL_FLAGS_IS_P2P);
// Increment in-flight receive NBL count.
nblCount = NdisInterlockedIncrement(&adapter->ReceiveNblInFlightCount);
ASSERT(nblCount > 0 );
//
// Indicate the packet
//
NdisMIndicateReceiveNetBufferLists(
adapter->MiniportAdapterHandle,
netBufferList,
NDIS_DEFAULT_PORT_NUMBER,
1, // NumberOfNetBufferLists
0 // ReceiveFlags
);
ntStatus = STATUS_PENDING;
}
else
{
mdl->Next = NULL;
NdisFreeMdl(mdl);
DEBUGP (("[%s] NdisMIndicateReceiveNetBufferLists failed in IRP_MJ_WRITE\n",
MINIPORT_INSTANCE_ID (adapter)));
NOTE_ERROR ();
// Fail the IRP
Irp->IoStatus.Information = 0;
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}
}
else
{
DEBUGP (("[%s] NdisAllocateMdl failed in IRP_MJ_WRITE\n",
MINIPORT_INSTANCE_ID (adapter)));
NOTE_ERROR ();
// Fail the IRP
Irp->IoStatus.Information = 0;
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}
}
*/
else
{
DEBUGP (("[%s] Bad buffer size in IRP_MJ_WRITE, len=%d\n",
MINIPORT_INSTANCE_ID (adapter),
irpSp->Parameters.Write.Length));
NOTE_ERROR ();
Irp->IoStatus.Information = 0; // ETHERNET_HEADER_SIZE;
Irp->IoStatus.Status = ntStatus = STATUS_BUFFER_TOO_SMALL;
}
}
else
{
DEBUGP (("[%s] Lying send in IRP_MJ_WRITE while adapter paused\n",
MINIPORT_INSTANCE_ID (adapter)));
ntStatus = STATUS_SUCCESS;
}
if (ntStatus != STATUS_PENDING)
{
Irp->IoStatus.Status = ntStatus;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
}
return ntStatus;
}

View File

@ -0,0 +1,81 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __TAP_WIN_H
#define __TAP_WIN_H
/*
* =============
* TAP IOCTLs
* =============
*/
#define TAP_WIN_CONTROL_CODE(request,method) \
CTL_CODE (FILE_DEVICE_UNKNOWN, request, method, FILE_ANY_ACCESS)
/* Present in 8.1 */
#define TAP_WIN_IOCTL_GET_MAC TAP_WIN_CONTROL_CODE (1, METHOD_BUFFERED)
#define TAP_WIN_IOCTL_GET_VERSION TAP_WIN_CONTROL_CODE (2, METHOD_BUFFERED)
#define TAP_WIN_IOCTL_GET_MTU TAP_WIN_CONTROL_CODE (3, METHOD_BUFFERED)
//#define TAP_WIN_IOCTL_GET_INFO TAP_WIN_CONTROL_CODE (4, METHOD_BUFFERED)
//#define TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT TAP_WIN_CONTROL_CODE (5, METHOD_BUFFERED)
#define TAP_WIN_IOCTL_SET_MEDIA_STATUS TAP_WIN_CONTROL_CODE (6, METHOD_BUFFERED)
//#define TAP_WIN_IOCTL_CONFIG_DHCP_MASQ TAP_WIN_CONTROL_CODE (7, METHOD_BUFFERED)
//#define TAP_WIN_IOCTL_GET_LOG_LINE TAP_WIN_CONTROL_CODE (8, METHOD_BUFFERED)
//#define TAP_WIN_IOCTL_CONFIG_DHCP_SET_OPT TAP_WIN_CONTROL_CODE (9, METHOD_BUFFERED)
/* Added in 8.2 */
/* obsoletes TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT */
//#define TAP_WIN_IOCTL_CONFIG_TUN TAP_WIN_CONTROL_CODE (10, METHOD_BUFFERED)
// Used by ZT1 to get multicast memberships at the L2 level -- Windows provides no native way to do this that I know of
#define TAP_WIN_IOCTL_GET_MULTICAST_MEMBERSHIPS TAP_WIN_CONTROL_CODE (11, METHOD_BUFFERED)
// Must be the same as NIC_MAX_MCAST_LIST in constants.h
#define TAP_MAX_MCAST_LIST 128
// Amount of memory that must be provided to ioctl TAP_WIN_IOCTL_GET_MULTICAST_MEMBERSHIPS
#define TAP_WIN_IOCTL_GET_MULTICAST_MEMBERSHIPS_OUTPUT_BUF_SIZE (TAP_MAX_MCAST_LIST * 6)
/*
* =================
* Registry keys
* =================
*/
#define ADAPTER_KEY "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
#define NETWORK_CONNECTIONS_KEY "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
/*
* ======================
* Filesystem prefixes
* ======================
*/
#define USERMODEDEVICEDIR "\\\\.\\Global\\"
#define SYSDEVICEDIR "\\Device\\"
#define USERDEVICEDIR "\\DosDevices\\Global\\"
#define TAP_WIN_SUFFIX ".tap"
#endif // __TAP_WIN_H

88
windows/TapDriver6/tap.h Normal file
View File

@ -0,0 +1,88 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __TAP_H
#define __TAP_H
#ifndef NDIS_SUPPORT_NDIS6
#define NDIS_SUPPORT_NDIS6 1
#define NDIS_SUPPORT_NDIS61 1
#define NDIS_WDM1 1
#define NDIS61_MINIPORT 1
#endif
#include <ntifs.h>
#include <ndis.h>
#include <ntstrsafe.h>
#include <netioapi.h>
#include "config.h"
#include "lock.h"
#include "constants.h"
#include "proto.h"
#include "mem.h"
#include "macinfo.h"
#include "error.h"
#include "endian.h"
#include "types.h"
#include "adapter.h"
#include "device.h"
#include "prototypes.h"
#include "tap-windows.h"
//========================================================
// Check for truncated IPv4 packets, log errors if found.
//========================================================
#define PACKET_TRUNCATION_CHECK 0
//========================================================
// EXPERIMENTAL -- Configure TAP device object to be
// accessible from non-administrative accounts, based
// on an advanced properties setting.
//
// Duplicates the functionality of OpenVPN's
// --allow-nonadmin directive.
//========================================================
#define ENABLE_NONADMIN 1
//
// The driver has exactly one instance of the TAP_GLOBAL structure. NDIS keeps
// an opaque handle to this data, (it doesn't attempt to read or interpret this
// data), and it passes the handle back to the miniport in MiniportSetOptions
// and MiniportInitializeEx.
//
typedef struct _TAP_GLOBAL
{
LIST_ENTRY AdapterList;
NDIS_RW_LOCK Lock;
NDIS_HANDLE NdisDriverHandle; // From NdisMRegisterMiniportDriver
} TAP_GLOBAL, *PTAP_GLOBAL;
// Global data
extern TAP_GLOBAL GlobalData;
#endif // __TAP_H

View File

@ -0,0 +1,232 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//======================================================
// This driver is designed to work on Windows Vista or higher
// versions of Windows.
//
// It is SMP-safe and handles power management.
//
// By default we operate as a "tap" virtual ethernet
// 802.3 interface, but we can emulate a "tun"
// interface (point-to-point IPv4) through the
// TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT or
// TAP_WIN_IOCTL_CONFIG_TUN ioctl.
//======================================================
//
// Include files.
//
#include <string.h>
#include "tap.h"
// Global data
TAP_GLOBAL GlobalData;
#ifdef ALLOC_PRAGMA
#pragma alloc_text( INIT, DriverEntry )
#pragma alloc_text( PAGE, TapDriverUnload)
#endif // ALLOC_PRAGMA
NTSTATUS
DriverEntry(
__in PDRIVER_OBJECT DriverObject,
__in PUNICODE_STRING RegistryPath
)
/*++
Routine Description:
In the context of its DriverEntry function, a miniport driver associates
itself with NDIS, specifies the NDIS version that it is using, and
registers its entry points.
Arguments:
PVOID DriverObject - pointer to the driver object.
PVOID RegistryPath - pointer to the driver registry path.
Return Value:
NTSTATUS code
--*/
{
NTSTATUS status;
UNREFERENCED_PARAMETER(RegistryPath);
DEBUGP (("[TAP] --> DriverEntry; version [%d.%d] %s %s\n",
TAP_DRIVER_MAJOR_VERSION,
TAP_DRIVER_MINOR_VERSION,
__DATE__,
__TIME__));
DEBUGP (("[TAP] Registry Path: '%wZ'\n", RegistryPath));
//
// Initialize any driver-global variables here.
//
NdisZeroMemory(&GlobalData, sizeof(GlobalData));
//
// The ApaterList in the GlobalData structure is used to track multiple
// adapters controlled by this miniport.
//
NdisInitializeListHead(&GlobalData.AdapterList);
//
// This lock protects the AdapterList.
//
NdisInitializeReadWriteLock(&GlobalData.Lock);
do
{
NDIS_MINIPORT_DRIVER_CHARACTERISTICS miniportCharacteristics;
NdisZeroMemory(&miniportCharacteristics, sizeof(miniportCharacteristics));
{C_ASSERT(sizeof(miniportCharacteristics) >= NDIS_SIZEOF_MINIPORT_DRIVER_CHARACTERISTICS_REVISION_2);}
miniportCharacteristics.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_DRIVER_CHARACTERISTICS;
miniportCharacteristics.Header.Size = NDIS_SIZEOF_MINIPORT_DRIVER_CHARACTERISTICS_REVISION_2;
miniportCharacteristics.Header.Revision = NDIS_MINIPORT_DRIVER_CHARACTERISTICS_REVISION_2;
miniportCharacteristics.MajorNdisVersion = TAP_NDIS_MAJOR_VERSION;
miniportCharacteristics.MinorNdisVersion = TAP_NDIS_MINOR_VERSION;
miniportCharacteristics.MajorDriverVersion = TAP_DRIVER_MAJOR_VERSION;
miniportCharacteristics.MinorDriverVersion = TAP_DRIVER_MINOR_VERSION;
miniportCharacteristics.Flags = 0;
//miniportCharacteristics.SetOptionsHandler = MPSetOptions; // Optional
miniportCharacteristics.InitializeHandlerEx = AdapterCreate;
miniportCharacteristics.HaltHandlerEx = AdapterHalt;
miniportCharacteristics.UnloadHandler = TapDriverUnload;
miniportCharacteristics.PauseHandler = AdapterPause;
miniportCharacteristics.RestartHandler = AdapterRestart;
miniportCharacteristics.OidRequestHandler = AdapterOidRequest;
miniportCharacteristics.SendNetBufferListsHandler = AdapterSendNetBufferLists;
miniportCharacteristics.ReturnNetBufferListsHandler = AdapterReturnNetBufferLists;
miniportCharacteristics.CancelSendHandler = AdapterCancelSend;
miniportCharacteristics.CheckForHangHandlerEx = AdapterCheckForHangEx;
miniportCharacteristics.ResetHandlerEx = AdapterReset;
miniportCharacteristics.DevicePnPEventNotifyHandler = AdapterDevicePnpEventNotify;
miniportCharacteristics.ShutdownHandlerEx = AdapterShutdownEx;
miniportCharacteristics.CancelOidRequestHandler = AdapterCancelOidRequest;
//
// Associate the miniport driver with NDIS by calling the
// NdisMRegisterMiniportDriver. This function returns an NdisDriverHandle.
// The miniport driver must retain this handle but it should never attempt
// to access or interpret this handle.
//
// By calling NdisMRegisterMiniportDriver, the driver indicates that it
// is ready for NDIS to call the driver's MiniportSetOptions and
// MiniportInitializeEx handlers.
//
DEBUGP (("[TAP] Calling NdisMRegisterMiniportDriver...\n"));
//NDIS_DECLARE_MINIPORT_DRIVER_CONTEXT(TAP_GLOBAL);
status = NdisMRegisterMiniportDriver(
DriverObject,
RegistryPath,
&GlobalData,
&miniportCharacteristics,
&GlobalData.NdisDriverHandle
);
if (NDIS_STATUS_SUCCESS == status)
{
DEBUGP (("[TAP] Registered miniport successfully\n"));
}
else
{
DEBUGP(("[TAP] NdisMRegisterMiniportDriver failed: %8.8X\n", status));
TapDriverUnload(DriverObject);
status = NDIS_STATUS_FAILURE;
break;
}
} while(FALSE);
DEBUGP (("[TAP] <-- DriverEntry; status = %8.8X\n",status));
return status;
}
VOID
TapDriverUnload(
__in PDRIVER_OBJECT DriverObject
)
/*++
Routine Description:
The unload handler is called during driver unload to free up resources
acquired in DriverEntry. This handler is registered in DriverEntry through
NdisMRegisterMiniportDriver. Note that an unload handler differs from
a MiniportHalt function in that this unload handler releases resources that
are global to the driver, while the halt handler releases resource for a
particular adapter.
Runs at IRQL = PASSIVE_LEVEL.
Arguments:
DriverObject Not used
Return Value:
None.
--*/
{
PDEVICE_OBJECT deviceObject = DriverObject->DeviceObject;
UNICODE_STRING uniWin32NameString;
DEBUGP (("[TAP] --> TapDriverUnload; version [%d.%d] %s %s unloaded\n",
TAP_DRIVER_MAJOR_VERSION,
TAP_DRIVER_MINOR_VERSION,
__DATE__,
__TIME__
));
PAGED_CODE();
//
// Clean up all globals that were allocated in DriverEntry
//
ASSERT(IsListEmpty(&GlobalData.AdapterList));
if(GlobalData.NdisDriverHandle != NULL )
{
NdisMDeregisterMiniportDriver(GlobalData.NdisDriverHandle);
}
DEBUGP (("[TAP] <-- TapDriverUnload\n"));
}

1175
windows/TapDriver6/txpath.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,90 @@
/*
* TAP-Windows -- A kernel driver to provide virtual tap
* device functionality on Windows.
*
* This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
*
* This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
* and is released under the GPL version 2 (see below).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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 (see the file COPYING included with this
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef TAP_TYPES_DEFINED
#define TAP_TYPES_DEFINED
//typedef
//struct _Queue
//{
// ULONG base;
// ULONG size;
// ULONG capacity;
// ULONG max_size;
// PVOID data[];
//} Queue;
//typedef struct _TAP_PACKET;
//typedef struct _TapExtension
//{
// // TAP device object and packet queues
// Queue *m_PacketQueue, *m_IrpQueue;
// PDEVICE_OBJECT m_TapDevice;
// NDIS_HANDLE m_TapDeviceHandle;
// ULONG TapFileIsOpen;
//
// // Used to lock packet queues
// NDIS_SPIN_LOCK m_QueueLock;
// BOOLEAN m_AllocatedSpinlocks;
//
// // Used to bracket open/close
// // state changes.
// MUTEX m_OpenCloseMutex;
//
// // True if device has been permanently halted
// BOOLEAN m_Halt;
//
// // TAP device name
// unsigned char *m_TapName;
// UNICODE_STRING m_UnicodeLinkName;
// BOOLEAN m_CreatedUnicodeLinkName;
//
// // Used for device status ioctl only
// const char *m_LastErrorFilename;
// int m_LastErrorLineNumber;
// LONG TapFileOpenCount;
//
// // Flags
// BOOLEAN TapDeviceCreated;
// BOOLEAN m_CalledTapDeviceFreeResources;
//
// // DPC queue for deferred packet injection
// BOOLEAN m_InjectDpcInitialized;
// KDPC m_InjectDpc;
// NDIS_SPIN_LOCK m_InjectLock;
// Queue *m_InjectQueue;
//}
//TapExtension, *TapExtensionPointer;
typedef struct _InjectPacket
{
# define INJECT_PACKET_SIZE(data_size) (sizeof (InjectPacket) + (data_size))
# define INJECT_PACKET_FREE(ib) NdisFreeMemory ((ib), INJECT_PACKET_SIZE ((ib)->m_Size), 0)
ULONG m_Size;
UCHAR m_Data []; // m_Data must be the last struct member
}
InjectPacket, *InjectPacketPointer;
#endif

View File

@ -0,0 +1,143 @@
;
; ZeroTier One Virtual Network Port NDIS6 Driver
;
; Based on the OpenVPN tap-windows6 driver version 9.21.1 git
; commit 48f027cfca52b16b5fd23d82e6016ed8a91fc4d3.
; See: https://github.com/OpenVPN/tap-windows6
;
; Modified by ZeroTier, Inc. - https://www.zerotier.com/
;
; (1) Comment out 'tun' functionality and related features such as DHCP
; emulation, since we don't use any of that. Just want straight 'tap'.
; (2) Added custom IOCTL to enumerate L2 multicast memberships.
; (3) Increase maximum number of multicast memberships to 128.
; (4) Set default and max device MTU to 2800.
; (5) Rename/rebrand driver as ZeroTier network port driver.
;
; Original copyright below. Modifications released under GPLv2 as well.
;
; ****************************************************************************
; * Copyright (C) 2002-2014 OpenVPN Technologies, Inc. *
; * This program is free software; you can redistribute it and/or modify *
; * it under the terms of the GNU General Public License version 2 *
; * as published by the Free Software Foundation. *
; ****************************************************************************
;
[Version]
Signature = "$Windows NT$"
CatalogFile = zttap300.cat
ClassGUID = {4d36e972-e325-11ce-bfc1-08002be10318}
Provider = %Provider%
Class = Net
DriverVer=04/25/2015,3.00.00.0
[Strings]
DeviceDescription = "ZeroTier One Virtual Port"
Provider = "ZeroTier Networks LLC" ; We're ZeroTier, Inc. now but kernel mode certs are $300+ so fuqdat.
; To build for x86, take NTamd64 off this and off the named section manually, build, then put it back!
[Manufacturer]
%Provider%=zttap300,NTamd64
[zttap300]
%DeviceDescription% = zttap300.ndi, root\zttap300 ; Root enumerated
%DeviceDescription% = zttap300.ndi, zttap300 ; Legacy
[zttap300.NTamd64]
%DeviceDescription% = zttap300.ndi, root\zttap300 ; Root enumerated
%DeviceDescription% = zttap300.ndi, zttap300 ; Legacy
;----------------- Characteristics ------------
; NCF_PHYSICAL = 0x04
; NCF_VIRTUAL = 0x01
; NCF_SOFTWARE_ENUMERATED = 0x02
; NCF_HIDDEN = 0x08
; NCF_NO_SERVICE = 0x10
; NCF_HAS_UI = 0x80
;----------------- Characteristics ------------
[zttap300.ndi]
CopyFiles = zttap300.driver, zttap300.files
AddReg = zttap300.reg
AddReg = zttap300.params.reg
Characteristics = 0x81
*IfType = 0x6 ; IF_TYPE_ETHERNET_CSMACD
*MediaType = 0x0 ; NdisMedium802_3
*PhysicalMediaType = 14 ; NdisPhysicalMedium802_3
[zttap300.ndi.Services]
AddService = zttap300, 2, zttap300.service
[zttap300.reg]
HKR, Ndi, Service, 0, "zttap300"
HKR, Ndi\Interfaces, UpperRange, 0, "ndis5" ; yes, 'ndis5' is correct... yup, Windows.
HKR, Ndi\Interfaces, LowerRange, 0, "ethernet"
HKR, , Manufacturer, 0, "%Provider%"
HKR, , ProductName, 0, "%DeviceDescription%"
[zttap300.params.reg]
HKR, Ndi\params\MTU, ParamDesc, 0, "MTU"
HKR, Ndi\params\MTU, Type, 0, "int"
HKR, Ndi\params\MTU, Default, 0, "2800"
HKR, Ndi\params\MTU, Optional, 0, "0"
HKR, Ndi\params\MTU, Min, 0, "100"
HKR, Ndi\params\MTU, Max, 0, "2800"
HKR, Ndi\params\MTU, Step, 0, "1"
HKR, Ndi\params\MediaStatus, ParamDesc, 0, "Media Status"
HKR, Ndi\params\MediaStatus, Type, 0, "enum"
HKR, Ndi\params\MediaStatus, Default, 0, "0"
HKR, Ndi\params\MediaStatus, Optional, 0, "0"
HKR, Ndi\params\MediaStatus\enum, "0", 0, "Application Controlled"
HKR, Ndi\params\MediaStatus\enum, "1", 0, "Always Connected"
HKR, Ndi\params\MAC, ParamDesc, 0, "MAC Address"
HKR, Ndi\params\MAC, Type, 0, "edit"
HKR, Ndi\params\MAC, Optional, 0, "1"
HKR, Ndi\params\AllowNonAdmin, ParamDesc, 0, "Non-Admin Access"
HKR, Ndi\params\AllowNonAdmin, Type, 0, "enum"
HKR, Ndi\params\AllowNonAdmin, Default, 0, "0"
HKR, Ndi\params\AllowNonAdmin, Optional, 0, "0"
HKR, Ndi\params\AllowNonAdmin\enum, "0", 0, "Not Allowed"
HKR, Ndi\params\AllowNonAdmin\enum, "1", 0, "Allowed"
;---------- Service Type -------------
; SERVICE_KERNEL_DRIVER = 0x01
; SERVICE_WIN32_OWN_PROCESS = 0x10
;---------- Service Type -------------
;---------- Start Mode ---------------
; SERVICE_BOOT_START = 0x0
; SERVICE_SYSTEM_START = 0x1
; SERVICE_AUTO_START = 0x2
; SERVICE_DEMAND_START = 0x3
; SERVICE_DISABLED = 0x4
;---------- Start Mode ---------------
[zttap300.service]
DisplayName = %DeviceDescription%
ServiceType = 1
StartType = 3
ErrorControl = 1
LoadOrderGroup = NDIS
ServiceBinary = %12%\zttap300.sys
;----------------- Copy Flags ------------
; COPYFLG_NOSKIP = 0x02
; COPYFLG_NOVERSIONCHECK = 0x04
;----------------- Copy Flags ------------
[SourceDisksNames]
1 = %DeviceDescription%, zttap300.sys
[SourceDisksFiles]
zttap300.sys = 1
[DestinationDirs]
zttap300.files = 11
zttap300.driver = 12
[zttap300.files]
;
[zttap300.driver]
zttap300.sys,,,6 ; COPYFLG_NOSKIP | COPYFLG_NOVERSIONCHECK

View File

@ -5,6 +5,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TapDriver", "TapDriver\TapD
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZeroTierOne", "ZeroTierOne\ZeroTierOne.vcxproj", "{B00A4957-5977-4AC1-9EF4-571DC27EADA2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TapDriver6", "TapDriver6\TapDriver6.vcxproj", "{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
CD_ROM|Any CPU = CD_ROM|Any CPU
@ -295,6 +297,149 @@ Global
{B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Release|x86.ActiveCfg = Release|Win32
{B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Release|x86.Build.0 = Release|Win32
{B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Release|x86.Deploy.0 = Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|Any CPU.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|Mixed Platforms.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|Mixed Platforms.Build.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|Mixed Platforms.Deploy.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|Win32.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|Win32.Build.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|Win32.Deploy.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|x64.ActiveCfg = Win8 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|x64.Build.0 = Win8 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|x64.Deploy.0 = Win8 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|x86.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|x86.Build.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|x86.Deploy.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|Any CPU.ActiveCfg = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|Mixed Platforms.ActiveCfg = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|Mixed Platforms.Build.0 = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|Mixed Platforms.Deploy.0 = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|Win32.ActiveCfg = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|Win32.Build.0 = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|Win32.Deploy.0 = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|x64.ActiveCfg = Win7 Debug|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|x64.Build.0 = Win7 Debug|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|x64.Deploy.0 = Win7 Debug|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|x86.ActiveCfg = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|x86.Build.0 = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|x86.Deploy.0 = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|Any CPU.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|Mixed Platforms.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|Mixed Platforms.Build.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|Mixed Platforms.Deploy.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|Win32.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|Win32.Build.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|Win32.Deploy.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|x64.ActiveCfg = Win8 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|x64.Build.0 = Win8 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|x64.Deploy.0 = Win8 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|x86.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|x86.Build.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|x86.Deploy.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|Any CPU.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|Mixed Platforms.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|Mixed Platforms.Build.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|Mixed Platforms.Deploy.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|Win32.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|Win32.Build.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|Win32.Deploy.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|x64.ActiveCfg = Win8 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|x64.Build.0 = Win8 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|x64.Deploy.0 = Win8 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|x86.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|x86.Build.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|x86.Deploy.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|Any CPU.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|Mixed Platforms.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|Mixed Platforms.Build.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|Mixed Platforms.Deploy.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|Win32.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|Win32.Build.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|Win32.Deploy.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|x64.ActiveCfg = Win8 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|x64.Build.0 = Win8 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|x64.Deploy.0 = Win8 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|x86.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|x86.Build.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|x86.Deploy.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|Any CPU.ActiveCfg = Vista Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|Mixed Platforms.ActiveCfg = Vista Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|Mixed Platforms.Build.0 = Vista Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|Mixed Platforms.Deploy.0 = Vista Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|Win32.ActiveCfg = Vista Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|Win32.Build.0 = Vista Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|Win32.Deploy.0 = Vista Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|x64.ActiveCfg = Vista Debug|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|x64.Build.0 = Vista Debug|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|x64.Deploy.0 = Vista Debug|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|x86.ActiveCfg = Vista Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|x86.Build.0 = Vista Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|x86.Deploy.0 = Vista Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|Any CPU.ActiveCfg = Vista Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|Mixed Platforms.ActiveCfg = Vista Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|Mixed Platforms.Build.0 = Vista Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|Mixed Platforms.Deploy.0 = Vista Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|Win32.ActiveCfg = Vista Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|Win32.Build.0 = Vista Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|Win32.Deploy.0 = Vista Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|x64.ActiveCfg = Vista Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|x64.Build.0 = Vista Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|x64.Deploy.0 = Vista Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|x86.ActiveCfg = Vista Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|x86.Build.0 = Vista Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|x86.Deploy.0 = Vista Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|Any CPU.ActiveCfg = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|Mixed Platforms.ActiveCfg = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|Mixed Platforms.Build.0 = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|Mixed Platforms.Deploy.0 = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|Win32.ActiveCfg = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|Win32.Build.0 = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|Win32.Deploy.0 = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|x64.ActiveCfg = Win7 Debug|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|x64.Build.0 = Win7 Debug|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|x64.Deploy.0 = Win7 Debug|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|x86.ActiveCfg = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|x86.Build.0 = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|x86.Deploy.0 = Win7 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|Any CPU.ActiveCfg = Win7 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|Mixed Platforms.ActiveCfg = Win7 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|Mixed Platforms.Build.0 = Win7 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|Mixed Platforms.Deploy.0 = Win7 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|Win32.ActiveCfg = Win7 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|Win32.Build.0 = Win7 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|Win32.Deploy.0 = Win7 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|x64.ActiveCfg = Win7 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|x64.Build.0 = Win7 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|x64.Deploy.0 = Win7 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|x86.ActiveCfg = Win7 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|x86.Build.0 = Win7 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|x86.Deploy.0 = Win7 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|Any CPU.ActiveCfg = Win8 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|Mixed Platforms.ActiveCfg = Win8 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|Mixed Platforms.Build.0 = Win8 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|Mixed Platforms.Deploy.0 = Win8 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|Win32.ActiveCfg = Win8 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|Win32.Build.0 = Win8 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|Win32.Deploy.0 = Win8 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|x64.ActiveCfg = Win8 Debug|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|x64.Build.0 = Win8 Debug|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|x64.Deploy.0 = Win8 Debug|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|x86.ActiveCfg = Win8 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|x86.Build.0 = Win8 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|x86.Deploy.0 = Win8 Debug|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|Any CPU.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|Mixed Platforms.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|Mixed Platforms.Build.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|Mixed Platforms.Deploy.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|Win32.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|Win32.Build.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|Win32.Deploy.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|x64.ActiveCfg = Win8 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|x64.Build.0 = Win8 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|x64.Deploy.0 = Win8 Release|x64
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|x86.ActiveCfg = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|x86.Build.0 = Win8 Release|Win32
{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|x86.Deploy.0 = Win8 Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE