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
3
                                    Server::Configuration::ServerFactoryContext& factory_context) {
12
3
  const auto& ip_config = MessageUtil::downcastAndValidate<
13
3
      const envoy::extensions::matching::input_matchers::ip::v3::Ip&>(
14
3
      config, factory_context.messageValidationVisitor());
15

            
16
3
  const auto& cidr_ranges = ip_config.cidr_ranges();
17
3
  std::vector<Network::Address::CidrRange> ranges;
18
3
  ranges.reserve(cidr_ranges.size());
19
3
  for (const auto& cidr_range : cidr_ranges) {
20
2
    const std::string& address = cidr_range.address_prefix();
21
2
    const uint32_t prefix_len = cidr_range.prefix_len().value();
22
2
    const auto range = THROW_OR_RETURN_VALUE(
23
2
        Network::Address::CidrRange::create(address, prefix_len), Network::Address::CidrRange);
24
2
    ranges.emplace_back(std::move(range));
25
2
  }
26

            
27
3
  const std::string& stat_prefix = ip_config.stat_prefix();
28
3
  Stats::Scope& scope = factory_context.scope();
29
3
  return [ranges, stat_prefix, &scope]() {
30
1
    return std::make_unique<Matcher>(ranges, stat_prefix, scope);
31
1
  };
32
3
}
33
/**
34
 * Static registration for the IP matcher. @see RegisterFactory.
35
 */
36
REGISTER_FACTORY(Config, Envoy::Matcher::InputMatcherFactory);
37

            
38
} // namespace IP
39
} // namespace InputMatchers
40
} // namespace Matching
41
} // namespace Extensions
42
} // namespace Envoy