/* Add a route entry to the route table. It is the help function for EfiIp6Routes. */
EFI_STATUS Ip6AddRoute(IN OUT IP6_ROUTE_TABLE *RtTable, IN EFI_IPv6_ADDRESS *Destination, IN UINT8 PrefixLength, IN EFI_IPv6_ADDRESS *GatewayAddress)
/* Add a route entry to the route table. It is the help function for EfiIp6Routes. */
EFI_STATUS Ip6AddRoute(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;
  IP6_ROUTE_ENTRY  *Route;
  ListHead = &RtTable->RouteArea[PrefixLength];
  NET_LIST_FOR_EACH (Entry, ListHead) {
    Route = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_ENTRY, Link);
    if (NetIp6IsNetEqual (Destination, &Route->Destination, PrefixLength) &&
        EFI_IP6_EQUAL (GatewayAddress, &Route->NextHop))
    {
      return EFI_ACCESS_DENIED;
    }
  }
  Route = Ip6CreateRouteEntry (Destination, PrefixLength, GatewayAddress);
  if (Route == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }
  if (NetIp6IsUnspecifiedAddr (GatewayAddress)) {
    Route->Flag = IP6_DIRECT_ROUTE;
  }
  InsertHeadList (ListHead, &Route->Link);
  RtTable->TotalNum++;
  return EFI_SUCCESS;
}