]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.h
eea4d7e0cffe8c584eb2831eae04bbdc0fee039a
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Input.h
1 /** @file
2
3 Copyright (c) 2005 - 2006, Intel Corporation.<BR>
4 All rights reserved. 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 typedef enum {
18 IP4_MIN_HEADLEN = 20,
19 IP4_MAX_HEADLEN = 60,
20
21 IP4_ASSEMLE_HASH_SIZE = 31,
22 IP4_FRAGMENT_LIFE = 120,
23 IP4_MAX_PACKET_SIZE = 65535
24 } IP4_INPUT_ENUM_TYPES;
25
26 ///
27 /// Per packet information for input process. LinkFlag specifies whether
28 /// the packet is received as Link layer unicast, multicast or broadcast.
29 /// The CastType is the IP layer cast type, such as IP multicast or unicast.
30 /// Start, End and Length are staffs used to assemble the packets. Start
31 /// is the sequence number of the first byte of data in the packet. Length
32 /// is the number of bytes of data. End = Start + Length, that is, the
33 /// sequence number of last byte + 1. Each assembled packet has a count down
34 /// life. If it isn't consumed before Life reaches zero, the packet is released.
35 ///
36 typedef struct {
37 UINTN LinkFlag;
38 INTN CastType;
39 INTN Start;
40 INTN End;
41 INTN Length;
42 UINT32 Life;
43 EFI_STATUS Status;
44 } IP4_CLIP_INFO;
45
46 ///
47 /// Structure used to assemble IP packets.
48 ///
49 typedef struct {
50 LIST_ENTRY Link;
51
52 //
53 // Identity of one IP4 packet. Each fragment of a packet has
54 // the same (Dst, Src, Id, Protocol).
55 //
56 IP4_ADDR Dst;
57 IP4_ADDR Src;
58 UINT16 Id;
59 UINT8 Protocol;
60
61 INTN TotalLen;
62 INTN CurLen;
63 LIST_ENTRY Fragments; // List of all the fragments of this packet
64
65 IP4_HEAD *Head; // IP head of the first fragment
66 IP4_CLIP_INFO *Info; // Per packet info of the first fragment
67 INTN Life; // Count down life for the packet.
68 } IP4_ASSEMBLE_ENTRY;
69
70 ///
71 /// Each Ip service instance has an assemble table to reassemble
72 /// the packets before delivery to its children. It is organized
73 /// as hash table.
74 ///
75 typedef struct {
76 LIST_ENTRY Bucket[IP4_ASSEMLE_HASH_SIZE];
77 } IP4_ASSEMBLE_TABLE;
78
79 #define IP4_GET_CLIP_INFO(Packet) ((IP4_CLIP_INFO *) ((Packet)->ProtoData))
80
81 #define IP4_ASSEMBLE_HASH(Dst, Src, Id, Proto) \
82 (((Dst) + (Src) + ((Id) << 16) + (Proto)) % IP4_ASSEMLE_HASH_SIZE)
83
84 #define IP4_RXDATA_WRAP_SIZE(NumFrag) \
85 (sizeof (IP4_RXDATA_WRAP) + sizeof (EFI_IP4_FRAGMENT_DATA) * ((NumFrag) - 1))
86
87 /**
88 Initialize an already allocated assemble table. This is generally
89 the assemble table embedded in the IP4 service instance.
90
91 @param[in, out] Table The assemble table to initialize.
92
93 **/
94 VOID
95 Ip4InitAssembleTable (
96 IN OUT IP4_ASSEMBLE_TABLE *Table
97 );
98
99 /**
100 Clean up the assemble table: remove all the fragments
101 and assemble entries.
102
103 @param[in] Table The assemble table to clean up
104
105 **/
106 VOID
107 Ip4CleanAssembleTable (
108 IN IP4_ASSEMBLE_TABLE *Table
109 );
110
111 /**
112 The IP4 input routine. It is called by the IP4_INTERFACE when a
113 IP4 fragment is received from MNP.
114
115 @param[in] Ip4Instance The IP4 child that request the receive, most like
116 it is NULL.
117 @param[in] Packet The IP4 packet received.
118 @param[in] IoStatus The return status of receive request.
119 @param[in] Flag The link layer flag for the packet received, such
120 as multicast.
121 @param[in] Context The IP4 service instance that own the MNP.
122
123 **/
124 VOID
125 Ip4AccpetFrame (
126 IN IP4_PROTOCOL *Ip4Instance,
127 IN NET_BUF *Packet,
128 IN EFI_STATUS IoStatus,
129 IN UINT32 Flag,
130 IN VOID *Context
131 );
132
133 /**
134 Demultiple the packet. the packet delivery is processed in two
135 passes. The first pass will enque a shared copy of the packet
136 to each IP4 child that accepts the packet. The second pass will
137 deliver a non-shared copy of the packet to each IP4 child that
138 has pending receive requests. Data is copied if more than one
139 child wants to consume the packet because each IP child needs
140 its own copy of the packet to make changes.
141
142 @param[in] IpSb The IP4 service instance that received the packet
143 @param[in] Head The header of the received packet
144 @param[in] Packet The data of the received packet
145
146 @retval EFI_NOT_FOUND No IP child accepts the packet
147 @retval EFI_SUCCESS The packet is enqueued or delivered to some IP
148 children.
149
150 **/
151 EFI_STATUS
152 Ip4Demultiplex (
153 IN IP4_SERVICE *IpSb,
154 IN IP4_HEAD *Head,
155 IN NET_BUF *Packet
156 );
157
158 /**
159 Enqueue a received packet to all the IP children that share
160 the same interface.
161
162 @param[in] IpSb The IP4 service instance that receive the packet
163 @param[in] Head The header of the received packet
164 @param[in] Packet The data of the received packet
165 @param[in] IpIf The interface to enqueue the packet to
166
167 @return The number of the IP4 children that accepts the packet
168
169 **/
170 INTN
171 Ip4InterfaceEnquePacket (
172 IN IP4_SERVICE *IpSb,
173 IN IP4_HEAD *Head,
174 IN NET_BUF *Packet,
175 IN IP4_INTERFACE *IpIf
176 );
177
178 /**
179 Deliver the received packets to upper layer if there are both received
180 requests and enqueued packets. If the enqueued packet is shared, it will
181 duplicate it to a non-shared packet, release the shared packet, then
182 deliver the non-shared packet up.
183
184 @param[in] IpInstance The IP child to deliver the packet up.
185
186 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to deliver the
187 packets.
188 @retval EFI_SUCCESS All the enqueued packets that can be delivered
189 are delivered up.
190
191 **/
192 EFI_STATUS
193 Ip4InstanceDeliverPacket (
194 IN IP4_PROTOCOL *IpInstance
195 );
196
197 /**
198 Timeout the fragment and enqueued packets.
199
200 @param[in] IpSb The IP4 service instance to timeout
201
202 **/
203 VOID
204 Ip4PacketTimerTicking (
205 IN IP4_SERVICE *IpSb
206 );
207
208 #endif