]>
Commit | Line | Data |
---|---|---|
772db4bb | 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 | enum { | |
30 | IP4_DIRECT_ROUTE = 0x00000001, | |
31 | ||
32 | IP4_ROUTE_CACHE_HASH = 31, | |
687a2e5f | 33 | IP4_ROUTE_CACHE_MAX = 64 // Max NO. of cache entry per hash bucket |
772db4bb | 34 | }; |
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 | NET_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 | NET_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 | NET_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 | ||
687a2e5f | 94 | struct _IP4_ROUTE_TABLE { |
772db4bb | 95 | INTN RefCnt; |
96 | UINT32 TotalNum; | |
97 | NET_LIST_ENTRY RouteArea[IP4_MASK_NUM]; | |
98 | IP4_ROUTE_TABLE *Next; | |
99 | IP4_ROUTE_CACHE Cache; | |
100 | }; | |
101 | ||
102 | IP4_ROUTE_TABLE* | |
103 | Ip4CreateRouteTable ( | |
104 | VOID | |
105 | ); | |
106 | ||
107 | VOID | |
108 | Ip4FreeRouteTable ( | |
109 | IN IP4_ROUTE_TABLE *RouteTable | |
110 | ); | |
111 | ||
112 | EFI_STATUS | |
113 | Ip4AddRoute ( | |
114 | IN IP4_ROUTE_TABLE *RtTable, | |
115 | IN IP4_ADDR Dest, | |
116 | IN IP4_ADDR Netmask, | |
117 | IN IP4_ADDR Gateway | |
118 | ); | |
119 | ||
120 | EFI_STATUS | |
121 | Ip4DelRoute ( | |
122 | IN IP4_ROUTE_TABLE *RtTable, | |
123 | IN IP4_ADDR Dest, | |
124 | IN IP4_ADDR Netmask, | |
125 | IN IP4_ADDR Gateway | |
126 | ); | |
127 | ||
128 | IP4_ROUTE_CACHE_ENTRY * | |
129 | Ip4FindRouteCache ( | |
130 | IN IP4_ROUTE_TABLE *RtTable, | |
131 | IN IP4_ADDR Dest, | |
132 | IN IP4_ADDR Src | |
133 | ); | |
134 | ||
135 | VOID | |
136 | Ip4FreeRouteCacheEntry ( | |
137 | IN IP4_ROUTE_CACHE_ENTRY *RtCacheEntry | |
138 | ); | |
139 | ||
140 | IP4_ROUTE_CACHE_ENTRY * | |
141 | Ip4Route ( | |
142 | IN IP4_ROUTE_TABLE *RtTable, | |
143 | IN IP4_ADDR Dest, | |
144 | IN IP4_ADDR Src | |
145 | ); | |
146 | ||
147 | EFI_STATUS | |
148 | Ip4BuildEfiRouteTable ( | |
149 | IN IP4_PROTOCOL *IpInstance | |
150 | ); | |
151 | #endif |