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