Skip to content

matchers: extend network inputs to HTTP requests#20796

Merged
snowp merged 6 commits intoenvoyproxy:mainfrom
kyessenov:network_inputs_http
Apr 18, 2022
Merged

matchers: extend network inputs to HTTP requests#20796
snowp merged 6 commits intoenvoyproxy:mainfrom
kyessenov:network_inputs_http

Conversation

@kyessenov
Copy link
Copy Markdown
Contributor

Signed-off-by: Kuat Yessenov kuat@google.com

Commit Message: Extend network inputs (e.g. source IP) to HTTP requests. Reuse all code with templates.
Additional Description:
Risk Level: low
Testing: unit
Docs Changes: yes
Release Notes: no
Issue: #20623

Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
@zhxie
Copy link
Copy Markdown
Contributor

zhxie commented Apr 13, 2022

I think SourceTypeInput is also available for HTTP matching data. Utility::isSameIpOrLoopback takes a ConnectionSocket as the argument but it just uses the connectionInfoProvider() behind the socket.

class HttpMatchingDataImpl : public HttpMatchingData {
public:
explicit HttpMatchingDataImpl(const Network::ConnectionInfoProvider& connection_info_provider)
: connection_info_provider_(connection_info_provider) {}
Copy link
Copy Markdown
Contributor

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 StreamInfo directly for HTTP matching data, compared to ConnectionSocket for network matching data?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StreamInfo is 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.

@kyessenov
Copy link
Copy Markdown
Contributor Author

Thanks @zhxie , added source type, too.

Signed-off-by: Kuat Yessenov <kuat@google.com>
const auto& address = data.socket().connectionInfoProvider().localAddress();
template <class MatchingDataType>
Matcher::DataInputGetResult
DestinationIPInput<MatchingDataType>::get(const MatchingDataType& data) const {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate? I've seen primary templates in .cc files used, and that works as long as it's used only within the .cc file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original contains a full template specialization implementation for MatchingData and another for UdpMatchingData. A template specialization implementation can be located in .cc, and the linker will recognize their symbols for linking. Now, we are going to change to a template member implementation, the implementation should be moved to ".h". We may come up with

// 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 {}

@kyessenov
Copy link
Copy Markdown
Contributor Author

/retest
(flake)

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #20796 (comment) was created by @kyessenov.

see: more, trace.

Signed-off-by: Kuat Yessenov <kuat@google.com>

template <class MatchingDataType>
Matcher::DataInputGetResult
DestinationIPInput<MatchingDataType>::get(const MatchingDataType& data) const {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and we can take a step further. The template member implementation can be inlined. We can directly move the code to line 37.

Signed-off-by: Kuat Yessenov <kuat@google.com>
Copy link
Copy Markdown
Contributor

@zhxie zhxie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a great work. In fact, I am not a first-pass, so maybe I cannot give an approval. Maybe @snowp can have a look.

@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Apr 18, 2022

cc @snowp friendly ping.

Copy link
Copy Markdown
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one optional request

public:
Matcher::DataInputGetResult get(const MatchingDataType& data) const override;
Matcher::DataInputGetResult get(const MatchingDataType& data) const override {
const auto& address = data.connectionInfoProvider().localAddress();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could add a data.localAddress() to all the matching types and then we don't need the different template specializations? i.e make them all quack the same for these shared input types

Can defer this to another PR if you'd prefer, lmk

Copy link
Copy Markdown
Contributor Author

@kyessenov kyessenov Apr 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the function get<T>(const T&) needs to be implemented for each data type T. We could use a base override getGeneric if all T implement some interface, but we still need to have the boilerplate to call getGeneric from get.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok not important, we can merge for now

@snowp snowp merged commit 569f239 into envoyproxy:main Apr 18, 2022
zhxie added a commit to zhxie/envoy that referenced this pull request Apr 19, 2022
refer to envoyproxy#20796

Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
vehre-x41 pushed a commit to vehre-x41/envoy that referenced this pull request Apr 19, 2022
Extend network inputs (e.g. source IP) to HTTP requests. Reuse all code with templates.

Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Andre Vehreschild <vehre@x41-dsec.de>
ravenblackx pushed a commit to ravenblackx/envoy that referenced this pull request Jun 8, 2022
Extend network inputs (e.g. source IP) to HTTP requests. Reuse all code with templates.

Signed-off-by: Kuat Yessenov <kuat@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants