2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS TCP/IP protocol driver
5 * PURPOSE: Internet Protocol related definitions
10 typedef VOID (*OBJECT_FREE_ROUTINE
)(PVOID Object
);
12 #define FOURCC(a,b,c,d) (((a)<<24)|((b)<<16)|((c)<<8)|(d))
14 /* Raw IPv4 style address */
15 typedef ULONG IPv4_RAW_ADDRESS
;
16 typedef IPv4_RAW_ADDRESS
*PIPv4_RAW_ADDRESS
;
18 /* Raw IPv6 style address */
19 typedef USHORT IPv6_RAW_ADDRESS
[8];
20 typedef IPv6_RAW_ADDRESS
*PIPv6_RAW_ADDRESS
;
22 /* IP style address */
23 typedef struct IP_ADDRESS
{
25 UCHAR Type
; /* Type of IP address */
27 IPv4_RAW_ADDRESS IPv4Address
; /* IPv4 address (in network byte order) */
28 PIPv6_RAW_ADDRESS IPv6Address
; /* IPv6 address (in network byte order) */
30 OBJECT_FREE_ROUTINE Free
; /* The free routine */
31 } IP_ADDRESS
, *PIP_ADDRESS
;
33 /* IP type constants */
34 #define IP_ADDRESS_V4 0x00 /* IPv4 style address */
35 #define IP_ADDRESS_V6 0x01 /* IPv6 style address */
38 /* IPv4 header format */
39 typedef struct IPv4_HEADER
{
40 UCHAR VerIHL
; /* 4-bit version, 4-bit Internet Header Length */
41 UCHAR Tos
; /* Type of Service */
42 USHORT TotalLength
; /* Total Length */
43 USHORT Id
; /* Identification */
44 USHORT FlagsFragOfs
; /* 3-bit Flags, 13-bit Fragment Offset */
45 UCHAR Ttl
; /* Time to Live */
46 UCHAR Protocol
; /* Protocol */
47 USHORT Checksum
; /* Header Checksum */
48 IPv4_RAW_ADDRESS SrcAddr
; /* Source Address */
49 IPv4_RAW_ADDRESS DstAddr
; /* Destination Address */
50 } IPv4_HEADER
, *PIPv4_HEADER
;
52 #define IPv4_FRAGOFS_MASK 0x1FFF /* Fragment offset mask (host byte order) */
53 #define IPv4_MF_MASK 0x2000 /* More fragments (host byte order) */
54 #define IPv4_DF_MASK 0x4000 /* Don't fragment (host byte order) */
55 #define IPv4_MAX_HEADER_SIZE 60
57 /* Packet completion handler prototype */
58 typedef VOID (*PACKET_COMPLETION_ROUTINE
)(
60 PNDIS_PACKET NdisPacket
,
61 NDIS_STATUS NdisStatus
);
63 /* Structure for an IP packet */
64 typedef struct _IP_PACKET
{
66 OBJECT_FREE_ROUTINE Free
; /* Routine used to free resources for the object */
67 UCHAR Type
; /* Type of IP packet (see IP_ADDRESS_xx above) */
68 UCHAR Flags
; /* Flags for packet (see IP_PACKET_FLAG_xx below)*/
69 PVOID Header
; /* Pointer to IP header for this packet */
70 UINT HeaderSize
; /* Size of IP header */
71 PVOID Data
; /* Current pointer into packet data */
72 UINT TotalSize
; /* Total amount of data in packet (IP header and data) */
73 UINT ContigSize
; /* Number of contiguous bytes left in current buffer */
74 UINT Position
; /* Current logical offset into packet */
75 PNDIS_PACKET NdisPacket
; /* Pointer to NDIS packet */
76 IP_ADDRESS SrcAddr
; /* Source address */
77 IP_ADDRESS DstAddr
; /* Destination address */
78 } IP_PACKET
, *PIP_PACKET
;
80 #define IP_PACKET_FLAG_RAW 0x01 /* Raw IP packet */
84 typedef struct _PACKET_CONTEXT
{
85 PACKET_COMPLETION_ROUTINE Complete
; /* Transport level completion handler */
86 PVOID Context
; /* Context information for handler */
87 PACKET_COMPLETION_ROUTINE DLComplete
; /* Data link level completion handler. Also
88 used to link to next packet in a queue */
89 UINT DLOffset
; /* Offset where data (IP header) starts */
90 } PACKET_CONTEXT
, *PPACKET_CONTEXT
;
92 /* The ProtocolReserved field is structured as a PACKET_CONTEXT */
93 #define PC(Packet) ((PPACKET_CONTEXT)(&Packet->ProtocolReserved))
95 /* Address information a.k.a ADE */
96 typedef struct _ADDRESS_ENTRY
{
98 LIST_ENTRY ListEntry
; /* Entry on list */
99 OBJECT_FREE_ROUTINE Free
; /* Routine used to free resources for the object */
100 struct _NET_TABLE_ENTRY
*NTE
; /* NTE associated with this address */
101 UCHAR Type
; /* Address type */
102 PIP_ADDRESS Address
; /* Pointer to address identifying this entry */
103 } ADDRESS_ENTRY
, *PADDRESS_ENTRY
;
105 /* Values for address type -- also the interface flags */
106 /* These values are mean to overlap meaningfully with the BSD ones */
107 #define ADE_UNICAST 0x01
108 #define ADE_MULTICAST 0x02
109 #define ADE_ADDRMASK 0x04
110 #define ADE_POINTOPOINT 0x10
112 /* There is one NTE for each source (unicast) address assigned to an interface */
113 typedef struct _NET_TABLE_ENTRY
{
115 LIST_ENTRY IFListEntry
; /* Entry on interface list */
116 LIST_ENTRY NTListEntry
; /* Entry on net table list */
117 struct _IP_INTERFACE
*Interface
; /* Pointer to interface on this net */
118 struct _PREFIX_LIST_ENTRY
*PLE
; /* Pointer to prefix list entry for this net */
119 OBJECT_FREE_ROUTINE Free
; /* Routine used to free resources for the object */
120 PIP_ADDRESS Address
; /* Pointer to unicast address for this net */
121 } NET_TABLE_ENTRY
, *PNET_TABLE_ENTRY
;
124 /* Link layer transmit prototype */
125 typedef VOID (*LL_TRANSMIT_ROUTINE
)(
127 PNDIS_PACKET NdisPacket
,
132 /* Link layer to IP binding information */
133 typedef struct _LLIP_BIND_INFO
{
134 PVOID Context
; /* Pointer to link layer context information */
135 UINT HeaderSize
; /* Size of link level header */
136 UINT MinFrameSize
; /* Minimum frame size in bytes */
137 UINT MTU
; /* Maximum transmission unit */
138 PUCHAR Address
; /* Pointer to interface address */
139 UINT AddressLength
; /* Length of address in bytes */
140 LL_TRANSMIT_ROUTINE Transmit
; /* Transmit function for this interface */
141 } LLIP_BIND_INFO
, *PLLIP_BIND_INFO
;
144 /* Information about an IP interface */
145 typedef struct _IP_INTERFACE
{
147 LIST_ENTRY NTEListHead
; /* List of NTEs on this interface */
148 LIST_ENTRY ADEListHead
; /* List of ADEs on this interface */
149 LIST_ENTRY ListEntry
; /* Entry on list */
150 OBJECT_FREE_ROUTINE Free
; /* Routine used to free resources used by the object */
151 KSPIN_LOCK Lock
; /* Spin lock for this object */
152 PVOID Context
; /* Pointer to link layer context information */
153 UINT HeaderSize
; /* Size of link level header */
154 UINT MinFrameSize
; /* Minimum frame size in bytes */
155 UINT MTU
; /* Maximum transmission unit */
156 PUCHAR Address
; /* Pointer to interface address */
157 UINT AddressLength
; /* Length of address in bytes */
158 LL_TRANSMIT_ROUTINE Transmit
; /* Pointer to transmit function */
160 PVOID TCPContext
; /* TCP Content for this interface */
161 } IP_INTERFACE
, *PIP_INTERFACE
;
164 #define IP_PROTOCOL_TABLE_SIZE 0x100
166 typedef VOID (*IP_PROTOCOL_HANDLER
)(
167 PNET_TABLE_ENTRY NTE
,
168 PIP_PACKET IPPacket
);
170 /* Loopback adapter address information (network byte order) */
171 #define LOOPBACK_ADDRESS_IPv4 ((IPv4_RAW_ADDRESS)DH2N(0x7F000001))
172 #define LOOPBACK_BCASTADDR_IPv4 ((IPv4_RAW_ADDRESS)DH2N(0x7F0000FF))
173 #define LOOPBACK_ADDRMASK_IPv4 ((IPv4_RAW_ADDRESS)DH2N(0xFFFFFF00))
175 /* Protocol definitions */
177 #define IPPROTO_RAW 0 /* Raw IP */
179 #define IPPROTO_ICMP 1 /* Internet Control Message Protocol */
180 #define IPPROTO_IGMP 2 /* Internet Group Management Protocol */
181 #define IPPROTO_TCP 6 /* Transmission Control Protocol */
182 #define IPPROTO_UDP 17 /* User Datagram Protocol */
184 /* Timeout timer constants */
185 #define IP_TICKS_SECOND 2 /* Two ticks per second */
186 #define IP_TIMEOUT (1000 / IP_TICKS_SECOND) /* Timeout in milliseconds */
189 extern LIST_ENTRY InterfaceListHead
;
190 extern KSPIN_LOCK InterfaceListLock
;
191 extern LIST_ENTRY NetTableListHead
;
192 extern KSPIN_LOCK NetTableListLock
;
193 extern UINT MaxLLHeaderSize
;
194 extern UINT MinLLFrameSize
;
196 PIP_PACKET
IPCreatePacket(
199 PIP_PACKET
IPInitializePacket(
203 PNET_TABLE_ENTRY
IPCreateNTE(
208 PIP_INTERFACE
IPCreateInterface(
209 PLLIP_BIND_INFO BindInfo
);
211 VOID
IPDestroyInterface(
214 BOOLEAN
IPRegisterInterface(
217 VOID
IPUnregisterInterface(
220 PNET_TABLE_ENTRY
IPLocateNTEOnInterface(
225 PNET_TABLE_ENTRY
IPLocateNTE(
229 PADDRESS_ENTRY
IPLocateADE(
233 PADDRESS_ENTRY
IPGetDefaultADE(
236 VOID STDCALL
IPTimeout( PVOID Context
);
238 VOID
IPDispatchProtocol(
239 PNET_TABLE_ENTRY NTE
,
240 PIP_PACKET IPPacket
);
242 VOID
IPRegisterProtocol(
244 IP_PROTOCOL_HANDLER Handler
);
246 NTSTATUS
IPStartup(PUNICODE_STRING RegistryPath
);
248 NTSTATUS
IPShutdown(VOID
);