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