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