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 2011/07/13 22:23:24 UTC

svn commit: r1146382 - in /trafficserver/traffic/trunk: CHANGES example/protocol/TxnSM.c example/protocol/TxnSM.h example/redirect-1/redirect-1.c example/server-transform/server-transform.c

Author: zwoop
Date: Wed Jul 13 20:23:23 2011
New Revision: 1146382

URL: http://svn.apache.org/viewvc?rev=1146382&view=rev
Log:
TS-853 Plugin examples should be updated to use the sockaddr API instead of the deprecated int style API.

This doesn't address IPv6 compatibility in every place, rewrites
of these example plugins would be necessary for that. But at least
we use the appropriate APIs now.

Modified:
    trafficserver/traffic/trunk/CHANGES
    trafficserver/traffic/trunk/example/protocol/TxnSM.c
    trafficserver/traffic/trunk/example/protocol/TxnSM.h
    trafficserver/traffic/trunk/example/redirect-1/redirect-1.c
    trafficserver/traffic/trunk/example/server-transform/server-transform.c

Modified: trafficserver/traffic/trunk/CHANGES
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/CHANGES?rev=1146382&r1=1146381&r2=1146382&view=diff
==============================================================================
--- trafficserver/traffic/trunk/CHANGES (original)
+++ trafficserver/traffic/trunk/CHANGES Wed Jul 13 20:23:23 2011
@@ -1,16 +1,19 @@
                                                          -*- coding: utf-8 -*-
 
 Changes with Apache Traffic Server 3.1.0
-  *) [TS-870]: Fix evacuate relevant codes in cache to work, Author: mohan_zl
+  *) [TS-853] Fix a few example plugins to use the new (appropriate) sockaddr
+   based APIs (and not the deprecated APIs).
 
-  *) [TS-869]: The stat code for ram_cache miss is lost, Author: mohan_zl
+  *) [TS-870] Fix evacuate relevant codes in cache to work, Author: mohan_zl
 
-  *) [TS-873]: Wrong code in iocore/net/UnixNet.cc, Author: mohan_zl
+  *) [TS-869] The stat code for ram_cache miss is lost, Author: mohan_zl
 
-  *) [TS-833]: Continuation::handleEvent deadbeef fix, authors jplevyak and
+  *) [TS-873] Wrong code in iocore/net/UnixNet.cc, Author: mohan_zl
+
+  *) [TS-833] Continuation::handleEvent deadbeef fix, authors jplevyak and
   taorui.
 
-  *) [TS-834]: InactivityCopy::check_inactivity crash.
+  *) [TS-834] InactivityCopy::check_inactivity crash.
 
   *) [TS-864] Need more information from CacheHttpInfo (req time, resp time,
   size). Author: William Bardwell.

Modified: trafficserver/traffic/trunk/example/protocol/TxnSM.c
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/example/protocol/TxnSM.c?rev=1146382&r1=1146381&r2=1146382&view=diff
==============================================================================
--- trafficserver/traffic/trunk/example/protocol/TxnSM.c (original)
+++ trafficserver/traffic/trunk/example/protocol/TxnSM.c Wed Jul 13 20:23:23 2011
@@ -21,6 +21,7 @@
   limitations under the License.
  */
 
+#include <netinet/in.h>
 #include "TxnSM.h"
 
 extern TSTextLogObject protocol_plugin_log;
@@ -458,6 +459,8 @@ int
 state_dns_lookup(TSCont contp, TSEvent event, TSHostLookupResult host_info)
 {
   TxnSM *txn_sm = (TxnSM *) TSContDataGet(contp);
+  struct sockaddr const* q_server_addr;
+  struct sockaddr_in ip_addr;
 
   TSDebug("protocol", "enter state_dns_lookup");
 
@@ -468,12 +471,16 @@ state_dns_lookup(TSCont contp, TSEvent e
   txn_sm->q_pending_action = NULL;
 
   /* Get the server IP from data structure TSHostLookupResult. */
-  txn_sm->q_server_ip = TSHostLookupResultIPGet(host_info);
+  q_server_addr = TSHostLookupResultAddrGet(host_info);
 
   /* Connect to the server using its IP. */
   set_handler(txn_sm->q_current_handler, (TxnSMHandler)&state_connect_to_server);
   TSAssert(txn_sm->q_pending_action == NULL);
-  txn_sm->q_pending_action = TSNetConnect(contp, txn_sm->q_server_ip, txn_sm->q_server_port);
+  TSAssert(q_server_addr->sa_family == AF_INET); /* NO IPv6 in this plugin */
+
+  memcpy(&ip_addr, q_server_addr, sizeof(ip_addr));
+  ip_addr.sin_port = txn_sm->q_server_port;
+  txn_sm->q_pending_action = TSNetConnect(contp, (struct sockaddr const*)&ip_addr);
 
   return TS_SUCCESS;
 }

Modified: trafficserver/traffic/trunk/example/protocol/TxnSM.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/example/protocol/TxnSM.h?rev=1146382&r1=1146381&r2=1146382&view=diff
==============================================================================
--- trafficserver/traffic/trunk/example/protocol/TxnSM.h (original)
+++ trafficserver/traffic/trunk/example/protocol/TxnSM.h Wed Jul 13 20:23:23 2011
@@ -53,7 +53,6 @@ typedef struct _TxnSM
   TSCacheKey q_key;
 
   char *q_server_name;
-  uint32_t q_server_ip;
   int q_server_port;
 
   TSVIO q_client_read_vio;

Modified: trafficserver/traffic/trunk/example/redirect-1/redirect-1.c
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/example/redirect-1/redirect-1.c?rev=1146382&r1=1146381&r2=1146382&view=diff
==============================================================================
--- trafficserver/traffic/trunk/example/redirect-1/redirect-1.c (original)
+++ trafficserver/traffic/trunk/example/redirect-1/redirect-1.c Wed Jul 13 20:23:23 2011
@@ -101,8 +101,6 @@ handle_client_lookup(TSHttpTxn txnp, TSC
 #endif
 
   const char *host;
-  char *clientstring;
-  struct in_addr tempstruct;
 
   /*
    * Here we declare local coupled statistics variables:
@@ -136,17 +134,24 @@ handle_client_lookup(TSHttpTxn txnp, TSC
    */
   INKStatFloatAddTo(local_requests_all, 1.0);
 
+  if (TSIsDebugTagSet("redirect")) {
+    struct sockaddr const* addr = TSHttpTxnClientAddrGet(txnp);
 
-#if !defined (_WIN32)
-  clientip = (in_addr_t) TSHttpTxnClientIPGet(txnp);
-#else
-  clientip = TSHttpTxnClientIPGet(txnp);
-#endif
-
+    if (addr) {
+      socklen_t addr_size = 0;
 
-  tempstruct.s_addr = clientip;
-  clientstring = inet_ntoa(tempstruct);
-  TSDebug("redirect", "clientip is %s and block_ip is %s", clientstring, block_ip);
+      if (addr->sa_family == AF_INET)
+        addr_size = sizeof(struct sockaddr_in);
+      else if (addr->sa_family == AF_INET6)
+        addr_size = sizeof(struct sockaddr_in6);
+      if (addr_size > 0) {
+        char clientstring[INET6_ADDRSTRLEN];
+
+        if (NULL != inet_ntop(addr->sa_family, addr, clientstring, addr_size))
+          TSDebug("redirect", "clientip is %s and block_ip is %s", clientstring, block_ip);
+      }
+    }
+  }
 
   if (TSHttpTxnClientReqGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
     TSError("couldn't retrieve client request header\n");

Modified: trafficserver/traffic/trunk/example/server-transform/server-transform.c
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/example/server-transform/server-transform.c?rev=1146382&r1=1146381&r2=1146382&view=diff
==============================================================================
--- trafficserver/traffic/trunk/example/server-transform/server-transform.c (original)
+++ trafficserver/traffic/trunk/example/server-transform/server-transform.c Wed Jul 13 20:23:23 2011
@@ -171,6 +171,7 @@ transform_connect(TSCont contp, Transfor
 {
   TSAction action;
   int content_length;
+  struct sockaddr_in ip_addr;
 
   data->state = STATE_CONNECT;
 
@@ -205,7 +206,14 @@ transform_connect(TSCont contp, Transfor
     return 0;
   }
 
-  action = TSNetConnect(contp, server_ip, server_port);
+  /* TODO: This only supports IPv4, probably should be changed at some point, but
+     it's an example ... */
+  memset(&ip_addr, 0, sizeof(ip_addr));
+  ip_addr.sin_family = AF_INET;
+  ip_addr.sin_addr.s_addr = server_ip; /* Should be in network byte order */
+  ip_addr.sin_port = server_port;
+  action = TSNetConnect(contp, (struct sockaddr const*)&ip_addr);
+
   if (!TSActionDone(action)) {
     data->pending_action = action;
   }