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