diff options
-rw-r--r-- | node/EthernetTap.cpp | 16 | ||||
-rw-r--r-- | vsprojects/TapDriver/dhcp.c | 4 | ||||
-rw-r--r-- | vsprojects/TapDriver/dhcp.h | 4 | ||||
-rw-r--r-- | vsprojects/TapDriver/error.c | 4 | ||||
-rw-r--r-- | vsprojects/TapDriver/tap-windows.h | 9 | ||||
-rw-r--r-- | vsprojects/TapDriver/tapdrvr.c | 36 | ||||
-rw-r--r-- | vsprojects/TapDriver/types.h | 4 |
7 files changed, 59 insertions, 18 deletions
diff --git a/node/EthernetTap.cpp b/node/EthernetTap.cpp index 8c6e15e1..ee866b6d 100644 --- a/node/EthernetTap.cpp +++ b/node/EthernetTap.cpp @@ -867,6 +867,7 @@ EthernetTap::EthernetTap( } } + // If we have a device, configure it if (_myDeviceInstanceId.length() > 0) { char tmps[4096]; unsigned int tmpsl = sprintf_s(tmps,"%.2X-%.2X-%.2X-%.2X-%.2X-%.2X",(unsigned int)mac.data[0],(unsigned int)mac.data[1],(unsigned int)mac.data[2],(unsigned int)mac.data[3],(unsigned int)mac.data[4],(unsigned int)mac.data[5]) + 1; @@ -878,11 +879,14 @@ EthernetTap::EthernetTap( RegSetKeyValueA(nwAdapters,mySubkeyName.c_str(),"EnableDHCP",REG_DWORD,(LPCVOID)&tmp,sizeof(tmp)); } + // Done with registry RegCloseKey(nwAdapters); + // If we didn't get a device, we can't start if (_myDeviceInstanceId.length() == 0) throw std::runtime_error("unable to create new tap adapter"); + // Convert device GUID junk... blech { char nobraces[128]; const char *nbtmp1 = _myDeviceInstanceId.c_str(); @@ -897,7 +901,7 @@ EthernetTap::EthernetTap( throw std::runtime_error("unable to convert instance ID GUID to native GUID (invalid NetCfgInstanceId in registry?)"); } - // Disable and enable interface to ensure settings take effect + // Disable and enable interface to ensure registry settings take effect { STARTUPINFOA startupInfo; startupInfo.cb = sizeof(startupInfo); @@ -928,26 +932,24 @@ EthernetTap::EthernetTap( } // Open the tap, which is in this weird Windows analog of /dev -#ifdef UNICODE - wchar_t tapPath[4096]; - swprintf_s(tapPath,L"\\\\.\\Global\\%S.tap",_myDeviceInstanceId.c_str()); -#else char tapPath[4096]; sprintf_s(tapPath,"\\\\.\\Global\\%s.tap",_myDeviceInstanceId.c_str()); -#endif - _tap = CreateFile(tapPath,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_SYSTEM|FILE_FLAG_OVERLAPPED,NULL); + _tap = CreateFileA(tapPath,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_SYSTEM|FILE_FLAG_OVERLAPPED,NULL); if (_tap == INVALID_HANDLE_VALUE) throw std::runtime_error("unable to open tap in \\\\.\\Global\\ namespace"); + // Set media status to enabled uint32_t tmpi = 1; DWORD bytesReturned = 0; DeviceIoControl(_tap,TAP_WIN_IOCTL_SET_MEDIA_STATUS,&tmpi,sizeof(tmpi),&tmpi,sizeof(tmpi),&bytesReturned,NULL); + // Initialized overlapped I/O structures and related events memset(&_tapOvlRead,0,sizeof(_tapOvlRead)); _tapOvlRead.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL); memset(&_tapOvlWrite,0,sizeof(_tapOvlWrite)); _tapOvlWrite.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL); + // Start background thread that actually performs I/O _injectSemaphore = CreateSemaphore(NULL,0,1,NULL); _thread = Thread::start(this); } diff --git a/vsprojects/TapDriver/dhcp.c b/vsprojects/TapDriver/dhcp.c index a3f74057..f3c61d6f 100644 --- a/vsprojects/TapDriver/dhcp.c +++ b/vsprojects/TapDriver/dhcp.c @@ -22,6 +22,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#if 0 + //========================= // Code to set DHCP options //========================= @@ -597,3 +599,5 @@ DumpDHCP (const ETH_HEADER *eth, } #endif /* DBG */ + +#endif diff --git a/vsprojects/TapDriver/dhcp.h b/vsprojects/TapDriver/dhcp.h index 94765a7b..92e5ca87 100644 --- a/vsprojects/TapDriver/dhcp.h +++ b/vsprojects/TapDriver/dhcp.h @@ -22,6 +22,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#if 0 + #pragma pack(1) //=================================================== @@ -162,3 +164,5 @@ DumpDHCP (const ETH_HEADER *eth, const int optlen); #endif + +#endif diff --git a/vsprojects/TapDriver/error.c b/vsprojects/TapDriver/error.c index 69e9ec63..e03fd114 100644 --- a/vsprojects/TapDriver/error.c +++ b/vsprojects/TapDriver/error.c @@ -324,7 +324,8 @@ DumpPacket (const char *prefix, && blen - hlen >= (sizeof (UDPHDR))) { const UDPHDR *udp = (UDPHDR *) (data + sizeof (ETH_HEADER) + hlen); - + +#if 0 // DHCP packet? if ((udp->dest == htons (BOOTPC_PORT) || udp->dest == htons (BOOTPS_PORT)) && blen - hlen >= (sizeof (UDPHDR) + sizeof (DHCP))) @@ -346,6 +347,7 @@ DumpPacket (const char *prefix, DumpDHCP (eth, ip, udp, dhcp, optlen); did = TRUE; } +#endif if (!did) { diff --git a/vsprojects/TapDriver/tap-windows.h b/vsprojects/TapDriver/tap-windows.h index 5c5bf5dd..ff1baf17 100644 --- a/vsprojects/TapDriver/tap-windows.h +++ b/vsprojects/TapDriver/tap-windows.h @@ -39,16 +39,16 @@ #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_CONFIG_POINT_TO_POINT TAP_WIN_CONTROL_CODE (5, METHOD_BUFFERED) #define TAP_WIN_IOCTL_SET_MEDIA_STATUS TAP_WIN_CONTROL_CODE (6, METHOD_BUFFERED) -#define TAP_WIN_IOCTL_CONFIG_DHCP_MASQ TAP_WIN_CONTROL_CODE (7, METHOD_BUFFERED) +//#define TAP_WIN_IOCTL_CONFIG_DHCP_MASQ TAP_WIN_CONTROL_CODE (7, METHOD_BUFFERED) #define TAP_WIN_IOCTL_GET_LOG_LINE TAP_WIN_CONTROL_CODE (8, METHOD_BUFFERED) -#define TAP_WIN_IOCTL_CONFIG_DHCP_SET_OPT TAP_WIN_CONTROL_CODE (9, METHOD_BUFFERED) +//#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) +//#define TAP_WIN_IOCTL_CONFIG_TUN TAP_WIN_CONTROL_CODE (10, METHOD_BUFFERED) /* * ================= @@ -57,7 +57,6 @@ */ #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}" /* diff --git a/vsprojects/TapDriver/tapdrvr.c b/vsprojects/TapDriver/tapdrvr.c index 43eca58c..4781c872 100644 --- a/vsprojects/TapDriver/tapdrvr.c +++ b/vsprojects/TapDriver/tapdrvr.c @@ -62,7 +62,7 @@ // Duplicates the functionality of OpenVPN's // --allow-nonadmin directive. //======================================================== -#define ENABLE_NONADMIN 1 +//#define ENABLE_NONADMIN 1 #if defined(DDKVER_MAJOR) && DDKVER_MAJOR < 5600 #include <ndis.h> @@ -551,6 +551,7 @@ NDIS_STATUS AdapterCreate l_Adapter->m_MAC[0], l_Adapter->m_MAC[1], l_Adapter->m_MAC[2], l_Adapter->m_MAC[3], l_Adapter->m_MAC[4], l_Adapter->m_MAC[5])); +#if 0 //================== // Set broadcast MAC //================== @@ -559,6 +560,7 @@ NDIS_STATUS AdapterCreate for (i = 0; i < sizeof (MACADDR); ++i) l_Adapter->m_MAC_Broadcast[i] = 0xFF; } +#endif //==================================== // Initialize TAP device @@ -1480,6 +1482,7 @@ static IPV6ADDR IPV6_NS_TARGET_UNICAST = { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08 }; +#if 0 BOOLEAN HandleIPv6NeighborDiscovery( TapAdapterPointer p_Adapter, UCHAR * m_Data ) { @@ -1581,6 +1584,7 @@ HandleIPv6NeighborDiscovery( TapAdapterPointer p_Adapter, UCHAR * m_Data ) return TRUE; // all fine } +#endif //==================================================================== // Adapter Transmission @@ -1662,6 +1666,7 @@ AdapterTransmit (IN NDIS_HANDLE p_AdapterContext, IPv4PacketSizeVerify (l_PacketBuffer->m_Data, l_PacketLength, FALSE, "TX", &l_Adapter->m_TxTrunc); #endif +#if 0 //===================================================== // Are we running in DHCP server masquerade mode? // @@ -1687,7 +1692,9 @@ AdapterTransmit (IN NDIS_HANDLE p_AdapterContext, l_Adapter->m_dhcp_server_mac)) goto no_queue; } +#endif +#if 0 // DHCP packet? else if (l_PacketLength >= sizeof (ETH_HEADER) + sizeof (IPHDR) + sizeof (UDPHDR) + sizeof (DHCP) && eth->proto == htons (ETH_P_IP) @@ -1715,6 +1722,7 @@ AdapterTransmit (IN NDIS_HANDLE p_AdapterContext, goto no_queue; } } +#endif //=============================================== // In Point-To-Point mode, check to see whether @@ -1723,7 +1731,8 @@ AdapterTransmit (IN NDIS_HANDLE p_AdapterContext, // (to be handled locally), and the rest is forwarded // all other protocols are dropped //=============================================== - if (l_Adapter->m_tun) +#if 0 + if (l_Adapter->m_tun) { ETH_HEADER *e; @@ -1790,8 +1799,9 @@ AdapterTransmit (IN NDIS_HANDLE p_AdapterContext, l_PacketBuffer->m_SizeFlags |= TP_TUN; } } +#endif - //=============================================== + //=============================================== // Push packet onto queue to wait for read from // userspace. //=============================================== @@ -2051,6 +2061,7 @@ TapDeviceHook (IN PDEVICE_OBJECT p_DeviceObject, IN PIRP p_IRP) } #endif +#if 0 case TAP_WIN_IOCTL_CONFIG_TUN: { if (l_IrpSp->Parameters.DeviceIoControl.InputBufferLength >= @@ -2097,7 +2108,9 @@ TapDeviceHook (IN PDEVICE_OBJECT p_DeviceObject, IN PIRP p_IRP) break; } +#endif +#if 0 case TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT: // Obsoleted by TAP_WIN_IOCTL_CONFIG_TUN { if (l_IrpSp->Parameters.DeviceIoControl.InputBufferLength >= @@ -2136,6 +2149,7 @@ TapDeviceHook (IN PDEVICE_OBJECT p_DeviceObject, IN PIRP p_IRP) break; } +#endif case TAP_WIN_IOCTL_SET_MEDIA_STATUS: { @@ -2154,6 +2168,7 @@ TapDeviceHook (IN PDEVICE_OBJECT p_DeviceObject, IN PIRP p_IRP) break; } +#if 0 case TAP_WIN_IOCTL_CONFIG_DHCP_MASQ: { if (l_IrpSp->Parameters.DeviceIoControl.InputBufferLength >= @@ -2220,6 +2235,7 @@ TapDeviceHook (IN PDEVICE_OBJECT p_DeviceObject, IN PIRP p_IRP) break; } +#endif default: { @@ -2370,6 +2386,7 @@ TapDeviceHook (IN PDEVICE_OBJECT p_DeviceObject, IN PIRP p_IRP) p_IRP->IoStatus.Status = l_Status = STATUS_UNSUCCESSFUL; p_IRP->IoStatus.Information = 0; } +#if 0 else if (!l_Adapter->m_tun && ((l_IrpSp->Parameters.Write.Length) >= ETHERNET_HEADER_SIZE)) { __try @@ -2414,6 +2431,8 @@ TapDeviceHook (IN PDEVICE_OBJECT p_DeviceObject, IN PIRP p_IRP) p_IRP->IoStatus.Information = 0; } } +#endif +#if 0 else if (l_Adapter->m_tun && ((l_IrpSp->Parameters.Write.Length) >= IP_HEADER_SIZE)) { __try @@ -2467,6 +2486,7 @@ TapDeviceHook (IN PDEVICE_OBJECT p_DeviceObject, IN PIRP p_IRP) p_IRP->IoStatus.Information = 0; } } +#endif else { DEBUGP (("[%s] Bad buffer size in IRP_MJ_WRITE, len=%d\n", @@ -2827,7 +2847,8 @@ SetMediaStatus (TapAdapterPointer p_Adapter, BOOLEAN state) VOID CheckIfDhcpAndTunMode (TapAdapterPointer p_Adapter) { - if (p_Adapter->m_tun && p_Adapter->m_dhcp_enabled) +#if 0 + if (p_Adapter->m_tun && p_Adapter->m_dhcp_enabled) { if ((p_Adapter->m_dhcp_server_ip & p_Adapter->m_remoteNetmask) == p_Adapter->m_remoteNetwork) { @@ -2835,8 +2856,10 @@ CheckIfDhcpAndTunMode (TapAdapterPointer p_Adapter) p_Adapter->m_dhcp_server_arp = FALSE; } } +#endif } +#if 0 //=================================================== // Generate an ARP reply message for specific kinds // ARP queries. @@ -2855,7 +2878,7 @@ ProcessARP (TapAdapterPointer p_Adapter, if (src->m_Proto == htons (ETH_P_ARP) && MAC_EQUAL (src->m_MAC_Source, p_Adapter->m_MAC) && MAC_EQUAL (src->m_ARP_MAC_Source, p_Adapter->m_MAC) - && MAC_EQUAL (src->m_MAC_Destination, p_Adapter->m_MAC_Broadcast) + && MAC_EQUAL (src->m_MAC_Destination, p_Adapter->m_MAC_Broadcast) && src->m_ARP_Operation == htons (ARP_REQUEST) && src->m_MAC_AddressType == htons (MAC_ADDR_TYPE) && src->m_MAC_AddressSize == sizeof (MACADDR) @@ -2902,6 +2925,7 @@ ProcessARP (TapAdapterPointer p_Adapter, else return FALSE; } +#endif //=============================================================== // Used in cases where internally generated packets such as @@ -3003,6 +3027,7 @@ InjectPacketNow (TapAdapterPointer p_Adapter, //=================================================================== VOID ResetTapAdapterState (TapAdapterPointer p_Adapter) { +#if 0 // Point-To-Point p_Adapter->m_tun = FALSE; p_Adapter->m_localIP = 0; @@ -3023,6 +3048,7 @@ VOID ResetTapAdapterState (TapAdapterPointer p_Adapter) p_Adapter->m_dhcp_received_discover = FALSE; p_Adapter->m_dhcp_bad_requests = 0; NdisZeroMemory (p_Adapter->m_dhcp_server_mac, sizeof (MACADDR)); +#endif } #if ENABLE_NONADMIN diff --git a/vsprojects/TapDriver/types.h b/vsprojects/TapDriver/types.h index 6ca841d4..4867a3e4 100644 --- a/vsprojects/TapDriver/types.h +++ b/vsprojects/TapDriver/types.h @@ -136,6 +136,7 @@ typedef struct _TapAdapter // Adapter power state char m_DeviceState; +#if 0 // Info for point-to-point mode BOOLEAN m_tun; IPADDR m_localIP; @@ -145,7 +146,9 @@ typedef struct _TapAdapter ETH_HEADER m_UserToTap; ETH_HEADER m_UserToTap_IPv6; // same as UserToTap but proto=ipv6 MACADDR m_MAC_Broadcast; +#endif +#if 0 // Used for DHCP server masquerade BOOLEAN m_dhcp_enabled; IPADDR m_dhcp_addr; @@ -158,6 +161,7 @@ typedef struct _TapAdapter ULONG m_dhcp_user_supplied_options_buffer_len; BOOLEAN m_dhcp_received_discover; ULONG m_dhcp_bad_requests; +#endif // Help to tear down the adapter by keeping // some state information on allocated |