chromium/services/network/public/cpp/ip_address_space_util.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/network/public/cpp/ip_address_space_util.h"

#include <utility>

#include "base/command_line.h"
#include "base/no_destructor.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/transport_info.h"
#include "services/network/public/cpp/content_security_policy/content_security_policy.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/network_switches.h"
#include "services/network/public/mojom/ip_address_space.mojom.h"
#include "services/network/public/mojom/parsed_headers.mojom.h"
#include "url/gurl.h"

namespace network {
namespace {

IPAddressSpace;
IPAddress;
IPEndPoint;

// Parses a string of the form "<URL-safe IP address>:<port>".
std::optional<IPEndPoint> ParseEndpoint(std::string_view str) {}

std::optional<IPAddressSpace> ParseIPAddressSpace(std::string_view str) {}

// Represents a single command-line-specified endpoint override.
struct EndpointOverride {};

// Parses an override from `str`, of the form "<endpoint>=<space>".
std::optional<EndpointOverride> ParseEndpointOverride(std::string_view str) {}

// Parses a comma-separated list of overrides. Ignores invalid entries.
std::vector<EndpointOverride> ParseEndpointOverrideList(std::string_view list) {}

// Applies overrides specified on the command-line to `endpoint`.
// Returns nullopt if no override matches `endpoint`.
std::optional<IPAddressSpace> ApplyCommandLineOverrides(
    const IPEndPoint& endpoint) {}

// Represents a single entry of the form: subnet -> address space.
class AddressSpaceMapEntry {};

std::optional<IPAddressSpace> AddressSpaceMapEntry::Apply(
    const IPAddress& address) const {}

// Maps IP addresses to IP address spaces.
class AddressSpaceMap {};

std::optional<IPAddressSpace> AddressSpaceMap::Apply(
    const IPAddress& address) const {}

// Returns a map containing all default-non-public subnets.
const AddressSpaceMap& NonPublicAddressSpaceMap() {}

}  // namespace

IPAddressSpace IPAddressToIPAddressSpace(const IPAddress& address) {}

namespace {

IPAddressSpace IPEndPointToIPAddressSpace(const IPEndPoint& endpoint) {}

}  // namespace

std::string_view IPAddressSpaceToStringPiece(IPAddressSpace space) {}

IPAddressSpace TransportInfoToIPAddressSpace(const net::TransportInfo& info) {}

namespace {

// For comparison purposes, we treat kUnknown the same as kPublic.
IPAddressSpace CollapseUnknown(IPAddressSpace space) {}

}  // namespace

bool IsLessPublicAddressSpace(IPAddressSpace lhs, IPAddressSpace rhs) {}

CalculateClientAddressSpaceParams::~CalculateClientAddressSpaceParams() =
    default;

mojom::IPAddressSpace CalculateClientAddressSpace(
    const GURL& url,
    std::optional<CalculateClientAddressSpaceParams> params) {}

mojom::IPAddressSpace CalculateResourceAddressSpace(
    const GURL& url,
    const net::IPEndPoint& endpoint) {}

}  // namespace network