]>
Commit | Line | Data |
---|---|---|
a3bcde70 HT |
1 | /** @file\r |
2 | IP6 internal functions and definitions to process the incoming packets.\r | |
3 | \r | |
4 | Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r | |
5 | \r | |
ecf98fbc | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
a3bcde70 HT |
7 | \r |
8 | **/\r | |
9 | \r | |
10 | #ifndef __EFI_IP6_INPUT_H__\r | |
11 | #define __EFI_IP6_INPUT_H__\r | |
12 | \r | |
13 | #define IP6_MIN_HEADLEN 40\r | |
14 | #define IP6_MAX_HEADLEN 120\r | |
15 | ///\r | |
16 | /// 8(ESP header) + 16(max IV) + 16(max padding) + 2(ESP tail) + 12(max ICV) = 54\r | |
17 | ///\r | |
18 | #define IP6_MAX_IPSEC_HEADLEN 54\r | |
19 | \r | |
20 | \r | |
21 | #define IP6_ASSEMLE_HASH_SIZE 127\r | |
22 | ///\r | |
23 | /// Lift time in seconds.\r | |
24 | ///\r | |
25 | #define IP6_FRAGMENT_LIFE 60\r | |
26 | #define IP6_MAX_PACKET_SIZE 65535\r | |
27 | \r | |
28 | \r | |
29 | #define IP6_GET_CLIP_INFO(Packet) ((IP6_CLIP_INFO *) ((Packet)->ProtoData))\r | |
30 | \r | |
31 | #define IP6_ASSEMBLE_HASH(Dst, Src, Id) \\r | |
32 | ((*((UINT32 *) (Dst)) + *((UINT32 *) (Src)) + (Id)) % IP6_ASSEMLE_HASH_SIZE)\r | |
33 | \r | |
34 | #define IP6_RXDATA_WRAP_SIZE(NumFrag) \\r | |
35 | (sizeof (IP6_RXDATA_WRAP) + sizeof (EFI_IP6_FRAGMENT_DATA) * ((NumFrag) - 1))\r | |
36 | \r | |
37 | //\r | |
38 | // Per packet information for input process. LinkFlag specifies whether\r | |
39 | // the packet is received as Link layer unicast, multicast or broadcast.\r | |
40 | // The CastType is the IP layer cast type, such as IP multicast or unicast.\r | |
41 | // Start, End and Length are staffs used to assemble the packets. Start\r | |
42 | // is the sequence number of the first byte of data in the packet. Length\r | |
43 | // is the number of bytes of data. End = Start + Length, that is, the\r | |
44 | // sequence number of last byte + 1. Each assembled packet has a count down\r | |
45 | // life. If it isn't consumed before Life reaches zero, the packet is released.\r | |
46 | //\r | |
47 | typedef struct {\r | |
48 | UINT32 LinkFlag;\r | |
49 | INT32 CastType;\r | |
50 | INT32 Start;\r | |
51 | INT32 End;\r | |
52 | INT32 Length;\r | |
53 | UINT32 Life;\r | |
54 | EFI_STATUS Status;\r | |
55 | UINT32 Id;\r | |
56 | UINT16 HeadLen;\r | |
57 | UINT8 NextHeader;\r | |
58 | UINT8 LastFrag;\r | |
59 | UINT32 FormerNextHeader;\r | |
60 | } IP6_CLIP_INFO;\r | |
61 | \r | |
62 | //\r | |
63 | // Structure used to assemble IP packets.\r | |
64 | //\r | |
65 | typedef struct {\r | |
66 | LIST_ENTRY Link;\r | |
67 | LIST_ENTRY Fragments; // List of all the fragments of this packet\r | |
68 | \r | |
69 | //\r | |
70 | // Identity of one IP6 packet. Each fragment of a packet has\r | |
71 | // the same (Dst, Src, Id).\r | |
72 | //\r | |
73 | EFI_IPv6_ADDRESS Dst;\r | |
74 | EFI_IPv6_ADDRESS Src;\r | |
75 | UINT32 Id;\r | |
76 | \r | |
77 | UINT32 TotalLen;\r | |
78 | UINT32 CurLen;\r | |
79 | UINT32 Life; // Count down life for the packet.\r | |
80 | \r | |
81 | EFI_IP6_HEADER *Head; // IP head of the first fragment\r | |
82 | IP6_CLIP_INFO *Info; // Per packet information of the first fragment\r | |
83 | NET_BUF *Packet; // The first fragment of the packet\r | |
84 | } IP6_ASSEMBLE_ENTRY;\r | |
85 | \r | |
86 | //\r | |
87 | // Each Ip service instance has an assemble table to reassemble\r | |
88 | // the packets before delivery to its children. It is organized\r | |
89 | // as hash table.\r | |
90 | //\r | |
91 | typedef struct {\r | |
92 | LIST_ENTRY Bucket[IP6_ASSEMLE_HASH_SIZE];\r | |
93 | } IP6_ASSEMBLE_TABLE;\r | |
94 | \r | |
95 | /**\r | |
96 | The IP6 input routine. It is called by the IP6_INTERFACE when an\r | |
97 | IP6 fragment is received from MNP.\r | |
98 | \r | |
99 | @param[in] Packet The IP6 packet received.\r | |
100 | @param[in] IoStatus The return status of receive request.\r | |
101 | @param[in] Flag The link layer flag for the packet received, such\r | |
102 | as multicast.\r | |
103 | @param[in] Context The IP6 service instance that own the MNP.\r | |
104 | \r | |
105 | **/\r | |
106 | VOID\r | |
107 | Ip6AcceptFrame (\r | |
108 | IN NET_BUF *Packet,\r | |
109 | IN EFI_STATUS IoStatus,\r | |
110 | IN UINT32 Flag,\r | |
111 | IN VOID *Context\r | |
112 | );\r | |
113 | \r | |
114 | /**\r | |
115 | Deliver the received packets to upper layer if there are both received\r | |
116 | requests and enqueued packets. If the enqueued packet is shared, it will\r | |
117 | duplicate it to a non-shared packet, release the shared packet, then\r | |
118 | deliver the non-shared packet up.\r | |
119 | \r | |
120 | @param[in] IpInstance The IP child to deliver the packet up.\r | |
121 | \r | |
122 | @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to deliver the\r | |
123 | packets.\r | |
124 | @retval EFI_SUCCESS All the enqueued packets that can be delivered\r | |
125 | are delivered up.\r | |
126 | \r | |
127 | **/\r | |
128 | EFI_STATUS\r | |
129 | Ip6InstanceDeliverPacket (\r | |
130 | IN IP6_PROTOCOL *IpInstance\r | |
131 | );\r | |
132 | \r | |
133 | /**\r | |
68d3f2fb | 134 | The work function to locate the IPsec protocol to process the inbound or\r |
135 | outbound IP packets. The process routine handles the packet with the following\r | |
a3bcde70 HT |
136 | actions: bypass the packet, discard the packet, or protect the packet.\r |
137 | \r | |
138 | @param[in] IpSb The IP6 service instance.\r | |
68d3f2fb | 139 | @param[in, out] Head The caller-supplied IP6 header.\r |
a3bcde70 HT |
140 | @param[in, out] LastHead The next header field of last IP header.\r |
141 | @param[in, out] Netbuf The IP6 packet to be processed by IPsec.\r | |
68d3f2fb | 142 | @param[in, out] ExtHdrs The caller-supplied options.\r |
143 | @param[in, out] ExtHdrsLen The length of the option.\r | |
a3bcde70 | 144 | @param[in] Direction The directionality in an SPD entry,\r |
68d3f2fb | 145 | EfiIPsecInBound, or EfiIPsecOutBound.\r |
a3bcde70 HT |
146 | @param[in] Context The token's wrap.\r |
147 | \r | |
148 | @retval EFI_SUCCESS The IPsec protocol is not available or disabled.\r | |
68d3f2fb | 149 | @retval EFI_SUCCESS The packet was bypassed, and all buffers remain the same.\r |
a3bcde70 HT |
150 | @retval EFI_SUCCESS The packet was protected.\r |
151 | @retval EFI_ACCESS_DENIED The packet was discarded.\r | |
7de8045a | 152 | @retval EFI_OUT_OF_RESOURCES There are not sufficient resources to complete the operation.\r |
68d3f2fb | 153 | @retval EFI_BUFFER_TOO_SMALL The number of non-empty blocks is bigger than the\r |
a3bcde70 HT |
154 | number of input data blocks when building a fragment table.\r |
155 | \r | |
156 | **/\r | |
157 | EFI_STATUS\r | |
158 | Ip6IpSecProcessPacket (\r | |
68d3f2fb | 159 | IN IP6_SERVICE *IpSb,\r |
160 | IN OUT EFI_IP6_HEADER **Head,\r | |
161 | IN OUT UINT8 *LastHead,\r | |
162 | IN OUT NET_BUF **Netbuf,\r | |
163 | IN OUT UINT8 **ExtHdrs,\r | |
164 | IN OUT UINT32 *ExtHdrsLen,\r | |
165 | IN EFI_IPSEC_TRAFFIC_DIR Direction,\r | |
166 | IN VOID *Context\r | |
a3bcde70 HT |
167 | );\r |
168 | \r | |
169 | /**\r | |
170 | Initialize an already allocated assemble table. This is generally\r | |
171 | the assemble table embedded in the IP6 service instance.\r | |
172 | \r | |
173 | @param[in, out] Table The assemble table to initialize.\r | |
174 | \r | |
175 | **/\r | |
176 | VOID\r | |
177 | Ip6CreateAssembleTable (\r | |
178 | IN OUT IP6_ASSEMBLE_TABLE *Table\r | |
179 | );\r | |
180 | \r | |
181 | /**\r | |
182 | Clean up the assemble table: remove all the fragments\r | |
183 | and assemble entries.\r | |
184 | \r | |
185 | @param[in, out] Table The assemble table to clean up.\r | |
186 | \r | |
187 | **/\r | |
188 | VOID\r | |
189 | Ip6CleanAssembleTable (\r | |
190 | IN OUT IP6_ASSEMBLE_TABLE *Table\r | |
191 | );\r | |
192 | \r | |
193 | /**\r | |
194 | Demultiple the packet. the packet delivery is processed in two\r | |
7de8045a | 195 | passes. The first pass will enqueue a shared copy of the packet\r |
a3bcde70 HT |
196 | to each IP6 child that accepts the packet. The second pass will\r |
197 | deliver a non-shared copy of the packet to each IP6 child that\r | |
198 | has pending receive requests. Data is copied if more than one\r | |
7de8045a | 199 | child wants to consume the packet because each IP child need\r |
a3bcde70 HT |
200 | its own copy of the packet to make changes.\r |
201 | \r | |
202 | @param[in] IpSb The IP6 service instance that received the packet.\r | |
203 | @param[in] Head The header of the received packet.\r | |
204 | @param[in] Packet The data of the received packet.\r | |
205 | \r | |
206 | @retval EFI_NOT_FOUND No IP child accepts the packet.\r | |
207 | @retval EFI_SUCCESS The packet is enqueued or delivered to some IP\r | |
208 | children.\r | |
209 | \r | |
210 | **/\r | |
211 | EFI_STATUS\r | |
212 | Ip6Demultiplex (\r | |
213 | IN IP6_SERVICE *IpSb,\r | |
214 | IN EFI_IP6_HEADER *Head,\r | |
215 | IN NET_BUF *Packet\r | |
216 | );\r | |
217 | \r | |
218 | /**\r | |
219 | Timeout the fragmented, enqueued, and transmitted packets.\r | |
220 | \r | |
221 | @param[in] IpSb The IP6 service instance to timeout.\r | |
222 | \r | |
223 | **/\r | |
224 | VOID\r | |
225 | Ip6PacketTimerTicking (\r | |
226 | IN IP6_SERVICE *IpSb\r | |
227 | );\r | |
228 | \r | |
229 | #endif\r |