/* Free the route table and its associated route cache. Route table is reference counted. */
VOID Ip4FreeRouteTable(IN IP4_ROUTE_TABLE *RtTable)
/* Free the route table and its associated route cache. Route table is reference counted. */
VOID Ip4FreeRouteTable(IN IP4_ROUTE_TABLE *RtTable)
{
  LIST_ENTRY       *Entry;
  LIST_ENTRY       *Next;
  IP4_ROUTE_ENTRY  *RtEntry;
  UINT32           Index;
  ASSERT (RtTable->RefCnt > 0);
  if (--RtTable->RefCnt > 0) {
    return;
  }
  for (Index = 0; Index <= IP4_MASK_MAX; Index++) {
    NET_LIST_FOR_EACH_SAFE (Entry, Next, &(RtTable->RouteArea[Index])) {
      RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);
      RemoveEntryList (Entry);
      Ip4FreeRouteEntry (RtEntry);
    }
  }
  Ip4CleanRouteCache (&RtTable->Cache);
  FreePool (RtTable);
}