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 IPv6_RAW_ADDRESS IPv6Address
;/* IPv6 address (in network byte order) */
30 } IP_ADDRESS
, *PIP_ADDRESS
;
32 /* IP type constants */
33 #define IP_ADDRESS_V4 0x04 /* IPv4 style address */
34 #define IP_ADDRESS_V6 0x06 /* IPv6 style address */
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
;
51 /* IPv6 header format */
52 typedef struct IPv6_HEADER
{
53 ULONG VTF
; /* Version, Traffic Class, Flow Label */
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
;
61 typedef union _IP_HEADER
{
64 } IP_HEADER
, *PIP_HEADER
;
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
71 /* Packet completion handler prototype */
72 typedef VOID (*PACKET_COMPLETION_ROUTINE
)(
74 PNDIS_PACKET NdisPacket
,
75 NDIS_STATUS NdisStatus
);
77 /* Structure for an IP packet */
78 typedef struct _IP_PACKET
{
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
;
94 #define IP_PACKET_FLAG_RAW 0x01 /* Raw IP packet */
98 typedef struct _PACKET_CONTEXT
{
99 PACKET_COMPLETION_ROUTINE DLComplete
; /* Data link level completion handler
100 * Also used to link to next packet
102 PVOID Context
; /* Context information for handler */
103 UINT PacketType
; /* Type of packet */
104 } PACKET_CONTEXT
, *PPACKET_CONTEXT
;
106 /* The ProtocolReserved field is structured as a PACKET_CONTEXT */
107 #define PC(Packet) ((PPACKET_CONTEXT)(&Packet->ProtocolReserved))
109 /* Values for address type -- also the interface flags */
110 /* These values are mean to overlap meaningfully with the BSD ones */
111 #define ADE_UNICAST 0x01
112 #define ADE_BROADCAST 0x02
113 #define ADE_ADDRMASK 0x04
114 #define ADE_POINTOPOINT 0x10
115 #define ADE_MULTICAST 0x8000
117 /* There is one NTE for each source (unicast) address assigned to an interface */
118 /* Link layer transmit prototype */
119 typedef VOID (*LL_TRANSMIT_ROUTINE
)(
121 PNDIS_PACKET NdisPacket
,
126 /* Link layer to IP binding information */
127 typedef struct _LLIP_BIND_INFO
{
128 PVOID Context
; /* Pointer to link layer context information */
129 UINT HeaderSize
; /* Size of link level header */
130 UINT MinFrameSize
; /* Minimum frame size in bytes */
131 UINT MTU
; /* Maximum transmission unit */
132 PUCHAR Address
; /* Pointer to interface address */
133 UINT AddressLength
; /* Length of address in bytes */
134 LL_TRANSMIT_ROUTINE Transmit
; /* Transmit function for this interface */
135 } LLIP_BIND_INFO
, *PLLIP_BIND_INFO
;
138 /* Information about an IP interface */
139 typedef struct _IP_INTERFACE
{
141 LIST_ENTRY ListEntry
; /* Entry on list */
142 OBJECT_FREE_ROUTINE Free
; /* Routine used to free resources used by the object */
143 KSPIN_LOCK Lock
; /* Spin lock for this object */
144 PVOID Context
; /* Pointer to link layer context information */
145 UINT HeaderSize
; /* Size of link level header */
146 UINT MinFrameSize
; /* Minimum frame size in bytes */
147 UINT MTU
; /* Maximum transmission unit */
148 UINT Speed
; /* Link speed */
149 IP_ADDRESS Unicast
; /* Unicast address */
150 IP_ADDRESS PointToPoint
; /* Point to point address */
151 IP_ADDRESS Netmask
; /* Netmask */
152 IP_ADDRESS Broadcast
; /* Broadcast */
153 UNICODE_STRING Name
; /* Adapter name (GUID) */
154 UNICODE_STRING Description
; /* Adapter description (Human readable) */
155 PUCHAR Address
; /* Pointer to interface address */
156 UINT AddressLength
; /* Length of address in bytes */
157 UINT Index
; /* Index of adapter (used to add ip addr) */
158 LL_TRANSMIT_ROUTINE Transmit
; /* Pointer to transmit function */
159 PVOID TCPContext
; /* TCP Content for this interface */
160 } IP_INTERFACE
, *PIP_INTERFACE
;
162 typedef struct _IP_SET_ADDRESS
{
164 IPv4_RAW_ADDRESS Address
;
165 IPv4_RAW_ADDRESS Netmask
;
166 } IP_SET_ADDRESS
, *PIP_SET_ADDRESS
;
168 #define IP_PROTOCOL_TABLE_SIZE 0x100
170 typedef VOID (*IP_PROTOCOL_HANDLER
)(
171 PIP_INTERFACE Interface
,
172 PIP_PACKET IPPacket
);
174 /* Loopback adapter address information (network byte order) */
175 #define LOOPBACK_ADDRESS_IPv4 ((IPv4_RAW_ADDRESS)DH2N(0x7F000001))
176 #define LOOPBACK_BCASTADDR_IPv4 ((IPv4_RAW_ADDRESS)DH2N(0x7F0000FF))
177 #define LOOPBACK_ADDRMASK_IPv4 ((IPv4_RAW_ADDRESS)DH2N(0xFFFFFF00))
179 /* Protocol definitions */
181 #define IPPROTO_RAW 0 /* Raw IP */
183 #define IPPROTO_ICMP 1 /* Internet Control Message Protocol */
184 #define IPPROTO_IGMP 2 /* Internet Group Management Protocol */
185 #define IPPROTO_TCP 6 /* Transmission Control Protocol */
186 #define IPPROTO_UDP 17 /* User Datagram Protocol */
188 /* Timeout timer constants */
189 #define IP_TICKS_SECOND 2 /* Two ticks per second */
190 #define IP_TIMEOUT (1000 / IP_TICKS_SECOND) /* Timeout in milliseconds */
191 #define IP_DEFAULT_LINK_SPEED 10000
193 extern LIST_ENTRY InterfaceListHead
;
194 extern KSPIN_LOCK InterfaceListLock
;
195 extern LIST_ENTRY NetTableListHead
;
196 extern KSPIN_LOCK NetTableListLock
;
197 extern UINT MaxLLHeaderSize
;
198 extern UINT MinLLFrameSize
;
199 extern BOOLEAN IpWorkItemQueued
;
201 PIP_PACKET
IPCreatePacket(
204 PIP_PACKET
IPInitializePacket(
208 PIP_INTERFACE
IPCreateInterface(
209 PLLIP_BIND_INFO BindInfo
);
211 VOID
IPAddInterfaceRoute(
214 VOID
IPRemoveInterfaceRoute(
217 VOID
IPDestroyInterface(
220 BOOLEAN
IPRegisterInterface(
223 VOID
IPUnregisterInterface(
226 VOID STDCALL
IPTimeout( PVOID Context
);
228 VOID
IPDispatchProtocol(
229 PIP_INTERFACE Interface
,
230 PIP_PACKET IPPacket
);
232 VOID
IPRegisterProtocol(
234 IP_PROTOCOL_HANDLER Handler
);
236 NTSTATUS
IPStartup(PUNICODE_STRING RegistryPath
);
238 NTSTATUS
IPShutdown(VOID
);