You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2020/05/15 21:07:10 UTC

[trafficserver] branch master updated: clang-analyzer: code clone in get_proxy_protocol_addr (#6791)

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new bf097d4  clang-analyzer: code clone in get_proxy_protocol_addr (#6791)
bf097d4 is described below

commit bf097d4289a3eaa3759a58fb19e48381b89ce32f
Author: Leif Hedstrom <zw...@apache.org>
AuthorDate: Fri May 15 15:06:59 2020 -0600

    clang-analyzer: code clone in get_proxy_protocol_addr (#6791)
    
    * clang-analyzer: code clone in get_proxy_protocol_addr
    
    * Per Bryan's suggestion, make the method const
---
 iocore/net/I_NetVConnection.h |  2 +-
 iocore/net/P_NetVConnection.h | 20 +++++++-------------
 2 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/iocore/net/I_NetVConnection.h b/iocore/net/I_NetVConnection.h
index 1b35a1d..97df42c 100644
--- a/iocore/net/I_NetVConnection.h
+++ b/iocore/net/I_NetVConnection.h
@@ -843,7 +843,7 @@ public:
     return pp_info.proxy_protocol_version;
   }
 
-  sockaddr const *get_proxy_protocol_addr(const ProxyProtocolData);
+  sockaddr const *get_proxy_protocol_addr(const ProxyProtocolData) const;
 
   sockaddr const *
   get_proxy_protocol_src_addr()
diff --git a/iocore/net/P_NetVConnection.h b/iocore/net/P_NetVConnection.h
index 679cf0b..ff3c91a 100644
--- a/iocore/net/P_NetVConnection.h
+++ b/iocore/net/P_NetVConnection.h
@@ -87,20 +87,14 @@ NetVConnection::get_local_port()
 }
 
 inline sockaddr const *
-NetVConnection::get_proxy_protocol_addr(const ProxyProtocolData src_or_dst)
+NetVConnection::get_proxy_protocol_addr(const ProxyProtocolData src_or_dst) const
 {
-  if (src_or_dst == ProxyProtocolData::SRC) {
-    if ((pp_info.src_addr.isValid() && pp_info.src_addr.port() != 0) ||
-        (ats_is_ip4(&pp_info.src_addr) && INADDR_ANY != ats_ip4_addr_cast(&pp_info.src_addr)) // IPv4
-        || (ats_is_ip6(&pp_info.src_addr) && !IN6_IS_ADDR_UNSPECIFIED(&pp_info.src_addr.sin6.sin6_addr))) {
-      return &pp_info.src_addr.sa;
-    }
-  } else {
-    if ((pp_info.dst_addr.isValid() && pp_info.dst_addr.port() != 0) ||
-        (ats_is_ip4(&pp_info.dst_addr) && INADDR_ANY != ats_ip4_addr_cast(&pp_info.dst_addr)) // IPv4
-        || (ats_is_ip6(&pp_info.dst_addr) && !IN6_IS_ADDR_UNSPECIFIED(&pp_info.dst_addr.sin6.sin6_addr))) {
-      return &pp_info.dst_addr.sa;
-    }
+  const IpEndpoint &addr = (src_or_dst == ProxyProtocolData::SRC ? pp_info.src_addr : pp_info.dst_addr);
+
+  if ((addr.isValid() && addr.port() != 0) || (ats_is_ip4(&addr) && INADDR_ANY != ats_ip4_addr_cast(&addr)) // IPv4
+      || (ats_is_ip6(&addr) && !IN6_IS_ADDR_UNSPECIFIED(&addr.sin6.sin6_addr))) {
+    return &addr.sa;
   }
+
   return nullptr;
 }