-
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.
move proxy protocol TLV parser into core
- Loading branch information
Showing
12 changed files
with
117 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_library", | ||
"envoy_package", | ||
) | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
envoy_package() | ||
|
||
envoy_cc_library( | ||
name = "proxy_protocol_lib", | ||
srcs = ["proxy_protocol.cc"], | ||
hdrs = ["proxy_protocol.h"], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//envoy/network:proxy_protocol_options_lib", | ||
"@com_google_absl//absl/types:optional", | ||
"@envoy_api//envoy/config/core/v3:pkg_cc_proto", | ||
], | ||
) |
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,19 @@ | ||
#include "source/common/proxy_protocol/proxy_protocol.h" | ||
|
||
namespace Envoy { | ||
namespace Common { | ||
namespace ProxyProtocol { | ||
|
||
Network::ProxyProtocolTLVVector | ||
parseTLVs(absl::Span<const envoy::config::core::v3::ProxyProtocolTLV* const> tlvs) { | ||
Network::ProxyProtocolTLVVector tlv_vector; | ||
for (const auto& tlv : tlvs) { | ||
const std::vector<unsigned char> value(tlv->value().begin(), tlv->value().end()); | ||
tlv_vector.push_back({static_cast<uint8_t>(tlv->type()), value}); | ||
} | ||
return tlv_vector; | ||
} | ||
|
||
} // namespace ProxyProtocol | ||
} // namespace Common | ||
} // 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,18 @@ | ||
#pragma once | ||
|
||
#include "envoy/config/core/v3/proxy_protocol.pb.h" | ||
#include "envoy/network/proxy_protocol.h" | ||
|
||
#include "absl/types/span.h" | ||
|
||
namespace Envoy { | ||
namespace Common { | ||
namespace ProxyProtocol { | ||
|
||
// Parses proxy protocol TLVs from the given configuration. | ||
Network::ProxyProtocolTLVVector | ||
parseTLVs(absl::Span<const envoy::config::core::v3::ProxyProtocolTLV* const> tlvs); | ||
|
||
} // namespace ProxyProtocol | ||
} // namespace Common | ||
} // 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
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,19 @@ | ||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_test", | ||
"envoy_package", | ||
) | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
envoy_package() | ||
|
||
envoy_cc_test( | ||
name = "proxy_protocol_test", | ||
srcs = ["proxy_protocol_test.cc"], | ||
rbe_pool = "6gig", | ||
deps = [ | ||
"//source/common/proxy_protocol:proxy_protocol_lib", | ||
"//test/test_common:utility_lib", | ||
], | ||
) |
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,34 @@ | ||
#include "source/common/common/logger.h" | ||
#include "source/common/proxy_protocol/proxy_protocol.h" | ||
|
||
#include "test/test_common/utility.h" | ||
|
||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
|
||
namespace Envoy { | ||
namespace Common { | ||
namespace ProxyProtocol { | ||
namespace { | ||
|
||
TEST(ProxyProtocolHeaderTest, ParseTLVs) { | ||
Protobuf::RepeatedPtrField<envoy::config::core::v3::ProxyProtocolTLV> tlvs; | ||
auto* tlv = tlvs.Add(); | ||
tlv->set_type(0x1); | ||
tlv->set_value("tlv1"); | ||
tlv = tlvs.Add(); | ||
tlv->set_type(0xE1); | ||
tlv->set_value("tlv2"); | ||
const auto tlv_vector = parseTLVs(tlvs); | ||
|
||
EXPECT_EQ(2, tlv_vector.size()); | ||
EXPECT_EQ(0x1, tlv_vector[0].type); | ||
EXPECT_EQ(std::vector<unsigned char>({'t', 'l', 'v', '1'}), tlv_vector[0].value); | ||
EXPECT_EQ(0xE1, tlv_vector[1].type); | ||
EXPECT_EQ(std::vector<unsigned char>({'t', 'l', 'v', '2'}), tlv_vector[1].value); | ||
} | ||
|
||
} // namespace | ||
} // namespace ProxyProtocol | ||
} // namespace Common | ||
} // 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