3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* $Id$ */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** @file
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * VBoxNetFltCmn-win.h - Bridged Networking Driver, Windows Specific Code.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Common header with configuration defines and global defs
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
7e9ca60730092c625220814121c54a593ad20997vboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/*
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Copyright (C) 2011 Oracle Corporation
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * available from http://www.virtualbox.org. This file is free software;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * you can redistribute it and/or modify it under the terms of the GNU
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * General Public License (GPL) as published by the Free Software
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
7e9ca60730092c625220814121c54a593ad20997vboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#ifndef ___VBoxNetFltCmn_win_h___
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define ___VBoxNetFltCmn_win_h___
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define LOG_GROUP LOG_GROUP_NET_FLT_DRV
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* debugging flags */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#ifdef DEBUG
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync//# define DEBUG_NETFLT_PACKETS
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# ifndef DEBUG_misha
7e9ca60730092c625220814121c54a593ad20997vboxsync# define RT_NO_STRICT
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* # define DEBUG_NETFLT_LOOPBACK */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* receive logic has several branches */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* the DEBUG_NETFLT_RECV* macros used to debug the ProtocolReceive callback
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * which is typically not used in case the underlying miniport indicates the packets with NdisMIndicateReceivePacket
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * the best way to debug the ProtocolReceive (which in turn has several branches) is to enable the DEBUG_NETFLT_RECV
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * one by one in the below order, i.e.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * first DEBUG_NETFLT_RECV
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * then DEBUG_NETFLT_RECV + DEBUG_NETFLT_RECV_NOPACKET */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync//# define DEBUG_NETFLT_RECV
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync//# define DEBUG_NETFLT_RECV_NOPACKET
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync//# define DEBUG_NETFLT_RECV_TRANSFERDATA
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* use ExAllocatePoolWithTag instead of NdisAllocateMemoryWithTag */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// #define DEBUG_NETFLT_USE_EXALLOC
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <VBox/intnet.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <VBox/log.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <VBox/err.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <VBox/version.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <iprt/initterm.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <iprt/assert.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <iprt/spinlock.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <iprt/semaphore.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <iprt/process.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <iprt/alloc.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <iprt/alloca.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <iprt/time.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <iprt/net.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncRT_C_DECLS_BEGIN
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* ntddk.h has a missing #pragma pack(), work around it
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * see #ifdef VBOX_WITH_WORKAROUND_MISSING_PACK below for detail */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOX_WITH_WORKAROUND_MISSING_PACK
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define _InterlockedExchange _InterlockedExchange_StupidDDKVsCompilerCrap
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define _InterlockedExchangeAdd _InterlockedExchangeAdd_StupidDDKVsCompilerCrap
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define _InterlockedCompareExchange _InterlockedCompareExchange_StupidDDKVsCompilerCrap
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define _InterlockedAddLargeStatistic _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define _interlockedbittestandset _interlockedbittestandset_StupidDDKVsCompilerCrap
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define _interlockedbittestandreset _interlockedbittestandreset_StupidDDKVsCompilerCrap
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define _interlockedbittestandset64 _interlockedbittestandset64_StupidDDKVsCompilerCrap
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define _interlockedbittestandreset64 _interlockedbittestandreset64_StupidDDKVsCompilerCrap
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# pragma warning(disable : 4163)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# ifdef VBOX_WITH_WORKAROUND_MISSING_PACK
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# pragma warning(disable : 4103)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# include <ntddk.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# pragma warning(default : 4163)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# ifdef VBOX_WITH_WORKAROUND_MISSING_PACK
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# pragma pack()
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# pragma warning(default : 4103)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# undef _InterlockedExchange
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# undef _InterlockedExchangeAdd
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# undef _InterlockedCompareExchange
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# undef _InterlockedAddLargeStatistic
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# undef _interlockedbittestandset
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# undef _interlockedbittestandreset
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# undef _interlockedbittestandset64
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# undef _interlockedbittestandreset64
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# include <ndis.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync//# include <ntddk.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* can include ndis.h right away */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# include <ndis.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncRT_C_DECLS_END
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETFLT_OS_SPECFIC 1
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** version
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * NOTE: we are NOT using NDIS 5.1 features now */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#ifdef NDIS51_MINIPORT
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define VBOXNETFLT_VERSION_MP_NDIS_MAJOR 5
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define VBOXNETFLT_VERSION_MP_NDIS_MINOR 1
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define VBOXNETFLT_VERSION_MP_NDIS_MAJOR 5
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define VBOXNETFLT_VERSION_MP_NDIS_MINOR 0
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#ifndef VBOXNETADP
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#ifdef NDIS51
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define VBOXNETFLT_VERSION_PT_NDIS_MAJOR 5
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define VBOXNETFLT_VERSION_PT_NDIS_MINOR 1 /* todo: use 0 here as well ? */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define VBOXNETFLT_VERSION_PT_NDIS_MAJOR 5
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define VBOXNETFLT_VERSION_PT_NDIS_MINOR 0
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define VBOXNETFLT_NAME_PROTOCOL L"VBoxNetFlt"
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** device to be used to prevent the driver unload & ioctl interface (if necessary in the future) */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define VBOXNETFLT_NAME_LINK L"\\DosDevices\\Global\\VBoxNetFlt"
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define VBOXNETFLT_NAME_DEVICE L"\\Device\\VBoxNetFlt"
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define VBOXNETFLT_NAME_LINK L"\\DosDevices\\Global\\VBoxNetAdp"
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define VBOXNETFLT_NAME_DEVICE L"\\Device\\VBoxNetAdp"
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct VBOXNETFLTINS *PVBOXNETFLTINS;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** configuration */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** Ndis Packet pool settings
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * these are applied to both receive and send packet pools */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* number of packets for normal used */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETFLT_PACKET_POOL_SIZE_NORMAL 0x000000FF
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* number of additional overflow packets */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETFLT_PACKET_POOL_SIZE_OVERFLOW 0x0000FF00
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** packet queue size used when the driver is working in the "active" mode */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETFLT_PACKET_INFO_POOL_SIZE 0x0000FFFF
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#ifndef VBOXNETADP
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** memory tag used for memory allocations
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * (VBNF stands for VBox NetFlt) */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define VBOXNETFLT_MEM_TAG 'FNBV'
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** memory tag used for memory allocations
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * (VBNA stands for VBox NetAdp) */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define VBOXNETFLT_MEM_TAG 'ANBV'
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** receive and transmit Ndis buffer pool size */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETFLT_BUFFER_POOL_SIZE_TX 128
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETFLT_BUFFER_POOL_SIZE_RX 128
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETFLT_PACKET_ETHEADER_SIZE 14
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETFLT_PACKET_HEADER_MATCH_SIZE 24
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETFLT_PACKET_QUEUE_SG_SEGS_ALLOC 32
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#if defined(DEBUG_NETFLT_PACKETS) || !defined(VBOX_LOOPBACK_USEFLAGS)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define VBOXNETFLT_PACKETMATCH_LENGTH (VBOXNETFLT_PACKET_ETHEADER_SIZE + 2)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#ifdef VBOXNETADP
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETADP_HEADER_SIZE 14
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETADP_MAX_DATA_SIZE 1500
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETADP_MAX_PACKET_SIZE (VBOXNETADP_HEADER_SIZE + VBOXNETADP_MAX_DATA_SIZE)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETADP_MIN_PACKET_SIZE 60
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* link speed 100Mbps (measured in 100 bps) */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETADP_LINK_SPEED 1000000
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETADP_MAX_LOOKAHEAD_SIZE VBOXNETADP_MAX_DATA_SIZE
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETADP_VENDOR_ID 0x080027
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETADP_VENDOR_DRIVER_VERSION 0x00010000
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETADP_VENDOR_DESC "Sun"
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETADP_MAX_MCAST_LIST 32
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETADP_ETH_ADDRESS_LENGTH 6
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync//#define VBOXNETADP_REPORT_DISCONNECTED
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* type defs */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** Flag specifying that the type of enqueued packet
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * if set the info contains the PINTNETSG packet
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * if clear the packet info contains the PNDIS_PACKET packet
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Typically the packet queue we are maintaining contains PNDIS_PACKETs only,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * however in case the underlying miniport indicates a packet with the NDIS_STATUS_RESOURCES status
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * we MUST return the packet back to the miniport immediately
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * this is why we are creating the INTNETSG, copying the ndis packet info there and enqueueing it */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETFLT_PACKET_SG 0x00000001
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** the flag specifying that the packet source
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * if set the packet comes from the host (upperlying protocol)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * if clear the packet comes from the wire (underlying miniport) */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETFLT_PACKET_SRC_HOST 0x00000002
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#ifndef VBOXNETFLT_NO_PACKET_QUEUE
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** flag specifying the packet was originated by our driver
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * i.e. we could use it on our needs and should not return it
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * we are enqueueing "our" packets on ProtocolReceive call-back when
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Ndis does not give us a receive packet (the driver below us has called NdisM..IndicateReceive)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * this is supported for Ndis Packet only */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETFLT_PACKET_MINE 0x00000004
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** flag passed to vboxNetFltWinQuEnqueuePacket specifying that the packet should be copied
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * this is supported for Ndis Packet only */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETFLT_PACKET_COPY 0x00000008
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** packet queue element containing the packet info */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct VBOXNETFLT_PACKET_INFO
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** list entry used for enqueueing the info */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync LIST_ENTRY ListEntry;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** pointer to the pool containing this packet info */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync struct VBOXNETFLT_PACKET_INFO_POOL *pPool;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** flags describing the referenced packet. Contains PACKET_xxx flags (i.e. PACKET_SG, PACKET_SRC_HOST) */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync uint32_t fFlags;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** pointer to the packet this info represents */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PVOID pPacket;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETFLT_PACKET_INFO, *PVBOXNETFLT_PACKET_INFO;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* paranoid check to make sure the elements in the packet info array are properly aligned */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncAssertCompile((sizeof(VBOXNETFLT_PACKET_INFO) & (sizeof(PVOID) - 1)) == 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** represents the packet queue */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef LIST_ENTRY PVBOXNETFLT_ACKET_QUEUE, *PVBOXNETFLT_PACKET_QUEUE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/*
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * we are using non-interlocked versions of LIST_ENTRY-related operations macros and synchronize
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * access to the queue and its elements by acquiring/releasing a spinlock using Ndis[Acquire,Release]Spinlock
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * we are NOT using interlocked versions of insert/remove head/tail list functions because we need to iterate though
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * the queue elements as well as remove elements from the midle of the queue
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * * @todo: it seems that we can switch to using interlocked versions of list-entry functions
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * since we have removed all functionality (mentioned above, i.e. queue elements iteration, etc.) that might prevent us from doing this
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct VBOXNETFLT_INTERLOCKED_PACKET_QUEUE
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** queue */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PVBOXNETFLT_ACKET_QUEUE Queue;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** queue lock */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_SPIN_LOCK Lock;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETFLT_INTERLOCKED_PACKET_QUEUE, *PVBOXNETFLT_INTERLOCKED_PACKET_QUEUE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct VBOXNETFLT_SINGLE_LIST
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** queue */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SINGLE_LIST_ENTRY Head;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** pointer to the list tail. used to enqueue elements to the tail of the list */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PSINGLE_LIST_ENTRY pTail;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETFLT_SINGLE_LIST, *PVBOXNETFLT_SINGLE_LIST;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct VBOXNETFLT_INTERLOCKED_SINGLE_LIST
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** queue */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VBOXNETFLT_SINGLE_LIST List;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** queue lock */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_SPIN_LOCK Lock;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETFLT_INTERLOCKED_SINGLE_LIST, *PVBOXNETFLT_INTERLOCKED_SINGLE_LIST;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** packet info pool contains free packet info elements to be used for the packet queue
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * we are using the pool mechanism to allocate packet queue elements
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * the pool mechanism is pretty simple now, we are allocating a bunch of memory
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * for maintaining VBOXNETFLT_PACKET_INFO_POOL_SIZE queue elements and just returning null when the pool is exhausted
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * This mechanism seems to be enough for now since we are using VBOXNETFLT_PACKET_INFO_POOL_SIZE = 0xffff which is
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * the maximum size of packets the ndis packet pool supports */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct VBOXNETFLT_PACKET_INFO_POOL
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** free packet info queue */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VBOXNETFLT_INTERLOCKED_PACKET_QUEUE Queue;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** memory bugger used by the pool */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PVOID pBuffer;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETFLT_PACKET_INFO_POOL, *PVBOXNETFLT_PACKET_INFO_POOL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef enum VBOXNETDEVOPSTATE
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync kVBoxNetDevOpState_InvalidValue = 0,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync kVBoxNetDevOpState_Initializing,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync kVBoxNetDevOpState_Initialized,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync kVBoxNetDevOpState_Deinitializing,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync kVBoxNetDevOpState_Deinitialized,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETDEVOPSTATE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef enum VBOXNETFLT_WINIFSTATE
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** The usual invalid state. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync kVBoxWinIfState_Invalid = 0,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** Initialization. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync kVBoxWinIfState_Connecting,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** Connected fuly functional state */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync kVBoxWinIfState_Connected,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** Disconnecting */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync kVBoxWinIfState_Disconnecting,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** Disconnected */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync kVBoxWinIfState_Disconnected,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETFLT_WINIFSTATE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** structure used to maintain the state and reference count of the miniport and protocol */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct VBOXNETFLT_WINIF_DEVICE
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** initialize state */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VBOXNETDEVOPSTATE OpState;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** ndis power state */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_DEVICE_POWER_STATE PowerState;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** reference count */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync uint32_t cReferences;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETFLT_WINIF_DEVICE, *PVBOXNETFLT_WINIF_DEVICE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNDISREQUEST_INPROGRESS 1
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNDISREQUEST_QUEUED 2
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct VBOXNETFLTWIN_STATE
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync union
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync struct
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync UINT fRequestInfo : 2;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync UINT fInterfaceClosing : 1;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync UINT fStandBy : 1;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync UINT fProcessingPacketFilter : 1;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync UINT fPPFNetFlt : 1;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync UINT fUpperProtSetFilterInitialized : 1;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync UINT Reserved : 25;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync };
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync UINT Value;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync };
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETFLTWIN_STATE, *PVBOXNETFLTWIN_STATE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncDECLINLINE(VBOXNETFLTWIN_STATE) vboxNetFltWinAtomicUoReadWinState(VBOXNETFLTWIN_STATE State)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync UINT fValue = ASMAtomicUoReadU32((volatile uint32_t *)&State.Value);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return *((PVBOXNETFLTWIN_STATE)((void*)&fValue));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* miniport layer globals */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct VBOXNETFLTGLOBALS_MP
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** our miniport handle */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_HANDLE hMiniport;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** ddis wrapper handle */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_HANDLE hNdisWrapper;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETFLTGLOBALS_MP, *PVBOXNETFLTGLOBALS_MP;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#ifndef VBOXNETADP
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* protocol layer globals */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct VBOXNETFLTGLOBALS_PT
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** our protocol handle */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_HANDLE hProtocol;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETFLTGLOBALS_PT, *PVBOXNETFLTGLOBALS_PT;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif /* #ifndef VBOXNETADP */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct VBOXNETFLTGLOBALS_WIN
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** synch event used for device creation synchronization */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync KEVENT SynchEvent;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** Device reference count */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync int cDeviceRefs;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** ndis device */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_HANDLE hDevice;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** device object */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PDEVICE_OBJECT pDevObj;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* loopback flags */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* ndis packet flags to disable packet loopback */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync UINT fPacketDontLoopBack;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* ndis packet flags specifying whether the packet is looped back */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync UINT fPacketIsLoopedBack;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* Minport info */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VBOXNETFLTGLOBALS_MP Mp;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#ifndef VBOXNETADP
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* Protocol info */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VBOXNETFLTGLOBALS_PT Pt;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETFLTGLOBALS_WIN, *PVBOXNETFLTGLOBALS_WIN;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncextern VBOXNETFLTGLOBALS_WIN g_VBoxNetFltGlobalsWin;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** represents filter driver device context*/
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct VBOXNETFLTWIN
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** handle used by miniport edge for ndis calls */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_HANDLE hMiniport;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** miniport edge state */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VBOXNETFLT_WINIF_DEVICE MpState;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** ndis packet pool used for receives */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_HANDLE hRecvPacketPool;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** ndis buffer pool used for receives */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_HANDLE hRecvBufferPool;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** driver bind adapter state. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VBOXNETFLT_WINIFSTATE enmState;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#ifndef VBOXNETADP
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* misc state flags */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VBOXNETFLTWIN_STATE StateFlags;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** handle used by protocol edge for ndis calls */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_HANDLE hBinding;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** protocol edge state */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VBOXNETFLT_WINIF_DEVICE PtState;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** ndis packet pool used for receives */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_HANDLE hSendPacketPool;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** ndis buffer pool used for receives */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_HANDLE hSendBufferPool;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** used for maintaining the pending send packets for handling packet loopback */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VBOXNETFLT_INTERLOCKED_SINGLE_LIST SendPacketQueue;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** used for serializing calls to the NdisRequest in the vboxNetFltWinSynchNdisRequest */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync RTSEMFASTMUTEX hSynchRequestMutex;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** event used to synchronize with the Ndis Request completion in the vboxNetFltWinSynchNdisRequest */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync KEVENT hSynchCompletionEvent;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** status of the Ndis Request initiated by the vboxNetFltWinSynchNdisRequest */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_STATUS volatile SynchCompletionStatus;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** pointer to the Ndis Request being executed by the vboxNetFltWinSynchNdisRequest */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PNDIS_REQUEST volatile pSynchRequest;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** open/close adapter status.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Since ndis adapter open and close requests may complete asynchronously,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * we are using event mechanism to wait for open/close completion
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * the status field is being set by the completion call-back */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_STATUS OpenCloseStatus;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** open/close adaptor completion event */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_EVENT OpenCloseEvent;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** medium we are attached to */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_MEDIUM enmMedium;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /**
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Passdown request info
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** ndis request we pass down to the miniport below */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_REQUEST PassDownRequest;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** Ndis pass down request bytes read or written original pointer */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PULONG pcPDRBytesRW;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** Ndis pass down request bytes needed original pointer */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PULONG pcPDRBytesNeeded;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** true if we should indicate the receive complete used by the ProtocolReceive mechanism.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * We need to indicate it only with the ProtocolReceive + NdisMEthIndicateReceive path.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Note: we're using KeGetCurrentProcessorNumber, which is not entirely correct in case
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * we're running on 64bit win7+, which can handle > 64 CPUs, however since KeGetCurrentProcessorNumber
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * always returns the number < than the number of CPUs in the first group, we're guaranteed to have CPU index < 64
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * @todo: use KeGetCurrentProcessorNumberEx for Win7+ 64 and dynamically extended array */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync bool abIndicateRxComplete[64];
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** Pending transfer data packet queue (i.e. packets that were indicated as pending on NdisTransferData call */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VBOXNETFLT_INTERLOCKED_SINGLE_LIST TransferDataList;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* mac options initialized on OID_GEN_MAC_OPTIONS */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ULONG fMacOptions;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** our miniport devuice name */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_STRING MpDeviceName;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** synchronize with unbind with Miniport initialization */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_EVENT MpInitCompleteEvent;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** media connect status that we indicated */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_STATUS MpIndicatedMediaStatus;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** media connect status pending to indicate */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NDIS_STATUS MpUnindicatedMediaStatus;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** packet filter flags set by the upper protocols */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ULONG fUpperProtocolSetFilter;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** packet filter flags set by the upper protocols */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ULONG fSetFilterBuffer;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** packet filter flags set by us */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ULONG fOurSetFilter;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync volatile ULONG cTxSuccess;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync volatile ULONG cRxSuccess;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync volatile ULONG cTxError;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync volatile ULONG cRxError;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETFLTWIN, *PVBOXNETFLTWIN;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct VBOXNETFLT_PACKET_QUEUE_WORKER
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** this event is used to initiate a packet queue worker thread kill */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync KEVENT KillEvent;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** this event is used to notify a worker thread that the packets are added to the queue */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync KEVENT NotifyEvent;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** pointer to the packet queue worker thread object */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PKTHREAD pThread;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** pointer to the SG used by the packet queue for IntNet receive notifications */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PINTNETSG pSG;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** Packet queue */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VBOXNETFLT_INTERLOCKED_PACKET_QUEUE PacketQueue;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** Packet info pool, i.e. the pool for the packet queue elements */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VBOXNETFLT_PACKET_INFO_POOL PacketInfoPool;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETFLT_PACKET_QUEUE_WORKER, *PVBOXNETFLT_PACKET_QUEUE_WORKER;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* protocol reserved data held in ndis packet */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct VBOXNETFLT_PKTRSVD_PT
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** original packet received from the upperlying protocol
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * can be null if the packet was originated by intnet */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PNDIS_PACKET pOrigPacket;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** pointer to the buffer to be freed on send completion
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * can be null if no buffer is to be freed */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PVOID pBufToFree;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#if !defined(VBOX_LOOPBACK_USEFLAGS) || defined(DEBUG_NETFLT_PACKETS)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SINGLE_LIST_ENTRY ListEntry;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* true if the packet is from IntNet */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync bool bFromIntNet;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETFLT_PKTRSVD_PT, *PVBOXNETFLT_PKTRSVD_PT;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** miniport reserved data held in ndis packet */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct VBOXNETFLT_PKTRSVD_MP
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** original packet received from the underling miniport
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * can be null if the packet was originated by intnet */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PNDIS_PACKET pOrigPacket;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** pointer to the buffer to be freed on receive completion
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * can be null if no buffer is to be freed */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PVOID pBufToFree;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETFLT_PKTRSVD_MP, *PVBOXNETFLT_PKTRSVD_MP;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** represents the data stored in the protocol reserved field of ndis packet on NdisTransferData processing */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct VBOXNETFLT_PKTRSVD_TRANSFERDATA_PT
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** next packet in a list */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SINGLE_LIST_ENTRY ListEntry;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* packet buffer start */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PNDIS_BUFFER pOrigBuffer;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync} VBOXNETFLT_PKTRSVD_TRANSFERDATA_PT, *PVBOXNETFLT_PKTRSVD_TRANSFERDATA_PT;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* VBOXNETFLT_PKTRSVD_TRANSFERDATA_PT should fit into PROTOCOL_RESERVED_SIZE_IN_PACKET because we use protocol reserved part
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * of our miniport edge on transfer data processing for honding our own info */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncAssertCompile(sizeof (VBOXNETFLT_PKTRSVD_TRANSFERDATA_PT) <= PROTOCOL_RESERVED_SIZE_IN_PACKET);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* this should fit in MiniportReserved */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncAssertCompile(sizeof (VBOXNETFLT_PKTRSVD_MP) <= RT_SIZEOFMEMB(NDIS_PACKET, MiniportReserved));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* we use RTAsmAtomic*U32 for those, make sure we're correct */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncAssertCompile(sizeof (NDIS_DEVICE_POWER_STATE) == sizeof (uint32_t));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncAssertCompile(sizeof (UINT) == sizeof (uint32_t));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define NDIS_FLAGS_SKIP_LOOPBACK_W2K 0x400
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include "../../VBoxNetFltInternal.h"
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include "VBoxNetFltRt-win.h"
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#ifndef VBOXNETADP
7e9ca60730092c625220814121c54a593ad20997vboxsync# include "VBoxNetFltP-win.h"
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif
7e9ca60730092c625220814121c54a593ad20997vboxsync#include "VBoxNetFltM-win.h"
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif /* #ifndef ___VBoxNetFltCmn_win_h___ */