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