:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / 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
13 /* Raw IPv4 style address */
14 typedef ULONG IPv4_RAW_ADDRESS;
15 typedef IPv4_RAW_ADDRESS *PIPv4_RAW_ADDRESS;
16
17 /* Raw IPv6 style address */
18 typedef USHORT IPv6_RAW_ADDRESS[8];
19 typedef IPv6_RAW_ADDRESS *PIPv6_RAW_ADDRESS;
20
21 /* IP style address */
22 typedef struct IP_ADDRESS {
23     DEFINE_TAG
24     ULONG RefCount;                     /* Number of references to this address */
25     UCHAR Type;                         /* Type of IP address */
26     union {
27         IPv4_RAW_ADDRESS IPv4Address;   /* IPv4 address (in network byte order) */
28         PIPv6_RAW_ADDRESS IPv6Address;  /* IPv6 address (in network byte order) */
29     } Address;
30     OBJECT_FREE_ROUTINE Free;           /* The free routine */
31 } IP_ADDRESS, *PIP_ADDRESS;
32
33 /* IP type constants */
34 #define IP_ADDRESS_V4   0x00 /* IPv4 style address */
35 #define IP_ADDRESS_V6   0x01 /* IPv6 style address */
36
37
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;
51
52 #define IPv4_FRAGOFS_MASK       0x1FFF
53 #define IPv4_MF_MASK            0x2000
54 #define IPv4_MAX_HEADER_SIZE    60
55
56 /* Packet completion handler prototype */
57 typedef VOID (*PACKET_COMPLETION_ROUTINE)(
58     PVOID Context,
59     PNDIS_PACKET NdisPacket,
60     NDIS_STATUS NdisStatus);
61
62 /* Structure for an IP packet */
63 typedef struct IP_PACKET {
64     DEFINE_TAG
65     ULONG RefCount;                     /* Reference count for this object */
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;
79
80 #define IP_PACKET_FLAG_RAW      0x01    /* Raw IP packet */
81
82
83 /* Packet context */
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;
91
92 /* The ProtocolReserved field is structured as a PACKET_CONTEXT */
93 #define PC(Packet) ((PPACKET_CONTEXT)(&Packet->ProtocolReserved))
94
95
96 /* Address information a.k.a ADE */
97 typedef struct _ADDRESS_ENTRY {
98     DEFINE_TAG
99     LIST_ENTRY              ListEntry;  /* Entry on list */
100     ULONG                   RefCount;   /* Reference count */
101     OBJECT_FREE_ROUTINE     Free;       /* Routine used to free resources for the object */
102     struct _NET_TABLE_ENTRY *NTE;       /* NTE associated with this address */
103     UCHAR                   Type;       /* Address type */
104     PIP_ADDRESS             Address;    /* Pointer to address identifying this entry */
105 } ADDRESS_ENTRY, *PADDRESS_ENTRY;
106
107 /* Values for address type */
108 #define ADE_UNICAST   0x01
109 #define ADE_MULTICAST 0x02
110 #define ADE_ADDRMASK  0x03
111
112 /* There is one NTE for each source (unicast) address assigned to an interface */
113 typedef struct _NET_TABLE_ENTRY {
114     DEFINE_TAG
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     ULONG                      RefCount;    /* Reference count */
120     OBJECT_FREE_ROUTINE        Free;        /* Routine used to free resources for the object */
121     PIP_ADDRESS                Address;     /* Pointer to unicast address for this net */
122 } NET_TABLE_ENTRY, *PNET_TABLE_ENTRY;
123
124
125 /* Link layer transmit prototype */
126 typedef VOID (*LL_TRANSMIT_ROUTINE)(
127     PVOID Context,
128     PNDIS_PACKET NdisPacket,
129     UINT Offset,
130     PVOID LinkAddress,
131     USHORT Type);
132
133 /* Link layer to IP binding information */
134 typedef struct _LLIP_BIND_INFO {
135     PVOID Context;                /* Pointer to link layer context information */
136     UINT  HeaderSize;             /* Size of link level header */
137     UINT  MinFrameSize;           /* Minimum frame size in bytes */
138     UINT  MTU;                    /* Maximum transmission unit */
139     PUCHAR Address;               /* Pointer to interface address */
140     UINT  AddressLength;          /* Length of address in bytes */
141     LL_TRANSMIT_ROUTINE Transmit; /* Transmit function for this interface */
142 } LLIP_BIND_INFO, *PLLIP_BIND_INFO;
143
144
145 /* Information about an IP interface */
146 typedef struct _IP_INTERFACE {
147     DEFINE_TAG
148     LIST_ENTRY ListEntry;         /* Entry on list */
149     ULONG RefCount;               /* Reference count */
150     OBJECT_FREE_ROUTINE Free;     /* Routine used to free resources used by the object */
151     KSPIN_LOCK Lock;              /* Spin lock for this object */
152     LIST_ENTRY NTEListHead;       /* List of NTEs on this interface */
153     LIST_ENTRY ADEListHead;       /* List of ADEs on this interface */
154     PVOID Context;                /* Pointer to link layer context information */
155     UINT  HeaderSize;             /* Size of link level header */
156     UINT  MinFrameSize;           /* Minimum frame size in bytes */
157     UINT  MTU;                    /* Maximum transmission unit */
158     PUCHAR Address;               /* Pointer to interface address */
159     UINT  AddressLength;          /* Length of address in bytes */
160     LL_TRANSMIT_ROUTINE Transmit; /* Pointer to transmit function */
161 } IP_INTERFACE, *PIP_INTERFACE;
162
163
164 /* Prefix List Entry */
165 typedef struct _PREFIX_LIST_ENTRY {
166     DEFINE_TAG
167     LIST_ENTRY ListEntry;    /* Entry on list */
168     ULONG RefCount;          /* Reference count */
169     PIP_INTERFACE Interface; /* Pointer to interface */
170     PIP_ADDRESS Prefix;      /* Pointer to prefix */
171     UINT PrefixLength;       /* Length of prefix */
172 } PREFIX_LIST_ENTRY, *PPREFIX_LIST_ENTRY;
173
174
175 #define IP_PROTOCOL_TABLE_SIZE 0x100
176
177 typedef VOID (*IP_PROTOCOL_HANDLER)(
178     PNET_TABLE_ENTRY NTE,
179     PIP_PACKET IPPacket);
180
181 /* Loopback adapter address information (network byte order) */
182 #define LOOPBACK_ADDRESS_IPv4   ((IPv4_RAW_ADDRESS)DH2N(0x7F000001))
183 #define LOOPBACK_BCASTADDR_IPv4 ((IPv4_RAW_ADDRESS)DH2N(0x7F0000FF))
184 #define LOOPBACK_ADDRMASK_IPv4  ((IPv4_RAW_ADDRESS)DH2N(0xFFFFFF00))
185
186 /* Protocol definitions */
187 #define IPPROTO_RAW     0   /* Raw IP */
188 #define IPPROTO_ICMP    1   /* Internet Control Message Protocol */
189 #define IPPROTO_IGMP    2   /* Internet Group Management Protocol */
190 #define IPPROTO_TCP     6   /* Transmission Control Protocol */
191 #define IPPROTO_UDP     17  /* User Datagram Protocol */
192
193 /* Timeout timer constants */
194 #define IP_TICKS_SECOND 2                   /* Two ticks per second */
195 #define IP_TIMEOUT (1000 / IP_TICKS_SECOND) /* Timeout in milliseconds */
196
197
198 extern LIST_ENTRY InterfaceListHead;
199 extern KSPIN_LOCK InterfaceListLock;
200 extern LIST_ENTRY NetTableListHead;
201 extern KSPIN_LOCK NetTableListLock;
202 extern LIST_ENTRY PrefixListHead;
203 extern KSPIN_LOCK PrefixListLock;
204 extern UINT MaxLLHeaderSize;
205 extern UINT MinLLFrameSize;
206
207 PIP_PACKET IPCreatePacket(
208   ULONG Type);
209
210 PNET_TABLE_ENTRY IPCreateNTE(
211     PIP_INTERFACE IF,
212     PIP_ADDRESS Address,
213     UINT PrefixLength);
214
215 PIP_INTERFACE IPCreateInterface(
216     PLLIP_BIND_INFO BindInfo);
217
218 VOID IPDestroyInterface(
219     PIP_INTERFACE IF);
220
221 BOOLEAN IPRegisterInterface(
222     PIP_INTERFACE IF);
223
224 VOID IPUnregisterInterface(
225     PIP_INTERFACE IF);
226
227 PNET_TABLE_ENTRY IPLocateNTEOnInterface(
228     PIP_INTERFACE IF,
229     PIP_ADDRESS Address,
230     PUINT AddressType);
231
232 PNET_TABLE_ENTRY IPLocateNTE(
233     PIP_ADDRESS Address,
234     PUINT AddressType);
235
236 PADDRESS_ENTRY IPLocateADE(
237     PIP_ADDRESS Address,
238     UINT AddressType);
239
240 PADDRESS_ENTRY IPGetDefaultADE(
241     UINT AddressType);
242
243 VOID STDCALL IPTimeout(
244     PKDPC Dpc,
245     PVOID DeferredContext,
246     PVOID SystemArgument1,
247     PVOID SystemArgument2);
248
249 VOID IPDispatchProtocol(
250     PNET_TABLE_ENTRY NTE,
251     PIP_PACKET IPPacket);
252
253 VOID IPRegisterProtocol(
254     UINT ProtocolNumber,
255     IP_PROTOCOL_HANDLER Handler);
256
257 NTSTATUS IPStartup(
258     PDRIVER_OBJECT DriverObject,
259     PUNICODE_STRING RegistryPath);
260
261 NTSTATUS IPShutdown(
262     VOID);
263
264 #endif /* __IP_H */
265
266 /* EOF */