]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.h
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Input.h
CommitLineData
83cbd279 1/** @file\r
2\r
e5eed7d3
HT
3Copyright (c) 2005 - 2009, Intel Corporation. All rights reserved.<BR>\r
4This program and the accompanying materials\r
83cbd279 5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
83cbd279 12**/\r
13\r
14#ifndef __EFI_IP4_INPUT_H__\r
15#define __EFI_IP4_INPUT_H__\r
16\r
f6b7393c 17#define IP4_MIN_HEADLEN 20\r
18#define IP4_MAX_HEADLEN 60\r
a1503a32 19///\r
20/// 8(ESP header) + 16(max IV) + 16(max padding) + 2(ESP tail) + 12(max ICV) = 54 \r
21///\r
22#define IP4_MAX_IPSEC_HEADLEN 54\r
83cbd279 23\r
f6b7393c 24#define IP4_ASSEMLE_HASH_SIZE 31\r
25#define IP4_FRAGMENT_LIFE 120\r
26#define IP4_MAX_PACKET_SIZE 65535\r
96e1079f 27\r
28///\r
29/// Per packet information for input process. LinkFlag specifies whether\r
30/// the packet is received as Link layer unicast, multicast or broadcast.\r
31/// The CastType is the IP layer cast type, such as IP multicast or unicast.\r
32/// Start, End and Length are staffs used to assemble the packets. Start\r
33/// is the sequence number of the first byte of data in the packet. Length\r
34/// is the number of bytes of data. End = Start + Length, that is, the\r
35/// sequence number of last byte + 1. Each assembled packet has a count down\r
36/// life. If it isn't consumed before Life reaches zero, the packet is released.\r
37///\r
83cbd279 38typedef struct {\r
39 UINTN LinkFlag;\r
40 INTN CastType;\r
41 INTN Start;\r
42 INTN End;\r
43 INTN Length;\r
44 UINT32 Life;\r
45 EFI_STATUS Status;\r
46} IP4_CLIP_INFO;\r
47\r
96e1079f 48///\r
49/// Structure used to assemble IP packets.\r
50///\r
83cbd279 51typedef struct {\r
e48e37fc 52 LIST_ENTRY Link;\r
83cbd279 53\r
54 //\r
55 // Identity of one IP4 packet. Each fragment of a packet has\r
56 // the same (Dst, Src, Id, Protocol).\r
57 //\r
58 IP4_ADDR Dst;\r
59 IP4_ADDR Src;\r
60 UINT16 Id;\r
61 UINT8 Protocol;\r
62\r
63 INTN TotalLen;\r
64 INTN CurLen;\r
e48e37fc 65 LIST_ENTRY Fragments; // List of all the fragments of this packet\r
83cbd279 66\r
67 IP4_HEAD *Head; // IP head of the first fragment\r
68 IP4_CLIP_INFO *Info; // Per packet info of the first fragment\r
69 INTN Life; // Count down life for the packet.\r
70} IP4_ASSEMBLE_ENTRY;\r
71\r
96e1079f 72///\r
73/// Each Ip service instance has an assemble table to reassemble\r
74/// the packets before delivery to its children. It is organized\r
75/// as hash table.\r
76///\r
83cbd279 77typedef struct {\r
e48e37fc 78 LIST_ENTRY Bucket[IP4_ASSEMLE_HASH_SIZE];\r
83cbd279 79} IP4_ASSEMBLE_TABLE;\r
80\r
81#define IP4_GET_CLIP_INFO(Packet) ((IP4_CLIP_INFO *) ((Packet)->ProtoData))\r
82\r
83#define IP4_ASSEMBLE_HASH(Dst, Src, Id, Proto) \\r
84 (((Dst) + (Src) + ((Id) << 16) + (Proto)) % IP4_ASSEMLE_HASH_SIZE)\r
85\r
86#define IP4_RXDATA_WRAP_SIZE(NumFrag) \\r
87 (sizeof (IP4_RXDATA_WRAP) + sizeof (EFI_IP4_FRAGMENT_DATA) * ((NumFrag) - 1))\r
88\r
2ff29212 89/**\r
90 Initialize an already allocated assemble table. This is generally\r
91 the assemble table embedded in the IP4 service instance.\r
92\r
3e8c18da 93 @param[in, out] Table The assemble table to initialize.\r
2ff29212 94\r
95**/\r
83cbd279 96VOID\r
97Ip4InitAssembleTable (\r
2ff29212 98 IN OUT IP4_ASSEMBLE_TABLE *Table\r
83cbd279 99 );\r
100\r
2ff29212 101/**\r
102 Clean up the assemble table: remove all the fragments\r
103 and assemble entries.\r
104\r
3e8c18da 105 @param[in] Table The assemble table to clean up\r
2ff29212 106\r
107**/\r
83cbd279 108VOID\r
109Ip4CleanAssembleTable (\r
110 IN IP4_ASSEMBLE_TABLE *Table\r
111 );\r
112\r
2ff29212 113/**\r
114 The IP4 input routine. It is called by the IP4_INTERFACE when a\r
115 IP4 fragment is received from MNP.\r
116\r
3e8c18da 117 @param[in] Ip4Instance The IP4 child that request the receive, most like\r
2ff29212 118 it is NULL.\r
3e8c18da 119 @param[in] Packet The IP4 packet received.\r
120 @param[in] IoStatus The return status of receive request.\r
121 @param[in] Flag The link layer flag for the packet received, such\r
2ff29212 122 as multicast.\r
3e8c18da 123 @param[in] Context The IP4 service instance that own the MNP.\r
2ff29212 124\r
125**/\r
83cbd279 126VOID\r
127Ip4AccpetFrame (\r
128 IN IP4_PROTOCOL *Ip4Instance,\r
129 IN NET_BUF *Packet,\r
130 IN EFI_STATUS IoStatus,\r
131 IN UINT32 Flag,\r
132 IN VOID *Context\r
133 );\r
134\r
2ff29212 135/**\r
136 Demultiple the packet. the packet delivery is processed in two\r
137 passes. The first pass will enque a shared copy of the packet\r
138 to each IP4 child that accepts the packet. The second pass will\r
139 deliver a non-shared copy of the packet to each IP4 child that\r
140 has pending receive requests. Data is copied if more than one\r
141 child wants to consume the packet because each IP child needs\r
142 its own copy of the packet to make changes.\r
143\r
3e8c18da 144 @param[in] IpSb The IP4 service instance that received the packet\r
145 @param[in] Head The header of the received packet\r
146 @param[in] Packet The data of the received packet\r
2ff29212 147\r
148 @retval EFI_NOT_FOUND No IP child accepts the packet\r
149 @retval EFI_SUCCESS The packet is enqueued or delivered to some IP\r
150 children.\r
151\r
152**/\r
83cbd279 153EFI_STATUS\r
154Ip4Demultiplex (\r
2ff29212 155 IN IP4_SERVICE *IpSb,\r
83cbd279 156 IN IP4_HEAD *Head,\r
157 IN NET_BUF *Packet\r
158 );\r
159\r
2ff29212 160/**\r
161 Enqueue a received packet to all the IP children that share\r
162 the same interface.\r
163\r
3e8c18da 164 @param[in] IpSb The IP4 service instance that receive the packet\r
165 @param[in] Head The header of the received packet\r
166 @param[in] Packet The data of the received packet\r
167 @param[in] IpIf The interface to enqueue the packet to\r
2ff29212 168\r
169 @return The number of the IP4 children that accepts the packet\r
170\r
171**/\r
83cbd279 172INTN\r
173Ip4InterfaceEnquePacket (\r
2ff29212 174 IN IP4_SERVICE *IpSb,\r
83cbd279 175 IN IP4_HEAD *Head,\r
176 IN NET_BUF *Packet,\r
2ff29212 177 IN IP4_INTERFACE *IpIf\r
83cbd279 178 );\r
179\r
2ff29212 180/**\r
181 Deliver the received packets to upper layer if there are both received\r
182 requests and enqueued packets. If the enqueued packet is shared, it will\r
183 duplicate it to a non-shared packet, release the shared packet, then\r
184 deliver the non-shared packet up.\r
185\r
3e8c18da 186 @param[in] IpInstance The IP child to deliver the packet up.\r
2ff29212 187\r
188 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to deliver the\r
189 packets.\r
190 @retval EFI_SUCCESS All the enqueued packets that can be delivered\r
191 are delivered up.\r
192\r
193**/\r
83cbd279 194EFI_STATUS\r
195Ip4InstanceDeliverPacket (\r
2ff29212 196 IN IP4_PROTOCOL *IpInstance\r
83cbd279 197 );\r
198\r
2ff29212 199/**\r
200 Timeout the fragment and enqueued packets.\r
201\r
3e8c18da 202 @param[in] IpSb The IP4 service instance to timeout\r
2ff29212 203\r
204**/\r
83cbd279 205VOID\r
206Ip4PacketTimerTicking (\r
207 IN IP4_SERVICE *IpSb\r
208 );\r
209\r
a1503a32 210/**\r
211 The work function to locate IPsec protocol to process the inbound or \r
212 outbound IP packets. The process routine handls the packet with following\r
213 actions: bypass the packet, discard the packet, or protect the packet. \r
214\r
215 @param[in] IpSb The IP4 service instance\r
216 @param[in] Head The The caller supplied IP4 header.\r
217 @param[in, out] Netbuf The IP4 packet to be processed by IPsec\r
218 @param[in] Options The caller supplied options\r
219 @param[in] OptionsLen The length of the option\r
220 @param[in] Direction The directionality in an SPD entry, \r
221 EfiIPsecInBound or EfiIPsecOutBound\r
222 @param[in] Context The token's wrap\r
223\r
224 @retval EFI_SUCCESS The IPsec protocol is not available or disabled.\r
225 @retval EFI_SUCCESS The packet was bypassed and all buffers remain the same.\r
226 @retval EFI_SUCCESS The packet was protected.\r
227 @retval EFI_ACCESS_DENIED The packet was discarded. \r
228 @retval EFI_OUT_OF_RESOURCES There is no suffcient resource to complete the operation.\r
229 @retval EFI_BUFFER_TOO_SMALL The number of non-empty block is bigger than the \r
230 number of input data blocks when build a fragment table.\r
231\r
232**/\r
233EFI_STATUS\r
234Ip4IpSecProcessPacket (\r
235 IN IP4_SERVICE *IpSb,\r
236 IN IP4_HEAD *Head,\r
237 IN OUT NET_BUF **Netbuf,\r
238 IN UINT8 *Options,\r
239 IN UINT32 OptionsLen,\r
240 IN EFI_IPSEC_TRAFFIC_DIR Direction,\r
241 IN VOID *Context\r
242 );\r
243\r
83cbd279 244#endif\r