]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Route.h
synced function header
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Route.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
13 Module Name:
14
15 Ip4Route.h
16
17 Abstract:
18
19 EFI IP4 route table and route cache table defintions.
20
21
22 **/
23
24 #ifndef __EFI_IP4_ROUTE_H__
25 #define __EFI_IP4_ROUTE_H__
26
27 #include "Ip4Common.h"
28
29 typedef enum {
30 IP4_DIRECT_ROUTE = 0x00000001,
31
32 IP4_ROUTE_CACHE_HASH = 31,
33 IP4_ROUTE_CACHE_MAX = 64 // Max NO. of cache entry per hash bucket
34 } IP4_ROUTE_ENUM_TYPES;
35
36 #define IP4_ROUTE_CACHE_HASH(Dst, Src) (((Dst) ^ (Src)) % IP4_ROUTE_CACHE_HASH)
37
38 ///
39 /// The route entry in the route table. Dest/Netmask is the destion
40 /// network. The nexthop is the gateway to send the packet to in
41 /// order to reach the Dest/Netmask. If the Flag has IP4_DIRECT_ROUTE
42 /// on, the gateway is the destination of the IP packet itself. Route
43 /// enties of the connected network have the flag on.
44 ///
45 typedef struct {
46 LIST_ENTRY Link;
47 INTN RefCnt;
48 IP4_ADDR Dest;
49 IP4_ADDR Netmask;
50 IP4_ADDR NextHop;
51 UINT32 Flag;
52 } IP4_ROUTE_ENTRY;
53
54 ///
55 /// The route cache entry. The route cache entry is optional.
56 /// But it is necessary to support the ICMP redirect message.
57 /// Check Ip4ProcessIcmpRedirect for information.
58 ///
59 /// The cache entry field Tag is used to tag all the route
60 /// cache entry spawned from a route table entry. This makes
61 /// it simple to delete all the route cache entries from a
62 /// to-be-deleted route entry.
63 ///
64 typedef struct {
65 LIST_ENTRY Link;
66 INTN RefCnt;
67 IP4_ADDR Dest;
68 IP4_ADDR Src;
69 IP4_ADDR NextHop;
70 UINTN Tag;
71 } IP4_ROUTE_CACHE_ENTRY;
72
73 ///
74 /// The route cache table is organized as a hash table. Each
75 /// IP4 route table has a embedded route cache. For now the
76 /// route cache and route table are binded togehter. But keep
77 /// the route cache a seperated structure in case we want to
78 /// detach them later.
79 ///
80 typedef struct {
81 LIST_ENTRY CacheBucket[IP4_ROUTE_CACHE_HASH];
82 } IP4_ROUTE_CACHE;
83
84 ///
85 /// Each IP4 instance has its own route table. Each ServiceBinding
86 /// instance has a default route table and default address.
87 ///
88 /// All the route table entries with the same mask are linked
89 /// together in one route area. For example, RouteArea[0] contains
90 /// the default routes. A route table also contains a route cache.
91 ///
92 typedef struct _IP4_ROUTE_TABLE IP4_ROUTE_TABLE;
93
94 struct _IP4_ROUTE_TABLE {
95 INTN RefCnt;
96 UINT32 TotalNum;
97 LIST_ENTRY RouteArea[IP4_MASK_NUM];
98 IP4_ROUTE_TABLE *Next;
99 IP4_ROUTE_CACHE Cache;
100 };
101
102 /**
103 Create an empty route table, includes its internal route cache
104
105 @return NULL if failed to allocate memory for the route table, otherwise
106 the point to newly created route table.
107
108 **/
109 IP4_ROUTE_TABLE *
110 Ip4CreateRouteTable (
111 VOID
112 );
113
114 /**
115 Free the route table and its associated route cache. Route
116 table is reference counted.
117
118 @param RtTable The route table to free.
119
120 @return None
121
122 **/
123 VOID
124 Ip4FreeRouteTable (
125 IN IP4_ROUTE_TABLE *RtTable
126 );
127
128 /**
129 Add a route entry to the route table. All the IP4_ADDRs are in
130 host byte order.
131
132 @param RtTable Route table to add route to
133 @param Dest The destination of the network
134 @param Netmask The netmask of the destination
135 @param Gateway The next hop address
136
137 @retval EFI_ACCESS_DENIED The same route already exists
138 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the entry
139 @retval EFI_SUCCESS The route is added successfully.
140
141 **/
142 EFI_STATUS
143 Ip4AddRoute (
144 IN OUT IP4_ROUTE_TABLE *RtTable,
145 IN IP4_ADDR Dest,
146 IN IP4_ADDR Netmask,
147 IN IP4_ADDR Gateway
148 );
149
150 /**
151 Remove a route entry and all the route caches spawn from it.
152
153 @param RtTable The route table to remove the route from
154 @param Dest The destination network
155 @param Netmask The netmask of the Dest
156 @param Gateway The next hop address
157
158 @retval EFI_SUCCESS The route entry is successfully removed
159 @retval EFI_NOT_FOUND There is no route entry in the table with that
160 properity.
161
162 **/
163 EFI_STATUS
164 Ip4DelRoute (
165 IN OUT IP4_ROUTE_TABLE *RtTable,
166 IN IP4_ADDR Dest,
167 IN IP4_ADDR Netmask,
168 IN IP4_ADDR Gateway
169 );
170
171 /**
172 Find a route cache with the dst and src. This is used by ICMP
173 redirect messasge process. All kinds of redirect is treated as
174 host redirect according to RFC1122. So, only route cache entries
175 are modified according to the ICMP redirect message.
176
177 @param RtTable The route table to search the cache for
178 @param Dest The destination address
179 @param Src The source address
180
181 @return NULL if no route entry to the (Dest, Src). Otherwise the point
182 to the correct route cache entry.
183
184 **/
185 IP4_ROUTE_CACHE_ENTRY *
186 Ip4FindRouteCache (
187 IN IP4_ROUTE_TABLE *RtTable,
188 IN IP4_ADDR Dest,
189 IN IP4_ADDR Src
190 );
191
192 /**
193 Free the route cache entry. It is reference counted.
194
195 @param RtCacheEntry The route cache entry to free.
196
197 @return None
198
199 **/
200 VOID
201 Ip4FreeRouteCacheEntry (
202 IN IP4_ROUTE_CACHE_ENTRY *RtCacheEntry
203 );
204
205 /**
206 Search the route table to route the packet. Return/create a route
207 cache if there is a route to the destination.
208
209 @param RtTable The route table to search from
210 @param Dest The destination address to search for
211 @param Src The source address to search for
212
213 @return NULL if failed to route packet, otherwise a route cache
214 entry that can be used to route packet.
215
216 **/
217 IP4_ROUTE_CACHE_ENTRY *
218 Ip4Route (
219 IN IP4_ROUTE_TABLE *RtTable,
220 IN IP4_ADDR Dest,
221 IN IP4_ADDR Src
222 );
223
224 /**
225 Build a EFI_IP4_ROUTE_TABLE to be returned to the caller of
226 GetModeData. The EFI_IP4_ROUTE_TABLE is clumsy to use in the
227 internal operation of the IP4 driver.
228
229 @param IpInstance The IP4 child that requests the route table.
230
231 @retval EFI_SUCCESS The route table is successfully build
232 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the rotue table.
233
234 **/
235 EFI_STATUS
236 Ip4BuildEfiRouteTable (
237 IN IP4_PROTOCOL *IpInstance
238 );
239 #endif