-
Notifications
You must be signed in to change notification settings - Fork 5.5k
matchers: extend network inputs to HTTP requests #20796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
fd4f8bb
6464060
200786d
817ae12
de264d3
3d77c5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #include "source/common/network/matching/inputs.h" | ||
|
|
||
| #include "envoy/http/filter.h" | ||
| #include "envoy/registry/registry.h" | ||
|
|
||
| #include "source/common/network/utility.h" | ||
|
|
@@ -10,9 +11,10 @@ namespace Envoy { | |
| namespace Network { | ||
| namespace Matching { | ||
|
|
||
| template <> | ||
| Matcher::DataInputGetResult DestinationIPInput<MatchingData>::get(const MatchingData& data) const { | ||
| const auto& address = data.socket().connectionInfoProvider().localAddress(); | ||
| template <class MatchingDataType> | ||
| Matcher::DataInputGetResult | ||
| DestinationIPInput<MatchingDataType>::get(const MatchingDataType& data) const { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these template implementations should be inlined and moved to "inputs.h". Otherwise, we may face with linking issues.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you elaborate? I've seen primary templates in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original contains a full template specialization implementation for // inputs.h
template <class MatchingDataType>
class SourceIPInput : public Matcher::DataInput<MatchingDataType> {
// template member implementation
Matcher::DataInputGetResult get(const MatchingDataType& data) const override {}
}
// template specialization definition for UdpMatchingData
template <>
Matcher::DataInputGetResult
DestinationIPInput<UdpMatchingData>::get(const UdpMatchingData& data) const;
// inputs.cc
// template specialization implementation for UdpMatchingData
template <>
Matcher::DataInputGetResult
DestinationIPInput<UdpMatchingData>::get(const UdpMatchingData& data) const {} |
||
| const auto& address = data.connectionInfoProvider().localAddress(); | ||
| if (address->type() != Network::Address::Type::Ip) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::nullopt}; | ||
| } | ||
|
|
@@ -31,10 +33,10 @@ DestinationIPInput<UdpMatchingData>::get(const UdpMatchingData& data) const { | |
| address.ip()->addressAsString()}; | ||
| } | ||
|
|
||
| template <> | ||
| template <class MatchingDataType> | ||
| Matcher::DataInputGetResult | ||
| DestinationPortInput<MatchingData>::get(const MatchingData& data) const { | ||
| const auto& address = data.socket().connectionInfoProvider().localAddress(); | ||
| DestinationPortInput<MatchingDataType>::get(const MatchingDataType& data) const { | ||
| const auto& address = data.connectionInfoProvider().localAddress(); | ||
| if (address->type() != Network::Address::Type::Ip) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::nullopt}; | ||
| } | ||
|
|
@@ -53,9 +55,10 @@ DestinationPortInput<UdpMatchingData>::get(const UdpMatchingData& data) const { | |
| absl::StrCat(address.ip()->port())}; | ||
| } | ||
|
|
||
| template <> | ||
| Matcher::DataInputGetResult SourceIPInput<MatchingData>::get(const MatchingData& data) const { | ||
| const auto& address = data.socket().connectionInfoProvider().remoteAddress(); | ||
| template <class MatchingDataType> | ||
| Matcher::DataInputGetResult | ||
| SourceIPInput<MatchingDataType>::get(const MatchingDataType& data) const { | ||
| const auto& address = data.connectionInfoProvider().remoteAddress(); | ||
| if (address->type() != Network::Address::Type::Ip) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::nullopt}; | ||
| } | ||
|
|
@@ -73,9 +76,10 @@ Matcher::DataInputGetResult SourceIPInput<UdpMatchingData>::get(const UdpMatchin | |
| address.ip()->addressAsString()}; | ||
| } | ||
|
|
||
| template <> | ||
| Matcher::DataInputGetResult SourcePortInput<MatchingData>::get(const MatchingData& data) const { | ||
| const auto& address = data.socket().connectionInfoProvider().remoteAddress(); | ||
| template <class MatchingDataType> | ||
| Matcher::DataInputGetResult | ||
| SourcePortInput<MatchingDataType>::get(const MatchingDataType& data) const { | ||
| const auto& address = data.connectionInfoProvider().remoteAddress(); | ||
| if (address->type() != Network::Address::Type::Ip) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::nullopt}; | ||
| } | ||
|
|
@@ -94,25 +98,32 @@ SourcePortInput<UdpMatchingData>::get(const UdpMatchingData& data) const { | |
| absl::StrCat(address.ip()->port())}; | ||
| } | ||
|
|
||
| Matcher::DataInputGetResult DirectSourceIPInput::get(const MatchingData& data) const { | ||
| const auto& address = data.socket().connectionInfoProvider().directRemoteAddress(); | ||
| template <class MatchingDataType> | ||
| Matcher::DataInputGetResult | ||
| DirectSourceIPInput<MatchingDataType>::get(const MatchingDataType& data) const { | ||
| const auto& address = data.connectionInfoProvider().directRemoteAddress(); | ||
| if (address->type() != Network::Address::Type::Ip) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::nullopt}; | ||
| } | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, | ||
| address->ip()->addressAsString()}; | ||
| } | ||
|
|
||
| Matcher::DataInputGetResult SourceTypeInput::get(const MatchingData& data) const { | ||
| const bool is_local_connection = Network::Utility::isSameIpOrLoopback(data.socket()); | ||
| template <class MatchingDataType> | ||
| Matcher::DataInputGetResult | ||
| SourceTypeInput<MatchingDataType>::get(const MatchingDataType& data) const { | ||
| const bool is_local_connection = | ||
| Network::Utility::isSameIpOrLoopback(data.connectionInfoProvider()); | ||
| if (is_local_connection) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, "local"}; | ||
| } | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::nullopt}; | ||
| } | ||
|
|
||
| Matcher::DataInputGetResult ServerNameInput::get(const MatchingData& data) const { | ||
| const auto server_name = data.socket().requestedServerName(); | ||
| template <class MatchingDataType> | ||
| Matcher::DataInputGetResult | ||
| ServerNameInput<MatchingDataType>::get(const MatchingDataType& data) const { | ||
| const auto server_name = data.connectionInfoProvider().requestedServerName(); | ||
| if (!server_name.empty()) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, | ||
| std::string(server_name)}; | ||
|
|
@@ -138,17 +149,53 @@ Matcher::DataInputGetResult ApplicationProtocolInput::get(const MatchingData& da | |
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::nullopt}; | ||
| } | ||
|
|
||
| class DestinationIPInputFactory : public DestinationIPInputBaseFactory<MatchingData> {}; | ||
| class UdpDestinationIPInputFactory : public DestinationIPInputBaseFactory<UdpMatchingData> {}; | ||
| class HttpDestinationIPInputFactory : public DestinationIPInputBaseFactory<Http::HttpMatchingData> { | ||
| }; | ||
| REGISTER_FACTORY(DestinationIPInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(UdpDestinationIPInputFactory, Matcher::DataInputFactory<UdpMatchingData>); | ||
| REGISTER_FACTORY(HttpDestinationIPInputFactory, Matcher::DataInputFactory<Http::HttpMatchingData>); | ||
|
|
||
| class DestinationPortInputFactory : public DestinationPortInputBaseFactory<MatchingData> {}; | ||
| class UdpDestinationPortInputFactory : public DestinationPortInputBaseFactory<UdpMatchingData> {}; | ||
| class HttpDestinationPortInputFactory | ||
| : public DestinationPortInputBaseFactory<Http::HttpMatchingData> {}; | ||
| REGISTER_FACTORY(DestinationPortInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(UdpDestinationPortInputFactory, Matcher::DataInputFactory<UdpMatchingData>); | ||
| REGISTER_FACTORY(HttpDestinationPortInputFactory, | ||
| Matcher::DataInputFactory<Http::HttpMatchingData>); | ||
|
|
||
| class SourceIPInputFactory : public SourceIPInputBaseFactory<MatchingData> {}; | ||
| class UdpSourceIPInputFactory : public SourceIPInputBaseFactory<UdpMatchingData> {}; | ||
| class HttpSourceIPInputFactory : public SourceIPInputBaseFactory<Http::HttpMatchingData> {}; | ||
| REGISTER_FACTORY(SourceIPInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(UdpSourceIPInputFactory, Matcher::DataInputFactory<UdpMatchingData>); | ||
| REGISTER_FACTORY(HttpSourceIPInputFactory, Matcher::DataInputFactory<Http::HttpMatchingData>); | ||
|
|
||
| class SourcePortInputFactory : public SourcePortInputBaseFactory<MatchingData> {}; | ||
| class UdpSourcePortInputFactory : public SourcePortInputBaseFactory<UdpMatchingData> {}; | ||
| class HttpSourcePortInputFactory : public SourcePortInputBaseFactory<Http::HttpMatchingData> {}; | ||
| REGISTER_FACTORY(SourcePortInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(UdpSourcePortInputFactory, Matcher::DataInputFactory<UdpMatchingData>); | ||
| REGISTER_FACTORY(HttpSourcePortInputFactory, Matcher::DataInputFactory<Http::HttpMatchingData>); | ||
|
|
||
| class DirectSourceIPInputFactory : public DirectSourceIPInputBaseFactory<MatchingData> {}; | ||
| class HttpDirectSourceIPInputFactory | ||
| : public DirectSourceIPInputBaseFactory<Http::HttpMatchingData> {}; | ||
| REGISTER_FACTORY(DirectSourceIPInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(SourceTypeInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(HttpDirectSourceIPInputFactory, Matcher::DataInputFactory<Http::HttpMatchingData>); | ||
|
|
||
| class ServerNameInputFactory : public ServerNameInputBaseFactory<MatchingData> {}; | ||
| class HttpServerNameInputFactory : public ServerNameInputBaseFactory<Http::HttpMatchingData> {}; | ||
| REGISTER_FACTORY(ServerNameInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(HttpServerNameInputFactory, Matcher::DataInputFactory<Http::HttpMatchingData>); | ||
|
|
||
| class SourceTypeInputFactory : public SourceTypeInputBaseFactory<MatchingData> {}; | ||
| class HttpSourceTypeInputFactory : public SourceTypeInputBaseFactory<Http::HttpMatchingData> {}; | ||
| REGISTER_FACTORY(SourceTypeInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(HttpSourceTypeInputFactory, Matcher::DataInputFactory<Http::HttpMatchingData>); | ||
|
|
||
| REGISTER_FACTORY(TransportProtocolInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(ApplicationProtocolInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would be better to provide a
StreamInfodirectly for HTTP matching data, compared toConnectionSocketfor network matching data?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StreamInfois complicated, it can be nested for internal redirects so I wanted to avoid bringing all that complexity implicitly.I think we'll probably end-up using it though.