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