b448b517c790ec9bed6f0601f0c6da286d3a8770
[reactos.git] / reactos / drivers / network / 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
8 #pragma once
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 UCHAR Type; /* Type of IP address */
25 union {
26 IPv4_RAW_ADDRESS IPv4Address;/* IPv4 address (in network byte order) */
27 IPv6_RAW_ADDRESS IPv6Address;/* IPv6 address (in network byte order) */
28 } Address;
29 } IP_ADDRESS, *PIP_ADDRESS;
30
31 /* IP type constants */
32 #define IP_ADDRESS_V4 0x04 /* IPv4 style address */
33 #define IP_ADDRESS_V6 0x06 /* IPv6 style address */
34
35
36 /* IPv4 header format */
37 typedef struct IPv4_HEADER {
38 UCHAR VerIHL; /* 4-bit version, 4-bit Internet Header Length */
39 UCHAR Tos; /* Type of Service */
40 USHORT TotalLength; /* Total Length */
41 USHORT Id; /* Identification */
42 USHORT FlagsFragOfs; /* 3-bit Flags, 13-bit Fragment Offset */
43 UCHAR Ttl; /* Time to Live */
44 UCHAR Protocol; /* Protocol */
45 USHORT Checksum; /* Header Checksum */
46 IPv4_RAW_ADDRESS SrcAddr; /* Source Address */
47 IPv4_RAW_ADDRESS DstAddr; /* Destination Address */
48 } IPv4_HEADER, *PIPv4_HEADER;
49
50 /* IPv6 header format */
51 typedef struct IPv6_HEADER {
52 ULONG VTF; /* Version, Traffic Class, Flow Label */
53 USHORT PayloadLength;
54 UCHAR NextHeader; /* Same as Protocol in IPv4 */
55 UCHAR HopLimit; /* Same as Ttl in IPv4 */
56 IPv6_RAW_ADDRESS SrcAddr;
57 IPv6_RAW_ADDRESS DstAddr;
58 } IPv6_HEADER, *PIPv6_HEADER;
59
60 typedef union _IP_HEADER {
61 IPv4_HEADER v4;
62 IPv6_HEADER v6;
63 } IP_HEADER, *PIP_HEADER;
64
65 #define IPv4_FRAGOFS_MASK 0x1FFF /* Fragment offset mask (host byte order) */
66 #define IPv4_MF_MASK 0x2000 /* More fragments (host byte order) */
67 #define IPv4_DF_MASK 0x4000 /* Don't fragment (host byte order) */
68 #define IPv4_MAX_HEADER_SIZE 60
69
70 /* Packet completion handler prototype */
71 typedef VOID (*PACKET_COMPLETION_ROUTINE)(
72 PVOID Context,
73 PNDIS_PACKET NdisPacket,
74 NDIS_STATUS NdisStatus);
75
76 /* Structure for an IP packet */
77 typedef struct _IP_PACKET {
78 OBJECT_FREE_ROUTINE Free; /* Routine used to free resources for the object */
79 UCHAR Type; /* Type of IP packet (see IP_ADDRESS_xx above) */
80 UCHAR Flags; /* Flags for packet (see IP_PACKET_FLAG_xx below)*/
81 BOOLEAN MappedHeader; /* States whether Header is from an MDL or allocated from pool */
82 BOOLEAN ReturnPacket; /* States whether NdisPacket should be passed to NdisReturnPackets */
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 Position; /* Current logical offset into packet */
88 PNDIS_PACKET NdisPacket; /* Pointer to NDIS packet */
89 IP_ADDRESS SrcAddr; /* Source address */
90 IP_ADDRESS DstAddr; /* Destination address */
91 } IP_PACKET, *PIP_PACKET;
92
93 #define IP_PACKET_FLAG_RAW 0x01 /* Raw IP packet */
94
95
96 /* Packet context */
97 typedef struct _PACKET_CONTEXT {
98 PACKET_COMPLETION_ROUTINE DLComplete; /* Data link level completion handler
99 * Also used to link to next packet
100 * in a queue */
101 PVOID Context; /* Context information for handler */
102 UINT PacketType; /* Type of packet */
103 } PACKET_CONTEXT, *PPACKET_CONTEXT;
104
105 /* The ProtocolReserved field is structured as a PACKET_CONTEXT */
106 #define PC(Packet) ((PPACKET_CONTEXT)(&Packet->ProtocolReserved))
107
108 /* Values for address type -- also the interface flags */
109 /* These values are mean to overlap meaningfully with the BSD ones */
110 #define ADE_UNICAST 0x01
111 #define ADE_BROADCAST 0x02
112 #define ADE_ADDRMASK 0x04
113 #define ADE_POINTOPOINT 0x10
114 #define ADE_MULTICAST 0x8000
115
116 /* There is one NTE for each source (unicast) address assigned to an interface */
117 /* Link layer transmit prototype */
118 typedef VOID (*LL_TRANSMIT_ROUTINE)(
119 PVOID Context,
120 PNDIS_PACKET NdisPacket,
121 UINT Offset,
122 PVOID LinkAddress,
123 USHORT Type);
124
125 /* Link layer to IP binding information */
126 typedef struct _LLIP_BIND_INFO {
127 PVOID Context; /* Pointer to link layer context information */
128 UINT HeaderSize; /* Size of link level header */
129 UINT MinFrameSize; /* Minimum frame size in bytes */
130 UINT MTU; /* Maximum transmission unit */
131 PUCHAR Address; /* Pointer to interface address */
132 UINT AddressLength; /* Length of address in bytes */
133 LL_TRANSMIT_ROUTINE Transmit; /* Transmit function for this interface */
134 } LLIP_BIND_INFO, *PLLIP_BIND_INFO;
135
136 typedef struct _SEND_RECV_STATS {
137 UINT InBytes;
138 UINT InUnicast;
139 UINT InNUnicast;
140 UINT InDiscarded;
141 UINT InErrors;
142 UINT InDiscardedUnknownProto;
143 UINT OutBytes;
144 UINT OutUnicast;
145 UINT OutNUnicast;
146 UINT OutDiscarded;
147 UINT OutErrors;
148 } SEND_RECV_STATS, *PSEND_RECV_STATS;
149
150 /* Information about an IP interface */
151 typedef struct _IP_INTERFACE {
152 LIST_ENTRY ListEntry; /* Entry on list */
153 OBJECT_FREE_ROUTINE Free; /* Routine used to free resources used by the object */
154 KSPIN_LOCK Lock; /* Spin lock for this object */
155 PVOID Context; /* Pointer to link layer context information */
156 UINT HeaderSize; /* Size of link level header */
157 UINT MinFrameSize; /* Minimum frame size in bytes */
158 UINT MTU; /* Maximum transmission unit */
159 UINT Speed; /* Link speed */
160 IP_ADDRESS Unicast; /* Unicast address */
161 IP_ADDRESS PointToPoint; /* Point to point address */
162 IP_ADDRESS Netmask; /* Netmask */
163 IP_ADDRESS Broadcast; /* Broadcast */
164 UNICODE_STRING Name; /* Adapter name (GUID) */
165 UNICODE_STRING Description; /* Adapter description (Human readable) */
166 PUCHAR Address; /* Pointer to interface address */
167 UINT AddressLength; /* Length of address in bytes */
168 UINT Index; /* Index of adapter (used to add ip addr) */
169 LL_TRANSMIT_ROUTINE Transmit; /* Pointer to transmit function */
170 PVOID TCPContext; /* TCP Content for this interface */
171 SEND_RECV_STATS Stats; /* Send/Receive statistics */
172 } IP_INTERFACE, *PIP_INTERFACE;
173
174 typedef struct _IP_SET_ADDRESS {
175 ULONG NteIndex;
176 IPv4_RAW_ADDRESS Address;
177 IPv4_RAW_ADDRESS Netmask;
178 } IP_SET_ADDRESS, *PIP_SET_ADDRESS;
179
180 #define IP_PROTOCOL_TABLE_SIZE 0x100
181
182 typedef VOID (*IP_PROTOCOL_HANDLER)(
183 PIP_INTERFACE Interface,
184 PIP_PACKET IPPacket);
185
186 /* Loopback adapter address information (network byte order) */
187 #define LOOPBACK_ADDRESS_IPv4 ((IPv4_RAW_ADDRESS)DH2N(0x7F000001))
188 #define LOOPBACK_BCASTADDR_IPv4 ((IPv4_RAW_ADDRESS)DH2N(0x7FFFFFFF))
189 #define LOOPBACK_ADDRMASK_IPv4 ((IPv4_RAW_ADDRESS)DH2N(0xFF000000))
190
191 /* Protocol definitions */
192 #ifndef IPPROTO_RAW
193 #define IPPROTO_RAW 0 /* Raw IP */
194 #endif
195 #define IPPROTO_ICMP 1 /* Internet Control Message Protocol */
196 #define IPPROTO_IGMP 2 /* Internet Group Management Protocol */
197 #define IPPROTO_TCP 6 /* Transmission Control Protocol */
198 #define IPPROTO_UDP 17 /* User Datagram Protocol */
199
200 /* Timeout timer constants */
201 #define IP_TIMEOUT 1000 /* Timeout in milliseconds */
202 #define IP_DEFAULT_LINK_SPEED 10000
203
204 extern LIST_ENTRY InterfaceListHead;
205 extern KSPIN_LOCK InterfaceListLock;
206 extern LIST_ENTRY NetTableListHead;
207 extern KSPIN_LOCK NetTableListLock;
208
209 PIP_PACKET IPCreatePacket(
210 ULONG Type);
211
212 PIP_PACKET IPInitializePacket(
213 PIP_PACKET IPPacket,
214 ULONG Type);
215
216 PIP_INTERFACE IPCreateInterface(
217 PLLIP_BIND_INFO BindInfo);
218
219 VOID IPAddInterfaceRoute(
220 PIP_INTERFACE IF);
221
222 VOID IPRemoveInterfaceRoute(
223 PIP_INTERFACE IF);
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 VOID NTAPI IPTimeoutDpcFn(PKDPC Dpc,
235 PVOID DeferredContext,
236 PVOID SystemArgument1,
237 PVOID SystemArgument2);
238
239 VOID IPDispatchProtocol(
240 PIP_INTERFACE Interface,
241 PIP_PACKET IPPacket);
242
243 VOID IPRegisterProtocol(
244 UINT ProtocolNumber,
245 IP_PROTOCOL_HANDLER Handler);
246
247 NTSTATUS IPStartup(PUNICODE_STRING RegistryPath);
248
249 NTSTATUS IPShutdown(VOID);
250
251 /* EOF */