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