-
Notifications
You must be signed in to change notification settings - Fork 5.3k
listener: remove the peek from the listener filters #17395
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
Merged
Merged
Changes from all commits
Commits
Show all changes
177 commits
Select commit
Hold shift + click to select a range
8be8d06
Add listener filter buffer
soulxu dfe1577
Update listener filter interface
soulxu c803b2c
Using the new ListenerFilterBuffer
soulxu a78ca39
fix
soulxu 8aaacff
convert proxy protocol filter to use ListenerFilterBuffer
soulxu f47023a
fix proxy filter
soulxu 6ceb43b
Using Buffer::Instance for ListenerFilterBuffer
soulxu 1fc908d
Using Buffer::Instance for copyOut method
soulxu 7c27f7f
using the new copyOut method for tls inspect
soulxu ab3fb54
turn the proxy filter to use new copyOut method
soulxu 066a931
remove the old copyOut method
soulxu 0ce5112
Peek the data manually when accept the connection
soulxu 375c1a5
fix format
soulxu eb61a46
Add ConstRawBuffer
soulxu 7523574
Using the ConstRawSlice for tls inspect
soulxu 31889ef
Using ConstRawSlice for proxy filter
soulxu 78d3104
Remove copyOut method
soulxu 52a5752
Add unittest for ListenerFilterBufferImpl
soulxu 7ba4fb9
Change inspectSize to maxReadBytes
soulxu e8faf52
Update the variable name
soulxu 8a4d00e
Add test for ActiveTcpSocket
soulxu bdf5559
fix the spell
soulxu 133a795
fix listener filter timeout test
soulxu 2d1eda8
add test for tls inspect filter
soulxu 9696e49
fix tls inspect benchmark test
soulxu 0f4e465
remove useless stats for tls inspect filter
soulxu f9ac956
Convert proxy filter to use new interface
soulxu 4ce02f6
Check the zero return value of recv
soulxu dff726a
close the socket when connection failed
soulxu 94104e2
fix format
soulxu e227e38
Remove useless method for proxy filter
soulxu efa5857
Convert the http inspect filter to new interface
soulxu a07c7f9
fix connection handler test
soulxu d558321
fix format
soulxu e8ce277
Add debug log
soulxu 3f73e69
Reject the conneciton when filter stop iteration and doesn't expect a…
soulxu 7b8d032
Merge branch 'main' into poc_peek_data
soulxu 82e5d2b
fix format
soulxu ae391ec
fix spell
soulxu 789456e
end with new line
soulxu 065d6b5
fix listener filter buffer test file
soulxu c2a57ad
revert the format change to quic logging
soulxu d2540e8
remove useless header file
soulxu bbfca55
fix http inspect filter test
soulxu 1d55e8d
Fix http insepct InvalidConnectionPreface test
soulxu a360a31
Address the issues clang tidy reported
soulxu 06aa973
fix the coverage
soulxu aba84f9
Merge branch 'main' into poc_peek_data
soulxu 9015048
make the maxReadBytes as pure method
soulxu df2ad02
Using drain instead of drainFromSocket and use raw buffer
soulxu aaa6d9a
fix format
soulxu 7bffad3
revert the format change for quic header
soulxu 37c16a5
cleanup
soulxu c7858e3
fix format
soulxu 80f8f8b
return Error when drain failed for proxy filter
soulxu 9725f08
Add debug log
soulxu 6b0f734
revert the quick header format change
soulxu 62c3845
remove the closed event registeration
soulxu 0fff99b
Remove close event handle in listenerfilterbuffer
soulxu 4bda3ac
fix test
soulxu 3be4ee0
Using uint8_t instead of char
soulxu d88ae5a
Using uint64_t instead of size_t
soulxu 4a8d69e
Using the buffer_ for drain
soulxu 41b3aa0
adjust comment
soulxu a606cf4
Assert the filter expect data when return stop from onAccept
soulxu 705a58d
fix format
soulxu fa5a289
Windows: Emulate MSG_PEEK by read
c2b5b44
fix format
fd85009
fix compiler warning
8972610
fix compilation issue
4aeaeae
more coverage is needed but still testing ci
544a1c8
Merge remote-tracking branch 'upstream/main' into peekWindows2
15fc820
fix format and increase coverage
4e60815
fix format
fe11b35
fix gcc
5370061
Merge branch 'main' into poc_peek_data
soulxu 775f040
fix
soulxu 052fdca
Remove the useless check for drainning
soulxu 268b047
Add assertion for valid data size
soulxu 1534dcd
address PR feedack v1
347d474
Merge branch 'peekWindows2' into poc_peek_data
soulxu 6efde49
fix format
soulxu e98e7b9
Fix proxy protocol test for windows mimic peek
soulxu 0e26bd2
Merge branch 'main' into poc_peek_data
soulxu 3f428ef
Fix the JA3 related unittest
soulxu 002aa00
Merge branch 'main' into poc_peek_data
soulxu bd75c8e
fix build for active internal listener
soulxu 3eb8880
address comments
f2fd1fb
fix spelling
72e8f20
fix format
db35fbf
add override keyword
16caa4f
another format fix
a479ef8
fix string buffer used in fuzzing
d3dd4d3
fix typo in fuzzer
23c6341
add override keyword
1c1223f
fixed another typo
abe8be2
remove unused parameters
046a769
fix format
soulxu 02e5397
Merge branch 'peekWindows2' into poc_peek_data
soulxu 5705fe5
fix active internal listener test
soulxu 3b60d73
test original src filter
soulxu bfb1336
Merge branch 'main' into poc_peek_data
soulxu 31aee37
PR comments and tests
55361a3
add hint for mac compiler
320e370
Improve the copyOutToSlices method
soulxu f73213d
Merge branch 'main' into peekWindows2
soulxu a2e8799
address comment
soulxu d113f4c
type conversion for macos
soulxu 0c03750
correct the copyOutToSlices method
soulxu 52828ee
Merge branch 'main' into peekWindows2
soulxu 959170b
remove NOT_IMPLEMENTED_GCOVR_EXCL_LINE
soulxu d023827
Merge branch 'main' into peekWindows2
soulxu d2fe6e2
address comment
soulxu d673110
Merge branch 'main' into peekWindows2
soulxu 6a25bfd
Merge branch 'peekWindows2' into poc_peek_data
soulxu f5491ce
Merge branch 'main' into poc_peek_data
soulxu eee4e6e
remove deprecated test
soulxu 7df678c
adjust coverage rate
soulxu 7e7c3da
Add more tests for windows
soulxu b3d9a42
update spell dict for iov and iovcnt
soulxu dfc5527
listener: check the listener isn't stopped when balance the request
soulxu 7dcd41c
fix comment
soulxu bef9023
add test
soulxu 48b574d
more fix
soulxu 72d978a
Assert the ip address
soulxu d32a126
revert unrelated change
soulxu 0749507
Merge branch 'main' into poc_peek_data
soulxu 12cb6b3
Merge branch 'check_listener' into poc_peek_data
soulxu 2ded76a
A test for windows
soulxu e77307a
Merge branch 'main' into poc_peek_data
soulxu cec8291
fix the merge
soulxu c9a90af
revert test change
soulxu 7965de9
fix format
soulxu 197af3b
Merge branch 'main' into poc_peek_data
soulxu dbcbc21
ListenerFilterBuffer: remove the bool return value for drain method
soulxu 607e348
ActiveTcpListener: add counter stats for peek data
soulxu f94ff76
ListenerFilterBuffer: add method to enable activate file event manually
soulxu a7baa39
Fix the test
soulxu 03b494e
Add assertion ensure filter won't return stop when no more data
soulxu 1c5a548
Add doc for stats
soulxu 6df4baa
ListenerFilterBuffer: pass the buffer as on data callback param
soulxu ff70529
fix the test
soulxu 0250b08
fix the assertion
soulxu 1b734b1
remove the useless check
soulxu e1d277c
Fix the test
soulxu aa0e113
revert useless format change
soulxu c713a4f
add fuzz test
soulxu 0296e09
add endline
soulxu 0c5f498
Remove the length method
soulxu f9d520f
fix typo
soulxu a3cd1e0
fix the clang tidy complain
soulxu 0c9d84d
Revert "revert useless format change"
soulxu 4088880
Merge branch 'main' into poc_peek_data
soulxu 8d190cb
revert unrelated format change
soulxu ec80e88
revert format change
soulxu 7daa3f0
Merge branch 'main' into poc_peek_data
soulxu 1abda9f
Address comment
soulxu 8b454fd
Address comment
soulxu c534a97
Fix the maxReadBytes for Proxy filter
soulxu 3248c72
fix comment
soulxu 3ea4755
change the stats name
soulxu 920dc64
Add comments
soulxu ca4fb1b
Process the case of drain failed
soulxu af40bae
Enable the capacity of ListenerFilterBufferImpl changable
soulxu 38dffc7
fix the spell
soulxu b8bb4df
Fix the connection handler test
soulxu 5136c59
Add resetCapacity and read eagain to the fuzz test
soulxu cab9e59
Add ListenerFilterWithDataFuzzer test
soulxu 730cf45
Refactor tls inspector test
soulxu 2b5636d
Cleanup build file
soulxu d30d7fc
fix format
soulxu ca84c78
fix build file
soulxu 2604a1b
correct the declare of Return
soulxu b523971
fix log
soulxu 5cdfe2b
Merge branch 'main' into poc_peek_data
soulxu 26f32f0
Merge branch 'main' into poc_peek_data
soulxu ea26901
fix release note
soulxu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,33 @@ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "envoy/buffer/buffer.h" | ||
| #include "envoy/common/pure.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Network { | ||
|
|
||
| /** | ||
| * Interface for ListenerFilterBuffer | ||
| */ | ||
| class ListenerFilterBuffer { | ||
| public: | ||
| virtual ~ListenerFilterBuffer() = default; | ||
|
|
||
| /** | ||
| * Return a single const raw slice to the buffer of the data. | ||
| * @return a Buffer::ConstRawSlice pointed to raw buffer. | ||
| */ | ||
| virtual const Buffer::ConstRawSlice rawSlice() const PURE; | ||
|
|
||
| /** | ||
| * Drain the data from the beginning of the buffer. | ||
| * @param length the length of data to drain. | ||
| * @return a bool indicate the drain is successful or not. | ||
| */ | ||
| virtual bool drain(uint64_t length) PURE; | ||
| }; | ||
|
|
||
| } // namespace Network | ||
| } // namespace Envoy | ||
This file contains hidden or 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 hidden or 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,107 @@ | ||
| #include "source/common/network/listener_filter_buffer_impl.h" | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace Envoy { | ||
| namespace Network { | ||
|
|
||
| ListenerFilterBufferImpl::ListenerFilterBufferImpl(IoHandle& io_handle, | ||
| Event::Dispatcher& dispatcher, | ||
| ListenerFilterBufferOnCloseCb close_cb, | ||
| ListenerFilterBufferOnDataCb on_data_cb, | ||
| uint64_t buffer_size) | ||
| : io_handle_(io_handle), dispatcher_(dispatcher), on_close_cb_(close_cb), | ||
| on_data_cb_(on_data_cb), buffer_(std::make_unique<uint8_t[]>(buffer_size)), | ||
| base_(buffer_.get()), buffer_size_(buffer_size) { | ||
| // If the buffer_size not greater than 0, it means that doesn't expect any data. | ||
| ASSERT(buffer_size > 0); | ||
|
|
||
| io_handle_.initializeFileEvent( | ||
| dispatcher_, [this](uint32_t events) { onFileEvent(events); }, | ||
| Event::PlatformDefaultTriggerType, Event::FileReadyType::Read); | ||
| } | ||
|
|
||
| const Buffer::ConstRawSlice ListenerFilterBufferImpl::rawSlice() const { | ||
| Buffer::ConstRawSlice slice; | ||
| slice.mem_ = base_; | ||
| slice.len_ = data_size_; | ||
| return slice; | ||
| } | ||
|
|
||
| bool ListenerFilterBufferImpl::drain(uint64_t length) { | ||
| if (length == 0) { | ||
| return true; | ||
| } | ||
|
|
||
| ASSERT(length <= data_size_); | ||
|
|
||
| uint64_t read_size = 0; | ||
| while (read_size < length) { | ||
| auto result = io_handle_.recv(base_, length - read_size, 0); | ||
| ENVOY_LOG(trace, "recv returned: {}", result.return_value_); | ||
|
|
||
| if (!result.ok()) { | ||
| // `IoErrorCode::Again` isn't processed here, since | ||
| // the data already in the socket buffer. | ||
| return false; | ||
| } | ||
| read_size += result.return_value_; | ||
| } | ||
| base_ += length; | ||
| data_size_ -= length; | ||
| return true; | ||
| } | ||
|
|
||
| PeekState ListenerFilterBufferImpl::peekFromSocket() { | ||
| // Reset buffer base in case of draining changed base. | ||
| auto old_base = base_; | ||
| base_ = buffer_.get(); | ||
| const auto result = io_handle_.recv(base_, buffer_size_, MSG_PEEK); | ||
mattklein123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ENVOY_LOG(trace, "recv returned: {}", result.return_value_); | ||
|
|
||
| if (!result.ok()) { | ||
| if (result.err_->getErrorCode() == Api::IoError::IoErrorCode::Again) { | ||
| ENVOY_LOG(trace, "recv return try again"); | ||
| base_ = old_base; | ||
| return PeekState::Again; | ||
| } | ||
| ENVOY_LOG(debug, "recv failed: {}: {}", static_cast<int>(result.err_->getErrorCode()), | ||
| result.err_->getErrorDetails()); | ||
| return PeekState::Error; | ||
| } | ||
| // Remote closed | ||
| if (result.return_value_ == 0) { | ||
| ENVOY_LOG(debug, "recv failed: remote closed"); | ||
| return PeekState::RemoteClose; | ||
| } | ||
| data_size_ = result.return_value_; | ||
| ASSERT(data_size_ <= buffer_size_); | ||
|
|
||
| return PeekState::Done; | ||
| } | ||
|
|
||
| void ListenerFilterBufferImpl::resetCapacity(uint64_t size) { | ||
| buffer_ = std::make_unique<uint8_t[]>(size); | ||
| base_ = buffer_.get(); | ||
| buffer_size_ = size; | ||
| data_size_ = 0; | ||
| } | ||
|
|
||
| void ListenerFilterBufferImpl::activateFileEvent(uint32_t events) { onFileEvent(events); } | ||
|
|
||
| void ListenerFilterBufferImpl::onFileEvent(uint32_t events) { | ||
| ENVOY_LOG(trace, "onFileEvent: {}", events); | ||
|
|
||
| auto state = peekFromSocket(); | ||
| if (state == PeekState::Done) { | ||
| on_data_cb_(*this); | ||
| } else if (state == PeekState::Error) { | ||
| on_close_cb_(true); | ||
| } else if (state == PeekState::RemoteClose) { | ||
| on_close_cb_(false); | ||
| } | ||
| // Did nothing for `Api::IoError::IoErrorCode::Again` | ||
| } | ||
|
|
||
| } // namespace Network | ||
| } // namespace Envoy | ||
This file contains hidden or 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,72 @@ | ||
| #pragma once | ||
|
|
||
| #include <functional> | ||
| #include <memory> | ||
|
|
||
| #include "envoy/buffer/buffer.h" | ||
| #include "envoy/network/io_handle.h" | ||
| #include "envoy/network/listener_filter_buffer.h" | ||
|
|
||
| #include "source/common/buffer/buffer_impl.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Network { | ||
|
|
||
| class ListenerFilterBufferImpl; | ||
| using ListenerFilterBufferOnCloseCb = std::function<void(bool)>; | ||
| using ListenerFilterBufferOnDataCb = std::function<void(ListenerFilterBufferImpl&)>; | ||
|
|
||
| enum class PeekState { | ||
| // Peek data status successful. | ||
| Done, | ||
| // Need to try again. | ||
| Again, | ||
| // Error to peek data. | ||
| Error, | ||
| // Connection closed by remote. | ||
| RemoteClose, | ||
| }; | ||
|
|
||
| class ListenerFilterBufferImpl : public ListenerFilterBuffer, Logger::Loggable<Logger::Id::filter> { | ||
| public: | ||
| ListenerFilterBufferImpl(IoHandle& io_handle, Event::Dispatcher& dispatcher, | ||
soulxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ListenerFilterBufferOnCloseCb close_cb, | ||
| ListenerFilterBufferOnDataCb on_data_cb, uint64_t buffer_size); | ||
|
|
||
| // ListenerFilterBuffer | ||
soulxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const Buffer::ConstRawSlice rawSlice() const override; | ||
soulxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| bool drain(uint64_t length) override; | ||
|
|
||
| /** | ||
| * Trigger the data peek from the socket. | ||
| */ | ||
| PeekState peekFromSocket(); | ||
|
|
||
| void reset() { io_handle_.resetFileEvents(); } | ||
|
|
||
| void activateFileEvent(uint32_t events); | ||
| uint64_t capacity() const { return buffer_size_; } | ||
| void resetCapacity(uint64_t size); | ||
|
|
||
| private: | ||
| void onFileEvent(uint32_t events); | ||
|
|
||
| IoHandle& io_handle_; | ||
| Event::Dispatcher& dispatcher_; | ||
| ListenerFilterBufferOnCloseCb on_close_cb_; | ||
| ListenerFilterBufferOnDataCb on_data_cb_; | ||
|
|
||
| // The buffer for the data peeked from the socket. | ||
| std::unique_ptr<uint8_t[]> buffer_; | ||
| // The start of buffer. | ||
| uint8_t* base_; | ||
| // The size of buffer; | ||
| uint64_t buffer_size_; | ||
| // The size of valid data. | ||
| uint64_t data_size_{0}; | ||
soulxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| using ListenerFilterBufferImplPtr = std::unique_ptr<ListenerFilterBufferImpl>; | ||
|
|
||
| } // namespace Network | ||
| } // namespace Envoy | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.