forked from squid-cache/squid
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Basic PROXY protocol support for Squid-to-peer connections #281
Open
eduard-bagdasaryan
wants to merge
44
commits into
master
Choose a base branch
from
SQUID-1042-basic-proxy-protocol-support-for-squid-to-peer-connections
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
e2130d1
Initial implementation
eduard-bagdasaryan 41a71bb
Revert tunnel.cc changes until FwdState changes become more stable
rousskov 8c367fb
Re-implement ad-hoc ProxyProtocol::Header packing using new BinaryPacker
rousskov 464bbc5
fixup: Removed failed attempt at (hopefully premature) optimization
rousskov 0392fde
fixup: Report packing state _before_ assertions
rousskov bf3f105
Generate a PROXY protocol header before opening a connection
eduard-bagdasaryan e3c4dab
Moved Magic() functions to Elements.cc
eduard-bagdasaryan 267ba2a
Made FwdState::proxyProtocolHeader optional<>
eduard-bagdasaryan 9fb2bb5
Added missing headers
eduard-bagdasaryan 42c5ef5
Detailed decision making time in directive docs
rousskov fb8efa2
Added pseudo header and TLV configuration documentation
rousskov f0ceb1f
Fixed the condition passed to cs->allowPersistent()
eduard-bagdasaryan 8434e72
Autoformatted
eduard-bagdasaryan 9ac8bfc
Basic options support for http_outgoing_proxy_protocol
eduard-bagdasaryan 5aa51b3
Refactored with AddrOption, PortOption and TlvOption classes
eduard-bagdasaryan dfe7934
Refactored, added some descriptions and performed some tests
eduard-bagdasaryan 3d6262f
Added RefCount for Options
eduard-bagdasaryan 1a90e3b
Autoformatted
eduard-bagdasaryan 49e50c0
Do not dereference a nil valueFormat
eduard-bagdasaryan b848cb7
Simplified and reduced duplication
eduard-bagdasaryan 0a1cf1f
Minor polishing
eduard-bagdasaryan 32742cb
Implemented OutgoingHttpConfig::dump()
eduard-bagdasaryan 58963f2
Added a missing header
eduard-bagdasaryan 0f209f3
Added a negative configuration test
eduard-bagdasaryan c856b67
Improved with format/forward.h
eduard-bagdasaryan b460c57
Addressing code review comments
eduard-bagdasaryan fa64314
Simplified by moving the parsing into the Option constructor
eduard-bagdasaryan 50096e6
Covered other exception paths in OutgoingHttpConfig::adjustAddresses()
eduard-bagdasaryan 2968fcd
Introduced special handling for "-" header fields
rousskov d3835c6
Introduced Token::print(ostream)
eduard-bagdasaryan 0f26c31
Remove Option::theValue
eduard-bagdasaryan 46f04ea
OutgoingHttpConfig::adjustAddresses()
eduard-bagdasaryan 97c059f
Merged from head
eduard-bagdasaryan 208b71b
Removed and unused method
eduard-bagdasaryan 72303fb
Format::needsAle() should cover all codes that does not need ALE
eduard-bagdasaryan 3717a74
Configure an unspecified port/address as a single dash
eduard-bagdasaryan b1aebf3
Let the adjustAddresses() decide whether the problem is fatal
eduard-bagdasaryan 04142e8
Added a couple of tlvs to the negative configuration test
eduard-bagdasaryan 9d069ee
Reject tlvs with a length greater than 65535
eduard-bagdasaryan ed07241
Code cleanup
eduard-bagdasaryan 2b537ce
Autoformatted
eduard-bagdasaryan e045f61
Renamed to Format::isConstant(), addressing a request
eduard-bagdasaryan 93cb024
Reject port options with leftovers
eduard-bagdasaryan c2338c5
Avoid duplicate tlvs
eduard-bagdasaryan 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 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,91 @@ | ||
/* | ||
* Copyright (C) 1996-2025 The Squid Software Foundation and contributors | ||
* | ||
* Squid software is distributed under GPLv2+ license and includes | ||
* contributions from numerous individuals and organizations. | ||
* Please see the COPYING and CONTRIBUTORS files for details. | ||
*/ | ||
|
||
#include "squid.h" | ||
#include "ip/Address.h" | ||
#include "parser/BinaryPacker.h" | ||
|
||
#include <limits> | ||
|
||
/// helper for methods that need to store a single byte | ||
void | ||
BinaryPacker::packOctet_(const uint8_t value) | ||
{ | ||
output_.append(static_cast<char>(value)); | ||
} | ||
|
||
/// helper for methods that need to store a variable number of bytes | ||
void | ||
BinaryPacker::packOctets_(const void *value, const size_t size) | ||
{ | ||
output_.append(static_cast<const char*>(value), size); | ||
} | ||
|
||
/// helper for reporting to-be-serialized field | ||
template <typename Value> | ||
void | ||
BinaryPacker::packing_(const char * const description, const Value &value, const size_t size) const | ||
{ | ||
debugs(24, 7, description << "[" << size << " bytes]: " << value); | ||
} | ||
|
||
void | ||
BinaryPacker::uint8(const char * const description, const uint8_t value) | ||
{ | ||
packing_(description, value, 1); | ||
packOctet_(value); | ||
} | ||
|
||
void | ||
BinaryPacker::uint16(const char * const description, const uint16_t value) | ||
{ | ||
packing_(description, value, 2); | ||
packOctet_(value >> 8); | ||
packOctet_(value); | ||
} | ||
|
||
void | ||
BinaryPacker::area(const char * const description, const SBuf &blob) | ||
{ | ||
packing_(description, __FUNCTION__, blob.length()); | ||
packOctets_(blob.rawContent(), blob.length()); | ||
} | ||
|
||
void | ||
BinaryPacker::inet(const char * const description, const Ip::Address &ip) | ||
{ | ||
if (ip.isIPv4()) { | ||
in_addr ip4; | ||
packing_(description, ip, sizeof(ip4)); | ||
ip.getInAddr(ip4); | ||
packOctets_(&ip4, sizeof(ip4)); | ||
} else { | ||
in6_addr ip6; | ||
packing_(description, ip, sizeof(ip6)); | ||
ip.getInAddr(ip6); | ||
packOctets_(&ip6, sizeof(ip6)); | ||
} | ||
} | ||
|
||
void | ||
BinaryPacker::pstring8(const char * const description, const SBuf &area) | ||
{ | ||
packing_(description, __FUNCTION__, area.length()); | ||
Assure(area.length() <= std::numeric_limits<uint8_t>::max()); | ||
uint8("pstring8() length", area.length()); | ||
packOctets_(area.rawContent(), area.length()); | ||
} | ||
|
||
void | ||
BinaryPacker::pstring16(const char * const description, const SBuf &area) | ||
{ | ||
packing_(description, __FUNCTION__, area.length()); | ||
Assure(area.length() <= std::numeric_limits<uint16_t>::max()); | ||
uint16("pstring16() length", area.length()); | ||
packOctets_(area.rawContent(), area.length()); | ||
} |
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,53 @@ | ||
/* | ||
* Copyright (C) 1996-2025 The Squid Software Foundation and contributors | ||
* | ||
* Squid software is distributed under GPLv2+ license and includes | ||
* contributions from numerous individuals and organizations. | ||
* Please see the COPYING and CONTRIBUTORS files for details. | ||
*/ | ||
|
||
#ifndef SQUID_SRC_PARSER_BINARYPACKER_H | ||
#define SQUID_SRC_PARSER_BINARYPACKER_H | ||
|
||
#include "ip/forward.h" | ||
#include "parser/forward.h" | ||
#include "sbuf/SBuf.h" | ||
|
||
/// Serializes various common types using network byte order (where applicable). | ||
/// \sa Parser::BinaryTokenizer that parses serialized fields. | ||
class BinaryPacker | ||
{ | ||
public: | ||
/// packs a single-byte unsigned integer | ||
void uint8(const char *description, uint8_t); | ||
|
||
/// packs a two-byte unsigned integer | ||
void uint16(const char *description, uint16_t); | ||
|
||
/// packs all given bytes as an opaque blob | ||
void area(const char *description, const SBuf &); | ||
|
||
/// packs in_addr or in6_addr structure; port information is not stored | ||
void inet(const char *description, const Ip::Address &); | ||
|
||
/* | ||
* Variable-length arrays (a.k.a. Pascal or prefix strings). | ||
* pstringN() packs an N-bit length field followed by length bytes | ||
*/ | ||
void pstring8(const char *description, const SBuf &); ///< up to 255 byte-long p-string | ||
void pstring16(const char *description, const SBuf &); ///< up to 64 KiB-long p-string | ||
|
||
const SBuf &packed() const { return output_; } | ||
|
||
private: | ||
void packOctet_(uint8_t); | ||
void packOctets_(const void *, size_t); | ||
template <typename Value> void packing_(const char *description, const Value &, size_t size) const; | ||
|
||
private: | ||
/// serialized bytes accumulated so far | ||
SBuf output_; | ||
}; | ||
|
||
#endif /* SQUID_SRC_PARSER_BINARYPACKER_H */ | ||
|
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
Oops, something went wrong.
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.
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.
When you update this code to generate the PROXY protocol header before opening a connection, please store it as SBuf. Convert to MemBuf only when it is time to write it (using the freshly opened connection).
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.
Done.