Revise constants requiring network-byte order
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
9a815147f6
commit
2a5da5c58f
29
wintun.c
29
wintun.c
@ -34,6 +34,7 @@
|
|||||||
#define TUN_EXCH_MIN_BUFFER_SIZE_READ TUN_EXCH_MAX_PACKET_SIZE // Minimum size of read exchange buffer
|
#define TUN_EXCH_MIN_BUFFER_SIZE_READ TUN_EXCH_MAX_PACKET_SIZE // Minimum size of read exchange buffer
|
||||||
#define TUN_EXCH_MIN_BUFFER_SIZE_WRITE (sizeof(TUN_PACKET)) // Minimum size of write exchange buffer
|
#define TUN_EXCH_MIN_BUFFER_SIZE_WRITE (sizeof(TUN_PACKET)) // Minimum size of write exchange buffer
|
||||||
#define TUN_QUEUE_MAX_NBLS 1000
|
#define TUN_QUEUE_MAX_NBLS 1000
|
||||||
|
#define TUN_MEMORY_TAG 'wtun'
|
||||||
|
|
||||||
typedef struct _TUN_PACKET {
|
typedef struct _TUN_PACKET {
|
||||||
ULONG Size; // Size of packet data (TUN_EXCH_MAX_IP_PACKET_SIZE max)
|
ULONG Size; // Size of packet data (TUN_EXCH_MAX_IP_PACKET_SIZE max)
|
||||||
@ -104,13 +105,11 @@ static NDIS_HANDLE NdisMiniportDriverHandle;
|
|||||||
static volatile LONG64 AdapterCount;
|
static volatile LONG64 AdapterCount;
|
||||||
|
|
||||||
#if REG_DWORD == REG_DWORD_BIG_ENDIAN
|
#if REG_DWORD == REG_DWORD_BIG_ENDIAN
|
||||||
#define TUN_MEMORY_TAG 'wtun'
|
#define TUN_HTONS(x) ((USHORT)(x))
|
||||||
#define TunHtons(x) ((USHORT)(x))
|
#define TUN_HTONL(x) ((ULONG)(x))
|
||||||
#define TunHtonl(x) ((ULONG)(x))
|
|
||||||
#elif REG_DWORD == REG_DWORD_LITTLE_ENDIAN
|
#elif REG_DWORD == REG_DWORD_LITTLE_ENDIAN
|
||||||
#define TUN_MEMORY_TAG 'nutw'
|
#define TUN_HTONS(x) (((USHORT)(x) & 0x00ff) << 8 | ((USHORT)(x) & 0xff00) >> 8)
|
||||||
#define TunHtons(x) RtlUshortByteSwap(x)
|
#define TUN_HTONL(x) (((ULONG)(x) & 0x000000ff) << 24 | ((ULONG)(x) & 0x0000ff00) << 8 | ((ULONG)(x) & 0x00ff0000) >> 8 | ((ULONG)(x) & 0xff000000) >> 24)
|
||||||
#define TunHtonl(x) RtlUlongByteSwap(x)
|
|
||||||
#else
|
#else
|
||||||
#error "Unable to determine endianess"
|
#error "Unable to determine endianess"
|
||||||
#endif
|
#endif
|
||||||
@ -620,8 +619,8 @@ static NTSTATUS TunWriteFromIrp(_Inout_ TUN_CTX *ctx, _Inout_ IRP *Irp)
|
|||||||
ULONG nbl_flags;
|
ULONG nbl_flags;
|
||||||
USHORT nbl_proto;
|
USHORT nbl_proto;
|
||||||
} ether_const[ethtypeidx_end] = {
|
} ether_const[ethtypeidx_end] = {
|
||||||
{ NDIS_NBL_FLAGS_IS_IPV4, NDIS_ETH_TYPE_IPV4 },
|
{ NDIS_NBL_FLAGS_IS_IPV4, TUN_HTONS(NDIS_ETH_TYPE_IPV4) },
|
||||||
{ NDIS_NBL_FLAGS_IS_IPV6, NDIS_ETH_TYPE_IPV6 },
|
{ NDIS_NBL_FLAGS_IS_IPV6, TUN_HTONS(NDIS_ETH_TYPE_IPV6) },
|
||||||
};
|
};
|
||||||
struct {
|
struct {
|
||||||
NET_BUFFER_LIST *head, *tail;
|
NET_BUFFER_LIST *head, *tail;
|
||||||
@ -672,7 +671,7 @@ static NTSTATUS TunWriteFromIrp(_Inout_ TUN_CTX *ctx, _Inout_ IRP *Irp)
|
|||||||
|
|
||||||
nbl->SourceHandle = ctx->MiniportAdapterHandle;
|
nbl->SourceHandle = ctx->MiniportAdapterHandle;
|
||||||
NdisSetNblFlag(nbl, ether_const[idx].nbl_flags);
|
NdisSetNblFlag(nbl, ether_const[idx].nbl_flags);
|
||||||
NET_BUFFER_LIST_INFO(nbl, NetBufferListFrameType) = (PVOID)TunHtons(ether_const[idx].nbl_proto);
|
NET_BUFFER_LIST_INFO(nbl, NetBufferListFrameType) = (PVOID)ether_const[idx].nbl_proto;
|
||||||
NET_BUFFER_LIST_STATUS(nbl) = NDIS_STATUS_SUCCESS;
|
NET_BUFFER_LIST_STATUS(nbl) = NDIS_STATUS_SUCCESS;
|
||||||
NET_BUFFER_LIST_IRP(nbl) = Irp;
|
NET_BUFFER_LIST_IRP(nbl) = Irp;
|
||||||
TunAppendNBL(&nbl_queue[idx].head, &nbl_queue[idx].tail, nbl);
|
TunAppendNBL(&nbl_queue[idx].head, &nbl_queue[idx].tail, nbl);
|
||||||
@ -729,8 +728,8 @@ static void TunForceHandlesClosed(_Inout_ TUN_CTX *ctx)
|
|||||||
|
|
||||||
for (ULONG size = 0, req; (status = ZwQuerySystemInformation(SystemExtendedHandleInformation, table, size, &req)) == STATUS_INFO_LENGTH_MISMATCH; size = req) {
|
for (ULONG size = 0, req; (status = ZwQuerySystemInformation(SystemExtendedHandleInformation, table, size, &req)) == STATUS_INFO_LENGTH_MISMATCH; size = req) {
|
||||||
if (table)
|
if (table)
|
||||||
ExFreePoolWithTag(table, TUN_MEMORY_TAG);
|
ExFreePoolWithTag(table, TUN_HTONL(TUN_MEMORY_TAG));
|
||||||
table = ExAllocatePoolWithTag(PagedPool, req, TUN_MEMORY_TAG);
|
table = ExAllocatePoolWithTag(PagedPool, req, TUN_HTONL(TUN_MEMORY_TAG));
|
||||||
if (!table)
|
if (!table)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -756,7 +755,7 @@ static void TunForceHandlesClosed(_Inout_ TUN_CTX *ctx)
|
|||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
if (table)
|
if (table)
|
||||||
ExFreePoolWithTag(table, TUN_MEMORY_TAG);
|
ExFreePoolWithTag(table, TUN_HTONL(TUN_MEMORY_TAG));
|
||||||
}
|
}
|
||||||
|
|
||||||
static DRIVER_DISPATCH TunDispatch;
|
static DRIVER_DISPATCH TunDispatch;
|
||||||
@ -1147,7 +1146,7 @@ static NDIS_STATUS TunInitializeEx(NDIS_HANDLE MiniportAdapterHandle, NDIS_HANDL
|
|||||||
|
|
||||||
ctx->Device.Handle = handle;
|
ctx->Device.Handle = handle;
|
||||||
ctx->Device.Object = object;
|
ctx->Device.Object = object;
|
||||||
IoInitializeRemoveLock(&ctx->Device.RemoveLock, TUN_MEMORY_TAG, 0, 0);
|
IoInitializeRemoveLock(&ctx->Device.RemoveLock, TUN_HTONL(TUN_MEMORY_TAG), 0, 0);
|
||||||
KeInitializeSpinLock(&ctx->Device.ReadQueue.Lock);
|
KeInitializeSpinLock(&ctx->Device.ReadQueue.Lock);
|
||||||
IoCsqInitializeEx(&ctx->Device.ReadQueue.Csq,
|
IoCsqInitializeEx(&ctx->Device.ReadQueue.Csq,
|
||||||
TunCsqInsertIrpEx,
|
TunCsqInsertIrpEx,
|
||||||
@ -1168,7 +1167,7 @@ static NDIS_STATUS TunInitializeEx(NDIS_HANDLE MiniportAdapterHandle, NDIS_HANDL
|
|||||||
},
|
},
|
||||||
.ProtocolId = NDIS_PROTOCOL_ID_DEFAULT,
|
.ProtocolId = NDIS_PROTOCOL_ID_DEFAULT,
|
||||||
.fAllocateNetBuffer = TRUE,
|
.fAllocateNetBuffer = TRUE,
|
||||||
.PoolTag = TUN_MEMORY_TAG
|
.PoolTag = TUN_HTONL(TUN_MEMORY_TAG)
|
||||||
};
|
};
|
||||||
#pragma warning(suppress: 6014) /* Leaking memory 'ctx->NBLPool'. Note: 'ctx->NBLPool' is freed in TunHaltEx; or on failure. */
|
#pragma warning(suppress: 6014) /* Leaking memory 'ctx->NBLPool'. Note: 'ctx->NBLPool' is freed in TunHaltEx; or on failure. */
|
||||||
ctx->NBLPool = NdisAllocateNetBufferListPool(MiniportAdapterHandle, &nbl_pool_param);
|
ctx->NBLPool = NdisAllocateNetBufferListPool(MiniportAdapterHandle, &nbl_pool_param);
|
||||||
@ -1478,7 +1477,7 @@ static NDIS_STATUS TunOidQuery(_Inout_ TUN_CTX *ctx, _Inout_ NDIS_OID_REQUEST *O
|
|||||||
return TunOidQueryWrite(OidRequest, TUN_EXCH_MAX_IP_PACKET_SIZE * TUN_EXCH_MAX_PACKETS);
|
return TunOidQueryWrite(OidRequest, TUN_EXCH_MAX_IP_PACKET_SIZE * TUN_EXCH_MAX_PACKETS);
|
||||||
|
|
||||||
case OID_GEN_VENDOR_ID:
|
case OID_GEN_VENDOR_ID:
|
||||||
return TunOidQueryWrite(OidRequest, TunHtonl(TUN_VENDOR_ID));
|
return TunOidQueryWrite(OidRequest, TUN_HTONL(TUN_VENDOR_ID));
|
||||||
|
|
||||||
case OID_GEN_VENDOR_DESCRIPTION:
|
case OID_GEN_VENDOR_DESCRIPTION:
|
||||||
return TunOidQueryWriteBuf(OidRequest, TUN_VENDOR_NAME, (UINT)sizeof(TUN_VENDOR_NAME));
|
return TunOidQueryWriteBuf(OidRequest, TUN_VENDOR_NAME, (UINT)sizeof(TUN_VENDOR_NAME));
|
||||||
|
Loading…
Reference in New Issue
Block a user