-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: antoniovleonti <[email protected]>
- Loading branch information
1 parent
ab9ff8e
commit 1cd6e9e
Showing
12 changed files
with
258 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "source/common/common/filter_state_object_matchers.h" | ||
|
||
#include "envoy/common/exception.h" | ||
#include "envoy/network/address.h" | ||
#include "envoy/stream_info/filter_state.h" | ||
|
||
#include "source/common/network/cidr_range.h" | ||
|
||
#include "absl/status/statusor.h" | ||
#include "xds/core/v3/cidr.pb.h" | ||
|
||
namespace Envoy { | ||
namespace Matchers { | ||
|
||
FilterStateIpRangeMatcher::FilterStateIpRangeMatcher(const Network::Address::CidrRange& cidr_range) | ||
: cidr_range_(cidr_range) {} | ||
|
||
bool FilterStateIpRangeMatcher::match(const StreamInfo::FilterState::Object& object) const { | ||
const Network::Address::InstanceConstSharedPtrAccessor* ip = | ||
dynamic_cast<const Network::Address::InstanceConstSharedPtrAccessor*>(&object); | ||
if (ip == nullptr) { | ||
return false; | ||
} | ||
return cidr_range_.isInRange(*ip->getIp()); | ||
} | ||
|
||
FilterStateStringMatcher::FilterStateStringMatcher(StringMatcherPtr&& string_matcher) | ||
: string_matcher_(std::move(string_matcher)) {} | ||
|
||
bool FilterStateStringMatcher::match(const StreamInfo::FilterState::Object& object) const { | ||
const auto string_value = object.serializeAsString(); | ||
return string_value && string_matcher_->match(*string_value); | ||
} | ||
|
||
} // namespace Matchers | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include "envoy/common/matchers.h" | ||
#include "envoy/common/pure.h" | ||
#include "envoy/stream_info/filter_state.h" | ||
|
||
#include "source/common/network/cidr_range.h" | ||
|
||
namespace Envoy { | ||
namespace Matchers { | ||
|
||
class FilterStateObjectMatcher { | ||
public: | ||
virtual bool match(const StreamInfo::FilterState::Object& object) const PURE; | ||
virtual ~FilterStateObjectMatcher(){}; | ||
}; | ||
|
||
using FilterStateObjectMatcherPtr = std::unique_ptr<FilterStateObjectMatcher>; | ||
|
||
class FilterStateIpRangeMatcher : public FilterStateObjectMatcher { | ||
public: | ||
FilterStateIpRangeMatcher(const Network::Address::CidrRange& cidr_range); | ||
bool match(const StreamInfo::FilterState::Object& object) const override; | ||
|
||
private: | ||
Envoy::Network::Address::CidrRange cidr_range_; | ||
}; | ||
|
||
class FilterStateStringMatcher : public FilterStateObjectMatcher { | ||
public: | ||
FilterStateStringMatcher(StringMatcherPtr&& string_matcher); | ||
bool match(const StreamInfo::FilterState::Object& object) const override; | ||
|
||
private: | ||
const StringMatcherPtr string_matcher_; | ||
}; | ||
|
||
} // namespace Matchers | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.