You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2011/10/11 03:03:16 UTC

svn commit: r1181325 - in /trafficserver/traffic/trunk: CHANGES configure.ac iocore/utils/Machine.cc lib/ts/ink_config.h.in proxy/http/HttpTransactHeaders.cc

Author: amc
Date: Tue Oct 11 01:03:16 2011
New Revision: 1181325

URL: http://svn.apache.org/viewvc?rev=1181325&view=rev
Log:
TS-938 Update - fix for not having getifaddr()

Modified:
    trafficserver/traffic/trunk/CHANGES
    trafficserver/traffic/trunk/configure.ac
    trafficserver/traffic/trunk/iocore/utils/Machine.cc
    trafficserver/traffic/trunk/lib/ts/ink_config.h.in
    trafficserver/traffic/trunk/proxy/http/HttpTransactHeaders.cc

Modified: trafficserver/traffic/trunk/CHANGES
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/CHANGES?rev=1181325&r1=1181324&r2=1181325&view=diff
==============================================================================
--- trafficserver/traffic/trunk/CHANGES (original)
+++ trafficserver/traffic/trunk/CHANGES Tue Oct 11 01:03:16 2011
@@ -14,7 +14,8 @@ Changes with Apache Traffic Server 3.1.1
 
   *) [TS-979] Found a few places where we can segfault with strlcpy.
 
-  *) [TS-938] Fix VIA to avoid loopback address.
+  *) [TS-938] Fix VIA to avoid loopback address. For Solaris only IPv4
+   is supported.
 
   *) [TS-945] Convert transparent forward requests to server style when
      forwarding to a parent proxy. Contributed by Yossi Gottlieb.

Modified: trafficserver/traffic/trunk/configure.ac
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/configure.ac?rev=1181325&r1=1181324&r2=1181325&view=diff
==============================================================================
--- trafficserver/traffic/trunk/configure.ac (original)
+++ trafficserver/traffic/trunk/configure.ac Tue Oct 11 01:03:16 2011
@@ -1031,7 +1031,8 @@ TS_FLAG_HEADERS([sys/epoll.h \
                   sys/sysmacros.h \
                   math.h \
                   stdint.h \
-                  net/ppp_defs.h])
+                  net/ppp_defs.h \
+                  ifaddrs.h])
 
 AC_SUBST(sys_epollh)
 AC_SUBST(sys_eventh)
@@ -1067,6 +1068,7 @@ AC_SUBST(sys_paramh)
 AC_SUBST(sys_sysmacrosh)
 AC_SUBST(mathh)
 AC_SUBST(net_ppp_defsh)
+AC_SUBST(ifaddrsh)
 
 TS_FLAG_HEADERS([netinet/ip.h], [], [],
                  [[#ifdef HAVE_SYS_TYPES_H

Modified: trafficserver/traffic/trunk/iocore/utils/Machine.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/utils/Machine.cc?rev=1181325&r1=1181324&r2=1181325&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/utils/Machine.cc (original)
+++ trafficserver/traffic/trunk/iocore/utils/Machine.cc Tue Oct 11 01:03:16 2011
@@ -23,7 +23,11 @@
 
 #include "libts.h"
 #include "I_Machine.h"
+
+# if TS_HAVE_IFADDRS_H
 #include <ifaddrs.h>
+# else
+# endif
 
 // Singleton
 Machine* Machine::_instance = NULL;
@@ -64,42 +68,80 @@ Machine::Machine(char const* the_hostnam
     }
     hostname = ats_strdup(the_hostname);
 
-    ifaddrs* ifa_addrs = 0;
-    status = getifaddrs(&ifa_addrs);
+#   if TS_HAVE_IFADDRS_H
+      ifaddrs* ifa_addrs = 0;
+      status = getifaddrs(&ifa_addrs);
+#   else
+      int s = socket(AF_INET, SOCK_DGRAM, 0);
+      // This number is hard to determine, but needs to be much larger than
+      // you would expect. On a normal system with just two interfaces and
+      // one address / interface the return count is 120. Stack space is
+      // cheap so it's best to go big.
+      static const int N_REQ = 1024;
+      ifconf conf;
+      ifreq req[N_REQ];
+      if (0 <= s) {
+        conf.ifc_len = sizeof(req);
+        conf.ifc_req = req;
+        status = ioctl(s, SIOCGIFCONF, &conf);
+        close(s);
+      } else {
+        status = -1;
+      }
+#   endif
+
     if (0 != status) {
       Warning("Unable to determine local host '%s' address information - %s"
         , hostname
         , strerror(errno)
       );
     } else {
-      /* Loop through the interface addresses. We have to prioritize
-         the values a little bit. The worst is the loopback address,
-         we accept that only if we can't find anything else. Next best
-         are non-routables and the best are "global" addresses.
-      */
-      enum { NA, LO, NR, MC, GA } spot_type = NA, ip4_type = NA, ip6_type = NA;
-      for (ifaddrs* spot = ifa_addrs ; spot ; spot = spot->ifa_next ) {
-        
-        if (!ink_inet_is_ip(spot->ifa_addr)) spot_type = NA;
-        else if (ink_inet_is_loopback(spot->ifa_addr)) spot_type = LO;
-        else if (ink_inet_is_nonroutable(spot->ifa_addr)) spot_type = NR;
-        else if (ink_inet_is_multicast(spot->ifa_addr)) spot_type = MC;
+      // Loop through the interface addresses and prefer by type.
+      enum {
+        NA, // Not an (IP) Address.
+        LO, // Loopback.
+        NR, // Non-Routable.
+        MC, // Multicast.
+        GA  // Globally unique Address.
+      } spot_type = NA, ip4_type = NA, ip6_type = NA;
+      sockaddr const* ifip;
+      for (
+#     if TS_HAVE_IFADDRS_H
+        ifaddrs* spot = ifa_addrs ; spot ; spot = spot->ifa_next
+#     else
+          ifreq* spot = req, *req_limit = req + (conf.ifc_len/sizeof(*req)) ; spot < req_limit ; ++spot
+#     endif
+      ) {
+#     if TS_HAVE_IFADDRS_H
+        ifip = spot->ifa_addr;
+#     else
+        ifip = &spot->ifr_addr;
+#     endif
+
+        if (!ink_inet_is_ip(ifip)) spot_type = NA;
+        else if (ink_inet_is_loopback(ifip)) spot_type = LO;
+        else if (ink_inet_is_nonroutable(ifip)) spot_type = NR;
+        else if (ink_inet_is_multicast(ifip)) spot_type = MC;
 
         if (spot_type == NA) continue; // Next!
 
-        if (ink_inet_is_ip4(spot->ifa_addr)) {
+        if (ink_inet_is_ip4(ifip)) {
           if (spot_type > ip4_type) {
-            ink_inet_copy(&ip4, spot->ifa_addr);
+            ink_inet_copy(&ip4, ifip);
             ip4_type = spot_type;
           }
-        } else if (ink_inet_is_ip6(spot->ifa_addr)) {
+        } else if (ink_inet_is_ip6(ifip)) {
           if (spot_type > ip6_type) {
-            ink_inet_copy(&ip6, spot->ifa_addr);
+            ink_inet_copy(&ip6, ifip);
             ip6_type = spot_type;
           }
         }
       }
+
+#     if TS_HAVE_IFADDRS_H
       freeifaddrs(ifa_addrs);
+#     endif
+
       // What about the general address? Prefer IPv4?
       if (ip4_type >= ip6_type)
         ink_inet_copy(&ip.sa, &ip4.sa);

Modified: trafficserver/traffic/trunk/lib/ts/ink_config.h.in
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_config.h.in?rev=1181325&r1=1181324&r2=1181325&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_config.h.in (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_config.h.in Tue Oct 11 01:03:16 2011
@@ -79,6 +79,7 @@
 #define TS_HAVE_NETINET_IP_H           @netinet_iph@
 #define TS_HAVE_NETINET_IP_ICMP_H      @netinet_ip_icmph@
 #define TS_HAVE_EXECINFO_H             @execinfoh@
+#define TS_HAVE_IFADDRS_H               @ifaddrsh@
 
 /* Libraries */
 #define TS_HAS_LIBZ                    @zlibh@

Modified: trafficserver/traffic/trunk/proxy/http/HttpTransactHeaders.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/HttpTransactHeaders.cc?rev=1181325&r1=1181324&r2=1181325&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/HttpTransactHeaders.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/HttpTransactHeaders.cc Tue Oct 11 01:03:16 2011
@@ -1067,22 +1067,13 @@ HttpTransactHeaders::insert_via_header_i
   }
   via_string += nstrcpy(via_string, http_config_param->proxy_hostname);
 
-  /* If we have an outbound IP address, use that. Otherwise use the
-     global value in @c Machine.
-  */
   *via_string++ = '[';
-  sockaddr const* outbound_ip = &http_config_param->oride.outgoing_ip_to_bind_saddr.sa;
-  if (ink_inet_is_ip(outbound_ip)) {
-    int l = ink_inet_to_hex(
-      outbound_ip,
-      via_string,
-      sizeof(new_via_string) - (via_string - new_via_string)
-    );
-    via_string += l;
-  } else {
-    memcpy(via_string, Machine::instance()->ip_hex_string, Machine::instance()->ip_hex_string_len);
-    via_string += Machine::instance()->ip_hex_string_len;
-  }
+  /* I thought we should use the transaction local outgoing IP address but
+     that makes cycle detection (which is the point) unrealiable. We must
+     use the same value every time to be sure.
+  */
+  memcpy(via_string, Machine::instance()->ip_hex_string, Machine::instance()->ip_hex_string_len);
+  via_string += Machine::instance()->ip_hex_string_len;
   *via_string++ = ']';
   *via_string++ = ' ';
   *via_string++ = '(';