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