33 if (RtEntry ==
NULL) {
41 RtEntry->Netmask = Netmask;
42 RtEntry->NextHop = GateWay;
59 ASSERT (RtEntry->RefCnt > 0);
61 if (--RtEntry->RefCnt == 0) {
91 if (RtCacheEntry ==
NULL) {
97 RtCacheEntry->RefCnt = 1;
98 RtCacheEntry->Dest = Dst;
99 RtCacheEntry->Src = Src;
100 RtCacheEntry->NextHop = GateWay;
101 RtCacheEntry->Tag = Tag;
117 ASSERT (RtCacheEntry->RefCnt > 0);
119 if (--RtCacheEntry->RefCnt == 0) {
137 for (Index = 0; Index < IP4_ROUTE_CACHE_HASH_VALUE; Index++) {
159 for (Index = 0; Index < IP4_ROUTE_CACHE_HASH_VALUE; Index++) {
160 NET_LIST_FOR_EACH_SAFE (Entry, Next, &(RtCache->CacheBucket[Index])) {
186 if (RtTable ==
NULL) {
191 RtTable->TotalNum = 0;
193 for (Index = 0; Index <= IP4_MASK_MAX; Index++) {
197 RtTable->Next =
NULL;
220 ASSERT (RtTable->RefCnt > 0);
222 if (--RtTable->RefCnt > 0) {
229 for (Index = 0; Index <= IP4_MASK_MAX; Index++) {
230 NET_LIST_FOR_EACH_SAFE (Entry, Next, &(RtTable->RouteArea[Index])) {
264 for (Index = 0; Index < IP4_ROUTE_CACHE_HASH_VALUE; Index++) {
265 NET_LIST_FOR_EACH_SAFE (Entry, Next, &RtCache->CacheBucket[Index]) {
268 if (RtCacheEntry->Tag == Tag) {
311 NET_LIST_FOR_EACH (Entry, Head) {
314 if (IP4_NET_EQUAL (RtEntry->Dest, Dest, Netmask) && (RtEntry->NextHop == Gateway)) {
315 return EFI_ACCESS_DENIED;
324 if (RtEntry ==
NULL) {
325 return EFI_OUT_OF_RESOURCES;
328 if (Gateway == IP4_ALLZERO_ADDRESS) {
329 RtEntry->Flag = IP4_DIRECT_ROUTE;
366 NET_LIST_FOR_EACH_SAFE (Entry, Next, Head) {
369 if (IP4_NET_EQUAL (RtEntry->Dest, Dest, Netmask) && (RtEntry->NextHop == Gateway)) {
379 return EFI_NOT_FOUND;
407 Index = IP4_ROUTE_CACHE_HASH (Dest, Src);
409 NET_LIST_FOR_EACH (Entry, &RtTable->Cache.CacheBucket[Index]) {
412 if ((RtCacheEntry->Dest == Dest) && (RtCacheEntry->Src == Src)) {
413 NET_GET_REF (RtCacheEntry);
450 for (Index = IP4_MASK_MAX; Index >= 0; Index--) {
451 for (Table = RtTable; Table !=
NULL; Table = Table->Next) {
452 NET_LIST_FOR_EACH (Entry, &Table->RouteArea[Index]) {
455 if (IP4_NET_EQUAL (RtEntry->Dest, Dst, RtEntry->Netmask)) {
456 NET_GET_REF (RtEntry);
488 IN IP4_ADDR SubnetMask,
489 IN BOOLEAN AlwaysTryDestAddr
501 ASSERT (RtTable !=
NULL);
503 Head = &RtTable->Cache.CacheBucket[IP4_ROUTE_CACHE_HASH (Dest, Src)];
509 if (RtCacheEntry !=
NULL) {
520 if (RtEntry ==
NULL) {
521 if (SubnetMask != IP4_ALLONE_ADDRESS) {
523 }
else if (!AlwaysTryDestAddr) {
537 if ((SubnetMask == IP4_ALLONE_ADDRESS) || ((RtEntry->Flag & IP4_DIRECT_ROUTE) != 0)) {
540 NextHop = RtEntry->NextHop;
543 if (RtEntry !=
NULL) {
554 if (RtCacheEntry ==
NULL) {
559 NET_GET_REF (RtCacheEntry);
567 NET_LIST_FOR_EACH_SAFE (Entry, Next, Head) {
568 if (++Count < IP4_ROUTE_CACHE_MAX) {
604 RtTable = IpInstance->RouteTable;
606 if (IpInstance->EfiRouteTable !=
NULL) {
607 FreePool (IpInstance->EfiRouteTable);
609 IpInstance->EfiRouteTable =
NULL;
610 IpInstance->EfiRouteCount = 0;
613 Count = RtTable->TotalNum;
615 if (RtTable->Next !=
NULL) {
616 Count += RtTable->Next->TotalNum;
626 return EFI_OUT_OF_RESOURCES;
637 for (Index = IP4_MASK_MAX; Index >= 0; Index--) {
638 for (RtTable = IpInstance->RouteTable; RtTable !=
NULL; RtTable = RtTable->Next) {
639 NET_LIST_FOR_EACH (Entry, &(RtTable->RouteArea[Index])) {
642 EFI_IP4 (Table[Count].SubnetAddress) = HTONL (RtEntry->Dest & RtEntry->Netmask);
643 EFI_IP4 (Table[Count].SubnetMask) = HTONL (RtEntry->Netmask);
644 EFI_IP4 (Table[Count].GatewayAddress) = HTONL (RtEntry->NextHop);
651 IpInstance->EfiRouteTable = Table;
652 IpInstance->EfiRouteCount = Count;
LIST_ENTRY *EFIAPI InsertHeadList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS Ip4BuildEfiRouteTable(IN IP4_PROTOCOL *IpInstance)
IP4_ROUTE_CACHE_ENTRY * Ip4FindRouteCache(IN IP4_ROUTE_TABLE *RtTable, IN IP4_ADDR Dest, IN IP4_ADDR Src)
EFI_STATUS Ip4DelRoute(IN OUT IP4_ROUTE_TABLE *RtTable, IN IP4_ADDR Dest, IN IP4_ADDR Netmask, IN IP4_ADDR Gateway)
VOID Ip4FreeRouteCacheEntry(IN IP4_ROUTE_CACHE_ENTRY *RtCacheEntry)
VOID Ip4CleanRouteCache(IN IP4_ROUTE_CACHE *RtCache)
IP4_ROUTE_TABLE * Ip4CreateRouteTable(VOID)
IP4_ROUTE_ENTRY * Ip4FindRouteEntry(IN IP4_ROUTE_TABLE *RtTable, IN IP4_ADDR Dst)
IP4_ROUTE_CACHE_ENTRY * Ip4Route(IN IP4_ROUTE_TABLE *RtTable, IN IP4_ADDR Dest, IN IP4_ADDR Src, IN IP4_ADDR SubnetMask, IN BOOLEAN AlwaysTryDestAddr)
VOID Ip4InitRouteCache(IN OUT IP4_ROUTE_CACHE *RtCache)
IP4_ROUTE_ENTRY * Ip4CreateRouteEntry(IN IP4_ADDR Dest, IN IP4_ADDR Netmask, IN IP4_ADDR GateWay)
EFI_STATUS Ip4AddRoute(IN OUT IP4_ROUTE_TABLE *RtTable, IN IP4_ADDR Dest, IN IP4_ADDR Netmask, IN IP4_ADDR Gateway)
VOID Ip4FreeRouteEntry(IN IP4_ROUTE_ENTRY *RtEntry)
VOID Ip4PurgeRouteCache(IN OUT IP4_ROUTE_CACHE *RtCache, IN UINTN Tag)
VOID Ip4FreeRouteTable(IN IP4_ROUTE_TABLE *RtTable)
IP4_ROUTE_CACHE_ENTRY * Ip4CreateRouteCacheEntry(IN IP4_ADDR Dst, IN IP4_ADDR Src, IN IP4_ADDR GateWay, IN UINTN Tag)
INTN EFIAPI NetGetMaskLength(IN IP4_ADDR NetMask)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)