]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.h
Fix a bug in IP4 driver which may cause “reconnect –r” hang.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Input.h
... / ...
CommitLineData
1/** @file\r
2\r
3Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>\r
4This program and the accompanying materials\r
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
12**/\r
13\r
14#ifndef __EFI_IP4_INPUT_H__\r
15#define __EFI_IP4_INPUT_H__\r
16\r
17#define IP4_MIN_HEADLEN 20\r
18#define IP4_MAX_HEADLEN 60\r
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
23\r
24#define IP4_ASSEMLE_HASH_SIZE 31\r
25#define IP4_FRAGMENT_LIFE 120\r
26#define IP4_MAX_PACKET_SIZE 65535\r
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
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
48///\r
49/// Structure used to assemble IP packets.\r
50///\r
51typedef struct {\r
52 LIST_ENTRY Link;\r
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
65 LIST_ENTRY Fragments; // List of all the fragments of this packet\r
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
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
77typedef struct {\r
78 LIST_ENTRY Bucket[IP4_ASSEMLE_HASH_SIZE];\r
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
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
93 @param[in, out] Table The assemble table to initialize.\r
94\r
95**/\r
96VOID\r
97Ip4InitAssembleTable (\r
98 IN OUT IP4_ASSEMBLE_TABLE *Table\r
99 );\r
100\r
101/**\r
102 Clean up the assemble table: remove all the fragments\r
103 and assemble entries.\r
104\r
105 @param[in] Table The assemble table to clean up\r
106\r
107**/\r
108VOID\r
109Ip4CleanAssembleTable (\r
110 IN IP4_ASSEMBLE_TABLE *Table\r
111 );\r
112\r
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
117 @param[in] Ip4Instance The IP4 child that request the receive, most like\r
118 it is NULL.\r
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
122 as multicast.\r
123 @param[in] Context The IP4 service instance that own the MNP.\r
124\r
125**/\r
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
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
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
147 @param[in] Option Point to the IP4 packet header options.\r
148 @param[in] OptionLen Length of the IP4 packet header options.\r
149\r
150 @retval EFI_NOT_FOUND No IP child accepts the packet.\r
151 @retval EFI_SUCCESS The packet is enqueued or delivered to some IP\r
152 children.\r
153\r
154**/\r
155EFI_STATUS\r
156Ip4Demultiplex (\r
157 IN IP4_SERVICE *IpSb,\r
158 IN IP4_HEAD *Head,\r
159 IN NET_BUF *Packet,\r
160 IN UINT8 *Option,\r
161 IN UINT32 OptionLen\r
162 );\r
163\r
164/**\r
165 Enqueue a received packet to all the IP children that share\r
166 the same interface.\r
167\r
168 @param[in] IpSb The IP4 service instance that receive the packet.\r
169 @param[in] Head The header of the received packet.\r
170 @param[in] Packet The data of the received packet.\r
171 @param[in] Option Point to the IP4 packet header options.\r
172 @param[in] OptionLen Length of the IP4 packet header options. \r
173 @param[in] IpIf The interface to enqueue the packet to.\r
174\r
175 @return The number of the IP4 children that accepts the packet\r
176\r
177**/\r
178INTN\r
179Ip4InterfaceEnquePacket (\r
180 IN IP4_SERVICE *IpSb,\r
181 IN IP4_HEAD *Head,\r
182 IN NET_BUF *Packet,\r
183 IN UINT8 *Option,\r
184 IN UINT32 OptionLen,\r
185 IN IP4_INTERFACE *IpIf\r
186 );\r
187\r
188/**\r
189 Deliver the received packets to upper layer if there are both received\r
190 requests and enqueued packets. If the enqueued packet is shared, it will\r
191 duplicate it to a non-shared packet, release the shared packet, then\r
192 deliver the non-shared packet up.\r
193\r
194 @param[in] IpInstance The IP child to deliver the packet up.\r
195\r
196 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to deliver the\r
197 packets.\r
198 @retval EFI_SUCCESS All the enqueued packets that can be delivered\r
199 are delivered up.\r
200\r
201**/\r
202EFI_STATUS\r
203Ip4InstanceDeliverPacket (\r
204 IN IP4_PROTOCOL *IpInstance\r
205 );\r
206\r
207/**\r
208 Timeout the fragment and enqueued packets.\r
209\r
210 @param[in] IpSb The IP4 service instance to timeout\r
211\r
212**/\r
213VOID\r
214Ip4PacketTimerTicking (\r
215 IN IP4_SERVICE *IpSb\r
216 );\r
217\r
218/**\r
219 The work function to locate IPsec protocol to process the inbound or \r
220 outbound IP packets. The process routine handls the packet with following\r
221 actions: bypass the packet, discard the packet, or protect the packet. \r
222\r
223 @param[in] IpSb The IP4 service instance.\r
224 @param[in, out] Head The The caller supplied IP4 header.\r
225 @param[in, out] Netbuf The IP4 packet to be processed by IPsec.\r
226 @param[in, out] Options The caller supplied options.\r
227 @param[in, out] OptionsLen The length of the option.\r
228 @param[in] Direction The directionality in an SPD entry, \r
229 EfiIPsecInBound or EfiIPsecOutBound.\r
230 @param[in] Context The token's wrap.\r
231\r
232 @retval EFI_SUCCESS The IPsec protocol is not available or disabled.\r
233 @retval EFI_SUCCESS The packet was bypassed and all buffers remain the same.\r
234 @retval EFI_SUCCESS The packet was protected.\r
235 @retval EFI_ACCESS_DENIED The packet was discarded. \r
236 @retval EFI_OUT_OF_RESOURCES There is no suffcient resource to complete the operation.\r
237 @retval EFI_BUFFER_TOO_SMALL The number of non-empty block is bigger than the \r
238 number of input data blocks when build a fragment table.\r
239\r
240**/\r
241EFI_STATUS\r
242Ip4IpSecProcessPacket (\r
243 IN IP4_SERVICE *IpSb,\r
244 IN OUT IP4_HEAD **Head,\r
245 IN OUT NET_BUF **Netbuf,\r
246 IN OUT UINT8 **Options,\r
247 IN OUT UINT32 *OptionsLen,\r
248 IN EFI_IPSEC_TRAFFIC_DIR Direction,\r
249 IN VOID *Context\r
250 );\r
251\r
252#endif\r