trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zw...@apache.org
Subject [07/12] git commit: TS-2530 - Check for loopback interfaces to avoid false multi-cycle hop detection
Date Thu, 30 Jan 2014 23:31:20 GMT
TS-2530 - Check for loopback interfaces to avoid false multi-cycle hop detection


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/61dbe66e
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/61dbe66e
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/61dbe66e

Branch: refs/heads/5.0.x
Commit: 61dbe66ece9dff3ab98abfc3d2463ca65bd75d3e
Parents: eb450fa
Author: Alan M. Carroll <amc@network-geographics.com>
Authored: Wed Jan 29 10:10:17 2014 -0600
Committer: Alan M. Carroll <amc@network-geographics.com>
Committed: Wed Jan 29 10:10:17 2014 -0600

----------------------------------------------------------------------
 CHANGES                 |  2 ++
 iocore/utils/Machine.cc | 20 ++++++++++++++------
 2 files changed, 16 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/61dbe66e/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 7fddf93..a45040f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 4.2.0
 
+  *) [TS-2530] Check for loopback interfaces when computing the local address.
+
   *) [TS-2031] Prevent duplicate SSL SNI name registration.
    Author: Feifei Cai <ffcai@yahoo-inc.com>
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/61dbe66e/iocore/utils/Machine.cc
----------------------------------------------------------------------
diff --git a/iocore/utils/Machine.cc b/iocore/utils/Machine.cc
index fdc089c..756d3a3 100644
--- a/iocore/utils/Machine.cc
+++ b/iocore/utils/Machine.cc
@@ -25,8 +25,8 @@
 #include "I_Machine.h"
 
 #if HAVE_IFADDRS_H
-#include <ifaddrs.h>
-# endif
+#  include <ifaddrs.h>
+#endif
 
 // Singleton
 Machine* Machine::_instance = NULL;
@@ -83,7 +83,6 @@ Machine::Machine(char const* the_hostname, sockaddr const* addr)
         conf.ifc_len = sizeof(req);
         conf.ifc_req = req;
         status = ioctl(s, SIOCGIFCONF, &conf);
-        close(s);
       } else {
         status = -1;
       }
@@ -105,6 +104,7 @@ Machine::Machine(char const* the_hostname, sockaddr const* addr)
         GL  // Global.
       } spot_type = NA, ip4_type = NA, ip6_type = NA;
       sockaddr const* ifip;
+      unsigned int ifflags;
       for (
 #if HAVE_IFADDRS_H
         ifaddrs* spot = ifa_addrs ; spot ; spot = spot->ifa_next
@@ -114,17 +114,22 @@ Machine::Machine(char const* the_hostname, sockaddr const* addr)
       ) {
 #if HAVE_IFADDRS_H
         ifip = spot->ifa_addr;
+        ifflags = spot->ifa_flags;
 #else
         ifip = &spot->ifr_addr;
-#endif
 
+        // get the interface's flags
+        struct ifreq ifr;
+        ink_strlcpy(ifr.ifr_name, spot->ifr_name, IFNAMSIZ);
+        if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0)   ifflags = ifr.ifr_flags;
+        else ifflags = 0; // flags not available, default to just looking at IP
+#endif
         if (!ats_is_ip(ifip)) spot_type = NA;
-        else if (ats_is_ip_loopback(ifip)) spot_type = LO;
+        else if (ats_is_ip_loopback(ifip) || (IFF_LOOPBACK & ifflags)) spot_type = LO;
         else if (ats_is_ip_linklocal(ifip)) spot_type = LL;
         else if (ats_is_ip_private(ifip)) spot_type = PR;
         else if (ats_is_ip_multicast(ifip)) spot_type = MC;
         else spot_type = GL;
-
         if (spot_type == NA) continue; // Next!
 
         if (ats_is_ip4(ifip)) {
@@ -150,6 +155,9 @@ Machine::Machine(char const* the_hostname, sockaddr const* addr)
       else
         ats_ip_copy(&ip.sa, &ip6.sa);
     }
+#if ! HAVE_IFADDRS_H
+    close(s);
+#endif
   } else { // address provided.
     ats_ip_copy(&ip, addr);
     if (ats_is_ip4(addr)) ats_ip_copy(&ip4, addr);


Mime
View raw message