1
#pragma once
2

            
3
#include "envoy/config/core/v3/address.pb.h"
4
#include "envoy/extensions/http/original_ip_detection/xff/v3/xff.pb.h"
5
#include "envoy/http/original_ip_detection.h"
6

            
7
#include "source/common/network/cidr_range.h"
8
#include "source/common/protobuf/protobuf.h"
9

            
10
namespace Envoy {
11
namespace Extensions {
12
namespace Http {
13
namespace OriginalIPDetection {
14
namespace Xff {
15

            
16
/**
17
 * XFF (x-forwarded-for) IP detection extension.
18
 */
19
class XffIPDetection : public Envoy::Http::OriginalIPDetection,
20
                       Logger::Loggable<Logger::Id::config> {
21
public:
22
  static absl::StatusOr<std::unique_ptr<XffIPDetection>>
23
  create(const envoy::extensions::http::original_ip_detection::xff::v3::XffConfig& config);
24

            
25
  XffIPDetection(uint32_t xff_num_trusted_hops, bool skip_xff_append);
26
  XffIPDetection(const std::vector<Network::Address::CidrRange> xff_trusted_cidrs,
27
                 bool skip_xff_append);
28

            
29
  Envoy::Http::OriginalIPDetectionResult
30
  detect(Envoy::Http::OriginalIPDetectionParams& params) override;
31

            
32
protected:
33
  XffIPDetection(const envoy::extensions::http::original_ip_detection::xff::v3::XffConfig& config);
34

            
35
  const uint32_t xff_num_trusted_hops_;
36
  std::vector<Network::Address::CidrRange> xff_trusted_cidrs_;
37
  const bool skip_xff_append_;
38
};
39

            
40
} // namespace Xff
41
} // namespace OriginalIPDetection
42
} // namespace Http
43
} // namespace Extensions
44
} // namespace Envoy