LCOV - code coverage report
Current view: top level - source/extensions/matching/input_matchers/ip - config.cc (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 0 20 0.0 %
Date: 2024-01-05 06:35:25 Functions: 0 2 0.0 %

          Line data    Source code
       1             : #include "source/extensions/matching/input_matchers/ip/config.h"
       2             : 
       3             : namespace Envoy {
       4             : namespace Extensions {
       5             : namespace Matching {
       6             : namespace InputMatchers {
       7             : namespace IP {
       8             : 
       9             : Envoy::Matcher::InputMatcherFactoryCb
      10             : Config::createInputMatcherFactoryCb(const Protobuf::Message& config,
      11           0 :                                     Server::Configuration::ServerFactoryContext& factory_context) {
      12           0 :   const auto& ip_config = MessageUtil::downcastAndValidate<
      13           0 :       const envoy::extensions::matching::input_matchers::ip::v3::Ip&>(
      14           0 :       config, factory_context.messageValidationVisitor());
      15             : 
      16           0 :   const auto& cidr_ranges = ip_config.cidr_ranges();
      17           0 :   std::vector<Network::Address::CidrRange> ranges;
      18           0 :   ranges.reserve(cidr_ranges.size());
      19           0 :   for (const auto& cidr_range : cidr_ranges) {
      20           0 :     const std::string& address = cidr_range.address_prefix();
      21           0 :     const uint32_t prefix_len = cidr_range.prefix_len().value();
      22           0 :     const auto range = Network::Address::CidrRange::create(address, prefix_len);
      23             :     // We only assert that the range is valid because:
      24             :     // * if "address" can't be parsed, it will throw an EnvoyException
      25             :     // * prefix_len can't be < 0 as per the protobuf definition as an uint32_t
      26             :     // * if prefix_len is too big, CidrRange::create clamps it to a valid value
      27             :     // => it is thus not possible to create an invalid range.
      28           0 :     ASSERT(range.isValid(), "address range should be valid!");
      29           0 :     ranges.emplace_back(std::move(range));
      30           0 :   }
      31             : 
      32           0 :   const std::string& stat_prefix = ip_config.stat_prefix();
      33           0 :   Stats::Scope& scope = factory_context.scope();
      34           0 :   return [ranges, stat_prefix, &scope]() {
      35           0 :     return std::make_unique<Matcher>(ranges, stat_prefix, scope);
      36           0 :   };
      37           0 : }
      38             : /**
      39             :  * Static registration for the IP matcher. @see RegisterFactory.
      40             :  */
      41             : REGISTER_FACTORY(Config, Envoy::Matcher::InputMatcherFactory);
      42             : 
      43             : } // namespace IP
      44             : } // namespace InputMatchers
      45             : } // namespace Matching
      46             : } // namespace Extensions
      47             : } // namespace Envoy

Generated by: LCOV version 1.15