1
#include "source/common/network/ip_address.h"
2

            
3
#include "envoy/registry/registry.h"
4
#include "envoy/stream_info/filter_state.h"
5

            
6
#include "source/common/network/utility.h"
7

            
8
namespace Envoy {
9
namespace Network {
10

            
11
namespace {
12
24
const std::string& key() { CONSTRUCT_ON_FIRST_USE(std::string, "envoy.network.ip"); }
13
} // namespace
14

            
15
/**
16
 * Registers the filter state object for the dynamic extension support.
17
 */
18
class BaseIPAddressObjectFactory : public StreamInfo::FilterState::ObjectFactory {
19
public:
20
24
  std::string name() const override { return key(); }
21

            
22
  std::unique_ptr<StreamInfo::FilterState::Object>
23
1
  createFromBytes(absl::string_view data) const override {
24
1
    const auto address = Utility::parseInternetAddressNoThrow(std::string(data));
25
1
    return address ? std::make_unique<IPAddressObject>(address) : nullptr;
26
1
  };
27
};
28

            
29
REGISTER_FACTORY(BaseIPAddressObjectFactory, StreamInfo::FilterState::ObjectFactory);
30
} // namespace Network
31
} // namespace Envoy