You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/11/24 17:45:24 UTC

[GitHub] [pulsar] codelipenghui opened a new pull request #8686: Support HAProxy proxy protocol for broker and proxy

codelipenghui opened a new pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686


   ### Motivation
   
   Currently, if enable the proxy in the pulsar cluster and client connect to the cluster through the proxy, when we get topic stats, the consumer address and producer address are not the real client address. This PR fix this problem by leverage HAProxy proxy protocol since this is a more general approach.  more details about the proxy protocol see 
   https://www.haproxy.com/blog/haproxy/proxy-protocol/
   https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/enable-proxy-protocol.html
   http://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
   
   ### Modifications
   
   Allow enable proxy protocol on proxy or broker.
   
   ### Verifying this change
   
   Tests added
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): (no)
     - The public API: (no)
     - The schema: (no)
     - The default values of configurations: (no)
     - The wire protocol: (no)
     - The rest endpoints: (no)
     - The admin cli options: (no)
     - Anything that affects deployment: (no)
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (yes)
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] codelipenghui commented on a change in pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on a change in pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#discussion_r530143288



##########
File path: conf/broker.conf
##########
@@ -55,6 +55,9 @@ advertisedAddress=
 # The Default value is absent, the broker uses the first listener as the internal listener.
 # internalListenerName=
 
+# Enable or disable the proxy protocol.
+proxyProtocolEnabled=false

Review comment:
       Ok, sounds good.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] codelipenghui commented on a change in pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on a change in pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#discussion_r530308859



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PulsarChannelInitializer.java
##########
@@ -118,6 +119,9 @@ protected void initChannel(SocketChannel ch) throws Exception {
             ch.pipeline().addLast("ByteBufPairEncoder", ByteBufPair.ENCODER);
         }
 
+        if (pulsar.getConfiguration().isHaProxyProtocolEnabled()) {
+            ch.pipeline().addLast(OptionalProxyProtocolDecoder.NAME, new OptionalProxyProtocolDecoder());

Review comment:
       This is a flag to control if users want to enable the haproxy protocol support. We must provide a way to disable this feature. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] diegosalvi commented on a change in pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
diegosalvi commented on a change in pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#discussion_r531150649



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PulsarChannelInitializer.java
##########
@@ -118,6 +119,9 @@ protected void initChannel(SocketChannel ch) throws Exception {
             ch.pipeline().addLast("ByteBufPairEncoder", ByteBufPair.ENCODER);
         }
 
+        if (pulsar.getConfiguration().isHaProxyProtocolEnabled()) {
+            ch.pipeline().addLast(OptionalProxyProtocolDecoder.NAME, new OptionalProxyProtocolDecoder());

Review comment:
       Sure! What I was saying is that there isn't a way to REQUIRE proxy header if pulsar.getConfiguration().isHaProxyProtocolEnabled(). Specs states that is MUST expect a proxy header, it isn't optional. There could be another option to handle optional/mandatory




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] sijie commented on pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
sijie commented on pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#issuecomment-735523563






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] eolivelli commented on pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
eolivelli commented on pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#issuecomment-733178783


   @diegosalvi you have recently implemented this feature on EmailSuccess, can you please take a look?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] sijie commented on a change in pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
sijie commented on a change in pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#discussion_r529775071



##########
File path: pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java
##########
@@ -169,6 +171,11 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
 
     @Override
     public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception {
+        System.out.println(haProxyMessage);

Review comment:
       remove this?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] diegosalvi commented on a change in pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
diegosalvi commented on a change in pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#discussion_r530195356



##########
File path: pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java
##########
@@ -143,10 +150,56 @@ protected void initChannel(SocketChannel ch) throws Exception {
                 inboundOutboundChannelMap.put(outboundChannel.id() , inboundChannel.id());
             }
 
-
+            if (config.isHaProxyProtocolEnabled()) {
+                if (proxyConnection.hasHAProxyMessage()) {
+                    outboundChannel.writeAndFlush(encodeProxyProtocolMessage(proxyConnection.getHAProxyMessage()));
+                } else {
+                    if (inboundChannel.remoteAddress() instanceof InetSocketAddress) {
+                        InetSocketAddress clientAddress = (InetSocketAddress) inboundChannel.remoteAddress();
+                        String sourceAddress = clientAddress.getAddress().getHostAddress();
+                        int sourcePort = clientAddress.getPort();
+                        if (outboundChannel.localAddress() instanceof InetSocketAddress) {
+                            InetSocketAddress proxyAddress = (InetSocketAddress) inboundChannel.remoteAddress();
+                            String destinationAddress = proxyAddress.getAddress().getHostAddress();
+                            int destinationPort = proxyAddress.getPort();
+                            HAProxyMessage msg = new HAProxyMessage(HAProxyProtocolVersion.V1, HAProxyCommand.PROXY,
+                                    HAProxyProxiedProtocol.TCP4, sourceAddress, destinationAddress, sourcePort, destinationPort);
+                            outboundChannel.writeAndFlush(encodeProxyProtocolMessage(msg));
+                            msg.release();
+                        }
+                    }
+                }
+            }
         });
     }
 
+    private ByteBuf encodeProxyProtocolMessage(HAProxyMessage msg) {
+        // Max length of v1 version proxy protocol message is 108
+        ByteBuf out = Unpooled.buffer(108);

Review comment:
       Actually maximum record size is 107 by spec:
     - worst case (optional fields set to 0xff) :```
   
         "PROXY UNKNOWN ffff:f...f:ffff ffff:f...f:ffff 65535 65535\r\n"
       => 5 + 1 + 7 + 1 + 39 + 1 + 39 + 1 + 5 + 1 + 5 + 2 = 107 chars
   
   [...]
   
   The receiver must wait for the CRLF sequence before starting to decode the
   addresses in order to ensure they are complete and properly parsed. If the CRLF
   sequence is not found in the first 107 characters, the receiver should declare
   the line invalid.
   ```

##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PulsarChannelInitializer.java
##########
@@ -118,6 +119,9 @@ protected void initChannel(SocketChannel ch) throws Exception {
             ch.pipeline().addLast("ByteBufPairEncoder", ByteBufPair.ENCODER);
         }
 
+        if (pulsar.getConfiguration().isHaProxyProtocolEnabled()) {
+            ch.pipeline().addLast(OptionalProxyProtocolDecoder.NAME, new OptionalProxyProtocolDecoder());

Review comment:
       I think we should have the possibilitiy to require proxy headers instead of handle them as _optional_.
   Specification itself states:
   ```
   The receiver MUST be configured to only receive the protocol described in this
   specification and MUST not try to guess whether the protocol header is present
   or not. This means that the protocol explicitly prevents port sharing between
   public and private access.
   ```

##########
File path: pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java
##########
@@ -143,10 +150,56 @@ protected void initChannel(SocketChannel ch) throws Exception {
                 inboundOutboundChannelMap.put(outboundChannel.id() , inboundChannel.id());
             }
 
-
+            if (config.isHaProxyProtocolEnabled()) {
+                if (proxyConnection.hasHAProxyMessage()) {
+                    outboundChannel.writeAndFlush(encodeProxyProtocolMessage(proxyConnection.getHAProxyMessage()));
+                } else {
+                    if (inboundChannel.remoteAddress() instanceof InetSocketAddress) {
+                        InetSocketAddress clientAddress = (InetSocketAddress) inboundChannel.remoteAddress();
+                        String sourceAddress = clientAddress.getAddress().getHostAddress();
+                        int sourcePort = clientAddress.getPort();
+                        if (outboundChannel.localAddress() instanceof InetSocketAddress) {
+                            InetSocketAddress proxyAddress = (InetSocketAddress) inboundChannel.remoteAddress();
+                            String destinationAddress = proxyAddress.getAddress().getHostAddress();
+                            int destinationPort = proxyAddress.getPort();
+                            HAProxyMessage msg = new HAProxyMessage(HAProxyProtocolVersion.V1, HAProxyCommand.PROXY,

Review comment:
       netty-haproxy can decode binary v2 version too (but doesn't implements encoding).
   We could add another encoding method for v2 protocol and let the configurer choose which use.
   
   For the encoding implementation I've done one for subethamail if you want take a peek. It has been done for testing purposes (so it permits some strange behaviour to check various edge cases and "wrong" headers and can surely be simplified): https://github.com/davidmoten/subethasmtp/blob/master/src/test/java/org/subethamail/smtp/internal/proxy/ProxyProtocolV2HandlerTest.java




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] codelipenghui commented on a change in pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on a change in pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#discussion_r530310262



##########
File path: pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java
##########
@@ -143,10 +150,56 @@ protected void initChannel(SocketChannel ch) throws Exception {
                 inboundOutboundChannelMap.put(outboundChannel.id() , inboundChannel.id());
             }
 
-
+            if (config.isHaProxyProtocolEnabled()) {
+                if (proxyConnection.hasHAProxyMessage()) {
+                    outboundChannel.writeAndFlush(encodeProxyProtocolMessage(proxyConnection.getHAProxyMessage()));
+                } else {
+                    if (inboundChannel.remoteAddress() instanceof InetSocketAddress) {
+                        InetSocketAddress clientAddress = (InetSocketAddress) inboundChannel.remoteAddress();
+                        String sourceAddress = clientAddress.getAddress().getHostAddress();
+                        int sourcePort = clientAddress.getPort();
+                        if (outboundChannel.localAddress() instanceof InetSocketAddress) {
+                            InetSocketAddress proxyAddress = (InetSocketAddress) inboundChannel.remoteAddress();
+                            String destinationAddress = proxyAddress.getAddress().getHostAddress();
+                            int destinationPort = proxyAddress.getPort();
+                            HAProxyMessage msg = new HAProxyMessage(HAProxyProtocolVersion.V1, HAProxyCommand.PROXY,

Review comment:
       It's not a required for this PR, we can support the proxy set the different protocol version in the following PRs.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] diegosalvi commented on a change in pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
diegosalvi commented on a change in pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#discussion_r531149684



##########
File path: pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java
##########
@@ -143,10 +150,56 @@ protected void initChannel(SocketChannel ch) throws Exception {
                 inboundOutboundChannelMap.put(outboundChannel.id() , inboundChannel.id());
             }
 
-
+            if (config.isHaProxyProtocolEnabled()) {
+                if (proxyConnection.hasHAProxyMessage()) {
+                    outboundChannel.writeAndFlush(encodeProxyProtocolMessage(proxyConnection.getHAProxyMessage()));
+                } else {
+                    if (inboundChannel.remoteAddress() instanceof InetSocketAddress) {
+                        InetSocketAddress clientAddress = (InetSocketAddress) inboundChannel.remoteAddress();
+                        String sourceAddress = clientAddress.getAddress().getHostAddress();
+                        int sourcePort = clientAddress.getPort();
+                        if (outboundChannel.localAddress() instanceof InetSocketAddress) {
+                            InetSocketAddress proxyAddress = (InetSocketAddress) inboundChannel.remoteAddress();
+                            String destinationAddress = proxyAddress.getAddress().getHostAddress();
+                            int destinationPort = proxyAddress.getPort();
+                            HAProxyMessage msg = new HAProxyMessage(HAProxyProtocolVersion.V1, HAProxyCommand.PROXY,

Review comment:
       Sounds good




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] codelipenghui commented on a change in pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on a change in pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#discussion_r530061518



##########
File path: conf/broker.conf
##########
@@ -55,6 +55,9 @@ advertisedAddress=
 # The Default value is absent, the broker uses the first listener as the internal listener.
 # internalListenerName=
 
+# Enable or disable the proxy protocol.
+proxyProtocolEnabled=false

Review comment:
       How about change to `haProxyProtocolEnabled`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] codelipenghui commented on a change in pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on a change in pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#discussion_r530307013



##########
File path: pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java
##########
@@ -143,10 +150,56 @@ protected void initChannel(SocketChannel ch) throws Exception {
                 inboundOutboundChannelMap.put(outboundChannel.id() , inboundChannel.id());
             }
 
-
+            if (config.isHaProxyProtocolEnabled()) {
+                if (proxyConnection.hasHAProxyMessage()) {
+                    outboundChannel.writeAndFlush(encodeProxyProtocolMessage(proxyConnection.getHAProxyMessage()));
+                } else {
+                    if (inboundChannel.remoteAddress() instanceof InetSocketAddress) {
+                        InetSocketAddress clientAddress = (InetSocketAddress) inboundChannel.remoteAddress();
+                        String sourceAddress = clientAddress.getAddress().getHostAddress();
+                        int sourcePort = clientAddress.getPort();
+                        if (outboundChannel.localAddress() instanceof InetSocketAddress) {
+                            InetSocketAddress proxyAddress = (InetSocketAddress) inboundChannel.remoteAddress();
+                            String destinationAddress = proxyAddress.getAddress().getHostAddress();
+                            int destinationPort = proxyAddress.getPort();
+                            HAProxyMessage msg = new HAProxyMessage(HAProxyProtocolVersion.V1, HAProxyCommand.PROXY,
+                                    HAProxyProxiedProtocol.TCP4, sourceAddress, destinationAddress, sourcePort, destinationPort);
+                            outboundChannel.writeAndFlush(encodeProxyProtocolMessage(msg));
+                            msg.release();
+                        }
+                    }
+                }
+            }
         });
     }
 
+    private ByteBuf encodeProxyProtocolMessage(HAProxyMessage msg) {
+        // Max length of v1 version proxy protocol message is 108
+        ByteBuf out = Unpooled.buffer(108);

Review comment:
       I'm using the netty-haproxy-codec directly. I think netty codec already handled this?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] sijie commented on a change in pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
sijie commented on a change in pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#discussion_r530118380



##########
File path: conf/broker.conf
##########
@@ -55,6 +55,9 @@ advertisedAddress=
 # The Default value is absent, the broker uses the first listener as the internal listener.
 # internalListenerName=
 
+# Enable or disable the proxy protocol.
+proxyProtocolEnabled=false

Review comment:
       `haProxyProtocol` looks much better than `proxyProtocol`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] codelipenghui commented on pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#issuecomment-733545416


   /pulsarbot run-failure-checks


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] sijie merged pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
sijie merged pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] merlimat commented on a change in pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#discussion_r530056369



##########
File path: conf/broker.conf
##########
@@ -55,6 +55,9 @@ advertisedAddress=
 # The Default value is absent, the broker uses the first listener as the internal listener.
 # internalListenerName=
 
+# Enable or disable the proxy protocol.
+proxyProtocolEnabled=false

Review comment:
       This naming can be confusing since we already have a "proxy" for Pulsar protocol




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] codelipenghui commented on pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#issuecomment-737582726


   /pulsarbot cherry-pick to branch-2.6


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] codelipenghui commented on a change in pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on a change in pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#discussion_r530061518



##########
File path: conf/broker.conf
##########
@@ -55,6 +55,9 @@ advertisedAddress=
 # The Default value is absent, the broker uses the first listener as the internal listener.
 # internalListenerName=
 
+# Enable or disable the proxy protocol.
+proxyProtocolEnabled=false

Review comment:
       How about changing it to `haProxyProtocolEnabled`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] codelipenghui commented on a change in pull request #8686: Support HAProxy proxy protocol for broker and proxy

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on a change in pull request #8686:
URL: https://github.com/apache/pulsar/pull/8686#discussion_r530311953



##########
File path: pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java
##########
@@ -143,10 +150,56 @@ protected void initChannel(SocketChannel ch) throws Exception {
                 inboundOutboundChannelMap.put(outboundChannel.id() , inboundChannel.id());
             }
 
-
+            if (config.isHaProxyProtocolEnabled()) {
+                if (proxyConnection.hasHAProxyMessage()) {
+                    outboundChannel.writeAndFlush(encodeProxyProtocolMessage(proxyConnection.getHAProxyMessage()));
+                } else {
+                    if (inboundChannel.remoteAddress() instanceof InetSocketAddress) {
+                        InetSocketAddress clientAddress = (InetSocketAddress) inboundChannel.remoteAddress();
+                        String sourceAddress = clientAddress.getAddress().getHostAddress();
+                        int sourcePort = clientAddress.getPort();
+                        if (outboundChannel.localAddress() instanceof InetSocketAddress) {
+                            InetSocketAddress proxyAddress = (InetSocketAddress) inboundChannel.remoteAddress();
+                            String destinationAddress = proxyAddress.getAddress().getHostAddress();
+                            int destinationPort = proxyAddress.getPort();
+                            HAProxyMessage msg = new HAProxyMessage(HAProxyProtocolVersion.V1, HAProxyCommand.PROXY,
+                                    HAProxyProxiedProtocol.TCP4, sourceAddress, destinationAddress, sourcePort, destinationPort);
+                            outboundChannel.writeAndFlush(encodeProxyProtocolMessage(msg));
+                            msg.release();
+                        }
+                    }
+                }
+            }
         });
     }
 
+    private ByteBuf encodeProxyProtocolMessage(HAProxyMessage msg) {
+        // Max length of v1 version proxy protocol message is 108
+        ByteBuf out = Unpooled.buffer(108);

Review comment:
       I just noticed the max length for v1 is 108 https://github.com/netty/netty/blob/4.1/codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessageDecoder.java#L37




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org