Skip to content

Conversation

@ivpr
Copy link
Contributor

@ivpr ivpr commented Jan 2, 2026

Currently proxy_protocol_tlvs field in tcp_proxy ignores the TLVs specified when downstream has proxy protocol data. This changes adds support to merge the TLVs through an explicit field merge_proxy_protocol_tlvs. When enabled

  • TLVs specified in proxy_protocol_tlvs take precedence over downstream TLVs with the same type.
  • This allows adding new TLV values or overriding specific downstream TLV values while preserving
    other downstream TLVs.
  • The source and destination addresses from the downstream PROXY protocol state are preserved.

Commit Message: tcp_proxy: added changes to support ppv2 tlvs to be merged when downstream proxy protocol values are present
Additional Description: Currently proxy_protocol_tlvs field in tcp_proxy ignores the TLVs specified when downstream has proxy protocol data. This changes adds support to merge the TLVs through an explicit field merge_proxy_protocol_tlvs.
Risk Level: Low
Testing: Unit tests
Docs Changes: Added
Release Notes: Added
Platform Specific Features: N/A
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

@repokitteh-read-only
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @markdroth
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #42824 was opened by ivpr.

see: more, trace.

Prasad I V added 3 commits January 5, 2026 08:51
Comment on lines 340 to 355
// When set to true and the connection already contains ``PROXY`` protocol state
// (including TLVs) from a downstream proxy protocol listener filter, the TLVs
// specified in ``proxy_protocol_tlvs`` are merged with the downstream TLVs.
//
// **Precedence behavior**:
//
// - TLVs specified in ``proxy_protocol_tlvs`` take precedence over downstream TLVs
// with the same type.
// - This allows adding or overriding specific TLV values while preserving
// other downstream TLVs.
// - The source/destination addresses from the downstream ``PROXY`` protocol state
// are preserved (not modified).
//
// When set to false (default), the ``proxy_protocol_tlvs`` are ignored if
// downstream ``PROXY`` protocol state already exists.
bool merge_proxy_protocol_tlvs = 23;
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest calling it merge_with_downstream_tlvs to be more clear and also add more info to the docs.

Suggested change
// When set to true and the connection already contains ``PROXY`` protocol state
// (including TLVs) from a downstream proxy protocol listener filter, the TLVs
// specified in ``proxy_protocol_tlvs`` are merged with the downstream TLVs.
//
// **Precedence behavior**:
//
// - TLVs specified in ``proxy_protocol_tlvs`` take precedence over downstream TLVs
// with the same type.
// - This allows adding or overriding specific TLV values while preserving
// other downstream TLVs.
// - The source/destination addresses from the downstream ``PROXY`` protocol state
// are preserved (not modified).
//
// When set to false (default), the ``proxy_protocol_tlvs`` are ignored if
// downstream ``PROXY`` protocol state already exists.
bool merge_proxy_protocol_tlvs = 23;
// Controls whether TLVs specified in ``proxy_protocol_tlvs`` are merged with downstream
// ``PROXY`` protocol TLVs when downstream ``PROXY`` protocol state already exists.
//
// When set to ``true`` and the connection already contains ``PROXY`` protocol state
// (including TLVs) from a downstream proxy protocol listener filter, the TLVs
// specified in ``proxy_protocol_tlvs`` are merged with the downstream TLVs.
//
// When set to ``false`` (default), the TLVs specified in ``proxy_protocol_tlvs`` are
// ignored if downstream ``PROXY`` protocol state already exists. In this case, only
// the downstream TLVs are forwarded to the upstream.
//
// **Precedence behavior**:
//
// - TLVs specified in ``proxy_protocol_tlvs`` take precedence over downstream TLVs
// with the same type. This allows adding or overriding specific TLV values while
// preserving other downstream TLVs.
// - The source/destination addresses from the downstream ``PROXY`` protocol state
// are preserved (not modified).
// - TLVs with types that do not conflict are combined, resulting in a merged set
// of TLVs from both sources.
//
// .. note::
// This field only takes effect when downstream ``PROXY`` protocol state exists.
// If the TCP proxy filter is creating new ``PROXY`` protocol state, this field
// has no effect and the TLVs specified in ``proxy_protocol_tlvs`` are always
// included.
//
// .. note::
// To ensure the merged TLVs are allowed in the upstream ``PROXY`` protocol header,
// you must also configure passthrough TLVs on the upstream proxy protocol transport.
// See :ref:`core.v3.ProxyProtocolConfig.pass_through_tlvs <envoy_v3_api_field_config.core.v3.ProxyProtocolConfig.pass_through_tlvs>`
// for details.
bool merge_with_downstream_tlvs = 23;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I've made the changes to rename the field along with the doc suggestions

@agrawroh
Copy link
Member

agrawroh commented Jan 6, 2026

/assign @ggreenway

Copy link
Member

@ggreenway ggreenway left a comment

Choose a reason for hiding this comment

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

/wait

// you must also configure passthrough TLVs on the upstream proxy protocol transport.
// See :ref:`core.v3.ProxyProtocolConfig.pass_through_tlvs <envoy_v3_api_field_config.core.v3.ProxyProtocolConfig.pass_through_tlvs>`
// for details.
bool merge_with_downstream_tlvs = 23;
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to be careful with how we handle merge vs override, when considering #42075. Would it ever make sense to add an additional TLV of the same key? Maybe we should use an enum instead of a bool here so that if different behaviors are needed in the future we can easily add it to the API.


// Add downstream TLVs that don't conflict with tcp_proxy TLVs.
for (const auto& tlv : existing_data.tlv_vector_) {
if (!seen_types.contains(tlv.type)) {
Copy link
Member

Choose a reason for hiding this comment

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

This will introduce the bug reported in #42075 to tcp_proxy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants