/* Remove a route entry and all the route caches spawn from it. It is the help function for EfiIp6Routes. */
EFI_STATUS Ip6DelRoute(IN OUT IP6_ROUTE_TABLE *RtTable, IN EFI_IPv6_ADDRESS *Destination, IN UINT8 PrefixLength, IN EFI_IPv6_ADDRESS *GatewayAddress)
/* Remove a route entry and all the route caches spawn from it. It is the help function for EfiIp6Routes. */
EFI_STATUS Ip6DelRoute(IN OUT IP6_ROUTE_TABLE *RtTable, IN EFI_IPv6_ADDRESS *Destination, IN UINT8 PrefixLength, IN EFI_IPv6_ADDRESS *GatewayAddress)
{
  LIST_ENTRY       *ListHead;
  LIST_ENTRY       *Entry;
  LIST_ENTRY       *Next;
  IP6_ROUTE_ENTRY  *Route;
  UINT32           TotalNum;
  ListHead = &RtTable->RouteArea[PrefixLength];
  TotalNum = RtTable->TotalNum;
  NET_LIST_FOR_EACH_SAFE (Entry, Next, ListHead) {
    Route = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_ENTRY, Link);
    if ((Destination != NULL) && !NetIp6IsNetEqual (Destination, &Route->Destination, PrefixLength)) {
      continue;
    }
    if ((GatewayAddress != NULL) && !EFI_IP6_EQUAL (GatewayAddress, &Route->NextHop)) {
      continue;
    }
    Ip6PurgeRouteCache (&RtTable->Cache, (UINTN)Route);
    RemoveEntryList (Entry);
    Ip6FreeRouteEntry (Route);
    ASSERT (RtTable->TotalNum > 0);
    RtTable->TotalNum--;
  }
  return TotalNum == RtTable->TotalNum ? EFI_NOT_FOUND : EFI_SUCCESS;
}