Skip to content

util: add PROXY protocol generation functions#10548

Merged
alyssawilk merged 9 commits intoenvoyproxy:masterfrom
wez470:proxy-protocol-header-generation
Apr 2, 2020
Merged

util: add PROXY protocol generation functions#10548
alyssawilk merged 9 commits intoenvoyproxy:masterfrom
wez470:proxy-protocol-header-generation

Conversation

@wez470
Copy link
Copy Markdown
Contributor

@wez470 wez470 commented Mar 26, 2020

Description: Add utility functions for generating v1 and v2 PROXY protocol headers. This is the first step to adding Envoy PROXY proto generation support. These functions can also be used in other places that would also like to generate the header.
Risk Level: Low
Testing: Unit
Docs Changes: None
Release Notes: None
Related to #1031

@alyssawilk


// See https://github.com/haproxy/haproxy/blob/master/doc/proxy-protocol.txt for definitions

constexpr char PROXY_PROTO_V1_SIGNATURE[] = "PROXY ";
Copy link
Copy Markdown
Contributor Author

@wez470 wez470 Mar 26, 2020

Choose a reason for hiding this comment

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

These constants overlap with ones created by the proxy proto listener filter. I opted to not refactor the listener filter to use these common ones for now to keep this PR simple. I think I can do that in a future PR. Willing to do it here if requested though.

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.

How about a TODO so we don't lose track?

@wez470
Copy link
Copy Markdown
Contributor Author

wez470 commented Mar 26, 2020

/retest

@repokitteh-read-only
Copy link
Copy Markdown

🐴 hold your horses - no failures detected, yet.

🐱

Caused by: a #10548 (comment) was created by @wez470.

see: more, trace.

@wez470
Copy link
Copy Markdown
Contributor Author

wez470 commented Mar 26, 2020

I saw the "envoy-linux (bazel clang_tidy)" build fail because it failed to fetch a repo. Thought I could re-run that with the retest thing but I guess not.
Screenshot_20200326_172512

Signed-off-by: Weston Carlson <[email protected]>
Copy link
Copy Markdown
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

This is awesome! Thanks for splitting it out :-)

One other thing would be good here, is having a unit test regression test that the header we generate is one the listener filter code can parse. I think it'd be better to land with this PR, but I'm fine with a TODO as long as you land it before landing any config using this utility.

namespace Common {
namespace ProxyProtocol {

void generate_v1_header(const std::string& src_addr, const std::string& dst_addr, uint32_t src_port,
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.

per style guide let's swap these from snake case towards generateV1Header etc.


// See https://github.com/haproxy/haproxy/blob/master/doc/proxy-protocol.txt for definitions

constexpr char PROXY_PROTO_V1_SIGNATURE[] = "PROXY ";
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.

How about a TODO so we don't lose track?

@wez470
Copy link
Copy Markdown
Contributor Author

wez470 commented Mar 30, 2020

Thanks for the feedback! I'll move the regression tests over to this branch 🙂.

@alyssawilk
Copy link
Copy Markdown
Contributor

LGTM pending CI cleanup :-)

@alyssawilk
Copy link
Copy Markdown
Contributor

@mattklein123 or @zuercher @snowp any of you up for second pass?

Signed-off-by: Weston Carlson <[email protected]>
@alyssawilk alyssawilk merged commit eb894d9 into envoyproxy:master Apr 2, 2020
@wez470 wez470 deleted the proxy-protocol-header-generation branch April 2, 2020 17:29
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Nice, just one small drive by comment post-submit. cc @alyssawilk

void generateV1Header(const std::string& src_addr, const std::string& dst_addr, uint32_t src_port,
uint32_t dst_port, Network::Address::IpVersion ip_version,
Buffer::Instance& out) {
std::ostringstream stream;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry late drive by: my (possibly out of date) understanding is that string streams are pretty slow. We probably would want to move this to an envoy buffer or similar in a later perf pass.

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.

3 participants