8b2711cac7a3b68c250665296d800876a9b152dd
[reactos.git] / reactos / drivers / net / tcpip / include / ip.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS TCP/IP protocol driver
4 * FILE: include/ip.h
5 * PURPOSE: Internet Protocol related definitions
6 */
7 #ifndef __IP_H
8 #define __IP_H
9
10 typedef VOID (*OBJECT_FREE_ROUTINE)(PVOID Object);
11
12 #define FOURCC(a,b,c,d) (((a)<<24)|((b)<<16)|((c)<<8)|(d))
13
14 /* Raw IPv4 style address */
15 typedef ULONG IPv4_RAW_ADDRESS;
16 typedef IPv4_RAW_ADDRESS *PIPv4_RAW_ADDRESS;
17
18 /* Raw IPv6 style address */
19 typedef USHORT IPv6_RAW_ADDRESS[8];
20 typedef IPv6_RAW_ADDRESS *PIPv6_RAW_ADDRESS;
21
22 /* IP style address */
23 typedef struct IP_ADDRESS {
24 DEFINE_TAG
25 UCHAR Type; /* Type of IP address */
26 union {
27 IPv4_RAW_ADDRESS IPv4Address;/* IPv4 address (in network byte order) */
28 IPv6_RAW_ADDRESS IPv6Address;/* IPv6 address (in network byte order) */
29 } Address;
30 } IP_ADDRESS, *PIP_ADDRESS;
31
32 /* IP type constants */
33 #define IP_ADDRESS_V4 0x04 /* IPv4 style address */
34 #define IP_ADDRESS_V6 0x06 /* IPv6 style address */
35
36
37 /* IPv4 header format */
38 typedef struct IPv4_HEADER {
39 UCHAR VerIHL; /* 4-bit version, 4-bit Internet Header Length */
40 UCHAR Tos; /* Type of Service */
41 USHORT TotalLength; /* Total Length */
42 USHORT Id; /* Identification */
43 USHORT FlagsFragOfs; /* 3-bit Flags, 13-bit Fragment Offset */
44 UCHAR Ttl; /* Time to Live */
45 UCHAR Protocol; /* Protocol */
46 USHORT Checksum; /* Header Checksum */
47 IPv4_RAW_ADDRESS SrcAddr; /* Source Address */
48 IPv4_RAW_ADDRESS DstAddr; /* Destination Address */
49 } IPv4_HEADER, *PIPv4_HEADER;
50
51 /* IPv6 header format */
52 typedef struct IPv6_HEADER {
53 ULONG VTF; /* Version, Traffic Class, Flow Label */
54 USHORT PayloadLength;
55 UCHAR NextHeader; /* Same as Protocol in IPv4 */
56 UCHAR HopLimit; /* Same as Ttl in IPv4 */
57 IPv6_RAW_ADDRESS SrcAddr;
58 IPv6_RAW_ADDRESS DstAddr;
59 } IPv6_HEADER, *PIPv6_HEADER;
60
61 typedef union _IP_HEADER {
62 IPv4_HEADER v4;
63 IPv6_HEADER v6;
64 } IP_HEADER, *PIP_HEADER;
65
66 #define IPv4_FRAGOFS_MASK 0x1FFF /* Fragment offset mask (host byte order) */
67 #define IPv4_MF_MASK 0x2000 /* More fragments (host byte order) */
68 #define IPv4_DF_MASK 0x4000 /* Don't fragment (host byte order) */
69 #define IPv4_MAX_HEADER_SIZE 60
70
71 /* Packet completion handler prototype */
72 typedef VOID (*PACKET_COMPLETION_ROUTINE)(
73 PVOID Context,
74 PNDIS_PACKET NdisPacket,
75 NDIS_STATUS NdisStatus);
76
77 /* Structure for an IP packet */
78 typedef struct _IP_PACKET {
79 DEFINE_TAG
80 OBJECT_FREE_ROUTINE Free; /* Routine used to free resources for the object */
81 UCHAR Type; /* Type of IP packet (see IP_ADDRESS_xx above) */
82 UCHAR Flags; /* Flags for packet (see IP_PACKET_FLAG_xx below)*/
83 PVOID Header; /* Pointer to IP header for this packet */
84 UINT HeaderSize; /* Size of IP header */
85 PVOID Data; /* Current pointer into packet data */
86 UINT TotalSize; /* Total amount of data in packet (IP header and data) */
87 UINT ContigSize; /* Number of contiguous bytes left in current buffer */
88 UINT Position; /* Current logical offset into packet */
89 PNDIS_PACKET NdisPacket; /* Pointer to NDIS packet */
90 IP_ADDRESS SrcAddr; /* Source address */
91 IP_ADDRESS DstAddr; /* Destination address */
92 } IP_PACKET, *PIP_PACKET;
93
94 #define IP_PACKET_FLAG_RAW 0x01 /* Raw IP packet */
95
96
97 /* Packet context */
98 typedef struct _PACKET_CONTEXT {
99 PACKET_COMPLETION_ROUTINE DLComplete; /* Data link level completion handler
100 * Also used to link to next packet
101 * in a queue */
102 PVOID Context; /* Context information for handler */
103 UINT PacketType; /* Type of packet */
104 } PACKET_CONTEXT, *PPACKET_CONTEXT;
105
106 /* The ProtocolReserved field is structured as a PACKET_CONTEXT */
107 #define PC(Packet) ((PPACKET_CONTEXT)(&Packet->ProtocolReserved))
108
109 /* Address information a.k.a ADE */
110 typedef struct _ADDRESS_ENTRY {
111 DEFINE_TAG
112 LIST_ENTRY ListEntry; /* Entry on list */
113 OBJECT_FREE_ROUTINE Free; /* Routine used to free resources for the object */
114 struct _NET_TABLE_ENTRY *NTE; /* NTE associated with this address */
115 UCHAR Type; /* Address type */
116 IP_ADDRESS Address; /* Pointer to address identifying this entry */
117 } ADDRESS_ENTRY, *PADDRESS_ENTRY;
118
119 /* Values for address type -- also the interface flags */
120 /* These values are mean to overlap meaningfully with the BSD ones */
121 #define ADE_UNICAST 0x01
122 #define ADE_MULTICAST 0x02
123 #define ADE_ADDRMASK 0x04
124 #define ADE_POINTOPOINT 0x10
125
126 /* There is one NTE for each source (unicast) address assigned to an interface */
127 typedef struct _NET_TABLE_ENTRY {
128 DEFINE_TAG
129 LIST_ENTRY IFListEntry; /* Entry on interface list */
130 LIST_ENTRY NTListEntry; /* Entry on net table list */
131 struct _IP_INTERFACE *Interface; /* Pointer to interface on this net */
132 struct _PREFIX_LIST_ENTRY *PLE; /* Pointer to prefix list entry for this net */
133 OBJECT_FREE_ROUTINE Free; /* Routine used to free resources for the object */
134 PIP_ADDRESS Address; /* Pointer to unicast address for this net */
135 } NET_TABLE_ENTRY, *PNET_TABLE_ENTRY;
136
137
138 /* Link layer transmit prototype */
139 typedef VOID (*LL_TRANSMIT_ROUTINE)(
140 PVOID Context,
141 PNDIS_PACKET NdisPacket,
142 UINT Offset,
143 PVOID LinkAddress,
144 USHORT Type);
145
146 /* Link layer to IP binding information */
147 typedef struct _LLIP_BIND_INFO {
148 PVOID Context; /* Pointer to link layer context information */
149 UINT HeaderSize; /* Size of link level header */
150 UINT MinFrameSize; /* Minimum frame size in bytes */
151 UINT MTU; /* Maximum transmission unit */
152 PUCHAR Address; /* Pointer to interface address */
153 UINT AddressLength; /* Length of address in bytes */
154 LL_TRANSMIT_ROUTINE Transmit; /* Transmit function for this interface */
155 } LLIP_BIND_INFO, *PLLIP_BIND_INFO;
156
157
158 /* Information about an IP interface */
159 typedef struct _IP_INTERFACE {
160 DEFINE_TAG
161 LIST_ENTRY NTEListHead; /* List of NTEs on this interface */
162 LIST_ENTRY ADEListHead; /* List of ADEs on this interface */
163 LIST_ENTRY ListEntry; /* Entry on list */
164 OBJECT_FREE_ROUTINE Free; /* Routine used to free resources used by the object */
165 KSPIN_LOCK Lock; /* Spin lock for this object */
166 PVOID Context; /* Pointer to link layer context information */
167 UINT HeaderSize; /* Size of link level header */
168 UINT MinFrameSize; /* Minimum frame size in bytes */
169 UINT MTU; /* Maximum transmission unit */
170 PUCHAR Address; /* Pointer to interface address */
171 UINT AddressLength; /* Length of address in bytes */
172 LL_TRANSMIT_ROUTINE Transmit; /* Pointer to transmit function */
173
174 PVOID TCPContext; /* TCP Content for this interface */
175 } IP_INTERFACE, *PIP_INTERFACE;
176
177
178 #define IP_PROTOCOL_TABLE_SIZE 0x100
179
180 typedef VOID (*IP_PROTOCOL_HANDLER)(
181 PNET_TABLE_ENTRY NTE,
182 PIP_PACKET IPPacket);
183
184 /* Loopback adapter address information (network byte order) */
185 #define LOOPBACK_ADDRESS_IPv4 ((IPv4_RAW_ADDRESS)DH2N(0x7F000001))
186 #define LOOPBACK_BCASTADDR_IPv4 ((IPv4_RAW_ADDRESS)DH2N(0x7F0000FF))
187 #define LOOPBACK_ADDRMASK_IPv4 ((IPv4_RAW_ADDRESS)DH2N(0xFFFFFF00))
188
189 /* Protocol definitions */
190 #ifndef IPPROTO_RAW
191 #define IPPROTO_RAW 0 /* Raw IP */
192 #endif
193 #define IPPROTO_ICMP 1 /* Internet Control Message Protocol */
194 #define IPPROTO_IGMP 2 /* Internet Group Management Protocol */
195 #define IPPROTO_TCP 6 /* Transmission Control Protocol */
196 #define IPPROTO_UDP 17 /* User Datagram Protocol */
197
198 /* Timeout timer constants */
199 #define IP_TICKS_SECOND 2 /* Two ticks per second */
200 #define IP_TIMEOUT (1000 / IP_TICKS_SECOND) /* Timeout in milliseconds */
201
202
203 extern LIST_ENTRY InterfaceListHead;
204 extern KSPIN_LOCK InterfaceListLock;
205 extern LIST_ENTRY NetTableListHead;
206 extern KSPIN_LOCK NetTableListLock;
207 extern UINT MaxLLHeaderSize;
208 extern UINT MinLLFrameSize;
209
210 PIP_PACKET IPCreatePacket(
211 ULONG Type);
212
213 PIP_PACKET IPInitializePacket(
214 PIP_PACKET IPPacket,
215 ULONG Type);
216
217 PNET_TABLE_ENTRY IPCreateNTE(
218 PIP_INTERFACE IF,
219 PIP_ADDRESS Address,
220 UINT PrefixLength);
221
222 PIP_INTERFACE IPCreateInterface(
223 PLLIP_BIND_INFO BindInfo);
224
225 VOID IPDestroyInterface(
226 PIP_INTERFACE IF);
227
228 BOOLEAN IPRegisterInterface(
229 PIP_INTERFACE IF);
230
231 VOID IPUnregisterInterface(
232 PIP_INTERFACE IF);
233
234 PNET_TABLE_ENTRY IPLocateNTEOnInterface(
235 PIP_INTERFACE IF,
236 PIP_ADDRESS Address,
237 PUINT AddressType);
238
239 PNET_TABLE_ENTRY IPLocateNTE(
240 PIP_ADDRESS Address,
241 PUINT AddressType);
242
243 PADDRESS_ENTRY IPLocateADE(
244 PIP_ADDRESS Address,
245 UINT AddressType);
246
247 PADDRESS_ENTRY IPGetDefaultADE(
248 UINT AddressType);
249
250 VOID STDCALL IPTimeout( PVOID Context );
251
252 VOID IPDispatchProtocol(
253 PNET_TABLE_ENTRY NTE,
254 PIP_PACKET IPPacket);
255
256 VOID IPRegisterProtocol(
257 UINT ProtocolNumber,
258 IP_PROTOCOL_HANDLER Handler);
259
260 NTSTATUS IPStartup(PUNICODE_STRING RegistryPath);
261
262 NTSTATUS IPShutdown(VOID);
263
264
265
266 #endif /* __IP_H */
267
268 /* EOF */