178 lines
4.6 KiB
C
178 lines
4.6 KiB
C
// Public NTLite net stack ABI declarations shared between kernel, drivers, and user mode.
|
|
|
|
#pragma once
|
|
// net_stack.h - provider interface between kernel socket facade and network stack drivers.
|
|
|
|
// The kernel owns process handles, user-memory copying, NET_DEVICE registration,
|
|
// and SOCKET_OBJECT lifetime. A stack driver owns protocol implementation behind
|
|
// a DEVICE_OBJECT so socket operations enter the same IRP pipe as other I/O.
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <ntlite/status.h>
|
|
#include <ntlite/ddi/net_device.h>
|
|
#include <ntlite/ddi/net_abi.h>
|
|
|
|
struct DEVICE_OBJECT;
|
|
|
|
#define NET_STACK_PROVIDER_VERSION 2u
|
|
#define NET_IOCTL_SOCKET 0x4E455401u
|
|
|
|
typedef enum NET_SOCKET_IRP_OPERATION {
|
|
NetSocketIrpInvalid = 0,
|
|
NetSocketIrpCreate = 1,
|
|
NetSocketIrpClose = 2,
|
|
NetSocketIrpBind = 3,
|
|
NetSocketIrpListen = 4,
|
|
NetSocketIrpAccept = 5,
|
|
NetSocketIrpConnect = 6,
|
|
NetSocketIrpSend = 7,
|
|
NetSocketIrpReceive = 8,
|
|
NetSocketIrpSendTo = 9,
|
|
NetSocketIrpReceiveFrom = 10,
|
|
NetSocketIrpShutdown = 11,
|
|
NetSocketIrpSetOption = 12,
|
|
NetSocketIrpGetOption = 13,
|
|
NetSocketIrpPoll = 14,
|
|
NetSocketIrpResolveHost = 15,
|
|
NetSocketIrpOperationCount,
|
|
} NET_SOCKET_IRP_OPERATION;
|
|
|
|
typedef struct NET_SOCKET_IRP_REQUEST {
|
|
uint32_t Size;
|
|
uint32_t Operation;
|
|
volatile uint8_t* CancelRequested;
|
|
|
|
union {
|
|
struct {
|
|
uint32_t Domain;
|
|
uint32_t Type;
|
|
uint32_t Protocol;
|
|
void** ProviderSocketOut;
|
|
} Create;
|
|
|
|
struct {
|
|
void* Socket;
|
|
} Close;
|
|
|
|
struct {
|
|
void* Socket;
|
|
const SYS_SOCKET_ADDRESS_K* Address;
|
|
size_t AddressSize;
|
|
} Bind;
|
|
|
|
struct {
|
|
void* Socket;
|
|
uint32_t Backlog;
|
|
} Listen;
|
|
|
|
struct {
|
|
void* Socket;
|
|
void** AcceptedOut;
|
|
SYS_SOCKET_ADDRESS_K* RemoteOut;
|
|
} Accept;
|
|
|
|
struct {
|
|
void* Socket;
|
|
const SYS_SOCKET_ADDRESS_K* Address;
|
|
size_t AddressSize;
|
|
} Connect;
|
|
|
|
struct {
|
|
void* Socket;
|
|
const void* Buffer;
|
|
size_t Length;
|
|
uint32_t Flags;
|
|
size_t* SentOut;
|
|
} Send;
|
|
|
|
struct {
|
|
void* Socket;
|
|
void* Buffer;
|
|
size_t Length;
|
|
uint32_t Flags;
|
|
size_t* ReceivedOut;
|
|
} Receive;
|
|
|
|
struct {
|
|
void* Socket;
|
|
const void* Buffer;
|
|
size_t Length;
|
|
uint32_t Flags;
|
|
const SYS_SOCKET_ADDRESS_K* Remote;
|
|
size_t RemoteSize;
|
|
size_t* SentOut;
|
|
} SendTo;
|
|
|
|
struct {
|
|
void* Socket;
|
|
void* Buffer;
|
|
size_t Length;
|
|
uint32_t Flags;
|
|
SYS_SOCKET_ADDRESS_K* RemoteOut;
|
|
size_t* ReceivedOut;
|
|
} ReceiveFrom;
|
|
|
|
struct {
|
|
void* Socket;
|
|
uint32_t How;
|
|
} Shutdown;
|
|
|
|
struct {
|
|
void* Socket;
|
|
uint32_t Option;
|
|
const void* Value;
|
|
size_t ValueSize;
|
|
} SetOption;
|
|
|
|
struct {
|
|
void* Socket;
|
|
uint32_t Option;
|
|
void* Value;
|
|
size_t ValueSize;
|
|
size_t* ActualSizeOut;
|
|
} GetOption;
|
|
|
|
struct {
|
|
void* Socket;
|
|
uint32_t Events;
|
|
uint32_t* ReturnedEventsOut;
|
|
} Poll;
|
|
|
|
struct {
|
|
const char* Name;
|
|
uint32_t Family;
|
|
SYS_SOCKET_ADDRESS_K* AddressOut;
|
|
} ResolveHost;
|
|
} u;
|
|
} NET_SOCKET_IRP_REQUEST;
|
|
|
|
typedef struct NET_IRP_STATS {
|
|
uint64_t Submitted;
|
|
uint64_t Completed;
|
|
uint64_t CompletedSynchronously;
|
|
uint64_t CompletedAsynchronously;
|
|
uint64_t Pending;
|
|
uint64_t CancelRequested;
|
|
uint64_t Cancelled;
|
|
uint64_t WouldBlock;
|
|
uint64_t Timeout;
|
|
uint64_t Failed;
|
|
uint64_t ByOperation[NetSocketIrpOperationCount];
|
|
} NET_IRP_STATS;
|
|
|
|
typedef struct NET_STACK_PROVIDER NET_STACK_PROVIDER;
|
|
|
|
struct NET_STACK_PROVIDER {
|
|
uint32_t Version;
|
|
const char* Name;
|
|
struct DEVICE_OBJECT* StackDevice;
|
|
|
|
KSTATUS (*AttachDevice)(NET_DEVICE* device);
|
|
KSTATUS (*ReceiveFrame)(NET_DEVICE* device, const void* frame, size_t length);
|
|
};
|
|
|
|
__declspec(dllexport) KSTATUS NetRegisterStackProvider(const NET_STACK_PROVIDER* provider);
|
|
__declspec(dllexport) const NET_STACK_PROVIDER* NetGetStackProvider(void);
|
|
__declspec(dllexport) void NetQueryIrpStats(NET_IRP_STATS* out);
|