First Commit
This commit is contained in:
@@ -0,0 +1,253 @@
|
||||
<?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|ARM64">
|
||||
<Configuration>Win8 Debug</Configuration>
|
||||
<Platform>ARM64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Win8 Debug|Win32">
|
||||
<Configuration>Win8 Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Win8 Release|ARM64">
|
||||
<Configuration>Win8 Release</Configuration>
|
||||
<Platform>ARM64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Win8 Release|Win32">
|
||||
<Configuration>Win8 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>
|
||||
</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>
|
||||
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="PropertySheets">
|
||||
<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>
|
||||
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'" Label="Configuration">
|
||||
<TargetVersion>Windows8</TargetVersion>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
|
||||
<Driver_SpectreMitigation>false</Driver_SpectreMitigation>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'" Label="Configuration">
|
||||
<TargetVersion>Windows8</TargetVersion>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|ARM64'" Label="Configuration">
|
||||
<TargetVersion>Windows8</TargetVersion>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'" Label="Configuration">
|
||||
<TargetVersion>Windows8</TargetVersion>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
|
||||
<Driver_SpectreMitigation>false</Driver_SpectreMitigation>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Release|ARM64'" Label="Configuration">
|
||||
<TargetVersion>Windows8</TargetVersion>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
|
||||
<Driver_SpectreMitigation>false</Driver_SpectreMitigation>
|
||||
</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>
|
||||
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'">
|
||||
<TargetName>zttap300</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">
|
||||
<TargetName>zttap300</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">
|
||||
<TargetName>zttap300</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|ARM64'">
|
||||
<TargetName>zttap300</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">
|
||||
<TargetName>zttap300</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Release|ARM64'">
|
||||
<TargetName>zttap300</TargetName>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<WppEnabled>false</WppEnabled>
|
||||
<WppScanConfigurationData Condition="'%(ClCompile. ScanConfigurationData)' == ''">trace.h</WppScanConfigurationData>
|
||||
<WppKernelMode>false</WppKernelMode>
|
||||
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'">false</WppMinimalRebuildFromTracking>
|
||||
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">false</WppMinimalRebuildFromTracking>
|
||||
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">false</WppMinimalRebuildFromTracking>
|
||||
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|ARM64'">false</WppMinimalRebuildFromTracking>
|
||||
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">false</WppMinimalRebuildFromTracking>
|
||||
<WppMinimalRebuildFromTracking Condition="'$(Configuration)|$(Platform)'=='Win8 Release|ARM64'">false</WppMinimalRebuildFromTracking>
|
||||
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'">Level1</WarningLevel>
|
||||
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">Level1</WarningLevel>
|
||||
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">Level1</WarningLevel>
|
||||
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|ARM64'">Level1</WarningLevel>
|
||||
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">Level1</WarningLevel>
|
||||
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Win8 Release|ARM64'">Level1</WarningLevel>
|
||||
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'">Default</CompileAs>
|
||||
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">Default</CompileAs>
|
||||
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">Default</CompileAs>
|
||||
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|ARM64'">Default</CompileAs>
|
||||
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">Default</CompileAs>
|
||||
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Win8 Release|ARM64'">Default</CompileAs>
|
||||
<BufferSecurityCheck Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">false</BufferSecurityCheck>
|
||||
<BufferSecurityCheck Condition="'$(Configuration)|$(Platform)'=='Win8 Release|ARM64'">false</BufferSecurityCheck>
|
||||
<ControlFlowGuard Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">false</ControlFlowGuard>
|
||||
<ControlFlowGuard Condition="'$(Configuration)|$(Platform)'=='Win8 Release|ARM64'">false</ControlFlowGuard>
|
||||
<FunctionLevelLinking Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">false</FunctionLevelLinking>
|
||||
<FunctionLevelLinking Condition="'$(Configuration)|$(Platform)'=='Win8 Release|ARM64'">false</FunctionLevelLinking>
|
||||
<BufferSecurityCheck Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">false</BufferSecurityCheck>
|
||||
<ControlFlowGuard Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">false</ControlFlowGuard>
|
||||
<FunctionLevelLinking Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">false</FunctionLevelLinking>
|
||||
</ClCompile>
|
||||
<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>
|
||||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|ARM64'">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 />
|
||||
<Link />
|
||||
<Link />
|
||||
<Link>
|
||||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\km\x64\ndis.lib;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\km\x64\ntstrsafe.lib;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\km\x64\wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Win8 Release|ARM64'">C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\km\x64\ndis.lib;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\km\x64\ntstrsafe.lib;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\km\x64\wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<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 />
|
||||
<Link />
|
||||
<Link />
|
||||
<Link>
|
||||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\km\x86\ndis.lib;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\km\x86\ntstrsafe.lib;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\km\x86\wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<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 />
|
||||
<Inf />
|
||||
<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 />
|
||||
<Inf>
|
||||
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">3.00.00.0</TimeStamp>
|
||||
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|ARM64'">3.00.00.0</TimeStamp>
|
||||
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">false</SpecifyDriverVerDirectiveVersion>
|
||||
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|ARM64'">false</SpecifyDriverVerDirectiveVersion>
|
||||
<SpecifyDriverVerDirectiveDate Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">false</SpecifyDriverVerDirectiveDate>
|
||||
<SpecifyDriverVerDirectiveDate Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|ARM64'">false</SpecifyDriverVerDirectiveDate>
|
||||
</Inf>
|
||||
<Inf />
|
||||
<Inf />
|
||||
<Inf />
|
||||
<Inf>
|
||||
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">3.00.00.0</TimeStamp>
|
||||
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Release|ARM64'">3.00.00.0</TimeStamp>
|
||||
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">false</SpecifyDriverVerDirectiveVersion>
|
||||
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win8 Release|ARM64'">false</SpecifyDriverVerDirectiveVersion>
|
||||
<SpecifyDriverVerDirectiveDate Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">false</SpecifyDriverVerDirectiveDate>
|
||||
<SpecifyDriverVerDirectiveDate Condition="'$(Configuration)|$(Platform)'=='Win8 Release|ARM64'">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">
|
||||
<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)'=='Win8 Release|Win32'">false</SpecifyDriverVerDirectiveVersion>
|
||||
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'">3.00.00.0</TimeStamp>
|
||||
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">false</SpecifyDriverVerDirectiveVersion>
|
||||
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|ARM64'">false</SpecifyDriverVerDirectiveVersion>
|
||||
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|x64'">3.00.00.0</TimeStamp>
|
||||
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|ARM64'">3.00.00.0</TimeStamp>
|
||||
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">false</SpecifyDriverVerDirectiveVersion>
|
||||
<SpecifyDriverVerDirectiveVersion Condition="'$(Configuration)|$(Platform)'=='Win8 Release|ARM64'">false</SpecifyDriverVerDirectiveVersion>
|
||||
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Release|x64'">3.00.00.0</TimeStamp>
|
||||
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Win8 Release|ARM64'">3.00.00.0</TimeStamp>
|
||||
</Inf>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -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>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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_
|
||||
@@ -0,0 +1,9 @@
|
||||
#define PRODUCT_NAME "ZeroTier 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"
|
||||
#define PRODUCT_TAP_WIN_DEVICE_DESCRIPTION PRODUCT_NAME
|
||||
#define PRODUCT_TAP_WIN_RELDATE "11/24/2020"
|
||||
@@ -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
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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_
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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));
|
||||
}
|
||||
@@ -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
@@ -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()
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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)
|
||||
#if DBG
|
||||
#define TAP_WIN_IOCTL_GET_LOG_LINE TAP_WIN_CONTROL_CODE (8, METHOD_BUFFERED)
|
||||
#endif
|
||||
//#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
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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_MINIPORT_DRIVER 1
|
||||
#define NDIS_SUPPORT_NDIS6 1
|
||||
#define NDIS_SUPPORT_NDIS630 1
|
||||
#define NDIS_WDM1 1
|
||||
#define NDIS630_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 0
|
||||
|
||||
//
|
||||
// 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
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
@@ -0,0 +1,145 @@
|
||||
;
|
||||
; ****************************************************************************
|
||||
; * 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. *
|
||||
; ****************************************************************************
|
||||
;
|
||||
|
||||
;
|
||||
; ZeroTier One Virtual Network Port NDIS6 Driver
|
||||
;
|
||||
; 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.
|
||||
|
||||
[Version]
|
||||
Signature = "$Windows NT$"
|
||||
CatalogFile = zttap300.cat
|
||||
ClassGUID = {4d36e972-e325-11ce-bfc1-08002be10318}
|
||||
Provider = %Provider%
|
||||
Class = Net
|
||||
DriverVer=11/24/2020,3.00.00.1
|
||||
|
||||
[Strings]
|
||||
DeviceDescription = "ZeroTier Virtual Port"
|
||||
Provider = "ZeroTier"
|
||||
|
||||
[Manufacturer]
|
||||
%Provider%=zttap300,NTx86
|
||||
%Provider%=zttap300,NTamd64
|
||||
%Provider%=zttap300,NTarm64
|
||||
|
||||
[zttap300.NTx86]
|
||||
%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
|
||||
|
||||
[zttap300.NTarm64]
|
||||
%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
|
||||
|
||||
Reference in New Issue
Block a user